use of org.eclipse.winery.repository.importing.CsarImportOptions 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, @ApiParam(value = "true: content of CSAR overwrites existing content. false (default): existing content is kept") @FormDataParam("overwrite") Boolean overwrite, @ApiParam(value = "true: validates the hash of the manifest file with the one stored in the accountability layer") @FormDataParam("validate") Boolean validate, @Context UriInfo uriInfo) {
LocalDateTime start = LocalDateTime.now();
// @formatter:on
CsarImporter importer;
IRepository repository = RepositoryFactory.getRepository();
if (Environments.getInstance().getUiConfig().getFeatures().get(YAML.toString())) {
if (repository instanceof GitBasedRepository) {
importer = new YamlCsarImporter((YamlRepository) ((GitBasedRepository) repository).getRepository());
} else {
importer = new YamlCsarImporter((YamlRepository) repository);
}
} else {
importer = new CsarImporter(repository);
}
CsarImportOptions options = new CsarImportOptions();
options.setOverwrite((overwrite != null) && overwrite);
options.setAsyncWPDParsing(false);
options.setValidate((validate != null) && validate);
ImportMetaInformation importMetaInformation;
try {
importMetaInformation = importer.readCSAR(uploadedInputStream, options);
} catch (Exception e) {
return Response.serverError().entity("Could not import CSAR").entity(e.getMessage()).build();
}
if (importMetaInformation.errors.isEmpty()) {
if (options.isValidate()) {
return Response.ok(importMetaInformation, MediaType.APPLICATION_JSON).build();
} else if (Objects.nonNull(importMetaInformation.entryServiceTemplate)) {
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(importMetaInformation.entryServiceTemplate));
LOGGER.debug("CSAR import lasted {}", Duration.between(LocalDateTime.now(), start).toString());
return Response.created(url).build();
} else {
LOGGER.debug("CSAR import lasted {}", Duration.between(LocalDateTime.now(), start).toString());
return Response.noContent().build();
}
} else {
LOGGER.debug("CSAR import lasted {}", Duration.between(LocalDateTime.now(), start).toString());
// In case there are errors, we send them as "bad request"
return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON).entity(importMetaInformation).build();
}
}
use of org.eclipse.winery.repository.importing.CsarImportOptions in project winery by eclipse.
the class MainResource method importDefinitions.
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_JSON)
public Response importDefinitions(InputStream is) throws IOException {
File toscaFile;
toscaFile = File.createTempFile("TOSCA", ".tosca");
FileUtils.copyInputStreamToFile(is, toscaFile);
CsarImporter importer = new CsarImporter(RepositoryFactory.getRepository());
List<String> errors = new ArrayList<>();
CsarImportOptions options = new CsarImportOptions();
options.setOverwrite(false);
options.setAsyncWPDParsing(true);
options.setValidate(false);
importer.importDefinitions(null, toscaFile.toPath(), errors, options);
if (errors.isEmpty()) {
return Response.noContent().build();
} else {
return Response.status(Status.BAD_REQUEST).entity(errors).build();
}
}
Aggregations