diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwin.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwin.java index 898e2036a0814..ccc78d7eb8d2d 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwin.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwin.java @@ -31,10 +31,10 @@ public final class BasicDigitalTwin { private String twinETag; @JsonProperty(value = DigitalTwinsJsonPropertyNames.DIGITAL_TWIN_METADATA, required = true) - private DigitalTwinMetadata metadata; + private BasicDigitalTwinMetadata metadata; @JsonIgnore - private final Map properties = new HashMap<>(); + private final Map contents = new HashMap<>(); /** * Construct a basic digital twin. @@ -69,7 +69,7 @@ public String getEtag() { * @param twinETag A string representing a weak ETag for the entity that this request performs an operation against, as per RFC7232. * @return The BasicDigitalTwin object itself. */ - public BasicDigitalTwin setDigitalTwinEtag(String twinETag) { + public BasicDigitalTwin setEtag(String twinETag) { this.twinETag = twinETag; return this; } @@ -78,7 +78,7 @@ public BasicDigitalTwin setDigitalTwinEtag(String twinETag) { * Gets the information about the model a digital twin conforms to. This field is present on every digital twin. * @return The information about the model a digital twin conforms to. This field is present on every digital twin. */ - public DigitalTwinMetadata getMetadata() { + public BasicDigitalTwinMetadata getMetadata() { return metadata; } @@ -87,29 +87,30 @@ public DigitalTwinMetadata getMetadata() { * @param metadata The information about the model a digital twin conforms to. This field is present on every digital twin. * @return The BasicDigitalTwin object itself. */ - public BasicDigitalTwin setMetadata(DigitalTwinMetadata metadata) { + public BasicDigitalTwin setMetadata(BasicDigitalTwinMetadata metadata) { this.metadata = metadata; return this; } /** - * Gets the additional custom properties of the digital twin. This field will contain any properties of the digital twin that are not already defined by the other strong types of this class. - * @return The additional properties of the digital twin. This field will contain any properties of the digital twin that are not already defined by the other strong types of this class. + * Gets the additional custom contents of the digital twin. This field will contain any contents of the digital twin that are not already defined by the other strong types of this class. + * @return The additional contents of the digital twin. This field will contain any contents of the digital twin that are not already defined by the other strong types of this class. */ @JsonAnyGetter - public Map getProperties() { - return properties; + public Map getContents() { + return contents; } /** - * Adds an additional custom property to the digital twin. This field will contain any properties of the digital twin that are not already defined by the other strong types of this class. + * Adds an additional custom property to the digital twin contents. This field will contain any contents of the + * digital twin that are not already defined by the other strong types of this class. * @param key The key of the additional property to be added to the digital twin. * @param value The value of the additional property to be added to the digital twin. * @return The BasicDigitalTwin object itself. */ @JsonAnySetter - public BasicDigitalTwin addProperty(String key, Object value) { - this.properties.put(key, value); + public BasicDigitalTwin addToContents(String key, Object value) { + this.contents.put(key, value); return this; } } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/ModelProperties.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinComponent.java similarity index 51% rename from sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/ModelProperties.java rename to sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinComponent.java index 8e4eeef92cfc9..33efa9e88cd7c 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/ModelProperties.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinComponent.java @@ -14,56 +14,56 @@ */ @Fluent @JsonInclude(JsonInclude.Include.NON_NULL) -public final class ModelProperties { +public final class BasicDigitalTwinComponent { /** * Information about the model a component conforms to. This field is present on every digital twin. */ @JsonProperty(value = "$metadata", required = true) - private ComponentMetadata metadata = new ComponentMetadata(); + private BasicDigitalTwinComponentMetadata metadata = new BasicDigitalTwinComponentMetadata(); /** - * The additional properties of the model. This field will contain any properties of the digital twin that are not already defined by the other strong types of this class. + * The additional contents of the model. This field will contain any contents of the digital twin that are not already defined by the other strong types of this class. */ @JsonIgnore - private final Map properties = new HashMap<>(); + private final Map contents = new HashMap<>(); /** * Gets the metadata about the model. * @return The model metadata. */ - public ComponentMetadata getMetadata() { + public BasicDigitalTwinComponentMetadata getMetadata() { return metadata; } /** * Sets the model metadata. * @param metadata Model metadata. - * @return The ModelProperties object itself. + * @return The BasicDigitalTwinComponent object itself. */ - public ModelProperties setMetadata(ComponentMetadata metadata) { + public BasicDigitalTwinComponent setMetadata(BasicDigitalTwinComponentMetadata metadata) { this.metadata = metadata; return this; } /** - * Gets the custom properties - * @return The custom properties + * Gets the custom contents + * @return The custom contents */ @JsonAnyGetter - public Map getProperties() { - return properties; + public Map getContents() { + return contents; } /** - * Adds additional custom properties to the model. - * @param key The key of the additional property to be added to the model. - * @param value The value of the additional property to be added to the model. - * @return The ModelProperties object itself. + * Adds additional custom property to the component's contents. + * @param key The key of the additional property to be added to the component's contents. + * @param value The value of the additional property to be added to the component's contents. + * @return The BasicDigitalTwinComponent object itself. */ @JsonAnySetter - public ModelProperties addProperty(String key, Object value) { - this.properties.put(key, value); + public BasicDigitalTwinComponent addToContents(String key, Object value) { + this.contents.put(key, value); return this; } } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinComponentMetadata.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinComponentMetadata.java new file mode 100644 index 0000000000000..fae2f71cd51fa --- /dev/null +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinComponentMetadata.java @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.digitaltwins.core.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.HashMap; +import java.util.Map; + +/** + * An optional, helper class for deserializing a digital twin component metadata object. This corresponds to the + * {@link DigitalTwinsJsonPropertyNames#DIGITAL_TWIN_METADATA} property object on a {@link BasicDigitalTwinComponent} + *

+ * Note that this class uses {@link JsonProperty} from the Jackson serialization library. Because of this, this type + * will only work if the default json serializer is used by the digital twins client or if the custom json + * serializer uses Jackson as well. In order to use a different json library, a new BasicDigitalTwinComponentMetadata class must + * be constructed and have its json propertyMetadata tagged by the annotation used by that json library. + */ +@Fluent +@JsonInclude(JsonInclude.Include.NON_NULL) +public final class BasicDigitalTwinComponentMetadata { + @JsonIgnore + private final Map propertyMetadata = new HashMap<>(); + + /** + * Gets the metadata about changes on properties on a component. The values can be deserialized into {@link BasicDigitalTwinPropertyMetadata} + * @return The metadata about changes on properties on a component. + */ + @JsonAnyGetter + public Map getPropertyMetadata() { + return propertyMetadata; + } + + /** + * Adds an additional custom property to the digital twin component. This field will contain any property + * of the digital twin component that is not already defined by the other strong types of this class. + * @param key The key of the additional property to be added to the digital twin. + * @param value The value of the additional property to be added to the digital twin. + * @return The BasicDigitalTwin object itself. + */ + @JsonAnySetter + public BasicDigitalTwinComponentMetadata addPropertyMetadata(String key, Object value) { + this.propertyMetadata.put(key, value); + return this; + } +} diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinMetadata.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinMetadata.java similarity index 59% rename from sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinMetadata.java rename to sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinMetadata.java index be2b8f4b050e6..04e634378b3b2 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinMetadata.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinMetadata.java @@ -18,18 +18,18 @@ */ @Fluent @JsonInclude(Include.NON_NULL) -public final class DigitalTwinMetadata { +public final class BasicDigitalTwinMetadata { @JsonProperty(value = DigitalTwinsJsonPropertyNames.METADATA_MODEL, required = true) private String modelId; @JsonIgnore - private final Map writableProperties = new HashMap<>(); + private final Map propertyMetadata = new HashMap<>(); /** * Creates an instance of digital twin metadata. */ - public DigitalTwinMetadata() { + public BasicDigitalTwinMetadata() { } /** @@ -43,32 +43,32 @@ public String getModelId() { /** * Sets the Id of the model that the digital twin or component is modeled by. * @param modelId The Id of the model that the digital twin or component is modeled by. - * @return The DigitalTwinMetadata object itself. + * @return The BasicDigitalTwinMetadata object itself. */ - public DigitalTwinMetadata setModelId(String modelId) { + public BasicDigitalTwinMetadata setModelId(String modelId) { this.modelId = modelId; return this; } /** - * Gets the model-defined writable properties' request state. - * For your convenience, the value of each map can be turned into an instance of {@link WritableProperty}. - * @return The model-defined writable properties' request state. + * Gets the metadata about changes on properties on a component. The values can be deserialized into {@link BasicDigitalTwinPropertyMetadata} + * @return The metadata about changes on properties on a component. */ @JsonAnyGetter - public Map getWritableProperties() { - return writableProperties; + public Map getPropertyMetadata() { + return propertyMetadata; } /** - * Adds additional writable properties to the model-defined writable properties' request state. - * @param key The key of the additional property to be added to the component metadata. - * @param value The value of the additional property to be added to the component metadata. - * @return The DigitalTwinMetadata object itself. + * Adds an additional custom property to the digital twin. This field will contain any property + * of the digital twin that is not already defined by the other strong types of this class. + * @param key The key of the additional property to be added to the digital twin. + * @param value The value of the additional property to be added to the digital twin. + * @return The BasicDigitalTwin object itself. */ @JsonAnySetter - public DigitalTwinMetadata addWritableProperties(String key, Object value) { - this.writableProperties.put(key, value); + public BasicDigitalTwinMetadata addPropertyMetadata(String key, Object value) { + this.propertyMetadata.put(key, value); return this; } } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinPropertyMetadata.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinPropertyMetadata.java new file mode 100644 index 0000000000000..91bf0dd51102c --- /dev/null +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/BasicDigitalTwinPropertyMetadata.java @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.digitaltwins.core.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.time.OffsetDateTime; + +/** + * Contains metadata about changes on properties on a digital twin or component. + */ +public class BasicDigitalTwinPropertyMetadata { + @JsonProperty(value = DigitalTwinsJsonPropertyNames.METADATA_PROPERTY_LAST_UPDATE_TIME, required = true) + private OffsetDateTime lastUpdatedOn; + + /** + * Gets the date and time the property was last updated. + * @return The date and time the property was last updated. + */ + public OffsetDateTime getLastUpdatedOn() { + return lastUpdatedOn; + } + + /** + * Sets the the date and time the property was last updated. + * @param lastUpdatedOn The date and time the property was last updated. + * @return The BasicDigitalTwinPropertyMetadata object itself. + */ + public BasicDigitalTwinPropertyMetadata setLastUpdatedOn(OffsetDateTime lastUpdatedOn) { + this.lastUpdatedOn = lastUpdatedOn; + return this; + } +} diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/ComponentMetadata.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/ComponentMetadata.java deleted file mode 100644 index 866f57449d295..0000000000000 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/ComponentMetadata.java +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.digitaltwins.core.models; - -import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.HashMap; -import java.util.Map; - -/** - * An optional helper class for deserializing a digital twin - *

- * Note that this class uses {@link JsonProperty} from the Jackson serialization library. Because of this, this type - * will only work if the default json serializer is used by the digital twins client or if the custom json - * serializer uses Jackson as well. In order to use a different json library, a new ComponentMetadata class must - * be constructed and have its json properties tagged by the annotation used by that json library. - */ -@Fluent -@JsonInclude(JsonInclude.Include.NON_NULL) -public final class ComponentMetadata { - - /** - * Model-defined writable properties' request state. - */ - @JsonIgnore - private final Map writableProperties = new HashMap<>(); - - /** - * The public constructor for the ComponentMetadata. - */ - public ComponentMetadata() {} - - /** - * Gets the model-defined writable properties' request state. - * For your convenience, the value of each map can be turned into an instance of {@link WritableProperty}. - * @return The model-defined writable properties' request state. - */ - @JsonAnyGetter - public Map getWritableProperties() { - return writableProperties; - } - - /** - * Adds additional writable properties to the model-defined writable properties' request state. - * @param key The key of the additional property to be added to the component metadata. - * @param value The value of the additional property to be added to the component metadata. - * @return The ComponentMetadata object itself. - */ - @JsonAnySetter - public ComponentMetadata addWritableProperties(String key, Object value) { - this.writableProperties.put(key, value); - return this; - } -} diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinsJsonPropertyNames.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinsJsonPropertyNames.java index d3d4e42710119..1d51e3821f3af 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinsJsonPropertyNames.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/DigitalTwinsJsonPropertyNames.java @@ -47,4 +47,9 @@ public class DigitalTwinsJsonPropertyNames { * The JSON property name for the name field on a relationship. */ public static final String RELATIONSHIP_NAME = "$relationshipName"; + + /** + * The JSON property name for the lastUpdateTime field on a digital twin component's property metadata. + */ + public static final String METADATA_PROPERTY_LAST_UPDATE_TIME = "lastUpdateTime"; } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/WritableProperty.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/WritableProperty.java deleted file mode 100644 index 5901ceda87b1a..0000000000000 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/models/WritableProperty.java +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.digitaltwins.core.models; - -import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import static com.fasterxml.jackson.annotation.JsonInclude.*; - -/** - * An optional, helper class for deserializing a digital twin. - */ -@Fluent -@JsonInclude(Include.NON_NULL) -public final class WritableProperty { - - @JsonProperty(value = "desiredValue") - private Object desiredValue; - - @JsonProperty(value = "desiredVersion") - private int desiredVersion; - - @JsonProperty(value = "ackVersion", required = true) - private int ackVersion; - - @JsonProperty(value = "ackCode", required = true) - private int ackCode; - - @JsonProperty(value = "ackDescription") - private String ackDescription; - - /** - * Gets the desired value. - * @return The desired value. - */ - public Object getDesiredValue() { - return desiredValue; - } - - /** - * Sets the desired value. - * @param desiredValue The desired value. - * @return The WritableProperty object itself. - */ - public WritableProperty setDesiredValue(Object desiredValue) { - this.desiredValue = desiredValue; - return this; - } - - /** - * Gets the version of the property with the specified desired value. - * @return The version of the property with the specified desired value. - */ - public int getDesiredVersion() { - return desiredVersion; - } - - /** - * Sets the version of the property with the specified desired value. - * @param desiredVersion The version of the property with the specified desired value. - * @return The WritableProperty object itself. - */ - public WritableProperty setDesiredVersion(int desiredVersion) { - this.desiredVersion = desiredVersion; - return this; - } - - /** - * Gets the version of the reported property value. - * @return The version of the reported property value. - */ - public int getAckVersion() { - return ackVersion; - } - - /** - * Sets the version of the reported property value. - * @param ackVersion The version of the reported property value. - * @return The WritableProperty object itself. - */ - public WritableProperty setAckVersion(int ackVersion) { - this.ackVersion = ackVersion; - return this; - } - - /** - * Gets the response code of the property update request, usually an HTTP Status Code (e.g. 200). - * @return The response code of the property update request, usually an HTTP Status Code (e.g. 200). - */ - public int getAckCode() { - return ackCode; - } - - /** - * Sets the response code of the property update request, usually an HTTP Status Code (e.g. 200). - * @param ackCode The response code of the property update request, usually an HTTP Status Code (e.g. 200). - * @return The WritableProperty object itself. - */ - public WritableProperty setAckCode(int ackCode) { - this.ackCode = ackCode; - return this; - } - - /** - * Gets the message response of the property update request. - * @return The message response of the property update request. - */ - public String getAckDescription() { - return ackDescription; - } - - /** - * Sets the message response of the property update request. - * @param ackDescription The message response of the property update request. - * @return The WritableProperty object itself. - */ - public WritableProperty setAckDescription(String ackDescription) { - this.ackDescription = ackDescription; - return this; - } -} diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/README.md b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/README.md index 16547e9f73dcf..6600481c9a93a 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/README.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/README.md @@ -103,18 +103,18 @@ Both sync and async clients have maximal overloads for getting the Http response For example you can get a model by calling: ```java -ModelData model = syncClient.getModel(modelId); +DigitalTwinsModelData model = syncClient.getModel(modelId); ``` This will only return the Model payload. The API's response will not contain any REST information. To get information about the REST call you can call the maximal overload and have access to both the response body (ModelData) and the HTTP REST information. ```java -Response modelResponse = syncClient.getModelWithResponse(modelId, context); +Response modelResponse = syncClient.getModelWithResponse(modelId, context); System.out.println(modelResponse.getStatuscode()); -ModelData modelObject = modelResponse.getValue(); +DigitalTwinsModelData modelObject = modelResponse.getValue(); ``` ## Create, list, decommission, and delete models @@ -128,16 +128,16 @@ Example of using sync client to create models. ```java List modelsList = new ArrayList<>(Arrays.asList(newComponentModelPayload, newModelPayload)); -List modelList = syncClient.createModels(modelsList); +List modelList = syncClient.createModels(modelsList); -for (ModelData model : modelList) { +for (DigitalTwinsModelData model : modelList) { ConsoleLogger.print("Created model: " + model.getId()); } ``` ### List models -Using the sync client, `listModels`, all created models are returned as [`PagedIterable`](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedIterable.java) while the async API will return a [`PagedFlux`](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedFlux.java). +Using the sync client, `listModels`, all created models are returned as [`PagedIterable`](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedIterable.java) while the async API will return a [`PagedFlux`](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/PagedFlux.java). Example of using the async client to list all models: @@ -203,11 +203,11 @@ BasicDigitalTwin basicTwin = new BasicDigitalTwin() new DigitalTwinMetadata() .setModelId(modelId) ) - .addProperty("Prop1", "Value1") - .addProperty("Prop2", 987) - .addProperty( + .addToContents("Prop1", "Value1") + .addToContents("Prop2", 987) + .addToContents( "Component1", - new ModelProperties() + new BasicDigitalTwinComponent() .addroperty("ComponentProp1", "Component value 1") .addroperty("ComponentProp2", 123) ); @@ -253,13 +253,12 @@ Query the Azure Digital Twins instance for digital twins using the [Azure Digita PagedIterable pageableResponse = syncClient.query("SELECT * FROM digitaltwins", String.class); // Iterate over the twin instances in the pageable response. -foreach (String response in pageableResponse) -{ +foreach (String response in pageableResponse) { System.out.println(response); } // Or you can use the generic API to get a specific type back. -PagedIterable deserializedResponse = syncClient.query("SELECT * FROM digitaltwins", BasicDigitalTwin.class) +PagedIterable deserializedResponse = syncClient.query("SELECT * FROM digitaltwins", BasicDigitalTwin.class); for(BasicDigitalTwin digitalTwin : deserializedResponse){ System.out.println("Retrieved digital twin with Id: " + digitalTwin.getId()); diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/ComponentSyncSamples.java b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/ComponentSyncSamples.java index 2e0e5e89511e9..f1effc0b579d8 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/ComponentSyncSamples.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/ComponentSyncSamples.java @@ -8,10 +8,10 @@ import com.azure.digitaltwins.core.helpers.SamplesConstants; import com.azure.digitaltwins.core.helpers.UniqueIdHelper; import com.azure.digitaltwins.core.implementation.models.ErrorResponseException; +import com.azure.digitaltwins.core.models.BasicDigitalTwinComponent; +import com.azure.digitaltwins.core.models.BasicDigitalTwinMetadata; import com.azure.digitaltwins.core.models.DigitalTwinsModelData; import com.azure.digitaltwins.core.models.BasicDigitalTwin; -import com.azure.digitaltwins.core.models.DigitalTwinMetadata; -import com.azure.digitaltwins.core.models.ModelProperties; import com.azure.digitaltwins.core.models.UpdateOperationUtility; import com.azure.identity.ClientSecretCredentialBuilder; import com.fasterxml.jackson.core.JsonProcessingException; @@ -85,20 +85,18 @@ public static void runComponentSample() throws JsonProcessingException { // Create digital twin with component payload using the BasicDigitalTwin serialization helper. BasicDigitalTwin basicTwin = new BasicDigitalTwin(basicDigitalTwinId) .setMetadata( - new DigitalTwinMetadata() + new BasicDigitalTwinMetadata() .setModelId(modelId) ) - .addProperty("Prop1", "Value1") - .addProperty("Prop2", 987) - .addProperty( + .addToContents("Prop1", "Value1") + .addToContents("Prop2", 987) + .addToContents( "Component1", - new ModelProperties() - .addProperty("ComponentProp1", "Component value 1") - .addProperty("ComponentProp2", 123) + new BasicDigitalTwinComponent() + .addToContents("ComponentProp1", "Component value 1") + .addToContents("ComponentProp2", 123) ); - String basicDigitalTwinPayload = mapper.writeValueAsString(basicTwin); - BasicDigitalTwin basicTwinResponse = client.createOrReplaceDigitalTwin(basicDigitalTwinId, basicTwin, BasicDigitalTwin.class); ConsoleLogger.print("Created digital twin " + basicTwinResponse.getId()); @@ -119,14 +117,14 @@ public static void runComponentSample() throws JsonProcessingException { BasicDigitalTwin basicDigitalTwin = basicDigitalTwinResponse.getValue(); - String component1RawText = mapper.writeValueAsString(basicDigitalTwin.getProperties().get("Component1")); + String component1RawText = mapper.writeValueAsString(basicDigitalTwin.getContents().get("Component1")); HashMap component1 = mapper.readValue(component1RawText, HashMap.class); ConsoleLogger.print("Retrieved digital twin using generic API to use built in deserialization into a BasicDigitalTwin with Id: " + basicDigitalTwin.getId() + ":\n\t" + "Etag: " + basicDigitalTwin.getEtag() + "\n\t" - + "Prop1: " + basicDigitalTwin.getProperties().get("Prop1") + "\n\t" - + "Prop2: " + basicDigitalTwin.getProperties().get("Prop2") + "\n\t" + + "Prop1: " + basicDigitalTwin.getContents().get("Prop1") + "\n\t" + + "Prop2: " + basicDigitalTwin.getContents().get("Prop2") + "\n\t" + "ComponentProp1: " + component1.get("ComponentProp1") + "\n\t" + "ComponentProp2: " + component1.get("ComponentProp2") + "\n\t" ); @@ -145,8 +143,12 @@ public static void runComponentSample() throws JsonProcessingException { ConsoleLogger.print("Updated component for digital twin: " + basicDigitalTwinId); ConsoleLogger.printHeader("Get Component"); - String getComponentResponse = client.getComponent(basicDigitalTwinId, "Component1", String.class); - ConsoleLogger.print("Retrieved component for digital twin " + basicDigitalTwinId + " :\n" + getComponentResponse); + BasicDigitalTwinComponent getComponentResponse = client.getComponent(basicDigitalTwinId, "Component1", BasicDigitalTwinComponent.class); + + ConsoleLogger.print("Retrieved component for digital twin " + basicDigitalTwinId + " :"); + for (String key : getComponentResponse.getContents().keySet()) { + ConsoleLogger.print("\t" + key + " : " + getComponentResponse.getContents().get(key)); + } // Clean up try { diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/RelationshipsSyncSamples.java b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/RelationshipsSyncSamples.java index 833c4d8925690..c5ada665870fc 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/RelationshipsSyncSamples.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/RelationshipsSyncSamples.java @@ -84,7 +84,7 @@ public static void runRelationshipsSample() throws JsonProcessingException { // Create a building digital twin BasicDigitalTwin buildingDigitalTwin = new BasicDigitalTwin(buildingTwinId) - .setMetadata(new DigitalTwinMetadata() + .setMetadata(new BasicDigitalTwinMetadata() .setModelId(sampleBuildingModelId)); client.createOrReplaceDigitalTwin(buildingTwinId, buildingDigitalTwin, BasicDigitalTwin.class); @@ -92,7 +92,7 @@ public static void runRelationshipsSample() throws JsonProcessingException { ConsoleLogger.print("Created twin" + buildingDigitalTwin.getId()); BasicDigitalTwin floorDigitalTwin = new BasicDigitalTwin(floorTwinId) - .setMetadata(new DigitalTwinMetadata() + .setMetadata(new BasicDigitalTwinMetadata() .setModelId(sampleFloorModelId)); BasicDigitalTwin createdTwin = client.createOrReplaceDigitalTwin(floorTwinId, floorDigitalTwin, BasicDigitalTwin.class); diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/serialization/CustomDigitalTwin.java b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/serialization/CustomDigitalTwin.java index 8586b46eae179..1b79f010ad7fc 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/serialization/CustomDigitalTwin.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/serialization/CustomDigitalTwin.java @@ -5,7 +5,6 @@ import com.azure.core.annotation.Fluent; import com.azure.digitaltwins.core.models.DigitalTwinsJsonPropertyNames; -import com.azure.digitaltwins.core.models.WritableProperty; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -21,9 +20,6 @@ public class CustomDigitalTwin { @JsonProperty(value = DigitalTwinsJsonPropertyNames.DIGITAL_TWIN_ETAG, required = true) private String etag; - @JsonProperty(value = DigitalTwinsJsonPropertyNames.DIGITAL_TWIN_METADATA, required = true) - private CustomDigitalTwinMetadata metadata; - @JsonProperty(value = "AverageTemperature") private int averageTemperature; @@ -48,15 +44,6 @@ public CustomDigitalTwin setEtag(String etag) { return this; } - public CustomDigitalTwinMetadata getMetadata() { - return metadata; - } - - public CustomDigitalTwin setMetadata(CustomDigitalTwinMetadata metadata) { - this.metadata = metadata; - return this; - } - public int getAverageTemperature() { return averageTemperature; } @@ -92,23 +79,3 @@ public Metadata setModelId(String modelId) { return this; } } - -@Fluent -@JsonInclude(Include.NON_NULL) -class CustomDigitalTwinMetadata extends Metadata { - - @JsonProperty(value = "AverageTemperature") - private WritableProperty averageTemperature; - - public WritableProperty getAverageTemperature() { - return averageTemperature; - } - - @JsonProperty(value = "TemperatureUnit") - private WritableProperty temperatureUnit; - - public CustomDigitalTwinMetadata setAverageTemperature(WritableProperty averageTemperature) { - this.averageTemperature = averageTemperature; - return this; - } -} diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsAsyncClientJavaDocCodeSnippets.java b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsAsyncClientJavaDocCodeSnippets.java index 2b558c7653d8c..12ea65c595ad2 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsAsyncClientJavaDocCodeSnippets.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsAsyncClientJavaDocCodeSnippets.java @@ -55,7 +55,7 @@ public void createDigitalTwin() { BasicDigitalTwin basicTwin = new BasicDigitalTwin("myDigitalTwinId") .setMetadata( - new DigitalTwinMetadata() + new BasicDigitalTwinMetadata() .setModelId(modelId) ); @@ -84,7 +84,7 @@ public void createDigitalTwinWithResponse(){ BasicDigitalTwin basicDigitalTwin = new BasicDigitalTwin("myDigitalTwinId") .setMetadata( - new DigitalTwinMetadata() + new BasicDigitalTwinMetadata() .setModelId(modelId) ); diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsClientJavaDocCodeSnippets.java b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsClientJavaDocCodeSnippets.java index f120cd994723a..81b5a14936011 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsClientJavaDocCodeSnippets.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/samples/java/com/azure/digitaltwins/core/snippets/DigitalTwinsClientJavaDocCodeSnippets.java @@ -60,7 +60,7 @@ public void createDigitalTwin() { BasicDigitalTwin basicTwin = new BasicDigitalTwin("myDigitalTwinId") .setMetadata( - new DigitalTwinMetadata() + new BasicDigitalTwinMetadata() .setModelId(modelId) ); @@ -96,7 +96,7 @@ public void createDigitalTwinWithResponse() { BasicDigitalTwin basicDigitalTwin = new BasicDigitalTwin("myDigitalTwinId") .setMetadata( - new DigitalTwinMetadata() + new BasicDigitalTwinMetadata() .setModelId(modelId) ); diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryAsyncTests.java b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryAsyncTests.java index f687154b0b677..09993de445ce3 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryAsyncTests.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryAsyncTests.java @@ -63,7 +63,7 @@ public void validQuerySucceeds(HttpClient httpClient, DigitalTwinsServiceVersion StepVerifier.create(asyncClient.query(queryString, BasicDigitalTwin.class, null)) .thenConsumeWhile(dt -> { - assertThat(dt.getProperties().get("IsOccupied")) + assertThat(dt.getContents().get("IsOccupied")) .as("IsOccupied should be true") .isEqualTo(true); return true; diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryTests.java b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryTests.java index 0bc907557e6c8..8b2079df87e68 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryTests.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/QueryTests.java @@ -52,7 +52,7 @@ public void validQuerySucceeds(HttpClient httpClient, DigitalTwinsServiceVersion PagedIterable pagedQueryResponse = client.query(queryString, BasicDigitalTwin.class, new QueryOptions().setMaxItemsPerPage(pageSize), Context.NONE); for(BasicDigitalTwin digitalTwin : pagedQueryResponse){ - assertThat(digitalTwin.getProperties().get("IsOccupied")) + assertThat(digitalTwin.getContents().get("IsOccupied")) .as("IsOccupied should be true") .isEqualTo(true); } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinAsyncTests.java b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinAsyncTests.java index 40597214f1f46..d474f8fc78e88 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinAsyncTests.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinAsyncTests.java @@ -73,10 +73,10 @@ public void digitalTwinLifecycle(HttpClient httpClient, DigitalTwinsServiceVersi // Get Twin and verify update was successful StepVerifier.create(asyncClient.getDigitalTwin(roomTwinId, BasicDigitalTwin.class)) .assertNext(response -> { - assertThat(response.getProperties().get("Humidity")) + assertThat(response.getContents().get("Humidity")) .as("Humidity is added") .isEqualTo(30); - assertThat(response.getProperties().get("Temperature")) + assertThat(response.getContents().get("Temperature")) .as("Temperature is updated") .isEqualTo(70); }) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinTests.java b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinTests.java index 421a5dbe374f0..f4ccd588cd92f 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinTests.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/TwinTests.java @@ -64,11 +64,11 @@ public void digitalTwinLifecycle(HttpClient httpClient, DigitalTwinsServiceVersi BasicDigitalTwin getTwinObject = client.getDigitalTwin(roomTwinId, BasicDigitalTwin.class); - assertThat(getTwinObject.getProperties().get("Humidity")) + assertThat(getTwinObject.getContents().get("Humidity")) .as("Humidity is added") .isEqualTo(30); - assertThat(getTwinObject.getProperties().get("Temperature")) + assertThat(getTwinObject.getContents().get("Temperature")) .as("Temperature is updated") .isEqualTo(70);