-
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
AAS Thumbnail operations #150
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8367fa1
merge conflict
zhangzai123 4ed740a
Revocer and update authors of CrudAasRepository
zhangzai123 dd08e5b
Refactor test logic
zhangzai123 03cd800
Optimize exception handling.
zhangzai123 878f387
Adjust thumbnail operations to actual state
zhangzai123 448c0e1
Minor changes for code refactoring
zhangzai123 e197f1e
Move private method to the end.
zhangzai123 230dcc0
Merge branch 'main' into AAS-thumbnail
zhangzai123 80d1bc0
Resolve conflict in BaSyxExceptionHandler.java
zhangzai123 d650114
Fix ambiguous exception handling
zhangzai123 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
3 changes: 2 additions & 1 deletion
3
basyx.aasrepository/basyx.aasrepository-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
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
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
Binary file added
BIN
+11.2 KB
...sitory/basyx.aasrepository-backend-inmemory/src/test/resources/BaSyx-Logo-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.9 KB
...sitory/basyx.aasrepository-backend-inmemory/src/test/resources/BaSyx-Logo-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.2 KB
...ository/basyx.aasrepository-backend-mongodb/src/test/resources/BaSyx-Logo-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.2 KB
...ository/basyx.aasrepository-backend-mongodb/src/test/resources/BaSyx-Logo-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
117 changes: 117 additions & 0 deletions
117
...rc/main/java/org/eclipse/digitaltwin/basyx/aasrepository/backend/AASThumbnailHandler.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,117 @@ | ||
/******************************************************************************* | ||
* 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.aasrepository.backend; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.InvalidPathException; | ||
import java.nio.file.Paths; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.Resource; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultResource; | ||
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; | ||
import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException; | ||
import org.eclipse.digitaltwin.basyx.core.exceptions.FileHandlingException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class AASThumbnailHandler { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(AASThumbnailHandler.class); | ||
|
||
public static void updateThumbnail(AasRepository aasRepo, String aasId, String contentType, String filePath) { | ||
AssetInformation assetInfor = aasRepo.getAssetInformation(aasId); | ||
assetInfor.getDefaultThumbnail().setContentType(contentType); | ||
assetInfor.getDefaultThumbnail().setPath(filePath); | ||
aasRepo.setAssetInformation(aasId, assetInfor); | ||
} | ||
|
||
public static void setNewThumbnail(AasRepository aasRepo, String aasId, String contentType, String filePath) { | ||
Resource resource = new DefaultResource(); | ||
resource.setContentType(contentType); | ||
resource.setPath(filePath); | ||
AssetInformation assetInfor = aasRepo.getAssetInformation(aasId); | ||
assetInfor.setDefaultThumbnail(resource); | ||
aasRepo.setAssetInformation(aasId, assetInfor); | ||
} | ||
|
||
public static void throwIfFileDoesNotExist(String aasId, Resource resource) { | ||
if (resource == null) | ||
throw new FileDoesNotExistException(aasId); | ||
|
||
String filePath = resource.getPath(); | ||
throwIfFilePathIsNotValid(aasId, filePath); | ||
} | ||
|
||
public static String createFilePath(String tmpDirectory, String aasId, String fileName) { | ||
return tmpDirectory + "/" + aasId + "-" + "Thumbnail" + "-" + fileName; | ||
} | ||
|
||
public static void createFileAtSpecifiedPath(String fileName, InputStream inputStream, String filePath) { | ||
java.io.File targetFile = new java.io.File(filePath); | ||
|
||
try (FileOutputStream outStream = new FileOutputStream(targetFile)) { | ||
IOUtils.copy(inputStream, outStream); | ||
} catch (IOException e) { | ||
throw new FileHandlingException(fileName); | ||
} | ||
} | ||
|
||
public static void deleteExistingFile(String path) { | ||
if (path == null || path.isEmpty()) | ||
return; | ||
|
||
try { | ||
Files.deleteIfExists(Paths.get(path, "")); | ||
} catch (IOException e) { | ||
logger.error("Unable to delete the file having path '{}'", path); | ||
} | ||
} | ||
|
||
public static String getTemporaryDirectoryPath() { | ||
String tempDirectoryPath = ""; | ||
try { | ||
tempDirectoryPath = Files.createTempDirectory("basyx-temp-thumbnail").toAbsolutePath().toString(); | ||
} catch (IOException e) { | ||
logger.error("Unable to create file in the temporary path."); | ||
} | ||
return tempDirectoryPath; | ||
} | ||
|
||
private static void throwIfFilePathIsNotValid(String aasId, String filePath) { | ||
if (filePath.isEmpty()) | ||
throw new FileDoesNotExistException(aasId); | ||
try { | ||
Paths.get(filePath); | ||
} catch (InvalidPathException | NullPointerException ex) { | ||
throw new FileDoesNotExistException(aasId); | ||
} | ||
} | ||
} |
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
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
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
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.
move to ThumbnailHandle?