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..c9bdfac13 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml @@ -0,0 +1,40 @@ + + 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 + + + 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 new file mode 100644 index 000000000..5da000700 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * 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.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 {@link AASXFileServer} + * + * @author chaithra + * + */ +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(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 + public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException { + throwIfAASXPackageIdDoesNotExist(packageId); + + return packageMap.get(packageId).getPackagesBody().getFile(); + } + + @Override + public void updateAASXByPackageId(String packageId, List shellIds, InputStream file, String filename) throws ElementDoesNotExistException { + + throwIfAASXPackageIdDoesNotExist(packageId); + + updateAASXPackage(packageId, shellIds, file, filename); + } + + @Override + public PackageDescription createAASXPackage(List shellIds, InputStream file, String fileName) { + + String newpackageId = String.valueOf(packageId.incrementAndGet()); + + PackageDescription packageDescription = createPackageDescription(shellIds, newpackageId); + + createPackage(shellIds, 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 shellIds, String newPackageId) { + PackageDescription packageDescription = new PackageDescription(); + packageDescription.packageId(newPackageId); + packageDescription.aasIds(shellIds); + + return packageDescription; + } + + private PackagesBody createPackagesBody(List shellIds, InputStream file, String fileName) { + PackagesBody packagesBody = new PackagesBody(); + packagesBody.aasIds(shellIds); + packagesBody.file(file); + packagesBody.fileName(fileName); + + return packagesBody; + } + + 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 shellIds, InputStream file, String filename) { + Package aasxPackage = this.packageMap.get(packageId); + + updatePackagesBody(shellIds, file, filename, aasxPackage.getPackagesBody()); + + aasxPackage.getPackageDescription().setAasIds(shellIds); + } + + private void updatePackagesBody(List shellIds, InputStream file, String filename, PackagesBody packagesBody) { + packagesBody.setAasIds(shellIds); + packagesBody.setFileName(filename); + packagesBody.setFile(file); + } + + 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-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..e30b85aef --- /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 {@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 new file mode 100644 index 000000000..7776fe394 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.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; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.core.AASXFileServerSuite; +import org.junit.Test; + +/** + * Tests the {@link InMemoryAASXFileServer} + * + * @author chaithra + * + */ +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/pom.xml b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml new file mode 100644 index 000000000..d837cd436 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/pom.xml @@ -0,0 +1,34 @@ + + 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 + + + + commons-io + commons-io + test + + + + + \ 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..c4ed5fecc --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServer.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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.aasxfileserver.model.PackageDescription; +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; + +/** + * Specifies the overall {@link AASXFileServer} API + * + * @author chaithra + * + */ +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(String shellId); + + /** + * 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 shellIds + * @param file + * @param filename + * @throws ElementDoesNotExistException + */ + public void updateAASXByPackageId(String packageId, List shellIds, InputStream file, String filename) throws ElementDoesNotExistException; + + /** + * Creates a new AASX Package + * + * @param shellIds + * @param file + * @param filename + * @throws CollidingIdentifierException + */ + public PackageDescription createAASXPackage(List shellIds, InputStream file, String fileName); + + /** + * 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 new file mode 100644 index 000000000..d4c848c73 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/AASXFileServerFactory.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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 @link{ AASXFileServer} + * + * @return + */ + 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 new file mode 100644 index 000000000..005a8d903 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/feature/AASXFileServerFeature.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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 AASX File Server + * + * @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..8409316fe --- /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/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 new file mode 100644 index 000000000..eb7ceedd2 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/Package.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.model; + +import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; + +/** + * Specifies the Package for {@link AASXFileServer} + * + * @author chaithra + * + */ +public class Package { + + 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; + } + + 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/model/PackageDescription.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java new file mode 100644 index 000000000..a42093974 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackageDescription.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * 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.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 {@link 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/model/PackagesBody.java b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java new file mode 100644 index 000000000..0e84fbf49 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/model/PackagesBody.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * 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.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 {@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 "); + } +} 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..6629bd01a --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/AASXFileServerSuite.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * 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.IOException; +import java.io.InputStream; +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.model.PackageDescription; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.junit.Test; + +/** + * Testsuite for implementations of the {@link AASXFileServer} interface + * + * @author chaithra + * + */ +public abstract class AASXFileServerSuite { + + protected abstract AASXFileServer getAASXFileServer(); + + @Test + public void getAllAASXPackageIds() { + + AASXFileServer server = getAASXFileServer(); + DummyAASXFileServerFactory.createMultipleDummyAASXPackagesOnServer(server); + + 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); + } + + @Test + public void createAASXPackage() { + + AASXFileServer server = getAASXFileServer(); + PackageDescription actualPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); + + 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(shellId); + + assertTrue(packageDescriptions.isEmpty()); + } + + @Test(expected = ElementDoesNotExistException.class) + public void getSpecificNonExistingPackageId() { + + AASXFileServer server = getAASXFileServer(); + server.getAASXByPackageId("doesNotExist"); + } + + @Test + public void updateExistingAASXByPackageId() throws IOException { + + AASXFileServer server = getAASXFileServer(); + + PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(server); + + updateAASXPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_SHELL_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"; + + AASXFileServer server = getAASXFileServer(); + + updateAASXPackage(server, packageId, DummyAASXFileServerFactory.FIRST_SHELL_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); + } + + @Test + public void getAASXByPackageId() throws ElementDoesNotExistException, IOException { + + AASXFileServer server = getAASXFileServer(); + + PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackageOnServer(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.createFirstDummyAASXPackageOnServer(server); + + server.deleteAASXByPackageId(packageDescription.getPackageId()); + + try { + server.getAASXByPackageId(packageDescription.getPackageId()); + fail(); + } catch (ElementDoesNotExistException expected) { + } + } + + @Test(expected = ElementDoesNotExistException.class) + public void deleteNonExistingAASXPackage() { + + AASXFileServer server = getAASXFileServer(); + server.deleteAASXByPackageId("nonExisting"); + } + + private void updateAASXPackage(AASXFileServer server, String packageId, List expectedShellIds, InputStream file, String filename) { + + server.updateAASXByPackageId(packageId, expectedShellIds, file, filename); + } + + private void assertGetAllAASXPackageIds(Collection expectedPackageDescriptions, Collection actualPackageDescriptions) { + assertTrue(expectedPackageDescriptions.containsAll(actualPackageDescriptions)); + assertTrue(actualPackageDescriptions.containsAll(expectedPackageDescriptions)); + } + + 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 new file mode 100644 index 000000000..9c9bb56fc --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver-core/src/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/core/DummyAASXFileServerFactory.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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.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.model.PackageDescription; + +/** + * Factory for creating AASX Packages for tests + * + * @author chaithra + * + */ +public class DummyAASXFileServerFactory { + + 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_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_SHELL_IDS, FIRST_FILE, FIRST_FILENAME); + } + + public static PackageDescription createSecondDummyAASXPackageOnServer(AASXFileServer server) { + return server.createAASXPackage(SECOND_SHELL_IDS, SECOND_FILE, SECOND_FILENAME); + } + + public static Collection createMultipleDummyAASXPackagesOnServer(AASXFileServer server) { + PackageDescription firstPackage = createFirstDummyAASXPackageOnServer(server); + PackageDescription secondPackage = createSecondDummyAASXPackageOnServer(server); + + ArrayList packages = new ArrayList<>(); + packages.add(firstPackage); + packages.add(secondPackage); + + return packages; + } + + public static PackageDescription createDummyPackageDescription(String packageId, List shellIds) { + PackageDescription expectedDescription1 = new PackageDescription(); + expectedDescription1.setPackageId(packageId); + expectedDescription1.setAasIds(shellIds); + + return expectedDescription1; + } +} 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..67125d5e5 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/pom.xml @@ -0,0 +1,58 @@ + + 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..25839b069 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/component/AASXFileServerComponent.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.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-the-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..cc1f6bad1 --- /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..4b4a1535c --- /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 '{}' is enabled: {}", feature.getName(), feature.isEnabled()); + } + + logger.info("----------------------------------------------------------------- "); + } +} 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..fa6177ab7 --- /dev/null +++ b/basyx.aasxfileserver/basyx.aasxfileserver.component/src/main/resources/application.properties @@ -0,0 +1,68 @@ +server.port=8081 +spring.application.name=AASX File Server + +basyx.backend = InMemory + +#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=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= +# +#################################################################################### + 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..685560df8 --- /dev/null +++ b/basyx.aasxfileserver/pom.xml @@ -0,0 +1,21 @@ + + 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 e1ffe745f..ef8775129 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ basyx.aasregistry basyx.aasenvironment basyx.conceptdescriptionrepository + basyx.aasxfileserver basyx.aasdiscoveryservice BaSyx Parent @@ -440,8 +441,7 @@ org.eclipse.digitaltwin.basyx basyx.conceptdescriptionrepository.component ${revision} - - + org.eclipse.digitaltwin.basyx @@ -473,6 +473,22 @@ basyx.aasdiscoveryservice.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} + @@ -679,7 +695,7 @@ basyx.conceptdescriptionrepository.component ${revision} tests - + org.eclipse.digitaltwin.basyx @@ -717,6 +733,25 @@ ${revision} tests + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-core + ${revision} + tests + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver-backend-inmemory + ${revision} + tests + + + org.eclipse.digitaltwin.basyx + basyx.aasxfileserver.component + ${revision} + tests +