Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removal of submodel removes other root attributes #131

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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