Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit ce604ce

Browse files
authored
Merge pull request #12 from kenwenzel/refactor-and-adapt
Partially fixed TransformationIntegrationTest.
2 parents e06a072 + f3f1a3e commit ce604ce

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

src/main/java/com/sap/dsc/aas/lib/expressions/Expressions.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
import static com.sap.dsc.aas.lib.expressions.Helpers.valueToStream;
1111

1212
import java.nio.charset.StandardCharsets;
13+
import java.util.Base64;
1314
import java.util.Collections;
1415
import java.util.HashMap;
1516
import java.util.Iterator;
16-
import java.util.List;
1717
import java.util.Map;
1818
import java.util.Objects;
1919
import java.util.Set;
20-
import java.util.Stack;
2120
import java.util.function.Function;
22-
import java.util.function.Supplier;
2321
import java.util.stream.Collectors;
2422
import java.util.stream.IntStream;
2523
import java.util.stream.Stream;
2624

25+
import org.dom4j.Node;
26+
2727
import com.google.common.hash.Hashing;
2828

2929
public class Expressions {
@@ -137,6 +137,19 @@ public class Expressions {
137137
String concatenated = stream.map(Object::toString).collect(Collectors.joining());
138138
return Hashing.sha256().hashString(concatenated, StandardCharsets.UTF_8).toString();
139139
});
140+
141+
// string encoding
142+
functions.put("base64", args -> {
143+
Stream<Object> stream = (Stream<Object>) valueToStream(args);
144+
String concatenated = stream.flatMap(o -> valueToStream(o)).map(o -> {
145+
if (o instanceof Node) {
146+
return ((Node) o).getStringValue();
147+
} else {
148+
return String.valueOf(o);
149+
}
150+
}).collect(Collectors.joining());
151+
return Base64.getEncoder().encodeToString(concatenated.getBytes());
152+
});
140153
}
141154

142155
public static Function<Object, Object> getFunctionByName(String name) {

src/test/java/com/sap/dsc/aas/lib/TransformationIntegrationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ SubmodelElement getElement(String idShort, Submodel submodel) {
384384
assertThat(submodel.getSubmodelElements()).isNotNull();
385385

386386
return submodel.getSubmodelElements().stream()
387-
.filter(submodelElement -> submodelElement.getIdShort().equals(idShort))
387+
.filter(submodelElement -> idShort.equals(submodelElement.getIdShort()))
388388
.findFirst()
389389
.orElseThrow(() -> new AssertionFailedError("SubmodelElement with IdShort '" + idShort + "' not found"));
390390
}
@@ -393,7 +393,7 @@ Submodel getSubmodel(String idShort) {
393393
assertNotNull(shellEnv.getSubmodels());
394394

395395
return shellEnv.getSubmodels().stream()
396-
.filter(submodel -> submodel.getIdShort().equals(idShort))
396+
.filter(submodel -> idShort.equals(submodel.getIdShort()))
397397
.findFirst()
398398
.orElseThrow(() -> new AssertionFailedError("Submodel with IdShort '" + idShort + "' not found"));
399399
}

src/test/resources/config/simpleConfig.json

+56-14
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,17 @@
3333
}
3434
},
3535
"@variables": {
36-
"submodel3Id": {
37-
"@xpath": "submodel3"
38-
},
36+
"submodel3Id": "submodel3",
3937
"submodelDocsId": "submodelDocuments"
4038
}
4139
},
4240
"aasEnvironmentMapping": {
41+
"@foreach": {
42+
"@xpath": "//caex:SystemUnitClass[caex:SupportedRoleClass/@RefRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent' or caex:RoleRequirements/@RefBaseRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent'] | //caex:InternalElement[caex:SupportedRoleClass/@RefRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent' or caex:RoleRequirements/@RefBaseRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent']"
43+
},
4344
"assets": [],
4445
"assetAdministrationShells": [
4546
{
46-
"@foreach": {
47-
"@xpath": "//caex:SystemUnitClass[caex:SupportedRoleClass/@RefRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent' or caex:RoleRequirements/@RefBaseRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent'] | //caex:InternalElement[caex:SupportedRoleClass/@RefRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent' or caex:RoleRequirements/@RefBaseRoleClassPath='AutomationMLComponentStandardRCL/AutomationComponent']"
48-
},
4947
"@bind": {
5048
"idShort": {
5149
"@xpath": "@Name"
@@ -88,9 +86,7 @@
8886
]
8987
},
9088
"@variables": {
91-
"submodel3Id": {
92-
"@xpath": "this is an updated Variable"
93-
}
89+
"submodel3Id": "this is an updated Variable"
9490
},
9591
"identification": {
9692
"@bind": {
@@ -255,10 +251,10 @@
255251
"value": [
256252
{
257253
"@bind": {
258-
"lang": {
254+
"language": {
259255
"@xpath": "'en'"
260256
},
261-
"value": {
257+
"text": {
262258
"@xpath": "caex:Value"
263259
}
264260
}
@@ -325,7 +321,12 @@
325321
},
326322
{
327323
"@foreach": {
328-
"@xpath": "caex:Attribute[@Name='GeneralTechnicalData']"
324+
"@caexAttributeName": "GeneralTechnicalData"
325+
},
326+
"@bind": {
327+
"idShort": {
328+
"@xpath": "@Name"
329+
}
329330
},
330331
"semanticId": {
331332
"keys": [
@@ -354,6 +355,11 @@
354355
"@foreach": {
355356
"@caexAttributeName": "AmbientTemperature"
356357
},
358+
"@bind": {
359+
"idShort": {
360+
"@xpath": "@Name"
361+
}
362+
},
357363
"modelType": {
358364
"name": "Range"
359365
},
@@ -378,16 +384,50 @@
378384
"@foreach": {
379385
"@caexAttributeName": "Material"
380386
},
387+
"@bind": {
388+
"idShort": {
389+
"@xpath": "@Name"
390+
}
391+
},
381392
"modelType": {
382393
"name": "MultiLanguageProperty"
383-
}
394+
},
395+
"value": [
396+
{
397+
"@foreach": {
398+
"@caexAttributeName": "aml-lang=en-US"
399+
},
400+
"@bind": {
401+
"language": "en",
402+
"text": {
403+
"@xpath": "caex:Value"
404+
}
405+
}
406+
},
407+
{
408+
"@foreach": {
409+
"@caexAttributeName": "aml-lang=de-DE"
410+
},
411+
"@bind": {
412+
"language": "de",
413+
"text": {
414+
"@xpath": "caex:Value"
415+
}
416+
}
417+
}
418+
]
384419
}
385420
]
386421
},
387422
{
388423
"@foreach": {
389424
"@caexAttributeName": "ParameterData"
390425
},
426+
"@bind": {
427+
"idShort": {
428+
"@xpath": "@Name"
429+
}
430+
},
391431
"semanticId": {
392432
"keys": [
393433
{
@@ -497,7 +537,9 @@
497537
"@xpath": "'BetriebsanleitungBIN'"
498538
},
499539
"value": {
500-
"@xpath": "caex:Attribute[@Name='refURI']/caex:Value"
540+
"@base64": {
541+
"@xpath": "caex:Attribute[@Name='refURI']/caex:Value"
542+
}
501543
},
502544
"mimeType": {
503545
"@xpath": "caex:Attribute[@Name='MIMEType']/caex:Value"

0 commit comments

Comments
 (0)