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