Search in sources :

Example 1 with GitBasedRepository

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();
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) CsarImportOptions(org.eclipse.winery.repository.importing.CsarImportOptions) YamlCsarImporter(org.eclipse.winery.repository.importing.YamlCsarImporter) CsarImporter(org.eclipse.winery.repository.importing.CsarImporter) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) URI(java.net.URI) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) YamlCsarImporter(org.eclipse.winery.repository.importing.YamlCsarImporter) IOException(java.io.IOException) ImportMetaInformation(org.eclipse.winery.repository.importing.ImportMetaInformation) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with GitBasedRepository

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);
    }
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) AbstractFileBasedRepository(org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository) TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository)

Example 3 with GitBasedRepository

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();
    }
}
Also used : Path(java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IOException(java.io.IOException) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) Test(org.junit.jupiter.api.Test)

Example 4 with GitBasedRepository

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();
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) IRepository(org.eclipse.winery.repository.backend.IRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 5 with GitBasedRepository

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!\" }");
    }
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) HashMap(java.util.HashMap) GitData(org.eclipse.winery.repository.rest.datatypes.GitData) IOException(java.io.IOException) IRepository(org.eclipse.winery.repository.backend.IRepository) HashMap(java.util.HashMap) Map(java.util.Map) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) OnMessage(javax.websocket.OnMessage)

Aggregations

GitBasedRepository (org.eclipse.winery.repository.backend.filebased.GitBasedRepository)11 IRepository (org.eclipse.winery.repository.backend.IRepository)5 MultiRepository (org.eclipse.winery.repository.filebased.MultiRepository)5 IOException (java.io.IOException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 WineryVersion (org.eclipse.winery.common.version.WineryVersion)2 YamlRepository (org.eclipse.winery.repository.yaml.YamlRepository)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OnMessage (javax.websocket.OnMessage)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1