Skip to content

Commit

Permalink
Merge pull request #260 from eclipse-basyx/development
Browse files Browse the repository at this point in the history
BaSyx Java 1.4.0 release
  • Loading branch information
FrankSchnicke authored Apr 3, 2023
2 parents cc8c441 + a79f7c4 commit 04d2957
Show file tree
Hide file tree
Showing 48 changed files with 1,978 additions and 165 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/maven-publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ jobs:
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Maven
run: mvn -B package --file pom.xml


- name: Delete old sdk package
uses: actions/delete-package-versions@v3
continue-on-error: true
with:
package-name: 'org.eclipse.basyx.basyx.sdk'

- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml -DskipTests
env:
GITHUB_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion .github/workflows/maven-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B install --file pom.xml
35 changes: 24 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.eclipse.basyx</groupId>
<artifactId>basyx.sdk</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
<name>BaSyx SDK</name>
<description>BaSyx Software Development Kit</description>
<url>https://www.eclipse.org/basyx/</url>
Expand Down Expand Up @@ -46,7 +46,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-security-version>5.8.1</spring-security-version>
<spring-security-version>5.8.2</spring-security-version>
</properties>

<repositories>
Expand All @@ -65,7 +65,7 @@
<!-- Compile Sources using Java 11 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
Expand Down Expand Up @@ -110,7 +110,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M8</version>
<version>3.0.0</version>
<configuration>
<excludes>
<exclude>**/*HTTP*</exclude>
Expand All @@ -126,7 +126,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M8</version>
<version>3.0.0</version>
<configuration>
<includes>
<include>**/*HTTP*</include>
Expand All @@ -147,7 +147,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<configuration>
<source>8</source>
</configuration>
Expand All @@ -169,7 +169,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.5</version>
<version>1.4.6</version>
</dependency>

<!-- JUnit 4 for running JUnit tests -->
Expand All @@ -184,7 +184,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.1.1</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -234,21 +234,21 @@
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.38</version>
<version>2.39.1</version>
</dependency>

<!-- Jersey InjectionManager (for Jersey client) -->
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.38</version>
<version>2.39.1</version>
</dependency>

<!-- Tomcat 8 for HTTP server resource -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.71</version>
<version>9.0.73</version>
</dependency>

