Search in sources :

Example 6 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project che by eclipse.

the class ProjectServiceLinksInjector method injectFolderLinks.

/**
     * Adds links for working with a folder.
     * Operations which are supported:
     * <p>get children</p>
     * <p>get tree</p>
     * <p>delete</p>
     *
     * @param itemReference
     *         information about node
     * @param serviceContext
     *         context of {@link ProjectService}
     * @return node with injected folder's links
     */
public ItemReference injectFolderLinks(ItemReference itemReference, ServiceContext serviceContext) {
    final UriBuilder uriBuilder = getUriBuilder(serviceContext);
    final List<Link> links = new ArrayList<>();
    final String relPath = itemReference.getPath().substring(1);
    links.add(createLink(GET, tuneUrl(uriBuilder.clone().path(ProjectService.class).path(ProjectService.class, "getChildren").build(new String[] { relPath }, false)), APPLICATION_JSON, LINK_REL_CHILDREN));
    links.add(createLink(GET, tuneUrl(uriBuilder.clone().path(ProjectService.class).path(ProjectService.class, "getTree").build(new String[] { relPath }, false)), APPLICATION_JSON, LINK_REL_TREE));
    links.add(createLink(DELETE, tuneUrl(uriBuilder.clone().path(ProjectService.class).path(ProjectService.class, "delete").build(new String[] { relPath }, false)), LINK_REL_DELETE));
    return itemReference.withLinks(links);
}
Also used : ArrayList(java.util.ArrayList) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink)

Example 7 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project che by eclipse.

the class WorkspaceServiceLinksInjector method injectLinks.

public SnapshotDto injectLinks(SnapshotDto snapshotDto, ServiceContext serviceContext) {
    final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
    final Link machineLink = createLink("GET", serviceContext.getBaseUriBuilder().path("/machine/{id}").build(snapshotDto.getId()).toString(), APPLICATION_JSON, "get machine");
    final Link workspaceLink = createLink("GET", uriBuilder.clone().path(WorkspaceService.class, "getByKey").build(snapshotDto.getWorkspaceId()).toString(), APPLICATION_JSON, LIN_REL_GET_WORKSPACE);
    final Link workspaceSnapshotLink = createLink("GET", uriBuilder.clone().path(WorkspaceService.class, "getSnapshot").build(snapshotDto.getWorkspaceId()).toString(), APPLICATION_JSON, LINK_REL_SELF);
    return snapshotDto.withLinks(asList(machineLink, workspaceLink, workspaceSnapshotLink));
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink)

Example 8 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project che by eclipse.

the class WorkspaceServiceLinksInjector method injectLinks.

public WorkspaceDto injectLinks(WorkspaceDto workspace, ServiceContext serviceContext) {
    final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
    final List<Link> links = new ArrayList<>();
    // add common workspace links
    links.add(createLink("GET", uriBuilder.clone().path(WorkspaceService.class, "getByKey").build(workspace.getId()).toString(), LINK_REL_SELF));
    links.add(createLink("POST", uriBuilder.clone().path(WorkspaceService.class, "startById").build(workspace.getId()).toString(), APPLICATION_JSON, LINK_REL_START_WORKSPACE));
    links.add(createLink("DELETE", uriBuilder.clone().path(WorkspaceService.class, "delete").build(workspace.getId()).toString(), APPLICATION_JSON, LINK_REL_REMOVE_WORKSPACE));
    links.add(createLink("GET", uriBuilder.clone().path(WorkspaceService.class, "getWorkspaces").build().toString(), APPLICATION_JSON, GET_ALL_USER_WORKSPACES));
    links.add(createLink("GET", uriBuilder.clone().path(WorkspaceService.class, "getSnapshot").build(workspace.getId()).toString(), APPLICATION_JSON, LINK_REL_GET_SNAPSHOT));
    //TODO here we add url to IDE with workspace name not good solution do it here but critical for this task  https://jira.codenvycorp.com/browse/IDEX-3619
    final URI ideUri = uriBuilder.clone().replacePath("").path(workspace.getNamespace()).path(workspace.getConfig().getName()).build();
    links.add(createLink("GET", ideUri.toString(), TEXT_HTML, LINK_REL_IDE_URL));
    // add workspace channel links
    final Link workspaceChannelLink = createLink("GET", serviceContext.getBaseUriBuilder().path("ws").scheme("https".equals(ideUri.getScheme()) ? "wss" : "ws").build().toString(), null);
    final LinkParameter channelParameter = newDto(LinkParameter.class).withName("channel").withRequired(true);
    links.add(cloneDto(workspaceChannelLink).withRel(LINK_REL_GET_WORKSPACE_EVENTS_CHANNEL).withParameters(singletonList(cloneDto(channelParameter).withDefaultValue("workspace:" + workspace.getId()))));
    links.add(cloneDto(workspaceChannelLink).withRel(LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL).withParameters(singletonList(cloneDto(channelParameter).withDefaultValue(format(ENVIRONMENT_OUTPUT_CHANNEL_TEMPLATE, workspace.getId())))));
    links.add(cloneDto(workspaceChannelLink).withRel(LINK_REL_ENVIRONMENT_STATUS_CHANNEL).withParameters(singletonList(cloneDto(channelParameter).withDefaultValue(format(ENVIRONMENT_STATUS_CHANNEL_TEMPLATE, workspace.getId())))));
    // add links for running workspace
    injectRuntimeLinks(workspace, ideUri, uriBuilder, serviceContext);
    return workspace.withLinks(links);
}
Also used : LinkParameter(org.eclipse.che.api.core.rest.shared.dto.LinkParameter) ArrayList(java.util.ArrayList) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink)

