Skip to content

Commit

Permalink
Fixes the aasx-unpack issue
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammad Ghazanfar Ali Danish <ghazanfar.danish@iese.fraunhofer.de>
  • Loading branch information
mdanish98 committed Mar 22, 2023
1 parent cf9d93f commit 7ad5679
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class AASXToMetamodelConverter {

private static final String XML_TYPE = "http://www.admin-shell.io/aasx/relationships/aas-spec";
private static final String AASX_ORIGIN = "/aasx/aasx-origin";
public static final String TEMP_DIRECTORY = "basyx-temp";

private String aasxPath;
private OPCPackage aasxRoot;
Expand Down Expand Up @@ -270,7 +271,7 @@ private List<String> parseElements(Collection<ISubmodelElement> elements) {
* @throws InvalidFormatException
*/
public void unzipRelatedFiles() throws IOException, ParserConfigurationException, SAXException, URISyntaxException, InvalidFormatException {
unzipRelatedFiles(getRootFolder());
unzipRelatedFiles(getTemporaryDirPath());
}

/**
Expand All @@ -294,14 +295,27 @@ public void unzipRelatedFiles(Path pathToDirectory) throws InvalidFormatExceptio
closeOPCPackage();
}

/**
* Creates a temporary directory to hold the unpackaged files.
*
* @return Path of the temporary directory
*
*/
protected Path getTemporaryDirPath() {
return Paths.get(FileUtils.getTempDirectory().getAbsolutePath(), TEMP_DIRECTORY);
}

/**
* Create a folder to hold the unpackaged files The folder has the path
* \target\classes\docs
*
* @throws IOException
* @throws URISyntaxException
*
* @deprecated This method is deprecated. Please use the {@link AASXToMetamodelConverter#getTemporaryDirPath()}
*/
protected Path getRootFolder() throws IOException, URISyntaxException {
@Deprecated(since = "1.4.0", forRemoval = true)
protected Path getRootFolder() throws URISyntaxException, IOException {
URI uri = AASXToMetamodelConverter.class.getProtectionDomain().getCodeSource().getLocation().toURI();
URI parent = new File(uri).getParentFile().toURI();
return Paths.get(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class TestAASXToMetamodelConverterFromBaSyx {
private static final String PDF_PATH = "/aasx/Document/docu.pdf";
private static final String PDF_MIMETYPE = "application/pdf";
private static final String PDF_IDSHORT = "pdf";
private static final String TARGET_PATH = "target/files"; // gets set by BaSyx
private static final String TARGET_PATH = "/basyx-temp/files"; // gets set by BaSyx
private static final String[] EXPECTED_UNZIPPED_FILES = { TARGET_PATH + PDF_PATH, TARGET_PATH + IMAGE_PATH };
private static final String[] EXPECTED_UNZIPPED_FILES_IN_TEMP_DIR = { PDF_PATH, IMAGE_PATH };

Expand Down Expand Up @@ -234,10 +234,12 @@ public void testQualifierValue() throws Exception {
public void testFilesOfGeneratedAASX() throws InvalidFormatException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
// Unzip files from the .aasx
packageManager.unzipRelatedFiles();

String tempDirectory = FileUtils.getTempDirectory().getAbsolutePath();

// Check if all expected files are present
for (String path : EXPECTED_UNZIPPED_FILES) {
assertTrue(new java.io.File(path).exists());
assertTrue(new java.io.File(tempDirectory + path).exists());
}
}

Expand Down

0 comments on commit 7ad5679

Please sign in to comment.