Skip to content

Commit

Permalink
Merge branch 'eclipse-basyx:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
geso02 authored Sep 17, 2024
2 parents 52611b6 + 97f5be8 commit ebfff60
Show file tree
Hide file tree
Showing 16 changed files with 485 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
- 'NOTICE'

env:
VERSION: 2.0.0-milestone-04
VERSION: 2.0.0-SNAPSHOT
MVN_ARGS_BUILD_BASYX_NO_TESTS: -DskipTests

jobs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<version>${revision}</version>
</parent>
<artifactId>basyx.authorization.rules.rbac.backend.inmemory</artifactId>
<name>BaSyx RBAC InMemory Backend</name>
<description>BaSyx RBAC InMemory Backend</description>

<dependencies>
<dependency>
Expand All @@ -24,4 +26,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<version>${revision}</version>
</parent>
<artifactId>basyx.authorization.rules.rbac.backend.submodel</artifactId>

<name>BaSyx RBAC Submodel Backend</name>
<description>BaSyx RBAC Submodel Backend</description>
<dependencies>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
Expand Down Expand Up @@ -47,4 +48,4 @@
</dependency>

</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelservice</artifactId>
<version>${revision}</version>
</parent>
<artifactId>basyx.submodelservice-backend-mongodb</artifactId>
<name>BaSyx submodelservice-backend-mongodb</name>
<description>BaSyx submodelservice-backend-mongodb</description>

<dependencies>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelservice-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelservice-core</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelservice-backend-inmemory</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.mongodbcore</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>
basyx.filerepository-backend-mongodb
</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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<Submodel, String> crudRepository;

private Submodel submodel;

/**
* Creates the MongoDB SubmodelService containing the passed Submodel
*
* @param submodel
*/

public MongoDBSubmodelService(Submodel submodel, FileRepository fileRepository, CrudRepository<Submodel, String> 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<List<SubmodelElement>> 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<SubmodelElement> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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());
}


}
Loading

0 comments on commit ebfff60

Please sign in to comment.