From 256660955889f3b095e8b538252e996cd0a2f833 Mon Sep 17 00:00:00 2001 From: Gerhard Sonnenberg <53293048+geso02@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:24:11 +0100 Subject: [PATCH] Fix removal of submodel removes other root attributes (#131) * Fix removal of submodel removes other root attributes Use set operation for update instead of set refs #129 * Remove line comment --- ...torAndWasPresent_thenElementIsRemoved.json | 42 +++++++++++++- ...dWasPresent_thenElementIsRemoved_repo.json | 56 +++++++++++++++++++ .../mongodb/MongoDbAasRegistryStorage.java | 4 +- 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json diff --git a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json index 856fb06d6..b949df23a 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json +++ b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json @@ -1,13 +1,49 @@ [ { - "id": "identification_1" + "id": "identification_1", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "1" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "BLUE" + } + ] }, { "id": "identification_2", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "2" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "RED" + } + ], "submodelDescriptors": [ { - "id": "identification_2.1" + "id": "identification_2.1", + "extensions": [ + { + "name": "COLOR", + "value": "RED" + } + ] } ] - } + } ] \ No newline at end of file diff --git a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json new file mode 100644 index 000000000..e83ab82aa --- /dev/null +++ b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json @@ -0,0 +1,56 @@ +[ + { + "id": "identification_1", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "1" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "BLUE" + } + ] + }, + { + "id": "identification_2", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "2" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "RED" + } + ], + "submodelDescriptors": [ + { + "id": "identification_2.1", + "extensions": [ + { + "name": "COLOR", + "value": "RED" + }] + }, + { + "id": "identification_2.2", + "extensions": [ + { + "name": "COLOR", + "value": "RED" + }] + } + ] + } +] \ No newline at end of file diff --git a/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java b/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java index ee7e30253..df50917e2 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java +++ b/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java @@ -62,6 +62,7 @@ import org.springframework.data.mongodb.core.aggregation.ArrayOperators; import org.springframework.data.mongodb.core.aggregation.ComparisonOperators; import org.springframework.data.mongodb.core.aggregation.MatchOperation; +import org.springframework.data.mongodb.core.aggregation.SetOperation; import org.springframework.data.mongodb.core.aggregation.SortOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -69,6 +70,7 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition; import com.mongodb.ClientSessionOptions; +import com.mongodb.internal.operation.UpdateOperation; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -274,7 +276,7 @@ private void assertReplacePerformed(AssetAdministrationShellDescriptor descr, St public void removeSubmodel(@NonNull String aasDescriptorId, @NonNull String submodelId) throws AasDescriptorNotFoundException, SubmodelNotFoundException { AggregationExpression notEquals = ComparisonOperators.valueOf(SUBMODEL_DESCRIPTORS_ID).notEqualToValue(submodelId); AggregationExpression filterArray = ArrayOperators.arrayOf(SUBMODEL_DESCRIPTORS).filter().as(SUBMODEL_DESCRIPTORS).by(notEquals); - AggregationUpdate update = Aggregation.newUpdate(Aggregation.project(SUBMODEL_DESCRIPTORS).and(filterArray).as(SUBMODEL_DESCRIPTORS)); + AggregationUpdate update = AggregationUpdate.update().set(SUBMODEL_DESCRIPTORS).toValue(filterArray); AssetAdministrationShellDescriptor old = template.findAndModify(Query.query(Criteria.where(ID).is(aasDescriptorId)), update, AssetAdministrationShellDescriptor.class); if (old == null) { throw new AasDescriptorNotFoundException(submodelId);