use of org.codice.ddf.admin.application.service.impl.ZipFileApplicationDetails in project ddf by codice.
the class ApplicationUploadEndpoint method update.
@POST
@Path("/update")
@Produces("application/json")
public Response update(MultipartBody multipartBody, @Context UriInfo requestUriInfo) {
LOGGER.trace("ENTERING: update");
Response response;
List<Attachment> attachmentList = multipartBody.getAllAttachments();
File newFile = null;
for (Attachment attachment : attachmentList) {
newFile = createFileFromAttachement(attachment);
}
try {
if (newFile != null) {
ZipFileApplicationDetails appDetails = ApplicationFileInstaller.getAppDetails(newFile);
if (appDetails != null) {
// lets get the existing app if it exists.
Application existingApplication = appService.getApplication(appDetails.getName());
// assume false until proved
boolean wasExistingAppStarted = false;
// otherwise.
if (existingApplication != null) {
wasExistingAppStarted = appService.isApplicationStarted(existingApplication);
appService.removeApplication(existingApplication);
}
appService.addApplication(newFile.toURI());
// if application was started before it was removed, lets try and start it.
if (wasExistingAppStarted) {
appService.startApplication(appDetails.getName());
}
} else {
throw new ApplicationServiceException("No Application details could be extracted from the provided file.");
}
} else {
throw new ApplicationServiceException("No file attachment provided.");
}
// we need to output valid JSON to the client so fileupload can correctly call
// done/fail callbacks correctly.
Response.ResponseBuilder responseBuilder = Response.ok("{\"status\":\"success\"}").type("application/json");
response = responseBuilder.build();
} catch (ApplicationServiceException e) {
LOGGER.warn("Unable to update an application on the server: {}", newFile, e);
Response.ResponseBuilder responseBuilder = Response.serverError();
response = responseBuilder.build();
}
LOGGER.trace("EXITING: update");
return response;
}
Aggregations