use of org.eclipse.winery.repository.yaml.YamlRepository 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.yaml.YamlRepository in project winery by eclipse.
the class YamlCsarImporter method storeDefs.
private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
IRepository repo = RepositoryFactory.getRepository();
FromCanonical converter = null;
if (repo instanceof GitBasedRepository) {
GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
converter = new FromCanonical((YamlRepository) wrapper.getRepository());
} else if (repo instanceof YamlRepository) {
converter = new FromCanonical((YamlRepository) repo);
}
if (Objects.nonNull(converter)) {
YamlWriter writer = new YamlWriter();
writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
}
}
Aggregations