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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 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,7 @@ 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
custom-types-subpackage: models
#custom-types:
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImpl;
import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImplBuilder;
import com.azure.digitaltwins.core.implementation.converters.ModelDataConverter;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinModelsListOptions;
import com.azure.digitaltwins.core.implementation.models.IncomingRelationship;
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.util.DigitalTwinsResponse;
import com.azure.digitaltwins.core.util.DigitalTwinsResponseHeaders;
import com.azure.digitaltwins.core.util.ListModelOptions;
Expand Down Expand Up @@ -53,7 +53,7 @@ public final class DigitalTwinsAsyncClient {
private static final ObjectMapper mapper = new ObjectMapper();
private final DigitalTwinsServiceVersion serviceVersion;
private final AzureDigitalTwinsAPIImpl protocolLayer;
private static final Boolean includeModelDefinition = true;
private static final Boolean includeModelDefinitionOnGet = true;

DigitalTwinsAsyncClient(HttpPipeline pipeline, DigitalTwinsServiceVersion serviceVersion, String host) {
final SimpleModule stringModule = new SimpleModule("String Serializer");
Expand Down Expand Up @@ -777,13 +777,20 @@ 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<ModelData> convertedList = objectPagedResponse.getValue().stream()
.map(ModelDataConverter::map)
.filter(Objects::nonNull)
.collect(Collectors.toList());
return new PagedResponseBase<>(
objectPagedResponse.getRequest(),
objectPagedResponse.getStatusCode(),
objectPagedResponse.getHeaders(),
convertedList,
null,
((PagedResponseBase) objectPagedResponse).getDeserializedHeaders());
}
);
}

/**
Expand All @@ -810,7 +817,15 @@ public Mono<Response<ModelData>> getModelWithResponse(String modelId) {
Mono<Response<ModelData>> getModelWithResponse(String modelId, Context context){
return protocolLayer
.getDigitalTwinModels()
.getByIdWithResponseAsync(modelId, includeModelDefinition, context);
.getByIdWithResponseAsync(modelId, includeModelDefinitionOnGet, context)
.map(response -> {
com.azure.digitaltwins.core.implementation.models.ModelData modelData = response.getValue();
return new SimpleResponse<>(
response.getRequest(),
response.getStatusCode(),
response.getHeaders(),
ModelDataConverter.map(modelData));
});
}

/**
Expand Down Expand Up @@ -851,11 +866,39 @@ Mono<PagedResponse<ModelData>> listModelsSinglePageAsync(ListModelOptions listMo
listModelOptions.getDependenciesFor(),
listModelOptions.getIncludeModelDefinition(),
new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount()),
context);
context)
.map(
objectPagedResponse -> {
List<ModelData> convertedList = objectPagedResponse.getValue().stream()
.map(ModelDataConverter::map)
.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);
return protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink, context)
.map(objectPagedResponse -> {
List<ModelData> convertedList = objectPagedResponse.getValue().stream()
.map(ModelDataConverter::map)
.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 @@ -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
@@ -0,0 +1,38 @@
package com.azure.digitaltwins.core.implementation.converters;

import com.azure.digitaltwins.core.models.ModelData;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* A converter between {@link com.azure.digitaltwins.core.implementation.models.ModelData} and
* {@link ModelData}.
*/
public final class ModelDataConverter {

/**
* Maps from {@link com.azure.digitaltwins.core.implementation.models.ModelData} to
* {@link ModelData}.
*/
public static ModelData map(com.azure.digitaltwins.core.implementation.models.ModelData input) {
String modelStringValue = null;

if (input.getModel() != null){
try {
modelStringValue = new ObjectMapper().writeValueAsString(input.getModel());
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("ModelData does not have a valid model definition.", e);
}
}

return new ModelData()
.setId(input.getId())
.setUploadTime(input.getUploadTime())
.setDisplayName(input.getDisplayName())
.setDescription(input.getDescription())
.setDecommissioned(input.isDecommissioned())
.setModel(modelStringValue);
}

private ModelDataConverter() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

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

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.OffsetDateTime;
import java.util.Map;

/** The ModelData model. */
@Fluent
public final class ModelData {
/*
* A language map that contains the localized display names as specified in
* the model definition.
*/
@JsonProperty(value = "displayName")
private Map<String, String> displayName;

/*
* A language map that contains the localized descriptions as specified in
* the model definition.
*/
@JsonProperty(value = "description")
private Map<String, String> description;

/*
* The id of the model as specified in the model definition.
*/
@JsonProperty(value = "id", required = true)
private String id;

/*
* The time the model was uploaded to the service.
*/
@JsonProperty(value = "uploadTime")
private OffsetDateTime uploadTime;

/*
* Indicates if the model is decommissioned. Decommissioned models cannot
* be referenced by newly created digital twins.
*/
@JsonProperty(value = "decommissioned")
private Boolean decommissioned;

/*
* The model definition.
*/
@JsonProperty(value = "model")
private Object model;

/**
* Get the displayName property: A language map that contains the localized display names as specified in the model
* definition.
*
* @return the displayName value.
*/
public Map<String, String> getDisplayName() {
return this.displayName;
}

/**
* Set the displayName property: A language map that contains the localized display names as specified in the model
* definition.
*
* @param displayName the displayName value to set.
* @return the ModelData object itself.
*/
public ModelData setDisplayName(Map<String, String> displayName) {
this.displayName = displayName;
return this;
}

/**
* Get the description property: A language map that contains the localized descriptions as specified in the model
* definition.
*
* @return the description value.
*/
public Map<String, String> getDescription() {
return this.description;
}

/**
* Set the description property: A language map that contains the localized descriptions as specified in the model
* definition.
*
* @param description the description value to set.
* @return the ModelData object itself.
*/
public ModelData setDescription(Map<String, String> description) {
this.description = description;
return this;
}

/**
* Get the id property: The id of the model as specified in the model definition.
*
* @return the id value.
*/
public String getId() {
return this.id;
}

/**
* Set the id property: The id of the model as specified in the model definition.
*
* @param id the id value to set.
* @return the ModelData object itself.
*/
public ModelData setId(String id) {
this.id = id;
return this;
}

/**
* Get the uploadTime property: The time the model was uploaded to the service.
*
* @return the uploadTime value.
*/
public OffsetDateTime getUploadTime() {
return this.uploadTime;
}

/**
* Set the uploadTime property: The time the model was uploaded to the service.
*
* @param uploadTime the uploadTime value to set.
* @return the ModelData object itself.
*/
public ModelData setUploadTime(OffsetDateTime uploadTime) {
this.uploadTime = uploadTime;
return this;
}

/**
* Get the decommissioned property: Indicates if the model is decommissioned. Decommissioned models cannot be
* referenced by newly created digital twins.
*
* @return the decommissioned value.
*/
public Boolean isDecommissioned() {
return this.decommissioned;
}

/**
* Set the decommissioned property: Indicates if the model is decommissioned. Decommissioned models cannot be
* referenced by newly created digital twins.
*
* @param decommissioned the decommissioned value to set.
* @return the ModelData object itself.
*/
public ModelData setDecommissioned(Boolean decommissioned) {
this.decommissioned = decommissioned;
return this;
}

/**
* Get the model property: The model definition.
*
* @return the model value.
*/
public Object getModel() {
return this.model;
}

/**
* Set the model property: The model definition.
*
* @param model the model value to set.
* @return the ModelData object itself.
*/
public ModelData setModel(Object model) {
this.model = model;
return this;
}
}
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