-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements InMemory AASX file server #84
Merged
FrankSchnicke
merged 20 commits into
eclipse-basyx:main
from
KBChaithra:feature/aasx-fs-inmem
Nov 8, 2023
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
22dc8a8
Implements InMemory AASX file server
KBChaithra 6893942
Resolves conflicts
KBChaithra fa1b16d
Deletes Readme.md file
KBChaithra 35db5d6
Refractors code
KBChaithra 54b33f3
Improves formatting
KBChaithra bf03b58
Review comments changes
KBChaithra 393d5be
Changes for review comments to use IOUtils for cheking the inputstrea…
KBChaithra 859ab7a
Changes for review comments
KBChaithra 7c63c47
Review comment changes
KBChaithra d1f74e9
Removing IOUtils
KBChaithra b0840da
Changes to AASXFileServerSuite
KBChaithra dd949ef
Changes for Review Comments
KBChaithra 4fccd79
Merge branch 'eclipse-basyx:main' into feature/aasx-fs-inmem
KBChaithra 6fb98ac
Merge branch 'main' of https://github.com/KBChaithra/basyx-java-serve…
KBChaithra 1d1052c
Changes for the review comments
KBChaithra 4a636e9
solving merge conflicts
KBChaithra f0169fc
Merge branch 'feature/aasx-fs-inmem' of https://github.com/KBChaithra…
KBChaithra 50a55b1
Applies BaSyx formatter and minor corrections
mdanish98 e4f1934
Uncomment other modules from parent pom
mdanish98 fa5272f
Resolves review remarks
mdanish98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
basyx.aasxfileserver/basyx.aasxfileserver-backend-inmemory/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<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.aasxfileserver</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>basyx.aasxfileserver-backend-inmemory</artifactId> | ||
<name>AASX File Server Backend InMemory</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasxfileserver-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasxfileserver-core</artifactId> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
160 changes: 160 additions & 0 deletions
160
...ry/src/main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/******************************************************************************* | ||
* 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<String, Package> 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<PackageDescription> getAllAASXPackageIds() { | ||
return packageMap.values().stream().map(Package::getPackageDescription).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<String> aasIds, InputStream file, String filename) throws ElementDoesNotExistException { | ||
|
||
throwIfAASXPackageIdDoesNotExist(packageId); | ||
|
||
updateAASXPackage(packageId, aasIds, file, filename); | ||
} | ||
|
||
@Override | ||
public PackageDescription createAASXPackage(List<String> aasIds, InputStream file, String fileName) { | ||
|
||
String newpackageId = String.valueOf(packageId.incrementAndGet()); | ||
|
||
PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); | ||
|
||
createPackage(aasIds, file, fileName, newpackageId, packageDescription); | ||
|
||
return packageDescription; | ||
} | ||
|
||
@Override | ||
public void deleteAASXByPackageId(String packageId) throws ElementDoesNotExistException { | ||
throwIfAASXPackageIdDoesNotExist(packageId); | ||
|
||
packageMap.remove(packageId); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return aasxFileServerName == null ? AASXFileServer.super.getName() : aasxFileServerName; | ||
} | ||
|
||
private PackageDescription createPackageDescription(List<String> aasIds, String newPackageId) { | ||
PackageDescription packageDescription = new PackageDescription(); | ||
packageDescription.packageId(newPackageId); | ||
packageDescription.aasIds(aasIds); | ||
|
||
return packageDescription; | ||
} | ||
|
||
private PackagesBody createPackagesBody(List<String> aasIds, InputStream file, String fileName) { | ||
PackagesBody packagesBody = new PackagesBody(); | ||
packagesBody.aasIds(aasIds); | ||
packagesBody.file(file); | ||
packagesBody.fileName(fileName); | ||
|
||
return packagesBody; | ||
} | ||
|
||
private void createPackage(List<String> aasIds, InputStream file, String fileName, String newPackageId, PackageDescription packageDescription) { | ||
PackagesBody packagesBody = createPackagesBody(aasIds, file, fileName); | ||
|
||
Package aasxPackage = new Package(newPackageId, packageDescription, packagesBody); | ||
|
||
packageMap.put(newPackageId, aasxPackage); | ||
} | ||
|
||
private void updateAASXPackage(String packageId, List<String> aasIds, InputStream file, String filename) { | ||
Package aasxPackage = this.packageMap.get(packageId); | ||
|
||
updatePackagesBody(aasIds, file, filename, aasxPackage.getPackagesBody()); | ||
|
||
aasxPackage.getPackageDescription().setAasIds(aasIds); | ||
} | ||
|
||
private void updatePackagesBody(List<String> aasIds, InputStream file, String filename, PackagesBody packagesBody) { | ||
packagesBody.setAasIds(aasIds); | ||
packagesBody.setFileName(filename); | ||
packagesBody.setFile(file); | ||
} | ||
|
||
private void throwIfAASXPackageIdDoesNotExist(String id) { | ||
|
||
if (!packageMap.containsKey(id)) | ||
throw new ElementDoesNotExistException(id); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...main/java/org/eclipse/digitaltwin/basyx/aasxfileserver/InMemoryAASXFileServerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...rc/test/java/org/eclipse/digitaltwin/basyx/aasxfileserver/TestInMemoryAASXFileServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<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.aasxfileserver</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>basyx.aasxfileserver-core</artifactId> | ||
<name>AASX File Server Core</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.aas4j</groupId> | ||
<artifactId>model</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test case for repo name (reference below).
basyx-java-server-sdk/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-backend-inmemory/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/TestInMemoryConceptDescriptionRepository.java
Line 61 in d9aece8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done