diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/pom.xml b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/pom.xml new file mode 100644 index 000000000..621d3b62a --- /dev/null +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/pom.xml @@ -0,0 +1,48 @@ + + 4.0.0 + + org.eclipse.digitaltwin.basyx + basyx.submodelservice + ${revision} + + basyx.submodelservice-backend-mongodb + BaSyx submodelservice-backend-mongodb + BaSyx submodelservice-backend-mongodb + + + + org.eclipse.digitaltwin.basyx + basyx.submodelservice-core + + + org.eclipse.digitaltwin.basyx + basyx.submodelservice-core + tests + test + + + org.eclipse.digitaltwin.basyx + basyx.submodelservice-backend-inmemory + + + org.eclipse.digitaltwin.basyx + basyx.mongodbcore + + + org.eclipse.digitaltwin.basyx + + basyx.filerepository-backend-mongodb + + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter + + + \ No newline at end of file diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java new file mode 100644 index 000000000..182add728 --- /dev/null +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (C) 2024 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.submodelservice; + +import java.io.File; +import java.io.InputStream; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementNotAFileException; +import org.eclipse.digitaltwin.basyx.core.exceptions.FeatureNotSupportedException; +import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.filerepository.FileRepository; +import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; +import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; +import org.eclipse.digitaltwin.basyx.submodelservice.value.SubmodelElementValue; +import org.springframework.data.repository.CrudRepository; + +/** + * Implements the SubmodelService as MongoDB variant + * + * @author zhangzai, mateusmolina + * + */ +public class MongoDBSubmodelService implements SubmodelService { + + private final FileRepository fileRepository; + + private CrudRepository crudRepository; + + private Submodel submodel; + + /** + * Creates the MongoDB SubmodelService containing the passed Submodel + * + * @param submodel + */ + + public MongoDBSubmodelService(Submodel submodel, FileRepository fileRepository, CrudRepository crudRepository) { + this.submodel = submodel; + this.fileRepository = fileRepository; + this.crudRepository = crudRepository; + crudRepository.save(submodel); + } + + private InMemorySubmodelService getInMemorySubmodelService() { + return new InMemorySubmodelService(getSubmodel(), fileRepository); + } + + @Override + public Submodel getSubmodel() { + return crudRepository.findById(submodel.getId()).get(); + } + + @Override + public CursorResult> getSubmodelElements(PaginationInfo pInfo) { + return getInMemorySubmodelService().getSubmodelElements(pInfo); + } + + @Override + public SubmodelElement getSubmodelElement(String idShortPath) throws ElementDoesNotExistException { + return getInMemorySubmodelService().getSubmodelElement(idShortPath); + } + + @Override + public SubmodelElementValue getSubmodelElementValue(String idShortPath) throws ElementDoesNotExistException { + return getInMemorySubmodelService().getSubmodelElementValue(idShortPath); + } + + @Override + public void setSubmodelElementValue(String idShortPath, SubmodelElementValue value) throws ElementDoesNotExistException { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.setSubmodelElementValue(idShortPath, value); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + + } + + @Override + public void createSubmodelElement(SubmodelElement submodelElement) { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.createSubmodelElement(submodelElement); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + } + + @Override + public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.createSubmodelElement(idShortPath, submodelElement); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + + } + + @Override + public void updateSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.updateSubmodelElement(idShortPath, submodelElement); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + } + + @Override + public void deleteSubmodelElement(String idShortPath) throws ElementDoesNotExistException { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.deleteSubmodelElement(idShortPath); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + + } + + @Override + public void patchSubmodelElements(List submodelElementList) { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.patchSubmodelElements(submodelElementList); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + } + + @Override + public OperationVariable[] invokeOperation(String idShortPath, OperationVariable[] input) throws ElementDoesNotExistException { + throw new FeatureNotSupportedException("invokeOperation"); + } + + @Override + public File getFileByPath(String idShortPath) throws ElementDoesNotExistException, ElementNotAFileException, FileDoesNotExistException { + return getInMemorySubmodelService().getFileByPath(idShortPath); + } + + @Override + public void setFileValue(String idShortPath, String fileName, InputStream inputStream) throws ElementDoesNotExistException, ElementNotAFileException { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.setFileValue(idShortPath, fileName, inputStream); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + } + + @Override + public void deleteFileValue(String idShortPath) throws ElementDoesNotExistException, ElementNotAFileException, FileDoesNotExistException { + InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); + inMemorySubmodelService.deleteFileValue(idShortPath); + Submodel submodel = inMemorySubmodelService.getSubmodel(); + crudRepository.save(submodel); + + } + + @Override + public InputStream getFileByFilePath(String filePath) { + return getInMemorySubmodelService().getFileByFilePath(filePath); + } + +} diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelServiceFactory.java b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelServiceFactory.java new file mode 100644 index 000000000..6ca0e49b4 --- /dev/null +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelServiceFactory.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (C) 2024 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.submodelservice; + +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.basyx.core.filerepository.FileRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.stereotype.Component; + +/** + * SubmodelService factory returning an MongoDB backend SubmodelService + * + * @author zhangzai, mateusmolina + * + */ +@ConditionalOnExpression("'${basyx.submodelservice.backend}'.equals('MongoDB') or '${basyx.backend}'.equals('MongoDB')") +@Component +public class MongoDBSubmodelServiceFactory implements SubmodelServiceFactory { + + private final FileRepository fileRepository; + private final SingleSubmodelMongoDBBackendProvider mongoDBBackendProvider; + + public MongoDBSubmodelServiceFactory(FileRepository fileRepository, SingleSubmodelMongoDBBackendProvider mongoDBBackendProvider) { + this.fileRepository = fileRepository; + this.mongoDBBackendProvider = mongoDBBackendProvider; + } + + @Override + public SubmodelService create(Submodel submodel) { + return new MongoDBSubmodelService(submodel, fileRepository, mongoDBBackendProvider.getCrudRepository()); + } + + +} diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SingleSubmodelMongoDBBackendProvider.java b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SingleSubmodelMongoDBBackendProvider.java new file mode 100644 index 000000000..5d81441ec --- /dev/null +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SingleSubmodelMongoDBBackendProvider.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (C) 2024 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.submodelservice; + +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.basyx.common.mongocore.BasyxMongoMappingContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity; +import org.springframework.data.mongodb.repository.support.MappingMongoEntityInformation; +import org.springframework.data.mongodb.repository.support.SimpleMongoRepository; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Component; + +/** + * + * MongoDB Backend Provider for the {@link Submodel} + * + * @author mateusmolina, zhangzai + */ +@ConditionalOnExpression("'${basyx.backend}'.equals('MongoDB')") +@Component +public class SingleSubmodelMongoDBBackendProvider { + + private BasyxMongoMappingContext mappingContext; + + private MongoTemplate template; + + @Autowired + public SingleSubmodelMongoDBBackendProvider(BasyxMongoMappingContext mappingContext, @Value("${basyx.submodelservice.mongodb.collectionName:submodel-service}") String collectionName, MongoTemplate template) { + super(); + this.mappingContext = mappingContext; + this.template = template; + + mappingContext.addEntityMapping(Submodel.class, collectionName); + } + + public CrudRepository getCrudRepository() { + @SuppressWarnings("unchecked") + MongoPersistentEntity entity = (MongoPersistentEntity) mappingContext.getPersistentEntity(Submodel.class); + + return new SimpleMongoRepository<>(new MappingMongoEntityInformation<>(entity), template); + } + +} diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/TestMongoDBSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/TestMongoDBSubmodelService.java new file mode 100644 index 000000000..66198a9b4 --- /dev/null +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/TestMongoDBSubmodelService.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (C) 2024 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.submodelservice; + +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.basyx.common.mongocore.BasyxMongoMappingContext; +import org.eclipse.digitaltwin.basyx.common.mongocore.MongoDBUtilities; +import org.eclipse.digitaltwin.basyx.core.exceptions.FeatureNotSupportedException; +import org.eclipse.digitaltwin.basyx.core.filerepository.FileRepository; +import org.eclipse.digitaltwin.basyx.core.filerepository.MongoDBFileRepository; +import org.junit.After; +import org.junit.Test; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.gridfs.GridFsTemplate; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; + +/** + * Test for mongoDb submodel service backend + * + * @author zhangzai, mateusmolina + * + */ +public class TestMongoDBSubmodelService extends SubmodelServiceSuite { + private final String COLLECTION = "submodelTestCollection"; + private final String CONNECTION_URL = "mongodb://mongoAdmin:mongoPassword@localhost:27017"; + private final MongoClient CLIENT = MongoClients.create(CONNECTION_URL); + private final MongoTemplate TEMPLATE = new MongoTemplate(CLIENT, "BaSyxTestDb"); + private final GridFsTemplate GRIDFS_TEMPLATE = new GridFsTemplate(TEMPLATE.getMongoDatabaseFactory(), TEMPLATE.getConverter()); + private FileRepository fileRepository = new MongoDBFileRepository(GRIDFS_TEMPLATE); + + @After + public void clear() { + MongoDBUtilities.clearCollection(TEMPLATE, COLLECTION); + } + + @Override + protected SubmodelService getSubmodelService(Submodel submodel) { + BasyxMongoMappingContext mappingContext = new BasyxMongoMappingContext(); + return new MongoDBSubmodelServiceFactory(fileRepository, new SingleSubmodelMongoDBBackendProvider(mappingContext, COLLECTION, TEMPLATE)).create(submodel); + } + + @Override + @Test(expected = FeatureNotSupportedException.class) + public void invokeOperation() { + super.invokeOperation(); + } + + @Override + @Test(expected = FeatureNotSupportedException.class) + public void invokeNonOperation() { + super.invokeNonOperation(); + } + + @Override + protected boolean fileExistsInStorage(String fileValue) { + return fileRepository.exists(fileValue); + } +} diff --git a/basyx.submodelservice/basyx.submodelservice.example/pom.xml b/basyx.submodelservice/basyx.submodelservice.example/pom.xml index 0220e706a..950dabc61 100644 --- a/basyx.submodelservice/basyx.submodelservice.example/pom.xml +++ b/basyx.submodelservice/basyx.submodelservice.example/pom.xml @@ -21,6 +21,10 @@ org.eclipse.digitaltwin.basyx basyx.submodelservice-backend-inmemory + + org.eclipse.digitaltwin.basyx + basyx.submodelservice-backend-mongodb + org.eclipse.digitaltwin.basyx basyx.submodelservice-http diff --git a/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelComponent.java b/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelComponent.java index 36bb73c6f..a7d22d528 100644 --- a/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelComponent.java +++ b/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelComponent.java @@ -27,6 +27,8 @@ 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 SubmodelService off-shelf-component @@ -34,7 +36,7 @@ * @author fried * */ -@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx") +@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx", exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) public class ExampleSubmodelComponent { public static void main(String[] args) { SpringApplication.run(ExampleSubmodelComponent.class, args); diff --git a/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelConfiguration.java b/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelConfiguration.java index 1f4aecbec..0915e78df 100644 --- a/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelConfiguration.java +++ b/basyx.submodelservice/basyx.submodelservice.example/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/example/ExampleSubmodelConfiguration.java @@ -26,8 +26,6 @@ package org.eclipse.digitaltwin.basyx.submodelservice.example; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; -import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository; -import org.eclipse.digitaltwin.basyx.submodelservice.InMemorySubmodelServiceFactory; import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelService; import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelServiceFactory; import org.springframework.context.annotation.Bean; @@ -43,13 +41,8 @@ @Configuration public class ExampleSubmodelConfiguration { @Bean - public SubmodelService getSubmodelService(Submodel submodel) { - return getSubmodelServiceFactory().create(submodel); - } - - @Bean - static SubmodelServiceFactory getSubmodelServiceFactory() { - return new InMemorySubmodelServiceFactory(new InMemoryFileRepository()); + public SubmodelService getSubmodelService(Submodel submodel, SubmodelServiceFactory submodelServiceFactory) { + return submodelServiceFactory.create(submodel); } @Bean diff --git a/basyx.submodelservice/basyx.submodelservice.example/src/main/resources/application.properties b/basyx.submodelservice/basyx.submodelservice.example/src/main/resources/application.properties index 8d08ffc30..02ce6d216 100644 --- a/basyx.submodelservice/basyx.submodelservice.example/src/main/resources/application.properties +++ b/basyx.submodelservice/basyx.submodelservice.example/src/main/resources/application.properties @@ -2,6 +2,17 @@ server.port=8081 spring.application.name=Submodel Service +basyx.backend=InMemory +# basyx.backend=MongoDB + + +# spring.data.mongodb.host=localhost +# spring.data.mongodb.port=27017 +# spring.data.mongodb.database=BaSyxTestDb +# spring.data.mongodb.authentication-database=admin +# spring.data.mongodb.username=mongoAdmin +# spring.data.mongodb.password=mongoPassword + # Base Path for Spring Boot Actuator # management.endpoints.web.base-path=/ diff --git a/basyx.submodelservice/basyx.submodelservice.example/src/test/resources/application.properties b/basyx.submodelservice/basyx.submodelservice.example/src/test/resources/application.properties index 51d6bb1cf..7057c9752 100644 --- a/basyx.submodelservice/basyx.submodelservice.example/src/test/resources/application.properties +++ b/basyx.submodelservice/basyx.submodelservice.example/src/test/resources/application.properties @@ -1,3 +1,13 @@ server.port=8080 spring.application.name=Submodel Service Test + +basyx.backend=InMemory +# basyx.backend=MongoDB + +# spring.data.mongodb.host=localhost +# spring.data.mongodb.port=27017 +# spring.data.mongodb.database=BaSyxTestDb +# spring.data.mongodb.authentication-database=admin +# spring.data.mongodb.username=mongoAdmin +# spring.data.mongodb.password=mongoPassword \ No newline at end of file diff --git a/basyx.submodelservice/pom.xml b/basyx.submodelservice/pom.xml index f5916f017..c47a3dff1 100644 --- a/basyx.submodelservice/pom.xml +++ b/basyx.submodelservice/pom.xml @@ -18,6 +18,7 @@ basyx.submodelservice-core basyx.submodelservice-http basyx.submodelservice-backend-inmemory + basyx.submodelservice-backend-mongodb basyx.submodelservice-feature-mqtt basyx.submodelservice.example basyx.submodelservice-client diff --git a/pom.xml b/pom.xml index ea8092ff2..953e70db9 100644 --- a/pom.xml +++ b/pom.xml @@ -459,6 +459,11 @@ basyx.submodelservice-backend-inmemory ${revision} + + org.eclipse.digitaltwin.basyx + basyx.submodelservice-backend-mongodb + ${revision} + org.eclipse.digitaltwin.basyx basyx.submodelservice.component