diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java index 603e78f4ac28..3795d7dccae6 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java @@ -21,7 +21,7 @@ public interface GenericResource extends GroupableResource, Refreshable, - Updatable, + Updatable, Wrapper { /** * @return the namespace of the resource provider @@ -54,169 +54,194 @@ public interface GenericResource extends Object properties(); /** - * A generic resource definition allowing region to be specified. + * The entirety of the generic resource definition. */ - interface DefinitionBlank extends GroupableResource.DefinitionWithRegion { + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithResourceType, + DefinitionStages.WithProviderNamespace, + DefinitionStages.WithParentResource, + DefinitionStages.WithPlan, + DefinitionStages.WithApiVersion, + DefinitionStages.WithCreate { } /** - * A generic resource definition allowing resource group to be specified. + * Grouping of generic resource definition stages. */ - interface DefinitionWithGroup extends GroupableResource.DefinitionStages.WithGroup { - } - - /** - * A generic resource definition allowing resource type to be specified. - */ - interface DefinitionWithResourceType { + interface DefinitionStages { /** - * Specifies the resource's type. - * - * @param resourceType the type of the resources - * @return the next stage of generic resource definition + * A generic resource definition allowing region to be specified. */ - DefinitionWithProviderNamespace withResourceType(String resourceType); - } + interface Blank extends GroupableResource.DefinitionWithRegion { + } - /** - * A generic resource definition allowing provider namespace to be specified. - */ - interface DefinitionWithProviderNamespace { /** - * Specifies the resource provider's namespace. - * - * @param resourceProviderNamespace the namespace of the resource provider - * @return the next stage of the generic resource definition + * A generic resource definition allowing resource group to be specified. */ - DefinitionWithOrWithoutParentResource withProviderNamespace(String resourceProviderNamespace); - } + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } - /** - * A generic resource definition allowing parent resource to be specified. - */ - interface DefinitionWithOrWithoutParentResource extends DefinitionWithPlan { /** - * Specifies the parent resource. - * - * @param parentResourceId the parent resource id - * @return the next stage of the generic resource definition + * A generic resource definition allowing resource type to be specified. */ - DefinitionWithPlan withParentResource(String parentResourceId); // ParentResource is optional so user can navigate to DefinitionWithPlan with or without it. - } + interface WithResourceType { + /** + * Specifies the resource's type. + * + * @param resourceType the type of the resources + * @return the next stage of generic resource definition + */ + WithProviderNamespace withResourceType(String resourceType); + } - /** - * A generic resource definition allowing plan to be specified. - */ - interface DefinitionWithPlan { /** - * Specifies the plan of the resource. The plan can only be set for 3rd party resources. - * - * @param name the name of the plan - * @param publisher the publisher of the plan - * @param product the name of the product - * @param promotionCode the promotion code, if any - * @return the next stage of the generic resource definition + * A generic resource definition allowing provider namespace to be specified. */ - DefinitionWithApiVersion withPlan(String name, String publisher, String product, String promotionCode); + interface WithProviderNamespace { + /** + * Specifies the resource provider's namespace. + * + * @param resourceProviderNamespace the namespace of the resource provider + * @return the next stage of the generic resource definition + */ + WithPlan withProviderNamespace(String resourceProviderNamespace); + } /** - * Specifies the plan of the resource. - * - * @return the next stage of the generic resource definition + * A generic resource definition allowing plan to be specified. */ - DefinitionWithApiVersion withoutPlan(); - } + interface WithPlan { + /** + * Specifies the plan of the resource. The plan can only be set for 3rd party resources. + * + * @param name the name of the plan + * @param publisher the publisher of the plan + * @param product the name of the product + * @param promotionCode the promotion code, if any + * @return the next stage of the generic resource definition + */ + WithApiVersion withPlan(String name, String publisher, String product, String promotionCode); + + /** + * Specifies the plan of the resource. + * + * @return the next stage of the generic resource definition + */ + WithApiVersion withoutPlan(); + } - /** - * A generic resource definition allowing api version to be specified. - */ - interface DefinitionWithApiVersion { /** - * Specifies the api version. - * - * @param apiVersion the API version of the resource - * @return the next stage of the generic resource definition + * A generic resource definition allowing api version to be specified. */ - DefinitionCreatable withApiVersion(String apiVersion); - } + interface WithApiVersion { + /** + * Specifies the api version. + * + * @param apiVersion the API version of the resource + * @return the next stage of the generic resource definition + */ + WithCreate withApiVersion(String apiVersion); + } - /** - * A deployment definition with sufficient inputs to create a new - * resource in the cloud, but exposing additional optional inputs to - * specify. - */ - interface DefinitionCreatable extends - Creatable, - Resource.DefinitionWithTags { /** - * Specifies other properties. - * - * @param properties the properties object - * @return the next stage of generic resource definition + * A generic resource definition allowing parent resource to be specified. */ - DefinitionCreatable withProperties(Object properties); - } + interface WithParentResource { + /** + * Specifies the parent resource. + * + * @param parentResourceId the parent resource id + * @return the next stage of the generic resource definition + */ + WithCreate withParentResource(String parentResourceId); + } - /** - * A generic resource update allowing to change the resource properties. - */ - interface UpdateWithProperties { /** - * Specifies other properties of the resource. - * - * @param properties the properties object - * @return the next stage of generic resource update + * A deployment definition with sufficient inputs to create a new + * resource in the cloud, but exposing additional optional inputs to + * specify. */ - Update withProperties(Object properties); + interface WithCreate extends + WithParentResource, + Creatable, + Resource.DefinitionWithTags { + /** + * Specifies other properties. + * + * @param properties the properties object + * @return the next stage of generic resource definition + */ + WithCreate withProperties(Object properties); + } } /** - * A generic resource update allowing to change the parent resource. + * Grouping of generic resource update stages. */ - interface UpdateWithParentResource { + interface UpdateStages { /** - * Specifies the parent resource. - * - * @param parentResourceId the parent resource ID - * @return the next stage of the generic resource definition + * A generic resource update allowing to change the resource properties. */ - Update withParentResource(String parentResourceId); - } + interface WithProperties { + /** + * Specifies other properties of the resource. + * + * @param properties the properties object + * @return the next stage of generic resource update + */ + Update withProperties(Object properties); + } - /** - * A generic resource update allowing to change the resource plan. - */ - interface UpdateWithPlan { /** - * Specifies the plan of the resource. - * - * @param name the name of the plan - * @param publisher the publisher of the plan - * @param product the name of the product - * @param promotionCode the promotion code, if any - * @return the next stage of the generic resource update + * A generic resource update allowing to change the parent resource. */ - Update withPlan(String name, String publisher, String product, String promotionCode); + interface WithParentResource { + /** + * Specifies the parent resource. + * + * @param parentResourceId the parent resource ID + * @return the next stage of the generic resource definition + */ + Update withParentResource(String parentResourceId); + } /** - * Specifies the plan of the resource. - * - * @return the next stage of the generic resource update + * A generic resource update allowing to change the resource plan. */ - Update withoutPlan(); - } + interface WithPlan { + /** + * Specifies the plan of the resource. + * + * @param name the name of the plan + * @param publisher the publisher of the plan + * @param product the name of the product + * @param promotionCode the promotion code, if any + * @return the next stage of the generic resource update + */ + Update withPlan(String name, String publisher, String product, String promotionCode); + + /** + * Specifies the plan of the resource. + * + * @return the next stage of the generic resource update + */ + Update withoutPlan(); + } - /** - * The template for a generic resource update operation for specifying the resource provider API version. - */ - interface UpdateWithApiVersion { /** - * Specifies the API version of the resource provider. - * - * @param apiVersion the API version - * @return the next stage of the generic resource update + * The template for a generic resource update operation for specifying the resource provider API version. */ - Update withApiVersion(String apiVersion); + interface WithApiVersion { + /** + * Specifies the API version of the resource provider. + * + * @param apiVersion the API version + * @return the next stage of the generic resource update + */ + Update withApiVersion(String apiVersion); + } } /** @@ -224,9 +249,9 @@ interface UpdateWithApiVersion { */ interface Update extends Appliable, - UpdateWithPlan, - UpdateWithParentResource, - UpdateWithProperties, + UpdateStages.WithPlan, + UpdateStages.WithParentResource, + UpdateStages.WithProperties, Resource.UpdateWithTags { } } \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java index d4ad3640329e..1a70853b83e4 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java @@ -20,7 +20,7 @@ public interface GenericResources extends SupportsListingByGroup, SupportsGettingById, - SupportsCreating { + SupportsCreating { /** * Checks if a resource exists in a resource group. * diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java index 5a3ee01f0580..de76b5e66554 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java @@ -11,42 +11,36 @@ import com.microsoft.azure.management.resources.Deployment; import com.microsoft.azure.management.resources.DeploymentOperation; import com.microsoft.azure.management.resources.DeploymentOperations; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; - +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; import java.io.IOException; /** * The implementation of {@link DeploymentOperations}. */ final class DeploymentOperationsImpl + extends ReadableWrappersImpl implements DeploymentOperations { private final DeploymentOperationsInner client; private final Deployment deployment; - private final PagedListConverter converter; DeploymentOperationsImpl(final DeploymentOperationsInner client, final Deployment deployment) { this.client = client; this.deployment = deployment; - converter = new PagedListConverter() { - @Override - public DeploymentOperation typeConvert(DeploymentOperationInner deploymentInner) { - return createFluentModel(deploymentInner); - } - }; } @Override public PagedList list() throws CloudException, IOException { - return converter.convert(client.list(deployment.resourceGroupName(), deployment.name()).getBody()); + return wrapList(client.list(deployment.resourceGroupName(), deployment.name()).getBody()); } @Override public DeploymentOperation getById(String operationId) throws CloudException, IllegalArgumentException, IOException { - return createFluentModel(client.get(deployment.resourceGroupName(), deployment.name(), operationId).getBody()); + return wrapModel(client.get(deployment.resourceGroupName(), deployment.name(), operationId).getBody()); } - private DeploymentOperationImpl createFluentModel(DeploymentOperationInner deploymentOperationInner) { - return new DeploymentOperationImpl(deploymentOperationInner, this.client); + @Override + protected DeploymentOperationImpl wrapModel(DeploymentOperationInner inner) { + return new DeploymentOperationImpl(inner, this.client); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java index 857cb16d5716..e6778969f710 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java @@ -25,15 +25,8 @@ final class GenericResourceImpl ResourceManager> implements GenericResource, - GenericResource.DefinitionBlank, - GenericResource.DefinitionWithGroup, - GenericResource.DefinitionWithResourceType, - GenericResource.DefinitionWithProviderNamespace, - GenericResource.DefinitionWithOrWithoutParentResource, - GenericResource.DefinitionWithPlan, - GenericResource.DefinitionWithApiVersion, - GenericResource.DefinitionCreatable, - GenericResource.UpdateWithApiVersion, + GenericResource.Definition, + GenericResource.UpdateStages.WithApiVersion, GenericResource.Update { private final ResourcesInner client; private String resourceProviderNamespace; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java index 626ec3d84b7c..cc9f409d1efe 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java @@ -42,7 +42,7 @@ public PagedList listByGroup(String groupName) throws CloudExce } @Override - public GenericResource.DefinitionBlank define(String name) { + public GenericResource.DefinitionStages.Blank define(String name) { return new GenericResourceImpl( name, new GenericResourceInner(), diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java index ae73aecc023a..c47e13e92d06 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GenericResourcesTests.java @@ -47,9 +47,9 @@ public void canCreateUpdateMoveResource() throws Exception { .withExistingResourceGroup(rgName) .withResourceType("sites") .withProviderNamespace("Microsoft.Web") - .withParentResource("") .withoutPlan() .withApiVersion("2015-08-01") + .withParentResource("") .withProperties(new ObjectMapper().readTree("{\"SiteMode\":\"Limited\",\"ComputeMode\":\"Shared\"}")) .create(); //List