<!-- Used for creating .aasx files -->
Expand Down Expand Up @@ -349,6 +349,19 @@
<version>5.9.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private MultiSubmodelProvider createMultiSubmodelProvider(AssetAdministrationShe
IConnectorFactory connectorFactory = new HTTPConnectorFactory();
IAASAPI aasApi = aasApiFactory.create(aas);
AASModelProvider contentProvider = new AASModelProvider(aasApi);
return new MultiSubmodelProvider(contentProvider, registry, connectorFactory, aasApiFactory, submodelAggregatorFactory.create());
return new MultiSubmodelProvider(contentProvider, registry, connectorFactory, aasApiFactory, submodelAggregatorFactory.create(aas.getIdentification()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
Expand Down Expand Up @@ -75,6 +77,7 @@ public class AASXToMetamodelConverter {

private static final String XML_TYPE = "http://www.admin-shell.io/aasx/relationships/aas-spec";
private static final String AASX_ORIGIN = "/aasx/aasx-origin";
public static final String TEMP_DIRECTORY = "basyx-temp";

private String aasxPath;
private OPCPackage aasxRoot;
Expand Down Expand Up @@ -136,6 +139,13 @@ public <T extends AASBundle> Set<T> retrieveAASBundles() throws IOException, Par
return (Set<T>) bundles;
}

public InputStream retrieveFileInputStream(String path) throws InvalidFormatException, IOException {
loadAASX();
PackagePart filePart = aasxRoot.getPart(PackagingURIHelper.createPartName(path));
closeOPCPackage();
return filePart.getInputStream();
}

private void loadAASX() throws IOException, InvalidFormatException {
if (aasxInputStream == null) {
aasxInputStream = FileLoaderHelper.getInputStream(aasxPath);
Expand Down Expand Up @@ -270,7 +280,7 @@ private List<String> parseElements(Collection<ISubmodelElement> elements) {
* @throws InvalidFormatException
*/
public void unzipRelatedFiles() throws IOException, ParserConfigurationException, SAXException, URISyntaxException, InvalidFormatException {
unzipRelatedFiles(getRootFolder());
unzipRelatedFiles(getTemporaryDirPath());
}

/**
Expand All @@ -294,14 +304,27 @@ public void unzipRelatedFiles(Path pathToDirectory) throws InvalidFormatExceptio
closeOPCPackage();
}

/**
* Creates a temporary directory to hold the unpackaged files.
*
* @return Path of the temporary directory
*
*/
protected Path getTemporaryDirPath() {
return Paths.get(FileUtils.getTempDirectory().getAbsolutePath(), TEMP_DIRECTORY);
}

/**
* Create a folder to hold the unpackaged files The folder has the path
* \target\classes\docs
*
* @throws IOException
* @throws URISyntaxException
*
* @deprecated This method is deprecated. Please use the {@link AASXToMetamodelConverter#getTemporaryDirPath()}
*/
protected Path getRootFolder() throws IOException, URISyntaxException {
@Deprecated(since = "1.4.0", forRemoval = true)
protected Path getRootFolder() throws URISyntaxException, IOException {
URI uri = AASXToMetamodelConverter.class.getProtectionDomain().getCodeSource().getLocation().toURI();
URI parent = new File(uri).getParentFile().toURI();
return Paths.get(parent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/
package org.eclipse.basyx.aas.factory.json;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
import org.eclipse.basyx.submodel.metamodel.api.ISubmodel;
import org.eclipse.basyx.submodel.metamodel.api.reference.IKey;
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
import org.eclipse.basyx.submodel.metamodel.map.reference.Key;
import org.eclipse.basyx.vab.coder.json.serialization.DefaultTypeFactory;
import org.eclipse.basyx.vab.coder.json.serialization.GSONTools;

/**
* Serializes and deserializes shells and submodels to and from json
*
* @author jungjan
*
*/
public class BidirectionalJSONConverter {
private static GSONTools gsonTools = new GSONTools(new DefaultTypeFactory());

public static String serializeSubmodel(ISubmodel submodel) {
return gsonTools.serialize(submodel);
}

@SuppressWarnings("unchecked")
public static ISubmodel deserializeSubmodel(String jsonSubmodel) {
return Submodel.createAsFacade((Map<String, Object>) gsonTools.deserialize(jsonSubmodel));
}

public static String serializeShell(AssetAdministrationShell shell) {
return gsonTools.serialize(shell);
}

@SuppressWarnings("unchecked")
public static AssetAdministrationShell deserializeShell(String jsonShell) {
return AssetAdministrationShell.createAsFacade((Map<String, Object>) gsonTools.deserialize(jsonShell));
}

public static <T> String serializeObject(T object) {
return gsonTools.serialize(object);
}

@SuppressWarnings("unchecked")
public static <T> T deserializeJSON(String json) {
T retrieved = (T) gsonTools.deserialize(json);
return retrieved;
}

@SuppressWarnings("unchecked")
public static AASDescriptor deserializeAASDescriptor(String json) {
return AASDescriptor.createAsFacade((Map<String, Object>) gsonTools.deserialize(json));
}

/**
*
* @param submodel
* @return the semanticId of a submodel serialized according to the following schema:
* {@code {type:<type>;value:<value>;idType:<idType>[/]}}.
* Example: {@code type:Submodel;value:a value;idType:Custom/type:Submodel;value:another value;idType:Custom}
*/
public static String semanticIdAsSString(ISubmodel submodel) {
if (submodel.getSemanticId() == null) {
return null;
}
List<IKey> keys = submodel.getSemanticId().getKeys();
return semanticIdKeysToString(keys);
}

public static String semanticIdKeysToString(List<IKey> keys) {
return keys.stream().map(k ->
Key.TYPE + ":" + k.getType() + ";"
/* + Key.LOCAL + ":" + k.isLocal() + ";" */ //ignoring local since it won't be relevant for V3
+ Key.VALUE + ":" + k.getValue() + ";"
+ Key.IDTYPE + ":" + k.getIdType())
.collect(Collectors.joining("/"));
}

}
Loading

0 comments on commit 04d2957

Please sign in to comment.