Translation Framework: cannot get preview file
I am trying to get the preview file while using the translation integration framework.
I am using the code provided in the Bootstrap Connector (https://github.com/Adobe-Marketing-Cloud/aem-translation-framework-bootstrap-connector).
Here's the specific code parts:
(in the uploadTranslationObject() function)
// Generate Preview
if(isPreviewEnabled) {
try {
ZipInputStream zipInputStream = translationObject.getTranslationObjectPreview();
if (zipInputStream != null) {
unzipFileFromStream(zipInputStream, previewPath);
} else {
log.error("Got null for zipInputStream for " + getObjectPath(translationObject));
}
} catch (FileNotFoundException e) {
log.error(e.getLocalizedMessage(), e);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
}
}
log.trace("Preview Directory is: {}", previewPath);
private static void unzipFileFromStream(ZipInputStream zipInputStream, String targetPath) throws IOException {
File dirFile = new File(targetPath + File.separator);
if (!dirFile.exists()) {
dirFile.mkdirs();
log.trace("Created directory: {}",dirFile);
}
ZipEntry zipEntry = null;
while (null != (zipEntry = zipInputStream.getNextEntry())) {
String zipFileName = zipEntry.getName();
if (zipEntry.isDirectory()) {
File zipFolder = new File(targetPath + File.separator + zipFileName);
if (!zipFolder.exists()) {
zipFolder.mkdirs();
log.trace("Created directory: {}",zipFolder);
}
} else {
File file = new File(targetPath + File.separator + zipFileName);
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
log.error(e.getLocalizedMessage(),e);
}
int readLen = 0;
byte buffer[] = new byte[1024];
while (-1 != (readLen = zipInputStream.read(buffer))) {
fos.write(buffer, 0, readLen);
}
fos.close();
}
}
zipInputStream.close();
}
How this should work? Is there a specific folder where the preview needs to be saved?
Or is it even a working code example?
Thanks in advance!