/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
- /**
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for
- * license information.
- *
- * Code generated by Microsoft (R) AutoRest Code Generator.
- */
- package com.microsoft.azure.management.apimanagement.v2019_01_01.implementation;
- import com.microsoft.azure.management.apimanagement.v2019_01_01.SchemaContract;
- import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl;
- import rx.Observable;
- import com.microsoft.azure.management.apimanagement.v2019_01_01.SchemaCreateOrUpdateContract;
- import rx.functions.Func1;
- class SchemaContractImpl extends CreatableUpdatableImpl<SchemaContract, SchemaContractInner, SchemaContractImpl> implements SchemaContract, SchemaContract.Definition, SchemaContract.Update {
- private final ApiManagementManager manager;
- private String resourceGroupName;
- private String serviceName;
- private String apiId;
- private String schemaId;
- private String cifMatch;
- private String uifMatch;
- private SchemaCreateOrUpdateContract createOrUpdateParameter;
- SchemaContractImpl(String name, ApiManagementManager manager) {
- super(name, new SchemaContractInner());
- this.manager = manager;
- // Set resource name
- this.schemaId = name;
- //
- this.createOrUpdateParameter = new SchemaCreateOrUpdateContract();
- }
- SchemaContractImpl(SchemaContractInner inner, ApiManagementManager manager) {
- super(inner.name(), inner);
- this.manager = manager;
- // Set resource name
- this.schemaId = inner.name();
- // set resource ancestor and positional variables
- this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups");
- this.serviceName = IdParsingUtils.getValueFromIdByName(inner.id(), "service");
- this.apiId = IdParsingUtils.getValueFromIdByName(inner.id(), "apis");
- this.schemaId = IdParsingUtils.getValueFromIdByName(inner.id(), "schemas");
- //
- this.createOrUpdateParameter = new SchemaCreateOrUpdateContract();
- }
- @Override
- public ApiManagementManager manager() {
- return this.manager;
- }
- @Override
- public Observable<SchemaContract> createResourceAsync() {
- ApiSchemasInner client = this.manager().inner().apiSchemas();
- return client.createOrUpdateAsync(this.resourceGroupName, this.serviceName, this.apiId, this.schemaId, this.createOrUpdateParameter, this.cifMatch)
- .map(new Func1<SchemaContractInner, SchemaContractInner>() {
- @Override
- public SchemaContractInner call(SchemaContractInner resource) {
- resetCreateUpdateParameters();
- return resource;
- }
- })
- .map(innerToFluentMap(this));
- }
- @Override
- public Observable<SchemaContract> updateResourceAsync() {
- ApiSchemasInner client = this.manager().inner().apiSchemas();
- return client.createOrUpdateAsync(this.resourceGroupName, this.serviceName, this.apiId, this.schemaId, this.createOrUpdateParameter, this.uifMatch)
- .map(new Func1<SchemaContractInner, SchemaContractInner>() {
- @Override
- public SchemaContractInner call(SchemaContractInner resource) {
- resetCreateUpdateParameters();
- return resource;
- }
- })
- .map(innerToFluentMap(this));
- }
- @Override
- protected Observable<SchemaContractInner> getInnerAsync() {
- ApiSchemasInner client = this.manager().inner().apiSchemas();
- return client.getAsync(this.resourceGroupName, this.serviceName, this.apiId, this.schemaId);
- }
- @Override
- public boolean isInCreateMode() {
- return this.inner().id() == null;
- }
- private void resetCreateUpdateParameters() {
- this.createOrUpdateParameter = new SchemaCreateOrUpdateContract();
- }
- @Override
- public String contentType() {
- return this.inner().contentType();
- }
- @Override
- public Object document() {
- return this.inner().document();
- }
- @Override
- public String id() {
- return this.inner().id();
- }
- @Override
- public String name() {
- return this.inner().name();
- }
- @Override
- public String type() {
- return this.inner().type();
- }
- @Override
- public SchemaContractImpl withExistingApi(String resourceGroupName, String serviceName, String apiId) {
- this.resourceGroupName = resourceGroupName;
- this.serviceName = serviceName;
- this.apiId = apiId;
- return this;
- }
- @Override
- public SchemaContractImpl withContentType(String contentType) {
- this.createOrUpdateParameter.withContentType(contentType);
- return this;
- }
- @Override
- public SchemaContractImpl withIfMatch(String ifMatch) {
- if (isInCreateMode()) {
- this.cifMatch = ifMatch;
- } else {
- this.uifMatch = ifMatch;
- }
- return this;
- }
- @Override
- public SchemaContractImpl withValue(String value) {
- this.createOrUpdateParameter.withValue(value);
- return this;
- }
- }