From da379809eac2a044f9dde211bc691fc664d20a72 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Fri, 9 May 2025 04:03:23 +0000 Subject: [PATCH] CodeGen from PR 34550 in Azure/azure-rest-api-specs Merge b8b785b5d18120df26ef25a2c4777bdd5fc632a2 into 9f69db7532b6706baedc004f2eda762196a3e1eb --- eng/versioning/version_client.txt | 1 + pom.xml | 1 + .../CHANGELOG.md | 8 + .../azure-resourcemanager-contoso/README.md | 102 ++ .../azure-resourcemanager-contoso/SAMPLE.md | 211 +++ .../azure-resourcemanager-contoso/pom.xml | 74 ++ .../contoso/ContosoManager.java | 298 +++++ .../contoso/fluent/ContosoClient.java | 62 + .../contoso/fluent/EmployeesClient.java | 237 ++++ .../contoso/fluent/OperationsClient.java | 40 + .../contoso/fluent/models/EmployeeInner.java | 192 +++ .../contoso/fluent/models/OperationInner.java | 161 +++ .../contoso/fluent/models/package-info.java | 9 + .../contoso/fluent/package-info.java | 9 + .../implementation/ContosoClientBuilder.java | 138 ++ .../implementation/ContosoClientImpl.java | 304 +++++ .../contoso/implementation/EmployeeImpl.java | 165 +++ .../implementation/EmployeesClientImpl.java | 1176 +++++++++++++++++ .../contoso/implementation/EmployeesImpl.java | 145 ++ .../contoso/implementation/OperationImpl.java | 50 + .../implementation/OperationsClientImpl.java | 235 ++++ .../implementation/OperationsImpl.java | 45 + .../implementation/ResourceManagerUtils.java | 195 +++ .../models/EmployeeListResult.java | 112 ++ .../models/OperationListResult.java | 113 ++ .../contoso/implementation/package-info.java | 9 + .../contoso/models/ActionType.java | 46 + .../contoso/models/Employee.java | 265 ++++ .../contoso/models/EmployeeProperties.java | 178 +++ .../contoso/models/Employees.java | 157 +++ .../contoso/models/Operation.java | 58 + .../contoso/models/OperationDisplay.java | 136 ++ .../contoso/models/Operations.java | 35 + .../contoso/models/Origin.java | 57 + .../contoso/models/ProvisioningState.java | 76 ++ .../contoso/models/package-info.java | 9 + .../resourcemanager/contoso/package-info.java | 9 + .../src/main/java/module-info.java | 16 + .../proxy-config.json | 1 + .../reflect-config.json | 1 + .../azure-resourcemanager-contoso.properties | 1 + .../EmployeesCreateOrUpdateSamples.java | 46 + .../generated/EmployeesDeleteSamples.java | 22 + .../EmployeesGetByResourceGroupSamples.java | 23 + .../EmployeesListByResourceGroupSamples.java | 22 + .../generated/EmployeesListSamples.java | 22 + .../generated/EmployeesUpdateSamples.java | 46 + .../generated/OperationsListSamples.java | 22 + .../contoso/generated/EmployeeInnerTests.java | 49 + .../generated/EmployeeListResultTests.java | 23 + .../generated/EmployeePropertiesTests.java | 28 + .../EmployeesCreateOrUpdateMockTests.java | 61 + ...tByResourceGroupWithResponseMockTests.java | 42 + ...EmployeesListByResourceGroupMockTests.java | 42 + .../generated/EmployeesListMockTests.java | 41 + .../generated/OperationDisplayTests.java | 17 + .../generated/OperationInnerTests.java | 17 + .../generated/OperationListResultTests.java | 19 + .../generated/OperationsListMockTests.java | 36 + .../tsp-location.yaml | 4 + sdk/contoso/ci.yml | 46 + sdk/contoso/pom.xml | 15 + 62 files changed, 5780 insertions(+) create mode 100644 sdk/contoso/azure-resourcemanager-contoso/CHANGELOG.md create mode 100644 sdk/contoso/azure-resourcemanager-contoso/README.md create mode 100644 sdk/contoso/azure-resourcemanager-contoso/SAMPLE.md create mode 100644 sdk/contoso/azure-resourcemanager-contoso/pom.xml create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/ContosoManager.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/ContosoClient.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/EmployeesClient.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/OperationsClient.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/EmployeeInner.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/OperationInner.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/package-info.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/package-info.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientBuilder.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeeImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesClientImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsClientImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsImpl.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ResourceManagerUtils.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/EmployeeListResult.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/OperationListResult.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/package-info.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ActionType.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employee.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/EmployeeProperties.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employees.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operation.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/OperationDisplay.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operations.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Origin.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ProvisioningState.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/package-info.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/package-info.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/java/module-info.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/proxy-config.json create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/reflect-config.json create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/main/resources/azure-resourcemanager-contoso.properties create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesDeleteSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesUpdateSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/OperationsListSamples.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeInnerTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeListResultTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeePropertiesTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateMockTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupWithResponseMockTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupMockTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListMockTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationDisplayTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationInnerTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationListResultTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationsListMockTests.java create mode 100644 sdk/contoso/azure-resourcemanager-contoso/tsp-location.yaml create mode 100644 sdk/contoso/ci.yml create mode 100644 sdk/contoso/pom.xml diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index f23b343f3b92..2222f5166e45 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -483,6 +483,7 @@ com.azure.resourcemanager:azure-resourcemanager-programmableconnectivity;1.0.0-b com.azure.resourcemanager:azure-resourcemanager-dell-storage;1.0.0-beta.1;1.0.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-sitemanager;1.0.0-beta.1;1.0.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-mongodbatlas;1.0.0-beta.1;1.0.0-beta.1 +com.azure.resourcemanager:azure-resourcemanager-contoso;1.0.0-beta.1;1.0.0-beta.1 com.azure.tools:azure-sdk-archetype;1.0.0;1.2.0-beta.1 com.azure.tools:azure-sdk-build-tool;1.0.0;1.1.0-beta.1 com.azure.v2:azure-client-sdk-parent;2.0.0-beta.1;2.0.0-beta.1 diff --git a/pom.xml b/pom.xml index a0c18e0cb24e..ebde03753d85 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,7 @@ sdk/containerregistry sdk/containerservicefleet sdk/contentsafety + sdk/contoso sdk/core sdk/core-v2 sdk/cosmos diff --git a/sdk/contoso/azure-resourcemanager-contoso/CHANGELOG.md b/sdk/contoso/azure-resourcemanager-contoso/CHANGELOG.md new file mode 100644 index 000000000000..3b1917311698 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 1.0.0-beta.1 (2025-05-09) + +- Azure Resource Manager Contoso client library for Java. This package contains Microsoft Azure SDK for Contoso Management SDK. Microsoft.Contoso Resource Provider management API. For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). +### Features Added + +- Initial release for the azure-resourcemanager-contoso Java SDK. diff --git a/sdk/contoso/azure-resourcemanager-contoso/README.md b/sdk/contoso/azure-resourcemanager-contoso/README.md new file mode 100644 index 000000000000..be9246e2cf79 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/README.md @@ -0,0 +1,102 @@ +# Azure Resource Manager Contoso client library for Java + +Azure Resource Manager Contoso client library for Java. + +This package contains Microsoft Azure SDK for Contoso Management SDK. Microsoft.Contoso Resource Provider management API. For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). + +## We'd love to hear your feedback + +We're always working on improving our products and the way we communicate with our users. So we'd love to learn what's working and how we can do better. + +If you haven't already, please take a few minutes to [complete this short survey][survey] we have put together. + +Thank you in advance for your collaboration. We really appreciate your time! + +## Documentation + +Various documentation is available to help you get started + +- [API reference documentation][docs] + +## Getting started + +### Prerequisites + +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] + +### Adding the package to your product + +[//]: # ({x-version-update-start;com.azure.resourcemanager:azure-resourcemanager-contoso;current}) +```xml + + com.azure.resourcemanager + azure-resourcemanager-contoso + 1.0.0-beta.1 + +``` +[//]: # ({x-version-update-end}) + +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] and [Azure Core Netty HTTP][azure_core_http_netty] packages provide the default implementation. + +### Authentication + +Microsoft Entra ID token authentication relies on the [credential class][azure_identity_credentials] from [Azure Identity][azure_identity] package. + +Azure subscription ID can be configured via `AZURE_SUBSCRIPTION_ID` environment variable. + +Assuming the use of the `DefaultAzureCredential` credential class, the client can be authenticated using the following code: + +```java +AzureProfile profile = new AzureProfile(AzureCloud.AZURE_PUBLIC_CLOUD); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ContosoManager manager = ContosoManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change the `AzureCloud.AZURE_PUBLIC_CLOUD` variable if otherwise. + +See [Authentication][authenticate] for more options. + +## Key concepts + +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + +## Examples + +[Code snippets and samples](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/contoso/azure-resourcemanager-contoso/SAMPLE.md) + + +## Troubleshooting + +## Next steps + +## Contributing + +For details on contributing to this repository, see the [contributing guide][cg]. + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit . + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact with any additional questions or comments. + + +[survey]: https://microsoft.qualtrics.com/jfe/form/SV_ehN0lIk2FKEBkwd?Q_CHL=DOCS +[docs]: https://azure.github.io/azure-sdk-for-java/ +[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity +[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity#credentials +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/AUTH.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/DESIGN.md +[cg]: https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md +[coc]: https://opensource.microsoft.com/codeofconduct/ +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ diff --git a/sdk/contoso/azure-resourcemanager-contoso/SAMPLE.md b/sdk/contoso/azure-resourcemanager-contoso/SAMPLE.md new file mode 100644 index 000000000000..8069b3b39c5c --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/SAMPLE.md @@ -0,0 +1,211 @@ +# Code snippets and samples + + +## Employees + +- [CreateOrUpdate](#employees_createorupdate) +- [Delete](#employees_delete) +- [GetByResourceGroup](#employees_getbyresourcegroup) +- [List](#employees_list) +- [ListByResourceGroup](#employees_listbyresourcegroup) +- [Update](#employees_update) + +## Operations + +- [List](#operations_list) +### Employees_CreateOrUpdate + +```java +/** + * Samples for Operations List. + */ +public final class OperationsListSamples { + /* + * x-ms-original-file: 2021-11-01/Operations_List.json + */ + /** + * Sample code: Operations_List. + * + * @param manager Entry point to ContosoManager. + */ + public static void operationsList(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.operations().list(com.azure.core.util.Context.NONE); + } +} +``` + +### Employees_Delete + +```java +/** + * Samples for Employees List. + */ +public final class EmployeesListSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_ListBySubscription.json + */ + /** + * Sample code: Employees_ListBySubscription. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesListBySubscription(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees().list(com.azure.core.util.Context.NONE); + } +} +``` + +### Employees_GetByResourceGroup + +```java +/** + * Samples for Employees GetByResourceGroup. + */ +public final class EmployeesGetByResourceGroupSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_Get.json + */ + /** + * Sample code: Employees_Get. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesGet(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees() + .getByResourceGroupWithResponse("rgopenapi", "le-8MU--J3W6q8D386p3-iT3", com.azure.core.util.Context.NONE); + } +} +``` + +### Employees_List + +```java +/** + * Samples for Employees ListByResourceGroup. + */ +public final class EmployeesListByResourceGroupSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_ListByResourceGroup.json + */ + /** + * Sample code: Employees_ListByResourceGroup. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesListByResourceGroup(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees().listByResourceGroup("rgopenapi", com.azure.core.util.Context.NONE); + } +} +``` + +### Employees_ListByResourceGroup + +```java +import com.azure.resourcemanager.contoso.models.Employee; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.util.HashMap; +import java.util.Map; + +/** + * Samples for Employees Update. + */ +public final class EmployeesUpdateSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_Update.json + */ + /** + * Sample code: Employees_Update. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesUpdate(com.azure.resourcemanager.contoso.ContosoManager manager) { + Employee resource = manager.employees() + .getByResourceGroupWithResponse("rgopenapi", "-XhyNJ--", com.azure.core.util.Context.NONE) + .getValue(); + resource.update() + .withTags(mapOf("key7952", "fakeTokenPlaceholder")) + .withProperties( + new EmployeeProperties().withAge(24).withCity("uyfg").withProfile("oapgijcswfkruiuuzbwco".getBytes())) + .apply(); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} +``` + +### Employees_Update + +```java +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.util.HashMap; +import java.util.Map; + +/** + * Samples for Employees CreateOrUpdate. + */ +public final class EmployeesCreateOrUpdateSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_CreateOrUpdate.json + */ + /** + * Sample code: Employees_CreateOrUpdate. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesCreateOrUpdate(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees() + .define("9KF-f-8b") + .withRegion("itajgxyqozseoygnl") + .withExistingResourceGroup("rgopenapi") + .withTags(mapOf("key2913", "fakeTokenPlaceholder")) + .withProperties(new EmployeeProperties().withAge(30) + .withCity("gydhnntudughbmxlkyzrskcdkotrxn") + .withProfile("ms".getBytes())) + .create(); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} +``` + +### Operations_List + +```java +/** + * Samples for Employees Delete. + */ +public final class EmployeesDeleteSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_Delete.json + */ + /** + * Sample code: Employees_Delete. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesDelete(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees().delete("rgopenapi", "5vX--BxSu3ux48rI4O9OQ569", com.azure.core.util.Context.NONE); + } +} +``` + diff --git a/sdk/contoso/azure-resourcemanager-contoso/pom.xml b/sdk/contoso/azure-resourcemanager-contoso/pom.xml new file mode 100644 index 000000000000..06b03f0c4467 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure.resourcemanager + azure-resourcemanager-contoso + 1.0.0-beta.1 + jar + + Microsoft Azure SDK for Contoso Management + This package contains Microsoft Azure SDK for Contoso Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Microsoft.Contoso Resource Provider management API. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + microsoft + Microsoft + + + + UTF-8 + 0 + 0 + true + + + + com.azure + azure-core + 1.55.3 + + + com.azure + azure-core-management + 1.17.0 + + + com.azure + azure-core-test + 1.27.0-beta.8 + test + + + com.azure + azure-identity + 1.16.0 + test + + + diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/ContosoManager.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/ContosoManager.java new file mode 100644 index 000000000000..d32266a0eed8 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/ContosoManager.java @@ -0,0 +1,298 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.contoso.fluent.ContosoClient; +import com.azure.resourcemanager.contoso.implementation.ContosoClientBuilder; +import com.azure.resourcemanager.contoso.implementation.EmployeesImpl; +import com.azure.resourcemanager.contoso.implementation.OperationsImpl; +import com.azure.resourcemanager.contoso.models.Employees; +import com.azure.resourcemanager.contoso.models.Operations; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Entry point to ContosoManager. + * Microsoft.Contoso Resource Provider management API. + */ +public final class ContosoManager { + private Operations operations; + + private Employees employees; + + private final ContosoClient clientObject; + + private ContosoManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + this.clientObject = new ContosoClientBuilder().pipeline(httpPipeline) + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) + .subscriptionId(profile.getSubscriptionId()) + .defaultPollInterval(defaultPollInterval) + .buildClient(); + } + + /** + * Creates an instance of Contoso service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the Contoso service API instance. + */ + public static ContosoManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return configure().authenticate(credential, profile); + } + + /** + * Creates an instance of Contoso service API entry point. + * + * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential. + * @param profile the Azure profile for client. + * @return the Contoso service API instance. + */ + public static ContosoManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return new ContosoManager(httpPipeline, profile, null); + } + + /** + * Gets a Configurable instance that can be used to create ContosoManager with optional configuration. + * + * @return the Configurable instance allowing configurations. + */ + public static Configurable configure() { + return new ContosoManager.Configurable(); + } + + /** + * The Configurable allowing configurations to be set. + */ + public static final class Configurable { + private static final ClientLogger LOGGER = new ClientLogger(Configurable.class); + private static final String SDK_VERSION = "version"; + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-resourcemanager-contoso.properties"); + + private HttpClient httpClient; + private HttpLogOptions httpLogOptions; + private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); + private RetryPolicy retryPolicy; + private RetryOptions retryOptions; + private Duration defaultPollInterval; + + private Configurable() { + } + + /** + * Sets the http client. + * + * @param httpClient the HTTP client. + * @return the configurable object itself. + */ + public Configurable withHttpClient(HttpClient httpClient) { + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); + return this; + } + + /** + * Sets the logging options to the HTTP pipeline. + * + * @param httpLogOptions the HTTP log options. + * @return the configurable object itself. + */ + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); + return this; + } + + /** + * Adds the pipeline policy to the HTTP pipeline. + * + * @param policy the HTTP pipeline policy. + * @return the configurable object itself. + */ + public Configurable withPolicy(HttpPipelinePolicy policy) { + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + + /** + * Sets the retry policy to the HTTP pipeline. + * + * @param retryPolicy the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); + return this; + } + + /** + * Sets the retry options for the HTTP pipeline retry policy. + *

