Search in sources :

Example 16 with FactoryDevfileV2Dto

use of org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto in project devspaces-images by redhat-developer.

the class FactoryLinksHelper method createLinks.

/**
 * Creates factory links.
 *
 * @param serviceContext the context to retrieve factory service base URI
 * @return list of factory links
 */
public static List<Link> createLinks(FactoryMetaDto factory, ServiceContext serviceContext, AdditionalFilenamesProvider additionalFilenamesProvider, String userName, String repositoryUrl) {
    final List<Link> links = new LinkedList<>();
    final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
    final String factoryId = factory.getId();
    if (factoryId != null) {
        // creation of link to retrieve factory
        links.add(createLink(HttpMethod.GET, uriBuilder.clone().path(FactoryService.class, "getFactory").build(factoryId).toString(), null, APPLICATION_JSON, RETRIEVE_FACTORY_REL_ATT));
        // creation of accept factory link
        final Link createWorkspace = createLink(HttpMethod.GET, uriBuilder.clone().replacePath("f").queryParam("id", factoryId).build().toString(), null, TEXT_HTML, FACTORY_ACCEPTANCE_REL_ATT);
        links.add(createWorkspace);
    }
    if (!isNullOrEmpty(factory.getName()) && !isNullOrEmpty(userName)) {
        // creation of accept factory link by name and creator
        final Link createWorkspaceFromNamedFactory = createLink(HttpMethod.GET, uriBuilder.clone().replacePath("f").queryParam("name", factory.getName()).queryParam("user", userName).build().toString(), null, TEXT_HTML, NAMED_FACTORY_ACCEPTANCE_REL_ATT);
        links.add(createWorkspaceFromNamedFactory);
    }
    if (factory instanceof FactoryDevfileV2Dto) {
        // link to devfile source
        if (!isNullOrEmpty(factory.getSource())) {
            links.add(createLink(HttpMethod.GET, uriBuilder.clone().replacePath("api").path(ScmService.class).path(ScmService.class, "resolveFile").queryParam("repository", repositoryUrl).queryParam("file", factory.getSource()).build(factoryId).toString(), factory.getSource() + " content"));
        }
        if (((FactoryDevfileV2Dto) factory).getScmInfo() != null) {
            // additional files links
            for (String additionalFile : additionalFilenamesProvider.get()) {
                links.add(createLink(HttpMethod.GET, uriBuilder.clone().replacePath("api").path(ScmService.class).path(ScmService.class, "resolveFile").queryParam("repository", repositoryUrl).queryParam("file", additionalFile).build(factoryId).toString(), additionalFile + " content"));
            }
        }
    }
    return links;
}
Also used : FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) UriBuilder(jakarta.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink) LinkedList(java.util.LinkedList)

Aggregations

FactoryDevfileV2Dto (org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto)16 Test (org.testng.annotations.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 IOException (java.io.IOException)8 Collections (java.util.Collections)8 Collections.emptyMap (java.util.Collections.emptyMap)8 Collections.singletonList (java.util.Collections.singletonList)8 Collections.singletonMap (java.util.Collections.singletonMap)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 Optional (java.util.Optional)8 ApiException (org.eclipse.che.api.core.ApiException)8 ServerException (org.eclipse.che.api.core.ServerException)8 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)8 ExtendedError (org.eclipse.che.api.core.rest.shared.dto.ExtendedError)8 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)8 ScmUnauthorizedException (org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException)8