Search in sources :

Example 1 with ImportMetaInformation

use of org.eclipse.winery.repository.importing.ImportMetaInformation in project winery by eclipse.

the class MainResource method importCSAR.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Imports the given CSAR (sent by simplesinglefileupload.jsp)")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", responseHeaders = @ResponseHeader(description = "If the CSAR could be partially imported, the points where it failed are returned in the body")) })
public // @formatter:off
Response importCSAR(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("overwrite") @ApiParam(value = "true: content of CSAR overwrites existing content. false (default): existing content is kept") Boolean overwrite, @Context UriInfo uriInfo) {
    // @formatter:on
    CsarImporter importer = new CsarImporter();
    boolean ow;
    ow = (overwrite != null) && overwrite;
    ImportMetaInformation importMetaInformation;
    try {
        importMetaInformation = importer.readCSAR(uploadedInputStream, ow, true);
    } catch (Exception e) {
        return Response.serverError().entity("Could not import CSAR").entity(e.getMessage()).build();
    }
    if (importMetaInformation.errors.isEmpty()) {
        if (importMetaInformation.entryServiceTemplate.isPresent()) {
            URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(importMetaInformation.entryServiceTemplate.get()));
            return Response.created(url).build();
        } else {
            return Response.noContent().build();
        }
    } else {
        // In case there are errors, we send them as "bad request"
        return Response.status(Status.BAD_REQUEST).entity(importMetaInformation.errors).build();
    }
}
Also used : CsarImporter(org.eclipse.winery.repository.importing.CsarImporter) URI(java.net.URI) IOException(java.io.IOException) ImportMetaInformation(org.eclipse.winery.repository.importing.ImportMetaInformation)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 CsarImporter (org.eclipse.winery.repository.importing.CsarImporter)1 ImportMetaInformation (org.eclipse.winery.repository.importing.ImportMetaInformation)1