use of org.apache.ant.compress.taskdefs.Unzip in project dhis2-core by dhis2.
the class DefaultAppManager method installApp.
@Override
public AppStatus installApp(File file, String fileName) {
try {
// -----------------------------------------------------------------
// Parse ZIP file and it's manifest.webapp file.
// -----------------------------------------------------------------
ZipFile zip = new ZipFile(file);
ZipEntry entry = zip.getEntry(MANIFEST_FILENAME);
InputStream inputStream = zip.getInputStream(entry);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
App app = mapper.readValue(inputStream, App.class);
// -----------------------------------------------------------------
// Check for namespace and if it's already taken by another app
// -----------------------------------------------------------------
String namespace = app.getActivities().getDhis().getNamespace();
if (namespace != null && (this.appNamespaces.containsKey(namespace) && !app.equals(appNamespaces.get(namespace)))) {
zip.close();
return AppStatus.NAMESPACE_TAKEN;
}
// -----------------------------------------------------------------
// Delete if app is already installed, assuming app update so no
// data is deleted
// -----------------------------------------------------------------
deleteApp(app.getName(), false);
// -----------------------------------------------------------------
// Unzip the app
// -----------------------------------------------------------------
log.info("Installing app, namespace: " + namespace);
String dest = getAppFolderPath() + File.separator + fileName.substring(0, fileName.lastIndexOf('.'));
Unzip unzip = new Unzip();
unzip.setSrc(file);
unzip.setDest(new File(dest));
unzip.execute();
log.info("Installed app: " + app);
// -----------------------------------------------------------------
// Installation complete. Closing zip, reloading apps and return OK
// -----------------------------------------------------------------
zip.close();
reloadApps();
return AppStatus.OK;
} catch (ZipException e) {
return AppStatus.INVALID_ZIP_FORMAT;
} catch (JsonParseException e) {
return AppStatus.INVALID_MANIFEST_JSON;
} catch (JsonMappingException e) {
return AppStatus.INVALID_MANIFEST_JSON;
} catch (IOException e) {
return AppStatus.INSTALLATION_FAILED;
}
}
Aggregations