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;
}
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;
}
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());
}
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;
}
}
}
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());
}
Aggregations