+ * This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}. + * + * @param retryOptions the retry options for the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryOptions(RetryOptions retryOptions) { + this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); + return this; + } + + /** + * Sets the default poll interval, used when service does not provide "Retry-After" header. + * + * @param defaultPollInterval the default poll interval. + * @return the configurable object itself. + */ + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval + = Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); + if (this.defaultPollInterval.isNegative()) { + throw LOGGER + .logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative")); + } + return this; + } + + /** + * Creates an instance of Contoso service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the Contoso service API instance. + */ + public ContosoManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + + StringBuilder userAgentBuilder = new StringBuilder(); + userAgentBuilder.append("azsdk-java") + .append("-") + .append("com.azure.resourcemanager.contoso") + .append("/") + .append(clientVersion); + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { + userAgentBuilder.append(" (") + .append(Configuration.getGlobalConfiguration().get("java.version")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.name")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.version")) + .append("; auto-generated)"); + } else { + userAgentBuilder.append(" (auto-generated)"); + } + + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } + if (retryPolicy == null) { + if (retryOptions != null) { + retryPolicy = new RetryPolicy(retryOptions); + } else { + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); + } + } + List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); + policies.add(new AddHeadersFromContextPolicy()); + policies.add(new RequestIdPolicy()); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy); + policies.add(new AddDatePolicy()); + policies.add(new BearerTokenAuthenticationPolicy(credential, scopes.toArray(new String[0]))); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + return new ContosoManager(httpPipeline, profile, defaultPollInterval); + } + } + + /** + * Gets the resource collection API of Operations. + * + * @return Resource collection API of Operations. + */ + public Operations operations() { + if (this.operations == null) { + this.operations = new OperationsImpl(clientObject.getOperations(), this); + } + return operations; + } + + /** + * Gets the resource collection API of Employees. It manages Employee. + * + * @return Resource collection API of Employees. + */ + public Employees employees() { + if (this.employees == null) { + this.employees = new EmployeesImpl(clientObject.getEmployees(), this); + } + return employees; + } + + /** + * Gets wrapped service client ContosoClient providing direct access to the underlying auto-generated API + * implementation, based on Azure REST API. + * + * @return Wrapped service client ContosoClient. + */ + public ContosoClient serviceClient() { + return this.clientObject; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/ContosoClient.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/ContosoClient.java new file mode 100644 index 000000000000..c248e58f7956 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/ContosoClient.java @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.fluent; + +import com.azure.core.http.HttpPipeline; +import java.time.Duration; + +/** + * The interface for ContosoClient class. + */ +public interface ContosoClient { + /** + * Gets Service host. + * + * @return the endpoint value. + */ + String getEndpoint(); + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + String getApiVersion(); + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the OperationsClient object to access its operations. + * + * @return the OperationsClient object. + */ + OperationsClient getOperations(); + + /** + * Gets the EmployeesClient object to access its operations. + * + * @return the EmployeesClient object. + */ + EmployeesClient getEmployees(); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/EmployeesClient.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/EmployeesClient.java new file mode 100644 index 000000000000..6527092af91f --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/EmployeesClient.java @@ -0,0 +1,237 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.fluent; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; + +/** + * An instance of this class provides access to all the operations defined in EmployeesClient. + */ +public interface EmployeesClient { + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, String employeeName, + Context context); + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + EmployeeInner getByResourceGroup(String resourceGroupName, String employeeName); + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of employee resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, EmployeeInner> beginCreateOrUpdate(String resourceGroupName, + String employeeName, EmployeeInner resource); + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of employee resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, EmployeeInner> beginCreateOrUpdate(String resourceGroupName, + String employeeName, EmployeeInner resource, Context context); + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + EmployeeInner createOrUpdate(String resourceGroupName, String employeeName, EmployeeInner resource); + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + EmployeeInner createOrUpdate(String resourceGroupName, String employeeName, EmployeeInner resource, + Context context); + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response updateWithResponse(String resourceGroupName, String employeeName, EmployeeInner properties, + Context context); + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + EmployeeInner update(String resourceGroupName, String employeeName, EmployeeInner properties); + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, Void> beginDelete(String resourceGroupName, String employeeName); + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, Void> beginDelete(String resourceGroupName, String employeeName, Context context); + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void delete(String resourceGroupName, String employeeName); + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void delete(String resourceGroupName, String employeeName, Context context); + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByResourceGroup(String resourceGroupName); + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByResourceGroup(String resourceGroupName, Context context); + + /** + * List Employee resources by subscription ID. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(); + + /** + * List Employee resources by subscription ID. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(Context context); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/OperationsClient.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/OperationsClient.java new file mode 100644 index 000000000000..a24a6850bf8c --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/OperationsClient.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.fluent; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; + +/** + * An instance of this class provides access to all the operations defined in OperationsClient. + */ +public interface OperationsClient { + /** + * List the operations for the provider. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(); + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(Context context); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/EmployeeInner.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/EmployeeInner.java new file mode 100644 index 000000000000..0c094e4050a4 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/EmployeeInner.java @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.fluent.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.management.Resource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.io.IOException; +import java.util.Map; + +/** + * Employee resource. + */ +@Fluent +public final class EmployeeInner extends Resource { + /* + * The resource-specific properties for this resource. + */ + private EmployeeProperties properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of EmployeeInner class. + */ + public EmployeeInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public EmployeeProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the EmployeeInner object itself. + */ + public EmployeeInner withProperties(EmployeeProperties properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public EmployeeInner withLocation(String location) { + super.withLocation(location); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public EmployeeInner withTags(Map tags) { + super.withTags(tags); + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (properties() != null) { + properties().validate(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("location", location()); + jsonWriter.writeMapField("tags", tags(), (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmployeeInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmployeeInner if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the EmployeeInner. + */ + public static EmployeeInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + EmployeeInner deserializedEmployeeInner = new EmployeeInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedEmployeeInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedEmployeeInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedEmployeeInner.type = reader.getString(); + } else if ("location".equals(fieldName)) { + deserializedEmployeeInner.withLocation(reader.getString()); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedEmployeeInner.withTags(tags); + } else if ("properties".equals(fieldName)) { + deserializedEmployeeInner.properties = EmployeeProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedEmployeeInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedEmployeeInner; + }); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/OperationInner.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/OperationInner.java new file mode 100644 index 000000000000..7216d9fa62ba --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/OperationInner.java @@ -0,0 +1,161 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.fluent.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.resourcemanager.contoso.models.ActionType; +import com.azure.resourcemanager.contoso.models.OperationDisplay; +import com.azure.resourcemanager.contoso.models.Origin; +import java.io.IOException; + +/** + * REST API Operation + * + * Details of a REST API operation, returned from the Resource Provider Operations API. + */ +@Immutable +public final class OperationInner implements JsonSerializable { + /* + * The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" + */ + private String name; + + /* + * Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure + * Resource Manager/control-plane operations. + */ + private Boolean isDataAction; + + /* + * Localized display information for this particular operation. + */ + private OperationDisplay display; + + /* + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default + * value is "user,system" + */ + private Origin origin; + + /* + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ + private ActionType actionType; + + /** + * Creates an instance of OperationInner class. + */ + private OperationInner() { + } + + /** + * Get the name property: The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + * + * @return the name value. + */ + public String name() { + return this.name; + } + + /** + * Get the isDataAction property: Whether the operation applies to data-plane. This is "true" for data-plane + * operations and "false" for Azure Resource Manager/control-plane operations. + * + * @return the isDataAction value. + */ + public Boolean isDataAction() { + return this.isDataAction; + } + + /** + * Get the display property: Localized display information for this particular operation. + * + * @return the display value. + */ + public OperationDisplay display() { + return this.display; + } + + /** + * Get the origin property: The intended executor of the operation; as in Resource Based Access Control (RBAC) and + * audit logs UX. Default value is "user,system". + * + * @return the origin value. + */ + public Origin origin() { + return this.origin; + } + + /** + * Get the actionType property: Extensible enum. Indicates the action type. "Internal" refers to actions that are + * for internal only APIs. + * + * @return the actionType value. + */ + public ActionType actionType() { + return this.actionType; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (display() != null) { + display().validate(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("display", this.display); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationInner if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the OperationInner. + */ + public static OperationInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationInner deserializedOperationInner = new OperationInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + deserializedOperationInner.name = reader.getString(); + } else if ("isDataAction".equals(fieldName)) { + deserializedOperationInner.isDataAction = reader.getNullable(JsonReader::getBoolean); + } else if ("display".equals(fieldName)) { + deserializedOperationInner.display = OperationDisplay.fromJson(reader); + } else if ("origin".equals(fieldName)) { + deserializedOperationInner.origin = Origin.fromString(reader.getString()); + } else if ("actionType".equals(fieldName)) { + deserializedOperationInner.actionType = ActionType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationInner; + }); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/package-info.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/package-info.java new file mode 100644 index 000000000000..407d157571eb --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the inner data models for Contoso. + * Microsoft.Contoso Resource Provider management API. + */ +package com.azure.resourcemanager.contoso.fluent.models; diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/package-info.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/package-info.java new file mode 100644 index 000000000000..5fd98a299528 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/fluent/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the service clients for Contoso. + * Microsoft.Contoso Resource Provider management API. + */ +package com.azure.resourcemanager.contoso.fluent; diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientBuilder.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientBuilder.java new file mode 100644 index 000000000000..bcbf8d8525f3 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientBuilder.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.SerializerAdapter; +import java.time.Duration; + +/** + * A builder for creating a new instance of the ContosoClientImpl type. + */ +@ServiceClientBuilder(serviceClients = { ContosoClientImpl.class }) +public final class ContosoClientBuilder { + /* + * Service host + */ + private String endpoint; + + /** + * Sets Service host. + * + * @param endpoint the endpoint value. + * @return the ContosoClientBuilder. + */ + public ContosoClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The ID of the target subscription. The value must be an UUID. + */ + private String subscriptionId; + + /** + * Sets The ID of the target subscription. The value must be an UUID. + * + * @param subscriptionId the subscriptionId value. + * @return the ContosoClientBuilder. + */ + public ContosoClientBuilder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /* + * The environment to connect to + */ + private AzureEnvironment environment; + + /** + * Sets The environment to connect to. + * + * @param environment the environment value. + * @return the ContosoClientBuilder. + */ + public ContosoClientBuilder environment(AzureEnvironment environment) { + this.environment = environment; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the ContosoClientBuilder. + */ + public ContosoClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The default poll interval for long-running operation + */ + private Duration defaultPollInterval; + + /** + * Sets The default poll interval for long-running operation. + * + * @param defaultPollInterval the defaultPollInterval value. + * @return the ContosoClientBuilder. + */ + public ContosoClientBuilder defaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval = defaultPollInterval; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the ContosoClientBuilder. + */ + public ContosoClientBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /** + * Builds an instance of ContosoClientImpl with the provided parameters. + * + * @return an instance of ContosoClientImpl. + */ + public ContosoClientImpl buildClient() { + String localEndpoint = (endpoint != null) ? endpoint : "https://management.azure.com"; + AzureEnvironment localEnvironment = (environment != null) ? environment : AzureEnvironment.AZURE; + HttpPipeline localPipeline = (pipeline != null) + ? pipeline + : new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(); + Duration localDefaultPollInterval + = (defaultPollInterval != null) ? defaultPollInterval : Duration.ofSeconds(30); + SerializerAdapter localSerializerAdapter = (serializerAdapter != null) + ? serializerAdapter + : SerializerFactory.createDefaultManagementSerializerAdapter(); + ContosoClientImpl client = new ContosoClientImpl(localPipeline, localSerializerAdapter, + localDefaultPollInterval, localEnvironment, localEndpoint, this.subscriptionId); + return client; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientImpl.java new file mode 100644 index 000000000000..457a0fd7c0a9 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ContosoClientImpl.java @@ -0,0 +1,304 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.annotation.ServiceClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.exception.ManagementError; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.AsyncPollResponse; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import com.azure.resourcemanager.contoso.fluent.ContosoClient; +import com.azure.resourcemanager.contoso.fluent.EmployeesClient; +import com.azure.resourcemanager.contoso.fluent.OperationsClient; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the ContosoClientImpl type. + */ +@ServiceClient(builder = ContosoClientBuilder.class) +public final class ContosoClientImpl implements ContosoClient { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Version parameter. + */ + private final String apiVersion; + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + public String getApiVersion() { + return this.apiVersion; + } + + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The OperationsClient object to access its operations. + */ + private final OperationsClient operations; + + /** + * Gets the OperationsClient object to access its operations. + * + * @return the OperationsClient object. + */ + public OperationsClient getOperations() { + return this.operations; + } + + /** + * The EmployeesClient object to access its operations. + */ + private final EmployeesClient employees; + + /** + * Gets the EmployeesClient object to access its operations. + * + * @return the EmployeesClient object. + */ + public EmployeesClient getEmployees() { + return this.employees; + } + + /** + * Initializes an instance of ContosoClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param defaultPollInterval The default poll interval for long-running operation. + * @param environment The Azure environment. + * @param endpoint Service host. + * @param subscriptionId The ID of the target subscription. The value must be an UUID. + */ + ContosoClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, Duration defaultPollInterval, + AzureEnvironment environment, String endpoint, String subscriptionId) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.defaultPollInterval = defaultPollInterval; + this.endpoint = endpoint; + this.subscriptionId = subscriptionId; + this.apiVersion = "2021-11-01"; + this.operations = new OperationsClientImpl(this); + this.employees = new EmployeesClientImpl(this); + } + + /** + * Gets default client context. + * + * @return the default client context. + */ + public Context getContext() { + return Context.NONE; + } + + /** + * Merges default client context with provided context. + * + * @param context the context to be merged with default client context. + * @return the merged context. + */ + public Context mergeContext(Context context) { + return CoreUtils.mergeContexts(this.getContext(), context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param httpPipeline the http pipeline. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return poller flux for poll result and final result. + */ + public PollerFlux, U> getLroResult(Mono>> activationResponse, + HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) { + return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, activationResponse, context); + } + + /** + * Gets the final result, or an error, based on last async poll response. + * + * @param response the last async poll response. + * @param type of poll result. + * @param type of final result. + * @return the final result, or an error. + */ + public Mono getLroFinalResultOrError(AsyncPollResponse, U> response) { + if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) { + String errorMessage; + ManagementError managementError = null; + HttpResponse errorResponse = null; + PollResult.Error lroError = response.getValue().getError(); + if (lroError != null) { + errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(), + lroError.getResponseBody()); + + errorMessage = response.getValue().getError().getMessage(); + String errorBody = response.getValue().getError().getResponseBody(); + if (errorBody != null) { + // try to deserialize error body to ManagementError + try { + managementError = this.getSerializerAdapter() + .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON); + if (managementError.getCode() == null || managementError.getMessage() == null) { + managementError = null; + } + } catch (IOException | RuntimeException ioe) { + LOGGER.logThrowableAsWarning(ioe); + } + } + } else { + // fallback to default error message + errorMessage = "Long running operation failed."; + } + if (managementError == null) { + // fallback to default ManagementError + managementError = new ManagementError(response.getStatus().toString(), errorMessage); + } + return Mono.error(new ManagementException(errorMessage, errorResponse, managementError)); + } else { + return response.getFinalResult(); + } + } + + private static final class HttpResponseImpl extends HttpResponse { + private final int statusCode; + + private final byte[] responseBody; + + private final HttpHeaders httpHeaders; + + HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) { + super(null); + this.statusCode = statusCode; + this.httpHeaders = httpHeaders; + this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8); + } + + public int getStatusCode() { + return statusCode; + } + + public String getHeaderValue(String s) { + return httpHeaders.getValue(HttpHeaderName.fromString(s)); + } + + public HttpHeaders getHeaders() { + return httpHeaders; + } + + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(responseBody)); + } + + public Mono getBodyAsByteArray() { + return Mono.just(responseBody); + } + + public Mono getBodyAsString() { + return Mono.just(new String(responseBody, StandardCharsets.UTF_8)); + } + + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(responseBody, charset)); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ContosoClientImpl.class); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeeImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeeImpl.java new file mode 100644 index 000000000000..3ab5ad2d03b4 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeeImpl.java @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; +import com.azure.resourcemanager.contoso.models.Employee; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.util.Collections; +import java.util.Map; + +public final class EmployeeImpl implements Employee, Employee.Definition, Employee.Update { + private EmployeeInner innerObject; + + private final com.azure.resourcemanager.contoso.ContosoManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public String location() { + return this.innerModel().location(); + } + + public Map tags() { + Map inner = this.innerModel().tags(); + if (inner != null) { + return Collections.unmodifiableMap(inner); + } else { + return Collections.emptyMap(); + } + } + + public EmployeeProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public Region region() { + return Region.fromName(this.regionName()); + } + + public String regionName() { + return this.location(); + } + + public String resourceGroupName() { + return resourceGroupName; + } + + public EmployeeInner innerModel() { + return this.innerObject; + } + + private com.azure.resourcemanager.contoso.ContosoManager manager() { + return this.serviceManager; + } + + private String resourceGroupName; + + private String employeeName; + + public EmployeeImpl withExistingResourceGroup(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + public Employee create() { + this.innerObject = serviceManager.serviceClient() + .getEmployees() + .createOrUpdate(resourceGroupName, employeeName, this.innerModel(), Context.NONE); + return this; + } + + public Employee create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getEmployees() + .createOrUpdate(resourceGroupName, employeeName, this.innerModel(), context); + return this; + } + + EmployeeImpl(String name, com.azure.resourcemanager.contoso.ContosoManager serviceManager) { + this.innerObject = new EmployeeInner(); + this.serviceManager = serviceManager; + this.employeeName = name; + } + + public EmployeeImpl update() { + return this; + } + + public Employee apply() { + this.innerObject = serviceManager.serviceClient() + .getEmployees() + .updateWithResponse(resourceGroupName, employeeName, this.innerModel(), Context.NONE) + .getValue(); + return this; + } + + public Employee apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getEmployees() + .updateWithResponse(resourceGroupName, employeeName, this.innerModel(), context) + .getValue(); + return this; + } + + EmployeeImpl(EmployeeInner innerObject, com.azure.resourcemanager.contoso.ContosoManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.employeeName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "employees"); + } + + public Employee refresh() { + this.innerObject = serviceManager.serviceClient() + .getEmployees() + .getByResourceGroupWithResponse(resourceGroupName, employeeName, Context.NONE) + .getValue(); + return this; + } + + public Employee refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getEmployees() + .getByResourceGroupWithResponse(resourceGroupName, employeeName, context) + .getValue(); + return this; + } + + public EmployeeImpl withRegion(Region location) { + this.innerModel().withLocation(location.toString()); + return this; + } + + public EmployeeImpl withRegion(String location) { + this.innerModel().withLocation(location); + return this; + } + + public EmployeeImpl withTags(Map tags) { + this.innerModel().withTags(tags); + return this; + } + + public EmployeeImpl withProperties(EmployeeProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesClientImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesClientImpl.java new file mode 100644 index 000000000000..1819d6933e4f --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesClientImpl.java @@ -0,0 +1,1176 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.Delete; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Patch; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import com.azure.resourcemanager.contoso.fluent.EmployeesClient; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; +import com.azure.resourcemanager.contoso.implementation.models.EmployeeListResult; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in EmployeesClient. + */ +public final class EmployeesClientImpl implements EmployeesClient { + /** + * The proxy service used to perform REST calls. + */ + private final EmployeesService service; + + /** + * The service client containing this operation class. + */ + private final ContosoClientImpl client; + + /** + * Initializes an instance of EmployeesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + EmployeesClientImpl(ContosoClientImpl client) { + this.service + = RestProxy.create(EmployeesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for ContosoClientEmployees to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ContosoClientEmploye") + public interface EmployeesService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Contoso/employees/{employeeName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("employeeName") String employeeName, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Contoso/employees/{employeeName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("employeeName") String employeeName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") EmployeeInner resource, Context context); + + @Patch("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Contoso/employees/{employeeName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> update(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("employeeName") String employeeName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") EmployeeInner properties, Context context); + + @Headers({ "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Contoso/employees/{employeeName}") + @ExpectedResponses({ 202, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> delete(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("employeeName") String employeeName, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Contoso/employees") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @HeaderParam("Accept") String accept, + Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Contoso/employees") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> list(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByResourceGroupNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listBySubscriptionNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + } + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, + String employeeName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, employeeName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, + String employeeName, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, employeeName, accept, context); + } + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getByResourceGroupAsync(String resourceGroupName, String employeeName) { + return getByResourceGroupWithResponseAsync(resourceGroupName, employeeName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, String employeeName, + Context context) { + return getByResourceGroupWithResponseAsync(resourceGroupName, employeeName, context).block(); + } + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public EmployeeInner getByResourceGroup(String resourceGroupName, String employeeName) { + return getByResourceGroupWithResponse(resourceGroupName, employeeName, Context.NONE).getValue(); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, + String employeeName, EmployeeInner resource) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + if (resource == null) { + return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null.")); + } else { + resource.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, employeeName, contentType, accept, resource, + context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, + String employeeName, EmployeeInner resource, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + if (resource == null) { + return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null.")); + } else { + resource.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, employeeName, contentType, accept, resource, context); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of employee resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, EmployeeInner> beginCreateOrUpdateAsync(String resourceGroupName, + String employeeName, EmployeeInner resource) { + Mono>> mono + = createOrUpdateWithResponseAsync(resourceGroupName, employeeName, resource); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), + EmployeeInner.class, EmployeeInner.class, this.client.getContext()); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of employee resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, EmployeeInner> beginCreateOrUpdateAsync(String resourceGroupName, + String employeeName, EmployeeInner resource, Context context) { + context = this.client.mergeContext(context); + Mono>> mono + = createOrUpdateWithResponseAsync(resourceGroupName, employeeName, resource, context); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), + EmployeeInner.class, EmployeeInner.class, context); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of employee resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, EmployeeInner> beginCreateOrUpdate(String resourceGroupName, + String employeeName, EmployeeInner resource) { + return this.beginCreateOrUpdateAsync(resourceGroupName, employeeName, resource).getSyncPoller(); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of employee resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, EmployeeInner> beginCreateOrUpdate(String resourceGroupName, + String employeeName, EmployeeInner resource, Context context) { + return this.beginCreateOrUpdateAsync(resourceGroupName, employeeName, resource, context).getSyncPoller(); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, String employeeName, + EmployeeInner resource) { + return beginCreateOrUpdateAsync(resourceGroupName, employeeName, resource).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, String employeeName, + EmployeeInner resource, Context context) { + return beginCreateOrUpdateAsync(resourceGroupName, employeeName, resource, context).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public EmployeeInner createOrUpdate(String resourceGroupName, String employeeName, EmployeeInner resource) { + return createOrUpdateAsync(resourceGroupName, employeeName, resource).block(); + } + + /** + * Create a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public EmployeeInner createOrUpdate(String resourceGroupName, String employeeName, EmployeeInner resource, + Context context) { + return createOrUpdateAsync(resourceGroupName, employeeName, resource, context).block(); + } + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> updateWithResponseAsync(String resourceGroupName, String employeeName, + EmployeeInner properties) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + if (properties == null) { + return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null.")); + } else { + properties.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.update(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, employeeName, contentType, accept, properties, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> updateWithResponseAsync(String resourceGroupName, String employeeName, + EmployeeInner properties, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + if (properties == null) { + return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null.")); + } else { + properties.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.update(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + resourceGroupName, employeeName, contentType, accept, properties, context); + } + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono updateAsync(String resourceGroupName, String employeeName, EmployeeInner properties) { + return updateWithResponseAsync(resourceGroupName, employeeName, properties) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response updateWithResponse(String resourceGroupName, String employeeName, + EmployeeInner properties, Context context) { + return updateWithResponseAsync(resourceGroupName, employeeName, properties, context).block(); + } + + /** + * Update a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param properties The resource properties to be updated. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return employee resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public EmployeeInner update(String resourceGroupName, String employeeName, EmployeeInner properties) { + return updateWithResponse(resourceGroupName, employeeName, properties, Context.NONE).getValue(); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> deleteWithResponseAsync(String resourceGroupName, String employeeName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, employeeName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> deleteWithResponseAsync(String resourceGroupName, String employeeName, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + if (employeeName == null) { + return Mono.error(new IllegalArgumentException("Parameter employeeName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.delete(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + resourceGroupName, employeeName, accept, context); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, Void> beginDeleteAsync(String resourceGroupName, String employeeName) { + Mono>> mono = deleteWithResponseAsync(resourceGroupName, employeeName); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, + this.client.getContext()); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, Void> beginDeleteAsync(String resourceGroupName, String employeeName, + Context context) { + context = this.client.mergeContext(context); + Mono>> mono = deleteWithResponseAsync(resourceGroupName, employeeName, context); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, + context); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, Void> beginDelete(String resourceGroupName, String employeeName) { + return this.beginDeleteAsync(resourceGroupName, employeeName).getSyncPoller(); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, Void> beginDelete(String resourceGroupName, String employeeName, + Context context) { + return this.beginDeleteAsync(resourceGroupName, employeeName, context).getSyncPoller(); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono deleteAsync(String resourceGroupName, String employeeName) { + return beginDeleteAsync(resourceGroupName, employeeName).last().flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono deleteAsync(String resourceGroupName, String employeeName, Context context) { + return beginDeleteAsync(resourceGroupName, employeeName, context).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void delete(String resourceGroupName, String employeeName) { + deleteAsync(resourceGroupName, employeeName).block(); + } + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void delete(String resourceGroupName, String employeeName, Context context) { + deleteAsync(resourceGroupName, employeeName, context).block(); + } + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByResourceGroupSinglePageAsync(String resourceGroupName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByResourceGroupSinglePageAsync(String resourceGroupName, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (resourceGroupName == null) { + return Mono + .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service + .listByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByResourceGroupAsync(String resourceGroupName) { + return new PagedFlux<>(() -> listByResourceGroupSinglePageAsync(resourceGroupName), + nextLink -> listByResourceGroupNextSinglePageAsync(nextLink)); + } + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByResourceGroupAsync(String resourceGroupName, Context context) { + return new PagedFlux<>(() -> listByResourceGroupSinglePageAsync(resourceGroupName, context), + nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context)); + } + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByResourceGroup(String resourceGroupName) { + return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName)); + } + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByResourceGroup(String resourceGroupName, Context context) { + return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context)); + } + + /** + * List Employee resources by subscription ID. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync() { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List Employee resources by subscription ID. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync(Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service + .list(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), accept, + context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List Employee resources by subscription ID. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync() { + return new PagedFlux<>(() -> listSinglePageAsync(), + nextLink -> listBySubscriptionNextSinglePageAsync(nextLink)); + } + + /** + * List Employee resources by subscription ID. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync(Context context) { + return new PagedFlux<>(() -> listSinglePageAsync(context), + nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context)); + } + + /** + * List Employee resources by subscription ID. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list() { + return new PagedIterable<>(listAsync()); + } + + /** + * List Employee resources by subscription ID. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(Context context) { + return new PagedIterable<>(listAsync(context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByResourceGroupNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByResourceGroupNextSinglePageAsync(String nextLink, + Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listBySubscriptionNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listBySubscriptionNextSinglePageAsync(String nextLink, Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesImpl.java new file mode 100644 index 000000000000..66f6991ddfb4 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/EmployeesImpl.java @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.contoso.fluent.EmployeesClient; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; +import com.azure.resourcemanager.contoso.models.Employee; +import com.azure.resourcemanager.contoso.models.Employees; + +public final class EmployeesImpl implements Employees { + private static final ClientLogger LOGGER = new ClientLogger(EmployeesImpl.class); + + private final EmployeesClient innerClient; + + private final com.azure.resourcemanager.contoso.ContosoManager serviceManager; + + public EmployeesImpl(EmployeesClient innerClient, com.azure.resourcemanager.contoso.ContosoManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, String employeeName, + Context context) { + Response inner + = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, employeeName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new EmployeeImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public Employee getByResourceGroup(String resourceGroupName, String employeeName) { + EmployeeInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, employeeName); + if (inner != null) { + return new EmployeeImpl(inner, this.manager()); + } else { + return null; + } + } + + public void deleteByResourceGroup(String resourceGroupName, String employeeName) { + this.serviceClient().delete(resourceGroupName, employeeName); + } + + public void delete(String resourceGroupName, String employeeName, Context context) { + this.serviceClient().delete(resourceGroupName, employeeName, context); + } + + public PagedIterable listByResourceGroup(String resourceGroupName) { + PagedIterable inner = this.serviceClient().listByResourceGroup(resourceGroupName); + return ResourceManagerUtils.mapPage(inner, inner1 -> new EmployeeImpl(inner1, this.manager())); + } + + public PagedIterable listByResourceGroup(String resourceGroupName, Context context) { + PagedIterable inner = this.serviceClient().listByResourceGroup(resourceGroupName, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new EmployeeImpl(inner1, this.manager())); + } + + public PagedIterable list() { + PagedIterable inner = this.serviceClient().list(); + return ResourceManagerUtils.mapPage(inner, inner1 -> new EmployeeImpl(inner1, this.manager())); + } + + public PagedIterable list(Context context) { + PagedIterable inner = this.serviceClient().list(context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new EmployeeImpl(inner1, this.manager())); + } + + public Employee getById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String employeeName = ResourceManagerUtils.getValueFromIdByName(id, "employees"); + if (employeeName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'employees'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, employeeName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String employeeName = ResourceManagerUtils.getValueFromIdByName(id, "employees"); + if (employeeName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'employees'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, employeeName, context); + } + + public void deleteById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String employeeName = ResourceManagerUtils.getValueFromIdByName(id, "employees"); + if (employeeName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'employees'.", id))); + } + this.delete(resourceGroupName, employeeName, Context.NONE); + } + + public void deleteByIdWithResponse(String id, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String employeeName = ResourceManagerUtils.getValueFromIdByName(id, "employees"); + if (employeeName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'employees'.", id))); + } + this.delete(resourceGroupName, employeeName, context); + } + + private EmployeesClient serviceClient() { + return this.innerClient; + } + + private com.azure.resourcemanager.contoso.ContosoManager manager() { + return this.serviceManager; + } + + public EmployeeImpl define(String name) { + return new EmployeeImpl(name, this.manager()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationImpl.java new file mode 100644 index 000000000000..3d6991b7373d --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationImpl.java @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; +import com.azure.resourcemanager.contoso.models.ActionType; +import com.azure.resourcemanager.contoso.models.Operation; +import com.azure.resourcemanager.contoso.models.OperationDisplay; +import com.azure.resourcemanager.contoso.models.Origin; + +public final class OperationImpl implements Operation { + private OperationInner innerObject; + + private final com.azure.resourcemanager.contoso.ContosoManager serviceManager; + + OperationImpl(OperationInner innerObject, com.azure.resourcemanager.contoso.ContosoManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + } + + public String name() { + return this.innerModel().name(); + } + + public Boolean isDataAction() { + return this.innerModel().isDataAction(); + } + + public OperationDisplay display() { + return this.innerModel().display(); + } + + public Origin origin() { + return this.innerModel().origin(); + } + + public ActionType actionType() { + return this.innerModel().actionType(); + } + + public OperationInner innerModel() { + return this.innerObject; + } + + private com.azure.resourcemanager.contoso.ContosoManager manager() { + return this.serviceManager; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsClientImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsClientImpl.java new file mode 100644 index 000000000000..eb035cbea3ad --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsClientImpl.java @@ -0,0 +1,235 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.resourcemanager.contoso.fluent.OperationsClient; +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; +import com.azure.resourcemanager.contoso.implementation.models.OperationListResult; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in OperationsClient. + */ +public final class OperationsClientImpl implements OperationsClient { + /** + * The proxy service used to perform REST calls. + */ + private final OperationsService service; + + /** + * The service client containing this operation class. + */ + private final ContosoClientImpl client; + + /** + * Initializes an instance of OperationsClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + OperationsClientImpl(ContosoClientImpl client) { + this.service + = RestProxy.create(OperationsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for ContosoClientOperations to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ContosoClientOperati") + public interface OperationsService { + @Headers({ "Content-Type: application/json" }) + @Get("/providers/Microsoft.Contoso/operations") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> list(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context); + } + + /** + * List the operations for the provider. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync() { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync(Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List the operations for the provider. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync() { + return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink)); + } + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync(Context context) { + return new PagedFlux<>(() -> listSinglePageAsync(context), + nextLink -> listNextSinglePageAsync(nextLink, context)); + } + + /** + * List the operations for the provider. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list() { + return new PagedIterable<>(listAsync()); + } + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(Context context) { + return new PagedIterable<>(listAsync(context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listNextSinglePageAsync(String nextLink, Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsImpl.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsImpl.java new file mode 100644 index 000000000000..e42b30f4ffad --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/OperationsImpl.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.contoso.fluent.OperationsClient; +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; +import com.azure.resourcemanager.contoso.models.Operation; +import com.azure.resourcemanager.contoso.models.Operations; + +public final class OperationsImpl implements Operations { + private static final ClientLogger LOGGER = new ClientLogger(OperationsImpl.class); + + private final OperationsClient innerClient; + + private final com.azure.resourcemanager.contoso.ContosoManager serviceManager; + + public OperationsImpl(OperationsClient innerClient, + com.azure.resourcemanager.contoso.ContosoManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public PagedIterable list() { + PagedIterable inner = this.serviceClient().list(); + return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager())); + } + + public PagedIterable list(Context context) { + PagedIterable inner = this.serviceClient().list(context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager())); + } + + private OperationsClient serviceClient() { + return this.innerClient; + } + + private com.azure.resourcemanager.contoso.ContosoManager manager() { + return this.serviceManager; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ResourceManagerUtils.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ResourceManagerUtils.java new file mode 100644 index 000000000000..cf0d8b505d86 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/ResourceManagerUtils.java @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation; + +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.util.CoreUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import reactor.core.publisher.Flux; + +final class ResourceManagerUtils { + private ResourceManagerUtils() { + } + + static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterator itr = Arrays.stream(id.split("/")).iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && !part.trim().isEmpty()) { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + static String getValueFromIdByParameterName(String id, String pathTemplate, String parameterName) { + if (id == null || pathTemplate == null) { + return null; + } + String parameterNameParentheses = "{" + parameterName + "}"; + List idSegmentsReverted = Arrays.asList(id.split("/")); + List pathSegments = Arrays.asList(pathTemplate.split("/")); + Collections.reverse(idSegmentsReverted); + Iterator idItrReverted = idSegmentsReverted.iterator(); + int pathIndex = pathSegments.size(); + while (idItrReverted.hasNext() && pathIndex > 0) { + String idSegment = idItrReverted.next(); + String pathSegment = pathSegments.get(--pathIndex); + if (!CoreUtils.isNullOrEmpty(idSegment) && !CoreUtils.isNullOrEmpty(pathSegment)) { + if (pathSegment.equalsIgnoreCase(parameterNameParentheses)) { + if (pathIndex == 0 || (pathIndex == 1 && pathSegments.get(0).isEmpty())) { + List segments = new ArrayList<>(); + segments.add(idSegment); + idItrReverted.forEachRemaining(segments::add); + Collections.reverse(segments); + if (!segments.isEmpty() && segments.get(0).isEmpty()) { + segments.remove(0); + } + return String.join("/", segments); + } else { + return idSegment; + } + } + } + } + return null; + } + + static PagedIterable mapPage(PagedIterable pageIterable, Function mapper) { + return new PagedIterableImpl<>(pageIterable, mapper); + } + + private static final class PagedIterableImpl extends PagedIterable { + + private final PagedIterable pagedIterable; + private final Function mapper; + private final Function, PagedResponse> pageMapper; + + private PagedIterableImpl(PagedIterable pagedIterable, Function mapper) { + super(PagedFlux.create(() -> (continuationToken, pageSize) -> Flux + .fromStream(pagedIterable.streamByPage().map(getPageMapper(mapper))))); + this.pagedIterable = pagedIterable; + this.mapper = mapper; + this.pageMapper = getPageMapper(mapper); + } + + private static Function, PagedResponse> getPageMapper(Function mapper) { + return page -> new PagedResponseBase(page.getRequest(), page.getStatusCode(), page.getHeaders(), + page.getElements().stream().map(mapper).collect(Collectors.toList()), page.getContinuationToken(), + null); + } + + @Override + public Stream stream() { + return pagedIterable.stream().map(mapper); + } + + @Override + public Stream> streamByPage() { + return pagedIterable.streamByPage().map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken) { + return pagedIterable.streamByPage(continuationToken).map(pageMapper); + } + + @Override + public Stream> streamByPage(int preferredPageSize) { + return pagedIterable.streamByPage(preferredPageSize).map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken, int preferredPageSize) { + return pagedIterable.streamByPage(continuationToken, preferredPageSize).map(pageMapper); + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(pagedIterable.iterator(), mapper); + } + + @Override + public Iterable> iterableByPage() { + return new IterableImpl<>(pagedIterable.iterableByPage(), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken), pageMapper); + } + + @Override + public Iterable> iterableByPage(int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(preferredPageSize), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken, int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken, preferredPageSize), pageMapper); + } + } + + private static final class IteratorImpl implements Iterator { + + private final Iterator iterator; + private final Function mapper; + + private IteratorImpl(Iterator iterator, Function mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public S next() { + return mapper.apply(iterator.next()); + } + + @Override + public void remove() { + iterator.remove(); + } + } + + private static final class IterableImpl implements Iterable { + + private final Iterable iterable; + private final Function mapper; + + private IterableImpl(Iterable iterable, Function mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(iterable.iterator(), mapper); + } + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/EmployeeListResult.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/EmployeeListResult.java new file mode 100644 index 000000000000..6ccdb5f7b4ac --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/EmployeeListResult.java @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation.models; + +import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; +import java.io.IOException; +import java.util.List; + +/** + * The response of a Employee list operation. + */ +@Immutable +public final class EmployeeListResult implements JsonSerializable { + /* + * The Employee items on this page + */ + private List value; + + /* + * The link to the next page of items + */ + private String nextLink; + + /** + * Creates an instance of EmployeeListResult class. + */ + private EmployeeListResult() { + } + + /** + * Get the value property: The Employee items on this page. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: The link to the next page of items. + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (value() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException("Missing required property value in model EmployeeListResult")); + } else { + value().forEach(e -> e.validate()); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(EmployeeListResult.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("nextLink", this.nextLink); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmployeeListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmployeeListResult if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the EmployeeListResult. + */ + public static EmployeeListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + EmployeeListResult deserializedEmployeeListResult = new EmployeeListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> EmployeeInner.fromJson(reader1)); + deserializedEmployeeListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedEmployeeListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedEmployeeListResult; + }); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/OperationListResult.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/OperationListResult.java new file mode 100644 index 000000000000..9abf95fa18e2 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/models/OperationListResult.java @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.implementation.models; + +import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; +import java.io.IOException; +import java.util.List; + +/** + * A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of + * results. + */ +@Immutable +public final class OperationListResult implements JsonSerializable { + /* + * The Operation items on this page + */ + private List value; + + /* + * The link to the next page of items + */ + private String nextLink; + + /** + * Creates an instance of OperationListResult class. + */ + private OperationListResult() { + } + + /** + * Get the value property: The Operation items on this page. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: The link to the next page of items. + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (value() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException("Missing required property value in model OperationListResult")); + } else { + value().forEach(e -> e.validate()); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(OperationListResult.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("nextLink", this.nextLink); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationListResult if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the OperationListResult. + */ + public static OperationListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationListResult deserializedOperationListResult = new OperationListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> OperationInner.fromJson(reader1)); + deserializedOperationListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedOperationListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationListResult; + }); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/package-info.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/package-info.java new file mode 100644 index 000000000000..30291625ebfe --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the implementations for Contoso. + * Microsoft.Contoso Resource Provider management API. + */ +package com.azure.resourcemanager.contoso.implementation; diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ActionType.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ActionType.java new file mode 100644 index 000000000000..e530f4e3e499 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ActionType.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ +public final class ActionType extends ExpandableStringEnum { + /** + * Actions are for internal-only APIs. + */ + public static final ActionType INTERNAL = fromString("Internal"); + + /** + * Creates a new instance of ActionType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ActionType() { + } + + /** + * Creates or finds a ActionType from its string representation. + * + * @param name a name to look for. + * @return the corresponding ActionType. + */ + public static ActionType fromString(String name) { + return fromString(name, ActionType.class); + } + + /** + * Gets known ActionType values. + * + * @return known ActionType values. + */ + public static Collection values() { + return values(ActionType.class); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employee.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employee.java new file mode 100644 index 000000000000..d318c31e7516 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employee.java @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; +import java.util.Map; + +/** + * An immutable client-side representation of Employee. + */ +public interface Employee { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the location property: The geo-location where the resource lives. + * + * @return the location value. + */ + String location(); + + /** + * Gets the tags property: Resource tags. + * + * @return the tags value. + */ + Map tags(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + EmployeeProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the region of the resource. + * + * @return the region of the resource. + */ + Region region(); + + /** + * Gets the name of the resource region. + * + * @return the name of the resource region. + */ + String regionName(); + + /** + * Gets the name of the resource group. + * + * @return the name of the resource group. + */ + String resourceGroupName(); + + /** + * Gets the inner com.azure.resourcemanager.contoso.fluent.models.EmployeeInner object. + * + * @return the inner object. + */ + EmployeeInner innerModel(); + + /** + * The entirety of the Employee definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithLocation, + DefinitionStages.WithResourceGroup, DefinitionStages.WithCreate { + } + + /** + * The Employee definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the Employee definition. + */ + interface Blank extends WithLocation { + } + + /** + * The stage of the Employee definition allowing to specify location. + */ + interface WithLocation { + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(Region location); + + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(String location); + } + + /** + * The stage of the Employee definition allowing to specify parent resource. + */ + interface WithResourceGroup { + /** + * Specifies resourceGroupName. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @return the next definition stage. + */ + WithCreate withExistingResourceGroup(String resourceGroupName); + } + + /** + * The stage of the Employee definition which contains all the minimum required properties for the resource to + * be created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithProperties { + /** + * Executes the create request. + * + * @return the created resource. + */ + Employee create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + Employee create(Context context); + } + + /** + * The stage of the Employee definition allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + WithCreate withTags(Map tags); + } + + /** + * The stage of the Employee definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(EmployeeProperties properties); + } + } + + /** + * Begins update for the Employee resource. + * + * @return the stage of resource update. + */ + Employee.Update update(); + + /** + * The template for Employee update. + */ + interface Update extends UpdateStages.WithTags, UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + Employee apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + Employee apply(Context context); + } + + /** + * The Employee update stages. + */ + interface UpdateStages { + /** + * The stage of the Employee update allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + Update withTags(Map tags); + } + + /** + * The stage of the Employee update allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + Update withProperties(EmployeeProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + Employee refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + Employee refresh(Context context); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/EmployeeProperties.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/EmployeeProperties.java new file mode 100644 index 000000000000..0f97946865ad --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/EmployeeProperties.java @@ -0,0 +1,178 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.util.Base64Url; +import com.azure.core.util.CoreUtils; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.Objects; + +/** + * Employee properties. + */ +@Fluent +public final class EmployeeProperties implements JsonSerializable { + private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + + /* + * Age of employee + */ + private Integer age; + + /* + * City of employee + */ + private String city; + + /* + * Profile of employee + */ + private Base64Url profile; + + /* + * The status of the last operation. + */ + private ProvisioningState provisioningState; + + /** + * Creates an instance of EmployeeProperties class. + */ + public EmployeeProperties() { + } + + /** + * Get the age property: Age of employee. + * + * @return the age value. + */ + public Integer age() { + return this.age; + } + + /** + * Set the age property: Age of employee. + * + * @param age the age value to set. + * @return the EmployeeProperties object itself. + */ + public EmployeeProperties withAge(Integer age) { + this.age = age; + return this; + } + + /** + * Get the city property: City of employee. + * + * @return the city value. + */ + public String city() { + return this.city; + } + + /** + * Set the city property: City of employee. + * + * @param city the city value to set. + * @return the EmployeeProperties object itself. + */ + public EmployeeProperties withCity(String city) { + this.city = city; + return this; + } + + /** + * Get the profile property: Profile of employee. + * + * @return the profile value. + */ + public byte[] profile() { + if (this.profile == null) { + return EMPTY_BYTE_ARRAY; + } + return this.profile.decodedBytes(); + } + + /** + * Set the profile property: Profile of employee. + * + * @param profile the profile value to set. + * @return the EmployeeProperties object itself. + */ + public EmployeeProperties withProfile(byte[] profile) { + if (profile == null) { + this.profile = null; + } else { + this.profile = Base64Url.encode(CoreUtils.clone(profile)); + } + return this; + } + + /** + * Get the provisioningState property: The status of the last operation. + * + * @return the provisioningState value. + */ + public ProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeNumberField("age", this.age); + jsonWriter.writeStringField("city", this.city); + jsonWriter.writeStringField("profile", Objects.toString(this.profile, null)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmployeeProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmployeeProperties if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the EmployeeProperties. + */ + public static EmployeeProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + EmployeeProperties deserializedEmployeeProperties = new EmployeeProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("age".equals(fieldName)) { + deserializedEmployeeProperties.age = reader.getNullable(JsonReader::getInt); + } else if ("city".equals(fieldName)) { + deserializedEmployeeProperties.city = reader.getString(); + } else if ("profile".equals(fieldName)) { + deserializedEmployeeProperties.profile + = reader.getNullable(nonNullReader -> new Base64Url(nonNullReader.getString())); + } else if ("provisioningState".equals(fieldName)) { + deserializedEmployeeProperties.provisioningState = ProvisioningState.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedEmployeeProperties; + }); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employees.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employees.java new file mode 100644 index 000000000000..1c4bb94aa861 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Employees.java @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of Employees. + */ +public interface Employees { + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, String employeeName, Context context); + + /** + * Get a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee. + */ + Employee getByResourceGroup(String resourceGroupName, String employeeName); + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteByResourceGroup(String resourceGroupName, String employeeName); + + /** + * Delete a Employee. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param employeeName The name of the Employee. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void delete(String resourceGroupName, String employeeName, Context context); + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByResourceGroup(String resourceGroupName); + + /** + * List Employee resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByResourceGroup(String resourceGroupName, Context context); + + /** + * List Employee resources by subscription ID. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable list(); + + /** + * List Employee resources by subscription ID. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a Employee list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable list(Context context); + + /** + * Get a Employee. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response}. + */ + Employee getById(String id); + + /** + * Get a Employee. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Employee along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Delete a Employee. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteById(String id); + + /** + * Delete a Employee. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new Employee resource. + * + * @param name resource name. + * @return the first stage of the new Employee definition. + */ + Employee.DefinitionStages.Blank define(String name); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operation.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operation.java new file mode 100644 index 000000000000..1feeb6644812 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operation.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; + +/** + * An immutable client-side representation of Operation. + */ +public interface Operation { + /** + * Gets the name property: The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + * + * @return the name value. + */ + String name(); + + /** + * Gets the isDataAction property: Whether the operation applies to data-plane. This is "true" for data-plane + * operations and "false" for Azure Resource Manager/control-plane operations. + * + * @return the isDataAction value. + */ + Boolean isDataAction(); + + /** + * Gets the display property: Localized display information for this particular operation. + * + * @return the display value. + */ + OperationDisplay display(); + + /** + * Gets the origin property: The intended executor of the operation; as in Resource Based Access Control (RBAC) and + * audit logs UX. Default value is "user,system". + * + * @return the origin value. + */ + Origin origin(); + + /** + * Gets the actionType property: Extensible enum. Indicates the action type. "Internal" refers to actions that are + * for internal only APIs. + * + * @return the actionType value. + */ + ActionType actionType(); + + /** + * Gets the inner com.azure.resourcemanager.contoso.fluent.models.OperationInner object. + * + * @return the inner object. + */ + OperationInner innerModel(); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/OperationDisplay.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/OperationDisplay.java new file mode 100644 index 000000000000..e9a903626966 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/OperationDisplay.java @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Localized display information for and operation. + */ +@Immutable +public final class OperationDisplay implements JsonSerializable { + /* + * The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or + * "Microsoft Compute". + */ + private String provider; + + /* + * The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or + * "Job Schedule Collections". + */ + private String resource; + + /* + * The concise, localized friendly name for the operation; suitable for dropdowns. E.g. + * "Create or Update Virtual Machine", "Restart Virtual Machine". + */ + private String operation; + + /* + * The short, localized friendly description of the operation; suitable for tool tips and detailed views. + */ + private String description; + + /** + * Creates an instance of OperationDisplay class. + */ + private OperationDisplay() { + } + + /** + * Get the provider property: The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring + * Insights" or "Microsoft Compute". + * + * @return the provider value. + */ + public String provider() { + return this.provider; + } + + /** + * Get the resource property: The localized friendly name of the resource type related to this operation. E.g. + * "Virtual Machines" or "Job Schedule Collections". + * + * @return the resource value. + */ + public String resource() { + return this.resource; + } + + /** + * Get the operation property: The concise, localized friendly name for the operation; suitable for dropdowns. E.g. + * "Create or Update Virtual Machine", "Restart Virtual Machine". + * + * @return the operation value. + */ + public String operation() { + return this.operation; + } + + /** + * Get the description property: The short, localized friendly description of the operation; suitable for tool tips + * and detailed views. + * + * @return the description value. + */ + public String description() { + return this.description; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationDisplay from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationDisplay if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the OperationDisplay. + */ + public static OperationDisplay fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationDisplay deserializedOperationDisplay = new OperationDisplay(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provider".equals(fieldName)) { + deserializedOperationDisplay.provider = reader.getString(); + } else if ("resource".equals(fieldName)) { + deserializedOperationDisplay.resource = reader.getString(); + } else if ("operation".equals(fieldName)) { + deserializedOperationDisplay.operation = reader.getString(); + } else if ("description".equals(fieldName)) { + deserializedOperationDisplay.description = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationDisplay; + }); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operations.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operations.java new file mode 100644 index 000000000000..6c8810ae2d2a --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Operations.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; + +/** + * Resource collection API of Operations. + */ +public interface Operations { + /** + * List the operations for the provider. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + PagedIterable list(); + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + PagedIterable list(Context context); +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Origin.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Origin.java new file mode 100644 index 000000000000..1fb5dcd14f20 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/Origin.java @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value + * is "user,system". + */ +public final class Origin extends ExpandableStringEnum { + /** + * Indicates the operation is initiated by a user. + */ + public static final Origin USER = fromString("user"); + + /** + * Indicates the operation is initiated by a system. + */ + public static final Origin SYSTEM = fromString("system"); + + /** + * Indicates the operation is initiated by a user or system. + */ + public static final Origin USER_SYSTEM = fromString("user,system"); + + /** + * Creates a new instance of Origin value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public Origin() { + } + + /** + * Creates or finds a Origin from its string representation. + * + * @param name a name to look for. + * @return the corresponding Origin. + */ + public static Origin fromString(String name) { + return fromString(name, Origin.class); + } + + /** + * Gets known Origin values. + * + * @return known Origin values. + */ + public static Collection values() { + return values(Origin.class); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ProvisioningState.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ProvisioningState.java new file mode 100644 index 000000000000..d570e69afca7 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/ProvisioningState.java @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The resource provisioning state. + */ +public final class ProvisioningState extends ExpandableStringEnum { + /** + * Resource has been created. + */ + public static final ProvisioningState SUCCEEDED = fromString("Succeeded"); + + /** + * Resource creation failed. + */ + public static final ProvisioningState FAILED = fromString("Failed"); + + /** + * Resource creation was canceled. + */ + public static final ProvisioningState CANCELED = fromString("Canceled"); + + /** + * The resource is being provisioned. + */ + public static final ProvisioningState PROVISIONING = fromString("Provisioning"); + + /** + * The resource is updating. + */ + public static final ProvisioningState UPDATING = fromString("Updating"); + + /** + * The resource is being deleted. + */ + public static final ProvisioningState DELETING = fromString("Deleting"); + + /** + * The resource create request has been accepted. + */ + public static final ProvisioningState ACCEPTED = fromString("Accepted"); + + /** + * Creates a new instance of ProvisioningState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ProvisioningState() { + } + + /** + * Creates or finds a ProvisioningState from its string representation. + * + * @param name a name to look for. + * @return the corresponding ProvisioningState. + */ + public static ProvisioningState fromString(String name) { + return fromString(name, ProvisioningState.class); + } + + /** + * Gets known ProvisioningState values. + * + * @return known ProvisioningState values. + */ + public static Collection values() { + return values(ProvisioningState.class); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/package-info.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/package-info.java new file mode 100644 index 000000000000..25f209c96c74 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the data models for Contoso. + * Microsoft.Contoso Resource Provider management API. + */ +package com.azure.resourcemanager.contoso.models; diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/package-info.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/package-info.java new file mode 100644 index 000000000000..cfcdcc12fb15 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/com/azure/resourcemanager/contoso/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the classes for Contoso. + * Microsoft.Contoso Resource Provider management API. + */ +package com.azure.resourcemanager.contoso; diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/java/module-info.java b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/module-info.java new file mode 100644 index 000000000000..35ea3ffa7c78 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/java/module-info.java @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +module com.azure.resourcemanager.contoso { + requires transitive com.azure.core.management; + + exports com.azure.resourcemanager.contoso; + exports com.azure.resourcemanager.contoso.fluent; + exports com.azure.resourcemanager.contoso.fluent.models; + exports com.azure.resourcemanager.contoso.models; + + opens com.azure.resourcemanager.contoso.fluent.models to com.azure.core; + opens com.azure.resourcemanager.contoso.models to com.azure.core; + opens com.azure.resourcemanager.contoso.implementation.models to com.azure.core; +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/proxy-config.json b/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/proxy-config.json new file mode 100644 index 000000000000..a410d025dc8e --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/proxy-config.json @@ -0,0 +1 @@ +[["com.azure.resourcemanager.contoso.implementation.EmployeesClientImpl$EmployeesService"],["com.azure.resourcemanager.contoso.implementation.OperationsClientImpl$OperationsService"]] \ No newline at end of file diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/reflect-config.json b/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/reflect-config.json new file mode 100644 index 000000000000..0637a088a01e --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-contoso/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/azure-resourcemanager-contoso.properties b/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/azure-resourcemanager-contoso.properties new file mode 100644 index 000000000000..defbd48204e4 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/main/resources/azure-resourcemanager-contoso.properties @@ -0,0 +1 @@ +version=${project.version} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateSamples.java new file mode 100644 index 000000000000..8fba1881f732 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateSamples.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.util.HashMap; +import java.util.Map; + +/** + * Samples for Employees CreateOrUpdate. + */ +public final class EmployeesCreateOrUpdateSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_CreateOrUpdate.json + */ + /** + * Sample code: Employees_CreateOrUpdate. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesCreateOrUpdate(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees() + .define("9KF-f-8b") + .withRegion("itajgxyqozseoygnl") + .withExistingResourceGroup("rgopenapi") + .withTags(mapOf("key2913", "fakeTokenPlaceholder")) + .withProperties(new EmployeeProperties().withAge(30) + .withCity("gydhnntudughbmxlkyzrskcdkotrxn") + .withProfile("ms".getBytes())) + .create(); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesDeleteSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesDeleteSamples.java new file mode 100644 index 000000000000..24554452b13d --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesDeleteSamples.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +/** + * Samples for Employees Delete. + */ +public final class EmployeesDeleteSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_Delete.json + */ + /** + * Sample code: Employees_Delete. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesDelete(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees().delete("rgopenapi", "5vX--BxSu3ux48rI4O9OQ569", com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupSamples.java new file mode 100644 index 000000000000..ba525bb5650a --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupSamples.java @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +/** + * Samples for Employees GetByResourceGroup. + */ +public final class EmployeesGetByResourceGroupSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_Get.json + */ + /** + * Sample code: Employees_Get. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesGet(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees() + .getByResourceGroupWithResponse("rgopenapi", "le-8MU--J3W6q8D386p3-iT3", com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupSamples.java new file mode 100644 index 000000000000..b7df8d932b39 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupSamples.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +/** + * Samples for Employees ListByResourceGroup. + */ +public final class EmployeesListByResourceGroupSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_ListByResourceGroup.json + */ + /** + * Sample code: Employees_ListByResourceGroup. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesListByResourceGroup(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees().listByResourceGroup("rgopenapi", com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListSamples.java new file mode 100644 index 000000000000..d6977978e6b1 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesListSamples.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +/** + * Samples for Employees List. + */ +public final class EmployeesListSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_ListBySubscription.json + */ + /** + * Sample code: Employees_ListBySubscription. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesListBySubscription(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.employees().list(com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesUpdateSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesUpdateSamples.java new file mode 100644 index 000000000000..014ceade25f0 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/EmployeesUpdateSamples.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.resourcemanager.contoso.models.Employee; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.util.HashMap; +import java.util.Map; + +/** + * Samples for Employees Update. + */ +public final class EmployeesUpdateSamples { + /* + * x-ms-original-file: 2021-11-01/Employees_Update.json + */ + /** + * Sample code: Employees_Update. + * + * @param manager Entry point to ContosoManager. + */ + public static void employeesUpdate(com.azure.resourcemanager.contoso.ContosoManager manager) { + Employee resource = manager.employees() + .getByResourceGroupWithResponse("rgopenapi", "-XhyNJ--", com.azure.core.util.Context.NONE) + .getValue(); + resource.update() + .withTags(mapOf("key7952", "fakeTokenPlaceholder")) + .withProperties( + new EmployeeProperties().withAge(24).withCity("uyfg").withProfile("oapgijcswfkruiuuzbwco".getBytes())) + .apply(); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/OperationsListSamples.java b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/OperationsListSamples.java new file mode 100644 index 000000000000..c8b9843c2411 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/samples/java/com/azure/resourcemanager/contoso/generated/OperationsListSamples.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +/** + * Samples for Operations List. + */ +public final class OperationsListSamples { + /* + * x-ms-original-file: 2021-11-01/Operations_List.json + */ + /** + * Sample code: Operations_List. + * + * @param manager Entry point to ContosoManager. + */ + public static void operationsList(com.azure.resourcemanager.contoso.ContosoManager manager) { + manager.operations().list(com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeInnerTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeInnerTests.java new file mode 100644 index 000000000000..95f9cacc4c07 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeInnerTests.java @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.util.BinaryData; +import com.azure.resourcemanager.contoso.fluent.models.EmployeeInner; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class EmployeeInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + EmployeeInner model = BinaryData.fromString( + "{\"properties\":{\"age\":1273684509,\"city\":\"pzvgnwzsymglzufc\",\"provisioningState\":\"Succeeded\"},\"location\":\"dbihanufhfcbj\",\"tags\":{\"xqhabi\":\"git\"},\"id\":\"pikxwczbyscnpqxu\",\"name\":\"ivyqniwbybrkxvd\",\"type\":\"mjgr\"}") + .toObject(EmployeeInner.class); + Assertions.assertEquals("dbihanufhfcbj", model.location()); + Assertions.assertEquals("git", model.tags().get("xqhabi")); + Assertions.assertEquals(1273684509, model.properties().age()); + Assertions.assertEquals("pzvgnwzsymglzufc", model.properties().city()); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + EmployeeInner model = new EmployeeInner().withLocation("dbihanufhfcbj") + .withTags(mapOf("xqhabi", "git")) + .withProperties(new EmployeeProperties().withAge(1273684509).withCity("pzvgnwzsymglzufc")); + model = BinaryData.fromObject(model).toObject(EmployeeInner.class); + Assertions.assertEquals("dbihanufhfcbj", model.location()); + Assertions.assertEquals("git", model.tags().get("xqhabi")); + Assertions.assertEquals(1273684509, model.properties().age()); + Assertions.assertEquals("pzvgnwzsymglzufc", model.properties().city()); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeListResultTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeListResultTests.java new file mode 100644 index 000000000000..b343ace4f525 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeeListResultTests.java @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.util.BinaryData; +import com.azure.resourcemanager.contoso.implementation.models.EmployeeListResult; +import org.junit.jupiter.api.Assertions; + +public final class EmployeeListResultTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + EmployeeListResult model = BinaryData.fromString( + "{\"value\":[{\"properties\":{\"age\":2045600331,\"city\":\"yejhk\",\"provisioningState\":\"Failed\"},\"location\":\"apcz\",\"tags\":{\"ni\":\"kjyemkk\",\"ilzyd\":\"joxzjnchgejspodm\"},\"id\":\"h\",\"name\":\"jwyahuxinpmqnja\",\"type\":\"wixjsprozvcp\"}],\"nextLink\":\"eg\"}") + .toObject(EmployeeListResult.class); + Assertions.assertEquals("apcz", model.value().get(0).location()); + Assertions.assertEquals("kjyemkk", model.value().get(0).tags().get("ni")); + Assertions.assertEquals(2045600331, model.value().get(0).properties().age()); + Assertions.assertEquals("yejhk", model.value().get(0).properties().city()); + Assertions.assertEquals("eg", model.nextLink()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeePropertiesTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeePropertiesTests.java new file mode 100644 index 000000000000..3b0057cbd219 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeePropertiesTests.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.util.BinaryData; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import org.junit.jupiter.api.Assertions; + +public final class EmployeePropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + EmployeeProperties model + = BinaryData.fromString("{\"age\":1126091678,\"city\":\"ukxgaud\",\"provisioningState\":\"Updating\"}") + .toObject(EmployeeProperties.class); + Assertions.assertEquals(1126091678, model.age()); + Assertions.assertEquals("ukxgaud", model.city()); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + EmployeeProperties model = new EmployeeProperties().withAge(1126091678).withCity("ukxgaud"); + model = BinaryData.fromObject(model).toObject(EmployeeProperties.class); + Assertions.assertEquals(1126091678, model.age()); + Assertions.assertEquals("ukxgaud", model.city()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateMockTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateMockTests.java new file mode 100644 index 000000000000..d2287d3052f1 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesCreateOrUpdateMockTests.java @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpClient; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.models.AzureCloud; +import com.azure.core.test.http.MockHttpResponse; +import com.azure.resourcemanager.contoso.ContosoManager; +import com.azure.resourcemanager.contoso.models.Employee; +import com.azure.resourcemanager.contoso.models.EmployeeProperties; +import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +public final class EmployeesCreateOrUpdateMockTests { + @Test + public void testCreateOrUpdate() throws Exception { + String responseStr + = "{\"properties\":{\"age\":1677515825,\"city\":\"ytb\",\"provisioningState\":\"Succeeded\"},\"location\":\"uflmm\",\"tags\":{\"b\":\"smodmgloug\"},\"id\":\"wtmutduq\",\"name\":\"ta\",\"type\":\"spwgcuertumkdosv\"}"; + + HttpClient httpClient + = response -> Mono.just(new MockHttpResponse(response, 200, responseStr.getBytes(StandardCharsets.UTF_8))); + ContosoManager manager = ContosoManager.configure() + .withHttpClient(httpClient) + .authenticate(tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)), + new AzureProfile("", "", AzureCloud.AZURE_PUBLIC_CLOUD)); + + Employee response = manager.employees() + .define("zdatqxhocdg") + .withRegion("kao") + .withExistingResourceGroup("nhutjeltmrldhugj") + .withTags(mapOf("tyhxhurokft", "i", "iawxklry", "xolniwpwcukjfk", "cbacphejkotynqg", "lwckbasyypnddhs")) + .withProperties(new EmployeeProperties().withAge(1293628182).withCity("phut")) + .create(); + + Assertions.assertEquals("uflmm", response.location()); + Assertions.assertEquals("smodmgloug", response.tags().get("b")); + Assertions.assertEquals(1677515825, response.properties().age()); + Assertions.assertEquals("ytb", response.properties().city()); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupWithResponseMockTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupWithResponseMockTests.java new file mode 100644 index 000000000000..789083f2e302 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesGetByResourceGroupWithResponseMockTests.java @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpClient; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.models.AzureCloud; +import com.azure.core.test.http.MockHttpResponse; +import com.azure.resourcemanager.contoso.ContosoManager; +import com.azure.resourcemanager.contoso.models.Employee; +import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +public final class EmployeesGetByResourceGroupWithResponseMockTests { + @Test + public void testGetByResourceGroupWithResponse() throws Exception { + String responseStr + = "{\"properties\":{\"age\":413609639,\"city\":\"dphlxaolt\",\"provisioningState\":\"Canceled\"},\"location\":\"qjbpfzfsin\",\"tags\":{\"jrwzox\":\"f\"},\"id\":\"j\",\"name\":\"felluwfzitonpe\",\"type\":\"fpjkjlxofp\"}"; + + HttpClient httpClient + = response -> Mono.just(new MockHttpResponse(response, 200, responseStr.getBytes(StandardCharsets.UTF_8))); + ContosoManager manager = ContosoManager.configure() + .withHttpClient(httpClient) + .authenticate(tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)), + new AzureProfile("", "", AzureCloud.AZURE_PUBLIC_CLOUD)); + + Employee response = manager.employees() + .getByResourceGroupWithResponse("ffdfdosygexpa", "jakhmsbzjh", com.azure.core.util.Context.NONE) + .getValue(); + + Assertions.assertEquals("qjbpfzfsin", response.location()); + Assertions.assertEquals("f", response.tags().get("jrwzox")); + Assertions.assertEquals(413609639, response.properties().age()); + Assertions.assertEquals("dphlxaolt", response.properties().city()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupMockTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupMockTests.java new file mode 100644 index 000000000000..c8ca6fcb8116 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListByResourceGroupMockTests.java @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpClient; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.models.AzureCloud; +import com.azure.core.test.http.MockHttpResponse; +import com.azure.resourcemanager.contoso.ContosoManager; +import com.azure.resourcemanager.contoso.models.Employee; +import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +public final class EmployeesListByResourceGroupMockTests { + @Test + public void testListByResourceGroup() throws Exception { + String responseStr + = "{\"value\":[{\"properties\":{\"age\":2045160621,\"city\":\"kpode\",\"provisioningState\":\"Accepted\"},\"location\":\"nuvamiheogna\",\"tags\":{\"o\":\"xth\",\"cciqihnhungbwjz\":\"usivye\",\"kufubljo\":\"nfygxgispemvtz\",\"v\":\"xqeofjaeqjhqjba\"},\"id\":\"smjqulngsntnbyb\",\"name\":\"zgcwrw\",\"type\":\"lxxwrljdouskc\"}]}"; + + HttpClient httpClient + = response -> Mono.just(new MockHttpResponse(response, 200, responseStr.getBytes(StandardCharsets.UTF_8))); + ContosoManager manager = ContosoManager.configure() + .withHttpClient(httpClient) + .authenticate(tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)), + new AzureProfile("", "", AzureCloud.AZURE_PUBLIC_CLOUD)); + + PagedIterable response + = manager.employees().listByResourceGroup("vhpfxxypininmay", com.azure.core.util.Context.NONE); + + Assertions.assertEquals("nuvamiheogna", response.iterator().next().location()); + Assertions.assertEquals("xth", response.iterator().next().tags().get("o")); + Assertions.assertEquals(2045160621, response.iterator().next().properties().age()); + Assertions.assertEquals("kpode", response.iterator().next().properties().city()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListMockTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListMockTests.java new file mode 100644 index 000000000000..1e3f1af418ef --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/EmployeesListMockTests.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpClient; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.models.AzureCloud; +import com.azure.core.test.http.MockHttpResponse; +import com.azure.resourcemanager.contoso.ContosoManager; +import com.azure.resourcemanager.contoso.models.Employee; +import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +public final class EmployeesListMockTests { + @Test + public void testList() throws Exception { + String responseStr + = "{\"value\":[{\"properties\":{\"age\":1685957957,\"city\":\"rcjd\",\"provisioningState\":\"Accepted\"},\"location\":\"xbnjbiksq\",\"tags\":{\"fmppe\":\"ssainqpjwnzll\",\"c\":\"bvmgxsabkyqduuji\"},\"id\":\"czdzev\",\"name\":\"dhkrwpdappdsbdk\",\"type\":\"wrwjfeu\"}]}"; + + HttpClient httpClient + = response -> Mono.just(new MockHttpResponse(response, 200, responseStr.getBytes(StandardCharsets.UTF_8))); + ContosoManager manager = ContosoManager.configure() + .withHttpClient(httpClient) + .authenticate(tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)), + new AzureProfile("", "", AzureCloud.AZURE_PUBLIC_CLOUD)); + + PagedIterable response = manager.employees().list(com.azure.core.util.Context.NONE); + + Assertions.assertEquals("xbnjbiksq", response.iterator().next().location()); + Assertions.assertEquals("ssainqpjwnzll", response.iterator().next().tags().get("fmppe")); + Assertions.assertEquals(1685957957, response.iterator().next().properties().age()); + Assertions.assertEquals("rcjd", response.iterator().next().properties().city()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationDisplayTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationDisplayTests.java new file mode 100644 index 000000000000..2081c64f15c6 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationDisplayTests.java @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.util.BinaryData; +import com.azure.resourcemanager.contoso.models.OperationDisplay; + +public final class OperationDisplayTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + OperationDisplay model = BinaryData.fromString( + "{\"provider\":\"cdm\",\"resource\":\"rcryuanzwuxzdxta\",\"operation\":\"lhmwhfpmrqobm\",\"description\":\"kknryrtihf\"}") + .toObject(OperationDisplay.class); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationInnerTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationInnerTests.java new file mode 100644 index 000000000000..d637b4aec300 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationInnerTests.java @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.util.BinaryData; +import com.azure.resourcemanager.contoso.fluent.models.OperationInner; + +public final class OperationInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + OperationInner model = BinaryData.fromString( + "{\"name\":\"nygj\",\"isDataAction\":true,\"display\":{\"provider\":\"eqsrdeupewnwreit\",\"resource\":\"yflusarhmofc\",\"operation\":\"smy\",\"description\":\"kdtmlxhekuk\"},\"origin\":\"user,system\",\"actionType\":\"Internal\"}") + .toObject(OperationInner.class); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationListResultTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationListResultTests.java new file mode 100644 index 000000000000..8d46e49375e0 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationListResultTests.java @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.util.BinaryData; +import com.azure.resourcemanager.contoso.implementation.models.OperationListResult; +import org.junit.jupiter.api.Assertions; + +public final class OperationListResultTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + OperationListResult model = BinaryData.fromString( + "{\"value\":[{\"name\":\"hq\",\"isDataAction\":true,\"display\":{\"provider\":\"pybczmehmtzopb\",\"resource\":\"h\",\"operation\":\"pidgsybbejhphoyc\",\"description\":\"xaobhdxbmtqioqjz\"},\"origin\":\"system\",\"actionType\":\"Internal\"},{\"name\":\"fpownoizhwlr\",\"isDataAction\":false,\"display\":{\"provider\":\"oqijgkdmbpaz\",\"resource\":\"bc\",\"operation\":\"pdznrbtcqqjnqgl\",\"description\":\"gnufoooj\"},\"origin\":\"system\",\"actionType\":\"Internal\"},{\"name\":\"esaagdfm\",\"isDataAction\":true,\"display\":{\"provider\":\"j\",\"resource\":\"ifkwmrvktsizntoc\",\"operation\":\"a\",\"description\":\"ajpsquc\"},\"origin\":\"system\",\"actionType\":\"Internal\"}],\"nextLink\":\"kfo\"}") + .toObject(OperationListResult.class); + Assertions.assertEquals("kfo", model.nextLink()); + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationsListMockTests.java b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationsListMockTests.java new file mode 100644 index 000000000000..727433313467 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/src/test/java/com/azure/resourcemanager/contoso/generated/OperationsListMockTests.java @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.resourcemanager.contoso.generated; + +import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpClient; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.models.AzureCloud; +import com.azure.core.test.http.MockHttpResponse; +import com.azure.resourcemanager.contoso.ContosoManager; +import com.azure.resourcemanager.contoso.models.Operation; +import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +public final class OperationsListMockTests { + @Test + public void testList() throws Exception { + String responseStr + = "{\"value\":[{\"name\":\"wmfdatscmdvpjhul\",\"isDataAction\":false,\"display\":{\"provider\":\"kjozkrwfnd\",\"resource\":\"djpslw\",\"operation\":\"dpvwryoqpsoaccta\",\"description\":\"kljla\"},\"origin\":\"user\",\"actionType\":\"Internal\"}]}"; + + HttpClient httpClient + = response -> Mono.just(new MockHttpResponse(response, 200, responseStr.getBytes(StandardCharsets.UTF_8))); + ContosoManager manager = ContosoManager.configure() + .withHttpClient(httpClient) + .authenticate(tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)), + new AzureProfile("", "", AzureCloud.AZURE_PUBLIC_CLOUD)); + + PagedIterable response = manager.operations().list(com.azure.core.util.Context.NONE); + + } +} diff --git a/sdk/contoso/azure-resourcemanager-contoso/tsp-location.yaml b/sdk/contoso/azure-resourcemanager-contoso/tsp-location.yaml new file mode 100644 index 000000000000..aaa0259477d8 --- /dev/null +++ b/sdk/contoso/azure-resourcemanager-contoso/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/contosowidgetmanager/Contoso.Management +commit: 3649dc32eda8644bc7af6833d281dbc0b1606f98 +repo: Azure/azure-rest-api-specs +additionalDirectories: diff --git a/sdk/contoso/ci.yml b/sdk/contoso/ci.yml new file mode 100644 index 000000000000..73561dc32b79 --- /dev/null +++ b/sdk/contoso/ci.yml @@ -0,0 +1,46 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: + branches: + include: + - main + - hotfix/* + - release/* + paths: + include: + - sdk/contoso/ci.yml + - sdk/contoso/azure-resourcemanager-contoso/ + exclude: + - sdk/contoso/pom.xml + - sdk/contoso/azure-resourcemanager-contoso/pom.xml + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/contoso/ci.yml + - sdk/contoso/azure-resourcemanager-contoso/ + exclude: + - sdk/contoso/pom.xml + - sdk/contoso/azure-resourcemanager-contoso/pom.xml + +parameters: + - name: release_azureresourcemanagercontoso + displayName: azure-resourcemanager-contoso + type: boolean + default: false + +extends: + template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: contoso + Artifacts: + - name: azure-resourcemanager-contoso + groupId: com.azure.resourcemanager + safeName: azureresourcemanagercontoso + releaseInBatch: ${{ parameters.release_azureresourcemanagercontoso }} diff --git a/sdk/contoso/pom.xml b/sdk/contoso/pom.xml new file mode 100644 index 000000000000..4dd511abe080 --- /dev/null +++ b/sdk/contoso/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + com.azure + azure-contoso-service + pom + 1.0.0 + + + azure-resourcemanager-contoso + +