Search in sources :

Example 1 with ZipFileApplicationDetails

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;
}
Also used : Response(javax.ws.rs.core.Response) ZipFileApplicationDetails(org.codice.ddf.admin.application.service.impl.ZipFileApplicationDetails) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) File(java.io.File) Application(org.codice.ddf.admin.application.service.Application) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

File (java.io.File)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)1 Application (org.codice.ddf.admin.application.service.Application)1 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)1 ZipFileApplicationDetails (org.codice.ddf.admin.application.service.impl.ZipFileApplicationDetails)1