From 22dc8a8460b449461a2f340e84d7af061f8b9010 Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Tue, 22 Aug 2023 16:16:12 +0200 Subject: [PATCH 01/15] Implements InMemory AASX file server - Adds core - Adds backend-inmemory - Adds component Signed-off-by: Chaithra Kandur Bhagavanthaiah --- .../Plattform_i40-Registry-and-Discovery.yaml | 0 basyx.aasxfileserver/Readme.md | 17 ++ .../pom.xml | 34 ++++ .../InMemoryAasxFileServer.java | 139 ++++++++++++++++ .../InMemoryAasxFileServerFactory.java | 43 +++++ .../TestInMemoryAasxFileServer.java | 43 +++++ .../basyx.aasxfileserver-core/pom.xml | 25 +++ .../basyx/aasxfileserver/AasxFileServer.java | 87 ++++++++++ .../aasxfileserver/AasxFileServerFactory.java | 43 +++++ .../basyx/aasxfileserver/Package.java | 61 +++++++ .../aasxfileserver/PackageDescription.java | 128 ++++++++++++++ .../basyx/aasxfileserver/PackagesBody.java | 156 ++++++++++++++++++ .../feature/AasxFileServerFeature.java | 40 +++++ .../DecoratedAasxFileServerFactory.java | 50 ++++++ .../core/AasxFileServerSuite.java | 155 +++++++++++++++++ .../basyx.aasxfileserver.component/Dockerfile | 7 + .../basyx.aasxfileserver.component/pom.xml | 56 +++++++ .../component/AasxFileServerComponent.java | 46 ++++++ .../AasxFileServerConfiguration.java | 52 ++++++ .../AasxFileServerFeaturePrinter.java | 55 ++++++ .../main/resources/META-INF/spring.factories | 1 + .../src/main/resources/application.properties | 15 ++ .../src/main/resources/banner.txt | 10 ++ basyx.aasxfileserver/pom.xml | 20 +++ pom.xml | 25 +++ 25 files changed, 1308 insertions(+) rename basyx.aasregistry/{basyx.aasregistry-service-basemodel => basyx.aasregistry-service}/open-api/Plattform_i40-Registry-and-Discovery.yaml (100%) create mode 100644 basyx.aasxfileserver/Readme.md create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/Dockerfile create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/banner.txt create mode 100644 basyx.aasxfileserver/pom.xml diff --git a/basyx.aasregistry/basyx.aasregistry-service-basemodel/open-api/Plattform_i40-Registry-and-Discovery.yaml b/basyx.aasregistry/basyx.aasregistry-service/open-api/Plattform_i40-Registry-and-Discovery.yaml similarity index 100% rename from basyx.aasregistry/basyx.aasregistry-service-basemodel/open-api/Plattform_i40-Registry-and-Discovery.yaml rename to basyx.aasregistry/basyx.aasregistry-service/open-api/Plattform_i40-Registry-and-Discovery.yaml diff --git a/basyx.aasxfileserver/Readme.md b/basyx.aasxfileserver/Readme.md new file mode 100644 index 000000000..b92350aba --- /dev/null +++ b/basyx.aasxfileserver/Readme.md @@ -0,0 +1,17 @@ +# Eclipse BaSyx - ConceptDescription Repository +Eclipse BaSyx provides the ConceptDescription Repository as off-the-shelf component: + + docker run --name=cd-repo -p:8081:8081 -v C:/tmp:/usr/share/config eclipsebasyx/conceptdescription-repository:2.0.0-SNAPSHOT + +The API endpoint documentation is available at: + + http://{host}:{port}/v3/api-docs + +The Swagger UI for the endpoint is available at: + + http://{host}:{port}/swagger-ui/index.html + +It supports DotAAS Part 1 V3 and all HTTP/REST endpoints defined in [DotAAS Part 2 V3 - ConceptDescription Repository](https://app.swaggerhub.com/apis/Plattform_i40/ConceptDescriptionRepositoryServiceSpecification/V3.0_SSP-001). +In addition, it supports InMemory as well as MongoDB backends. + +For a configuration example, see [application.properties](basyx.conceptdescriptionrepository.component/src/main/resources/application.properties) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml new file mode 100644 index 000000000..7c61f8383 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver + ${revision} + + + basyx.aasxfileserver-backend-inmemory + AASX File Server Backend InMemory + + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-core + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-core + tests + test + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter + + + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java new file mode 100644 index 000000000..a1eeafd52 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +import java.io.InputStream; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; + +/** + * In-memory implementation of the AasxFileServer + * + * @author chaithra + * + */ +public class InMemoryAasxFileServer implements AasxFileServer { + + private Map packageMap = new LinkedHashMap<>(); + private AtomicInteger packageId = new AtomicInteger(0); + + /** + * Creates the InMemoryAasxFileServer + * @author chaithra + */ + public InMemoryAasxFileServer() {} + + @Override + public Collection getAllAASXPackageIds() { + + return packageMap.values().stream() + .map(aasxPackage -> aasxPackage.getPackageDescription()) + .collect(Collectors.toList()); + } + + @Override + public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException { + throwIfAasxFileIdDoesNotExist(packageId); + + return packageMap.get(packageId).getPackagesBody().getFile(); + } + + @Override + public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) + throws ElementDoesNotExistException { + + throwIfAasxFileIdDoesNotExist(packageId); + + updateAASXPackage(packageId, aasIds, file, filename); + } + + @Override + public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) + throws CollidingIdentifierException { + + String newpackageId = String.valueOf(packageId.incrementAndGet()); + PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); + createPackage(aasIds, file, fileName, newpackageId, packageDescription); + + return packageDescription; + } + + @Override + public void deleteAASXPackageById(String packageId) throws ElementDoesNotExistException { + throwIfAasxFileIdDoesNotExist(packageId); + + packageMap.remove(packageId); + } + + public Integer increment(Integer n) { + return n++; + } + + private PackageDescription createPackageDescription(List aasIds, String newpackageId) { + PackageDescription packageDescription = new PackageDescription(); + packageDescription.packageId(newpackageId); + packageDescription.aasIds(aasIds); + + return packageDescription; + } + + private PackagesBody createPackagesBody(List aasIds, InputStream file, String fileName) { + PackagesBody packagesBody = new PackagesBody(); + packagesBody.aasIds(aasIds); + packagesBody.file(file); + packagesBody.fileName(fileName); + + return packagesBody; + } + + private void createPackage(List aasIds, InputStream file, String fileName, String newpackageId, PackageDescription packageDescription) { + PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); + Package aasxPackage = new Package(newpackageId, packageDescription, packagesBody); + packageMap.put(newpackageId, aasxPackage); + } + + private void updateAASXPackage(String packageId, List aasIds, InputStream file, String filename) { + Package aasxPackage = this.packageMap.get(packageId); + aasxPackage.getPackagesBody().setAasIds(aasIds); + aasxPackage.getPackagesBody().setFileName(filename); + aasxPackage.getPackagesBody().setFile(file); + aasxPackage.getPackageDescription().setAasIds(aasIds); + } + + private void throwIfAasxFileIdDoesNotExist(String id) { + + if (!packageMap.containsKey(id)) + throw new ElementDoesNotExistException(id); + } + +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java new file mode 100644 index 000000000..1d37c387c --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.stereotype.Component; + +/** + * AasxFileServer factory returning an in-memory backend AasxFileServer + * + * @author schnicke, chaithra + */ +@Component +@ConditionalOnExpression("'${basyx.backend}'.equals('InMemory')") +public class InMemoryAasxFileServerFactory implements AasxFileServerFactory { + + @Override + public AasxFileServer create() { + return new InMemoryAasxFileServer(); + } +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java new file mode 100644 index 000000000..9ce0a8ab4 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.core.AasxFileServerSuite; + +/** + * Tests the {@link InMemoryAasxFileServer} + * + * @author chaithra + * + */ +public class TestInMemoryAasxFileServer extends AasxFileServerSuite { + + @Override + protected AasxFileServer getAasxFileServer() { + return new InMemoryAasxFileServer(); + } + +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml new file mode 100644 index 000000000..0ada2d204 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver + ${revision} + + + basyx.aasxfileserver-core + AASX File Server Core + + + + org.eclipse.digitaltwin.basyx + basyx.core + + + + org.eclipse.digitaltwin.aas4j + model + + + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java new file mode 100644 index 000000000..3ac6aced8 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +import java.io.InputStream; +import java.util.Collection; +import java.util.List; + +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; + +/** + * Specifies the overall AasxFileServer API + * + * @author chaithra + * + */ +public interface AasxFileServer { + + /** + * Retrieves all AASXPackageIds from the repository + * + * @return a list of available AASX packages at the server + */ + public Collection getAllAASXPackageIds(); + + /** + * Retrieves a specific AASX package from the server + * + * @param packageId + * @return a specific AASX package from the server + * @throws ElementDoesNotExistException + */ + public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException; + + /** + * Updates an existing AASX package at the server + * + * @param packageId + * @param aasIds + * @param filename + * @param file + * @throws ElementDoesNotExistException + */ + public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException; + + /** + * Creates a new AASXPackage + * + * @param aasIds + * @param filename + * @param file + * @throws CollidingIdentifierException + */ + public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) throws CollidingIdentifierException; + + /** + * Deletes a AASXPackage + * @param packageId + * @throws ElementDoesNotExistException + */ + public void deleteAASXPackageById(String packageId) throws ElementDoesNotExistException; + +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java new file mode 100644 index 000000000..e2653412c --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +/** + * Interface for a factory creating a {@link AasxFileServer} + * + * @author schnicke, chaithra + * + */ +public interface AasxFileServerFactory { + + /** + * Creates a new AasxFileServer + * + * @return + */ + public AasxFileServer create(); +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java new file mode 100644 index 000000000..5d21209f5 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +/** + * Specifies the Package for AasxFileServer + * + * @author chaithra + * + */ +public class Package { + + private String packageId = null; + + private PackageDescription packageDescription; + + private PackagesBody packagesBody; + + + public Package(String packageId, PackageDescription packageDescription, PackagesBody packagesBody ) { + this.packageId = packageId; + this.packageDescription = packageDescription; + this.packagesBody = packagesBody; + + } + + public String getPackageId() { + return packageId; + } + + public PackageDescription getPackageDescription() { + return packageDescription; + } + + public PackagesBody getPackagesBody() { + return packagesBody; + } +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java new file mode 100644 index 000000000..9ae96bb62 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +import java.util.Objects; +import java.util.ArrayList; +import java.util.List; +import org.springframework.validation.annotation.Validated; + +/** + * Specifies the PackageDescription for AasxFileServer + * + * + * + */ +@Validated +@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2023-06-22T10:58:56.694021713Z[GMT]") + + +public class PackageDescription { + + private List aasIds = null; + + + private String packageId = null; + + public PackageDescription aasIds(List aasIds) { + this.aasIds = aasIds; + return this; + } + + public PackageDescription addAasIdsItem(String aasIdsItem) { + if (this.aasIds == null) { + this.aasIds = new ArrayList(); + } + this.aasIds.add(aasIdsItem); + return this; + } + + public List getAasIds() { + return aasIds; + } + + public void setAasIds(List aasIds) { + this.aasIds = aasIds; + } + + public PackageDescription packageId(String packageId) { + this.packageId = packageId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PackageDescription packageDescription = (PackageDescription) o; + return Objects.equals(this.aasIds, packageDescription.aasIds) && + Objects.equals(this.packageId, packageDescription.packageId); + } + + @Override + public int hashCode() { + return Objects.hash(aasIds, packageId); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PackageDescription {\n"); + + sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); + sb.append(" packageId: ").append(toIndentedString(packageId)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +public boolean isEmpty() { + return false; +} +} + diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java new file mode 100644 index 000000000..20ef46b48 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import org.springframework.validation.annotation.Validated; + + +/** + * Specifies the PackagesBody for AasxFileServer + * + */ +@Validated +@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2023-06-22T10:58:56.694021713Z[GMT]") + + +public class PackagesBody { + + private List aasIds = null; + + private InputStream file = null; + + + private String fileName = null; + + private String packageId = null; + + public PackagesBody aasIds(List aasIds) { + this.aasIds = aasIds; + return this; + } + + public PackagesBody addAasIdsItem(String aasIdsItem) { + if (this.aasIds == null) { + this.aasIds = new ArrayList(); + } + this.aasIds.add(aasIdsItem); + return this; + } + + public List getAasIds() { + return aasIds; + } + + public void setAasIds(List aasIds) { + this.aasIds = aasIds; + } + + public PackagesBody file(InputStream file) { + this.file = file; + return this; + } + + public InputStream getFile() { + return file; + } + + public void setFile(InputStream file) { + this.file = file; + } + + public PackagesBody fileName(String fileName) { + this.fileName = fileName; + return this; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public PackagesBody packageId(String packageId) { + this.packageId = packageId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PackagesBody packagesBody = (PackagesBody) o; + return Objects.equals(this.aasIds, packagesBody.aasIds) && + Objects.equals(this.file, packagesBody.file) && + Objects.equals(this.fileName, packagesBody.fileName); + } + + @Override + public int hashCode() { + return Objects.hash(aasIds, file, fileName); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PackagesBody {\n"); + + sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); + sb.append(" file: ").append(toIndentedString(file)).append("\n"); + sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java new file mode 100644 index 000000000..6c7289b0e --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.feature; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.core.BaSyxFeature; + +/** + * Base interface for all features for the ConceptDescription + * + * @author schnicke, chaithra + * + */ +public interface AasxFileServerFeature extends BaSyxFeature { + +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java new file mode 100644 index 000000000..10e918799 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.feature; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.core.DecoratedFactory; + +/** + * Factory for {@link AasxFileServerFactory} decoration + * + * @author schnicke, chaithra + * + */ +public class DecoratedAasxFileServerFactory extends DecoratedFactory implements AasxFileServerFactory { + + public DecoratedAasxFileServerFactory(AasxFileServerFactory toDecorate, List features) { + super(toDecorate, features); + } + + @Override + public AasxFileServer create() { + return getDecorated().create(); + } +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java new file mode 100644 index 000000000..2d9bb20db --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.junit.Test; + +/** + * Testsuite for implementations of the AasxFileServerSuite interface + * + * @author chaithra + * + */ +public abstract class AasxFileServerSuite { + + protected abstract AasxFileServer getAasxFileServer(); + + private static final List DUMMY_AAS_IDS = new ArrayList<>(Arrays.asList("AAS_ID_1", "AAS_ID_2")); + private static final String DUMMY_FILENAME = "test_file.txt"; + private static final byte[] byteArray = {65, 66, 67, 68, 69}; + private static final InputStream DUMMY_FILE = new ByteArrayInputStream(byteArray); + + @Test + public void getAllAASXPackageIds() { + + AasxFileServer server = getAasxFileServer(); + createDummyAASXPackage(server); + Collection packageDescriptions = server.getAllAASXPackageIds(); + PackageDescription firstPackage = packageDescriptions.iterator().next(); + + assertGetAllAASXPackageIds(packageDescriptions, firstPackage); + } + + @Test + public void getAllAASXPackageIdsEmpty() { + + AasxFileServer server = getAasxFileServer(); + Collection packageDescriptions = server.getAllAASXPackageIds(); + + assertIsEmpty(packageDescriptions); + } + + @Test(expected = ElementDoesNotExistException.class) + public void getSpecificNonExistingPackageId() { + + AasxFileServer server = getAasxFileServer(); + server.getAASXByPackageId("doesNotExist"); + } + + @Test + public void updateExistingAASXByPackageId() { + + List expectedAasIds = new ArrayList<>(Arrays.asList("AAS_ID_3", "AAS_ID_4")); + AasxFileServer server = getAasxFileServer(); + PackageDescription packageDescription = createDummyAASXPackage(server); + server.updateAASXByPackageId(packageDescription.getPackageId(), expectedAasIds, DUMMY_FILE, DUMMY_FILENAME); + + assertUpdateAASXpaxkageID(packageDescription, expectedAasIds); + } + + @Test(expected = ElementDoesNotExistException.class) + public void updateNonExistingAASXByPackageId() { + + String packageId = "notExisting"; + AasxFileServer server = getAasxFileServer(); + server.updateAASXByPackageId(packageId, DUMMY_AAS_IDS, DUMMY_FILE, DUMMY_FILENAME); + } + + @Test + public void getAASXByPackageId() throws ElementDoesNotExistException { + + AasxFileServer server = getAasxFileServer(); + PackageDescription packageDescription = createDummyAASXPackage(server); + InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); + + assertEquals(DUMMY_FILE, actualValue); + } + + @Test + public void deleteAASXPackageById() { + + AasxFileServer server = getAasxFileServer(); + PackageDescription packageDescription = createDummyAASXPackage(server); + server.deleteAASXPackageById(packageDescription.getPackageId()); + try { + server.getAASXByPackageId(packageDescription.getPackageId()); + fail(); + } catch (ElementDoesNotExistException expected) { + } + } + + @Test(expected = ElementDoesNotExistException.class) + public void deleteNonExistingConceptDescription() { + + AasxFileServer server = getAasxFileServer(); + server.deleteAASXPackageById("nonExisting"); + } + + private PackageDescription createDummyAASXPackage(AasxFileServer server) { + return server.createAASXPackage(DUMMY_AAS_IDS, DUMMY_FILE, DUMMY_FILENAME); + } + + private void assertGetAllAASXPackageIds(Collection packageDescriptions, PackageDescription firstPackage) { + assertEquals(1, packageDescriptions.size()); + assertEquals("1", firstPackage.getPackageId()); + assertEquals(DUMMY_AAS_IDS,firstPackage.getAasIds()); + assertTrue(DUMMY_AAS_IDS.containsAll(firstPackage.getAasIds())); + } + + private void assertUpdateAASXpaxkageID(PackageDescription actualPackageDescription, List expectedNewAasIds ) { + assertEquals(expectedNewAasIds, actualPackageDescription.getAasIds()); + assertEquals("1",actualPackageDescription.getPackageId()); + } + + private void assertIsEmpty(Collection packageDescription) { + assertTrue(packageDescription.isEmpty()); + } + +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/Dockerfile b/basyx.aasxfileserver/basyx.aasxfileserver.component/Dockerfile new file mode 100644 index 000000000..11cb6d9d8 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/Dockerfile @@ -0,0 +1,7 @@ +FROM amazoncorretto:11 +USER nobody +WORKDIR /application +ARG JAR_FILE=target/*-exec.jar +COPY ${JAR_FILE} basyxExecutable.jar +COPY src/main/resources/application.properties application.properties +ENTRYPOINT ["java","-jar","basyxExecutable.jar"] diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml new file mode 100644 index 000000000..f9f6d8480 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml @@ -0,0 +1,56 @@ + + 4.0.0 + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver + ${revision} + + + basyx.aasxfileserver.component + AASX File Server Component + + + + org.eclipse.digitaltwin.basyx + basyx.mongodbcore + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-core + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-backend-inmemory + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java new file mode 100644 index 000000000..f3ab3cd9a --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.component; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; + +/** + * Creates and starts the AasxFileServer off-shelf-component + * + * @author schnicke, chaithra + * + */ +@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx", +exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) +public class AasxFileServerComponent { + public static void main(String[] args) { + SpringApplication.run(AasxFileServerComponent.class, args); + } +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java new file mode 100644 index 000000000..239d8d4ab --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.component; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AasxFileServerFeature; +import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.DecoratedAasxFileServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Provides the spring bean configuration for the {@link AasxFileServer} + * utilizing all found features for the respective services + * + * @author chaithra + * + */ +@Configuration +public class AasxFileServerConfiguration { + + @Bean + public static AasxFileServer getAasxFileServer(AasxFileServerFactory aasRepositoryFactory, List features) { + return new DecoratedAasxFileServerFactory(aasRepositoryFactory, features).create(); + } + +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java new file mode 100644 index 000000000..272257a69 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.component; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AasxFileServerFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Prints all AasxFileServer features that are on the classpath + * + * @author schnicke, chaithra + * + */ +@Service +public class AasxFileServerFeaturePrinter { + + private static final Logger logger = LoggerFactory.getLogger(AasxFileServerFeaturePrinter.class); + + @Autowired + public AasxFileServerFeaturePrinter(List features) { + logger.info("-------------------- AASX File Server Features: --------------------"); + for (AasxFileServerFeature feature : features) { + logger.info("BaSyxFeature " + feature.getName() + " is enabled: " + feature.isEnabled()); + } + + logger.info("----------------------------------------------------------------- "); + } +} diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..21fe5983e --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.env.PropertySourceLoader=org.eclipse.digitaltwin.basyx.core.LoggingPropertySourceLoader \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties new file mode 100644 index 000000000..fcb074518 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties @@ -0,0 +1,15 @@ +server.port=8081 + +spring.application.name=AASX File Server + +basyx.backend = InMemory + +# basyx.backend = MongoDB +#spring.data.mongodb.host=localhost +#spring.data.mongodb.port=27017 +#spring.data.mongodb.database=aas +#spring.data.mongodb.username=admin +#spring.data.mongodb.password=password + +# Base Path for Spring Boot Actuator +management.endpoints.web.base-path=/ diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/banner.txt b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/banner.txt new file mode 100644 index 000000000..bdcb71f9b --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/banner.txt @@ -0,0 +1,10 @@ + ____ _____ + | _ \ / ____| + | |_) | __ _ | (___ _ _ __ __ + | _ < / _` | \___ \ | | | |\ \/ / + | |_) || (_| | ____) || |_| | > < + |____/ \__,_||_____/ \__, |/_/\_\ +======================== __/ |====== +AASX File Server |___/ +2.0.0-PREVIEW + \ No newline at end of file diff --git a/basyx.aasxfileserver/pom.xml b/basyx.aasxfileserver/pom.xml new file mode 100644 index 000000000..b35796f33 --- /dev/null +++ b/basyx.aasxfileserver/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + + + org.eclipse.digitaltwin.basyx + basyx.parent + ${revision} + + + basyx.aasxfileserver + AASX File Server Repository + pom + + + basyx.aasxfileserver-core + basyx.aasxfileserver.component + basyx.aasxfileserver-backend-inmemory + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2c6ecd6d2..da8ab3de5 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ basyx.aasregistry basyx.aasenvironment basyx.conceptdescriptionrepository + basyx.aasxfileserver BaSyx Parent Parent POM for Eclipse BaSyx @@ -362,6 +363,23 @@ basyx.conceptdescriptionrepository.component ${revision} + + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-core + ${revision} + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-backend-inmemory + ${revision} + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver.component + ${revision} + @@ -540,6 +558,13 @@ ${revision} tests + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-core + ${revision} + tests + From fa1b16d7042e5dc6316fcc913f6c55646f6faebd Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Fri, 25 Aug 2023 17:41:02 +0200 Subject: [PATCH 02/15] Deletes Readme.md file Signed-off-by: Chaithra Kandur Bhagavanthaiah --- basyx.aasxfileserver/Readme.md | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 basyx.aasxfileserver/Readme.md diff --git a/basyx.aasxfileserver/Readme.md b/basyx.aasxfileserver/Readme.md deleted file mode 100644 index b92350aba..000000000 --- a/basyx.aasxfileserver/Readme.md +++ /dev/null @@ -1,17 +0,0 @@ -# Eclipse BaSyx - ConceptDescription Repository -Eclipse BaSyx provides the ConceptDescription Repository as off-the-shelf component: - - docker run --name=cd-repo -p:8081:8081 -v C:/tmp:/usr/share/config eclipsebasyx/conceptdescription-repository:2.0.0-SNAPSHOT - -The API endpoint documentation is available at: - - http://{host}:{port}/v3/api-docs - -The Swagger UI for the endpoint is available at: - - http://{host}:{port}/swagger-ui/index.html - -It supports DotAAS Part 1 V3 and all HTTP/REST endpoints defined in [DotAAS Part 2 V3 - ConceptDescription Repository](https://app.swaggerhub.com/apis/Plattform_i40/ConceptDescriptionRepositoryServiceSpecification/V3.0_SSP-001). -In addition, it supports InMemory as well as MongoDB backends. - -For a configuration example, see [application.properties](basyx.conceptdescriptionrepository.component/src/main/resources/application.properties) From 35db5d6ca8dd0d0c40e75feb58a999492b1f5f5f Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Fri, 25 Aug 2023 17:58:55 +0200 Subject: [PATCH 03/15] Refractors code Signed-off-by: Chaithra Kandur Bhagavanthaiah --- .../aasxfileserver/PackageDescription.java | 171 +++++++++--------- .../feature/AasxFileServerFeature.java | 2 +- .../core/AasxFileServerSuite.java | 2 +- 3 files changed, 85 insertions(+), 90 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java index 9ae96bb62..374773ea0 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java @@ -31,98 +31,93 @@ import org.springframework.validation.annotation.Validated; /** - * Specifies the PackageDescription for AasxFileServer + * Specifies the PackageDescription for AasxFileServer * - * - * */ @Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2023-06-22T10:58:56.694021713Z[GMT]") - -public class PackageDescription { - - private List aasIds = null; - - - private String packageId = null; - - public PackageDescription aasIds(List aasIds) { - this.aasIds = aasIds; - return this; - } - - public PackageDescription addAasIdsItem(String aasIdsItem) { - if (this.aasIds == null) { - this.aasIds = new ArrayList(); - } - this.aasIds.add(aasIdsItem); - return this; - } - - public List getAasIds() { - return aasIds; - } - - public void setAasIds(List aasIds) { - this.aasIds = aasIds; - } - - public PackageDescription packageId(String packageId) { - this.packageId = packageId; - return this; - } - - public String getPackageId() { - return packageId; - } - - public void setPackageId(String packageId) { - this.packageId = packageId; - } - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PackageDescription packageDescription = (PackageDescription) o; - return Objects.equals(this.aasIds, packageDescription.aasIds) && - Objects.equals(this.packageId, packageDescription.packageId); - } - - @Override - public int hashCode() { - return Objects.hash(aasIds, packageId); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class PackageDescription {\n"); - - sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); - sb.append(" packageId: ").append(toIndentedString(packageId)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(java.lang.Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - -public boolean isEmpty() { +public class PackageDescription { + + private List aasIds = null; + + private String packageId = null; + + public PackageDescription aasIds(List aasIds) { + this.aasIds = aasIds; + return this; + } + + public PackageDescription addAasIdsItem(String aasIdsItem) { + if (this.aasIds == null) { + this.aasIds = new ArrayList(); + } + this.aasIds.add(aasIdsItem); + return this; + } + + public List getAasIds() { + return aasIds; + } + + public void setAasIds(List aasIds) { + this.aasIds = aasIds; + } + + public PackageDescription packageId(String packageId) { + this.packageId = packageId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PackageDescription packageDescription = (PackageDescription) o; + return Objects.equals(this.aasIds, packageDescription.aasIds) + && Objects.equals(this.packageId, packageDescription.packageId); + } + + @Override + public int hashCode() { + return Objects.hash(aasIds, packageId); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PackageDescription {\n"); + + sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); + sb.append(" packageId: ").append(toIndentedString(packageId)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public boolean isEmpty() { return false; + } } -} - diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java index 6c7289b0e..c55ff3d96 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java @@ -30,7 +30,7 @@ import org.eclipse.digitaltwin.basyx.core.BaSyxFeature; /** - * Base interface for all features for the ConceptDescription + * Base interface for all features for the AASX File Server * * @author schnicke, chaithra * diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java index 2d9bb20db..052827695 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java @@ -126,7 +126,7 @@ public void deleteAASXPackageById() { } @Test(expected = ElementDoesNotExistException.class) - public void deleteNonExistingConceptDescription() { + public void deleteNonExistingAasxFileServer() { AasxFileServer server = getAasxFileServer(); server.deleteAASXPackageById("nonExisting"); From 54b33f300af17bcd1f0da80bccb9ab97841bd6cd Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Tue, 29 Aug 2023 12:44:29 +0200 Subject: [PATCH 04/15] Improves formatting Signed-off-by: Chaithra Kandur Bhagavanthaiah --- .../basyx/aasxfileserver/PackagesBody.java | 210 +++++++++--------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java index 20ef46b48..0e7afda79 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java @@ -43,114 +43,114 @@ public class PackagesBody { - private List aasIds = null; - - private InputStream file = null; - - - private String fileName = null; - - private String packageId = null; - - public PackagesBody aasIds(List aasIds) { - this.aasIds = aasIds; - return this; - } - - public PackagesBody addAasIdsItem(String aasIdsItem) { - if (this.aasIds == null) { - this.aasIds = new ArrayList(); - } - this.aasIds.add(aasIdsItem); - return this; - } - - public List getAasIds() { - return aasIds; - } - - public void setAasIds(List aasIds) { - this.aasIds = aasIds; - } - - public PackagesBody file(InputStream file) { - this.file = file; - return this; - } - - public InputStream getFile() { - return file; - } - - public void setFile(InputStream file) { - this.file = file; - } - - public PackagesBody fileName(String fileName) { - this.fileName = fileName; - return this; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public PackagesBody packageId(String packageId) { - this.packageId = packageId; + private List aasIds = null; + + private InputStream file = null; + + + private String fileName = null; + + private String packageId = null; + + public PackagesBody aasIds(List aasIds) { + this.aasIds = aasIds; + return this; + } + + public PackagesBody addAasIdsItem(String aasIdsItem) { + if (this.aasIds == null) { + this.aasIds = new ArrayList(); + } + this.aasIds.add(aasIdsItem); return this; } - public String getPackageId() { - return packageId; + public List getAasIds() { + return aasIds; + } + + public void setAasIds(List aasIds) { + this.aasIds = aasIds; + } + + public PackagesBody file(InputStream file) { + this.file = file; + return this; + } + + public InputStream getFile() { + return file; + } + + public void setFile(InputStream file) { + this.file = file; + } + + public PackagesBody fileName(String fileName) { + this.fileName = fileName; + return this; } - - public void setPackageId(String packageId) { - this.packageId = packageId; - } - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PackagesBody packagesBody = (PackagesBody) o; - return Objects.equals(this.aasIds, packagesBody.aasIds) && - Objects.equals(this.file, packagesBody.file) && - Objects.equals(this.fileName, packagesBody.fileName); - } - - @Override - public int hashCode() { - return Objects.hash(aasIds, file, fileName); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class PackagesBody {\n"); - - sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); - sb.append(" file: ").append(toIndentedString(file)).append("\n"); - sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(java.lang.Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public PackagesBody packageId(String packageId) { + this.packageId = packageId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PackagesBody packagesBody = (PackagesBody) o; + return Objects.equals(this.aasIds, packagesBody.aasIds) && + Objects.equals(this.file, packagesBody.file) && + Objects.equals(this.fileName, packagesBody.fileName); + } + + @Override + public int hashCode() { + return Objects.hash(aasIds, file, fileName); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PackagesBody {\n"); + + sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); + sb.append(" file: ").append(toIndentedString(file)).append("\n"); + sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } From bf03b583299c52a9c190e7f888edd580595a01d6 Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Fri, 8 Sep 2023 22:48:10 +0200 Subject: [PATCH 05/15] Review comments changes --- .../InMemoryAasxFileServer.java | 38 ++++----- .../InMemoryAasxFileServerFactory.java | 2 +- .../basyx/aasxfileserver/AasxFileServer.java | 16 ++-- .../basyx/aasxfileserver/Package.java | 12 +-- .../basyx/aasxfileserver/PackagesBody.java | 18 ++-- .../core/AasxFileServerSuite.java | 82 ++++++++++--------- .../core/AasxFileServerSuiteHelper.java | 50 +++++++++++ .../core/DummyAasxFileServerFactory.java | 71 ++++++++++++++++ .../component/AasxFileServerComponent.java | 5 +- .../main/resources/META-INF/spring.factories | 1 - .../src/main/resources/application.properties | 67 +++++++++++++-- 11 files changed, 261 insertions(+), 101 deletions(-) create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java create mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java delete mode 100644 basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java index a1eeafd52..0cc1c76af 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java @@ -49,21 +49,20 @@ public class InMemoryAasxFileServer implements AasxFileServer { /** * Creates the InMemoryAasxFileServer - * @author chaithra */ public InMemoryAasxFileServer() {} @Override public Collection getAllAASXPackageIds() { - - return packageMap.values().stream() - .map(aasxPackage -> aasxPackage.getPackageDescription()) - .collect(Collectors.toList()); + return packageMap.values() + .stream() + .map(Package::getPackageDescription) + .collect(Collectors.toList()); } @Override public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException { - throwIfAasxFileIdDoesNotExist(packageId); + throwIfAasxPackageIdDoesNotExist(packageId); return packageMap.get(packageId).getPackagesBody().getFile(); } @@ -72,8 +71,7 @@ public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExi public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException { - throwIfAasxFileIdDoesNotExist(packageId); - + throwIfAasxPackageIdDoesNotExist(packageId); updateAASXPackage(packageId, aasIds, file, filename); } @@ -89,19 +87,15 @@ public PackageDescription createAASXPackage(List aasIds, InputStream fil } @Override - public void deleteAASXPackageById(String packageId) throws ElementDoesNotExistException { - throwIfAasxFileIdDoesNotExist(packageId); + public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException { + throwIfAasxPackageIdDoesNotExist(packageId); packageMap.remove(packageId); - } - - public Integer increment(Integer n) { - return n++; - } + } - private PackageDescription createPackageDescription(List aasIds, String newpackageId) { + private PackageDescription createPackageDescription(List aasIds, String newPackageId) { PackageDescription packageDescription = new PackageDescription(); - packageDescription.packageId(newpackageId); + packageDescription.packageId(newPackageId); packageDescription.aasIds(aasIds); return packageDescription; @@ -116,10 +110,10 @@ private PackagesBody createPackagesBody(List aasIds, InputStream file, S return packagesBody; } - private void createPackage(List aasIds, InputStream file, String fileName, String newpackageId, PackageDescription packageDescription) { + private void createPackage(List aasIds, InputStream file, String fileName, String newPackageId, PackageDescription packageDescription) { PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); - Package aasxPackage = new Package(newpackageId, packageDescription, packagesBody); - packageMap.put(newpackageId, aasxPackage); + Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); + packageMap.put(newPackageId, aasxPackage); } private void updateAASXPackage(String packageId, List aasIds, InputStream file, String filename) { @@ -130,10 +124,10 @@ private void updateAASXPackage(String packageId, List aasIds, InputStrea aasxPackage.getPackageDescription().setAasIds(aasIds); } - private void throwIfAasxFileIdDoesNotExist(String id) { + private void throwIfAasxPackageIdDoesNotExist(String id) { if (!packageMap.containsKey(id)) throw new ElementDoesNotExistException(id); - } + } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java index 1d37c387c..eac2e3671 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java @@ -28,7 +28,7 @@ import org.springframework.stereotype.Component; /** - * AasxFileServer factory returning an in-memory backend AasxFileServer + * AasxFileServer factory returning an in-memory backend {@link AasxFileServer} * * @author schnicke, chaithra */ diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java index 3ac6aced8..695efe29c 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java @@ -41,9 +41,9 @@ public interface AasxFileServer { /** - * Retrieves all AASXPackageIds from the repository + * Retrieves all AASX package ids from the repository * - * @return a list of available AASX packages at the server + * @return a list of available AASX Package Descriptions at the server */ public Collection getAllAASXPackageIds(); @@ -61,27 +61,27 @@ public interface AasxFileServer { * * @param packageId * @param aasIds + * @param file * @param filename - * @param file * @throws ElementDoesNotExistException */ public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException; /** - * Creates a new AASXPackage + * Creates a new AASX Package * * @param aasIds - * @param filename - * @param file + * @param file + * @param filename * @throws CollidingIdentifierException */ public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) throws CollidingIdentifierException; /** - * Deletes a AASXPackage + * Deletes a AASX Package * @param packageId * @throws ElementDoesNotExistException */ - public void deleteAASXPackageById(String packageId) throws ElementDoesNotExistException; + public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException; } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java index 5d21209f5..89837b6ee 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java @@ -33,18 +33,14 @@ */ public class Package { - private String packageId = null; - - private PackageDescription packageDescription; - - private PackagesBody packagesBody; - + private String packageId; + private PackageDescription packageDescription; + private PackagesBody packagesBody; public Package(String packageId, PackageDescription packageDescription, PackagesBody packagesBody ) { this.packageId = packageId; this.packageDescription = packageDescription; - this.packagesBody = packagesBody; - + this.packagesBody = packagesBody; } public String getPackageId() { diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java index 0e7afda79..4f467b127 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java @@ -39,17 +39,11 @@ */ @Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2023-06-22T10:58:56.694021713Z[GMT]") - - public class PackagesBody { - private List aasIds = null; - - private InputStream file = null; - - - private String fileName = null; - + private List aasIds = null; + private InputStream file = null; + private String fileName = null; private String packageId = null; public PackagesBody aasIds(List aasIds) { @@ -102,15 +96,15 @@ public void setFileName(String fileName) { public PackagesBody packageId(String packageId) { this.packageId = packageId; return this; - } + } public String getPackageId() { return packageId; - } + } public void setPackageId(String packageId) { this.packageId = packageId; - } + } @Override public boolean equals(java.lang.Object o) { diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java index 052827695..13e29bbbf 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; @@ -42,36 +41,29 @@ import org.junit.Test; /** - * Testsuite for implementations of the AasxFileServerSuite interface + * Testsuite for implementations of the {@link AasxFileServer} interface * * @author chaithra * */ public abstract class AasxFileServerSuite { - protected abstract AasxFileServer getAasxFileServer(); - - private static final List DUMMY_AAS_IDS = new ArrayList<>(Arrays.asList("AAS_ID_1", "AAS_ID_2")); - private static final String DUMMY_FILENAME = "test_file.txt"; - private static final byte[] byteArray = {65, 66, 67, 68, 69}; - private static final InputStream DUMMY_FILE = new ByteArrayInputStream(byteArray); + protected abstract AasxFileServer getAasxFileServer(); @Test public void getAllAASXPackageIds() { AasxFileServer server = getAasxFileServer(); - createDummyAASXPackage(server); - Collection packageDescriptions = server.getAllAASXPackageIds(); - PackageDescription firstPackage = packageDescriptions.iterator().next(); - - assertGetAllAASXPackageIds(packageDescriptions, firstPackage); + Collection packageDescriptions = DummyAasxFileServerFactory.getAllDummyAASXPackages(server); + + assertGetAllAASXPackageIds(packageDescriptions); } @Test public void getAllAASXPackageIdsEmpty() { AasxFileServer server = getAasxFileServer(); - Collection packageDescriptions = server.getAllAASXPackageIds(); + Collection packageDescriptions = server.getAllAASXPackageIds(); assertIsEmpty(packageDescriptions); } @@ -84,14 +76,15 @@ public void getSpecificNonExistingPackageId() { } @Test - public void updateExistingAASXByPackageId() { + public void updateExistingAASXByPackageId() { - List expectedAasIds = new ArrayList<>(Arrays.asList("AAS_ID_3", "AAS_ID_4")); AasxFileServer server = getAasxFileServer(); - PackageDescription packageDescription = createDummyAASXPackage(server); - server.updateAASXByPackageId(packageDescription.getPackageId(), expectedAasIds, DUMMY_FILE, DUMMY_FILENAME); + PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); + List expectedAasIds = new ArrayList<>(Arrays.asList("AAS_ID_3", "AAS_ID_4")); + server.updateAASXByPackageId(packageDescription.getPackageId(), expectedAasIds, + AasxFileServerSuiteHelper.FIRST_FILE, AasxFileServerSuiteHelper.FIRST_FILENAME); - assertUpdateAASXpaxkageID(packageDescription, expectedAasIds); + assertAASXPackageId(packageDescription, expectedAasIds); } @Test(expected = ElementDoesNotExistException.class) @@ -99,25 +92,26 @@ public void updateNonExistingAASXByPackageId() { String packageId = "notExisting"; AasxFileServer server = getAasxFileServer(); - server.updateAASXByPackageId(packageId, DUMMY_AAS_IDS, DUMMY_FILE, DUMMY_FILENAME); + server.updateAASXByPackageId(packageId, AasxFileServerSuiteHelper.FIRST_AAS_IDS, + AasxFileServerSuiteHelper.FIRST_FILE, AasxFileServerSuiteHelper.FIRST_FILENAME); } @Test public void getAASXByPackageId() throws ElementDoesNotExistException { AasxFileServer server = getAasxFileServer(); - PackageDescription packageDescription = createDummyAASXPackage(server); - InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); + PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); + InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); - assertEquals(DUMMY_FILE, actualValue); + assertEquals(AasxFileServerSuiteHelper.FIRST_FILE, actualValue); } @Test - public void deleteAASXPackageById() { + public void deleteAASXByPackageId() { AasxFileServer server = getAasxFileServer(); - PackageDescription packageDescription = createDummyAASXPackage(server); - server.deleteAASXPackageById(packageDescription.getPackageId()); + PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); + server.deleteAASXByPackageId(packageDescription.getPackageId()); try { server.getAASXByPackageId(packageDescription.getPackageId()); fail(); @@ -129,27 +123,35 @@ public void deleteAASXPackageById() { public void deleteNonExistingAasxFileServer() { AasxFileServer server = getAasxFileServer(); - server.deleteAASXPackageById("nonExisting"); + server.deleteAASXByPackageId("nonExisting"); } - private PackageDescription createDummyAASXPackage(AasxFileServer server) { - return server.createAASXPackage(DUMMY_AAS_IDS, DUMMY_FILE, DUMMY_FILENAME); - } - - private void assertGetAllAASXPackageIds(Collection packageDescriptions, PackageDescription firstPackage) { - assertEquals(1, packageDescriptions.size()); - assertEquals("1", firstPackage.getPackageId()); - assertEquals(DUMMY_AAS_IDS,firstPackage.getAasIds()); - assertTrue(DUMMY_AAS_IDS.containsAll(firstPackage.getAasIds())); - } + private void assertGetAllAASXPackageIds(Collection packageDescriptions) { + + assertEquals(2, packageDescriptions.size()); + + List expectedFirstAasIds = AasxFileServerSuiteHelper.FIRST_AAS_IDS; + List expectedSecondAasIds = AasxFileServerSuiteHelper.SECOND_AAS_IDS; + + for (PackageDescription packageDescription : packageDescriptions) { + if (packageDescription.getPackageId().equals("1")) { + assertEquals(expectedFirstAasIds, packageDescription.getAasIds()); + } else if (packageDescription.getPackageId().equals("2")) { + assertEquals(expectedSecondAasIds, packageDescription.getAasIds()); + } else { + fail("Unexpected package ID: " + packageDescription.getPackageId()); + } + } + } - private void assertUpdateAASXpaxkageID(PackageDescription actualPackageDescription, List expectedNewAasIds ) { + private void assertAASXPackageId(PackageDescription actualPackageDescription, List expectedNewAasIds ) { assertEquals(expectedNewAasIds, actualPackageDescription.getAasIds()); + assertEquals(expectedNewAasIds.size(), actualPackageDescription.getAasIds().size()); assertEquals("1",actualPackageDescription.getPackageId()); - } + } private void assertIsEmpty(Collection packageDescription) { assertTrue(packageDescription.isEmpty()); - } + } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java new file mode 100644 index 000000000..1fb3a152e --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.core; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + +/** + * Test helper class for {@link AasxFileServerSuite} + * + * @author chaithra + * + */ +public class AasxFileServerSuiteHelper { + + public static final List FIRST_AAS_IDS = Arrays.asList("AAS_ID_1", "AAS_ID_2"); + public static final String FIRST_FILENAME = "test_file1.txt"; + public static final byte[] FIRST_BYTEARRAY = {65, 66, 67, 68, 69}; + public static final InputStream FIRST_FILE = new ByteArrayInputStream(FIRST_BYTEARRAY); + + public static final List SECOND_AAS_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); + public static final String SECOND_FILENAME = "test_file2.txt"; + public static final byte[] SECOND_BYTEARRAY = {75, 76, 77, 78, 79}; + public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); + +} \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java new file mode 100644 index 000000000..1cf0aa573 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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.digitaltwin.basyx.aasxfileserver.core; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; + +/** + * Factory for creating AASX Packages for tests + * + * @author chaithra + * + */ +public class DummyAasxFileServerFactory { + + public static PackageDescription createFirstDummyAASXPackage(AasxFileServer server) { + return server.createAASXPackage( + AasxFileServerSuiteHelper.FIRST_AAS_IDS, + AasxFileServerSuiteHelper.FIRST_FILE, + AasxFileServerSuiteHelper.FIRST_FILENAME); + } + + public static PackageDescription createSecondDummyAASXPackage(AasxFileServer server) { + return server.createAASXPackage( + AasxFileServerSuiteHelper.SECOND_AAS_IDS, + AasxFileServerSuiteHelper.SECOND_FILE, + AasxFileServerSuiteHelper.SECOND_FILENAME); + } + + public static Collection getAllDummyAASXPackages(AasxFileServer server) { + PackageDescription firstPackage = createFirstDummyAASXPackage(server); + PackageDescription secondPackage = createSecondDummyAASXPackage(server); + + ArrayList packages = new ArrayList<>(); + packages.add(firstPackage); + packages.add(secondPackage); + + return packages; + } +} + + + + + + diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java index f3ab3cd9a..36e917c29 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java @@ -26,20 +26,21 @@ package org.eclipse.digitaltwin.basyx.aasxfileserver.component; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; /** - * Creates and starts the AasxFileServer off-shelf-component + * Creates and starts the {@link AasxFileServer} off-shelf-component * * @author schnicke, chaithra * */ @SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx", exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) -public class AasxFileServerComponent { +public class AasxFileServerComponent { public static void main(String[] args) { SpringApplication.run(AasxFileServerComponent.class, args); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 21fe5983e..000000000 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.env.PropertySourceLoader=org.eclipse.digitaltwin.basyx.core.LoggingPropertySourceLoader \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties index fcb074518..fe31136ce 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties @@ -1,15 +1,68 @@ -server.port=8081 - + server.port=8081 spring.application.name=AASX File Server basyx.backend = InMemory -# basyx.backend = MongoDB -#spring.data.mongodb.host=localhost +#basyx.backend = MongoDB +#spring.data.mongodb.host=127.0.0.1 +##or spring.data.mongodb.host=127.0.0.1 #spring.data.mongodb.port=27017 -#spring.data.mongodb.database=aas -#spring.data.mongodb.username=admin -#spring.data.mongodb.password=password +#spring.data.mongodb.database=concepts +#spring.data.mongodb.authentication-database=admin +#spring.data.mongodb.username=mongoAdmin +#spring.data.mongodb.password=mongoPassword + +#alternative +#spring.data.mongodb.uri=mongodb://mongoAdmin:mongoPassword@localhost:27017/?authMechanism=DEFAULT # Base Path for Spring Boot Actuator management.endpoints.web.base-path=/ + +#################################################################################### +# Cross-Site Resource Sharing (CORS); +# As seen on https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.cors +#################################################################################### +# Comma-separated list of origins to allow. '*' allows all origins. When credentials +# are allowed, '*' cannot be used and origin patterns should be configured instead. +# When no allowed origins or allowed origin patterns are set, CORS support is +# disabled. +# +# management.endpoints.web.cors.allowed-origins=https://example.com +# +#################################################################################### +# Comma-separated list of origin patterns to allow. Unlike allowed origins which only +# supports '*', origin patterns are more flexible (for example +# 'https://*.example.com') and can be used when credentials are allowed. When no +# allowed origin patterns or allowed origins are set, CORS support is disabled. +# +# management.endpoints.web.cors.allowed-origin-patterns=https://*.example.com +# +#################################################################################### +# Comma-separated list of methods to allow. '*' allows all methods. When not set, +# defaults to GET. +# +# management.endpoints.web.cors.allowed-methods= +# +#################################################################################### +# Comma-separated list of headers to allow in a request. '*' allows all headers. +# +# management.endpoints.web.cors.allowed-headers= +# +#################################################################################### +# Comma-separated list of headers to include in a response. +# +# management.endpoints.web.cors.exposed-headers= +# +#################################################################################### +# Boolean; Whether credentials are supported. When not set, credentials are not supported. +# +# management.endpoints.web.cors.allow-credentials= +# +#################################################################################### +# Number; How long in seconds the response from a pre-flight request can be cached +# by clients. +# +# management.endpoints.web.cors.max-age= +# +#################################################################################### + From 393d5be03084904cc187bdb63298e8449bcac805 Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Tue, 19 Sep 2023 12:24:00 +0200 Subject: [PATCH 06/15] Changes for review comments to use IOUtils for cheking the inputstream data Signed-off-by: Chaithra Kandur Bhagavanthaiah --- basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml | 5 +++++ .../basyx/aasxfileserver/core/AasxFileServerSuite.java | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml index 0ada2d204..dc16f28bc 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml @@ -21,5 +21,10 @@ org.eclipse.digitaltwin.aas4j model + + commons-io + commons-io + test + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java index 13e29bbbf..c932c2f42 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java @@ -29,12 +29,14 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import org.apache.commons.io.IOUtils; import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; @@ -97,13 +99,14 @@ public void updateNonExistingAASXByPackageId() { } @Test - public void getAASXByPackageId() throws ElementDoesNotExistException { + public void getAASXByPackageId() throws ElementDoesNotExistException, IOException { AasxFileServer server = getAasxFileServer(); PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); - InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); + InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); + InputStream expectedValue = AasxFileServerSuiteHelper.FIRST_FILE; - assertEquals(AasxFileServerSuiteHelper.FIRST_FILE, actualValue); + IOUtils.contentEquals(expectedValue, actualValue); } @Test From 859ab7a8aff636c75f9a8f50933985ee53461eee Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Thu, 21 Sep 2023 09:53:38 +0200 Subject: [PATCH 07/15] Changes for review comments --- .../basyx/aasxfileserver/core/AasxFileServerSuite.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java index c932c2f42..8ce18079b 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java @@ -105,8 +105,8 @@ public void getAASXByPackageId() throws ElementDoesNotExistException, IOExceptio PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); InputStream expectedValue = AasxFileServerSuiteHelper.FIRST_FILE; - - IOUtils.contentEquals(expectedValue, actualValue); + + assertTrue(IOUtils.contentEquals(expectedValue, actualValue)); } @Test From 7c63c47b2ecf86dd98c26ccf7ff5623c593a998b Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Tue, 26 Sep 2023 12:44:29 +0200 Subject: [PATCH 08/15] Review comment changes --- ...erver.java => InMemoryAASXFileServer.java} | 17 ++-- ...ava => InMemoryAASXFileServerFactory.java} | 8 +- ...r.java => TestInMemoryAASXFileServer.java} | 10 +- ...asxFileServer.java => AASXFileServer.java} | 2 +- ...actory.java => AASXFileServerFactory.java} | 6 +- .../feature/AasxFileServerFeature.java | 4 +- .../DecoratedAasxFileServerFactory.java | 12 +-- ...verSuite.java => AASXFileServerSuite.java} | 98 ++++++++++++------- .../core/AasxFileServerSuiteHelper.java | 50 ---------- ...y.java => DummyAASXFileServerFactory.java} | 34 ++++--- ...nent.java => AASXFileServerComponent.java} | 8 +- ....java => AASXFileServerConfiguration.java} | 10 +- ...java => AASXFileServerFeaturePrinter.java} | 6 +- basyx.aasxfileserver/pom.xml | 2 +- 14 files changed, 127 insertions(+), 140 deletions(-) rename basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{InMemoryAasxFileServer.java => InMemoryAASXFileServer.java} (92%) rename basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{InMemoryAasxFileServerFactory.java => InMemoryAASXFileServerFactory.java} (91%) rename basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{TestInMemoryAasxFileServer.java => TestInMemoryAASXFileServer.java} (84%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{AasxFileServer.java => AASXFileServer.java} (98%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{AasxFileServerFactory.java => AASXFileServerFactory.java} (91%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/{AasxFileServerSuite.java => AASXFileServerSuite.java} (56%) delete mode 100644 basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/{DummyAasxFileServerFactory.java => DummyAASXFileServerFactory.java} (65%) rename basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/{AasxFileServerComponent.java => AASXFileServerComponent.java} (89%) rename basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/{AasxFileServerConfiguration.java => AASXFileServerConfiguration.java} (87%) rename basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/{AasxFileServerFeaturePrinter.java => AASXFileServerFeaturePrinter.java} (91%) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java similarity index 92% rename from basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java rename to basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java index 0cc1c76af..5a0a95c5e 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java @@ -37,20 +37,20 @@ import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; /** - * In-memory implementation of the AasxFileServer + * In-memory implementation of the AASXFileServer * * @author chaithra * */ -public class InMemoryAasxFileServer implements AasxFileServer { +public class InMemoryAASXFileServer implements AASXFileServer { private Map packageMap = new LinkedHashMap<>(); private AtomicInteger packageId = new AtomicInteger(0); /** - * Creates the InMemoryAasxFileServer + * Creates the InMemoryAASXFileServer */ - public InMemoryAasxFileServer() {} + public InMemoryAASXFileServer() {} @Override public Collection getAllAASXPackageIds() { @@ -62,7 +62,7 @@ public Collection getAllAASXPackageIds() { @Override public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException { - throwIfAasxPackageIdDoesNotExist(packageId); + throwIfAASXPackageIdDoesNotExist(packageId); return packageMap.get(packageId).getPackagesBody().getFile(); } @@ -71,7 +71,8 @@ public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExi public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException { - throwIfAasxPackageIdDoesNotExist(packageId); + throwIfAASXPackageIdDoesNotExist(packageId); + updateAASXPackage(packageId, aasIds, file, filename); } @@ -88,7 +89,7 @@ public PackageDescription createAASXPackage(List aasIds, InputStream fil @Override public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException { - throwIfAasxPackageIdDoesNotExist(packageId); + throwIfAASXPackageIdDoesNotExist(packageId); packageMap.remove(packageId); } @@ -124,7 +125,7 @@ private void updateAASXPackage(String packageId, List aasIds, InputStrea aasxPackage.getPackageDescription().setAasIds(aasIds); } - private void throwIfAasxPackageIdDoesNotExist(String id) { + private void throwIfAASXPackageIdDoesNotExist(String id) { if (!packageMap.containsKey(id)) throw new ElementDoesNotExistException(id); diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java similarity index 91% rename from basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java rename to basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java index eac2e3671..e160b0d7f 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAasxFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java @@ -28,16 +28,16 @@ import org.springframework.stereotype.Component; /** - * AasxFileServer factory returning an in-memory backend {@link AasxFileServer} + * AasxFileServer factory returning an in-memory backend {@link AASXFileServer} * * @author schnicke, chaithra */ @Component @ConditionalOnExpression("'${basyx.backend}'.equals('InMemory')") -public class InMemoryAasxFileServerFactory implements AasxFileServerFactory { +public class InMemoryAASXFileServerFactory implements AASXFileServerFactory { @Override - public AasxFileServer create() { - return new InMemoryAasxFileServer(); + public AASXFileServer create() { + return new InMemoryAASXFileServer(); } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java similarity index 84% rename from basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java rename to basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java index 9ce0a8ab4..ac79a0aba 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAasxFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java @@ -25,19 +25,19 @@ package org.eclipse.digitaltwin.basyx.aasxfileserver; -import org.eclipse.digitaltwin.basyx.aasxfileserver.core.AasxFileServerSuite; +import org.eclipse.digitaltwin.basyx.aasxfileserver.core.AASXFileServerSuite; /** - * Tests the {@link InMemoryAasxFileServer} + * Tests the {@link InMemoryAASXFileServer} * * @author chaithra * */ -public class TestInMemoryAasxFileServer extends AasxFileServerSuite { +public class TestInMemoryAASXFileServer extends AASXFileServerSuite { @Override - protected AasxFileServer getAasxFileServer() { - return new InMemoryAasxFileServer(); + protected AASXFileServer getAASXFileServer() { + return new InMemoryAASXFileServer(); } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java similarity index 98% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java index 695efe29c..090342d93 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java @@ -38,7 +38,7 @@ * @author chaithra * */ -public interface AasxFileServer { +public interface AASXFileServer { /** * Retrieves all AASX package ids from the repository diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java similarity index 91% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java index e2653412c..bf7dc71e1 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AasxFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java @@ -27,17 +27,17 @@ package org.eclipse.digitaltwin.basyx.aasxfileserver; /** - * Interface for a factory creating a {@link AasxFileServer} + * Interface for a factory creating a {@link AASXFileServer} * * @author schnicke, chaithra * */ -public interface AasxFileServerFactory { +public interface AASXFileServerFactory { /** * Creates a new AasxFileServer * * @return */ - public AasxFileServer create(); + public AASXFileServer create(); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java index c55ff3d96..616590f3c 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java @@ -26,7 +26,7 @@ package org.eclipse.digitaltwin.basyx.aasxfileserver.feature; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServerFactory; import org.eclipse.digitaltwin.basyx.core.BaSyxFeature; /** @@ -35,6 +35,6 @@ * @author schnicke, chaithra * */ -public interface AasxFileServerFeature extends BaSyxFeature { +public interface AasxFileServerFeature extends BaSyxFeature { } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java index 10e918799..73ae0bcb1 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java @@ -27,24 +27,24 @@ import java.util.List; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServerFactory; import org.eclipse.digitaltwin.basyx.core.DecoratedFactory; /** - * Factory for {@link AasxFileServerFactory} decoration + * Factory for {@link AASXFileServerFactory} decoration * * @author schnicke, chaithra * */ -public class DecoratedAasxFileServerFactory extends DecoratedFactory implements AasxFileServerFactory { +public class DecoratedAasxFileServerFactory extends DecoratedFactory implements AASXFileServerFactory { - public DecoratedAasxFileServerFactory(AasxFileServerFactory toDecorate, List features) { + public DecoratedAasxFileServerFactory(AASXFileServerFactory toDecorate, List features) { super(toDecorate, features); } @Override - public AasxFileServer create() { + public AASXFileServer create() { return getDecorated().create(); } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java similarity index 56% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java index 8ce18079b..d3a41dc6a 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -31,32 +31,31 @@ import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.apache.commons.io.IOUtils; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.junit.Test; +import org.eclipse.digitaltwin.basyx.aasxfileserver.core.DummyAASXFileServerFactory; /** - * Testsuite for implementations of the {@link AasxFileServer} interface + * Testsuite for implementations of the {@link AASXFileServer} interface * * @author chaithra * */ -public abstract class AasxFileServerSuite { +public abstract class AASXFileServerSuite { - protected abstract AasxFileServer getAasxFileServer(); + protected abstract AASXFileServer getAASXFileServer(); @Test public void getAllAASXPackageIds() { - AasxFileServer server = getAasxFileServer(); - Collection packageDescriptions = DummyAasxFileServerFactory.getAllDummyAASXPackages(server); + AASXFileServer server = getAASXFileServer(); + Collection packageDescriptions = DummyAASXFileServerFactory.getAllDummyAASXPackages(server); assertGetAllAASXPackageIds(packageDescriptions); } @@ -64,7 +63,7 @@ public void getAllAASXPackageIds() { @Test public void getAllAASXPackageIdsEmpty() { - AasxFileServer server = getAasxFileServer(); + AASXFileServer server = getAASXFileServer(); Collection packageDescriptions = server.getAllAASXPackageIds(); assertIsEmpty(packageDescriptions); @@ -73,47 +72,50 @@ public void getAllAASXPackageIdsEmpty() { @Test(expected = ElementDoesNotExistException.class) public void getSpecificNonExistingPackageId() { - AasxFileServer server = getAasxFileServer(); + AASXFileServer server = getAASXFileServer(); server.getAASXByPackageId("doesNotExist"); } @Test public void updateExistingAASXByPackageId() { - AasxFileServer server = getAasxFileServer(); - PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); - List expectedAasIds = new ArrayList<>(Arrays.asList("AAS_ID_3", "AAS_ID_4")); - server.updateAASXByPackageId(packageDescription.getPackageId(), expectedAasIds, - AasxFileServerSuiteHelper.FIRST_FILE, AasxFileServerSuiteHelper.FIRST_FILENAME); + AASXFileServer server = getAASXFileServer(); + + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + + updateAasxPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS , + DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); - assertAASXPackageId(packageDescription, expectedAasIds); + Collection actualPackageDescription = server.getAllAASXPackageIds(); + + assertUpdatedAASXPackageId(expectedPackageDescription, actualPackageDescription, server); } @Test(expected = ElementDoesNotExistException.class) public void updateNonExistingAASXByPackageId() { String packageId = "notExisting"; - AasxFileServer server = getAasxFileServer(); - server.updateAASXByPackageId(packageId, AasxFileServerSuiteHelper.FIRST_AAS_IDS, - AasxFileServerSuiteHelper.FIRST_FILE, AasxFileServerSuiteHelper.FIRST_FILENAME); + AASXFileServer server = getAASXFileServer(); + server.updateAASXByPackageId(packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, + DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); } @Test public void getAASXByPackageId() throws ElementDoesNotExistException, IOException { - AasxFileServer server = getAasxFileServer(); - PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); + AASXFileServer server = getAASXFileServer(); + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); - InputStream expectedValue = AasxFileServerSuiteHelper.FIRST_FILE; - - assertTrue(IOUtils.contentEquals(expectedValue, actualValue)); + InputStream expectedValue = DummyAASXFileServerFactory.FIRST_FILE; + + assertInputStreamsEqual(expectedValue, actualValue); } @Test public void deleteAASXByPackageId() { - AasxFileServer server = getAasxFileServer(); - PackageDescription packageDescription = DummyAasxFileServerFactory.createFirstDummyAASXPackage(server); + AASXFileServer server = getAASXFileServer(); + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); server.deleteAASXByPackageId(packageDescription.getPackageId()); try { server.getAASXByPackageId(packageDescription.getPackageId()); @@ -125,16 +127,24 @@ public void deleteAASXByPackageId() { @Test(expected = ElementDoesNotExistException.class) public void deleteNonExistingAasxFileServer() { - AasxFileServer server = getAasxFileServer(); + AASXFileServer server = getAASXFileServer(); server.deleteAASXByPackageId("nonExisting"); } + private void updateAasxPackage(AASXFileServer server, String packageId, List expectedAasIds, InputStream secondFile, + String secondFilename) { + + server.updateAASXByPackageId(packageId, expectedAasIds, + DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); + + } + private void assertGetAllAASXPackageIds(Collection packageDescriptions) { assertEquals(2, packageDescriptions.size()); - List expectedFirstAasIds = AasxFileServerSuiteHelper.FIRST_AAS_IDS; - List expectedSecondAasIds = AasxFileServerSuiteHelper.SECOND_AAS_IDS; + List expectedFirstAasIds = DummyAASXFileServerFactory.FIRST_AAS_IDS; + List expectedSecondAasIds = DummyAASXFileServerFactory.SECOND_AAS_IDS; for (PackageDescription packageDescription : packageDescriptions) { if (packageDescription.getPackageId().equals("1")) { @@ -147,14 +157,32 @@ private void assertGetAllAASXPackageIds(Collection packageDe } } - private void assertAASXPackageId(PackageDescription actualPackageDescription, List expectedNewAasIds ) { - assertEquals(expectedNewAasIds, actualPackageDescription.getAasIds()); - assertEquals(expectedNewAasIds.size(), actualPackageDescription.getAasIds().size()); - assertEquals("1",actualPackageDescription.getPackageId()); - } + private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, Collection actualPackageDescriptions, AASXFileServer server) { + assertEquals(1, actualPackageDescriptions.size()); + assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); + + InputStream actualAASXFile = server.getAASXByPackageId(actualPackageDescriptions.iterator().next().getPackageId()); + InputStream expectedAASXFile = server.getAASXByPackageId(expectedPackageDescription.getPackageId()); + + assertEquals(expectedAASXFile,actualAASXFile); + } private void assertIsEmpty(Collection packageDescription) { assertTrue(packageDescription.isEmpty()); } + private boolean assertInputStreamsEqual(InputStream expectedValue, InputStream actualValue) throws IOException { + int expectedByte; + int actualByte; + + while ((expectedByte = expectedValue.read()) != -1) { + actualByte = actualValue.read(); + + if (expectedByte != actualByte) { + return false; + } + } + return actualValue.read() == -1; + } + } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java deleted file mode 100644 index 1fb3a152e..000000000 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AasxFileServerSuiteHelper.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * 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.digitaltwin.basyx.aasxfileserver.core; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; - -/** - * Test helper class for {@link AasxFileServerSuite} - * - * @author chaithra - * - */ -public class AasxFileServerSuiteHelper { - - public static final List FIRST_AAS_IDS = Arrays.asList("AAS_ID_1", "AAS_ID_2"); - public static final String FIRST_FILENAME = "test_file1.txt"; - public static final byte[] FIRST_BYTEARRAY = {65, 66, 67, 68, 69}; - public static final InputStream FIRST_FILE = new ByteArrayInputStream(FIRST_BYTEARRAY); - - public static final List SECOND_AAS_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); - public static final String SECOND_FILENAME = "test_file2.txt"; - public static final byte[] SECOND_BYTEARRAY = {75, 76, 77, 78, 79}; - public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); - -} \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java similarity index 65% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java index 1cf0aa573..508c1a682 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAasxFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java @@ -24,10 +24,14 @@ ******************************************************************************/ package org.eclipse.digitaltwin.basyx.aasxfileserver.core; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.List; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; /** @@ -36,23 +40,27 @@ * @author chaithra * */ -public class DummyAasxFileServerFactory { +public class DummyAASXFileServerFactory { + + public static final List FIRST_AAS_IDS = Arrays.asList("AAS_ID_1", "AAS_ID_2"); + public static final String FIRST_FILENAME = "test_file1.txt"; + public static final byte[] FIRST_BYTEARRAY = {65, 66, 67, 68, 69}; + public static final InputStream FIRST_FILE = new ByteArrayInputStream(FIRST_BYTEARRAY); - public static PackageDescription createFirstDummyAASXPackage(AasxFileServer server) { - return server.createAASXPackage( - AasxFileServerSuiteHelper.FIRST_AAS_IDS, - AasxFileServerSuiteHelper.FIRST_FILE, - AasxFileServerSuiteHelper.FIRST_FILENAME); + public static final List SECOND_AAS_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); + public static final String SECOND_FILENAME = "test_file2.txt"; + public static final byte[] SECOND_BYTEARRAY = {75, 76, 77, 78, 79}; + public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); + + public static PackageDescription createFirstDummyAASXPackage(AASXFileServer server) { + return server.createAASXPackage(FIRST_AAS_IDS, FIRST_FILE, FIRST_FILENAME); } - public static PackageDescription createSecondDummyAASXPackage(AasxFileServer server) { - return server.createAASXPackage( - AasxFileServerSuiteHelper.SECOND_AAS_IDS, - AasxFileServerSuiteHelper.SECOND_FILE, - AasxFileServerSuiteHelper.SECOND_FILENAME); + public static PackageDescription createSecondDummyAASXPackage(AASXFileServer server) { + return server.createAASXPackage(SECOND_AAS_IDS, SECOND_FILE, SECOND_FILENAME); } - public static Collection getAllDummyAASXPackages(AasxFileServer server) { + public static Collection getAllDummyAASXPackages(AASXFileServer server) { PackageDescription firstPackage = createFirstDummyAASXPackage(server); PackageDescription secondPackage = createSecondDummyAASXPackage(server); diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java similarity index 89% rename from basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java rename to basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java index 36e917c29..9dc60529c 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerComponent.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java @@ -26,22 +26,22 @@ package org.eclipse.digitaltwin.basyx.aasxfileserver.component; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; /** - * Creates and starts the {@link AasxFileServer} off-shelf-component + * Creates and starts the {@link AASXFileServer} off-shelf-component * * @author schnicke, chaithra * */ @SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx", exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) -public class AasxFileServerComponent { +public class AASXFileServerComponent { public static void main(String[] args) { - SpringApplication.run(AasxFileServerComponent.class, args); + SpringApplication.run(AASXFileServerComponent.class, args); } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java similarity index 87% rename from basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java rename to basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java index 239d8d4ab..3009341d9 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerConfiguration.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java @@ -27,25 +27,25 @@ import java.util.List; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServer; -import org.eclipse.digitaltwin.basyx.aasxfileserver.AasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServerFactory; import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AasxFileServerFeature; import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.DecoratedAasxFileServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * Provides the spring bean configuration for the {@link AasxFileServer} + * Provides the spring bean configuration for the {@link AASXFileServer} * utilizing all found features for the respective services * * @author chaithra * */ @Configuration -public class AasxFileServerConfiguration { +public class AASXFileServerConfiguration { @Bean - public static AasxFileServer getAasxFileServer(AasxFileServerFactory aasRepositoryFactory, List features) { + public static AASXFileServer getAasxFileServer(AASXFileServerFactory aasRepositoryFactory, List features) { return new DecoratedAasxFileServerFactory(aasRepositoryFactory, features).create(); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java similarity index 91% rename from basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java rename to basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java index 272257a69..9f2ab516d 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AasxFileServerFeaturePrinter.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java @@ -39,12 +39,12 @@ * */ @Service -public class AasxFileServerFeaturePrinter { +public class AASXFileServerFeaturePrinter { - private static final Logger logger = LoggerFactory.getLogger(AasxFileServerFeaturePrinter.class); + private static final Logger logger = LoggerFactory.getLogger(AASXFileServerFeaturePrinter.class); @Autowired - public AasxFileServerFeaturePrinter(List features) { + public AASXFileServerFeaturePrinter(List features) { logger.info("-------------------- AASX File Server Features: --------------------"); for (AasxFileServerFeature feature : features) { logger.info("BaSyxFeature " + feature.getName() + " is enabled: " + feature.isEnabled()); diff --git a/basyx.aasxfileserver/pom.xml b/basyx.aasxfileserver/pom.xml index b35796f33..2cef4d475 100644 --- a/basyx.aasxfileserver/pom.xml +++ b/basyx.aasxfileserver/pom.xml @@ -15,6 +15,6 @@ basyx.aasxfileserver-core basyx.aasxfileserver.component - basyx.aasxfileserver-backend-inmemory + basyx.aasxfileserver-backend-inmemory \ No newline at end of file From d1f74e90091656843fcfd23709a9a4a710ad8d8f Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Tue, 26 Sep 2023 12:53:11 +0200 Subject: [PATCH 09/15] Removing IOUtils --- basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml index dc16f28bc..0ada2d204 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml @@ -21,10 +21,5 @@ org.eclipse.digitaltwin.aas4j model - - commons-io - commons-io - test - \ No newline at end of file From b0840da4b4aa7240996d28f2fdd3128ba2efc21b Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Thu, 28 Sep 2023 12:45:14 +0200 Subject: [PATCH 10/15] Changes to AASXFileServerSuite --- .../core/AASXFileServerSuite.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java index d3a41dc6a..632f7e8c5 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -31,9 +31,10 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.Collection; import java.util.List; - +import java.util.Iterator; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; @@ -139,30 +140,23 @@ private void updateAasxPackage(AASXFileServer server, String packageId, List packageDescriptions) { + private void assertGetAllAASXPackageIds(Collection packageDescriptions) { + assertEquals(2, packageDescriptions.size()); + + Iterator iterator = packageDescriptions.iterator(); - assertEquals(2, packageDescriptions.size()); - - List expectedFirstAasIds = DummyAASXFileServerFactory.FIRST_AAS_IDS; - List expectedSecondAasIds = DummyAASXFileServerFactory.SECOND_AAS_IDS; - - for (PackageDescription packageDescription : packageDescriptions) { - if (packageDescription.getPackageId().equals("1")) { - assertEquals(expectedFirstAasIds, packageDescription.getAasIds()); - } else if (packageDescription.getPackageId().equals("2")) { - assertEquals(expectedSecondAasIds, packageDescription.getAasIds()); - } else { - fail("Unexpected package ID: " + packageDescription.getPackageId()); - } - } + PackageDescription expectedFirstPackage = iterator.next(); + PackageDescription expectedSecondPackage = iterator.next(); + + assertTrue(packageDescriptions.containsAll(Arrays.asList(expectedFirstPackage, expectedSecondPackage))); } private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, Collection actualPackageDescriptions, AASXFileServer server) { assertEquals(1, actualPackageDescriptions.size()); assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); - InputStream actualAASXFile = server.getAASXByPackageId(actualPackageDescriptions.iterator().next().getPackageId()); - InputStream expectedAASXFile = server.getAASXByPackageId(expectedPackageDescription.getPackageId()); + InputStream actualAASXFile = server.getAASXByPackageId("1"); + InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; assertEquals(expectedAASXFile,actualAASXFile); } From dd949ef8ad66e99007b59f35824de3f187a7f36f Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Tue, 17 Oct 2023 15:29:36 +0200 Subject: [PATCH 11/15] Changes for Review Comments --- .../pom.xml | 5 + .../InMemoryAASXFileServer.java | 33 ++-- .../basyx.aasxfileserver-core/pom.xml | 12 +- .../core/AASXFileServerSuite.java | 166 ++++++++---------- 4 files changed, 111 insertions(+), 105 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml index 7c61f8383..d87f24c2a 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml @@ -29,6 +29,11 @@ org.springframework.boot spring-boot-starter + + + commons-io + commons-io + test \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java index 5a0a95c5e..c1f8fd10d 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java @@ -45,12 +45,7 @@ public class InMemoryAASXFileServer implements AASXFileServer { private Map packageMap = new LinkedHashMap<>(); - private AtomicInteger packageId = new AtomicInteger(0); - - /** - * Creates the InMemoryAASXFileServer - */ - public InMemoryAASXFileServer() {} + private AtomicInteger packageId = new AtomicInteger(0); @Override public Collection getAllAASXPackageIds() { @@ -80,8 +75,10 @@ public void updateAASXByPackageId(String packageId, List aasIds, InputSt public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) throws CollidingIdentifierException { - String newpackageId = String.valueOf(packageId.incrementAndGet()); - PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); + String newpackageId = String.valueOf(packageId.incrementAndGet()); + + PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); + createPackage(aasIds, file, fileName, newpackageId, packageDescription); return packageDescription; @@ -112,17 +109,25 @@ private PackagesBody createPackagesBody(List aasIds, InputStream file, S } private void createPackage(List aasIds, InputStream file, String fileName, String newPackageId, PackageDescription packageDescription) { - PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); - Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); + PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); + + Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); + packageMap.put(newPackageId, aasxPackage); } private void updateAASXPackage(String packageId, List aasIds, InputStream file, String filename) { - Package aasxPackage = this.packageMap.get(packageId); - aasxPackage.getPackagesBody().setAasIds(aasIds); - aasxPackage.getPackagesBody().setFileName(filename); - aasxPackage.getPackagesBody().setFile(file); + Package aasxPackage = this.packageMap.get(packageId); + + updatePackagesBody(aasIds, file, filename, aasxPackage.getPackagesBody()); + aasxPackage.getPackageDescription().setAasIds(aasIds); + } + + private void updatePackagesBody(List aasIds, InputStream file, String filename, PackagesBody packagesBody) { + packagesBody.setAasIds(aasIds); + packagesBody.setFileName(filename); + packagesBody.setFile(file); } private void throwIfAASXPackageIdDoesNotExist(String id) { diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml index 0ada2d204..85e4d65f1 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml @@ -10,7 +10,7 @@ basyx.aasxfileserver-core AASX File Server Core - + org.eclipse.digitaltwin.basyx @@ -21,5 +21,13 @@ org.eclipse.digitaltwin.aas4j model + + commons-io + commons-io + test + + - \ No newline at end of file + + + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java index 632f7e8c5..8dac25630 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -35,12 +35,12 @@ import java.util.Collection; import java.util.List; import java.util.Iterator; +import org.apache.commons.io.IOUtils; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.junit.Test; -import org.eclipse.digitaltwin.basyx.aasxfileserver.core.DummyAASXFileServerFactory; /** * Testsuite for implementations of the {@link AASXFileServer} interface @@ -49,134 +49,122 @@ * */ public abstract class AASXFileServerSuite { - - protected abstract AASXFileServer getAASXFileServer(); - + + protected abstract AASXFileServer getAASXFileServer(); + @Test public void getAllAASXPackageIds() { - - AASXFileServer server = getAASXFileServer(); - Collection packageDescriptions = DummyAASXFileServerFactory.getAllDummyAASXPackages(server); - + + AASXFileServer server = getAASXFileServer(); + Collection packageDescriptions = DummyAASXFileServerFactory.getAllDummyAASXPackages(server); + assertGetAllAASXPackageIds(packageDescriptions); } - + @Test public void getAllAASXPackageIdsEmpty() { - - AASXFileServer server = getAASXFileServer(); - Collection packageDescriptions = server.getAllAASXPackageIds(); - - assertIsEmpty(packageDescriptions); + + AASXFileServer server = getAASXFileServer(); + Collection packageDescriptions = server.getAllAASXPackageIds(); + + assertTrue(packageDescriptions.isEmpty()); } @Test(expected = ElementDoesNotExistException.class) public void getSpecificNonExistingPackageId() { - + AASXFileServer server = getAASXFileServer(); server.getAASXByPackageId("doesNotExist"); } @Test - public void updateExistingAASXByPackageId() { - - AASXFileServer server = getAASXFileServer(); - - PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); - - updateAasxPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS , - DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); - + public void updateExistingAASXByPackageId() { + + AASXFileServer server = getAASXFileServer(); + + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + + updateAasxPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, + DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); + Collection actualPackageDescription = server.getAllAASXPackageIds(); - + assertUpdatedAASXPackageId(expectedPackageDescription, actualPackageDescription, server); - } + } @Test(expected = ElementDoesNotExistException.class) public void updateNonExistingAASXByPackageId() { + + String packageId = "notExisting"; - String packageId = "notExisting"; - AASXFileServer server = getAASXFileServer(); - server.updateAASXByPackageId(packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, - DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); - } - + AASXFileServer server = getAASXFileServer(); + + server.updateAASXByPackageId(packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); + } + @Test public void getAASXByPackageId() throws ElementDoesNotExistException, IOException { - + AASXFileServer server = getAASXFileServer(); - PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); - InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); - InputStream expectedValue = DummyAASXFileServerFactory.FIRST_FILE; - - assertInputStreamsEqual(expectedValue, actualValue); + + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + + InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); + InputStream expectedValue = DummyAASXFileServerFactory.FIRST_FILE; + + assertTrue(IOUtils.contentEquals(expectedValue, actualValue)); } @Test public void deleteAASXByPackageId() { - + AASXFileServer server = getAASXFileServer(); - PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); - server.deleteAASXByPackageId(packageDescription.getPackageId()); + + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + + server.deleteAASXByPackageId(packageDescription.getPackageId()); + try { server.getAASXByPackageId(packageDescription.getPackageId()); fail(); } catch (ElementDoesNotExistException expected) { } - } - + } + @Test(expected = ElementDoesNotExistException.class) public void deleteNonExistingAasxFileServer() { - + AASXFileServer server = getAASXFileServer(); server.deleteAASXByPackageId("nonExisting"); - } - - private void updateAasxPackage(AASXFileServer server, String packageId, List expectedAasIds, InputStream secondFile, - String secondFilename) { - - server.updateAASXByPackageId(packageId, expectedAasIds, - DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); - } - - private void assertGetAllAASXPackageIds(Collection packageDescriptions) { - assertEquals(2, packageDescriptions.size()); - - Iterator iterator = packageDescriptions.iterator(); - - PackageDescription expectedFirstPackage = iterator.next(); - PackageDescription expectedSecondPackage = iterator.next(); - - assertTrue(packageDescriptions.containsAll(Arrays.asList(expectedFirstPackage, expectedSecondPackage))); - } - - private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, Collection actualPackageDescriptions, AASXFileServer server) { - assertEquals(1, actualPackageDescriptions.size()); - assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); - - InputStream actualAASXFile = server.getAASXByPackageId("1"); - InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; - - assertEquals(expectedAASXFile,actualAASXFile); + + private void updateAasxPackage(AASXFileServer server, String packageId, List expectedAasIds, + InputStream secondFile, String secondFilename) { + + server.updateAASXByPackageId(packageId, expectedAasIds, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); } - - private void assertIsEmpty(Collection packageDescription) { - assertTrue(packageDescription.isEmpty()); - } - - private boolean assertInputStreamsEqual(InputStream expectedValue, InputStream actualValue) throws IOException { - int expectedByte; - int actualByte; - - while ((expectedByte = expectedValue.read()) != -1) { - actualByte = actualValue.read(); - - if (expectedByte != actualByte) { - return false; - } - } - return actualValue.read() == -1; + + private void assertGetAllAASXPackageIds(Collection packageDescriptions) { + assertEquals(2, packageDescriptions.size()); + + Iterator iterator = packageDescriptions.iterator(); + + PackageDescription expectedFirstPackage = iterator.next(); + PackageDescription expectedSecondPackage = iterator.next(); + + assertTrue(packageDescriptions.containsAll(Arrays.asList(expectedFirstPackage, expectedSecondPackage))); + } + + private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, + Collection actualPackageDescriptions, AASXFileServer server) { + + assertEquals(1, actualPackageDescriptions.size()); + assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); + + InputStream actualAASXFile = server.getAASXByPackageId("1"); + InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; + + assertEquals(expectedAASXFile, actualAASXFile); } } From 1d1052c6b95b655b270a5b36ab6f2d9bab38cc88 Mon Sep 17 00:00:00 2001 From: Chaithra Kandur Bhagavanthaiah Date: Thu, 26 Oct 2023 15:40:04 +0200 Subject: [PATCH 12/15] Changes for the review comments --- .../InMemoryAASXFileServer.java | 31 +++++++-- .../InMemoryAASXFileServerFactory.java | 2 +- .../TestInMemoryAASXFileServer.java | 15 ++++- .../basyx/aasxfileserver/AASXFileServer.java | 17 ++++- .../aasxfileserver/AASXFileServerFactory.java | 2 +- ...eature.java => AASXFileServerFeature.java} | 2 +- ...va => DecoratedAASXFileServerFactory.java} | 4 +- .../aasxfileserver/{ => model}/Package.java | 6 +- .../{ => model}/PackageDescription.java | 6 +- .../{ => model}/PackagesBody.java | 5 +- .../core/AASXFileServerSuite.java | 63 +++++++++++-------- .../core/DummyAASXFileServerFactory.java | 20 ++++-- .../AASXFileServerConfiguration.java | 8 +-- .../AASXFileServerFeaturePrinter.java | 8 +-- 14 files changed, 129 insertions(+), 60 deletions(-) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/{AasxFileServerFeature.java => AASXFileServerFeature.java} (96%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/{DecoratedAasxFileServerFactory.java => DecoratedAASXFileServerFactory.java} (88%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{ => model}/Package.java (91%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{ => model}/PackageDescription.java (94%) rename basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/{ => model}/PackagesBody.java (95%) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java index c1f8fd10d..8e9080e59 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java @@ -33,11 +33,13 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.aasxfileserver.model.Package; +import org.eclipse.digitaltwin.basyx.aasxfileserver.model.PackageDescription; +import org.eclipse.digitaltwin.basyx.aasxfileserver.model.PackagesBody; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; /** - * In-memory implementation of the AASXFileServer + * In-memory implementation of the {@link AASXFileServer} * * @author chaithra * @@ -47,6 +49,23 @@ public class InMemoryAASXFileServer implements AASXFileServer { private Map packageMap = new LinkedHashMap<>(); private AtomicInteger packageId = new AtomicInteger(0); + private String aasxFileServerName; + + /** + * Creates the InMemoryAASXFileServer + * + */ + public InMemoryAASXFileServer() { } + + /** + * Creates the InMemoryAASXFileServer + * + * @param aasxRepositoryName Name of the CDRepository + */ + public InMemoryAASXFileServer(String aasxFileServerName) { + this.aasxFileServerName = aasxFileServerName; + } + @Override public Collection getAllAASXPackageIds() { return packageMap.values() @@ -72,8 +91,7 @@ public void updateAASXByPackageId(String packageId, List aasIds, InputSt } @Override - public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) - throws CollidingIdentifierException { + public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) { String newpackageId = String.valueOf(packageId.incrementAndGet()); @@ -91,6 +109,11 @@ public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistEx packageMap.remove(packageId); } + @Override + public String getName() { + return aasxFileServerName == null ? AASXFileServer.super.getName() : aasxFileServerName; + } + private PackageDescription createPackageDescription(List aasIds, String newPackageId) { PackageDescription packageDescription = new PackageDescription(); packageDescription.packageId(newPackageId); diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java index e160b0d7f..09576fcc2 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java @@ -28,7 +28,7 @@ import org.springframework.stereotype.Component; /** - * AasxFileServer factory returning an in-memory backend {@link AASXFileServer} + * AASXFileServer factory returning an in-memory backend {@link AASXFileServer} * * @author schnicke, chaithra */ diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java index ac79a0aba..f23372e0b 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java @@ -25,7 +25,10 @@ package org.eclipse.digitaltwin.basyx.aasxfileserver; +import static org.junit.Assert.assertEquals; + import org.eclipse.digitaltwin.basyx.aasxfileserver.core.AASXFileServerSuite; +import org.junit.Test; /** * Tests the {@link InMemoryAASXFileServer} @@ -34,10 +37,20 @@ * */ public class TestInMemoryAASXFileServer extends AASXFileServerSuite { + + private static final String CONFIGURED_AASX_SERVER_NAME = "configured-aasx-server-name"; @Override protected AASXFileServer getAASXFileServer() { return new InMemoryAASXFileServer(); } - + + @Test + public void getConfiguredInMemoryAASXFileServer() { + AASXFileServer server = new InMemoryAASXFileServer(CONFIGURED_AASX_SERVER_NAME); + + assertEquals(CONFIGURED_AASX_SERVER_NAME, server.getName()); + } + + } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java index 090342d93..dcfa6d720 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java @@ -29,11 +29,12 @@ import java.util.Collection; import java.util.List; +import org.eclipse.digitaltwin.basyx.aasxfileserver.model.PackageDescription; import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; /** - * Specifies the overall AasxFileServer API + * Specifies the overall {@link AASXFileServer} API * * @author chaithra * @@ -75,13 +76,23 @@ public interface AASXFileServer { * @param filename * @throws CollidingIdentifierException */ - public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) throws CollidingIdentifierException; + public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName); /** - * Deletes a AASX Package + * Deletes a AASX Package + * * @param packageId * @throws ElementDoesNotExistException */ public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException; + /** + * Returns the name of the AASX file server + * + * @return serverName + */ + public default String getName() { + return "aasx-server"; + } + } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java index bf7dc71e1..c46e7e4fe 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java @@ -35,7 +35,7 @@ public interface AASXFileServerFactory { /** - * Creates a new AasxFileServer + * Creates a new @link{ AASXFileServer} * * @return */ diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java similarity index 96% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java index 616590f3c..72e924313 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AasxFileServerFeature.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java @@ -35,6 +35,6 @@ * @author schnicke, chaithra * */ -public interface AasxFileServerFeature extends BaSyxFeature { +public interface AASXFileServerFeature extends BaSyxFeature { } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAASXFileServerFactory.java similarity index 88% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAASXFileServerFactory.java index 73ae0bcb1..8409316fe 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAasxFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/DecoratedAASXFileServerFactory.java @@ -37,9 +37,9 @@ * @author schnicke, chaithra * */ -public class DecoratedAasxFileServerFactory extends DecoratedFactory implements AASXFileServerFactory { +public class DecoratedAASXFileServerFactory extends DecoratedFactory implements AASXFileServerFactory { - public DecoratedAasxFileServerFactory(AASXFileServerFactory toDecorate, List features) { + public DecoratedAASXFileServerFactory(AASXFileServerFactory toDecorate, List features) { super(toDecorate, features); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java similarity index 91% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java index 89837b6ee..0945e18b9 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/Package.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java @@ -23,10 +23,12 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasxfileserver; +package org.eclipse.digitaltwin.basyx.aasxfileserver.model; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; /** - * Specifies the Package for AasxFileServer + * Specifies the Package for {@link AASXFileServer} * * @author chaithra * diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java similarity index 94% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java index 374773ea0..ab025c6c3 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackageDescription.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java @@ -23,15 +23,17 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasxfileserver; +package org.eclipse.digitaltwin.basyx.aasxfileserver.model; import java.util.Objects; import java.util.ArrayList; import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.springframework.validation.annotation.Validated; /** - * Specifies the PackageDescription for AasxFileServer + * Specifies the PackageDescription for {@link AASXFileServer} * */ @Validated diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java similarity index 95% rename from basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java rename to basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java index 4f467b127..a6620a266 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/PackagesBody.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java @@ -23,18 +23,19 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasxfileserver; +package org.eclipse.digitaltwin.basyx.aasxfileserver.model; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.springframework.validation.annotation.Validated; /** - * Specifies the PackagesBody for AasxFileServer + * Specifies the PackagesBody for {@link AASXFileServer} * */ @Validated diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java index 8dac25630..9cdc9b4d8 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -34,11 +34,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.Iterator; import org.apache.commons.io.IOUtils; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; -import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; +import org.eclipse.digitaltwin.basyx.aasxfileserver.model.PackageDescription; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.junit.Test; @@ -56,9 +55,25 @@ public abstract class AASXFileServerSuite { public void getAllAASXPackageIds() { AASXFileServer server = getAASXFileServer(); - Collection packageDescriptions = DummyAASXFileServerFactory.getAllDummyAASXPackages(server); + Collection actualPackageDescriptions = DummyAASXFileServerFactory.createMultipleDummyAASXPackagesOnServer(server); - assertGetAllAASXPackageIds(packageDescriptions); + PackageDescription expectedDescription1 = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_AAS_IDS); + PackageDescription expectedDescription2 = DummyAASXFileServerFactory.createDummyPackageDescription("2", DummyAASXFileServerFactory.SECOND_AAS_IDS); + + Collection expectedPackageDescriptions = Arrays.asList(expectedDescription1, expectedDescription2); + + assertGetAllAASXPackageIds(expectedPackageDescriptions, actualPackageDescriptions); + } + + @Test + public void createAASXPackage() { + + AASXFileServer server = getAASXFileServer(); + PackageDescription actualPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); + + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_AAS_IDS); + + assertEquals(expectedPackageDescription, actualPackageDescription); } @Test @@ -78,13 +93,13 @@ public void getSpecificNonExistingPackageId() { } @Test - public void updateExistingAASXByPackageId() { + public void updateExistingAASXByPackageId() throws IOException { AASXFileServer server = getAASXFileServer(); - PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); - updateAasxPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, + updateAASXPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); Collection actualPackageDescription = server.getAllAASXPackageIds(); @@ -98,8 +113,8 @@ public void updateNonExistingAASXByPackageId() { String packageId = "notExisting"; AASXFileServer server = getAASXFileServer(); - - server.updateAASXByPackageId(packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); + + updateAASXPackage(server, packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); } @Test @@ -107,7 +122,7 @@ public void getAASXByPackageId() throws ElementDoesNotExistException, IOExceptio AASXFileServer server = getAASXFileServer(); - PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); InputStream expectedValue = DummyAASXFileServerFactory.FIRST_FILE; @@ -120,7 +135,7 @@ public void deleteAASXByPackageId() { AASXFileServer server = getAASXFileServer(); - PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); server.deleteAASXByPackageId(packageDescription.getPackageId()); @@ -132,39 +147,33 @@ public void deleteAASXByPackageId() { } @Test(expected = ElementDoesNotExistException.class) - public void deleteNonExistingAasxFileServer() { + public void deleteNonExistingAASXPackage() { AASXFileServer server = getAASXFileServer(); server.deleteAASXByPackageId("nonExisting"); } - private void updateAasxPackage(AASXFileServer server, String packageId, List expectedAasIds, - InputStream secondFile, String secondFilename) { + private void updateAASXPackage(AASXFileServer server, String packageId, List expectedAasIds, + InputStream file, String filename) { - server.updateAASXByPackageId(packageId, expectedAasIds, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); + server.updateAASXByPackageId(packageId, expectedAasIds, file, filename); } - private void assertGetAllAASXPackageIds(Collection packageDescriptions) { - assertEquals(2, packageDescriptions.size()); - - Iterator iterator = packageDescriptions.iterator(); - - PackageDescription expectedFirstPackage = iterator.next(); - PackageDescription expectedSecondPackage = iterator.next(); - - assertTrue(packageDescriptions.containsAll(Arrays.asList(expectedFirstPackage, expectedSecondPackage))); + private void assertGetAllAASXPackageIds(Collection expectedPackageDescriptions, Collection actualPackageDescriptions) { + assertTrue(expectedPackageDescriptions.containsAll(actualPackageDescriptions)); + assertTrue(actualPackageDescriptions.containsAll(expectedPackageDescriptions)); } private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, - Collection actualPackageDescriptions, AASXFileServer server) { + Collection actualPackageDescriptions, AASXFileServer server) throws IOException { assertEquals(1, actualPackageDescriptions.size()); assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); InputStream actualAASXFile = server.getAASXByPackageId("1"); InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; - - assertEquals(expectedAASXFile, actualAASXFile); + + assertTrue(IOUtils.contentEquals(expectedAASXFile, actualAASXFile)); } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java index 508c1a682..1297eb0fd 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java @@ -32,7 +32,7 @@ import java.util.List; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; -import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; +import org.eclipse.digitaltwin.basyx.aasxfileserver.model.PackageDescription; /** * Factory for creating AASX Packages for tests @@ -52,17 +52,17 @@ public class DummyAASXFileServerFactory { public static final byte[] SECOND_BYTEARRAY = {75, 76, 77, 78, 79}; public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); - public static PackageDescription createFirstDummyAASXPackage(AASXFileServer server) { + public static PackageDescription createFirstDummyAASXPackageOnServer(AASXFileServer server) { return server.createAASXPackage(FIRST_AAS_IDS, FIRST_FILE, FIRST_FILENAME); } - public static PackageDescription createSecondDummyAASXPackage(AASXFileServer server) { + public static PackageDescription createSecondDummyAASXPackageOnServer(AASXFileServer server) { return server.createAASXPackage(SECOND_AAS_IDS, SECOND_FILE, SECOND_FILENAME); } - public static Collection getAllDummyAASXPackages(AASXFileServer server) { - PackageDescription firstPackage = createFirstDummyAASXPackage(server); - PackageDescription secondPackage = createSecondDummyAASXPackage(server); + public static Collection createMultipleDummyAASXPackagesOnServer(AASXFileServer server) { + PackageDescription firstPackage = createFirstDummyAASXPackageOnServer(server); + PackageDescription secondPackage = createSecondDummyAASXPackageOnServer(server); ArrayList packages = new ArrayList<>(); packages.add(firstPackage); @@ -70,6 +70,14 @@ public static Collection getAllDummyAASXPackages(AASXFileSer return packages; } + + public static PackageDescription createDummyPackageDescription(String packageId, List aasIds) { + PackageDescription expectedDescription1 = new PackageDescription(); + expectedDescription1.setPackageId(packageId); + expectedDescription1.setAasIds(aasIds); + + return expectedDescription1; + } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java index 3009341d9..9fce53e36 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java @@ -29,8 +29,8 @@ import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServerFactory; -import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AasxFileServerFeature; -import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.DecoratedAasxFileServerFactory; +import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AASXFileServerFeature; +import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.DecoratedAASXFileServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -45,8 +45,8 @@ public class AASXFileServerConfiguration { @Bean - public static AASXFileServer getAasxFileServer(AASXFileServerFactory aasRepositoryFactory, List features) { - return new DecoratedAasxFileServerFactory(aasRepositoryFactory, features).create(); + public static AASXFileServer getAASXFileServer(AASXFileServerFactory aasRepositoryFactory, List features) { + return new DecoratedAASXFileServerFactory(aasRepositoryFactory, features).create(); } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java index 9f2ab516d..8fd0cf983 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java @@ -26,14 +26,14 @@ import java.util.List; -import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AasxFileServerFeature; +import org.eclipse.digitaltwin.basyx.aasxfileserver.feature.AASXFileServerFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** - * Prints all AasxFileServer features that are on the classpath + * Prints all AASXFileServer features that are on the classpath * * @author schnicke, chaithra * @@ -44,9 +44,9 @@ public class AASXFileServerFeaturePrinter { private static final Logger logger = LoggerFactory.getLogger(AASXFileServerFeaturePrinter.class); @Autowired - public AASXFileServerFeaturePrinter(List features) { + public AASXFileServerFeaturePrinter(List features) { logger.info("-------------------- AASX File Server Features: --------------------"); - for (AasxFileServerFeature feature : features) { + for (AASXFileServerFeature feature : features) { logger.info("BaSyxFeature " + feature.getName() + " is enabled: " + feature.isEnabled()); } From 50a55b18227afed456d35ce1170d338ff54b59c1 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 3 Nov 2023 10:46:41 +0100 Subject: [PATCH 13/15] Applies BaSyx formatter and minor corrections Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../pom.xml | 9 +- .../InMemoryAASXFileServer.java | 78 +++---- .../InMemoryAASXFileServerFactory.java | 4 +- .../TestInMemoryAASXFileServer.java | 11 +- .../basyx.aasxfileserver-core/pom.xml | 13 +- .../basyx/aasxfileserver/AASXFileServer.java | 12 +- .../aasxfileserver/AASXFileServerFactory.java | 3 +- .../feature/AASXFileServerFeature.java | 1 - .../basyx/aasxfileserver/model/Package.java | 18 +- .../model/PackageDescription.java | 5 +- .../aasxfileserver/model/PackagesBody.java | 217 +++++++++--------- .../core/AASXFileServerSuite.java | 37 ++- .../core/DummyAASXFileServerFactory.java | 56 ++--- .../basyx.aasxfileserver.component/pom.xml | 4 +- .../component/AASXFileServerComponent.java | 6 +- .../AASXFileServerConfiguration.java | 2 +- .../src/main/resources/application.properties | 2 +- basyx.aasxfileserver/pom.xml | 3 +- 18 files changed, 233 insertions(+), 248 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml index d87f24c2a..c9bdfac13 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml @@ -1,7 +1,8 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + org.eclipse.digitaltwin.basyx basyx.aasxfileserver @@ -25,7 +26,7 @@ org.springframework spring-context - + org.springframework.boot spring-boot-starter @@ -34,6 +35,6 @@ commons-io commons-io test - + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java index 8e9080e59..efcdd879d 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java @@ -47,31 +47,30 @@ public class InMemoryAASXFileServer implements AASXFileServer { private Map packageMap = new LinkedHashMap<>(); - private AtomicInteger packageId = new AtomicInteger(0); - + private AtomicInteger packageId = new AtomicInteger(0); + private String aasxFileServerName; - + /** * Creates the InMemoryAASXFileServer * */ - public InMemoryAASXFileServer() { } - + public InMemoryAASXFileServer() { + } + /** * Creates the InMemoryAASXFileServer * - * @param aasxRepositoryName Name of the CDRepository + * @param aasxRepositoryName + * Name of the CDRepository */ public InMemoryAASXFileServer(String aasxFileServerName) { this.aasxFileServerName = aasxFileServerName; } - + @Override public Collection getAllAASXPackageIds() { - return packageMap.values() - .stream() - .map(Package::getPackageDescription) - .collect(Collectors.toList()); + return packageMap.values().stream().map(Package::getPackageDescription).collect(Collectors.toList()); } @Override @@ -82,68 +81,67 @@ public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExi } @Override - public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) - throws ElementDoesNotExistException { - + public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException { + throwIfAASXPackageIdDoesNotExist(packageId); - + updateAASXPackage(packageId, aasIds, file, filename); - } + } @Override public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) { - + String newpackageId = String.valueOf(packageId.incrementAndGet()); - - PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); - + + PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); + createPackage(aasIds, file, fileName, newpackageId, packageDescription); return packageDescription; - } + } @Override public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException { throwIfAASXPackageIdDoesNotExist(packageId); packageMap.remove(packageId); - } - + } + @Override public String getName() { return aasxFileServerName == null ? AASXFileServer.super.getName() : aasxFileServerName; } - - private PackageDescription createPackageDescription(List aasIds, String newPackageId) { + + private PackageDescription createPackageDescription(List aasIds, String newPackageId) { PackageDescription packageDescription = new PackageDescription(); packageDescription.packageId(newPackageId); packageDescription.aasIds(aasIds); - + return packageDescription; } - - private PackagesBody createPackagesBody(List aasIds, InputStream file, String fileName) { + + private PackagesBody createPackagesBody(List aasIds, InputStream file, String fileName) { PackagesBody packagesBody = new PackagesBody(); packagesBody.aasIds(aasIds); packagesBody.file(file); packagesBody.fileName(fileName); - + return packagesBody; - } - + } + private void createPackage(List aasIds, InputStream file, String fileName, String newPackageId, PackageDescription packageDescription) { PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); - - Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); - + + Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); + packageMap.put(newPackageId, aasxPackage); } - + private void updateAASXPackage(String packageId, List aasIds, InputStream file, String filename) { Package aasxPackage = this.packageMap.get(packageId); - + updatePackagesBody(aasIds, file, filename, aasxPackage.getPackagesBody()); - + aasxPackage.getPackageDescription().setAasIds(aasIds); } @@ -151,10 +149,10 @@ private void updatePackagesBody(List aasIds, InputStream file, String fi packagesBody.setAasIds(aasIds); packagesBody.setFileName(filename); packagesBody.setFile(file); - } - + } + private void throwIfAASXPackageIdDoesNotExist(String id) { - + if (!packageMap.containsKey(id)) throw new ElementDoesNotExistException(id); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java index 09576fcc2..e30b85aef 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java @@ -28,14 +28,14 @@ import org.springframework.stereotype.Component; /** - * AASXFileServer factory returning an in-memory backend {@link AASXFileServer} + * AASXFileServer factory returning an in-memory backend {@link AASXFileServer} * * @author schnicke, chaithra */ @Component @ConditionalOnExpression("'${basyx.backend}'.equals('InMemory')") public class InMemoryAASXFileServerFactory implements AASXFileServerFactory { - + @Override public AASXFileServer create() { return new InMemoryAASXFileServer(); diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java index f23372e0b..7776fe394 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java @@ -37,20 +37,19 @@ * */ public class TestInMemoryAASXFileServer extends AASXFileServerSuite { - + private static final String CONFIGURED_AASX_SERVER_NAME = "configured-aasx-server-name"; @Override protected AASXFileServer getAASXFileServer() { return new InMemoryAASXFileServer(); } - + @Test - public void getConfiguredInMemoryAASXFileServer() { + public void getConfiguredInMemoryAASXFileServer() { AASXFileServer server = new InMemoryAASXFileServer(CONFIGURED_AASX_SERVER_NAME); - + assertEquals(CONFIGURED_AASX_SERVER_NAME, server.getName()); } - - + } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml index 85e4d65f1..d837cd436 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml @@ -1,5 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -10,7 +11,7 @@ basyx.aasxfileserver-core AASX File Server Core - + org.eclipse.digitaltwin.basyx @@ -21,13 +22,13 @@ org.eclipse.digitaltwin.aas4j model + commons-io commons-io test - + - - - \ No newline at end of file + + \ No newline at end of file diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java index dcfa6d720..6bc77f4a6 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java @@ -47,7 +47,7 @@ public interface AASXFileServer { * @return a list of available AASX Package Descriptions at the server */ public Collection getAllAASXPackageIds(); - + /** * Retrieves a specific AASX package from the server * @@ -73,19 +73,19 @@ public interface AASXFileServer { * * @param aasIds * @param file - * @param filename + * @param filename * @throws CollidingIdentifierException */ public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName); /** - * Deletes a AASX Package - * + * Deletes a AASX Package + * * @param packageId * @throws ElementDoesNotExistException */ public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException; - + /** * Returns the name of the AASX file server * @@ -94,5 +94,5 @@ public interface AASXFileServer { public default String getName() { return "aasx-server"; } - + } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java index c46e7e4fe..d4c848c73 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java @@ -23,7 +23,6 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ - package org.eclipse.digitaltwin.basyx.aasxfileserver; /** @@ -33,7 +32,7 @@ * */ public interface AASXFileServerFactory { - + /** * Creates a new @link{ AASXFileServer} * diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java index 72e924313..005a8d903 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java @@ -23,7 +23,6 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ - package org.eclipse.digitaltwin.basyx.aasxfileserver.feature; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServerFactory; diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java index 0945e18b9..eb7ceedd2 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java @@ -34,20 +34,20 @@ * */ public class Package { - - private String packageId; - private PackageDescription packageDescription; - private PackagesBody packagesBody; - - public Package(String packageId, PackageDescription packageDescription, PackagesBody packagesBody ) { + + private String packageId; + private PackageDescription packageDescription; + private PackagesBody packagesBody; + + public Package(String packageId, PackageDescription packageDescription, PackagesBody packagesBody) { this.packageId = packageId; this.packageDescription = packageDescription; - this.packagesBody = packagesBody; + this.packagesBody = packagesBody; } public String getPackageId() { return packageId; - } + } public PackageDescription getPackageDescription() { return packageDescription; @@ -55,5 +55,5 @@ public PackageDescription getPackageDescription() { public PackagesBody getPackagesBody() { return packagesBody; - } + } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java index ab025c6c3..a42093974 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java @@ -33,7 +33,7 @@ import org.springframework.validation.annotation.Validated; /** - * Specifies the PackageDescription for {@link AASXFileServer} + * Specifies the PackageDescription for {@link AASXFileServer} * */ @Validated @@ -88,8 +88,7 @@ public boolean equals(java.lang.Object o) { return false; } PackageDescription packageDescription = (PackageDescription) o; - return Objects.equals(this.aasIds, packageDescription.aasIds) - && Objects.equals(this.packageId, packageDescription.packageId); + return Objects.equals(this.aasIds, packageDescription.aasIds) && Objects.equals(this.packageId, packageDescription.packageId); } @Override diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java index a6620a266..0e84fbf49 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java @@ -33,119 +33,116 @@ import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; import org.springframework.validation.annotation.Validated; - /** - * Specifies the PackagesBody for {@link AASXFileServer} + * Specifies the PackagesBody for {@link AASXFileServer} * */ @Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2023-06-22T10:58:56.694021713Z[GMT]") -public class PackagesBody { - - private List aasIds = null; - private InputStream file = null; - private String fileName = null; - private String packageId = null; - - public PackagesBody aasIds(List aasIds) { - this.aasIds = aasIds; - return this; - } - - public PackagesBody addAasIdsItem(String aasIdsItem) { - if (this.aasIds == null) { - this.aasIds = new ArrayList(); - } - this.aasIds.add(aasIdsItem); - return this; - } - - public List getAasIds() { - return aasIds; - } - - public void setAasIds(List aasIds) { - this.aasIds = aasIds; - } - - public PackagesBody file(InputStream file) { - this.file = file; - return this; - } - - public InputStream getFile() { - return file; - } - - public void setFile(InputStream file) { - this.file = file; - } - - public PackagesBody fileName(String fileName) { - this.fileName = fileName; - return this; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public PackagesBody packageId(String packageId) { - this.packageId = packageId; - return this; - } - - public String getPackageId() { - return packageId; - } - - public void setPackageId(String packageId) { - this.packageId = packageId; - } - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PackagesBody packagesBody = (PackagesBody) o; - return Objects.equals(this.aasIds, packagesBody.aasIds) && - Objects.equals(this.file, packagesBody.file) && - Objects.equals(this.fileName, packagesBody.fileName); - } - - @Override - public int hashCode() { - return Objects.hash(aasIds, file, fileName); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class PackagesBody {\n"); - - sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); - sb.append(" file: ").append(toIndentedString(file)).append("\n"); - sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(java.lang.Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } +public class PackagesBody { + + private List aasIds = null; + private InputStream file = null; + private String fileName = null; + private String packageId = null; + + public PackagesBody aasIds(List aasIds) { + this.aasIds = aasIds; + return this; + } + + public PackagesBody addAasIdsItem(String aasIdsItem) { + if (this.aasIds == null) { + this.aasIds = new ArrayList(); + } + this.aasIds.add(aasIdsItem); + return this; + } + + public List getAasIds() { + return aasIds; + } + + public void setAasIds(List aasIds) { + this.aasIds = aasIds; + } + + public PackagesBody file(InputStream file) { + this.file = file; + return this; + } + + public InputStream getFile() { + return file; + } + + public void setFile(InputStream file) { + this.file = file; + } + + public PackagesBody fileName(String fileName) { + this.fileName = fileName; + return this; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public PackagesBody packageId(String packageId) { + this.packageId = packageId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PackagesBody packagesBody = (PackagesBody) o; + return Objects.equals(this.aasIds, packagesBody.aasIds) && Objects.equals(this.file, packagesBody.file) && Objects.equals(this.fileName, packagesBody.fileName); + } + + @Override + public int hashCode() { + return Objects.hash(aasIds, file, fileName); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PackagesBody {\n"); + + sb.append(" aasIds: ").append(toIndentedString(aasIds)).append("\n"); + sb.append(" file: ").append(toIndentedString(file)).append("\n"); + sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java index 9cdc9b4d8..b9f412194 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -59,21 +59,21 @@ public void getAllAASXPackageIds() { PackageDescription expectedDescription1 = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_AAS_IDS); PackageDescription expectedDescription2 = DummyAASXFileServerFactory.createDummyPackageDescription("2", DummyAASXFileServerFactory.SECOND_AAS_IDS); - + Collection expectedPackageDescriptions = Arrays.asList(expectedDescription1, expectedDescription2); - + assertGetAllAASXPackageIds(expectedPackageDescriptions, actualPackageDescriptions); } - - @Test + + @Test public void createAASXPackage() { - + AASXFileServer server = getAASXFileServer(); PackageDescription actualPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); - + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_AAS_IDS); - - assertEquals(expectedPackageDescription, actualPackageDescription); + + assertEquals(expectedPackageDescription, actualPackageDescription); } @Test @@ -99,8 +99,7 @@ public void updateExistingAASXByPackageId() throws IOException { PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); - updateAASXPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, - DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); + updateAASXPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); Collection actualPackageDescription = server.getAllAASXPackageIds(); @@ -111,9 +110,9 @@ public void updateExistingAASXByPackageId() throws IOException { public void updateNonExistingAASXByPackageId() { String packageId = "notExisting"; - + AASXFileServer server = getAASXFileServer(); - + updateAASXPackage(server, packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); } @@ -153,26 +152,24 @@ public void deleteNonExistingAASXPackage() { server.deleteAASXByPackageId("nonExisting"); } - private void updateAASXPackage(AASXFileServer server, String packageId, List expectedAasIds, - InputStream file, String filename) { + private void updateAASXPackage(AASXFileServer server, String packageId, List expectedAasIds, InputStream file, String filename) { server.updateAASXByPackageId(packageId, expectedAasIds, file, filename); } private void assertGetAllAASXPackageIds(Collection expectedPackageDescriptions, Collection actualPackageDescriptions) { - assertTrue(expectedPackageDescriptions.containsAll(actualPackageDescriptions)); - assertTrue(actualPackageDescriptions.containsAll(expectedPackageDescriptions)); + assertTrue(expectedPackageDescriptions.containsAll(actualPackageDescriptions)); + assertTrue(actualPackageDescriptions.containsAll(expectedPackageDescriptions)); } - private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, - Collection actualPackageDescriptions, AASXFileServer server) throws IOException { - + private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, Collection actualPackageDescriptions, AASXFileServer server) throws IOException { + assertEquals(1, actualPackageDescriptions.size()); assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); InputStream actualAASXFile = server.getAASXByPackageId("1"); InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; - + assertTrue(IOUtils.contentEquals(expectedAASXFile, actualAASXFile)); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java index 1297eb0fd..59abfd8ff 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java @@ -41,47 +41,41 @@ * */ public class DummyAASXFileServerFactory { - + public static final List FIRST_AAS_IDS = Arrays.asList("AAS_ID_1", "AAS_ID_2"); - public static final String FIRST_FILENAME = "test_file1.txt"; - public static final byte[] FIRST_BYTEARRAY = {65, 66, 67, 68, 69}; - public static final InputStream FIRST_FILE = new ByteArrayInputStream(FIRST_BYTEARRAY); + public static final String FIRST_FILENAME = "test_file1.txt"; + public static final byte[] FIRST_BYTEARRAY = { 65, 66, 67, 68, 69 }; + public static final InputStream FIRST_FILE = new ByteArrayInputStream(FIRST_BYTEARRAY); + + public static final List SECOND_AAS_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); + public static final String SECOND_FILENAME = "test_file2.txt"; + public static final byte[] SECOND_BYTEARRAY = { 75, 76, 77, 78, 79 }; + public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); - public static final List SECOND_AAS_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); - public static final String SECOND_FILENAME = "test_file2.txt"; - public static final byte[] SECOND_BYTEARRAY = {75, 76, 77, 78, 79}; - public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); + public static PackageDescription createFirstDummyAASXPackageOnServer(AASXFileServer server) { + return server.createAASXPackage(FIRST_AAS_IDS, FIRST_FILE, FIRST_FILENAME); + } - public static PackageDescription createFirstDummyAASXPackageOnServer(AASXFileServer server) { - return server.createAASXPackage(FIRST_AAS_IDS, FIRST_FILE, FIRST_FILENAME); - } + public static PackageDescription createSecondDummyAASXPackageOnServer(AASXFileServer server) { + return server.createAASXPackage(SECOND_AAS_IDS, SECOND_FILE, SECOND_FILENAME); + } - public static PackageDescription createSecondDummyAASXPackageOnServer(AASXFileServer server) { - return server.createAASXPackage(SECOND_AAS_IDS, SECOND_FILE, SECOND_FILENAME); - } + public static Collection createMultipleDummyAASXPackagesOnServer(AASXFileServer server) { + PackageDescription firstPackage = createFirstDummyAASXPackageOnServer(server); + PackageDescription secondPackage = createSecondDummyAASXPackageOnServer(server); - public static Collection createMultipleDummyAASXPackagesOnServer(AASXFileServer server) { - PackageDescription firstPackage = createFirstDummyAASXPackageOnServer(server); - PackageDescription secondPackage = createSecondDummyAASXPackageOnServer(server); + ArrayList packages = new ArrayList<>(); + packages.add(firstPackage); + packages.add(secondPackage); - ArrayList packages = new ArrayList<>(); - packages.add(firstPackage); - packages.add(secondPackage); + return packages; + } - return packages; - } - - public static PackageDescription createDummyPackageDescription(String packageId, List aasIds) { + public static PackageDescription createDummyPackageDescription(String packageId, List aasIds) { PackageDescription expectedDescription1 = new PackageDescription(); expectedDescription1.setPackageId(packageId); expectedDescription1.setAasIds(aasIds); - + return expectedDescription1; } } - - - - - - diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml index f9f6d8480..67125d5e5 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java index 9dc60529c..7bedb9331 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java @@ -23,7 +23,6 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ - package org.eclipse.digitaltwin.basyx.aasxfileserver.component; import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; @@ -38,9 +37,8 @@ * @author schnicke, chaithra * */ -@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx", -exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) -public class AASXFileServerComponent { +@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx", exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) +public class AASXFileServerComponent { public static void main(String[] args) { SpringApplication.run(AASXFileServerComponent.class, args); } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java index 9fce53e36..cc1f6bad1 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerConfiguration.java @@ -48,5 +48,5 @@ public class AASXFileServerConfiguration { public static AASXFileServer getAASXFileServer(AASXFileServerFactory aasRepositoryFactory, List features) { return new DecoratedAASXFileServerFactory(aasRepositoryFactory, features).create(); } - + } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties index fe31136ce..fa6177ab7 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties @@ -1,4 +1,4 @@ - server.port=8081 +server.port=8081 spring.application.name=AASX File Server basyx.backend = InMemory diff --git a/basyx.aasxfileserver/pom.xml b/basyx.aasxfileserver/pom.xml index 2cef4d475..685560df8 100644 --- a/basyx.aasxfileserver/pom.xml +++ b/basyx.aasxfileserver/pom.xml @@ -1,5 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 From e4f1934de044b6c782f060402a5e606507b0bce5 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 3 Nov 2023 11:05:29 +0100 Subject: [PATCH 14/15] Uncomment other modules from parent pom Signed-off-by: Mohammad Ghazanfar Ali Danish --- pom.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7b43743eb..ef8775129 100644 --- a/pom.xml +++ b/pom.xml @@ -15,13 +15,13 @@ basyx.common basyx.submodelservice - - - - - - - + basyx.submodelrepository + basyx.submodelregistry + basyx.aasservice + basyx.aasrepository + basyx.aasregistry + basyx.aasenvironment + basyx.conceptdescriptionrepository basyx.aasxfileserver basyx.aasdiscoveryservice From fa5272f263aa9f4e6e4256614e2128d768668af7 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 7 Nov 2023 16:39:42 +0100 Subject: [PATCH 15/15] Resolves review remarks Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../InMemoryAASXFileServer.java | 47 +++++++++++-------- .../basyx/aasxfileserver/AASXFileServer.java | 11 +++-- .../core/AASXFileServerSuite.java | 38 +++++++++++---- .../core/DummyAASXFileServerFactory.java | 12 ++--- .../component/AASXFileServerComponent.java | 2 +- .../AASXFileServerFeaturePrinter.java | 2 +- 6 files changed, 70 insertions(+), 42 deletions(-) diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java index efcdd879d..5da000700 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java @@ -39,7 +39,7 @@ import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; /** - * In-memory implementation of the {@link AASXFileServer} + * In-Memory implementation of the {@link AASXFileServer} * * @author chaithra * @@ -69,8 +69,13 @@ public InMemoryAASXFileServer(String aasxFileServerName) { } @Override - public Collection getAllAASXPackageIds() { - return packageMap.values().stream().map(Package::getPackageDescription).collect(Collectors.toList()); + public Collection getAllAASXPackageIds(String shellId) { + Collection packageDescriptions = packageMap.values().stream().map(Package::getPackageDescription).collect(Collectors.toList()); + + if (shellId == null || shellId.isBlank()) + return packageDescriptions; + + return packageDescriptions.stream().filter(packageDesc -> containsShellId(packageDesc, shellId)).collect(Collectors.toList()); } @Override @@ -81,21 +86,21 @@ public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExi } @Override - public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException { + public void updateAASXByPackageId(String packageId, List shellIds, InputStream file, String filename) throws ElementDoesNotExistException { throwIfAASXPackageIdDoesNotExist(packageId); - updateAASXPackage(packageId, aasIds, file, filename); + updateAASXPackage(packageId, shellIds, file, filename); } @Override - public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName) { + public PackageDescription createAASXPackage(List shellIds, InputStream file, String fileName) { String newpackageId = String.valueOf(packageId.incrementAndGet()); - PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); + PackageDescription packageDescription = createPackageDescription(shellIds, newpackageId); - createPackage(aasIds, file, fileName, newpackageId, packageDescription); + createPackage(shellIds, file, fileName, newpackageId, packageDescription); return packageDescription; } @@ -112,41 +117,41 @@ public String getName() { return aasxFileServerName == null ? AASXFileServer.super.getName() : aasxFileServerName; } - private PackageDescription createPackageDescription(List aasIds, String newPackageId) { + private PackageDescription createPackageDescription(List shellIds, String newPackageId) { PackageDescription packageDescription = new PackageDescription(); packageDescription.packageId(newPackageId); - packageDescription.aasIds(aasIds); + packageDescription.aasIds(shellIds); return packageDescription; } - private PackagesBody createPackagesBody(List aasIds, InputStream file, String fileName) { + private PackagesBody createPackagesBody(List shellIds, InputStream file, String fileName) { PackagesBody packagesBody = new PackagesBody(); - packagesBody.aasIds(aasIds); + packagesBody.aasIds(shellIds); packagesBody.file(file); packagesBody.fileName(fileName); return packagesBody; } - private void createPackage(List aasIds, InputStream file, String fileName, String newPackageId, PackageDescription packageDescription) { - PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); + private void createPackage(List shellIds, InputStream file, String fileName, String newPackageId, PackageDescription packageDescription) { + PackagesBody packagesBody = createPackagesBody(shellIds, file, fileName); Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); packageMap.put(newPackageId, aasxPackage); } - private void updateAASXPackage(String packageId, List aasIds, InputStream file, String filename) { + private void updateAASXPackage(String packageId, List shellIds, InputStream file, String filename) { Package aasxPackage = this.packageMap.get(packageId); - updatePackagesBody(aasIds, file, filename, aasxPackage.getPackagesBody()); + updatePackagesBody(shellIds, file, filename, aasxPackage.getPackagesBody()); - aasxPackage.getPackageDescription().setAasIds(aasIds); + aasxPackage.getPackageDescription().setAasIds(shellIds); } - private void updatePackagesBody(List aasIds, InputStream file, String filename, PackagesBody packagesBody) { - packagesBody.setAasIds(aasIds); + private void updatePackagesBody(List shellIds, InputStream file, String filename, PackagesBody packagesBody) { + packagesBody.setAasIds(shellIds); packagesBody.setFileName(filename); packagesBody.setFile(file); } @@ -156,5 +161,9 @@ private void throwIfAASXPackageIdDoesNotExist(String id) { if (!packageMap.containsKey(id)) throw new ElementDoesNotExistException(id); } + + private boolean containsShellId(PackageDescription packageDesc, String shellId) { + return packageDesc.getAasIds().stream().anyMatch(aasId -> aasId.equals(shellId)); + } } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java index 6bc77f4a6..c4ed5fecc 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java @@ -44,9 +44,10 @@ public interface AASXFileServer { /** * Retrieves all AASX package ids from the repository * + * @param shellId * @return a list of available AASX Package Descriptions at the server */ - public Collection getAllAASXPackageIds(); + public Collection getAllAASXPackageIds(String shellId); /** * Retrieves a specific AASX package from the server @@ -61,22 +62,22 @@ public interface AASXFileServer { * Updates an existing AASX package at the server * * @param packageId - * @param aasIds + * @param shellIds * @param file * @param filename * @throws ElementDoesNotExistException */ - public void updateAASXByPackageId(String packageId, List aasIds, InputStream file, String filename) throws ElementDoesNotExistException; + public void updateAASXByPackageId(String packageId, List shellIds, InputStream file, String filename) throws ElementDoesNotExistException; /** * Creates a new AASX Package * - * @param aasIds + * @param shellIds * @param file * @param filename * @throws CollidingIdentifierException */ - public PackageDescription createAASXPackage(List aasIds, InputStream file, String fileName); + public PackageDescription createAASXPackage(List shellIds, InputStream file, String fileName); /** * Deletes a AASX Package diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java index b9f412194..6629bd01a 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -55,12 +55,29 @@ public abstract class AASXFileServerSuite { public void getAllAASXPackageIds() { AASXFileServer server = getAASXFileServer(); - Collection actualPackageDescriptions = DummyAASXFileServerFactory.createMultipleDummyAASXPackagesOnServer(server); + DummyAASXFileServerFactory.createMultipleDummyAASXPackagesOnServer(server); - PackageDescription expectedDescription1 = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_AAS_IDS); - PackageDescription expectedDescription2 = DummyAASXFileServerFactory.createDummyPackageDescription("2", DummyAASXFileServerFactory.SECOND_AAS_IDS); + PackageDescription expectedDescription1 = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_SHELL_IDS); + PackageDescription expectedDescription2 = DummyAASXFileServerFactory.createDummyPackageDescription("2", DummyAASXFileServerFactory.SECOND_SHELL_IDS); Collection expectedPackageDescriptions = Arrays.asList(expectedDescription1, expectedDescription2); + + Collection actualPackageDescriptions = server.getAllAASXPackageIds(""); + + assertGetAllAASXPackageIds(expectedPackageDescriptions, actualPackageDescriptions); + } + + @Test + public void getAllAASXPackageIdsByShellId() { + + AASXFileServer server = getAASXFileServer(); + DummyAASXFileServerFactory.createMultipleDummyAASXPackagesOnServer(server); + + PackageDescription expectedDescription = DummyAASXFileServerFactory.createDummyPackageDescription("2", DummyAASXFileServerFactory.SECOND_SHELL_IDS); + + Collection expectedPackageDescriptions = Arrays.asList(expectedDescription); + + Collection actualPackageDescriptions = server.getAllAASXPackageIds("AAS_ID_3"); assertGetAllAASXPackageIds(expectedPackageDescriptions, actualPackageDescriptions); } @@ -71,16 +88,17 @@ public void createAASXPackage() { AASXFileServer server = getAASXFileServer(); PackageDescription actualPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); - PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_AAS_IDS); + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createDummyPackageDescription("1", DummyAASXFileServerFactory.FIRST_SHELL_IDS); assertEquals(expectedPackageDescription, actualPackageDescription); } @Test public void getAllAASXPackageIdsEmpty() { + String shellId = "testShellId"; AASXFileServer server = getAASXFileServer(); - Collection packageDescriptions = server.getAllAASXPackageIds(); + Collection packageDescriptions = server.getAllAASXPackageIds(shellId); assertTrue(packageDescriptions.isEmpty()); } @@ -99,9 +117,9 @@ public void updateExistingAASXByPackageId() throws IOException { PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); - updateAASXPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); + updateAASXPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_SHELL_IDS, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); - Collection actualPackageDescription = server.getAllAASXPackageIds(); + Collection actualPackageDescription = server.getAllAASXPackageIds(""); assertUpdatedAASXPackageId(expectedPackageDescription, actualPackageDescription, server); } @@ -113,7 +131,7 @@ public void updateNonExistingAASXByPackageId() { AASXFileServer server = getAASXFileServer(); - updateAASXPackage(server, packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); + updateAASXPackage(server, packageId, DummyAASXFileServerFactory.FIRST_SHELL_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); } @Test @@ -152,9 +170,9 @@ public void deleteNonExistingAASXPackage() { server.deleteAASXByPackageId("nonExisting"); } - private void updateAASXPackage(AASXFileServer server, String packageId, List expectedAasIds, InputStream file, String filename) { + private void updateAASXPackage(AASXFileServer server, String packageId, List expectedShellIds, InputStream file, String filename) { - server.updateAASXByPackageId(packageId, expectedAasIds, file, filename); + server.updateAASXByPackageId(packageId, expectedShellIds, file, filename); } private void assertGetAllAASXPackageIds(Collection expectedPackageDescriptions, Collection actualPackageDescriptions) { diff --git a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java index 59abfd8ff..9c9bb56fc 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java @@ -42,22 +42,22 @@ */ public class DummyAASXFileServerFactory { - public static final List FIRST_AAS_IDS = Arrays.asList("AAS_ID_1", "AAS_ID_2"); + public static final List FIRST_SHELL_IDS = Arrays.asList("AAS_ID_1", "AAS_ID_2"); public static final String FIRST_FILENAME = "test_file1.txt"; public static final byte[] FIRST_BYTEARRAY = { 65, 66, 67, 68, 69 }; public static final InputStream FIRST_FILE = new ByteArrayInputStream(FIRST_BYTEARRAY); - public static final List SECOND_AAS_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); + public static final List SECOND_SHELL_IDS = Arrays.asList("AAS_ID_3", "AAS_ID_4"); public static final String SECOND_FILENAME = "test_file2.txt"; public static final byte[] SECOND_BYTEARRAY = { 75, 76, 77, 78, 79 }; public static final InputStream SECOND_FILE = new ByteArrayInputStream(SECOND_BYTEARRAY); public static PackageDescription createFirstDummyAASXPackageOnServer(AASXFileServer server) { - return server.createAASXPackage(FIRST_AAS_IDS, FIRST_FILE, FIRST_FILENAME); + return server.createAASXPackage(FIRST_SHELL_IDS, FIRST_FILE, FIRST_FILENAME); } public static PackageDescription createSecondDummyAASXPackageOnServer(AASXFileServer server) { - return server.createAASXPackage(SECOND_AAS_IDS, SECOND_FILE, SECOND_FILENAME); + return server.createAASXPackage(SECOND_SHELL_IDS, SECOND_FILE, SECOND_FILENAME); } public static Collection createMultipleDummyAASXPackagesOnServer(AASXFileServer server) { @@ -71,10 +71,10 @@ public static Collection createMultipleDummyAASXPackagesOnSe return packages; } - public static PackageDescription createDummyPackageDescription(String packageId, List aasIds) { + public static PackageDescription createDummyPackageDescription(String packageId, List shellIds) { PackageDescription expectedDescription1 = new PackageDescription(); expectedDescription1.setPackageId(packageId); - expectedDescription1.setAasIds(aasIds); + expectedDescription1.setAasIds(shellIds); return expectedDescription1; } diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java index 7bedb9331..25839b069 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java @@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; /** - * Creates and starts the {@link AASXFileServer} off-shelf-component + * Creates and starts the {@link AASXFileServer} off-the-shelf-component * * @author schnicke, chaithra * diff --git a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java index 8fd0cf983..4b4a1535c 100644 --- a/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerFeaturePrinter.java @@ -47,7 +47,7 @@ public class AASXFileServerFeaturePrinter { public AASXFileServerFeaturePrinter(List features) { logger.info("-------------------- AASX File Server Features: --------------------"); for (AASXFileServerFeature feature : features) { - logger.info("BaSyxFeature " + feature.getName() + " is enabled: " + feature.isEnabled()); + logger.info("BaSyxFeature '{}' is enabled: {}", feature.getName(), feature.isEnabled()); } logger.info("----------------------------------------------------------------- ");