Example 9 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project che by eclipse.

the class StackService method asStackDto.

private StackDto asStackDto(StackImpl stack) {
    final UriBuilder builder = getServiceContext().getServiceUriBuilder();
    List<Link> links = new ArrayList<>();
    final Link removeLink = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeStack").build(stack.getId()).toString(), LINK_REL_REMOVE_STACK);
    final Link getLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getStack").build(stack.getId()).toString(), APPLICATION_JSON, LINK_REL_GET_STACK_BY_ID);
    links.add(removeLink);
    links.add(getLink);
    StackIcon stackIcon = stack.getStackIcon();
    if (stackIcon != null) {
        Link deleteIcon = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeIcon").build(stack.getId()).toString(), stackIcon.getMediaType(), LINK_REL_DELETE_ICON);
        Link getIconLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getIcon").build(stack.getId()).toString(), stackIcon.getMediaType(), LINK_REL_GET_ICON);
        links.add(deleteIcon);
        links.add(getIconLink);
    }
    return asDto(stack).withLinks(links);
}
Also used : ArrayList(java.util.ArrayList) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 10 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project che by eclipse.

the class RecipeService method asRecipeDescriptor.

/**
     * Transforms {@link ManagedRecipe} to {@link RecipeDescriptor}.
     */
private RecipeDescriptor asRecipeDescriptor(ManagedRecipe recipe) {
    final RecipeDescriptor descriptor = DtoFactory.getInstance().createDto(RecipeDescriptor.class).withId(recipe.getId()).withName(recipe.getName()).withType(recipe.getType()).withScript(recipe.getScript()).withCreator(recipe.getCreator()).withTags(recipe.getTags());
    final UriBuilder builder = getServiceContext().getServiceUriBuilder();
    final Link removeLink = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeRecipe").build(recipe.getId()).toString(), LINK_REL_REMOVE_RECIPE);
    final Link scriptLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getRecipeScript").build(recipe.getId()).toString(), TEXT_PLAIN, LINK_REL_GET_RECIPE_SCRIPT);
    descriptor.setLinks(asList(scriptLink, removeLink));
    return descriptor;
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)123 URI (java.net.URI)45 Test (org.junit.Test)42 HashMap (java.util.HashMap)15 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 PUT (javax.ws.rs.PUT)11 IOException (java.io.IOException)10 Path (javax.ws.rs.Path)10 ArrayList (java.util.ArrayList)8 Produces (javax.ws.rs.Produces)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 GET (javax.ws.rs.GET)7 URL (java.net.URL)6 ServerException (org.eclipse.che.api.core.ServerException)6 POST (javax.ws.rs.POST)5 ApiException (org.eclipse.che.api.core.ApiException)4 WorkspaceService (org.eclipse.che.api.workspace.server.WorkspaceService)4 ExternalTestContainerFactory (org.glassfish.jersey.test.external.ExternalTestContainerFactory)4 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)3