-
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
Changes from 5 commits
22dc8a8
6893942
fa1b16d
35db5d6
54b33f3
bf03b58
393d5be
859ab7a
7c63c47
d1f74e9
b0840da
dd949ef
4fccd79
6fb98ac
1d1052c
4a636e9
f0169fc
50a55b1
e4f1934
fa5272f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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-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> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/******************************************************************************* | ||
* 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.core.exceptions.CollidingIdentifierException; | ||
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; | ||
|
||
/** | ||
* In-memory implementation of the AasxFileServer | ||
* | ||
* @author chaithra | ||
* | ||
*/ | ||
public class InMemoryAasxFileServer implements AasxFileServer { | ||
|
||
private Map<String, Package> packageMap = new LinkedHashMap<>(); | ||
private AtomicInteger packageId = new AtomicInteger(0); | ||
|
||
/** | ||
* Creates the InMemoryAasxFileServer | ||
* @author chaithra | ||
*/ | ||
public InMemoryAasxFileServer() {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there a need for this Constructor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed the constructor |
||
|
||
@Override | ||
public Collection<PackageDescription> getAllAASXPackageIds() { | ||
|
||
return packageMap.values().stream() | ||
.map(aasxPackage -> aasxPackage.getPackageDescription()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Package::getPackageDescription There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException { | ||
throwIfAasxFileIdDoesNotExist(packageId); | ||
|
||
return packageMap.get(packageId).getPackagesBody().getFile(); | ||
} | ||
|
||
@Override | ||
public void updateAASXByPackageId(String packageId, List<String> aasIds, InputStream file, String filename) | ||
throws ElementDoesNotExistException { | ||
|
||
throwIfAasxFileIdDoesNotExist(packageId); | ||
|
||
updateAASXPackage(packageId, aasIds, file, filename); | ||
} | ||
|
||
@Override | ||
public PackageDescription createAASXPackage(List<String> aasIds, InputStream file, String fileName) | ||
throws CollidingIdentifierException { | ||
|
||
String newpackageId = String.valueOf(packageId.incrementAndGet()); | ||
PackageDescription packageDescription = createPackageDescription(aasIds, newpackageId); | ||
createPackage(aasIds, file, fileName, newpackageId, packageDescription); | ||
|
||
return packageDescription; | ||
} | ||
|
||
@Override | ||
public void deleteAASXPackageById(String packageId) throws ElementDoesNotExistException { | ||
throwIfAasxFileIdDoesNotExist(packageId); | ||
|
||
packageMap.remove(packageId); | ||
} | ||
|
||
public Integer increment(Integer n) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No usage of this method, please remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return n++; | ||
} | ||
|
||
private PackageDescription createPackageDescription(List<String> aasIds, String newpackageId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newPackageId There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newPackageId There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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); | ||
aasxPackage.getPackagesBody().setAasIds(aasIds); | ||
aasxPackage.getPackagesBody().setFileName(filename); | ||
aasxPackage.getPackagesBody().setFile(file); | ||
aasxPackage.getPackageDescription().setAasIds(aasIds); | ||
} | ||
|
||
private void throwIfAasxFileIdDoesNotExist(String id) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename it to throwIfAasxPackageIdDoesNotExist There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
if (!packageMap.containsKey(id)) | ||
throw new ElementDoesNotExistException(id); | ||
} | ||
|
||
} |
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 AasxFileServer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use @link to mention the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* | ||
* @author schnicke, chaithra | ||
*/ | ||
@Component | ||
@ConditionalOnExpression("'${basyx.backend}'.equals('InMemory')") | ||
public class InMemoryAasxFileServerFactory implements AasxFileServerFactory { | ||
|
||
@Override | ||
public AasxFileServer create() { | ||
return new InMemoryAasxFileServer(); | ||
} | ||
} |
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.eclipse.digitaltwin.basyx.aasxfileserver.core.AasxFileServerSuite; | ||
|
||
/** | ||
* Tests the {@link InMemoryAasxFileServer} | ||
* | ||
* @author chaithra | ||
* | ||
*/ | ||
public class TestInMemoryAasxFileServer extends AasxFileServerSuite { | ||
|
||
@Override | ||
protected AasxFileServer getAasxFileServer() { | ||
return new InMemoryAasxFileServer(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<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> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2023 the Eclipse BaSyx Authors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
******************************************************************************/ | ||
|
||
package org.eclipse.digitaltwin.basyx.aasxfileserver; | ||
|
||
import java.io.InputStream; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; | ||
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; | ||
|
||
/** | ||
* Specifies the overall AasxFileServer API | ||
* | ||
* @author chaithra | ||
* | ||
*/ | ||
public interface AasxFileServer { | ||
|
||
/** | ||
* Retrieves all AASXPackageIds from the repository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AASX package ids There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* | ||
* @return a list of available AASX packages at the server | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please improve this, as it is not returning the AASX packages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
*/ | ||
public Collection<PackageDescription> getAllAASXPackageIds(); | ||
|
||
/** | ||
* Retrieves a specific AASX package from the server | ||
* | ||
* @param packageId | ||
* @return a specific AASX package from the server | ||
* @throws ElementDoesNotExistException | ||
*/ | ||
public InputStream getAASXByPackageId(String packageId) throws ElementDoesNotExistException; | ||
|
||
/** | ||
* Updates an existing AASX package at the server | ||
* | ||
* @param packageId | ||
* @param aasIds | ||
* @param filename | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep @param in same order as defined in method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* @param file | ||
* @throws ElementDoesNotExistException | ||
*/ | ||
public void updateAASXByPackageId(String packageId, List<String> aasIds, InputStream file, String filename) throws ElementDoesNotExistException; | ||
|
||
/** | ||
* Creates a new AASXPackage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AASX Package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* | ||
* @param aasIds | ||
* @param filename | ||
* @param file | ||
* @throws CollidingIdentifierException | ||
*/ | ||
public PackageDescription createAASXPackage(List<String> aasIds, InputStream file, String fileName) throws CollidingIdentifierException; | ||
|
||
/** | ||
* Deletes a AASXPackage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AASX Package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* @param packageId | ||
* @throws ElementDoesNotExistException | ||
*/ | ||
public void deleteAASXPackageById(String packageId) throws ElementDoesNotExistException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename it to deleteAASXByPackageId There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
} |
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.
No need for author here.
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.
removed