/sdk/apimanagement/mgmt-v2019_01_01/src/main/java/com/microsoft/azure/management/apimanagement/v2019_01_01/implementation/SchemaContractImpl.java

http://github.com/WindowsAzure/azure-sdk-for-java · Java · 153 lines · 120 code · 21 blank · 12 comment · 3 complexity · 098f0b17f06596eb48eac21509465a8c MD5 · raw file

  1. /**
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for
  4. * license information.
  5. *
  6. * Code generated by Microsoft (R) AutoRest Code Generator.
  7. */
  8. package com.microsoft.azure.management.apimanagement.v2019_01_01.implementation;
  9. import com.microsoft.azure.management.apimanagement.v2019_01_01.SchemaContract;
  10. import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl;
  11. import rx.Observable;
  12. import com.microsoft.azure.management.apimanagement.v2019_01_01.SchemaCreateOrUpdateContract;
  13. import rx.functions.Func1;
  14. class SchemaContractImpl extends CreatableUpdatableImpl<SchemaContract, SchemaContractInner, SchemaContractImpl> implements SchemaContract, SchemaContract.Definition, SchemaContract.Update {
  15. private final ApiManagementManager manager;
  16. private String resourceGroupName;
  17. private String serviceName;
  18. private String apiId;
  19. private String schemaId;
  20. private String cifMatch;
  21. private String uifMatch;
  22. private SchemaCreateOrUpdateContract createOrUpdateParameter;
  23. SchemaContractImpl(String name, ApiManagementManager manager) {
  24. super(name, new SchemaContractInner());
  25. this.manager = manager;
  26. // Set resource name
  27. this.schemaId = name;
  28. //
  29. this.createOrUpdateParameter = new SchemaCreateOrUpdateContract();
  30. }
  31. SchemaContractImpl(SchemaContractInner inner, ApiManagementManager manager) {
  32. super(inner.name(), inner);
  33. this.manager = manager;
  34. // Set resource name
  35. this.schemaId = inner.name();
  36. // set resource ancestor and positional variables
  37. this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups");
  38. this.serviceName = IdParsingUtils.getValueFromIdByName(inner.id(), "service");
  39. this.apiId = IdParsingUtils.getValueFromIdByName(inner.id(), "apis");
  40. this.schemaId = IdParsingUtils.getValueFromIdByName(inner.id(), "schemas");
  41. //
  42. this.createOrUpdateParameter = new SchemaCreateOrUpdateContract();
  43. }
  44. @Override
  45. public ApiManagementManager manager() {
  46. return this.manager;
  47. }
  48. @Override
  49. public Observable<SchemaContract> createResourceAsync() {
  50. ApiSchemasInner client = this.manager().inner().apiSchemas();
  51. return client.createOrUpdateAsync(this.resourceGroupName, this.serviceName, this.apiId, this.schemaId, this.createOrUpdateParameter, this.cifMatch)
  52. .map(new Func1<SchemaContractInner, SchemaContractInner>() {
  53. @Override
  54. public SchemaContractInner call(SchemaContractInner resource) {
  55. resetCreateUpdateParameters();
  56. return resource;
  57. }
  58. })
  59. .map(innerToFluentMap(this));
  60. }
  61. @Override
  62. public Observable<SchemaContract> updateResourceAsync() {
  63. ApiSchemasInner client = this.manager().inner().apiSchemas();
  64. return client.createOrUpdateAsync(this.resourceGroupName, this.serviceName, this.apiId, this.schemaId, this.createOrUpdateParameter, this.uifMatch)
  65. .map(new Func1<SchemaContractInner, SchemaContractInner>() {
  66. @Override
  67. public SchemaContractInner call(SchemaContractInner resource) {
  68. resetCreateUpdateParameters();
  69. return resource;
  70. }
  71. })
  72. .map(innerToFluentMap(this));
  73. }
  74. @Override
  75. protected Observable<SchemaContractInner> getInnerAsync() {
  76. ApiSchemasInner client = this.manager().inner().apiSchemas();
  77. return client.getAsync(this.resourceGroupName, this.serviceName, this.apiId, this.schemaId);
  78. }
  79. @Override
  80. public boolean isInCreateMode() {
  81. return this.inner().id() == null;
  82. }
  83. private void resetCreateUpdateParameters() {
  84. this.createOrUpdateParameter = new SchemaCreateOrUpdateContract();
  85. }
  86. @Override
  87. public String contentType() {
  88. return this.inner().contentType();
  89. }
  90. @Override
  91. public Object document() {
  92. return this.inner().document();
  93. }
  94. @Override
  95. public String id() {
  96. return this.inner().id();
  97. }
  98. @Override
  99. public String name() {
  100. return this.inner().name();
  101. }
  102. @Override
  103. public String type() {
  104. return this.inner().type();
  105. }
  106. @Override
  107. public SchemaContractImpl withExistingApi(String resourceGroupName, String serviceName, String apiId) {
  108. this.resourceGroupName = resourceGroupName;
  109. this.serviceName = serviceName;
  110. this.apiId = apiId;
  111. return this;
  112. }
  113. @Override
  114. public SchemaContractImpl withContentType(String contentType) {
  115. this.createOrUpdateParameter.withContentType(contentType);
  116. return this;
  117. }
  118. @Override
  119. public SchemaContractImpl withIfMatch(String ifMatch) {
  120. if (isInCreateMode()) {
  121. this.cifMatch = ifMatch;
  122. } else {
  123. this.uifMatch = ifMatch;
  124. }
  125. return this;
  126. }
  127. @Override
  128. public SchemaContractImpl withValue(String value) {
  129. this.createOrUpdateParameter.withValue(value);
  130. return this;
  131. }
  132. }