Skip to content
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

Bugfix/aasx files #265

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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