From 15080d9f6a9873c958bbe7c2e480bfd7ab3eb5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20J=C3=A4ckle?= Date: Thu, 12 Oct 2023 14:38:39 +0200 Subject: [PATCH 1/2] provide new option for "if-equal" header: "skip-minimizing-merge" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * which reduces the part of a merge/patch command to the actually changed elements, removing non-changed elements * this reduces e.g. required storage in the MongoDB by a lot, if redundant data is sent often * this also reduces the event payload to the actually changed parts of the thing Signed-off-by: Thomas Jäckle --- .../ditto/base/model/headers/IfEqual.java | 12 ++- .../model/signals/WithOptionalEntity.java | 18 +++- .../model/signals/acks/Acknowledgement.java | 5 +- .../model/signals/acks/Acknowledgements.java | 23 +++-- .../base/model/signals/events/Event.java | 2 +- .../StreamingSubscriptionComplete.java | 6 ++ .../StreamingSubscriptionCreated.java | 6 ++ .../StreamingSubscriptionFailed.java | 6 ++ .../StreamingSubscriptionHasNext.java | 5 + .../signals/events/assertions/TestEvent.java | 12 ++- .../modify/CheckConnectionLogsActive.java | 24 +++-- .../commands/modify/CloseConnection.java | 18 ++-- .../modify/CloseConnectionResponse.java | 6 ++ .../modify/ConnectivityModifyCommand.java | 4 +- .../ConnectivityModifyCommandResponse.java | 4 +- .../commands/modify/CreateConnection.java | 12 +++ .../modify/CreateConnectionResponse.java | 5 + .../commands/modify/DeleteConnection.java | 18 ++-- .../modify/DeleteConnectionResponse.java | 6 ++ .../commands/modify/EnableConnectionLogs.java | 18 ++-- .../modify/EnableConnectionLogsResponse.java | 6 ++ .../commands/modify/LoggingExpired.java | 18 ++-- .../commands/modify/ModifyConnection.java | 28 ++++-- .../modify/ModifyConnectionResponse.java | 5 + .../commands/modify/OpenConnection.java | 18 ++-- .../modify/OpenConnectionResponse.java | 6 ++ .../commands/modify/ResetConnectionLogs.java | 18 ++-- .../modify/ResetConnectionLogsResponse.java | 6 ++ .../modify/ResetConnectionMetrics.java | 18 ++-- .../ResetConnectionMetricsResponse.java | 6 ++ .../commands/modify/TestConnection.java | 28 ++++-- .../modify/TestConnectionResponse.java | 6 ++ .../signals/events/ConnectionClosed.java | 9 +- .../signals/events/ConnectionCreated.java | 6 ++ .../signals/events/ConnectionDeleted.java | 6 ++ .../signals/events/ConnectionModified.java | 6 ++ .../signals/events/ConnectionOpened.java | 6 ++ .../ImmutableFeaturePlaceholder.java | 2 +- .../actors/AbstractHttpRequestActor.java | 50 +++++----- .../service/endpoints/EndpointTestBase.java | 36 ++++--- .../ConditionalHeadersValidator.java | 2 +- .../IfEqualPreconditionHeader.java | 99 ++++++++++++++++--- .../utils/persistentactors/EmptyEvent.java | 6 ++ .../eclipse/ditto/json/JsonMergePatch.java | 11 +-- .../actions/ActivateTokenIntegration.java | 22 +++-- .../ActivateTokenIntegrationResponse.java | 17 ++-- .../actions/DeactivateTokenIntegration.java | 23 +++-- .../DeactivateTokenIntegrationResponse.java | 18 ++-- .../commands/actions/PolicyActionCommand.java | 6 +- .../actions/PolicyActionCommandResponse.java | 4 +- .../actions/TopLevelPolicyActionCommand.java | 21 ++-- .../TopLevelPolicyActionCommandResponse.java | 16 ++- .../signals/commands/modify/CreatePolicy.java | 8 +- .../commands/modify/CreatePolicyResponse.java | 6 ++ .../signals/commands/modify/DeletePolicy.java | 16 ++- .../commands/modify/DeletePolicyEntry.java | 18 ++-- .../modify/DeletePolicyEntryResponse.java | 6 ++ .../commands/modify/DeletePolicyImport.java | 6 ++ .../modify/DeletePolicyImportResponse.java | 6 ++ .../commands/modify/DeletePolicyResponse.java | 6 ++ .../commands/modify/DeleteResource.java | 20 ++-- .../modify/DeleteResourceResponse.java | 6 ++ .../commands/modify/DeleteSubject.java | 18 ++-- .../modify/DeleteSubjectResponse.java | 6 ++ .../signals/commands/modify/ModifyPolicy.java | 17 ++-- .../commands/modify/ModifyPolicyEntries.java | 5 + .../modify/ModifyPolicyEntriesResponse.java | 6 ++ .../commands/modify/ModifyPolicyEntry.java | 18 ++-- .../modify/ModifyPolicyEntryResponse.java | 8 ++ .../commands/modify/ModifyPolicyImport.java | 6 ++ .../modify/ModifyPolicyImportResponse.java | 8 ++ .../commands/modify/ModifyPolicyImports.java | 5 + .../modify/ModifyPolicyImportsResponse.java | 8 ++ .../commands/modify/ModifyPolicyResponse.java | 8 ++ .../commands/modify/ModifyResource.java | 18 ++-- .../modify/ModifyResourceResponse.java | 7 ++ .../commands/modify/ModifyResources.java | 17 ++-- .../modify/ModifyResourcesResponse.java | 6 ++ .../commands/modify/ModifySubject.java | 18 ++-- .../modify/ModifySubjectResponse.java | 8 ++ .../commands/modify/ModifySubjects.java | 17 ++-- .../modify/ModifySubjectsResponse.java | 6 ++ .../commands/modify/PolicyModifyCommand.java | 2 +- .../modify/PolicyModifyCommandResponse.java | 2 +- .../model/signals/events/PolicyCreated.java | 6 ++ .../model/signals/events/PolicyDeleted.java | 6 ++ .../signals/events/PolicyEntriesModified.java | 6 ++ .../signals/events/PolicyEntryCreated.java | 6 ++ .../signals/events/PolicyEntryDeleted.java | 6 ++ .../signals/events/PolicyEntryModified.java | 6 ++ .../signals/events/PolicyImportCreated.java | 7 ++ .../signals/events/PolicyImportDeleted.java | 6 ++ .../signals/events/PolicyImportModified.java | 7 ++ .../signals/events/PolicyImportsModified.java | 6 ++ .../model/signals/events/PolicyModified.java | 6 ++ .../model/signals/events/ResourceCreated.java | 6 ++ .../model/signals/events/ResourceDeleted.java | 6 ++ .../signals/events/ResourceModified.java | 6 ++ .../signals/events/ResourcesModified.java | 6 ++ .../model/signals/events/SubjectCreated.java | 7 ++ .../model/signals/events/SubjectDeleted.java | 6 ++ .../model/signals/events/SubjectModified.java | 7 ++ .../events/SubjectsDeletedPartially.java | 6 ++ .../signals/events/SubjectsModified.java | 6 ++ .../events/SubjectsModifiedPartially.java | 6 ++ .../PolicyModifyCommandAdapterTest.java | 15 ++- .../things/SubscriptionEventAdapterTest.java | 18 ++-- .../adapter/things/ThingEventAdapterTest.java | 5 + .../things/ThingModifyCommandAdapterTest.java | 16 +-- ...ThingModifyCommandResponseAdapterTest.java | 21 ++-- .../ditto/things/api/ThingSnapshotTaken.java | 18 ++-- .../acks/ThingAcknowledgementsFactory.java | 2 +- .../signals/commands/modify/CreateThing.java | 9 ++ .../commands/modify/CreateThingResponse.java | 5 + .../commands/modify/DeleteAttribute.java | 18 ++-- .../modify/DeleteAttributeResponse.java | 6 ++ .../commands/modify/DeleteAttributes.java | 16 ++- .../modify/DeleteAttributesResponse.java | 6 ++ .../commands/modify/DeleteFeature.java | 6 ++ .../modify/DeleteFeatureDefinition.java | 20 ++-- .../DeleteFeatureDefinitionResponse.java | 6 ++ .../DeleteFeatureDesiredProperties.java | 20 ++-- ...eleteFeatureDesiredPropertiesResponse.java | 6 ++ .../modify/DeleteFeatureDesiredProperty.java | 20 ++-- .../DeleteFeatureDesiredPropertyResponse.java | 6 ++ .../modify/DeleteFeatureProperties.java | 20 ++-- .../DeleteFeaturePropertiesResponse.java | 6 ++ .../modify/DeleteFeatureProperty.java | 20 ++-- .../modify/DeleteFeaturePropertyResponse.java | 6 ++ .../modify/DeleteFeatureResponse.java | 6 ++ .../commands/modify/DeleteFeatures.java | 16 ++- .../modify/DeleteFeaturesResponse.java | 6 ++ .../signals/commands/modify/DeleteThing.java | 16 ++- .../modify/DeleteThingDefinition.java | 16 ++- .../modify/DeleteThingDefinitionResponse.java | 6 ++ .../commands/modify/DeleteThingResponse.java | 6 ++ .../signals/commands/modify/MergeThing.java | 12 +++ .../commands/modify/MergeThingResponse.java | 6 ++ .../commands/modify/ModifyAttribute.java | 17 ++-- .../modify/ModifyAttributeResponse.java | 6 ++ .../commands/modify/ModifyAttributes.java | 19 ++-- .../modify/ModifyAttributesResponse.java | 9 ++ .../commands/modify/ModifyFeature.java | 22 +++-- .../modify/ModifyFeatureDefinition.java | 19 ++-- .../ModifyFeatureDefinitionResponse.java | 7 ++ .../ModifyFeatureDesiredProperties.java | 19 ++-- ...odifyFeatureDesiredPropertiesResponse.java | 7 ++ .../modify/ModifyFeatureDesiredProperty.java | 19 ++-- .../ModifyFeatureDesiredPropertyResponse.java | 10 ++ .../modify/ModifyFeatureProperties.java | 22 +++-- .../ModifyFeaturePropertiesResponse.java | 7 ++ .../modify/ModifyFeatureProperty.java | 19 ++-- .../modify/ModifyFeaturePropertyResponse.java | 10 ++ .../modify/ModifyFeatureResponse.java | 9 ++ .../commands/modify/ModifyFeatures.java | 17 ++-- .../modify/ModifyFeaturesResponse.java | 8 ++ .../commands/modify/ModifyPolicyId.java | 17 ++-- .../modify/ModifyPolicyIdResponse.java | 5 + .../signals/commands/modify/ModifyThing.java | 9 ++ .../modify/ModifyThingDefinition.java | 19 ++-- .../modify/ModifyThingDefinitionResponse.java | 7 ++ .../commands/modify/ModifyThingResponse.java | 7 ++ .../commands/modify/ThingModifyCommand.java | 2 +- .../modify/ThingModifyCommandResponse.java | 2 +- .../signals/events/AttributeCreated.java | 6 ++ .../signals/events/AttributeDeleted.java | 6 ++ .../signals/events/AttributeModified.java | 6 ++ .../signals/events/AttributesCreated.java | 6 ++ .../signals/events/AttributesDeleted.java | 6 ++ .../signals/events/AttributesModified.java | 6 ++ .../model/signals/events/FeatureCreated.java | 8 ++ .../events/FeatureDefinitionCreated.java | 6 ++ .../events/FeatureDefinitionDeleted.java | 6 ++ .../events/FeatureDefinitionModified.java | 6 ++ .../model/signals/events/FeatureDeleted.java | 6 ++ .../FeatureDesiredPropertiesCreated.java | 11 ++- .../FeatureDesiredPropertiesDeleted.java | 6 ++ .../FeatureDesiredPropertiesModified.java | 6 ++ .../events/FeatureDesiredPropertyCreated.java | 6 ++ .../events/FeatureDesiredPropertyDeleted.java | 6 ++ .../FeatureDesiredPropertyModified.java | 6 ++ .../model/signals/events/FeatureModified.java | 7 ++ .../events/FeaturePropertiesCreated.java | 8 ++ .../events/FeaturePropertiesDeleted.java | 6 ++ .../events/FeaturePropertiesModified.java | 14 ++- .../events/FeaturePropertyCreated.java | 6 ++ .../events/FeaturePropertyDeleted.java | 6 ++ .../events/FeaturePropertyModified.java | 6 ++ .../model/signals/events/FeaturesCreated.java | 13 ++- .../model/signals/events/FeaturesDeleted.java | 6 ++ .../signals/events/FeaturesModified.java | 6 ++ .../signals/events/PolicyIdModified.java | 6 ++ .../model/signals/events/ThingCreated.java | 6 ++ .../events/ThingDefinitionCreated.java | 6 ++ .../events/ThingDefinitionDeleted.java | 8 ++ .../events/ThingDefinitionModified.java | 6 ++ .../model/signals/events/ThingDeleted.java | 8 ++ .../model/signals/events/ThingMerged.java | 6 ++ .../model/signals/events/ThingModified.java | 6 ++ .../commands/MetadataFromCommand.java | 2 +- .../events/AbstractThingEventStrategy.java | 2 +- .../events/ThingMergedStrategy.java | 6 +- .../api/events/ThingsOutOfSync.java | 6 ++ .../signals/events/SubscriptionComplete.java | 12 ++- .../signals/events/SubscriptionCreated.java | 12 ++- .../signals/events/SubscriptionFailed.java | 16 ++- .../events/SubscriptionHasNextPage.java | 12 ++- 207 files changed, 1724 insertions(+), 459 deletions(-) diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java b/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java index 90e833a8a5..2a5b9e9638 100644 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java @@ -32,7 +32,17 @@ public enum IfEqual { * Option which will skip the update of a twin if the new value is the same (via {@code equal()}) than the value * before. */ - SKIP("skip"); + SKIP("skip"), + + /** + * Option which will skip the update of a twin if the new value is the same (via {@code equal()}) than the value + * before. + * And additionally minimized a "Merge" command to only the actually changed fields compared to the current state + * of the entity. This can be beneficial to reduce (persisted and emitted) events to the minimum of what actually + * did change. + * @since 3.4.0 + */ + SKIP_MINIMIZING_MERGE("skip-minimizing-merge"); private final String option; diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/WithOptionalEntity.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/WithOptionalEntity.java index db2c3da5c4..cf350e400e 100755 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/WithOptionalEntity.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/WithOptionalEntity.java @@ -14,13 +14,15 @@ import java.util.Optional; -import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; /** - * Implementations of this interface are associated to an entity returned from {@link #getEntity(org.eclipse.ditto.base.model.json.JsonSchemaVersion)} . + * Implementations of this interface are associated to an entity returned from {@link #getEntity(JsonSchemaVersion)} . + * + * @param the type of the implementing class. */ -public interface WithOptionalEntity { +public interface WithOptionalEntity> { /** * Returns the entity as JSON. @@ -41,4 +43,14 @@ default Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.empty(); } + /** + * Sets the entity and returns a new object. + * + * @param entity the entity to set. + * @return the newly created object with the set entity. + * @throws NullPointerException if the passed {@code entity} is null. + * @since 3.4.0 + */ + T setEntity(JsonValue entity); + } diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgement.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgement.java index 15869dde66..47456a6b47 100644 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgement.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgement.java @@ -56,8 +56,8 @@ */ @JsonParsableCommandResponse(type = Acknowledgement.TYPE) @Immutable -public final class Acknowledgement implements CommandResponse, WithOptionalEntity, WithEntityType, - SignalWithEntityId { +public final class Acknowledgement implements CommandResponse, WithOptionalEntity, + WithEntityType, SignalWithEntityId { /** * The type of {@code Acknowledgement} signals. @@ -231,6 +231,7 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { * @return the Acknowledgement with set payload. * @since 1.2.0 */ + @Override public Acknowledgement setEntity(final @Nullable JsonValue payload) { if (payload != null) { return of(label, entityId, httpStatus, dittoHeaders, payload); diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgements.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgements.java index 6e15911e46..d99146d31e 100644 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgements.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/acks/Acknowledgements.java @@ -71,8 +71,8 @@ @JsonParsableCommandResponse(type = Acknowledgements.TYPE) @Immutable public final class Acknowledgements - implements Iterable, CommandResponse, WithOptionalEntity, WithEntityType, - SignalWithEntityId { + implements Iterable, CommandResponse, WithOptionalEntity, + WithEntityType, SignalWithEntityId { static final String TYPE = "acknowledgements"; private final EntityId entityId; @@ -81,7 +81,7 @@ public final class Acknowledgements private final DittoHeaders dittoHeaders; private Acknowledgements(final EntityId entityId, - final Collection acknowledgements, + final Collection acknowledgements, final HttpStatus httpStatus, final DittoHeaders dittoHeaders) { @@ -107,7 +107,7 @@ private Acknowledgements(final EntityId entityId, * @throws IllegalArgumentException if the given {@code acknowledgements} are empty or if the entity IDs or entity * types of the given acknowledgements are not equal. */ - public static Acknowledgements of(final Collection acknowledgements, + public static Acknowledgements of(final Collection acknowledgements, final DittoHeaders dittoHeaders) { argumentNotEmpty(acknowledgements, "acknowledgements"); @@ -130,7 +130,7 @@ public static Acknowledgements of(final Collection ac * @since 2.0.0 */ public static Acknowledgements of(final EntityId entityId, - final Collection acknowledgements, + final Collection acknowledgements, final HttpStatus httpStatus, final DittoHeaders dittoHeaders) { @@ -142,8 +142,8 @@ public static Acknowledgements of(final EntityId entityId, return new Acknowledgements(entityId, acknowledgements, httpStatus, dittoHeaders); } - private static EntityId getEntityId(final Iterable acknowledgements) { - final Iterator acknowledgementIterator = acknowledgements.iterator(); + private static EntityId getEntityId(final Iterable acknowledgements) { + final Iterator acknowledgementIterator = acknowledgements.iterator(); Acknowledgement acknowledgement = acknowledgementIterator.next(); final EntityId entityId = acknowledgement.getEntityId(); while (acknowledgementIterator.hasNext()) { @@ -157,7 +157,7 @@ private static EntityId getEntityId(final Iterable ac return entityId; } - private static HttpStatus getCombinedHttpStatus(final Collection acknowledgements) { + private static HttpStatus getCombinedHttpStatus(final Collection acknowledgements) { final HttpStatus result; if (1 == acknowledgements.size()) { result = acknowledgements.stream() @@ -165,7 +165,7 @@ private static HttpStatus getCombinedHttpStatus(final Collection acknowledgementStream = acknowledgements.stream(); + final Stream acknowledgementStream = acknowledgements.stream(); final boolean allAcknowledgementsSuccessful = acknowledgementStream.allMatch(Acknowledgement::isSuccess); if (allAcknowledgementsSuccessful) { result = HttpStatus.OK; @@ -364,6 +364,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return result; } + @Override + public Acknowledgements setEntity(final JsonValue entity) { + return this; + } + private JsonObject acknowledgementsEntitiesToJson(final JsonSchemaVersion schemaVersion) { return acknowledgementsToJsonWithDisambiguation(schemaVersion, FieldType.all(), (ack, version, predicate) -> { final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder() diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/Event.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/Event.java index 4fca6e5810..1754ae4f66 100755 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/Event.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/Event.java @@ -34,7 +34,7 @@ * @param the type of the implementing class. */ @IndexSubclasses -public interface Event> extends Signal, WithOptionalEntity { +public interface Event> extends Signal, WithOptionalEntity { /** * Type qualifier of events. diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionComplete.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionComplete.java index e6bd039cdd..2f96a7ded9 100755 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionComplete.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionComplete.java @@ -22,6 +22,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after all items of a subscription are sent. @@ -93,6 +94,11 @@ public StreamingSubscriptionComplete setDittoHeaders(final DittoHeaders dittoHea return new StreamingSubscriptionComplete(getSubscriptionId(), getEntityId(), dittoHeaders); } + @Override + public StreamingSubscriptionComplete setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { // nothing to add diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionCreated.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionCreated.java index 6c6ffc518e..ea5b60f62b 100755 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionCreated.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionCreated.java @@ -22,6 +22,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a stream is established for items to be streamed in the back-end. @@ -95,6 +96,11 @@ public StreamingSubscriptionCreated setDittoHeaders(final DittoHeaders dittoHead return new StreamingSubscriptionCreated(getSubscriptionId(), getEntityId(), dittoHeaders); } + @Override + public StreamingSubscriptionCreated setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { // nothing to add diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionFailed.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionFailed.java index 4e4f878e34..e31740ae74 100755 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionFailed.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionFailed.java @@ -28,6 +28,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a stream failed. @@ -128,6 +129,11 @@ public StreamingSubscriptionFailed setDittoHeaders(final DittoHeaders dittoHeade return new StreamingSubscriptionFailed(getSubscriptionId(), getEntityId(), error, dittoHeaders); } + @Override + public StreamingSubscriptionFailed setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { jsonObjectBuilder.set(JsonFields.ERROR, error.toJson()); diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionHasNext.java b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionHasNext.java index c8539110fb..91d6de2c75 100755 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionHasNext.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/signals/events/streaming/StreamingSubscriptionHasNext.java @@ -126,6 +126,11 @@ public StreamingSubscriptionHasNext setDittoHeaders(final DittoHeaders dittoHead return new StreamingSubscriptionHasNext(getSubscriptionId(), getEntityId(), item, dittoHeaders); } + @Override + public StreamingSubscriptionHasNext setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { jsonObjectBuilder.set(JsonFields.ITEM, item); diff --git a/base/model/src/test/java/org/eclipse/ditto/base/model/signals/events/assertions/TestEvent.java b/base/model/src/test/java/org/eclipse/ditto/base/model/signals/events/assertions/TestEvent.java index 2ce1ee7a0e..850b47523a 100644 --- a/base/model/src/test/java/org/eclipse/ditto/base/model/signals/events/assertions/TestEvent.java +++ b/base/model/src/test/java/org/eclipse/ditto/base/model/signals/events/assertions/TestEvent.java @@ -18,14 +18,15 @@ import javax.annotation.Nonnull; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.entity.metadata.Metadata; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableEvent; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.base.model.signals.events.Event; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; @JsonParsableEvent(name = TestEvent.NAME, typePrefix = TestEvent.TYPE_PREFIX) @@ -91,4 +92,9 @@ public String getManifest() { public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate predicate) { return JsonObject.empty(); } + + @Override + public TestEvent setEntity(final JsonValue entity) { + return this; + } } diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CheckConnectionLogsActive.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CheckConnectionLogsActive.java index fcfd7de30c..078540d78b 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CheckConnectionLogsActive.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CheckConnectionLogsActive.java @@ -22,21 +22,22 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonParseException; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; +import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonParseException; +import org.eclipse.ditto.json.JsonValue; /** * Command that will enable logging in a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -56,7 +57,7 @@ public final class CheckConnectionLogsActive extends AbstractCommand JSON_TIMESTAMP = + static final JsonFieldDefinition JSON_TIMESTAMP = JsonFactory.newStringFieldDefinition("timestamp", FieldType.REGULAR, JsonSchemaVersion.V_2); @@ -191,6 +192,11 @@ public CheckConnectionLogsActive setDittoHeaders(final DittoHeaders dittoHeaders return of(connectionId, timestamp, dittoHeaders); } + @Override + public CheckConnectionLogsActive setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return (other instanceof CheckConnectionLogsActive); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnection.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnection.java index cf7c4913a8..0fe95fcc0f 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnection.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnection.java @@ -20,18 +20,19 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonValue; /** * Command which closes a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -133,6 +134,11 @@ public CloseConnection setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public CloseConnection setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return (other instanceof CloseConnection); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnectionResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnectionResponse.java index d29802d37b..0611c026d6 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnectionResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CloseConnectionResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link CloseConnection} command. @@ -142,6 +143,11 @@ public CloseConnectionResponse setDittoHeaders(final DittoHeaders dittoHeaders) return of(connectionId, dittoHeaders); } + @Override + public CloseConnectionResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof CloseConnectionResponse; diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommand.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommand.java index 28fd8369b7..967e770bd8 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommand.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommand.java @@ -12,9 +12,9 @@ */ package org.eclipse.ditto.connectivity.model.signals.commands.modify; -import org.eclipse.ditto.connectivity.model.WithConnectionId; import org.eclipse.ditto.base.model.signals.SignalWithEntityId; import org.eclipse.ditto.base.model.signals.WithOptionalEntity; +import org.eclipse.ditto.connectivity.model.WithConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; /** @@ -23,5 +23,5 @@ * @param the type of the implementing class. */ public interface ConnectivityModifyCommand> - extends ConnectivityCommand, WithOptionalEntity, WithConnectionId, SignalWithEntityId { + extends ConnectivityCommand, WithOptionalEntity, WithConnectionId, SignalWithEntityId { } diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommandResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommandResponse.java index 0a8b5e9c06..108120fa4b 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommandResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ConnectivityModifyCommandResponse.java @@ -13,9 +13,9 @@ package org.eclipse.ditto.connectivity.model.signals.commands.modify; import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.connectivity.model.WithConnectionId; import org.eclipse.ditto.base.model.signals.SignalWithEntityId; import org.eclipse.ditto.base.model.signals.WithOptionalEntity; +import org.eclipse.ditto.connectivity.model.WithConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommandResponse; /** @@ -25,7 +25,7 @@ * @param the type of the implementing class. */ public interface ConnectivityModifyCommandResponse> - extends ConnectivityCommandResponse, WithOptionalEntity, WithConnectionId, SignalWithEntityId { + extends ConnectivityCommandResponse, WithOptionalEntity, WithConnectionId, SignalWithEntityId { @Override T setDittoHeaders(DittoHeaders dittoHeaders); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnection.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnection.java index 54f5cb45fb..8bb659adc6 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnection.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnection.java @@ -15,6 +15,7 @@ import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; import java.util.Objects; +import java.util.Optional; import java.util.function.Predicate; import javax.annotation.Nullable; @@ -35,6 +36,7 @@ import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Command which creates a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -135,6 +137,16 @@ public Category getCategory() { return Category.CREATE; } + @Override + public Optional getEntity(final JsonSchemaVersion schemaVersion) { + return Optional.of(connection.toJson(schemaVersion, FieldType.regularOrSpecial())); + } + + @Override + public CreateConnection setEntity(final JsonValue entity) { + return of(ConnectivityModelFactory.connectionFromJson(entity.asObject()), getDittoHeaders()); + } + @Override public CreateConnection setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connection, dittoHeaders); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnectionResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnectionResponse.java index 2a57b54a13..32c81421e1 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnectionResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/CreateConnectionResponse.java @@ -138,6 +138,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(connection.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public CreateConnectionResponse setEntity(final JsonValue entity) { + return of(ConnectivityModelFactory.connectionFromJson(entity.asObject()), getDittoHeaders()); + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnection.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnection.java index de2d1e39fd..d2130c1de6 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnection.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnection.java @@ -20,17 +20,18 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; +import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Command which deletes a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -127,6 +128,11 @@ public DeleteConnection setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public DeleteConnection setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return (other instanceof DeleteConnection); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnectionResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnectionResponse.java index 5e7bc51b0d..ed55140674 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnectionResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/DeleteConnectionResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link DeleteConnection} command. @@ -142,6 +143,11 @@ public DeleteConnectionResponse setDittoHeaders(final DittoHeaders dittoHeaders) return of(connectionId, dittoHeaders); } + @Override + public DeleteConnectionResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeleteConnectionResponse; diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogs.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogs.java index 29e0c54a8d..8ce82852ae 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogs.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogs.java @@ -21,18 +21,19 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonValue; /** * Command that will enable logging in a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -127,6 +128,11 @@ public EnableConnectionLogs setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public EnableConnectionLogs setEntity(final JsonValue entity) { + return this; + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/command"); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogsResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogsResponse.java index b0ecc5ac31..4759be3edf 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogsResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/EnableConnectionLogsResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link EnableConnectionLogs} command. @@ -138,6 +139,11 @@ public EnableConnectionLogsResponse setDittoHeaders(final DittoHeaders dittoHead return of(connectionId, dittoHeaders); } + @Override + public EnableConnectionLogsResponse setEntity(final JsonValue entity) { + return this; + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/command"); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/LoggingExpired.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/LoggingExpired.java index f3d2a5ec88..9fb13ab259 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/LoggingExpired.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/LoggingExpired.java @@ -21,17 +21,18 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; +import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Command that will enable logging in a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -143,6 +144,11 @@ public LoggingExpired setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public LoggingExpired setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return (other instanceof LoggingExpired); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnection.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnection.java index 6332465f69..f57b338421 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnection.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnection.java @@ -15,26 +15,28 @@ import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; import java.util.Objects; +import java.util.Optional; import java.util.function.Predicate; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.connectivity.model.Connection; import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.ConnectivityModelFactory; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Command which modifies a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -136,6 +138,16 @@ public Category getCategory() { return Category.MODIFY; } + @Override + public Optional getEntity(final JsonSchemaVersion schemaVersion) { + return Optional.of(connection.toJson(schemaVersion, FieldType.regularOrSpecial())); + } + + @Override + public ModifyConnection setEntity(final JsonValue entity) { + return of(ConnectivityModelFactory.connectionFromJson(entity.asObject()), getDittoHeaders()); + } + @Override public ModifyConnection setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connection, dittoHeaders); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnectionResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnectionResponse.java index a76fcbbab2..20c8abbcd3 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnectionResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ModifyConnectionResponse.java @@ -139,6 +139,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.empty(); } + @Override + public ModifyConnectionResponse setEntity(final JsonValue entity) { + return this; + } + @Override public ModifyConnectionResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnection.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnection.java index f177685645..88d06c004d 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnection.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnection.java @@ -20,18 +20,19 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonValue; /** * Command which opens a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -133,6 +134,11 @@ public OpenConnection setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public OpenConnection setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return (other instanceof OpenConnection); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnectionResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnectionResponse.java index 034568c2bf..ed74baa6f4 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnectionResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/OpenConnectionResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link OpenConnection} command. @@ -142,6 +143,11 @@ public OpenConnectionResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public OpenConnectionResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof OpenConnectionResponse; diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogs.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogs.java index a376332ce9..1082d23947 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogs.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogs.java @@ -21,18 +21,19 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonValue; /** * Command that will reset logging for a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -127,6 +128,11 @@ public ResetConnectionLogs setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public ResetConnectionLogs setEntity(final JsonValue entity) { + return this; + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/command"); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogsResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogsResponse.java index 0ca6670812..48cc8d3017 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogsResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionLogsResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link ResetConnectionLogs} command. @@ -137,6 +138,11 @@ public ResetConnectionLogsResponse setDittoHeaders(final DittoHeaders dittoHeade return of(connectionId, dittoHeaders); } + @Override + public ResetConnectionLogsResponse setEntity(final JsonValue entity) { + return this; + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/command"); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetrics.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetrics.java index 97c908af70..fdbf1c9ea3 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetrics.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetrics.java @@ -20,18 +20,19 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.connectivity.model.ConnectionId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonValue; /** * Command which resets the complete {@code Metrics} of a {@link org.eclipse.ditto.connectivity.model.Connection}. @@ -133,6 +134,11 @@ public ResetConnectionMetrics setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connectionId, dittoHeaders); } + @Override + public ResetConnectionMetrics setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return (other instanceof ResetConnectionMetrics); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetricsResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetricsResponse.java index b1f68a6aa7..f504fd819a 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetricsResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/ResetConnectionMetricsResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link ResetConnectionMetrics} command. @@ -146,6 +147,11 @@ public ResetConnectionMetricsResponse setDittoHeaders(final DittoHeaders dittoHe return of(connectionId, dittoHeaders); } + @Override + public ResetConnectionMetricsResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof ResetConnectionMetricsResponse; diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnection.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnection.java index de220951db..b0c3d08bc9 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnection.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnection.java @@ -15,26 +15,28 @@ import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; import java.util.Objects; +import java.util.Optional; import java.util.function.Predicate; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.connectivity.model.Connection; import org.eclipse.ditto.connectivity.model.ConnectionId; import org.eclipse.ditto.connectivity.model.ConnectivityModelFactory; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Command which test whether a {@link org.eclipse.ditto.connectivity.model.Connection} can successfully be established (e.g. by connecting to the endpoint, @@ -137,6 +139,16 @@ public Category getCategory() { return Category.QUERY; } + @Override + public Optional getEntity(final JsonSchemaVersion schemaVersion) { + return Optional.of(connection.toJson(schemaVersion, FieldType.regularOrSpecial())); + } + + @Override + public TestConnection setEntity(final JsonValue entity) { + return of(ConnectivityModelFactory.connectionFromJson(entity.asObject()), getDittoHeaders()); + } + @Override public TestConnection setDittoHeaders(final DittoHeaders dittoHeaders) { return of(connection, dittoHeaders); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnectionResponse.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnectionResponse.java index bd42694893..b02b87dfbf 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnectionResponse.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/commands/modify/TestConnectionResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonValue; /** * Response to a {@link TestConnection} command. @@ -177,6 +178,11 @@ public TestConnectionResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return success(connectionId, testResult, dittoHeaders); } + @Override + public TestConnectionResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof TestConnectionResponse; diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionClosed.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionClosed.java index 104b63c86b..460ba3c5a9 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionClosed.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionClosed.java @@ -31,6 +31,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a {@link org.eclipse.ditto.connectivity.model.Connection} was closed. @@ -127,8 +128,12 @@ public ConnectionClosed setRevision(final long revision) { @Override public ConnectionClosed setDittoHeaders(final DittoHeaders dittoHeaders) { - return of(getEntityId(), getRevision(), getTimestamp().orElse(null), dittoHeaders, - getMetadata().orElse(null)); + return this; + } + + @Override + public ConnectionClosed setEntity(final JsonValue entity) { + return this; } @Override diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionCreated.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionCreated.java index 7cbc465b47..029ad283de 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionCreated.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionCreated.java @@ -136,6 +136,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(connection.toJson(schemaVersion)); } + @Override + public ConnectionCreated setEntity(final JsonValue entity) { + return of(ConnectivityModelFactory.connectionFromJson(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionDeleted.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionDeleted.java index 021d462dd6..c655e04b72 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionDeleted.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionDeleted.java @@ -31,6 +31,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a {@link org.eclipse.ditto.connectivity.model.Connection} was deleted. @@ -130,6 +131,11 @@ public ConnectionDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public ConnectionDeleted setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionModified.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionModified.java index e6222d7f25..e8eaf280ac 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionModified.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionModified.java @@ -135,6 +135,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(connection.toJson(schemaVersion)); } + @Override + public ConnectionModified setEntity(final JsonValue entity) { + return of(ConnectivityModelFactory.connectionFromJson(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionOpened.java b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionOpened.java index 46b8ba5623..c116d67504 100644 --- a/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionOpened.java +++ b/connectivity/model/src/main/java/org/eclipse/ditto/connectivity/model/signals/events/ConnectionOpened.java @@ -31,6 +31,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a {@link org.eclipse.ditto.connectivity.model.Connection} was opened. @@ -130,6 +131,11 @@ public ConnectionOpened setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public ConnectionOpened setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/edge/service/src/main/java/org/eclipse/ditto/edge/service/placeholders/ImmutableFeaturePlaceholder.java b/edge/service/src/main/java/org/eclipse/ditto/edge/service/placeholders/ImmutableFeaturePlaceholder.java index cce7444e0c..a3b65f2dbf 100644 --- a/edge/service/src/main/java/org/eclipse/ditto/edge/service/placeholders/ImmutableFeaturePlaceholder.java +++ b/edge/service/src/main/java/org/eclipse/ditto/edge/service/placeholders/ImmutableFeaturePlaceholder.java @@ -70,7 +70,7 @@ private static List resolveIdPlaceholder(final Signal signal) { featureIds = Collections.singletonList((withFeatureId).getFeatureId()); } else if (signal instanceof ThingModifyCommand || signal instanceof ThingModifiedEvent || signal instanceof ThingModifyCommandResponse) { - featureIds = ((WithOptionalEntity) signal).getEntity() + featureIds = ((WithOptionalEntity) signal).getEntity() .map(value -> resolveFeatureIds(signal.getResourcePath(), value)) .orElseGet(List::of); } else { diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/actors/AbstractHttpRequestActor.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/actors/AbstractHttpRequestActor.java index 445022ef34..6928aa31aa 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/actors/AbstractHttpRequestActor.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/actors/AbstractHttpRequestActor.java @@ -27,6 +27,28 @@ import javax.annotation.Nullable; +import org.apache.pekko.Done; +import org.apache.pekko.actor.AbstractActor; +import org.apache.pekko.actor.ActorRef; +import org.apache.pekko.actor.Cancellable; +import org.apache.pekko.actor.CoordinatedShutdown; +import org.apache.pekko.actor.ReceiveTimeout; +import org.apache.pekko.actor.Status; +import org.apache.pekko.http.javadsl.model.ContentTypes; +import org.apache.pekko.http.javadsl.model.HttpEntities; +import org.apache.pekko.http.javadsl.model.HttpHeader; +import org.apache.pekko.http.javadsl.model.HttpRequest; +import org.apache.pekko.http.javadsl.model.HttpResponse; +import org.apache.pekko.http.javadsl.model.StatusCodes; +import org.apache.pekko.http.javadsl.model.Uri; +import org.apache.pekko.http.javadsl.model.headers.Location; +import org.apache.pekko.http.javadsl.model.headers.RawHeader; +import org.apache.pekko.http.scaladsl.model.ContentType$; +import org.apache.pekko.http.scaladsl.model.EntityStreamSizeException; +import org.apache.pekko.japi.pf.ReceiveBuilder; +import org.apache.pekko.pattern.AskTimeoutException; +import org.apache.pekko.pattern.Patterns; +import org.apache.pekko.util.ByteString; import org.eclipse.ditto.base.api.devops.signals.commands.DevOpsCommand; import org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel; import org.eclipse.ditto.base.model.common.HttpStatus; @@ -65,37 +87,15 @@ import org.eclipse.ditto.gateway.service.util.config.endpoints.CommandConfig; import org.eclipse.ditto.gateway.service.util.config.endpoints.HttpConfig; import org.eclipse.ditto.internal.models.signal.correlation.MatchingValidationResult; +import org.eclipse.ditto.internal.utils.cluster.JsonValueSourceRef; import org.eclipse.ditto.internal.utils.pekko.actors.AbstractActorWithShutdownBehavior; import org.eclipse.ditto.internal.utils.pekko.logging.DittoDiagnosticLoggingAdapter; import org.eclipse.ditto.internal.utils.pekko.logging.DittoLoggerFactory; -import org.eclipse.ditto.internal.utils.cluster.JsonValueSourceRef; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonRuntimeException; import org.eclipse.ditto.messages.model.Message; import org.eclipse.ditto.messages.model.signals.commands.MessageCommandResponse; -import org.apache.pekko.Done; -import org.apache.pekko.actor.AbstractActor; -import org.apache.pekko.actor.ActorRef; -import org.apache.pekko.actor.Cancellable; -import org.apache.pekko.actor.CoordinatedShutdown; -import org.apache.pekko.actor.ReceiveTimeout; -import org.apache.pekko.actor.Status; -import org.apache.pekko.http.javadsl.model.ContentTypes; -import org.apache.pekko.http.javadsl.model.HttpEntities; -import org.apache.pekko.http.javadsl.model.HttpHeader; -import org.apache.pekko.http.javadsl.model.HttpRequest; -import org.apache.pekko.http.javadsl.model.HttpResponse; -import org.apache.pekko.http.javadsl.model.StatusCodes; -import org.apache.pekko.http.javadsl.model.Uri; -import org.apache.pekko.http.javadsl.model.headers.Location; -import org.apache.pekko.http.javadsl.model.headers.RawHeader; -import org.apache.pekko.http.scaladsl.model.ContentType$; -import org.apache.pekko.http.scaladsl.model.EntityStreamSizeException; -import org.apache.pekko.japi.pf.ReceiveBuilder; -import org.apache.pekko.pattern.AskTimeoutException; -import org.apache.pekko.pattern.Patterns; -import org.apache.pekko.util.ByteString; import scala.Option; import scala.util.Either; @@ -468,7 +468,7 @@ private void handleCommandResponseWithOptionalEntity(final CommandResponse co rememberResponseLocationUri(commandResponse); completeWithResult(createCommandResponse(commandResponse.getDittoHeaders(), commandResponse.getHttpStatus(), - (WithOptionalEntity) commandResponse)); + (WithOptionalEntity) commandResponse)); } private HttpResponse handleMessageResponseMessage(final MessageCommandResponse messageCommandResponse) { @@ -664,7 +664,7 @@ private HttpResponse createCommandResponse(final DittoHeaders dittoHeaders, fina } private static UnaryOperator createBodyAddingResponseMapper(final DittoHeaders dittoHeaders, - final WithOptionalEntity withOptionalEntity) { + final WithOptionalEntity withOptionalEntity) { return response -> { if (StatusCodes.NO_CONTENT.equals(response.status())) { diff --git a/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/EndpointTestBase.java b/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/EndpointTestBase.java index ca4244197c..3a73685577 100755 --- a/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/EndpointTestBase.java +++ b/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/EndpointTestBase.java @@ -12,8 +12,8 @@ */ package org.eclipse.ditto.gateway.service.endpoints; -import static org.apache.pekko.http.javadsl.model.ContentTypes.APPLICATION_JSON; import static java.util.Objects.requireNonNull; +import static org.apache.pekko.http.javadsl.model.ContentTypes.APPLICATION_JSON; import java.util.Collections; import java.util.Optional; @@ -23,6 +23,19 @@ import javax.annotation.Nullable; +import org.apache.pekko.actor.AbstractActor; +import org.apache.pekko.actor.ActorRef; +import org.apache.pekko.actor.ActorSystem; +import org.apache.pekko.actor.Props; +import org.apache.pekko.http.javadsl.model.HttpEntities; +import org.apache.pekko.http.javadsl.model.HttpRequest; +import org.apache.pekko.http.javadsl.model.HttpResponse; +import org.apache.pekko.http.javadsl.model.StatusCodes; +import org.apache.pekko.http.javadsl.server.Route; +import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest; +import org.apache.pekko.http.javadsl.testkit.TestRouteResult; +import org.apache.pekko.japi.pf.ReceiveBuilder; +import org.apache.pekko.testkit.TestProbe; import org.eclipse.ditto.base.model.common.HttpStatus; import org.eclipse.ditto.base.model.correlationid.TestNameCorrelationId; import org.eclipse.ditto.base.model.headers.DittoHeaders; @@ -79,20 +92,6 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; -import org.apache.pekko.actor.AbstractActor; -import org.apache.pekko.actor.ActorRef; -import org.apache.pekko.actor.ActorSystem; -import org.apache.pekko.actor.Props; -import org.apache.pekko.http.javadsl.model.HttpEntities; -import org.apache.pekko.http.javadsl.model.HttpRequest; -import org.apache.pekko.http.javadsl.model.HttpResponse; -import org.apache.pekko.http.javadsl.model.StatusCodes; -import org.apache.pekko.http.javadsl.server.Route; -import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest; -import org.apache.pekko.http.javadsl.testkit.TestRouteResult; -import org.apache.pekko.japi.pf.ReceiveBuilder; -import org.apache.pekko.testkit.TestProbe; - /** * Abstract base class for Endpoint tests for the gateway. */ @@ -266,7 +265,7 @@ public Receive createReceive() { protected static final class DummyThingModifyCommandResponse extends AbstractCommandResponse - implements ThingCommandResponse, WithOptionalEntity { + implements ThingCommandResponse, WithOptionalEntity { private JsonValue dummyEntity = DEFAULT_DUMMY_ENTITY_JSON; @@ -322,6 +321,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(dummyEntity); } + @Override + public DummyThingModifyCommandResponse setEntity(final JsonValue entity) { + return this; + } + @Override public ThingId getEntityId() { return EndpointTestConstants.KNOWN_THING_ID; diff --git a/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/ConditionalHeadersValidator.java b/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/ConditionalHeadersValidator.java index 89b909322f..d39c967c88 100644 --- a/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/ConditionalHeadersValidator.java +++ b/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/ConditionalHeadersValidator.java @@ -183,7 +183,7 @@ private void checkIfNoneMatch(final Command command, @Nullable final EntityTa private > C applyIfEqual(final C command, @Nullable final Entity entity) { return IfEqualPreconditionHeader.fromDittoHeaders(command, validationSettings) - .map(ifEqual -> ifEqual.handleCommand(() -> ifEqual.meetsConditionFor(entity))) + .map(ifEqual -> ifEqual.handleCommand(() -> ifEqual.meetsConditionFor(entity), entity)) .orElse(command); } diff --git a/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java b/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java index 7385f4c800..aeef281236 100644 --- a/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java +++ b/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java @@ -33,7 +33,9 @@ import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonKey; +import org.eclipse.ditto.json.JsonMergePatch; import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; /** @@ -108,12 +110,12 @@ public boolean meetsConditionFor(@Nullable final Entity entity) { return false; } - if (ifEqual == IfEqual.SKIP) { + if (ifEqual == IfEqual.SKIP || ifEqual == IfEqual.SKIP_MINIMIZING_MERGE) { if (command.getCategory() == Command.Category.MODIFY && - command instanceof WithOptionalEntity withOptionalEntity) { + command instanceof WithOptionalEntity withOptionalEntity) { return meetsConditionForModifyCommand(entity, withOptionalEntity); } else if (command.getCategory() == Command.Category.MERGE && - command instanceof WithOptionalEntity withOptionalEntity) { + command instanceof WithOptionalEntity withOptionalEntity) { return meetsConditionForMergeCommand(entity, withOptionalEntity); } else { // other commands to "MODIFY" and "MERGE" do never match the "if-equal" precondition header @@ -126,23 +128,29 @@ public boolean meetsConditionFor(@Nullable final Entity entity) { } private Boolean meetsConditionForModifyCommand(final Entity entity, - final WithOptionalEntity withOptionalEntity) { + final WithOptionalEntity withOptionalEntity) { return withOptionalEntity.getEntity() .map(newValue -> { - final Predicate nonHiddenAndNamespace = - FieldType.notHidden() - .or(jsonField -> jsonField.getKey().equals(JsonKey.of("_namespace"))); + final Predicate fieldPredicate = calculatePredicate(command.getResourcePath()); final Optional previousValue = - entity.toJson(JsonSchemaVersion.LATEST, nonHiddenAndNamespace) + entity.toJson(JsonSchemaVersion.LATEST, fieldPredicate) .getValue(command.getResourcePath()); - return previousValue.filter(jsonValue -> jsonValue.equals(newValue)) + final JsonValue adjustedNewValue; + if (newValue.isObject()) { + adjustedNewValue = newValue.asObject() + .filter(calculatePredicateForNew(command.getResourcePath())); + } else { + adjustedNewValue = newValue; + } + return previousValue.filter(jsonValue -> jsonValue.equals(adjustedNewValue)) .isPresent(); }) .orElse(false); } - private Boolean meetsConditionForMergeCommand(final Entity entity, final WithOptionalEntity withOptionalEntity) { + private Boolean meetsConditionForMergeCommand(final Entity entity, + final WithOptionalEntity withOptionalEntity) { return withOptionalEntity.getEntity() .map(newValue -> { @@ -150,10 +158,9 @@ private Boolean meetsConditionForMergeCommand(final Entity entity, final With if (newValue.isObject()) { final JsonObject newObject; if (command.getResourcePath().isEmpty()) { - // filter "special fields" for e.g. on thing level the inline "_policy": newObject = newValue.asObject() .stream() - .filter(jsonField -> !jsonField.getKeyName().startsWith("_")) + .filter(calculatePredicateForNew(command.getResourcePath())) .collect(JsonCollectors.fieldsToObject()); } else { newObject = newValue.asObject(); @@ -183,18 +190,30 @@ private Boolean meetsConditionForMergeCommand(final Entity entity, final With * Handles the {@link #command} field of this class by invoking the passed {@code isCompletelyEqualSupplier} to * check whether the affected entity would be completely equal after applying the {@link #command}. * + * @param isCompletelyEqualSupplier a boolean supplier for evaluating lazily whether this command's modifications + * would lead to the equal entity than it was before. + * @param entity the previous entity. * @return the potentially adjusted Command. */ - C handleCommand(final BooleanSupplier isCompletelyEqualSupplier) { + C handleCommand(final BooleanSupplier isCompletelyEqualSupplier, @Nullable final Entity entity) { final C potentiallyAdjustedCommand; + final Command.Category category = command.getCategory(); if (ifEqual == IfEqual.UPDATE) { // default behavior - no change, just use the complete modify command, not matter what: potentiallyAdjustedCommand = command; + } else if (ifEqual == IfEqual.SKIP_MINIMIZING_MERGE && category == Command.Category.MERGE) { + // lazily check for equality as this might be expensive to do: + final boolean completelyEqual = isCompletelyEqualSupplier.getAsBoolean(); + if (completelyEqual) { + potentiallyAdjustedCommand = respondWithPreconditionFailed(); + } else { + // not completely equal and a merge command + potentiallyAdjustedCommand = adjustMergeCommandByOnlyKeepingChanges(command, entity); + } } else if (ifEqual == IfEqual.SKIP) { // lazily check for equality as this might be expensive to do: final boolean completelyEqual = isCompletelyEqualSupplier.getAsBoolean(); - final Command.Category category = command.getCategory(); if (completelyEqual && (category == Command.Category.MODIFY || category == Command.Category.MERGE)) { potentiallyAdjustedCommand = respondWithPreconditionFailed(); @@ -207,6 +226,58 @@ C handleCommand(final BooleanSupplier isCompletelyEqualSupplier) { return potentiallyAdjustedCommand; } + private C adjustMergeCommandByOnlyKeepingChanges(final C command, @Nullable final Entity entity) { + if (null != entity && command instanceof WithOptionalEntity withOptionalEntity) { + return adjustMergeCommandByOnlyKeepingChanges(command, entity, withOptionalEntity); + } else { + return command; + } + } + + private C adjustMergeCommandByOnlyKeepingChanges(final C command, + final Entity entity, + final WithOptionalEntity withOptionalEntity) { + + return withOptionalEntity.getEntity() + .map(newValue -> { + final Predicate fieldPredicate = calculatePredicate(command.getResourcePath()); + final JsonValue oldValue = entity.toJson(JsonSchemaVersion.LATEST, fieldPredicate) + .getValue(command.getResourcePath()).orElse(null); + if (null == oldValue) { + return command; + } else if (command instanceof WithOptionalEntity commandWithEntity) { + return JsonMergePatch.compute(oldValue, newValue) + .map(jsonMergePatch -> { + final JsonValue jsonValue = jsonMergePatch.asJsonValue(); + return (C) commandWithEntity.setEntity(jsonValue); + }) + .orElse(command); + } else { + return command; + } + }) + .orElse(command); + } + + private static Predicate calculatePredicate(final JsonPointer resourcePath) { + if (resourcePath.isEmpty()) { + return FieldType.notHidden() + .and(Predicate.not(jsonField -> jsonField.getKey().equals(JsonKey.of("thingId")))) + .and(Predicate.not(jsonField -> jsonField.getKey().equals(JsonKey.of("policyId")))); + } else { + return FieldType.notHidden(); + } + } + + private static Predicate calculatePredicateForNew(final JsonPointer resourcePath) { + if (resourcePath.isEmpty()) { + // filter "special fields" for e.g. on thing level the inline "_policy": + return jsonField -> !jsonField.getKeyName().startsWith("_"); + } else { + return jsonField -> true; + } + } + private C respondWithPreconditionFailed() { throw validationSettings .createPreconditionFailedForEqualityExceptionBuilder() diff --git a/internal/utils/persistent-actors/src/main/java/org/eclipse/ditto/internal/utils/persistentactors/EmptyEvent.java b/internal/utils/persistent-actors/src/main/java/org/eclipse/ditto/internal/utils/persistentactors/EmptyEvent.java index 51d6a0430e..9c2daf89ab 100644 --- a/internal/utils/persistent-actors/src/main/java/org/eclipse/ditto/internal/utils/persistentactors/EmptyEvent.java +++ b/internal/utils/persistent-actors/src/main/java/org/eclipse/ditto/internal/utils/persistentactors/EmptyEvent.java @@ -109,6 +109,11 @@ public EmptyEvent setDittoHeaders(final DittoHeaders dittoHeaders) { return new EmptyEvent(effect, revision, dittoHeaders); } + @Override + public EmptyEvent setEntity(final JsonValue entity) { + return this; + } + @Override public String getType() { return TYPE; @@ -156,4 +161,5 @@ public String toString() { ", dittoHeaders=" + dittoHeaders + "]"; } + } diff --git a/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java b/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java index 415ecfac59..09d96353b0 100644 --- a/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java +++ b/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java @@ -146,7 +146,7 @@ private static JsonObject mergeJsonObjects(final JsonObject jsonObject1, final J return JsonFactory.nullObject(); } - final JsonObjectBuilder builder = JsonFactory.newObjectBuilder(); + final JsonObjectBuilder builder = jsonObject2.toBuilder(); // add fields of jsonObject1 jsonObject1.forEach(jsonField -> { final JsonKey key = jsonField.getKey(); @@ -154,9 +154,8 @@ private static JsonObject mergeJsonObjects(final JsonObject jsonObject1, final J final Optional maybeValue2 = jsonObject2.getValue(key); if (value1.isNull()) { - return; - } - if (maybeValue2.isPresent()) { + builder.remove(key); + } else if (maybeValue2.isPresent()) { builder.set(key, mergeJsonValues(value1, maybeValue2.get())); } else { if (value1.isObject()) { @@ -171,8 +170,8 @@ private static JsonObject mergeJsonObjects(final JsonObject jsonObject1, final J // add fields of jsonObject2 not present in jsonObject1 jsonObject2.forEach(jsonField -> { - if (!jsonObject1.contains(jsonField.getKey()) && !toBeNulledKeysByRegex.contains(jsonField.getKey())) { - builder.set(jsonField); + if (!jsonObject1.contains(jsonField.getKey()) && toBeNulledKeysByRegex.contains(jsonField.getKey())) { + builder.remove(jsonField.getKey()); } }); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegration.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegration.java index 9ed2b7023c..9f6797c560 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegration.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegration.java @@ -27,6 +27,14 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.auth.AuthorizationContext; +import org.eclipse.ditto.base.model.common.HttpStatus; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonArray; import org.eclipse.ditto.json.JsonCollectors; import org.eclipse.ditto.json.JsonFactory; @@ -37,12 +45,6 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.auth.AuthorizationContext; -import org.eclipse.ditto.base.model.common.HttpStatus; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.EffectedPermissions; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesResourceType; @@ -52,8 +54,6 @@ import org.eclipse.ditto.policies.model.SubjectAnnouncement; import org.eclipse.ditto.policies.model.SubjectExpiry; import org.eclipse.ditto.policies.model.SubjectId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; import org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyActionFailedException; @@ -279,6 +279,11 @@ public ActivateTokenIntegration setDittoHeaders(final DittoHeaders dittoHeaders) dittoHeaders); } + @Override + public ActivateTokenIntegration setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof ActivateTokenIntegration; @@ -317,4 +322,5 @@ public String toString() { ", subjectAnnouncement=" + subjectAnnouncement + "]"; } + } diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegrationResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegrationResponse.java index c50838b271..f49ecba11a 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegrationResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/ActivateTokenIntegrationResponse.java @@ -25,6 +25,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.common.HttpStatus; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommandResponse; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; import org.eclipse.ditto.json.JsonArray; import org.eclipse.ditto.json.JsonCollectors; import org.eclipse.ditto.json.JsonFactory; @@ -35,16 +41,10 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.common.HttpStatus; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommandResponse; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.Policy; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.SubjectId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; /** @@ -157,6 +157,11 @@ public ActivateTokenIntegrationResponse setDittoHeaders(final DittoHeaders ditto return new ActivateTokenIntegrationResponse(policyId, label, subjectIds, dittoHeaders); } + @Override + public ActivateTokenIntegrationResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof ActivateTokenIntegrationResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegration.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegration.java index 0ea1927300..866b3ea1d3 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegration.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegration.java @@ -25,6 +25,14 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.auth.AuthorizationContext; +import org.eclipse.ditto.base.model.common.HttpStatus; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonArray; import org.eclipse.ditto.json.JsonCollectors; import org.eclipse.ditto.json.JsonFactory; @@ -35,21 +43,13 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.auth.AuthorizationContext; -import org.eclipse.ditto.base.model.common.HttpStatus; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.Policy; import org.eclipse.ditto.policies.model.PolicyEntry; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.SubjectId; -import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; +import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; import org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyActionFailedException; /** @@ -200,6 +200,11 @@ public DeactivateTokenIntegration setDittoHeaders(final DittoHeaders dittoHeader return new DeactivateTokenIntegration(policyId, label, subjectIds, dittoHeaders); } + @Override + public DeactivateTokenIntegration setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeactivateTokenIntegration; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegrationResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegrationResponse.java index 9f45e359aa..57031ba28a 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegrationResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/DeactivateTokenIntegrationResponse.java @@ -20,6 +20,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.common.HttpStatus; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommandResponse; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -27,15 +33,10 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.common.HttpStatus; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommandResponse; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.Policy; import org.eclipse.ditto.policies.model.PolicyId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; /** @@ -134,6 +135,11 @@ public DeactivateTokenIntegrationResponse setDittoHeaders(final DittoHeaders dit return new DeactivateTokenIntegrationResponse(policyId, label, dittoHeaders); } + @Override + public DeactivateTokenIntegrationResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeactivateTokenIntegrationResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommand.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommand.java index ca89fc7252..1807eb5fc4 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommand.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommand.java @@ -14,13 +14,13 @@ import java.util.Set; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.auth.AuthorizationContext; import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.signals.WithOptionalEntity; +import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyEntry; import org.eclipse.ditto.policies.model.SubjectId; -import org.eclipse.ditto.base.model.signals.WithOptionalEntity; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; import org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyActionFailedException; @@ -30,7 +30,7 @@ * @param the type of the implementing class. * @since 2.0.0 */ -public interface PolicyActionCommand> extends PolicyCommand, WithOptionalEntity { +public interface PolicyActionCommand> extends PolicyCommand, WithOptionalEntity { /** * Path of Policy actions as part of the {@link #getResourcePath()}. diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommandResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommandResponse.java index 09e7ef9e66..af396bfd06 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommandResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/PolicyActionCommandResponse.java @@ -12,8 +12,8 @@ */ package org.eclipse.ditto.policies.model.signals.commands.actions; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.signals.WithOptionalEntity; +import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; /** @@ -23,7 +23,7 @@ * @since 2.0.0 */ public interface PolicyActionCommandResponse> extends - PolicyCommandResponse, WithOptionalEntity { + PolicyCommandResponse, WithOptionalEntity { /** * Path of Policy actions as part of the the {@link #getResourcePath()}. diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommand.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommand.java index 4567104925..a2c74cdb70 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommand.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommand.java @@ -26,6 +26,14 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.auth.AuthorizationContext; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.JsonParsable; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonArray; import org.eclipse.ditto.json.JsonCollectors; import org.eclipse.ditto.json.JsonFactory; @@ -37,18 +45,10 @@ import org.eclipse.ditto.json.JsonParseException; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.auth.AuthorizationContext; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyEntry; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.SubjectId; -import org.eclipse.ditto.base.model.signals.JsonParsable; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; import org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyActionFailedException; @@ -209,6 +209,11 @@ public TopLevelPolicyActionCommand setDittoHeaders(final DittoHeaders dittoHeade return new TopLevelPolicyActionCommand(policyActionCommand.setDittoHeaders(dittoHeaders), authorizedLabels); } + @Override + public TopLevelPolicyActionCommand setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof TopLevelPolicyActionCommand; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommandResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommandResponse.java index 2fc2d63aea..a6e5d579ff 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommandResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/actions/TopLevelPolicyActionCommandResponse.java @@ -20,16 +20,17 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.common.HttpStatus; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableCommandResponse; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommandResponse; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; /** @@ -113,6 +114,11 @@ public TopLevelPolicyActionCommandResponse setDittoHeaders(final DittoHeaders di return new TopLevelPolicyActionCommandResponse(policyId, dittoHeaders); } + @Override + public TopLevelPolicyActionCommandResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof TopLevelPolicyActionCommandResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicy.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicy.java index b8e04edd69..58cddc4457 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicy.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicy.java @@ -79,7 +79,8 @@ private CreatePolicy(final Policy policy, final DittoHeaders dittoHeaders) { final JsonObject policyJsonObject = policy.toJson(); - PolicyImportsValidator.validatePolicyImports(policy.getEntityId().get(), policy.getPolicyImports()); + PolicyImportsValidator.validatePolicyImports(policy.getEntityId().orElse(null), + policy.getPolicyImports()); PolicyCommandSizeValidator.getInstance().ensureValidSize( policyJsonObject::getUpperBoundForStringSize, @@ -152,6 +153,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policy.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public CreatePolicy setEntity(final JsonValue entity) { + return of(PoliciesModelFactory.newPolicy(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicyResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicyResponse.java index 438b8b8c44..5e1dae5513 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicyResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/CreatePolicyResponse.java @@ -177,6 +177,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(policyCreated).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public CreatePolicyResponse setEntity(final JsonValue entity) { + return newInstance(policyId, PoliciesModelFactory.newPolicy(entity.asObject()), getHttpStatus(), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicy.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicy.java index d797a11d2f..1d17d52692 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicy.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicy.java @@ -18,18 +18,19 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command deletes a {@link org.eclipse.ditto.policies.model.Policy}. @@ -135,6 +136,11 @@ public DeletePolicy setDittoHeaders(final DittoHeaders dittoHeaders) { return of(policyId, dittoHeaders); } + @Override + public DeletePolicy setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeletePolicy; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntry.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntry.java index d49e371a10..b91198f021 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntry.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntry.java @@ -18,22 +18,23 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command deletes a {@link org.eclipse.ditto.policies.model.PolicyEntry}. @@ -160,6 +161,11 @@ public DeletePolicyEntry setDittoHeaders(final DittoHeaders dittoHeaders) { return of(policyId, label, dittoHeaders); } + @Override + public DeletePolicyEntry setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeletePolicyEntry; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntryResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntryResponse.java index 87679451ec..81a77026dd 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntryResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyEntryResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; @@ -186,6 +187,11 @@ public DeletePolicyEntryResponse setDittoHeaders(final DittoHeaders dittoHeaders return newInstance(policyId, label, getHttpStatus(), dittoHeaders); } + @Override + public DeletePolicyEntryResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeletePolicyEntryResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImport.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImport.java index cdbd7a9d33..4f4800bf09 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImport.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImport.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; @@ -158,6 +159,11 @@ public DeletePolicyImport setDittoHeaders(final DittoHeaders dittoHeaders) { return of(policyId, importedPolicyId, dittoHeaders); } + @Override + public DeletePolicyImport setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeletePolicyImport; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImportResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImportResponse.java index 6c177cb724..60cd12858b 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImportResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyImportResponse.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; @@ -169,6 +170,11 @@ public DeletePolicyImportResponse setDittoHeaders(final DittoHeaders dittoHeader return of(policyId, importedPolicyId, dittoHeaders); } + @Override + public DeletePolicyImportResponse setEntity(final JsonValue entity) { + return this; + } + @Override public PolicyId getEntityId() { return policyId; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyResponse.java index 6e15601cf6..49442b5859 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeletePolicyResponse.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; @@ -157,6 +158,11 @@ public DeletePolicyResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(policyId, getHttpStatus(), dittoHeaders); } + @Override + public DeletePolicyResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeletePolicyResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResource.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResource.java index 5aa290fe8b..4b2db42663 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResource.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResource.java @@ -18,23 +18,24 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.ResourceKey; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command deletes a {@link org.eclipse.ditto.policies.model.Resource} of a {@link @@ -158,7 +159,7 @@ public PolicyId getEntityId() { @Override public JsonPointer getResourcePath() { - final String p = "/entries/" + label + "/resources/" + resourceKey.toString(); + final String p = "/entries/" + label + "/resources/" + resourceKey; return JsonPointer.of(p); } @@ -182,6 +183,11 @@ public DeleteResource setDittoHeaders(final DittoHeaders dittoHeaders) { return of(policyId, label, resourceKey, dittoHeaders); } + @Override + public DeleteResource setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeleteResource; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResourceResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResourceResponse.java index ef5c86b012..1f0ad1c06e 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResourceResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteResourceResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; @@ -210,6 +211,11 @@ public DeleteResourceResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(policyId, label, resourceKey, getHttpStatus(), dittoHeaders); } + @Override + public DeleteResourceResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeleteResourceResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubject.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubject.java index 496b7e7157..9d68feab4f 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubject.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubject.java @@ -18,23 +18,24 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.SubjectId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command deletes a {@link org.eclipse.ditto.policies.model.Subject} of a {@link @@ -186,6 +187,11 @@ public DeleteSubject setDittoHeaders(final DittoHeaders dittoHeaders) { return of(policyId, label, subjectId, dittoHeaders); } + @Override + public DeleteSubject setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeleteSubject; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubjectResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubjectResponse.java index b9feaa6997..cb28146706 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubjectResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/DeleteSubjectResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; @@ -191,6 +192,11 @@ public DeleteSubjectResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(policyId, label, subjectId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteSubjectResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof DeleteSubjectResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicy.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicy.java index a95e862c23..283c003d5f 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicy.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicy.java @@ -19,6 +19,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -27,16 +33,10 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.Policy; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandSizeValidator; import org.eclipse.ditto.policies.model.signals.commands.PolicyImportsValidator; @@ -155,6 +155,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policy.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyPolicy setEntity(final JsonValue entity) { + return of(policyId, PoliciesModelFactory.newPolicy(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntries.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntries.java index 4a149f8245..7f01cccc01 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntries.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntries.java @@ -167,6 +167,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(jsonObject); } + @Override + public ModifyPolicyEntries setEntity(final JsonValue entity) { + return of(policyId, PoliciesModelFactory.newPolicyEntries(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/entries"); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntriesResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntriesResponse.java index e24f28393e..bcfd9b6616 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntriesResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntriesResponse.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; @@ -158,6 +159,11 @@ public ModifyPolicyEntriesResponse setDittoHeaders(final DittoHeaders dittoHeade return newInstance(policyId, getHttpStatus(), dittoHeaders); } + @Override + public ModifyPolicyEntriesResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntry.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntry.java index 62145d4b8d..7cf2b04282 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntry.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntry.java @@ -21,6 +21,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,16 +34,10 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyEntry; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandSizeValidator; /** @@ -159,6 +159,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyEntry.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyPolicyEntry setEntity(final JsonValue entity) { + return of(policyId, PoliciesModelFactory.newPolicyEntry(policyEntry.getLabel(), entity.asObject()), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + policyEntry.getLabel(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntryResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntryResponse.java index 36df6062b9..a6b333d926 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntryResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyEntryResponse.java @@ -239,6 +239,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(policyEntry).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyPolicyEntryResponse setEntity(final JsonValue entity) { + return newInstance(policyId, + getHttpStatus() == HttpStatus.CREATED ? PoliciesModelFactory.newPolicyEntry(label, entity.asObject()) : + null, + label, getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/entries/" + label); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImport.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImport.java index d8a5910c22..5029d69082 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImport.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImport.java @@ -149,6 +149,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyImport.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyPolicyImport setEntity(final JsonValue entity) { + return of(policyId, PoliciesModelFactory.newPolicyImport(policyImport.getImportedPolicyId(), entity.asObject()), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/imports/" + policyImport.getImportedPolicyId(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportResponse.java index b7304aec47..c2fc9567d3 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportResponse.java @@ -222,6 +222,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(policyImportCreated).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyPolicyImportResponse setEntity(final JsonValue entity) { + return newInstance(policyId, importedPolicyId, + getHttpStatus() == HttpStatus.CREATED ? + PoliciesModelFactory.newPolicyImport(importedPolicyId, entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { if (policyImportCreated == null) { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImports.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImports.java index e4b62dfbfe..d63af6028d 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImports.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImports.java @@ -144,6 +144,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyImports.toJson(schemaVersion)); } + @Override + public ModifyPolicyImports setEntity(final JsonValue entity) { + return of(policyId, PoliciesModelFactory.newPolicyImports(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/imports"); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportsResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportsResponse.java index 7757f2b4d4..227943ff26 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportsResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyImportsResponse.java @@ -195,6 +195,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(policyImportsCreated).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyPolicyImportsResponse setEntity(final JsonValue entity) { + return newInstance(policyId, + getHttpStatus() == HttpStatus.CREATED ? + PoliciesModelFactory.newPolicyImports(entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/imports"); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyResponse.java index 708e51f342..8005c748d7 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyPolicyResponse.java @@ -212,6 +212,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(policy).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyPolicyResponse setEntity(final JsonValue entity) { + return newInstance(policyId, + getHttpStatus() == HttpStatus.CREATED ? + PoliciesModelFactory.newPolicy(entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResource.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResource.java index 29bf82b77d..aabd422010 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResource.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResource.java @@ -19,6 +19,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -26,18 +32,12 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.Resource; import org.eclipse.ditto.policies.model.ResourceKey; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command modifies a {@link org.eclipse.ditto.policies.model.Resource} of a {@link org.eclipse.ditto.policies.model.PolicyEntry}'s {@link @@ -174,6 +174,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(resource.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyResource setEntity(final JsonValue entity) { + return of(policyId, label, PoliciesModelFactory.newResource(resource.getResourceKey(), entity), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resource.getResourceKey(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourceResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourceResponse.java index 0184f96908..bd4866debc 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourceResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourceResponse.java @@ -266,6 +266,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(resource).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyResourceResponse setEntity(final JsonValue entity) { + return newInstance(policyId, label, resourceKey, + getHttpStatus() == HttpStatus.CREATED ? PoliciesModelFactory.newResource(resourceKey, entity) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/entries/" + label + "/resources/" + resourceKey); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResources.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResources.java index cc366e90f4..9ecdfa89a4 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResources.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResources.java @@ -19,6 +19,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -26,18 +32,12 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.Resources; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandSizeValidator; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command modifies {@link org.eclipse.ditto.policies.model.Resources} of a {@link org.eclipse.ditto.policies.model.PolicyEntry}. @@ -175,6 +175,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(resources.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyResources setEntity(final JsonValue entity) { + return of(policyId, label, PoliciesModelFactory.newResources(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources"; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourcesResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourcesResponse.java index d5f6932296..e04ea83a93 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourcesResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifyResourcesResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; @@ -185,6 +186,11 @@ public ModifyResourcesResponse setDittoHeaders(final DittoHeaders dittoHeaders) return newInstance(policyId, label, getHttpStatus(), dittoHeaders); } + @Override + public ModifyResourcesResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof ModifyResourcesResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubject.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubject.java index b94cedcd4b..78a2b4729e 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubject.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubject.java @@ -19,6 +19,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -26,17 +32,11 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.Subject; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; /** * This command modifies a {@link org.eclipse.ditto.policies.model.Subject} of a {@link org.eclipse.ditto.policies.model.PolicyEntry}'s {@link @@ -171,6 +171,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subject.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifySubject setEntity(final JsonValue entity) { + return of(policyId, label, PoliciesModelFactory.newSubject(subject.getId(), entity.asObject()), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects/" + subject.getId(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectResponse.java index 97bbd4ccd6..5bea6898f4 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectResponse.java @@ -260,6 +260,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(subject).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifySubjectResponse setEntity(final JsonValue entity) { + return newInstance(policyId, label, subjectId, + getHttpStatus() == HttpStatus.CREATED ? + PoliciesModelFactory.newSubject(subjectId, entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/entries/" + label + "/subjects/" + subjectId); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjects.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjects.java index 24e73f6d37..a9e23b4052 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjects.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjects.java @@ -19,6 +19,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -26,17 +32,11 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.Subjects; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandSizeValidator; /** @@ -174,6 +174,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subjects.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifySubjects setEntity(final JsonValue entity) { + return of(policyId, label, PoliciesModelFactory.newSubjects(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects"; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectsResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectsResponse.java index a471faecd4..91e4140953 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectsResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/ModifySubjectsResponse.java @@ -34,6 +34,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.signals.commands.PolicyCommandResponse; @@ -185,6 +186,11 @@ public ModifySubjectsResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(policyId, label, getHttpStatus(), dittoHeaders); } + @Override + public ModifySubjectsResponse setEntity(final JsonValue entity) { + return this; + } + @Override protected boolean canEqual(@Nullable final Object other) { return other instanceof ModifySubjectsResponse; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommand.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommand.java index 772c7b121a..48505aa0fd 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommand.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommand.java @@ -21,7 +21,7 @@ * * @param the type of the implementing class. */ -public interface PolicyModifyCommand> extends PolicyCommand, WithOptionalEntity { +public interface PolicyModifyCommand> extends PolicyCommand, WithOptionalEntity { @Override T setDittoHeaders(DittoHeaders dittoHeaders); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommandResponse.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommandResponse.java index 9ffb541a45..70ba914326 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommandResponse.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/commands/modify/PolicyModifyCommandResponse.java @@ -21,5 +21,5 @@ * @param the type of the implementing class. */ public interface PolicyModifyCommandResponse> extends - PolicyCommandResponse, WithOptionalEntity { + PolicyCommandResponse, WithOptionalEntity { } diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyCreated.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyCreated.java index c1ffb71c8f..4ea9b01818 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyCreated.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyCreated.java @@ -139,6 +139,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policy.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public PolicyCreated setEntity(final JsonValue entity) { + return of(PoliciesModelFactory.newPolicy(entity.asObject()), getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyDeleted.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyDeleted.java index 3fc88ef7b3..48fa1cfe1f 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyDeleted.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyDeleted.java @@ -30,6 +30,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; /** @@ -127,6 +128,11 @@ public PolicyDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public PolicyDeleted setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate predicate) { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntriesModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntriesModified.java index 38438ad3a6..965dbc81cb 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntriesModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntriesModified.java @@ -155,6 +155,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(jsonObject); } + @Override + public PolicyEntriesModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), PoliciesModelFactory.newPolicyEntries(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/entries"); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryCreated.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryCreated.java index ec045a8fa4..3312768f16 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryCreated.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryCreated.java @@ -151,6 +151,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyEntry.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public PolicyEntryCreated setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), PoliciesModelFactory.newPolicyEntry(policyEntry.getLabel(), entity.asObject()), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + policyEntry.getLabel(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryDeleted.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryDeleted.java index bca60f1b35..65075067f9 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryDeleted.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyId; @@ -154,6 +155,11 @@ public PolicyEntryDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public PolicyEntryDeleted setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryModified.java index 0158bd9caa..5b087c1901 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyEntryModified.java @@ -150,6 +150,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyEntry.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public PolicyEntryModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), PoliciesModelFactory.newPolicyEntry(policyEntry.getLabel(), entity.asObject()), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + policyEntry.getLabel(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportCreated.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportCreated.java index f8c6124cc4..556e7ced91 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportCreated.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportCreated.java @@ -152,6 +152,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyImport.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public PolicyImportCreated setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), + PoliciesModelFactory.newPolicyImport(PolicyId.of(policyImport.getImportedPolicyId()), entity.asObject()), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/imports/" + policyImport.getImportedPolicyId(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportDeleted.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportDeleted.java index 8a9448869d..c047c10aa7 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportDeleted.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; /** @@ -155,6 +156,11 @@ public PolicyImportDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public PolicyImportDeleted setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportModified.java index 0b88e98a3b..e523cab30f 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportModified.java @@ -152,6 +152,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyImport.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public PolicyImportModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), + PoliciesModelFactory.newPolicyImport(PolicyId.of(policyImport.getImportedPolicyId()), entity.asObject()), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/imports/" + policyImport.getImportedPolicyId(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportsModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportsModified.java index 73f69e8807..4b0f77f701 100644 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportsModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyImportsModified.java @@ -149,6 +149,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(jsonObject); } + @Override + public PolicyImportsModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), PoliciesModelFactory.newPolicyImports(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/imports"); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyModified.java index ab5f82e829..e4c0366a36 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/PolicyModified.java @@ -139,6 +139,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policy.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public PolicyModified setEntity(final JsonValue entity) { + return of(PoliciesModelFactory.newPolicy(entity.asObject()), getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceCreated.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceCreated.java index 60946bdc41..af5b19fe28 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceCreated.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceCreated.java @@ -169,6 +169,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(resource.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ResourceCreated setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), label, PoliciesModelFactory.newResource(resource.getResourceKey(), entity), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources" + resource.getPath(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceDeleted.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceDeleted.java index bb61b4403f..bdba95231a 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceDeleted.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.ResourceKey; @@ -174,6 +175,11 @@ public ResourceDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public ResourceDeleted setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceModified.java index 7032ca0c78..f1da1cc82c 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourceModified.java @@ -172,6 +172,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(resource.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ResourceModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), label, PoliciesModelFactory.newResource(resource.getResourceKey(), entity), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources" + resource.getPath(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourcesModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourcesModified.java index bcdf249ade..475afbcb02 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourcesModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/ResourcesModified.java @@ -164,6 +164,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(resources.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ResourcesModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), label, PoliciesModelFactory.newResources(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources"; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectCreated.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectCreated.java index 6c85327292..1fcac958d7 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectCreated.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectCreated.java @@ -45,6 +45,7 @@ import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.Subject; +import org.eclipse.ditto.policies.model.SubjectId; /** * This event is emitted after a {@link org.eclipse.ditto.policies.model.Subject} was created. @@ -174,6 +175,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subject.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public SubjectCreated setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), label, Subject.newInstance(SubjectId.newInstance(entity.asString())), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects/" + subject.getId(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectDeleted.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectDeleted.java index dbf417163b..73024cc418 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectDeleted.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectDeleted.java @@ -39,6 +39,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.Label; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.SubjectId; @@ -179,6 +180,11 @@ public SubjectDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public SubjectDeleted setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectModified.java index e0b74780d5..b909cd6760 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectModified.java @@ -45,6 +45,7 @@ import org.eclipse.ditto.policies.model.PoliciesModelFactory; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.Subject; +import org.eclipse.ditto.policies.model.SubjectId; /** * This event is emitted after a {@link org.eclipse.ditto.policies.model.Subject} was modified. @@ -174,6 +175,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subject.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public SubjectModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), label, Subject.newInstance(SubjectId.newInstance(entity.asString())), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects/" + subject.getId(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsDeletedPartially.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsDeletedPartially.java index 755acbe469..67d59fabb3 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsDeletedPartially.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsDeletedPartially.java @@ -159,6 +159,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(deletedSubjectsToJson(deletedSubjectIds)); } + @Override + public SubjectsDeletedPartially setEntity(final JsonValue entity) { + return new SubjectsDeletedPartially(getPolicyEntityId(), entity.asObject(), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModified.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModified.java index 4862e5c7b9..574bb6854e 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModified.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModified.java @@ -165,6 +165,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(subjects.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public SubjectsModified setEntity(final JsonValue entity) { + return of(getPolicyEntityId(), label, PoliciesModelFactory.newSubjects(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/subjects"; diff --git a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModifiedPartially.java b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModifiedPartially.java index a1c8515342..60682c5210 100755 --- a/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModifiedPartially.java +++ b/policies/model/src/main/java/org/eclipse/ditto/policies/model/signals/events/SubjectsModifiedPartially.java @@ -159,6 +159,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(modifiedSubjectsToJson(modifiedSubjects)); } + @Override + public SubjectsModifiedPartially setEntity(final JsonValue entity) { + return new SubjectsModifiedPartially(getPolicyEntityId(), entity.asObject(), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/policies/PolicyModifyCommandAdapterTest.java b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/policies/PolicyModifyCommandAdapterTest.java index 58c16a027a..6485e6cdc0 100644 --- a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/policies/PolicyModifyCommandAdapterTest.java +++ b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/policies/PolicyModifyCommandAdapterTest.java @@ -16,18 +16,19 @@ import javax.annotation.Nonnull; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; -import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; -import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; +import org.eclipse.ditto.policies.model.signals.commands.modify.PolicyModifyCommand; import org.eclipse.ditto.protocol.TestConstants; import org.eclipse.ditto.protocol.TestConstants.Policies; import org.eclipse.ditto.protocol.TopicPath; import org.eclipse.ditto.protocol.UnknownCommandException; -import org.eclipse.ditto.policies.model.signals.commands.modify.PolicyModifyCommand; +import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; +import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; import org.junit.Before; import org.junit.Test; @@ -94,6 +95,10 @@ public UnknownPolicyModifyCommand setDittoHeaders(final DittoHeaders dittoHeader return this; } + @Override + public UnknownPolicyModifyCommand setEntity(final JsonValue entity) { + return this; + } } } diff --git a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/SubscriptionEventAdapterTest.java b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/SubscriptionEventAdapterTest.java index 7a9435521e..c145b2a743 100644 --- a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/SubscriptionEventAdapterTest.java +++ b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/SubscriptionEventAdapterTest.java @@ -16,21 +16,22 @@ import java.util.Optional; import java.util.function.Predicate; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.entity.metadata.Metadata; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.GlobalErrorRegistry; +import org.eclipse.ditto.base.model.signals.events.Event; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.protocol.Adaptable; -import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; import org.eclipse.ditto.protocol.Payload; -import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; import org.eclipse.ditto.protocol.TestConstants; import org.eclipse.ditto.protocol.TopicPath; import org.eclipse.ditto.protocol.UnknownEventException; -import org.eclipse.ditto.base.model.signals.GlobalErrorRegistry; +import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; +import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; import org.eclipse.ditto.thingsearch.model.signals.commands.exceptions.SubscriptionProtocolErrorException; -import org.eclipse.ditto.base.model.signals.events.Event; import org.eclipse.ditto.thingsearch.model.signals.events.SubscriptionComplete; import org.eclipse.ditto.thingsearch.model.signals.events.SubscriptionCreated; import org.eclipse.ditto.thingsearch.model.signals.events.SubscriptionEvent; @@ -332,5 +333,10 @@ public UnknownSubscriptionEvent setDittoHeaders(final DittoHeaders dittoHeaders) public String getManifest() { return getType(); } + + @Override + public UnknownSubscriptionEvent setEntity(final JsonValue entity) { + return this; + } } } diff --git a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingEventAdapterTest.java b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingEventAdapterTest.java index 0b42254f12..ab02cdaef1 100644 --- a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingEventAdapterTest.java +++ b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingEventAdapterTest.java @@ -1656,6 +1656,11 @@ public String getManifest() { public ThingId getEntityId() { return TestConstants.THING_ID; } + + @Override + public UnknownThingEvent setEntity(final JsonValue entity) { + return this; + } } private DittoHeaders setChannelHeader(final DittoHeaders dittoHeaders) { diff --git a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandAdapterTest.java b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandAdapterTest.java index 5b380a4897..223febed99 100644 --- a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandAdapterTest.java +++ b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandAdapterTest.java @@ -17,22 +17,22 @@ import javax.annotation.Nonnull; import org.assertj.core.api.Assertions; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.base.model.exceptions.DittoJsonException; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.things.model.ThingId; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.protocol.Adaptable; -import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; import org.eclipse.ditto.protocol.LiveTwinTest; import org.eclipse.ditto.protocol.Payload; -import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; import org.eclipse.ditto.protocol.TestConstants; import org.eclipse.ditto.protocol.TopicPath; import org.eclipse.ditto.protocol.UnknownCommandException; +import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; +import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; +import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing; import org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttribute; import org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttributes; @@ -1165,6 +1165,10 @@ public boolean changesAuthorization() { return false; } + @Override + public ThingModifyCommand setEntity(final JsonValue entity) { + return this; + } } } diff --git a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandResponseAdapterTest.java b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandResponseAdapterTest.java index 504ae68674..d2b0e0370c 100644 --- a/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandResponseAdapterTest.java +++ b/protocol/src/test/java/org/eclipse/ditto/protocol/adapter/things/ThingModifyCommandResponseAdapterTest.java @@ -16,24 +16,24 @@ import javax.annotation.Nonnull; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.base.model.common.HttpStatus; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.things.model.ThingsModelFactory; +import org.eclipse.ditto.base.model.signals.commands.CommandResponse; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.protocol.Adaptable; -import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; import org.eclipse.ditto.protocol.LiveTwinTest; import org.eclipse.ditto.protocol.Payload; -import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; import org.eclipse.ditto.protocol.TestConstants; import org.eclipse.ditto.protocol.TopicPath; import org.eclipse.ditto.protocol.UnknownCommandResponseException; -import org.eclipse.ditto.base.model.signals.commands.CommandResponse; +import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; +import org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest; +import org.eclipse.ditto.things.model.ThingId; +import org.eclipse.ditto.things.model.ThingsModelFactory; import org.eclipse.ditto.things.model.signals.commands.modify.CreateThingResponse; import org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttributeResponse; import org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttributesResponse; @@ -116,6 +116,11 @@ public ThingModifyCommandResponse setDittoHeaders(final DittoHeaders dittoHea return this; } + @Override + public ThingModifyCommandResponse setEntity(final JsonValue entity) { + return this; + } + @Nonnull @Override public String getManifest() { diff --git a/things/api/src/main/java/org/eclipse/ditto/things/api/ThingSnapshotTaken.java b/things/api/src/main/java/org/eclipse/ditto/things/api/ThingSnapshotTaken.java index 308151cc5a..06752b4c15 100644 --- a/things/api/src/main/java/org/eclipse/ditto/things/api/ThingSnapshotTaken.java +++ b/things/api/src/main/java/org/eclipse/ditto/things/api/ThingSnapshotTaken.java @@ -20,22 +20,23 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.base.api.persistence.PersistenceLifecycle; +import org.eclipse.ditto.base.api.persistence.SnapshotTaken; import org.eclipse.ditto.base.model.common.ConditionChecker; import org.eclipse.ditto.base.model.entity.metadata.Metadata; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableEvent; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.policies.model.PolicyIdInvalidException; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingIdInvalidException; -import org.eclipse.ditto.base.api.persistence.PersistenceLifecycle; -import org.eclipse.ditto.base.api.persistence.SnapshotTaken; /** * Event published when a thing snapshot is taken. @@ -181,6 +182,11 @@ protected ThingSnapshotTaken setDittoHeaders(final DittoHeaders dittoHeaders, fi .build(); } + @Override + public ThingSnapshotTaken setEntity(final JsonValue entity) { + return this; + } + @Override public String getResourceType() { return RESOURCE_TYPE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/acks/ThingAcknowledgementsFactory.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/acks/ThingAcknowledgementsFactory.java index 317d888e8e..889496f823 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/acks/ThingAcknowledgementsFactory.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/acks/ThingAcknowledgementsFactory.java @@ -71,7 +71,7 @@ public static Acknowledgements newAcknowledgements(final Collection acknowledgements, + final Collection acknowledgements, final HttpStatus httpStatus, final DittoHeaders dittoHeaders) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThing.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThing.java index 9088f5dfeb..612299e2ef 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThing.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThing.java @@ -268,6 +268,15 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(fullThingJson); } + @Override + public CreateThing setEntity(final JsonValue entity) { + final JsonObject jsonObject = entity.asObject(); + final JsonObject initialPolicyObject = jsonObject.getValue(JSON_INLINE_POLICY).orElse(null); + final String localPolicyIdOrPlaceholder = jsonObject.getValue(JSON_COPY_POLICY_FROM).orElse(null); + return of(ThingsModelFactory.newThing(jsonObject), initialPolicyObject, localPolicyIdOrPlaceholder, + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThingResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThingResponse.java index d9d2cc74ef..d377f2c779 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThingResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/CreateThingResponse.java @@ -171,6 +171,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(createdThing.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public CreateThingResponse setEntity(final JsonValue entity) { + return newInstance(ThingsModelFactory.newThing(entity.asObject()), getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttribute.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttribute.java index f2cb5e2bc2..815f60b355 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttribute.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttribute.java @@ -20,20 +20,21 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.AttributesModelFactory; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.exceptions.AttributePointerInvalidException; @@ -182,6 +183,11 @@ public DeleteAttribute setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, dittoHeaders); } + @Override + public DeleteAttribute setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributeResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributeResponse.java index ce18e9fe96..3ef0f0bd97 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributeResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributeResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.AttributesModelFactory; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -207,6 +208,11 @@ public DeleteAttributeResponse setDittoHeaders(final DittoHeaders dittoHeaders) return newInstance(thingId, attributePointer, getHttpStatus(), dittoHeaders); } + @Override + public DeleteAttributeResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributes.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributes.java index 12c29c4aa4..6228d07a66 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributes.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributes.java @@ -20,17 +20,18 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -134,6 +135,11 @@ public DeleteAttributes setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, dittoHeaders); } + @Override + public DeleteAttributes setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributesResponse.java index 435c7b0475..8d3a51722a 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteAttributesResponse.java @@ -31,6 +31,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -157,6 +158,11 @@ public DeleteAttributesResponse setDittoHeaders(final DittoHeaders dittoHeaders) return newInstance(thingId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteAttributesResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeature.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeature.java index 0149683caf..50eadd5f8b 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeature.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeature.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; @@ -153,6 +154,11 @@ public DeleteFeature setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, featureId, dittoHeaders); } + @Override + public DeleteFeature setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinition.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinition.java index 5e79b35204..ed44c176da 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinition.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinition.java @@ -20,20 +20,21 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.base.model.signals.WithFeatureId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -156,6 +157,11 @@ public DeleteFeatureDefinition setDittoHeaders(final DittoHeaders dittoHeaders) return of(thingId, featureId, dittoHeaders); } + @Override + public DeleteFeatureDefinition setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinitionResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinitionResponse.java index d1ed602c22..e1002a84b1 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinitionResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDefinitionResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -207,6 +208,11 @@ public DeleteFeatureDefinitionResponse setDittoHeaders(final DittoHeaders dittoH return newInstance(thingId, featureId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteFeatureDefinitionResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperties.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperties.java index 29eda0216e..ce9f2af01e 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperties.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperties.java @@ -20,20 +20,21 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.base.model.signals.WithFeatureId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -172,6 +173,11 @@ public DeleteFeatureDesiredProperties setDittoHeaders(final DittoHeaders dittoHe return of(thingId, featureId, dittoHeaders); } + @Override + public DeleteFeatureDesiredProperties setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertiesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertiesResponse.java index d7239bb9da..3d2de308b0 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertiesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertiesResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -205,6 +206,11 @@ public DeleteFeatureDesiredPropertiesResponse setDittoHeaders(final DittoHeaders return newInstance(thingId, featureId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteFeatureDesiredPropertiesResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperty.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperty.java index ff4a0539b7..9b04573e7a 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperty.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredProperty.java @@ -20,21 +20,22 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -201,6 +202,11 @@ public DeleteFeatureDesiredProperty setDittoHeaders(final DittoHeaders dittoHead return of(thingId, featureId, desiredPropertyPointer, dittoHeaders); } + @Override + public DeleteFeatureDesiredProperty setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertyResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertyResponse.java index 5200795d2e..3e69ff86b6 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertyResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureDesiredPropertyResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -239,6 +240,11 @@ public DeleteFeatureDesiredPropertyResponse setDittoHeaders(final DittoHeaders d return newInstance(thingId, featureId, desiredPropertyPointer, getHttpStatus(), dittoHeaders); } + @Override + public DeleteFeatureDesiredPropertyResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperties.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperties.java index fe60f09d91..b5a1dc8c1f 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperties.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperties.java @@ -20,20 +20,21 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonField; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.base.model.json.JsonParsableCommand; import org.eclipse.ditto.base.model.json.JsonSchemaVersion; -import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.base.model.signals.WithFeatureId; import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -155,6 +156,11 @@ public DeleteFeatureProperties setDittoHeaders(final DittoHeaders dittoHeaders) return of(thingId, featureId, dittoHeaders); } + @Override + public DeleteFeatureProperties setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertiesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertiesResponse.java index 429c7df2ff..655cc915bb 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertiesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertiesResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -190,6 +191,11 @@ public DeleteFeaturePropertiesResponse setDittoHeaders(final DittoHeaders dittoH return newInstance(thingId, featureId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteFeaturePropertiesResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperty.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperty.java index 65d593ca3d..9a2639be3c 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperty.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureProperty.java @@ -20,21 +20,22 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -188,6 +189,11 @@ public DeleteFeatureProperty setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, featureId, propertyPointer, dittoHeaders); } + @Override + public DeleteFeatureProperty setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertyResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertyResponse.java index 1765fc3483..737414ec11 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertyResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturePropertyResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -220,6 +221,11 @@ protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, public DeleteFeaturePropertyResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(thingId, featureId, propertyPointer, getHttpStatus(), dittoHeaders); } + + @Override + public DeleteFeaturePropertyResponse setEntity(final JsonValue entity) { + return this; + } @Override public boolean equals(@Nullable final Object o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureResponse.java index 3ad69d1e65..09026e6713 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatureResponse.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -188,6 +189,11 @@ public DeleteFeatureResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(thingId, featureId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteFeatureResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatures.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatures.java index 3e90a642c1..6ea30b3ccd 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatures.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeatures.java @@ -20,17 +20,18 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -134,6 +135,11 @@ public DeleteFeatures setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, dittoHeaders); } + @Override + public DeleteFeatures setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturesResponse.java index 7f44a7bf92..2674c265a6 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteFeaturesResponse.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -158,6 +159,11 @@ public DeleteFeaturesResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(thingId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteFeaturesResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThing.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThing.java index b06b3a5ed6..725b1f772c 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThing.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThing.java @@ -20,17 +20,18 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -135,6 +136,11 @@ public DeleteThing setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, dittoHeaders); } + @Override + public DeleteThing setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return true; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinition.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinition.java index addaf04986..59d15121b0 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinition.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinition.java @@ -21,17 +21,18 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -142,6 +143,11 @@ public DeleteThingDefinition setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, dittoHeaders); } + @Override + public DeleteThingDefinition setEntity(final JsonValue entity) { + return this; + } + @Override public boolean changesAuthorization() { return false; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinitionResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinitionResponse.java index 0919debb50..13bdc185ae 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinitionResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingDefinitionResponse.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -160,6 +161,11 @@ public DeleteThingDefinitionResponse setDittoHeaders(final DittoHeaders dittoHea return newInstance(thingId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteThingDefinitionResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingResponse.java index 5b6d5d607e..7922533adb 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/DeleteThingResponse.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -155,6 +156,11 @@ public DeleteThingResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(thingId, getHttpStatus(), dittoHeaders); } + @Override + public DeleteThingResponse setEntity(final JsonValue entity) { + return this; + } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThing.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThing.java index eccbfde79e..a33da2469d 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThing.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThing.java @@ -515,6 +515,18 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return getEntity(); } + @Override + public MergeThing setEntity(final JsonValue entity) { + if (path.isEmpty()) { + final JsonObject jsonObject = entity.asObject(); + final JsonObject initialPolicyObject = jsonObject.getValue(JSON_INLINE_POLICY).orElse(null); + final String localPolicyIdOrPlaceholder = jsonObject.getValue(JSON_COPY_POLICY_FROM).orElse(null); + return new MergeThing(thingId, path, entity, initialPolicyObject, localPolicyIdOrPlaceholder, getDittoHeaders()); + } else { + return new MergeThing(thingId, path, entity, initialPolicy, policyIdOrPlaceholder, getDittoHeaders()); + } + } + @Override public JsonPointer getResourcePath() { return path; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThingResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThingResponse.java index 0d1a08d818..ec6de1b83e 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThingResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/MergeThingResponse.java @@ -36,6 +36,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandResponse; @@ -161,6 +162,11 @@ public MergeThingResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return newInstance(thingId, path, getHttpStatus(), dittoHeaders); } + @Override + public MergeThingResponse setEntity(final JsonValue entity) { + return this; + } + @Override public JsonSchemaVersion[] getSupportedSchemaVersions() { return new JsonSchemaVersion[]{JsonSchemaVersion.V_2}; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttribute.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttribute.java index ece0afeda3..476e9b2916 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttribute.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttribute.java @@ -21,6 +21,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,14 +34,8 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.AttributesModelFactory; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; import org.eclipse.ditto.things.model.signals.commands.exceptions.AttributePointerInvalidException; @@ -199,6 +199,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(attributeValue); } + @Override + public ModifyAttribute setEntity(final JsonValue entity) { + return of(thingId, attributePointer, entity, getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/attributes" + attributePointer); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributeResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributeResponse.java index 52503aee0e..9112e126af 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributeResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributeResponse.java @@ -257,6 +257,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(attributeValue); } + @Override + public ModifyAttributeResponse setEntity(final JsonValue entity) { + return newInstance(thingId, attributePointer, getHttpStatus() == HttpStatus.CREATED ? entity : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/attributes" + attributePointer); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributes.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributes.java index 120fdf11c0..50c47d8700 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributes.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributes.java @@ -21,6 +21,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,15 +34,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.Attributes; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -157,6 +157,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(attributes.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyAttributes setEntity(final JsonValue entity) { + return of(thingId, entity.isNull() ? ThingsModelFactory.nullAttributes() : + ThingsModelFactory.newAttributes(entity.asObject()), + getDittoHeaders()); + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributesResponse.java index fa5e6f0024..c382e36f57 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyAttributesResponse.java @@ -206,6 +206,15 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(attributes); } + @Override + public ModifyAttributesResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newAttributes(entity.asObject()) : + ThingsModelFactory.nullAttributes(), + getHttpStatus(), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/attributes"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeature.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeature.java index 11eaa1ec2f..c99e17107a 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeature.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeature.java @@ -21,6 +21,13 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,16 +35,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.Feature; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -169,6 +169,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(feature.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyFeature setEntity(final JsonValue entity) { + return of(thingId, + entity.isNull() ? ThingsModelFactory.nullFeature(getFeatureId()) : + ThingsModelFactory.newFeatureBuilder(entity.asObject()).useId(getFeatureId()).build(), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + getFeatureId(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinition.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinition.java index 9692f19058..509b2a0ad2 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinition.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinition.java @@ -21,6 +21,13 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonArray; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; @@ -29,16 +36,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.FeatureDefinition; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -171,6 +171,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(definition.toJson()); } + @Override + public ModifyFeatureDefinition setEntity(final JsonValue entity) { + return of(thingId, featureId, ThingsModelFactory.newFeatureDefinition(entity.asArray()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/definition"; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinitionResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinitionResponse.java index 642da27531..562e8c9095 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinitionResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDefinitionResponse.java @@ -260,6 +260,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(definitionCreated).map(Jsonifiable::toJson); } + @Override + public ModifyFeatureDefinitionResponse setEntity(final JsonValue entity) { + return newInstance(thingId, featureId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newFeatureDefinition(entity.asArray()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/features/" + featureId + "/definition"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperties.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperties.java index b5ecc272d0..1f19cccef9 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperties.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperties.java @@ -21,6 +21,13 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,16 +35,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.FeatureProperties; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -176,6 +176,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(desiredProperties.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyFeatureDesiredProperties setEntity(final JsonValue entity) { + return of(thingId, featureId, ThingsModelFactory.newFeatureProperties(entity.asObject()), getDittoHeaders()); + } + /** * ModifyFeatureDesiredProperties is only available in JsonSchemaVersion V_2. * diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertiesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertiesResponse.java index f4dc2089f4..e1749f13aa 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertiesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertiesResponse.java @@ -248,6 +248,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(desiredPropertiesCreated); } + @Override + public ModifyFeatureDesiredPropertiesResponse setEntity(final JsonValue entity) { + return newInstance(thingId, featureId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newFeatureProperties(entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + /** * ModifyFeatureDesiredPropertiesResponse is only available in JsonSchemaVersion V_2. * diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperty.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperty.java index 4a13294c08..ba554ea4be 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperty.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredProperty.java @@ -21,6 +21,13 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,15 +35,8 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -209,6 +209,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(desiredPropertyValue); } + @Override + public ModifyFeatureDesiredProperty setEntity(final JsonValue entity) { + return of(thingId, featureId, desiredPropertyPointer, entity, getDittoHeaders()); + } + /** * ModifyFeatureDesiredProperty is only available in JsonSchemaVersion V_2. * diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertyResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertyResponse.java index 47c8a33b74..f19550f114 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertyResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureDesiredPropertyResponse.java @@ -276,6 +276,16 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(desiredPropertyValue); } + @Override + public ModifyFeatureDesiredPropertyResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + featureId, + desiredPropertyPointer, + getHttpStatus() == HttpStatus.CREATED ? entity : null, + getHttpStatus(), + getDittoHeaders()); + } + /** * ModifyFeatureDesiredPropertyResponse is only available in JsonSchemaVersion V_2. * diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperties.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperties.java index 0cde3b4cb0..7a641d714f 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperties.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperties.java @@ -21,6 +21,13 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,16 +35,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.FeatureProperties; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -176,6 +176,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(properties.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyFeatureProperties setEntity(final JsonValue entity) { + return of(thingId, featureId, + entity.isNull() ? ThingsModelFactory.nullFeatureProperties() : + ThingsModelFactory.newFeatureProperties(entity.asObject()), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/properties"; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertiesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertiesResponse.java index f9a376a459..7566d03f59 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertiesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertiesResponse.java @@ -241,6 +241,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(featurePropertiesCreated); } + @Override + public ModifyFeaturePropertiesResponse setEntity(final JsonValue entity) { + return newInstance(thingId, featureId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newFeatureProperties(entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/features/" + featureId + "/properties"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperty.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperty.java index 53518c8a36..6aad23f31d 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperty.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureProperty.java @@ -21,6 +21,13 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.WithFeatureId; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,15 +35,8 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.WithFeatureId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -199,6 +199,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(propertyValue); } + @Override + public ModifyFeatureProperty setEntity(final JsonValue entity) { + return of(thingId, featureId, propertyPointer, entity, getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/properties" + propertyPointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertyResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertyResponse.java index 8083d049fa..d400d1e072 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertyResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturePropertyResponse.java @@ -270,6 +270,16 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(featurePropertyValue); } + @Override + public ModifyFeaturePropertyResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + featureId, + featurePropertyPointer, + getHttpStatus() == HttpStatus.CREATED ? entity : null, + getHttpStatus(), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/features/" + featureId + "/properties" + featurePropertyPointer); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureResponse.java index 05e183bac5..d536377afa 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatureResponse.java @@ -254,6 +254,15 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return result; } + @Override + public ModifyFeatureResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newFeatureBuilder(entity.asObject()) + .useId(featureId) + .build() : null, + featureId, getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/features/" + featureId); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatures.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatures.java index bf52542802..8ecd822b0f 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatures.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeatures.java @@ -20,6 +20,12 @@ import javax.annotation.Nullable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -27,15 +33,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.Features; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; import org.eclipse.ditto.things.model.signals.commands.ThingCommandSizeValidator; @@ -149,6 +149,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(features.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public ModifyFeatures setEntity(final JsonValue entity) { + return of(thingId, ThingsModelFactory.newFeatures(entity.asObject()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/features"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturesResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturesResponse.java index 610158e703..ee575645c8 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturesResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyFeaturesResponse.java @@ -205,6 +205,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(features.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyFeaturesResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newFeatures(entity.asObject()) : + ThingsModelFactory.nullFeatures(), + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/features"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyId.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyId.java index 5bbbe60397..e64413669a 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyId.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyId.java @@ -22,6 +22,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -29,15 +35,9 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.policies.model.PolicyId; import org.eclipse.ditto.things.model.Thing; import org.eclipse.ditto.things.model.ThingId; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -153,6 +153,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(JsonValue.of(policyId)); } + @Override + public ModifyPolicyId setEntity(final JsonValue entity) { + return of(thingId, PolicyId.of(entity.asString()), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.POLICY_ID.getPointer().toString(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyIdResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyIdResponse.java index 234138fc15..dc74fef651 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyIdResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyPolicyIdResponse.java @@ -216,6 +216,11 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(policyId).map(JsonValue::of); } + @Override + public ModifyPolicyIdResponse setEntity(final JsonValue entity) { + return newInstance(thingId, PolicyId.of(entity.asString()), getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of(Thing.JsonFields.POLICY_ID.getPointer().toString()); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThing.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThing.java index 0b40da9b8d..3692345f6b 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThing.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThing.java @@ -268,6 +268,15 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(fullThingJson); } + @Override + public ModifyThing setEntity(final JsonValue entity) { + final JsonObject jsonObject = entity.asObject(); + final JsonObject initialPolicyObject = jsonObject.getValue(JSON_INLINE_POLICY).orElse(null); + final String localPolicyIdOrPlaceholder = jsonObject.getValue(JSON_COPY_POLICY_FROM).orElse(null); + return of(thingId, ThingsModelFactory.newThing(jsonObject), initialPolicyObject, localPolicyIdOrPlaceholder, + getDittoHeaders()); + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate thePredicate) { diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinition.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinition.java index c4b9591de3..da0a9693e9 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinition.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinition.java @@ -21,6 +21,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.FieldType; +import org.eclipse.ditto.base.model.json.JsonParsableCommand; +import org.eclipse.ditto.base.model.json.JsonSchemaVersion; +import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; +import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonFieldDefinition; @@ -28,16 +34,10 @@ import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.FieldType; -import org.eclipse.ditto.base.model.json.JsonParsableCommand; -import org.eclipse.ditto.base.model.json.JsonSchemaVersion; import org.eclipse.ditto.things.model.Thing; import org.eclipse.ditto.things.model.ThingDefinition; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.ThingsModelFactory; -import org.eclipse.ditto.base.model.signals.commands.AbstractCommand; -import org.eclipse.ditto.base.model.signals.commands.CommandJsonDeserializer; import org.eclipse.ditto.things.model.signals.commands.ThingCommand; /** @@ -161,6 +161,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(JsonValue.of(definition)); } + @Override + public ModifyThingDefinition setEntity(final JsonValue entity) { + return of(thingId, entity.isNull() ? ThingsModelFactory.nullDefinition() : + ThingsModelFactory.newDefinition(entity.asString()), + getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.DEFINITION.getPointer().toString(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinitionResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinitionResponse.java index 15de2b544f..b5dd4b0560 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinitionResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingDefinitionResponse.java @@ -220,6 +220,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(definition).map(JsonValue::of); } + @Override + public ModifyThingDefinitionResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newDefinition(entity.asString()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of(Thing.JsonFields.DEFINITION.getPointer().toString()); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingResponse.java index 83ecd18aac..e3e7728e32 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ModifyThingResponse.java @@ -205,6 +205,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(thingCreated).map(thing -> thing.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ModifyThingResponse setEntity(final JsonValue entity) { + return newInstance(thingId, + getHttpStatus() == HttpStatus.CREATED ? ThingsModelFactory.newThing(entity.asObject()) : null, + getHttpStatus(), getDittoHeaders()); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommand.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommand.java index 07cce68312..9543005c79 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommand.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommand.java @@ -21,7 +21,7 @@ * * @param the type of the implementing class. */ -public interface ThingModifyCommand> extends ThingCommand, WithOptionalEntity { +public interface ThingModifyCommand> extends ThingCommand, WithOptionalEntity { @Override T setDittoHeaders(DittoHeaders dittoHeaders); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommandResponse.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommandResponse.java index 4b36d3052d..c09be8a9df 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommandResponse.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/commands/modify/ThingModifyCommandResponse.java @@ -22,7 +22,7 @@ * @param the type of the implementing class. */ public interface ThingModifyCommandResponse> extends ThingCommandResponse, - WithOptionalEntity { + WithOptionalEntity { @Override T setDittoHeaders(DittoHeaders dittoHeaders); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeCreated.java index c5323537a4..ac6669290e 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeCreated.java @@ -166,6 +166,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(attributeValue); } + @Override + public AttributeCreated setEntity(final JsonValue entity) { + return of(getEntityId(), attributePointer, entity, getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/attributes" + attributePointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeDeleted.java index fdd1ec5673..2c0b0528a9 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeDeleted.java @@ -32,6 +32,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -155,6 +156,11 @@ public AttributeDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public AttributeDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeModified.java index bebc430a34..da83ba2b1f 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributeModified.java @@ -166,6 +166,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(attributeValue); } + @Override + public AttributeModified setEntity(final JsonValue entity) { + return of(getEntityId(), attributePointer, entity, getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/attributes" + attributePointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesCreated.java index 26442352c7..bf1ab173b8 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesCreated.java @@ -146,6 +146,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(createdAttributes.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public AttributesCreated setEntity(final JsonValue entity) { + return of(getEntityId(), ThingsModelFactory.newAttributes(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/attributes"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesDeleted.java index 0447a0de1a..5c6a15f34f 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesDeleted.java @@ -29,6 +29,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -130,6 +131,11 @@ public AttributesDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public AttributesDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesModified.java index 7aa4729638..0385693239 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/AttributesModified.java @@ -147,6 +147,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(modifiedAttributes.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public AttributesModified setEntity(final JsonValue entity) { + return of(getEntityId(), ThingsModelFactory.newAttributes(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.of("/attributes"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureCreated.java index a602b1b9a7..1be75f9b96 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureCreated.java @@ -160,6 +160,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(feature.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public FeatureCreated setEntity(final JsonValue entity) { + return of(getEntityId(), + entity.isNull() ? ThingsModelFactory.nullFeature(getFeatureId()) : + ThingsModelFactory.newFeatureBuilder(entity.asObject()).useId(getFeatureId()).build(), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features/" + getFeatureId()); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionCreated.java index cdfc5a17b3..6f3fa7deb6 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionCreated.java @@ -166,6 +166,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(definition.toJson()); } + @Override + public FeatureDefinitionCreated setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, ThingsModelFactory.newFeatureDefinition(entity.asArray()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/definition"; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionDeleted.java index f5f592b12c..e6baf7535a 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -148,6 +149,11 @@ public FeatureDefinitionDeleted setDittoHeaders(final DittoHeaders dittoHeaders) getMetadata().orElse(null)); } + @Override + public FeatureDefinitionDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionModified.java index 3c23094c43..8b89be24e8 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDefinitionModified.java @@ -166,6 +166,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(definition.toJson()); } + @Override + public FeatureDefinitionModified setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, ThingsModelFactory.newFeatureDefinition(entity.asArray()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features/" + featureId + "/definition"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDeleted.java index f9a644f499..6668b7e6f6 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -148,6 +149,11 @@ public FeatureDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public FeatureDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesCreated.java index b65591fbf1..54d47fd18b 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesCreated.java @@ -173,6 +173,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(desiredProperties.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public FeatureDesiredPropertiesCreated setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, + entity.isNull() ? ThingsModelFactory.nullFeatureProperties() : + ThingsModelFactory.newFeatureProperties(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/desiredProperties"; @@ -182,8 +190,7 @@ public JsonPointer getResourcePath() { @Override public FeatureDesiredPropertiesCreated setRevision(final long revision) { return of(getEntityId(), featureId, desiredProperties, revision, getTimestamp().orElse(null), - getDittoHeaders(), - getMetadata().orElse(null)); + getDittoHeaders(), getMetadata().orElse(null)); } @Override diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesDeleted.java index cb7b949d48..44730e6f6c 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -152,6 +153,11 @@ public FeatureDesiredPropertiesDeleted setDittoHeaders(final DittoHeaders dittoH getMetadata().orElse(null)); } + @Override + public FeatureDesiredPropertiesDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesModified.java index 1c8d8c5694..a53366b69b 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertiesModified.java @@ -169,6 +169,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(desiredProperties.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public FeatureDesiredPropertiesModified setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, ThingsModelFactory.newFeatureProperties(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features/" + featureId + "/desiredProperties"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyCreated.java index c5b6d92d9a..150e3acb98 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyCreated.java @@ -180,6 +180,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(desiredPropertyValue); } + @Override + public FeatureDesiredPropertyCreated setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, desiredPropertyPointer, entity, getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/desiredProperties" + desiredPropertyPointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyDeleted.java index 40997ec438..62a93f9ffb 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyDeleted.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -173,6 +174,11 @@ public FeatureDesiredPropertyDeleted setDittoHeaders(final DittoHeaders dittoHea dittoHeaders, getMetadata().orElse(null)); } + @Override + public FeatureDesiredPropertyDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyModified.java index cdb14b9e60..9921d957d1 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureDesiredPropertyModified.java @@ -180,6 +180,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(desiredPropertyValue); } + @Override + public FeatureDesiredPropertyModified setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, desiredPropertyPointer, entity, getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/desiredProperties" + desiredPropertyPointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureModified.java index a198db2683..013f0f5475 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeatureModified.java @@ -159,6 +159,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(feature.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public FeatureModified setEntity(final JsonValue entity) { + return of(getEntityId(), + ThingsModelFactory.newFeatureBuilder(entity.asObject()).useId(getFeatureId()).build(), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features/" + getFeatureId()); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesCreated.java index 9c6aa4a618..33d018595c 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesCreated.java @@ -169,6 +169,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(properties.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public FeaturePropertiesCreated setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, + entity.isNull() ? ThingsModelFactory.nullFeatureProperties() : + ThingsModelFactory.newFeatureProperties(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/properties"; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesDeleted.java index 71b85b1cfd..0e3e55721f 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesDeleted.java @@ -33,6 +33,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -148,6 +149,11 @@ public FeaturePropertiesDeleted setDittoHeaders(final DittoHeaders dittoHeaders) getMetadata().orElse(null)); } + @Override + public FeaturePropertiesDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesModified.java index 7bdb3817fe..294a9409ba 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertiesModified.java @@ -138,9 +138,9 @@ public static FeaturePropertiesModified fromJson(final JsonObject jsonObject, fi final String extractedFeatureId = jsonObject.getValueOrThrow(ThingEvent.JsonFields.FEATURE_ID); final JsonObject propertiesJsonObject = jsonObject.getValueOrThrow(JSON_PROPERTIES); - final FeatureProperties extractedProperties = (null != propertiesJsonObject) - ? ThingsModelFactory.newFeatureProperties(propertiesJsonObject) - : ThingsModelFactory.nullFeatureProperties(); + final FeatureProperties extractedProperties = propertiesJsonObject.isNull() + ? ThingsModelFactory.nullFeatureProperties() + : ThingsModelFactory.newFeatureProperties(propertiesJsonObject); return of(thingId, extractedFeatureId, extractedProperties, revision, timestamp, dittoHeaders, metadata); @@ -166,6 +166,14 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(properties.toJson(schemaVersion, FieldType.regularOrSpecial())); } + @Override + public FeaturePropertiesModified setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, + entity.isNull() ? ThingsModelFactory.nullFeatureProperties() : + ThingsModelFactory.newFeatureProperties(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features/" + featureId + "/properties"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyCreated.java index 6765d7d211..965f5d9d8b 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyCreated.java @@ -181,6 +181,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(propertyValue); } + @Override + public FeaturePropertyCreated setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, propertyPointer, entity, getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/properties" + propertyPointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyDeleted.java index 2ecc509155..791cfd21ab 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyDeleted.java @@ -35,6 +35,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -173,6 +174,11 @@ public FeaturePropertyDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { dittoHeaders, getMetadata().orElse(null)); } + @Override + public FeaturePropertyDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyModified.java index 4a0c3b3af4..09425d7c68 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturePropertyModified.java @@ -181,6 +181,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(propertyValue); } + @Override + public FeaturePropertyModified setEntity(final JsonValue entity) { + return of(getEntityId(), featureId, propertyPointer, entity, getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = "/features/" + featureId + "/properties" + propertyPointer; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesCreated.java index 49bd634fd2..7bbaaf0667 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesCreated.java @@ -131,9 +131,9 @@ public static FeaturesCreated fromJson(final JsonObject jsonObject, final DittoH final ThingId thingId = ThingId.of(extractedThingId); final JsonObject featuresJsonObject = jsonObject.getValueOrThrow(JSON_FEATURES); - final Features extractedFeatures = (null != featuresJsonObject && !featuresJsonObject.isNull()) - ? ThingsModelFactory.newFeatures(featuresJsonObject) - : ThingsModelFactory.nullFeatures(); + final Features extractedFeatures = featuresJsonObject.isNull() + ? ThingsModelFactory.nullFeatures() + : ThingsModelFactory.newFeatures(featuresJsonObject); return of(thingId, extractedFeatures, revision, timestamp, dittoHeaders, metadata); }); @@ -153,6 +153,13 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(features.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public FeaturesCreated setEntity(final JsonValue entity) { + return of(getEntityId(), + entity.isNull() ? ThingsModelFactory.nullFeatures() : ThingsModelFactory.newFeatures(entity.asObject()), + getRevision(), getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesDeleted.java index 189431755b..7da0146f0d 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesDeleted.java @@ -29,6 +29,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -131,6 +132,11 @@ public FeaturesDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public FeaturesDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesModified.java index 156c0f29dd..2756814d94 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/FeaturesModified.java @@ -150,6 +150,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(features.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public FeaturesModified setEntity(final JsonValue entity) { + return of(getEntityId(), ThingsModelFactory.newFeatures(entity.asObject()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonFactory.newPointer("/features"); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/PolicyIdModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/PolicyIdModified.java index 03db4813e2..99fa3301fc 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/PolicyIdModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/PolicyIdModified.java @@ -146,6 +146,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(policyId).map(String::valueOf).map(JsonFactory::newValue); } + @Override + public PolicyIdModified setEntity(final JsonValue entity) { + return of(getEntityId(), PolicyId.of(entity.asString()), getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.POLICY_ID.getPointer().toString(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingCreated.java index 2ecd3814aa..58ccdf0862 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingCreated.java @@ -150,6 +150,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(thing.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ThingCreated setEntity(final JsonValue entity) { + return of(ThingsModelFactory.newThing(entity.asObject()), getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionCreated.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionCreated.java index 5dc0274fe4..48dccce183 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionCreated.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionCreated.java @@ -157,6 +157,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { } } + @Override + public ThingDefinitionCreated setEntity(final JsonValue entity) { + return of(getEntityId(), ThingsModelFactory.newDefinition(entity.asString()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.DEFINITION.getPointer().toString(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionDeleted.java index 07f197cc1c..f6108fd6c2 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionDeleted.java @@ -29,6 +29,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -130,6 +131,11 @@ public ThingDefinitionDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public ThingDefinitionDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; @@ -146,4 +152,6 @@ public String toString() { return getClass().getSimpleName() + " [" + super.toString() + "]"; } + + } diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionModified.java index b3574f7536..c144de5663 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDefinitionModified.java @@ -159,6 +159,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { } } + @Override + public ThingDefinitionModified setEntity(final JsonValue entity) { + return of(getEntityId(), ThingsModelFactory.newDefinition(entity.asString()), getRevision(), + getTimestamp().orElse(null), getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.DEFINITION.getPointer().toString(); diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDeleted.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDeleted.java index 5b7b338664..bb64c937bd 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDeleted.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingDeleted.java @@ -29,6 +29,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; import org.eclipse.ditto.things.model.ThingId; /** @@ -129,6 +130,11 @@ public ThingDeleted setDittoHeaders(final DittoHeaders dittoHeaders) { getMetadata().orElse(null)); } + @Override + public ThingDeleted setEntity(final JsonValue entity) { + return this; + } + @Override public Command.Category getCommandCategory() { return Command.Category.DELETE; @@ -151,4 +157,6 @@ public String toString() { return getClass().getSimpleName() + " [" + super.toString() + "]"; } + + } diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingMerged.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingMerged.java index 5a280a94a5..1948a65e77 100644 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingMerged.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingMerged.java @@ -160,6 +160,12 @@ public Optional getEntity() { return Optional.of(value); } + @Override + public ThingMerged setEntity(final JsonValue entity) { + return of(thingId, path, entity, getRevision(), getTimestamp().orElse(null), getDittoHeaders(), + getMetadata().orElse(null)); + } + @Override public JsonSchemaVersion[] getSupportedSchemaVersions() { return new JsonSchemaVersion[]{JsonSchemaVersion.V_2}; diff --git a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingModified.java b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingModified.java index 3a09f93c7e..e4b9c03939 100755 --- a/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingModified.java +++ b/things/model/src/main/java/org/eclipse/ditto/things/model/signals/events/ThingModified.java @@ -140,6 +140,12 @@ public Optional getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(thing.toJson(schemaVersion, FieldType.notHidden())); } + @Override + public ThingModified setEntity(final JsonValue entity) { + return of(ThingsModelFactory.newThing(entity.asObject()), getRevision(), getTimestamp().orElse(null), + getDittoHeaders(), getMetadata().orElse(null)); + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); diff --git a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/MetadataFromCommand.java b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/MetadataFromCommand.java index 1a082f8b06..0a06a3badc 100644 --- a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/MetadataFromCommand.java +++ b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/MetadataFromCommand.java @@ -88,7 +88,7 @@ static MetadataFromCommand of(final Command command, final Thing existingOrEmptyThing = Objects.requireNonNullElseGet(existingThing, () -> Thing.newBuilder().build()); - if (command instanceof WithOptionalEntity withOptionalEntity) { + if (command instanceof WithOptionalEntity withOptionalEntity) { final var mergedThing = withOptionalEntity.getEntity() .map(entity -> { final var resourcePath = command.getResourcePath(); diff --git a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/AbstractThingEventStrategy.java b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/AbstractThingEventStrategy.java index 8a5f3b05f8..33149b7fa0 100644 --- a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/AbstractThingEventStrategy.java +++ b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/AbstractThingEventStrategy.java @@ -117,7 +117,7 @@ private Metadata deleteMetadataForMergeAndModifiedEvents(final T event, final Me .collect(Collectors.toSet()); jsonKeysForNullValue.forEach(jsonKey -> - metadataBuilder.remove(event.getResourcePath() + "/" + jsonKey.toString())); + metadataBuilder.remove(event.getResourcePath().addLeaf(jsonKey))); return metadataBuilder.build(); } diff --git a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/ThingMergedStrategy.java b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/ThingMergedStrategy.java index 6f71a56cc3..521ff5bc89 100644 --- a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/ThingMergedStrategy.java +++ b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/events/ThingMergedStrategy.java @@ -15,21 +15,21 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.base.model.json.FieldType; import org.eclipse.ditto.things.model.Thing; import org.eclipse.ditto.things.model.ThingLifecycle; import org.eclipse.ditto.things.model.ThingsModelFactory; import org.eclipse.ditto.things.model.signals.events.ThingMerged; /** - * This strategy handles the {@link org.eclipse.ditto.things.model.signals.events.ThingMerged} event. + * This strategy handles the {@link ThingMerged} event. */ @Immutable final class ThingMergedStrategy extends AbstractThingEventStrategy { - protected ThingMergedStrategy() { + ThingMergedStrategy() { super(); } diff --git a/thingsearch/api/src/main/java/org/eclipse/ditto/thingsearch/api/events/ThingsOutOfSync.java b/thingsearch/api/src/main/java/org/eclipse/ditto/thingsearch/api/events/ThingsOutOfSync.java index 24b4f3759a..f8f342b165 100644 --- a/thingsearch/api/src/main/java/org/eclipse/ditto/thingsearch/api/events/ThingsOutOfSync.java +++ b/thingsearch/api/src/main/java/org/eclipse/ditto/thingsearch/api/events/ThingsOutOfSync.java @@ -124,6 +124,11 @@ public ThingsOutOfSync setDittoHeaders(final DittoHeaders dittoHeaders) { return new ThingsOutOfSync(thingIds, dittoHeaders); } + @Override + public ThingsOutOfSync setEntity(final JsonValue entity) { + return this; + } + @Override public JsonPointer getResourcePath() { return JsonPointer.empty(); @@ -192,4 +197,5 @@ public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate< .set(JSON_THING_IDS, thingIdsJsonArray, predicate) .build(); } + } diff --git a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionComplete.java b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionComplete.java index 131967fd9e..6174fdb85c 100755 --- a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionComplete.java +++ b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionComplete.java @@ -14,12 +14,13 @@ import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableEvent; import org.eclipse.ditto.base.model.signals.events.EventJsonDeserializer; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after all pages of a search subscription are sent. @@ -85,6 +86,11 @@ public SubscriptionComplete setDittoHeaders(final DittoHeaders dittoHeaders) { return new SubscriptionComplete(getSubscriptionId(), dittoHeaders); } + @Override + public SubscriptionComplete setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { // nothing to add diff --git a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionCreated.java b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionCreated.java index decb027f69..201584a5d2 100755 --- a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionCreated.java +++ b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionCreated.java @@ -14,12 +14,13 @@ import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableEvent; import org.eclipse.ditto.base.model.signals.events.EventJsonDeserializer; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a stream is established for search results in the back-end. @@ -85,6 +86,11 @@ public SubscriptionCreated setDittoHeaders(final DittoHeaders dittoHeaders) { return new SubscriptionCreated(getSubscriptionId(), dittoHeaders); } + @Override + public SubscriptionCreated setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { // nothing to add diff --git a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionFailed.java b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionFailed.java index 67f46c7e0a..e473905586 100755 --- a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionFailed.java +++ b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionFailed.java @@ -16,16 +16,17 @@ import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonFactory; -import org.eclipse.ditto.json.JsonFieldDefinition; -import org.eclipse.ditto.json.JsonObject; -import org.eclipse.ditto.json.JsonObjectBuilder; -import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException; import org.eclipse.ditto.base.model.headers.DittoHeaders; import org.eclipse.ditto.base.model.json.JsonParsableEvent; import org.eclipse.ditto.base.model.signals.GlobalErrorRegistry; import org.eclipse.ditto.base.model.signals.events.EventJsonDeserializer; +import org.eclipse.ditto.json.JsonFactory; +import org.eclipse.ditto.json.JsonFieldDefinition; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonObjectBuilder; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a stream of search results failed. @@ -121,6 +122,11 @@ public SubscriptionFailed setDittoHeaders(final DittoHeaders dittoHeaders) { return new SubscriptionFailed(getSubscriptionId(), error, dittoHeaders); } + @Override + public SubscriptionFailed setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { jsonObjectBuilder.set(JsonFields.ERROR, error.toJson()); diff --git a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionHasNextPage.java b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionHasNextPage.java index 9393ee2e4f..58c432887a 100755 --- a/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionHasNextPage.java +++ b/thingsearch/model/src/main/java/org/eclipse/ditto/thingsearch/model/signals/events/SubscriptionHasNextPage.java @@ -16,15 +16,16 @@ import javax.annotation.concurrent.Immutable; +import org.eclipse.ditto.base.model.headers.DittoHeaders; +import org.eclipse.ditto.base.model.json.JsonParsableEvent; +import org.eclipse.ditto.base.model.signals.events.EventJsonDeserializer; import org.eclipse.ditto.json.JsonArray; import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonFieldDefinition; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonObjectBuilder; import org.eclipse.ditto.json.JsonPointer; -import org.eclipse.ditto.base.model.headers.DittoHeaders; -import org.eclipse.ditto.base.model.json.JsonParsableEvent; -import org.eclipse.ditto.base.model.signals.events.EventJsonDeserializer; +import org.eclipse.ditto.json.JsonValue; /** * This event is emitted after a page of search result is ready. @@ -118,6 +119,11 @@ public SubscriptionHasNextPage setDittoHeaders(final DittoHeaders dittoHeaders) return new SubscriptionHasNextPage(getSubscriptionId(), items, dittoHeaders); } + @Override + public SubscriptionHasNextPage setEntity(final JsonValue entity) { + return this; + } + @Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder) { jsonObjectBuilder.set(JsonFields.ITEMS, items); From 332c1559b61a499a48a6e75c6b5a701e67a8f4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20J=C3=A4ckle?= Date: Thu, 12 Oct 2023 20:00:51 +0200 Subject: [PATCH 2/2] added unit test for "if-equal" header: "skip-minimizing-merge" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * also added documentation * enhanced release notes + blogpost about release with last-minute addition Signed-off-by: Thomas Jäckle --- .../ditto/base/model/headers/IfEqual.java | 3 +- .../2023-10-16-release-announcement-340.md | 1 + .../jsonschema/protocol-envelope.json | 2 +- .../main/resources/openapi/ditto-api-2.yml | 3 +- .../sources/parameters/ifEqualHeaderParam.yml | 10 ++- .../resources/pages/ditto/httpapi-concepts.md | 15 +++- .../protocol-specification-things-merge.md | 8 +- .../pages/ditto/protocol-specification.md | 2 +- .../pages/ditto/release_notes_340.md | 12 +++ .../IfEqualPreconditionHeader.java | 2 +- .../eclipse/ditto/json/JsonMergePatch.java | 46 ++++++++--- ...ThingsConditionalHeadersValidatorTest.java | 77 ++++++++++++++++++- 12 files changed, 152 insertions(+), 29 deletions(-) diff --git a/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java b/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java index 2a5b9e9638..28f43e3ded 100644 --- a/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java +++ b/base/model/src/main/java/org/eclipse/ditto/base/model/headers/IfEqual.java @@ -37,9 +37,10 @@ public enum IfEqual { /** * Option which will skip the update of a twin if the new value is the same (via {@code equal()}) than the value * before. - * And additionally minimized a "Merge" command to only the actually changed fields compared to the current state + * And additionally minimizes a "Merge" command to only the actually changed fields compared to the current state * of the entity. This can be beneficial to reduce (persisted and emitted) events to the minimum of what actually * did change. + * * @since 3.4.0 */ SKIP_MINIMIZING_MERGE("skip-minimizing-merge"); diff --git a/documentation/src/main/resources/_posts/2023-10-16-release-announcement-340.md b/documentation/src/main/resources/_posts/2023-10-16-release-announcement-340.md index 86dca0e278..f57fa00820 100644 --- a/documentation/src/main/resources/_posts/2023-10-16-release-announcement-340.md +++ b/documentation/src/main/resources/_posts/2023-10-16-release-announcement-340.md @@ -36,6 +36,7 @@ Eclipse Ditto 3.4.0 focuses on the following areas: * Addition of a **new placeholder** to use **in connections** to use **payload of the thing JSON** e.g. in headers or addresses * New **placeholder functions** for **joining** multiple elements into a single string and doing **URL-encoding and -decoding** * Configure **MQTT message expiry interval for published messages** via a header +* **Reduce patch/merge thing commands** to **modify** only the **actually changed values** with a new option * UI enhancements: * Adding sending messages to Things * Made UI (at least navigation bar) responsive for small screen sizes diff --git a/documentation/src/main/resources/jsonschema/protocol-envelope.json b/documentation/src/main/resources/jsonschema/protocol-envelope.json index a8812a07e0..193b6700bd 100644 --- a/documentation/src/main/resources/jsonschema/protocol-envelope.json +++ b/documentation/src/main/resources/jsonschema/protocol-envelope.json @@ -34,7 +34,7 @@ }, "if-equal": { "type": "string", - "description": "The `if-equal` header can take the values 'update' (which is the default if omitted) or 'skip'.\nIf 'update' is defined, the entity will always be updated, even if it is equal before the update.\nIf 'skip' is defined, the entity not be updated if it is equal before the update. In this case a 'Not Modified' 304 status is returned." + "description": "The `if-equal` header can take the values 'update' (which is the default if omitted) or 'skip'.\nIf 'update' is defined, the entity will always be updated, even if it is equal before the update.\nIf 'skip' is defined, the entity not be updated if it is equal before the update. In this case a 'Precondition Failed' 412 status is returned.\nIf 'skip-minimizing-merge' is defined, the entity will not be updated if it is equal before the update. In this case a 'Precondition Failed' 412 status is returned. Additionally, merge/patch commands will be minimized to only the fields which actually changed, compared to the current state of the entity." }, "response-required": { "type": "boolean", diff --git a/documentation/src/main/resources/openapi/ditto-api-2.yml b/documentation/src/main/resources/openapi/ditto-api-2.yml index da01240f84..be48b3cb0b 100644 --- a/documentation/src/main/resources/openapi/ditto-api-2.yml +++ b/documentation/src/main/resources/openapi/ditto-api-2.yml @@ -8595,13 +8595,14 @@ components: IfEqualHeaderParam: name: if-equal in: header - description: 'The `if-equal` header can take the values ''update'' (which is the default if omitted) or ''skip''. If ''update'' is defined, the entity will always be updated, even if it is equal before the update. If ''skip'' is defined, the entity not be updated if it is equal before the update. In this case a ''Not Modified'' 304 status is returned.' + description: 'The `if-equal` header can take the values ''update'' (which is the default if omitted), ''skip'' or ''skip-minimizing-merge''. If ''update'' is defined, the entity will always be updated, even if it is equal before the update. If ''skip'' is defined, the entity not be updated if it is equal before the update. In this case a ''Precondition Failed'' 412 status is returned. If ''skip-minimizing-merge'' is defined, the entity will not be updated if it is equal before the update. In this case a ''Precondition Failed'' 412 status is returned. Additionally, merge/patch commands will be minimized to only the fields which actually changed, compared to the current state of the entity.' required: false schema: type: string enum: - update - skip + - skip-minimizing-merge ImportedPolicyIdPathParam: name: importedPolicyId in: path diff --git a/documentation/src/main/resources/openapi/sources/parameters/ifEqualHeaderParam.yml b/documentation/src/main/resources/openapi/sources/parameters/ifEqualHeaderParam.yml index a8ad4ab832..049ea35a3c 100644 --- a/documentation/src/main/resources/openapi/sources/parameters/ifEqualHeaderParam.yml +++ b/documentation/src/main/resources/openapi/sources/parameters/ifEqualHeaderParam.yml @@ -11,13 +11,17 @@ name: if-equal in: header description: >- - The `if-equal` header can take the values 'update' (which is the default if omitted) or 'skip'. + The `if-equal` header can take the values 'update' (which is the default if omitted), 'skip' or 'skip-minimizing-merge'. If 'update' is defined, the entity will always be updated, even if it is equal before the update. If 'skip' is defined, the entity not be updated if it is equal before the update. - In this case a 'Not Modified' 304 status is returned. + In this case a 'Precondition Failed' 412 status is returned. + If 'skip-minimizing-merge' is defined, the entity will not be updated if it is equal before the update. + In this case a 'Precondition Failed' 412 status is returned. + Additionally, merge/patch commands will be minimized to only the fields which actually changed, compared to the current state of the entity. required: false schema: type: string enum: - update - - skip \ No newline at end of file + - skip + - skip-minimizing-merge \ No newline at end of file diff --git a/documentation/src/main/resources/pages/ditto/httpapi-concepts.md b/documentation/src/main/resources/pages/ditto/httpapi-concepts.md index e0782be015..36fd9a749c 100644 --- a/documentation/src/main/resources/pages/ditto/httpapi-concepts.md +++ b/documentation/src/main/resources/pages/ditto/httpapi-concepts.md @@ -622,11 +622,18 @@ The following request headers can be used to issue a conditional request: * for read requests, status `304 (Not Modified)` without response body, with the current entity-tag of the resource as `ETag` header * `if-equal`: - * The `if-equal` header can take the values `'update'` (which is the default if omitted) or `'skip'` - * Write the resource only - * in case `if-equal: 'update'` is defined - even if the entity is equal before the update. + * The `if-equal` header can take the values `'update'` (which is the default if omitted), `'skip'` or `'skip-minimizing-merge'` + * Modify/Update the resource only + * in case `if-equal: 'update'` is defined always updates - even if the entity is equal before the update. * in case `if-equal: 'skip'` is defined, the entity will not be updated if it is equal before the update. - In this case a 'Not Modified' 304 status is returned. + In this case a 'Precondition Failed' 412 status is returned. + * in case `if-equal: 'skip-minimizing-merge'` is defined, the entity will not be updated if it is equal before the update. + In this case a 'Precondition Failed' 412 status is returned. + Additionally, [Merge commands](protocol-specification-things-merge.html) will be minimized to only the fields + which actually changed, compared to the current state of the entity. + * this reduces the part of a merge/patch command to the actually changed elements, removing non-changed elements + * this reduces e.g. required storage in the MongoDB by a lot, if redundant data is sent often + * this also reduces the event payload (e.g. emitted to subscribers) to only the actually changed parts of the thing Note that the Ditto HTTP API always provides a `strong` entity-tag in the `ETag` header, thus you will never receive a `weak` entity-tag (see [RFC-7232 Section 2.1](https://tools.ietf.org/html/rfc7232#section-2.1)). If you convert this diff --git a/documentation/src/main/resources/pages/ditto/protocol-specification-things-merge.md b/documentation/src/main/resources/pages/ditto/protocol-specification-things-merge.md index d2013f2809..beb6ae8693 100644 --- a/documentation/src/main/resources/pages/ditto/protocol-specification-things-merge.md +++ b/documentation/src/main/resources/pages/ditto/protocol-specification-things-merge.md @@ -20,10 +20,10 @@ If the Thing did not yet exist, it is created. ### Command -| Field | Value | -|-----------|-------------------------| -| **topic** | `//things//commands/merge` | -| **path** | `/` | +| Field | Value | +|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **topic** | `//things//commands/merge` | +| **path** | `/` | | **value** | The JSON value in [JSON merge patch](https://tools.ietf.org/html/rfc7396) format that is applied to the [Thing](basic-thing.html#thing) referenced in the `topic`. | ### Response diff --git a/documentation/src/main/resources/pages/ditto/protocol-specification.md b/documentation/src/main/resources/pages/ditto/protocol-specification.md index c99d137e9e..1f202fd344 100644 --- a/documentation/src/main/resources/pages/ditto/protocol-specification.md +++ b/documentation/src/main/resources/pages/ditto/protocol-specification.md @@ -93,7 +93,7 @@ There are some pre-defined headers, which have a special meaning for Ditto: | `ditto-originator` | Contains the first authorization subject of the command that caused the sending of this message. Set by Ditto. | `String` | | `if-match` | Has the same semantics as defined for the [HTTP API](httpapi-concepts.html#conditional-requests). | `String` | | `if-none-match` | Has the same semantics as defined for the [HTTP API](httpapi-concepts.html#conditional-requests). | `String` | -| `if-equal` | Has the same semantics as defined for the [HTTP API](httpapi-concepts.html#conditional-requests). | `String` - currently possible: \['update','skip'\] - default: `'update'` | +| `if-equal` | Has the same semantics as defined for the [HTTP API](httpapi-concepts.html#conditional-requests). | `String` - currently possible: \['update','skip','skip-minimizing-merge'\] - default: `'update'` | | `response-required` | Configures for a **command** whether or not a **response** should be sent back. | `Boolean` - default: `true` | | `requested-acks` | Defines which [acknowledgements](basic-acknowledgements.html) are requested for a command processed by Ditto. | `JsonArray` of `String` - default: `["twin-persisted"]` | | `ditto-weak-ack` | Marks [weak acknowledgements](basic-acknowledgements.html) issued by Ditto. | `Boolean` - default: `false` | diff --git a/documentation/src/main/resources/pages/ditto/release_notes_340.md b/documentation/src/main/resources/pages/ditto/release_notes_340.md index bc2b59d4a0..1bf945fe1b 100644 --- a/documentation/src/main/resources/pages/ditto/release_notes_340.md +++ b/documentation/src/main/resources/pages/ditto/release_notes_340.md @@ -23,6 +23,7 @@ Eclipse Ditto 3.4.0 focuses on the following areas: * Addition of a **new placeholder** to use **in connections** to use **payload of the thing JSON** e.g. in headers or addresses * New **placeholder functions** for **joining** multiple elements into a single string and doing **URL-encoding and -decoding** * Configure **MQTT message expiry interval for published messages** via a header +* **Reduce patch/merge thing commands** to **modify** only the **actually changed values** with a new option * UI enhancements: * Adding sending messages to Things * Made UI (at least navigation bar) responsive for small screen sizes @@ -89,6 +90,17 @@ header `mqtt.message-expiry-interval` as part of a [MQTT5 target header mapping] dynamically influencing the MQTT message expiry interval, e.g. as part of a payload mapper for certain to-be-published messages, or as a header mapping for all published messages. +#### Reduce patch/merge thing commands to modify only the actually changed values with a new option + +In [#1772](https://github.com/eclipse-ditto/ditto/pull/1772) the existing [if-equal header](httpapi-concepts.html#conditional-headers) +has been enhanced with a new option: `skip-minimizing-merge`. +Performing a [merge/patch command](protocol-specification-things-merge.html) and specifying this option as header will +cause that the merge command's payload will be minimized to only the values which will actually be changed in the thing. + +This reduces e.g. required storage in the MongoDB a lot, if redundant data is often sent and +also reduces the emitted event payload to [subscribers](basic-changenotifications.html) to only the actually changed +parts of the thing, reducing network load and making it more clear what actually changed with a "merge event". + #### Enhancements in Ditto explorer UI The UI was mainly enhanced with new features in a single PR, [#1773](https://github.com/eclipse-ditto/ditto/pull/1773). diff --git a/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java b/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java index aeef281236..1b1b7f16df 100644 --- a/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java +++ b/internal/utils/conditional-headers/src/main/java/org/eclipse/ditto/internal/utils/headers/conditional/IfEqualPreconditionHeader.java @@ -246,7 +246,7 @@ private C adjustMergeCommandByOnlyKeepingChanges(final C command, if (null == oldValue) { return command; } else if (command instanceof WithOptionalEntity commandWithEntity) { - return JsonMergePatch.compute(oldValue, newValue) + return JsonMergePatch.compute(oldValue, newValue, false) .map(jsonMergePatch -> { final JsonValue jsonValue = jsonMergePatch.asJsonValue(); return (C) commandWithEntity.setEntity(jsonValue); diff --git a/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java b/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java index 09d96353b0..a626436cdf 100644 --- a/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java +++ b/json/src/main/java/org/eclipse/ditto/json/JsonMergePatch.java @@ -43,18 +43,38 @@ private JsonMergePatch(final JsonValue mergePatch) { * * @param oldValue the original value * @param newValue the new changed value - * @return a JSON merge patch according to RFC 7386 or empty if values are equal. + * @return a JSON merge patch according to RFC 7386 + * or empty if values are equal. */ public static Optional compute(final JsonValue oldValue, final JsonValue newValue) { - return computeForValue(oldValue, newValue).map(JsonMergePatch::of); + return compute(oldValue, newValue, true); } - private static Optional computeForValue(final JsonValue oldValue, final JsonValue newValue) { + /** + * This method computes the change from the given {@code oldValue} to the given {@code newValue}. + * The result is a JSON merge patch according to RFC 7386. + * + * @param oldValue the original value + * @param newValue the new changed value + * @param deleteMissingFieldsWithNull whether to delete fields contained in {@code oldValue} by setting those to + * {@code null} as defined in RFC 7386. This is the default behavior in order to create a valid JSON merge patch. + * @return a JSON merge patch according to RFC 7386 + * or empty if values are equal. + * @since 3.4.0 + */ + public static Optional compute(final JsonValue oldValue, final JsonValue newValue, + final boolean deleteMissingFieldsWithNull) { + return computeForValue(oldValue, newValue, deleteMissingFieldsWithNull).map(JsonMergePatch::of); + } + + private static Optional computeForValue(final JsonValue oldValue, final JsonValue newValue, + final boolean deleteMissingFieldsWithNull) { @Nullable final JsonValue diff; if (oldValue.equals(newValue)) { diff = null; } else if (oldValue.isObject() && newValue.isObject()) { - diff = computeForObject(oldValue.asObject(), newValue.asObject()).orElse(null); + diff = computeForObject(oldValue.asObject(), newValue.asObject(), deleteMissingFieldsWithNull) + .orElse(null); } else { diff = newValue; } @@ -62,7 +82,8 @@ private static Optional computeForValue(final JsonValue oldValue, fin } private static Optional computeForObject(final JsonObject oldJsonObject, - final JsonObject newJsonObject) { + final JsonObject newJsonObject, + final boolean deleteMissingFieldsWithNull) { final JsonObjectBuilder builder = JsonObject.newBuilder(); final List oldKeys = oldJsonObject.getKeys(); final List newKeys = newJsonObject.getKeys(); @@ -72,10 +93,12 @@ private static Optional computeForObject(final JsonObject oldJsonObj .collect(Collectors.toList()); addedKeys.forEach(key -> newJsonObject.getValue(key).ifPresent(value -> builder.set(key, value))); - final List deletedKeys = oldKeys.stream() - .filter(key -> !newKeys.contains(key)) - .collect(Collectors.toList()); - deletedKeys.forEach(key -> builder.set(key, JsonValue.nullLiteral())); + if (deleteMissingFieldsWithNull) { + final List deletedKeys = oldKeys.stream() + .filter(key -> !newKeys.contains(key)) + .collect(Collectors.toList()); + deletedKeys.forEach(key -> builder.set(key, JsonValue.nullLiteral())); + } final List keptKeys = oldKeys.stream() .filter(newKeys::contains) @@ -84,7 +107,8 @@ private static Optional computeForObject(final JsonObject oldJsonObj final Optional oldValue = oldJsonObject.getValue(key); final Optional newValue = newJsonObject.getValue(key); if (oldValue.isPresent() && newValue.isPresent()) { - computeForValue(oldValue.get(), newValue.get()).ifPresent(diff -> builder.set(key, diff)); + computeForValue(oldValue.get(), newValue.get(), deleteMissingFieldsWithNull) + .ifPresent(diff -> builder.set(key, diff)); } else if (oldValue.isPresent()) { // Should never happen because deleted keys were handled before builder.set(key, JsonValue.nullLiteral()); @@ -98,7 +122,7 @@ private static Optional computeForObject(final JsonObject oldJsonObj } /** - * Creates a {@link JsonMergePatch} with an patch object containing the given {@code mergePatch} at the given {@code path}. + * Creates a {@link JsonMergePatch} with a patch object containing the given {@code mergePatch} at the given {@code path}. * * @param path The path on which the given {@code mergePatch} should be applied later. * @param mergePatch the actual patch. diff --git a/things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/ThingsConditionalHeadersValidatorTest.java b/things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/ThingsConditionalHeadersValidatorTest.java index edc0bf1a7a..03c8dc2c5d 100644 --- a/things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/ThingsConditionalHeadersValidatorTest.java +++ b/things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/ThingsConditionalHeadersValidatorTest.java @@ -41,6 +41,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonPointer; import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.things.model.FeatureProperties; import org.eclipse.ditto.things.model.Thing; import org.eclipse.ditto.things.model.ThingId; import org.eclipse.ditto.things.model.signals.commands.exceptions.ThingPreconditionFailedException; @@ -48,6 +49,7 @@ import org.eclipse.ditto.things.model.signals.commands.modify.MergeThing; import org.eclipse.ditto.things.model.signals.commands.modify.ModifyAttribute; import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing; +import org.junit.Assert; import org.junit.Test; /** @@ -198,7 +200,76 @@ public void ifEqualDoesThrowExceptionWhenIfEqualSkipAndValueIsEqualUsingMerge() assertThatExceptionOfType(ThingPreconditionFailedException.class) .isThrownBy(() -> SUT.applyIfEqualHeader(command, thing)) - .withMessage("The previous value was equal to the new value and the 'if-equal' header was set to 'skip'."); + .withMessage( + "The previous value was equal to the new value and the 'if-equal' header was set to 'skip'."); + } + + @Test + public void ifEqualSkipMinimizingMergeReducesMergeCommandToActuallyChangedJsonFields() { + final ThingId thingId = ThingId.generateRandom(); + final Thing existingThing = Thing.newBuilder() + .setId(thingId) + .setAttribute(JsonPointer.of("existing/bar"), JsonValue.of(false)) + .setAttribute(JsonPointer.of("other-existing"), JsonValue.of(42)) + .setFeature("some-feature", FeatureProperties.newBuilder() + .set("existing-prop", JsonObject.newBuilder() + .set("foo", 23) + .set("bar", false) + .build() + ).build() + ) + .build(); + + final JsonObject mergePayload = JsonObject.newBuilder() + .set("attributes", JsonObject.newBuilder() + .set("other-existing", JsonValue.of(42)) // already present in existingThing + .set("new-attr", JsonObject.newBuilder() // new field + .set("nested", JsonValue.of("Fantastic!")) + .build() + ).build() + ) + .set("features", JsonObject.newBuilder() + .set("some-feature", JsonObject.newBuilder() + .set("properties", JsonObject.newBuilder() + .set("existing-prop", JsonObject.newBuilder() + .set("foo", 99) // changed value + .set("bar", false) // already present in existingThing + .set("bum", "lux!") // new field + .build() + ).build() + ).build() + ) + .build() + ).build(); + final MergeThing command = MergeThing.of(thingId, JsonPointer.empty(), mergePayload, + DittoHeaders.newBuilder().ifEqual(IfEqual.SKIP_MINIMIZING_MERGE).build()); + + final JsonObject expectedMergePayload = JsonObject.newBuilder() + .set("attributes", JsonObject.newBuilder() + // .set("other-existing", JsonValue.of(42)) // already present in existingThing + .set("new-attr", JsonObject.newBuilder() // new field + .set("nested", JsonValue.of("Fantastic!")) + .build() + ).build() + ) + .set("features", JsonObject.newBuilder() + .set("some-feature", JsonObject.newBuilder() + .set("properties", JsonObject.newBuilder() + .set("existing-prop", JsonObject.newBuilder() + .set("foo", 99) // changed value + // .set("bar", false) // already present in existingThing + .set("bum", "lux!") // new field + .build() + ).build() + ).build() + ) + .build() + ).build(); + final MergeThing expectedMergeCommand = MergeThing.of(thingId, JsonPointer.empty(), expectedMergePayload, + DittoHeaders.newBuilder().ifEqual(IfEqual.SKIP_MINIMIZING_MERGE).build()); + final MergeThing adjustedMergeCommand = SUT.applyIfEqualHeader(command, existingThing); + + Assert.assertEquals(expectedMergeCommand, adjustedMergeCommand); } @Test @@ -243,7 +314,9 @@ private RetrieveThing createRetrieveThingCommand(final String ifNoneMatchHeaderV .ifNoneMatch(EntityTagMatchers.fromCommaSeparatedString(ifNoneMatchHeaderValue)) .build(); - return RetrieveThing.getBuilder(ThingId.of("under:test"), dittoHeaders).withSelectedFields(fieldSelector).build(); + return RetrieveThing.getBuilder(ThingId.of("under:test"), dittoHeaders) + .withSelectedFields(fieldSelector) + .build(); }