Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ModelData.model to String #14702

Merged
merged 11 commits into from
Sep 2, 2020
Merged
2 changes: 0 additions & 2 deletions sdk/digitaltwins/azure-digitaltwins-core/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ java:
generate-client-as-impl: true
implementation-subpackage: implementation
models-subpackage: implementation.models
custom-types-subpackage: models
custom-types: ModelData
context-client-method-parameter: true
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImplBuilder;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinModelsListOptions;
import com.azure.digitaltwins.core.implementation.models.IncomingRelationship;
import com.azure.digitaltwins.core.implementation.models.ModelData;
import com.azure.digitaltwins.core.implementation.serializer.DigitalTwinsStringSerializer;
import com.azure.digitaltwins.core.models.ModelData;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetComponentResponse;
import com.azure.digitaltwins.core.models.DigitalTwinModelData;
import com.azure.digitaltwins.core.models.ModelConverter;
import com.azure.digitaltwins.core.util.DigitalTwinsResponse;
import com.azure.digitaltwins.core.util.DigitalTwinsResponseHeaders;
import com.azure.digitaltwins.core.util.ListModelOptions;
Expand Down Expand Up @@ -750,19 +752,19 @@ PagedFlux<IncomingRelationship> listIncomingRelationships(String digitalTwinId,
* @return A {@link PagedFlux} of created models and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<ModelData> createModels(List<String> models) {
public PagedFlux<DigitalTwinModelData> createModels(List<String> models) {
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
return new PagedFlux<>(
() -> withContext(context -> createModelsSinglePageAsync(models, context)),
nextLink -> withContext(context -> Mono.empty()));
}

PagedFlux<ModelData> createModels(List<String> models, Context context){
PagedFlux<DigitalTwinModelData> createModels(List<String> models, Context context){
return new PagedFlux<>(
() -> createModelsSinglePageAsync(models, context),
nextLink -> Mono.empty());
}

Mono<PagedResponse<ModelData>> createModelsSinglePageAsync(List<String> models, Context context)
Mono<PagedResponse<DigitalTwinModelData>> createModelsSinglePageAsync(List<String> models, Context context)
{
List<Object> modelsPayload = new ArrayList<>();
for (String model: models) {
Expand All @@ -777,13 +779,26 @@ Mono<PagedResponse<ModelData>> createModelsSinglePageAsync(List<String> models,

return protocolLayer.getDigitalTwinModels().addWithResponseAsync(modelsPayload, context)
.map(
listResponse -> new PagedResponseBase<>(
listResponse.getRequest(),
listResponse.getStatusCode(),
listResponse.getHeaders(),
listResponse.getValue(),
null,
((ResponseBase)listResponse).getDeserializedHeaders()));
objectPagedResponse -> {
List<DigitalTwinModelData> convertedList = objectPagedResponse.getValue().stream()
.map(object -> ModelConverter.convertToDigitalTwinModelData(
object.getId(),
object.getModel(),
object.getUploadTime(),
object.getDescription(),
object.getDisplayName(),
object.isDecommissioned()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
return new PagedResponseBase<>(
objectPagedResponse.getRequest(),
objectPagedResponse.getStatusCode(),
objectPagedResponse.getHeaders(),
convertedList,
null,
((PagedResponseBase) objectPagedResponse).getDeserializedHeaders());
}
);
}

/**
Expand All @@ -792,7 +807,7 @@ Mono<PagedResponse<ModelData>> createModelsSinglePageAsync(List<String> models,
* @return The ModelData
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<ModelData> getModel(String modelId) {
public Mono<DigitalTwinModelData> getModel(String modelId) {
return getModelWithResponse(modelId)
.map(Response::getValue);
}
Expand All @@ -803,14 +818,28 @@ public Mono<ModelData> getModel(String modelId) {
* @return The ModelData and the http response
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<ModelData>> getModelWithResponse(String modelId) {
public Mono<Response<DigitalTwinModelData>> getModelWithResponse(String modelId) {
return withContext(context -> getModelWithResponse(modelId, context));
}

Mono<Response<ModelData>> getModelWithResponse(String modelId, Context context){
Mono<Response<DigitalTwinModelData>> getModelWithResponse(String modelId, Context context){
return protocolLayer
.getDigitalTwinModels()
.getByIdWithResponseAsync(modelId, includeModelDefinition, context);
.getByIdWithResponseAsync(modelId, includeModelDefinition, context)
.map(response -> {
ModelData modelData = response.getValue();
return new SimpleResponse<>(
response.getRequest(),
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
response.getStatusCode(),
response.getHeaders(),
ModelConverter.convertToDigitalTwinModelData(
modelData.getId(),
modelData.getModel(),
modelData.getUploadTime(),
modelData.getDescription(),
modelData.getDisplayName(),
modelData.isDecommissioned()));
});
}

/**
Expand All @@ -819,7 +848,7 @@ Mono<Response<ModelData>> getModelWithResponse(String modelId, Context context){
* @return A {@link PagedFlux} of ModelData and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<ModelData> listModels(ListModelOptions listModelOptions) {
public PagedFlux<DigitalTwinModelData> listModels(ListModelOptions listModelOptions) {
return new PagedFlux<>(
() -> withContext(context -> listModelsSinglePageAsync(listModelOptions, context)),
nextLink -> withContext(context -> listModelsNextSinglePageAsync(nextLink, context)));
Expand All @@ -830,32 +859,73 @@ public PagedFlux<ModelData> listModels(ListModelOptions listModelOptions) {
* @return A {@link PagedFlux} of ModelData and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<ModelData> listModels() {
public PagedFlux<DigitalTwinModelData> listModels() {
return listModels(new ListModelOptions());
}

PagedFlux<ModelData> listModels(Context context){
PagedFlux<DigitalTwinModelData> listModels(Context context){
return new PagedFlux<>(
() -> listModelsSinglePageAsync(new ListModelOptions(), context),
nextLink -> listModelsNextSinglePageAsync(nextLink, context));
}

PagedFlux<ModelData> listModels(ListModelOptions listModelOptions, Context context){
PagedFlux<DigitalTwinModelData> listModels(ListModelOptions listModelOptions, Context context){
return new PagedFlux<>(
() -> listModelsSinglePageAsync(listModelOptions, context),
nextLink -> listModelsNextSinglePageAsync(nextLink, context));
}

Mono<PagedResponse<ModelData>> listModelsSinglePageAsync(ListModelOptions listModelOptions, Context context){
Mono<PagedResponse<DigitalTwinModelData>> listModelsSinglePageAsync(ListModelOptions listModelOptions, Context context){
return protocolLayer.getDigitalTwinModels().listSinglePageAsync(
listModelOptions.getDependenciesFor(),
listModelOptions.getIncludeModelDefinition(),
new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount()),
context);
context)
.map(
objectPagedResponse -> {
List<DigitalTwinModelData> convertedList = objectPagedResponse.getValue().stream()
.map(object -> ModelConverter.convertToDigitalTwinModelData(
object.getId(),
object.getModel(),
object.getUploadTime(),
object.getDescription(),
object.getDisplayName(),
object.isDecommissioned()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
return new PagedResponseBase<>(
objectPagedResponse.getRequest(),
objectPagedResponse.getStatusCode(),
objectPagedResponse.getHeaders(),
convertedList,
null,
((PagedResponseBase) objectPagedResponse).getDeserializedHeaders());
}
);
}

Mono<PagedResponse<ModelData>> listModelsNextSinglePageAsync(String nextLink, Context context){
return protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink, context);
Mono<PagedResponse<DigitalTwinModelData>> listModelsNextSinglePageAsync(String nextLink, Context context){
return protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink, context)
.map(objectPagedResponse -> {
List<DigitalTwinModelData> convertedList = objectPagedResponse.getValue().stream()
.map(object ->
ModelConverter.convertToDigitalTwinModelData(
object.getId(),
object.getModel(),
object.getUploadTime(),
object.getDescription(),
object.getDisplayName(),
object.isDecommissioned()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
return new PagedResponseBase<>(
objectPagedResponse.getRequest(),
objectPagedResponse.getStatusCode(),
objectPagedResponse.getHeaders(),
convertedList,
objectPagedResponse.getContinuationToken(),
((PagedResponseBase)objectPagedResponse).getDeserializedHeaders());
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.digitaltwins.core.implementation.models.IncomingRelationship;
import com.azure.digitaltwins.core.models.ModelData;
import com.azure.digitaltwins.core.implementation.models.ModelData;
import com.azure.digitaltwins.core.models.DigitalTwinModelData;
import com.azure.digitaltwins.core.util.DigitalTwinsResponse;
import com.azure.digitaltwins.core.util.ListModelOptions;

Expand Down Expand Up @@ -461,7 +462,7 @@ public PagedIterable<IncomingRelationship> listIncomingRelationships(String digi
* @return A {@link PagedIterable} of created models and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<ModelData> createModels(List<String> models, Context context) {
public PagedIterable<DigitalTwinModelData> createModels(List<String> models, Context context) {
return new PagedIterable<>(digitalTwinsAsyncClient.createModels(models, context));
}

Expand All @@ -471,7 +472,7 @@ public PagedIterable<ModelData> createModels(List<String> models, Context contex
* @return The ModelData
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ModelData getModel(String modelId) {
public DigitalTwinModelData getModel(String modelId) {
return digitalTwinsAsyncClient.getModel(modelId).block();
}

Expand All @@ -482,7 +483,7 @@ public ModelData getModel(String modelId) {
* @return The ModelData and the http response
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<ModelData> getModelWithResponse(String modelId, Context context) {
public Response<DigitalTwinModelData> getModelWithResponse(String modelId, Context context) {
return digitalTwinsAsyncClient.getModelWithResponse(modelId, context).block();
}

Expand All @@ -493,7 +494,7 @@ public Response<ModelData> getModelWithResponse(String modelId, Context context)
* @return A {@link PagedIterable} of ModelData and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<ModelData> listModels(ListModelOptions listModelOptions, Context context) {
public PagedIterable<DigitalTwinModelData> listModels(ListModelOptions listModelOptions, Context context) {
return new PagedIterable<>(
digitalTwinsAsyncClient.listModels(listModelOptions, context));
}
Expand All @@ -503,7 +504,7 @@ public PagedIterable<ModelData> listModels(ListModelOptions listModelOptions, Co
* @return A {@link PagedFlux} of ModelData and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<ModelData> listModels() {
public PagedIterable<DigitalTwinModelData> listModels() {
return new PagedIterable<>(digitalTwinsAsyncClient.listModels());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinModelsListOptions;
import com.azure.digitaltwins.core.implementation.models.ErrorResponseException;
import com.azure.digitaltwins.core.implementation.models.ModelData;
import com.azure.digitaltwins.core.implementation.models.PagedModelDataCollection;
import com.azure.digitaltwins.core.models.ModelData;
import java.util.List;
import reactor.core.publisher.Mono;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.digitaltwins.core.models;
package com.azure.digitaltwins.core.implementation.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.azure.digitaltwins.core.implementation.models;

import com.azure.core.annotation.Fluent;
import com.azure.digitaltwins.core.models.ModelData;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

Expand Down
Loading