Skip to content

Commit

Permalink
Merge pull request #12 from arnoweiss/main
Browse files Browse the repository at this point in the history
add uuid gen and update dependencies
  • Loading branch information
arnoweiss authored Jul 12, 2023
2 parents e9a073a + cea0956 commit d6d620a
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/delete-package-versions@v4
continue-on-error: true
with:
package-name: 'com.sap.dsc.aas.lib.aas-transformation-library'
package-name: 'org.eclipse.digitaltwin.aas4j.aas4j-transformation-library'
- name: Publish package
run: ./gradlew -i publish
env:
Expand Down
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-FileCopyrightText: (C)2021 SAP SE or an affiliate company and aas-transformation-library contributors. All rights reserved.
SPDX-FileCopyrightText: (C)2021 SAP SE or an affiliate company and aas4j-transformation-library contributors. All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -17,7 +17,7 @@ plugins {
}

group = 'org.eclipse.digitaltwin.aas4j'
version = '0.1.2'
version = '0.1.3'

application {
group = group
Expand Down Expand Up @@ -154,15 +154,15 @@ spotless {
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
licenseHeader('/* \n SPDX-FileCopyrightText: (C)$YEAR SAP SE or an affiliate company and aas-transformation-library contributors. All rights reserved. \n\n SPDX-License-Identifier: Apache-2.0 \n */','\\w')
licenseHeader('/* \n SPDX-FileCopyrightText: (C)$YEAR SAP SE or an affiliate company and aas4j-transformation-library contributors. All rights reserved. \n\n SPDX-License-Identifier: Apache-2.0 \n */','\\w')
}

// format 'xmlaml', {
// target('src/**/*.xml','src/**/*.aml')
// trimTrailingWhitespace()
// indentWithSpaces()
// endWithNewline()
// licenseHeader('<!-- \n SPDX-FileCopyrightText: (C)$YEAR SAP SE or an affiliate company and aas-transformation-library contributors. All rights reserved. \n\n SPDX-License-Identifier: Apache-2.0 \n -->','<[^!]')
// licenseHeader('<!-- \n SPDX-FileCopyrightText: (C)$YEAR SAP SE or an affiliate company and aas4j-transformation-library contributors. All rights reserved. \n\n SPDX-License-Identifier: Apache-2.0 \n -->','<[^!]')
// }

java {
Expand All @@ -172,7 +172,7 @@ spotless {
endWithNewline()
eclipse('4.12.0').configFile 'codestyle/EclipseFormatterProfile.xml'
importOrderFile('codestyle/EclipseOrganizeImports.importorder')
licenseHeader('/* \n SPDX-FileCopyrightText: (C)$YEAR SAP SE or an affiliate company and aas-transformation-library contributors. All rights reserved. \n\n SPDX-License-Identifier: Apache-2.0 \n */')
licenseHeader('/* \n SPDX-FileCopyrightText: (C)$YEAR SAP SE or an affiliate company and aas4j-transformation-library contributors. All rights reserved. \n\n SPDX-License-Identifier: Apache-2.0 \n */')
}
}

Expand Down Expand Up @@ -218,8 +218,8 @@ task buildJar (type: Jar) {

exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/NOTICE', 'META-INF/LICENSE', 'META-INF/DEPENDENCIES'

archiveExtension.set('jar')
with jar
archiveExtension.set('jar')
}

task build(overwrite: true) {
Expand All @@ -228,12 +228,12 @@ task build(overwrite: true) {

shadowJar {
destinationDirectory = file("${buildDir}/distributions")
archiveClassifier.set("")

exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/NOTICE', 'META-INF/LICENSE', 'META-INF/LICENSE'

archiveBaseName.set("aas-transformation-library")
archiveBaseName.set("aas4j-transformation-library")
archiveAppendix.set("shadow")
archiveClassifier.set("shadedJar")
archiveExtension.set("jar")
}

Expand All @@ -254,7 +254,7 @@ publishing {
}
publications {
gpr(MavenPublication) {
artifact jar
from components.java
}
}
}
Expand All @@ -266,7 +266,7 @@ dependencies {
def mockito_version = "3.2.4"
def dom4j_version = "2.1.3"
def apache_poi_version = "4.1.2"
def jackson_version = "2.11.3"
def jackson_version = "2.14.2"
def truth_version = "1.1"
def slf4j_version = "1.7.30"
def json_schema_validator_version = "1.0.45"
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
SPDX-License-Identifier: Apache-2.0
*/
rootProject.name = 'aas-transformation-library'
rootProject.name = 'aas4j-transformation-library'
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
package org.eclipse.digitaltwin.aas4j.expressions;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand All @@ -21,6 +15,7 @@
import org.dom4j.Node;

import com.google.common.hash.Hashing;
import org.eclipse.digitaltwin.aas4j.exceptions.TransformationException;

public class Expressions {

Expand Down Expand Up @@ -135,6 +130,18 @@ public class Expressions {
return Hashing.sha256().hashString(concatenated, StandardCharsets.UTF_8).toString();
});

functions.put("generate_uuid", args ->
{
boolean isEmpty = Helpers.valueToStream(args).allMatch(element -> element.equals(""));
if (args == null || isEmpty) {
return UUID.randomUUID();
} else {
String input = nodeListsToString(Helpers.valueToStream(args)).collect(Collectors.joining());
return UUID.nameUUIDFromBytes(input.getBytes());
}
}
);

// string encoding
functions.put("base64", args -> {
Stream<Object> stream = (Stream<Object>) Helpers.valueToStream(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ static TransformationContext buildContext(TransformationContext parentCtx, Objec
}
// add and/or override with template context
if (template != null) {
if (template.getDefinitions() != null) {
build.definitions.putAll(template.getDefinitions());
if (template.getTemplateDefinitions() != null) {
build.definitions.putAll(template.getTemplateDefinitions());
}
if (template.getVariables() != null) {
template.getVariables().forEach((key, expr) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void setForeachExpression(Expression expression) {
}

@Override
public Map<String, Expression> getDefinitions() {
return template.getDefinitions();
public Map<String, Expression> getTemplateDefinitions() {
return template.getTemplateDefinitions();
}

@Override
public void setDefinitions(Map<String, Expression> definitions) {
template.setDefinitions(definitions);
public void setTemplateDefinitions(Map<String, Expression> definitions) {
template.setTemplateDefinitions(definitions);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public interface Template {
@JsonProperty("@foreach")
void setForeachExpression(Expression expression);

Map<String, Expression> getDefinitions();
Map<String, Expression> getTemplateDefinitions();

@JsonProperty("@definitions")
void setDefinitions(Map<String, Expression> definitions);
void setTemplateDefinitions(Map<String, Expression> definitions);

Map<String, Expression> getVariables();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public void setForeachExpression(Expression foreachExpression) {
}

@Override
public Map<String, Expression> getDefinitions() {
public Map<String, Expression> getTemplateDefinitions() {
return definitions;
}

@Override
public void setDefinitions(Map<String, Expression> definitions) {
public void setTemplateDefinitions(Map<String, Expression> definitions) {
this.definitions = definitions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ void setup() {
mockDefs1.put("myDef", Expressions.getConstantByName("pi"));
mockTemplate1 = Mockito.mock(Template.class);
Mockito.when(mockTemplate1.getVariables()).thenReturn(null);
Mockito.when(mockTemplate1.getDefinitions()).thenReturn(mockDefs1);
Mockito.when(mockTemplate1.getTemplateDefinitions()).thenReturn(mockDefs1);

HashMap<String, Expression> mockDefs2 = new HashMap<>();
mockDefs2.put("myDef", Expressions.getConstantByName("NaN"));
mockDefs2.put("myDef2", Expressions.getConstantByName("e"));
mockTemplate2 = Mockito.mock(Template.class);
Mockito.when(mockTemplate2.getVariables()).thenReturn(null);
Mockito.when(mockTemplate2.getDefinitions()).thenReturn(mockDefs2);
Mockito.when(mockTemplate2.getTemplateDefinitions()).thenReturn(mockDefs2);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@

import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class GenericDocumentTransformerTest {

public static final String XML_INPUT = "src/test/resources/ua/aasfull.xml";
public static final String JSON_CONFIG = "src/test/resources/ua/genericSampleConfig.json";
public static final String SPARQL_XML_INPUT = "src/test/resources/xml/groupable.xml";
public static final String NESTED_FOR_EACH_JSON_CONFIG = "src/test/resources/mappings/generic/nestedForEach.json";


private InputStream testInputStream;

Expand All @@ -39,14 +45,14 @@ static void tearDownAfterClass() throws Exception {}
@BeforeEach
void setUp() throws Exception {
TestUtils.resetBindings();
testInputStream = Files.newInputStream(Paths.get(XML_INPUT));
}

@AfterEach
void tearDown() throws Exception {}

@Test
void testNsBindings() throws TransformationException, IOException {
testInputStream = Files.newInputStream(Paths.get(XML_INPUT));
DocumentTransformer transformer = new GenericDocumentTransformer();

MappingSpecification mapping = new MappingSpecificationParser().loadMappingSpecification(JSON_CONFIG);
Expand All @@ -56,4 +62,17 @@ void testNsBindings() throws TransformationException, IOException {
Assert.assertEquals(71, transform.getSubmodels().size());
}

@Test
void testNestedForEach() throws IOException, TransformationException {
testInputStream = Files.newInputStream(Paths.get(SPARQL_XML_INPUT));
DocumentTransformer transformer = new GenericDocumentTransformer();

MappingSpecification mapping = new MappingSpecificationParser().loadMappingSpecification(NESTED_FOR_EACH_JSON_CONFIG);

AssetAdministrationShellEnvironment transform = transformer.execute(testInputStream, mapping);

assertEquals(2, transform.getSubmodels().size());
assertTrue(transform.getSubmodels().stream().anyMatch(sm -> sm.getIdShort().equals("131")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ void testIntegration() throws Exception {
boolean idInEnv = shellEnv.getSubmodels().stream().map(s -> s.getIdentification().getIdentifier())
.collect(Collectors.toList()).contains("http://exp.organization.com/UA/BigMachine/ns=4;i=1281");
assertTrue(idInEnv);

assertEquals("407ef772-7040-3b9e-b51a-80286d1c8e49", shellEnv.getAssetAdministrationShells().get(0).getIdentification().getIdentifier());

//this value was extracted from the first run. Since it should change
assertNotEquals("6b6dcb8f-352c-49f7-8267-e2586601e858", shellEnv.getAssetAdministrationShells().get(0).getIdShort());

}

@Test
Expand Down
52 changes: 52 additions & 0 deletions src/test/resources/mappings/generic/nestedForEach.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"@header": {
"version": "1.0.0",
"aasVersion": "3.0RC01",
"@namespaces": {
"ns": "http://ns.org/"
}
},
"aasEnvironmentMapping": {
"submodels": [
{
"@foreach": {
"@xpath": "//ns:a/ns:c[not(.=../following::ns:c)]"
},
"@variables": {
"here": {
"@xpath": "."
}
},
"semanticId": {
"keys": [
{
"@bind": {
"value": {
"@var": "here"
}
},
"idType": "Iri",
"type": "Submodel"
}
]
},
"@bind": {
"idShort": {
"@concatenate": [
{
"@xpath": {
"@concatenate": [
"//ns:a[ns:c='",
{
"@var": "here"
},
"']/ns:b[@name='prop_b']"
]
}
}]
}
}
}
]
}
}
14 changes: 11 additions & 3 deletions src/test/resources/ua/uaIntegrationTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
"assets": [],
"assetAdministrationShells": [
{
"idShort": "UaAdminShell",
"@bind": {
"idShort": {
"@generate_uuid": ""
}
},
"identification": {
"idType": "Custom",
"id": "UaAdminShellId"
"@bind": {
"idType": "Custom",
"id": {
"@generate_uuid": "someStringAsSeed"
}
}
},
"assetInformation": {
"@bind": {
Expand Down
27 changes: 27 additions & 0 deletions src/test/resources/xml/groupable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<ns:root xmlns:ns="http://ns.org/" targetNamespace="http://ns.org/">
<ns:a>
<ns:c>foo</ns:c>
<ns:b name="prop_b">1</ns:b>
<ns:b name="prop_c">2</ns:b>
</ns:a>
<ns:a>
<ns:c>foo</ns:c>
<ns:b name="prop_b">3</ns:b>
<ns:b name="prop_c">3</ns:b>
</ns:a>
<ns:a>
<ns:c>foo</ns:c>
<ns:b name="prop_b">1</ns:b>
<ns:b name="prop_c">2</ns:b>
</ns:a>
<ns:a>
<ns:c>bar</ns:c>
<ns:b name="prop_b">4</ns:b>
<ns:b name="prop_c">5</ns:b>
</ns:a>
<ns:a>
<ns:c>bar</ns:c>
<ns:b name="prop_b">4</ns:b>
<ns:b name="prop_c">8</ns:b>
</ns:a>
</ns:root>

0 comments on commit d6d620a

Please sign in to comment.