Skip to content

Commit 13158b9

Browse files
FriedJannikaaronzi
andauthored
Fixes Bug in HierarchicalSubmodelElementParser (eclipse-basyx#694)
* Adds Submodel Service docker release step * Fixes Bug in HierarchicalSubmodelElementParser * Removes unrelated change --------- Co-authored-by: Aaron Zielstorff <[email protected]>
1 parent 606c8f0 commit 13158b9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/pathparsing/HierarchicalSubmodelElementParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public SubmodelElement getSubmodelElementFromIdShortPath(String idShortPath) thr
8585
*/
8686
public String getIdShortPathOfParentElement(String idShortPath) {
8787

88+
boolean isLastElementABracket = idShortPath.endsWith("]");
89+
if (isLastElementABracket){
90+
int lastElementBracketIndex = idShortPath.lastIndexOf("[");
91+
return idShortPath.substring(0, lastElementBracketIndex);
92+
}
93+
8894
int lastElementIdShortIndex = idShortPath.lastIndexOf(".");
8995

9096
if (lastElementIdShortIndex == -1)

basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelElementIdShortPathParserTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Stack;
3030

3131
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException;
32+
import org.eclipse.digitaltwin.basyx.submodelservice.pathparsing.HierarchicalSubmodelElementParser;
3233
import org.eclipse.digitaltwin.basyx.submodelservice.pathparsing.PathToken;
3334
import org.eclipse.digitaltwin.basyx.submodelservice.pathparsing.SubmodelElementIdShortPathParser;
3435
import org.junit.Test;
@@ -78,4 +79,27 @@ public void idShortWithSpecialCharactersDoesNotThrowError() {
7879
Stack<PathToken> tokenStack = pathParser.parsePathTokens(ID_SHORT_WITH_SPECIAL_CHARACTERS);
7980
assertEquals(ID_SHORT_WITH_SPECIAL_CHARACTERS, tokenStack.pop().getToken());
8081
}
82+
83+
@Test
84+
public void parentPathIsExtractedCorrectly() {
85+
String[][] testCases = {
86+
// input expected output
87+
{ "a", "a" },
88+
{ "a.b", "a" },
89+
{ "a.b[0]", "a.b" },
90+
{ "a.b[0].c", "a.b[0]" },
91+
{ "a.b[0].c.d", "a.b[0].c" },
92+
{ "sensor[3].value[1]", "sensor[3].value" },
93+
{ "root.list[12][3]", "root.list[12]" },
94+
{ "deep.nest[4].elem[2].data", "deep.nest[4].elem[2]" },
95+
};
96+
97+
for (String[] testCase : testCases) {
98+
String input = testCase[0];
99+
String expected = testCase[1];
100+
HierarchicalSubmodelElementParser hierarchicalSubmodelElementParser = new HierarchicalSubmodelElementParser(null);
101+
String actual = hierarchicalSubmodelElementParser.getIdShortPathOfParentElement(input);
102+
assertEquals("Failed for input: " + input, expected, actual);
103+
}
104+
}
81105
}

basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,23 @@ public void updateFileSMEWithFileSME() throws FileNotFoundException, IOException
464464
assertStoredFileContentEquals(submodelService, idShortPathPropertyInSmeCol, DUMMY_JSON_2);
465465
}
466466

467+
@Test
468+
public void updateSMEInSubmodelElementList(){
469+
Submodel operationDataSubmodel = DummySubmodelFactory.createOperationalDataSubmodelWithHierarchicalSubmodelElements();
470+
SubmodelService submodelService = getSubmodelService(operationDataSubmodel);
471+
472+
DefaultProperty submodelElement = (DefaultProperty) submodelService.getSubmodelElement(generateIdShortPath());
473+
474+
String expectedValue = "1308";
475+
submodelElement.setValue(expectedValue);
476+
477+
submodelService.updateSubmodelElement(generateIdShortPath(), submodelElement);
478+
479+
DefaultProperty actualElement = (DefaultProperty) submodelService.getSubmodelElement(generateIdShortPath());
480+
481+
assertEquals(expectedValue, actualElement.getValue());
482+
}
483+
467484
@Test
468485
public void deleteNestedSubmodelElementInSubmodelElementCollection() {
469486
Submodel operationDataSubmodel = DummySubmodelFactory.createOperationalDataSubmodelWithHierarchicalSubmodelElements();

0 commit comments

Comments
 (0)