From 1443f5493e6ea4f8da02849b207e6335af0a45f0 Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Thu, 18 Jan 2024 10:56:32 +0100 Subject: [PATCH 1/4] Fix MongoDB Backend incorrectly saving files from loaded AASX --- .../components/aas/AASServerComponent.java | 36 +++--- .../aas/internal/StorageSubmodelAPI.java | 3 +- .../AASServer/TestAASXMongoDBAASServer.java | 105 ++++++++++++++++++ 3 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java index 7c8d78c4..188f300b 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java @@ -251,22 +251,12 @@ public void startComponent() { loadAASServerFeaturesFromConfig(); initializeAASServerFeatures(); - BaSyxContext context = contextConfig.createBaSyxContext(); - context.addServletMapping("/*", createAggregatorServlet()); - addAASServerFeaturesToContext(context); - - // An initial AAS has been loaded from the drive? - if (aasBundles != null) { - createBasyxResourceDirectoryIfNotExists(); - - addAasxFilesResourceServlet(context); - // 2. Fix the file paths according to the servlet configuration - modifyFilePaths(contextConfig.getHostname(), contextConfig.getPort(), getRootFilePathWithContext(contextConfig.getContextPath())); + initializeAasBundles(context); - registerWhitelistedSubmodels(); - } + context.addServletMapping("/*", createAggregatorServlet()); + addAASServerFeaturesToContext(context); logger.info("Start the server"); server = new BaSyxHTTPServer(context); @@ -523,6 +513,24 @@ private void initializeAASServerFeatures() { } } + private void initializeAasBundles(BaSyxContext context) { + loadAASBundles(); + + if (aasBundles == null) + return; + + logger.info("Initializing AAS Bundles"); + + createBasyxResourceDirectoryIfNotExists(); + + addAasxFilesResourceServlet(context); + + // 2. Fix the file paths according to the servlet configuration + modifyFilePaths(contextConfig.getHostname(), contextConfig.getPort(), getRootFilePathWithContext(contextConfig.getContextPath())); + + registerWhitelistedSubmodels(); + } + private void cleanUpAASServerFeatures() { for (IAASServerFeature aasServerFeature : aasServerFeatureList) { aasServerFeature.cleanUp(); @@ -585,7 +593,6 @@ private Collection getFlatAASBundles() { private VABHTTPInterface createAggregatorServlet() { aggregator = createAASAggregator(); - loadAASBundles(); if (aasBundles != null) { try (final var ignored = ElevatedCodeAuthentication.enterElevatedCodeAuthenticationArea()) { @@ -844,5 +851,6 @@ private void createBasyxResourceDirectoryIfNotExists() { directory.mkdir(); } + } diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/internal/StorageSubmodelAPI.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/internal/StorageSubmodelAPI.java index 0df5f9f8..2df887c1 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/internal/StorageSubmodelAPI.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/internal/StorageSubmodelAPI.java @@ -205,8 +205,7 @@ public java.io.File getSubmodelElementFile(String idShortPath) { public void uploadSubmodelElementFile(String idShortPath, InputStream fileStream) { VABSubmodelAPI api = new VABSubmodelAPI(new VABLambdaProvider(getSubmodel())); ISubmodelElement element = api.getSubmodelElement(idShortPath); - String fileName = storageApi.writeFile(idShortPath, getSubmodel().getIdentification().getId(), fileStream, element); - updateSubmodelElement(idShortPath, fileName); + storageApi.writeFile(idShortPath, getSubmodel().getIdentification().getId(), fileStream, element); } } diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java new file mode 100644 index 00000000..658d7e15 --- /dev/null +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (C) 2021 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.basyx.regression.AASServer; + +import java.net.URLEncoder; +import java.nio.file.Paths; + +import org.apache.commons.io.FileUtils; +import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider; +import org.eclipse.basyx.aas.factory.aasx.AASXToMetamodelConverter; +import org.eclipse.basyx.components.aas.AASServerComponent; +import org.eclipse.basyx.components.aas.configuration.AASServerBackend; +import org.eclipse.basyx.components.aas.configuration.BaSyxAASServerConfiguration; +import org.eclipse.basyx.components.aas.mongodb.MongoDBAASAggregator; +import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration; +import org.eclipse.basyx.components.configuration.BaSyxMongoDBConfiguration; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test accessing to AAS using basys aas SDK + * + * @author mateusmolina + * + */ +public class TestAASXMongoDBAASServer extends AASXSuite { + private static Logger logger = LoggerFactory.getLogger(TestAASXMongoDBAASServer.class); + private static AASServerComponent component; + private static BaSyxMongoDBConfiguration basyxMongoDBConfig = buildBaSyxMongoDBConfiguration(); + + @BeforeClass + public static void setUpClass() throws Exception { + // Setup component's test configuration + BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(); + contextConfig.loadFromResource(BaSyxContextConfiguration.DEFAULT_CONFIG_PATH); + BaSyxAASServerConfiguration aasConfig = new BaSyxAASServerConfiguration(AASServerBackend.MONGODB, "[\"aasx/01_Festo.aasx\", \"aasx/a.aasx\", \"aasx/b.aasx\"]"); + + String docBasepath = Paths.get(FileUtils.getTempDirectory().getAbsolutePath(), AASXToMetamodelConverter.TEMP_DIRECTORY).toAbsolutePath().toString(); + contextConfig.setDocBasePath(docBasepath); + + resetMongoDBTestData(); + + // Start the component + component = new AASServerComponent(contextConfig, aasConfig, basyxMongoDBConfig); + component.startComponent(); + + rootEndpoint = contextConfig.getUrl() + "/"; + aasEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + aasId.getEncodedURN() + "/aas"; + smEndpoint = aasEndpoint + "/submodels/" + smIdShort + "/submodel"; + String encodedAasAId = URLEncoder.encode(aasAId.getId(), "UTF-8"); + aasAEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + encodedAasAId + "/aas"; + smAEndpoint = aasAEndpoint + "/submodels/" + smAIdShort + "/submodel"; + String encodedAasBId = URLEncoder.encode(aasBId.getId(), "UTF-8"); + aasBEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + encodedAasBId + "/aas"; + smBEndpoint = aasBEndpoint + "/submodels/" + smBIdShort + "/submodel"; + logger.info("AAS URL for servlet test: " + aasEndpoint); + } + + @AfterClass + public static void tearDownClass() { + component.stopComponent(); + } + + // TODO + @Override + public void testCollidingFiles() throws Exception { + } + + @SuppressWarnings("deprecation") + private static void resetMongoDBTestData() { + new MongoDBAASAggregator(basyxMongoDBConfig).reset(); + } + + private static BaSyxMongoDBConfiguration buildBaSyxMongoDBConfiguration() { + BaSyxMongoDBConfiguration mongoDBConfig = new BaSyxMongoDBConfiguration(); + mongoDBConfig.setAASCollection("TestAASXMongoDBAASServer_AAS"); + mongoDBConfig.setSubmodelCollection("TestAASXMongoDBAASServer_SM"); + return mongoDBConfig; + } + +} From 6f053ac17008bcd3169e98bec6a12e5d7599a304 Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Thu, 18 Jan 2024 11:56:03 +0100 Subject: [PATCH 2/4] Refactor endpoint construction to use VABPathTools --- .../basyx/regression/AASServer/AASXSuite.java | 34 +++++++++++++++---- .../AASServer/TestAASXAASServer.java | 16 +-------- .../AASServer/TestAASXMongoDBAASServer.java | 16 +-------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java index ef9d88c4..462007e3 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java @@ -36,6 +36,7 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; +import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider; import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager; import org.eclipse.basyx.aas.metamodel.connected.ConnectedAssetAdministrationShell; import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor; @@ -44,12 +45,14 @@ import org.eclipse.basyx.aas.metamodel.map.descriptor.SubmodelDescriptor; import org.eclipse.basyx.aas.registration.api.IAASRegistry; import org.eclipse.basyx.aas.registration.memory.InMemoryRegistry; +import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration; import org.eclipse.basyx.submodel.metamodel.api.ISubmodel; import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement; import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElementCollection; import org.eclipse.basyx.submodel.metamodel.api.submodelelement.dataelement.IFile; import org.eclipse.basyx.submodel.metamodel.connected.submodelelement.ConnectedSubmodelElementCollection; import org.eclipse.basyx.submodel.metamodel.connected.submodelelement.dataelement.ConnectedFile; +import org.eclipse.basyx.vab.modelprovider.VABPathTools; import org.eclipse.basyx.vab.protocol.api.IConnectorFactory; import org.eclipse.basyx.vab.protocol.http.connector.HTTPConnectorFactory; import org.glassfish.jersey.client.JerseyClientBuilder; @@ -86,6 +89,7 @@ public abstract class AASXSuite { protected static final String fileShortIdPath = "file"; // Has to be individualized by each test inheriting from this suite + // Default configuration is provided by buildEnpoints method protected static String aasEndpoint; protected static String smEndpoint; protected static String aasAEndpoint; @@ -137,9 +141,8 @@ public void testGetSingleSubmodel() throws Exception { @Test public void testGetSingleModule() throws Exception { - final String FILE_ENDING = "basyx-temp/aasx0/files/aasx/Nameplate/marking_rcm.jpg"; - final String FILE_PATH = rootEndpoint + "basyx-temp/aasx0/files/aasx/Nameplate/marking_rcm.jpg"; - checkFile(FILE_PATH); + final String FILE_ENDING = VABPathTools.buildPath(new String[] { "basyx-temp", "aasx0", "files", "aasx", "Nameplate", "marking_rcm.jpg" }, 0); + checkFile(VABPathTools.concatenatePaths(rootEndpoint, FILE_ENDING)); // Get the submdoel nameplate ISubmodel nameplate = manager.retrieveSubmodel(aasId, smId); @@ -163,11 +166,11 @@ public void testGetSingleModule() throws Exception { @Test public void testCollidingFiles() throws Exception { - final String FILE_ENDING_A = "basyx-temp/aasx1/files/aasx/files/text.txt"; - final String FILE_ENDING_B = "basyx-temp/aasx2/files/aasx/files/text.txt"; + final String FILE_ENDING_A = VABPathTools.buildPath(new String[] { "basyx-temp", "aasx1", "files", "aasx", "files", "text.txt" }, 0); + final String FILE_ENDING_B = VABPathTools.buildPath(new String[] { "basyx-temp", "aasx2", "files", "aasx", "files", "text.txt" }, 0); - checkFile(rootEndpoint + FILE_ENDING_A); - checkFile(rootEndpoint + FILE_ENDING_B); + checkFile(VABPathTools.concatenatePaths(rootEndpoint, FILE_ENDING_A)); + checkFile(VABPathTools.concatenatePaths(rootEndpoint, FILE_ENDING_B)); ISubmodel smA = manager.retrieveSubmodel(aasAId, smAId); ISubmodel smB = manager.retrieveSubmodel(aasBId, smBId); @@ -194,6 +197,23 @@ public void testAllFiles() throws Exception { } + protected static void buildEndpoints(BaSyxContextConfiguration contextConfig) { + rootEndpoint = VABPathTools.stripSlashes(contextConfig.getUrl()); + + aasEndpoint = VABPathTools.concatenatePaths(rootEndpoint, AASAggregatorProvider.PREFIX, aasId.getEncodedURN(), "aas"); + smEndpoint = VABPathTools.concatenatePaths(aasEndpoint, "submodels", smIdShort, "submodel"); + + String encodedAasAId = VABPathTools.encodePathElement(aasAId.getId()); + aasAEndpoint = VABPathTools.concatenatePaths(rootEndpoint, AASAggregatorProvider.PREFIX, encodedAasAId, "aas"); + smAEndpoint = VABPathTools.concatenatePaths(aasAEndpoint, "submodels", smAIdShort, "submodel"); + + String encodedAasBId = VABPathTools.encodePathElement(aasBId.getId()); + aasBEndpoint = VABPathTools.concatenatePaths(rootEndpoint, AASAggregatorProvider.PREFIX, encodedAasBId, "aas"); + smBEndpoint = VABPathTools.concatenatePaths(aasBEndpoint, "submodels", smBIdShort, "submodel"); + + logger.info("AAS URL for servlet test: " + aasEndpoint); + } + private void checkElementCollectionFiles(Collection elements) { for (ISubmodelElement element : elements) { if (element instanceof IFile) { diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXAASServer.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXAASServer.java index cd8e3473..477e8403 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXAASServer.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXAASServer.java @@ -26,14 +26,12 @@ import java.io.IOException; import java.net.URISyntaxException; -import java.net.URLEncoder; import java.nio.file.Paths; import javax.servlet.ServletException; import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.io.FileUtils; -import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider; import org.eclipse.basyx.aas.factory.aasx.AASXToMetamodelConverter; import org.eclipse.basyx.components.aas.AASServerComponent; import org.eclipse.basyx.components.aas.configuration.AASServerBackend; @@ -41,8 +39,6 @@ import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; /** @@ -52,7 +48,6 @@ * */ public class TestAASXAASServer extends AASXSuite { - private static Logger logger = LoggerFactory.getLogger(TestAASXAASServer.class); private static AASServerComponent component; @BeforeClass @@ -69,16 +64,7 @@ public static void setUpClass() throws ParserConfigurationException, SAXExceptio component = new AASServerComponent(contextConfig, aasConfig); component.startComponent(); - rootEndpoint = contextConfig.getUrl() + "/"; - aasEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + aasId.getEncodedURN() + "/aas"; - smEndpoint = aasEndpoint + "/submodels/" + smIdShort + "/submodel"; - String encodedAasAId = URLEncoder.encode(aasAId.getId(), "UTF-8"); - aasAEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + encodedAasAId + "/aas"; - smAEndpoint = aasAEndpoint + "/submodels/" + smAIdShort + "/submodel"; - String encodedAasBId = URLEncoder.encode(aasBId.getId(), "UTF-8"); - aasBEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + encodedAasBId + "/aas"; - smBEndpoint = aasBEndpoint + "/submodels/" + smBIdShort + "/submodel"; - logger.info("AAS URL for servlet test: " + aasEndpoint); + buildEndpoints(contextConfig); } @AfterClass diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java index 658d7e15..3880a952 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java @@ -24,11 +24,9 @@ ******************************************************************************/ package org.eclipse.basyx.regression.AASServer; -import java.net.URLEncoder; import java.nio.file.Paths; import org.apache.commons.io.FileUtils; -import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider; import org.eclipse.basyx.aas.factory.aasx.AASXToMetamodelConverter; import org.eclipse.basyx.components.aas.AASServerComponent; import org.eclipse.basyx.components.aas.configuration.AASServerBackend; @@ -38,8 +36,6 @@ import org.eclipse.basyx.components.configuration.BaSyxMongoDBConfiguration; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Test accessing to AAS using basys aas SDK @@ -48,7 +44,6 @@ * */ public class TestAASXMongoDBAASServer extends AASXSuite { - private static Logger logger = LoggerFactory.getLogger(TestAASXMongoDBAASServer.class); private static AASServerComponent component; private static BaSyxMongoDBConfiguration basyxMongoDBConfig = buildBaSyxMongoDBConfiguration(); @@ -68,16 +63,7 @@ public static void setUpClass() throws Exception { component = new AASServerComponent(contextConfig, aasConfig, basyxMongoDBConfig); component.startComponent(); - rootEndpoint = contextConfig.getUrl() + "/"; - aasEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + aasId.getEncodedURN() + "/aas"; - smEndpoint = aasEndpoint + "/submodels/" + smIdShort + "/submodel"; - String encodedAasAId = URLEncoder.encode(aasAId.getId(), "UTF-8"); - aasAEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + encodedAasAId + "/aas"; - smAEndpoint = aasAEndpoint + "/submodels/" + smAIdShort + "/submodel"; - String encodedAasBId = URLEncoder.encode(aasBId.getId(), "UTF-8"); - aasBEndpoint = rootEndpoint + "/" + AASAggregatorProvider.PREFIX + "/" + encodedAasBId + "/aas"; - smBEndpoint = aasBEndpoint + "/submodels/" + smBIdShort + "/submodel"; - logger.info("AAS URL for servlet test: " + aasEndpoint); + buildEndpoints(contextConfig); } @AfterClass From bc10b465600610249136ccccd0a172bd11d5929e Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Fri, 19 Jan 2024 11:03:19 +0100 Subject: [PATCH 3/4] Fix FileValueAdaptingFeature not working for MongoDBSubmodelApi --- .../mongodb/MongoDBSubmodelAggregator.java | 5 +- .../basyx/regression/AASServer/AASXSuite.java | 93 +++++++++++++++--- .../src/test/resources/BaSyx.png | Bin 0 -> 11192 bytes 3 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/resources/BaSyx.png diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mongodb/MongoDBSubmodelAggregator.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mongodb/MongoDBSubmodelAggregator.java index d92a5913..140c8d06 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mongodb/MongoDBSubmodelAggregator.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mongodb/MongoDBSubmodelAggregator.java @@ -42,7 +42,6 @@ import org.eclipse.basyx.submodel.metamodel.map.Submodel; import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPI; import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPIFactory; -import org.eclipse.basyx.submodel.restapi.vab.VABSubmodelAPIFactory; import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException; import com.mongodb.client.MongoClient; @@ -159,12 +158,12 @@ public ISubmodel getSubmodelbyIdShort(String idShort) throws ResourceNotFoundExc @Override public ISubmodelAPI getSubmodelAPIById(IIdentifier identifier) throws ResourceNotFoundException { Submodel submodel = (Submodel) getSubmodel(identifier); - return new VABSubmodelAPIFactory().create(submodel); + return submodelApiFactory.create(submodel); } @Override public ISubmodelAPI getSubmodelAPIByIdShort(String idShort) throws ResourceNotFoundException { Submodel submodel = (Submodel) getSubmodelbyIdShort(idShort); - return new VABSubmodelAPIFactory().create(submodel); + return submodelApiFactory.create(submodel); } } diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java index 462007e3..bb9dc216 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java @@ -25,8 +25,13 @@ package org.eclipse.basyx.regression.AASServer; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -36,6 +41,13 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider; import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager; import org.eclipse.basyx.aas.metamodel.connected.ConnectedAssetAdministrationShell; @@ -60,6 +72,7 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; /** * Suite for testing that the XMLAAS servlet is set up correctly. The tests here @@ -148,22 +161,12 @@ public void testGetSingleModule() throws Exception { ISubmodel nameplate = manager.retrieveSubmodel(aasId, smId); // Get the submodel element collection marking_rcm ConnectedSubmodelElementCollection marking_rcm = (ConnectedSubmodelElementCollection) nameplate.getSubmodelElements().get("Marking_RCM"); - Collection values = marking_rcm.getValue(); - // navigate to the File element - Iterator iter = values.iterator(); - while (iter.hasNext()) { - ISubmodelElement element = iter.next(); - if (element instanceof ConnectedFile) { - ConnectedFile connectedFile = (ConnectedFile) element; - // get value of the file element + ConnectedFile fileSE = retrieveFileSEFromCollection(marking_rcm); - String fileurl = connectedFile.getValue(); - assertTrue(fileurl.endsWith(FILE_ENDING)); - } - } + assertTrue(fileSE.getValue().endsWith(FILE_ENDING)); } - + @Test public void testCollidingFiles() throws Exception { final String FILE_ENDING_A = VABPathTools.buildPath(new String[] { "basyx-temp", "aasx1", "files", "aasx", "files", "text.txt" }, 0); @@ -197,6 +200,50 @@ public void testAllFiles() throws Exception { } + @Test + public void fileValueIsCorrectlyUpdated_whenFileIsUpdated() throws Exception { + final String UPLOAD_ENDPOINT = VABPathTools.concatenatePaths(smEndpoint, "submodelElements", "Marking_CRUUS", "File", "upload"); + + // Retrieve fileSE + ISubmodel nameplate = manager.retrieveSubmodel(aasId, smId); + ConnectedSubmodelElementCollection marking_cruus = (ConnectedSubmodelElementCollection) nameplate.getSubmodelElements().get("Marking_CRUUS"); + ConnectedFile fileSE = retrieveFileSEFromCollection(marking_cruus); + + String fileEndpointBefore = fileSE.getValue(); + checkFile(fileEndpointBefore); + + // When the file is updated + CloseableHttpResponse response = uploadDummyFileToSubmodelElement(UPLOAD_ENDPOINT, getFileFromResources("BaSyx.png"), ContentType.IMAGE_PNG); + try { + int statusCode = response.getStatusLine().getStatusCode(); + + assertEquals(HttpStatus.CREATED.value(), statusCode); + + // Then + String fileEndpointAfter = fileSE.getValue(); + + assertNotEquals(fileEndpointBefore, fileEndpointAfter); + checkFile(fileEndpointAfter); + + } finally { + response.close(); + } + } + + + private ConnectedFile retrieveFileSEFromCollection(ConnectedSubmodelElementCollection marking_rcm) throws Exception { + Collection values = marking_rcm.getValue(); + + Iterator iter = values.iterator(); + while (iter.hasNext()) { + ISubmodelElement element = iter.next(); + if (element instanceof ConnectedFile) { + return (ConnectedFile) element; + } + } + throw new RuntimeException("No File SubmodelElement found in " + marking_rcm.getIdShort()); + } + protected static void buildEndpoints(BaSyxContextConfiguration contextConfig) { rootEndpoint = VABPathTools.stripSlashes(contextConfig.getUrl()); @@ -246,4 +293,24 @@ private void checkFile(String absolutePath) { private ConnectedAssetAdministrationShell getConnectedAssetAdministrationShell() throws Exception { return manager.retrieveAAS(aasId); } + + private File getFileFromResources(String filename) throws IOException, URISyntaxException { + URL resource = getClass().getClassLoader().getResource(filename); + if (resource == null) + throw new IllegalArgumentException("File not found!"); + + return new File(resource.toURI()); + + } + + private CloseableHttpResponse uploadDummyFileToSubmodelElement(String endpoint, File file, ContentType contentType) throws IOException { + CloseableHttpClient client = HttpClients.createDefault(); + + // Create the file entity + HttpEntity fileEntity = MultipartEntityBuilder.create().addBinaryBody("file", file, contentType, file.getName()).build(); + HttpPost postRequest = new HttpPost(endpoint); + postRequest.setEntity(fileEntity); + + return client.execute(postRequest); + } } diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/resources/BaSyx.png b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/resources/BaSyx.png new file mode 100644 index 0000000000000000000000000000000000000000..819b681885eff2d671ce2bdbc0d32d6aeda7917b GIT binary patch literal 11192 zcmW++1ymH@7e)|JLKIm<5K)m@x{(${LUP$*326i*m1b!Wq`SKomRVqFB$kpEkVd4G zl15tkzrX)E6X(plcV_N;_ucz_-+f`4>WY+P^kf7C1eD53uVDCl?|&VzuX?+2ubZt2S!i(#rCmnVb z*1l(C35>=gx#hLvfqkoyE94hJb-SlC-U{5*^`kmgrVN) zyd(3$%HBQ>F$W0hr2)d15n=j8R;lajV*g134kRD{gHnHPlF<2}tFG=v17+Wv6oT8>`PX#>$tIDDTY8yNq>(p%`iGV~ zFY=J3GJe4j@E&Rw$f`O|%vo5w{_Gj%!MAjr79 zpm&hz@sAal$AEe-<~^EB-ZT;9JCWPv_HU!(h)mt|dn_RJp2^6@jX9|6!>S}LubAvj zcwW>!DjLaLheZVln3^;486I$7v4mg9(!s;)XHRPS+!vF|b#2W?F0GX(_xezs%X3t5 z&ww_mG*yVZT_K-MxnJxd13(W)=#_5!RP%O7k2cL2G4o@SLx%2`^I8==1~8*Z5I zkyLHnG56rwR#)nEpsA=353c?bpx?s#(QsUN4G1V8t8)EFwBQ)l+sL%rr6N!vS-pb$ zK$Lk;VDyTxOw>ZmmD+0P6`HW97)pH;MIZYf?UcQNmeVXDd?n&scidrIG{>y0d*a0< z;!FZ+XNNq5xy~Vzau5w(xn#gNLQNhFw0^VCDZnuQlD15v$x+|hkdn6g+I|=y3$~qap-$IP8s{zAmAb9&+TL+7Wj2 zL4SLTs1FEE!bBI4ZPdzYTh|(~XhD266QPdh*5m?f2AQ}`QKjqAnsZ)}&1V(RG2OHe zX2zl95fw@PMl0_&hcLbQ8N|HAH$QWiiw@pNwLN)Q;2z(h^waQRkSnpSTh~W;Ej5W` zn6L>wGKs;)lbvQZUQ9|eGIB(6K(|t=X$c`ACEzBe+gl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$Xm!-UBpq6oF}4%>+tec0{zfFJ)V>5AbaCL^Bf!L- zEZOUFc_8nrqMZ%z8esG1iJ1n^$pKXh>i=(%C%h*v?@edwxPyXU3jZ-mH6|uFS@6rX zFR`(Wf&5q(w2EPpX?Kk1*e036=u0iJ&~6e`5ahy2n$Lc2rtlcP7S=dnntg(t_*b5_ z)a2GV-B4CJL=a(6soVHrucI%a_@DCY8+13GCW#T3M2}%q$KJMhPnT^v>WS9XwYIhb zmkbzJYTeoJuEpcB`r>u!i`KHC^E?^%&F zRBDmX!uGE?;eXR^I&*Ej*`ur)-+84!sW``{1Pw-&;8{?09E3WN_yp_5s{wqU~?3Y`=?rUpnGlB?8DyqxH>+9>< z-+HaK)jKyLW>DW!G_s_fj|ZlmP@^2kiNAmU;%%R<*^6#znNN1tgiYF;5WD^BV*YF_ zNw{5xfc%S0nOu`1&i*9!|jV#~a!@tAAFx&v`+4&hh;FKG;I=B@2{JC4- z>+q`Li<=WkRbUwqn}NwB5f Date: Mon, 22 Jan 2024 14:12:39 +0100 Subject: [PATCH 4/4] Address review remarks --- .../org/eclipse/basyx/regression/AASServer/AASXSuite.java | 7 +------ .../regression/AASServer/TestAASXMongoDBAASServer.java | 7 ++----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java index bb9dc216..0b797664 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/AASXSuite.java @@ -78,7 +78,7 @@ * Suite for testing that the XMLAAS servlet is set up correctly. The tests here * can be used by the servlet test itself and the integration test * - * @author schnicke, espen + * @author schnicke, espen, mateusmolina * */ public abstract class AASXSuite { @@ -204,7 +204,6 @@ public void testAllFiles() throws Exception { public void fileValueIsCorrectlyUpdated_whenFileIsUpdated() throws Exception { final String UPLOAD_ENDPOINT = VABPathTools.concatenatePaths(smEndpoint, "submodelElements", "Marking_CRUUS", "File", "upload"); - // Retrieve fileSE ISubmodel nameplate = manager.retrieveSubmodel(aasId, smId); ConnectedSubmodelElementCollection marking_cruus = (ConnectedSubmodelElementCollection) nameplate.getSubmodelElements().get("Marking_CRUUS"); ConnectedFile fileSE = retrieveFileSEFromCollection(marking_cruus); @@ -212,14 +211,12 @@ public void fileValueIsCorrectlyUpdated_whenFileIsUpdated() throws Exception { String fileEndpointBefore = fileSE.getValue(); checkFile(fileEndpointBefore); - // When the file is updated CloseableHttpResponse response = uploadDummyFileToSubmodelElement(UPLOAD_ENDPOINT, getFileFromResources("BaSyx.png"), ContentType.IMAGE_PNG); try { int statusCode = response.getStatusLine().getStatusCode(); assertEquals(HttpStatus.CREATED.value(), statusCode); - // Then String fileEndpointAfter = fileSE.getValue(); assertNotEquals(fileEndpointBefore, fileEndpointAfter); @@ -230,7 +227,6 @@ public void fileValueIsCorrectlyUpdated_whenFileIsUpdated() throws Exception { } } - private ConnectedFile retrieveFileSEFromCollection(ConnectedSubmodelElementCollection marking_rcm) throws Exception { Collection values = marking_rcm.getValue(); @@ -306,7 +302,6 @@ private File getFileFromResources(String filename) throws IOException, URISyntax private CloseableHttpResponse uploadDummyFileToSubmodelElement(String endpoint, File file, ContentType contentType) throws IOException { CloseableHttpClient client = HttpClients.createDefault(); - // Create the file entity HttpEntity fileEntity = MultipartEntityBuilder.create().addBinaryBody("file", file, contentType, file.getName()).build(); HttpPost postRequest = new HttpPost(endpoint); postRequest.setEntity(fileEntity); diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java index 3880a952..588e788c 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/TestAASXMongoDBAASServer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2021 the Eclipse BaSyx Authors + * 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 @@ -49,7 +49,6 @@ public class TestAASXMongoDBAASServer extends AASXSuite { @BeforeClass public static void setUpClass() throws Exception { - // Setup component's test configuration BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(); contextConfig.loadFromResource(BaSyxContextConfiguration.DEFAULT_CONFIG_PATH); BaSyxAASServerConfiguration aasConfig = new BaSyxAASServerConfiguration(AASServerBackend.MONGODB, "[\"aasx/01_Festo.aasx\", \"aasx/a.aasx\", \"aasx/b.aasx\"]"); @@ -59,7 +58,6 @@ public static void setUpClass() throws Exception { resetMongoDBTestData(); - // Start the component component = new AASServerComponent(contextConfig, aasConfig, basyxMongoDBConfig); component.startComponent(); @@ -71,7 +69,7 @@ public static void tearDownClass() { component.stopComponent(); } - // TODO + // TODO Investigation needed on why it's failing for TestAASXMongoDBAASServer @Override public void testCollidingFiles() throws Exception { } @@ -87,5 +85,4 @@ private static BaSyxMongoDBConfiguration buildBaSyxMongoDBConfiguration() { mongoDBConfig.setSubmodelCollection("TestAASXMongoDBAASServer_SM"); return mongoDBConfig; } - }