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

Remove DigitalTwins Writable property, rewrite Basic classes to match .NET #16896

Merged
merged 5 commits into from
Oct 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> properties = new HashMap<>();
private final Map<String, Object> contents = new HashMap<>();

/**
* Construct a basic digital twin.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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<String, Object> getProperties() {
return properties;
public Map<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> properties = new HashMap<>();
private final Map<String, Object> 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<String, Object> getProperties() {
return properties;
public Map<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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}
* <p>
* 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<String, Object> 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<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> writableProperties = new HashMap<>();
private final Map<String, Object> propertyMetadata = new HashMap<>();

/**
* Creates an instance of digital twin metadata.
*/
public DigitalTwinMetadata() {
public BasicDigitalTwinMetadata() {
}

/**
Expand All @@ -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<String, Object> getWritableProperties() {
return writableProperties;
public Map<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we decided to use lastUpdatedOn, I just wanted to say I think lastUpdatedTime might have been a better property name. goodbye

Copy link
Member Author

@timtay-microsoft timtay-microsoft Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly this is the name the service choose, so I'm not looking to change it.

Scratch that, the service went with "lastUpdateTime" but Azure SDK team prefers we name like the above. We already renamed the digital twins model data class' date time field like this, so it should pass review


/**
* 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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Loading