use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository 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.backend.filebased.GitBasedRepository in project winery by eclipse.
the class RepositoryFactory method reconfigure.
public static void reconfigure(GitBasedRepositoryConfiguration configuration) throws IOException, GitAPIException {
RepositoryFactory.gitBasedRepositoryConfiguration = configuration;
RepositoryFactory.fileBasedRepositoryConfiguration = null;
if (repositoryContainsMultiRepositoryConfiguration(configuration)) {
repository = new MultiRepository(configuration.getRepositoryPath().get());
} else if (Environments.getInstance().getRepositoryConfig().isTenantRepository()) {
repository = new TenantRepository(configuration.getRepositoryPath().get());
} else {
// if a repository root is specified, use it instead of the root specified in the config
AbstractFileBasedRepository localRepository = configuration.getRepositoryPath().isPresent() ? createXmlOrYamlRepository(configuration, configuration.getRepositoryPath().get()) : createXmlOrYamlRepository(configuration, Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot()));
repository = new GitBasedRepository(configuration, localRepository);
}
}
use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.
the class RepositoryResolverTest method getRepository.
@Test
public void getRepository() throws GitAPIException {
this.setRevisionTo("1f24de8867bf3df5d26b932abf4526c625d8502f");
Path resolverRepositoryPath = Paths.get(System.getProperty("java.io.tmpdir")).resolve("test-repository");
try {
GitBasedRepository resolverRepository = resolver.createRepository(resolverRepositoryPath.toFile());
assertEquals(59, resolverRepository.getNamespaceManager().getAllNamespaces().size());
SortedSet<NodeTypeId> allNodeTypes = resolverRepository.getAllDefinitionsChildIds(NodeTypeId.class);
assertEquals(45, allNodeTypes.size());
} catch (IOException | GitAPIException ex) {
ex.getStackTrace();
}
}
use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.
the class RestUtils method releaseVersion.
public static Response releaseVersion(DefinitionsChildId releasableComponent) {
ResourceResult result = new ResourceResult();
final IRepository repository = RepositoryFactory.getRepository();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasableComponent, repository);
if (version.isReleasable()) {
if (repository instanceof GitBasedRepository) {
try {
freezeVersion(releasableComponent);
version.setWorkInProgressVersion(0);
String newId = releasableComponent.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version;
DefinitionsChildId newComponent = BackendUtils.getDefinitionsChildId(releasableComponent.getClass(), releasableComponent.getNamespace().getDecoded(), newId, false);
result = duplicate(releasableComponent, newComponent);
BackendUtils.commit(newComponent, "Release", repository);
} catch (GitAPIException e) {
result.setStatus(Status.INTERNAL_SERVER_ERROR);
}
} else {
result.setStatus(Status.INTERNAL_SERVER_ERROR);
}
} else {
result.setStatus(Status.BAD_REQUEST);
}
return result.getResponse();
}
use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.
the class GitWebSocket method onMessage.
@OnMessage
public void onMessage(String message, Session session) {
try {
GitData data = JacksonProvider.mapper.readValue(message, GitData.class);
Map<String, Map<DiffEntry, String>> repoEntryList = new HashMap<>();
if (RepositoryFactory.getRepository() instanceof MultiRepository) {
IRepository gitRepo;
for (IRepository repo : ((MultiRepository) RepositoryFactory.getRepository()).getRepositories()) {
gitRepo = repo;
if (gitRepo instanceof GitBasedRepository) {
handleGitRepository((GitBasedRepository) gitRepo, data, repoEntryList);
}
}
setGitDifferences(repoEntryList);
} else if (RepositoryFactory.getRepository() instanceof GitBasedRepository) {
handleGitRepository((GitBasedRepository) RepositoryFactory.getRepository(), data, repoEntryList);
setGitDifferences(repoEntryList);
}
} catch (IOException e) {
writeInSession(session, "{ \"error\": \"Could not parse message!\" }");
}
}
Aggregations