Skip to content

Commit

Permalink
Bugfix/aasx files (#265)
Browse files Browse the repository at this point in the history
* Ensures sames files are only tried to be added once

Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>

* Removes changing of file value to start with file:// on AASX serialization

Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>

---------

Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>
  • Loading branch information
FrankSchnicke authored Mar 14, 2024
1 parent 2c508b6 commit 1017e1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.UUID;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
Expand Down Expand Up @@ -95,7 +95,6 @@ public AASXSerializer(XmlSerializer xmlSerializer) {
*/
public void write(Environment environment, Collection<InMemoryFile> files, OutputStream os)
throws SerializationException, IOException {
prepareFilePaths(environment);

OPCPackage rootPackage = OPCPackage.create(os);

Expand Down Expand Up @@ -234,7 +233,7 @@ private void writeDataToPart(PackagePart part, byte[] content) {
* @return the found Files
*/
private Collection<File> findFileElements(Environment environment) {
Collection<File> files = new ArrayList<>();
Collection<File> files = new HashSet<>();
new AssetAdministrationShellElementWalkerVisitor() {
@Override
public void visit(File file) {
Expand All @@ -246,15 +245,6 @@ public void visit(File file) {
return files;
}

/**
* Replaces the path in all File Elements with the result of preparePath
*
* @param environment the Environment
*/
private void prepareFilePaths(Environment environment) {
findFileElements(environment).forEach(f -> f.setValue(preparePath(f.getValue())));
}

/**
* Finds an InMemoryFile by its path
*
Expand All @@ -271,17 +261,4 @@ private InMemoryFile findFileByPath(Collection<InMemoryFile> files, String path)
throw new RuntimeException("The wanted file '" + path + "' was not found in the given files.");
}

/**
* Removes the serverpart from a path and ensures it starts with "file://"
*
* @param path the path to be prepared
* @return the prepared path
*/
private String preparePath(String path) {
if (path.startsWith("/")) {
path = "file://" + path;
}
return path;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public class ValidationTest {
public void validateXmlInsideAasx() throws SerializationException, IOException, InvalidFormatException, DeserializationException, ParserConfigurationException, SAXException {
List<InMemoryFile> fileList = new ArrayList<>();
byte[] operationManualContent = { 0, 1, 2, 3, 4 };
byte[] thumbnail = { 0, 1, 2, 3, 4 };
InMemoryFile inMemoryFile = new InMemoryFile(operationManualContent, "file:///aasx/OperatingManual.pdf");
InMemoryFile inMemoryFileThumbnail = new InMemoryFile(thumbnail, "file:///master/verwaltungsschale-detail-part1.png");
fileList.add(inMemoryFile);
fileList.add(inMemoryFileThumbnail);

File file = tempFolder.newFile("output.aasx");

Expand Down

0 comments on commit 1017e1d

Please # to comment.