Search in sources :

Example 26 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

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(FactoryDto factory, ServiceContext serviceContext, String userName) {
    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 snippet links
        links.addAll(SNIPPET_TYPES.stream().map(snippet -> createLink(HttpMethod.GET, uriBuilder.clone().path(FactoryService.class, "getFactorySnippet").queryParam("type", snippet).build(factoryId).toString(), null, TEXT_PLAIN, SNIPPET_REL_ATT + '/' + snippet)).collect(toList()));
        // 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);
        // creation of links for analytics
        links.add(createLink(HttpMethod.GET, uriBuilder.clone().path("analytics").path("public-metric/factory_used").queryParam("factory", createWorkspace.getHref()).toString(), null, TEXT_PLAIN, ACCEPTED_REL_ATT));
    }
    if (!Strings.isNullOrEmpty(factory.getName()) && !Strings.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);
    }
    return links;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) LinkedList(java.util.LinkedList) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink)

Example 27 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class FactoryLinksHelper method createLinks.

/**
     * Creates factory links and links for retrieving factory images.
     *
     * @param images
     *         a set of factory images
     * @param serviceContext
     *         the context to retrieve factory service base URI
     * @return list of factory and factory images links
     */
public static List<Link> createLinks(FactoryDto factory, Set<FactoryImage> images, ServiceContext serviceContext, String userName) {
    final List<Link> links = new LinkedList<>(createLinks(factory, serviceContext, userName));
    final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
    final String factoryId = factory.getId();
    // creation of links to retrieve images
    links.addAll(images.stream().map(image -> createLink(HttpMethod.GET, uriBuilder.clone().path(FactoryService.class, "getImage").queryParam("imgId", image.getName()).build(factoryId).toString(), null, image.getMediaType(), IMAGE_REL_ATT)).collect(toList()));
    return links;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) LinkedList(java.util.LinkedList) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink)

Example 28 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ProjectServiceLinksInjectorTest method verifyProjectLinks.

@Test
public void verifyProjectLinks() throws Exception {
    ProjectConfigDto projectConfigDto = DtoFactory.newDto(ProjectConfigDto.class);
    projectConfigDto.withPath(PROJECT_PATH);
    ProjectConfigDto result = projectServiceLinksInjector.injectProjectLinks(projectConfigDto, serviceContext);
    final List<Link> links = result.getLinks();
    assertEquals(4, links.size());
    final Link updateProjectLink = links.get(0);
    assertNotNull(updateProjectLink);
    assertEquals("localhost:8080/project/project_path", updateProjectLink.getHref());
    assertEquals(HttpMethod.PUT, updateProjectLink.getMethod());
    assertEquals(LINK_REL_UPDATE_PROJECT, updateProjectLink.getRel());
    assertEquals(APPLICATION_JSON, updateProjectLink.getConsumes());
    assertEquals(APPLICATION_JSON, updateProjectLink.getProduces());
    final Link childrenProjectLink = links.get(1);
    assertNotNull(childrenProjectLink);
    assertEquals("localhost:8080/project/children/project_path", childrenProjectLink.getHref());
    assertEquals(HttpMethod.GET, childrenProjectLink.getMethod());
    assertEquals(LINK_REL_CHILDREN, childrenProjectLink.getRel());
    assertEquals(APPLICATION_JSON, childrenProjectLink.getProduces());
    final Link treeProjectLink = links.get(2);
    assertNotNull(treeProjectLink);
    assertEquals("localhost:8080/project/tree/project_path", treeProjectLink.getHref());
    assertEquals(HttpMethod.GET, treeProjectLink.getMethod());
    assertEquals(LINK_REL_TREE, treeProjectLink.getRel());
    assertEquals(APPLICATION_JSON, treeProjectLink.getProduces());
    final Link deleteProjectLink = links.get(3);
    assertNotNull(deleteProjectLink);
    assertEquals("localhost:8080/project/project_path", deleteProjectLink.getHref());
    assertEquals(HttpMethod.DELETE, deleteProjectLink.getMethod());
    assertEquals(LINK_REL_DELETE, deleteProjectLink.getRel());
}
Also used : ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Link(org.eclipse.che.api.core.rest.shared.dto.Link) Test(org.testng.annotations.Test)

Example 29 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ProjectServiceTest method validateProjectLinks.

private void validateProjectLinks(ProjectConfigDto project) {
    List<Link> links = project.getLinks();
    for (Link link : links) {
        switch(link.getHref()) {
            case "update project":
                assertNotNull(link);
                assertEquals(link.getMethod(), PUT);
                assertEquals(link.getHref(), "http://localhost:8080/api/project" + project.getPath());
                assertEquals(link.getConsumes(), APPLICATION_JSON);
                assertEquals(link.getProduces(), APPLICATION_JSON);
                break;
            case "children":
                assertNotNull(link);
                assertEquals(link.getMethod(), GET);
                assertEquals(link.getHref(), "http://localhost:8080/api/project/children" + project.getPath());
                assertEquals(link.getProduces(), APPLICATION_JSON);
                break;
            case "tree":
                assertNotNull(link);
                assertEquals(link.getMethod(), GET);
                assertEquals(link.getHref(), "http://localhost:8080/api/project/tree" + project.getPath());
                assertEquals(link.getProduces(), APPLICATION_JSON);
                break;
            case "modules":
                assertNotNull(link);
                assertEquals(link.getMethod(), GET);
                assertEquals(link.getHref(), "http://localhost:8080/api/project/modules" + project.getPath());
                assertEquals(link.getProduces(), APPLICATION_JSON);
                break;
            case "zipball sources":
                assertNotNull(link);
                assertEquals(link.getMethod(), GET);
                assertEquals(link.getHref(), "http://localhost:8080/api/project/export" + project.getPath());
                assertEquals(link.getProduces(), APPLICATION_ZIP);
                break;
            case "delete":
                assertNotNull(link);
                assertEquals(link.getMethod(), DELETE);
                assertEquals(link.getHref(), "http://localhost:8080/api/project" + project.getPath());
                break;
        }
    }
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 30 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ProjectServiceTest method validateFolderLinks.

private void validateFolderLinks(ItemReference item) {
    Link link = item.getLink("children");
    assertNotNull(link);
    assertEquals(link.getMethod(), GET);
    assertEquals(link.getHref(), "http://localhost:8080/api/project/children" + item.getPath());
    assertEquals(link.getProduces(), APPLICATION_JSON);
    link = item.getLink("tree");
    assertNotNull(link);
    assertEquals(link.getMethod(), GET);
    assertEquals(link.getHref(), "http://localhost:8080/api/project/tree" + item.getPath());
    assertEquals(link.getProduces(), APPLICATION_JSON);
    link = item.getLink("delete");
    assertNotNull(link);
    assertEquals(link.getMethod(), DELETE);
    assertEquals(link.getHref(), "http://localhost:8080/api/project" + item.getPath());
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Aggregations

Link (org.eclipse.che.api.core.rest.shared.dto.Link)40 UriBuilder (javax.ws.rs.core.UriBuilder)15 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)13 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)11 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)7 LinkParameter (org.eclipse.che.api.core.rest.shared.dto.LinkParameter)7 LinkedList (java.util.LinkedList)4 HttpMethod (javax.ws.rs.HttpMethod)2 Produces (javax.ws.rs.Produces)2 Description (org.eclipse.che.api.core.rest.annotations.Description)2 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1