Skip to content

Commit

Permalink
Fix removal of submodel removes other root attributes (#131)
Browse files Browse the repository at this point in the history
* Fix removal of submodel removes other root attributes

Use set operation for update instead of set

refs #129

* Remove line comment
  • Loading branch information
geso02 authored Nov 14, 2023
1 parent 164fb59 commit 2566609
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -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"
}]
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@
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;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.mongodb.core.query.UpdateDefinition;

import com.mongodb.ClientSessionOptions;
import com.mongodb.internal.operation.UpdateOperation;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2566609

Please sign in to comment.