use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.
the class StackLoaderTest method dtoShouldBeSerialized.
@Test
public void dtoShouldBeSerialized() {
StackDto stackDtoDescriptor = newDto(StackDto.class).withName("nameWorkspaceConfig");
StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("java").withVersion("1.8");
stackDtoDescriptor.setComponents(Collections.singletonList(stackComponentDto));
stackDtoDescriptor.setTags(Arrays.asList("some teg1", "some teg2"));
stackDtoDescriptor.setDescription("description");
stackDtoDescriptor.setId("someId");
stackDtoDescriptor.setScope("scope");
stackDtoDescriptor.setCreator("Created in Codenvy");
Map<String, String> attributes = new HashMap<>();
attributes.put("attribute1", "valute attribute1");
Link link = newDto(Link.class).withHref("some url").withMethod("get").withRel("someRel").withConsumes("consumes").withProduces("produces");
HashMap<String, List<String>> projectMap = new HashMap<>();
projectMap.put("test", Arrays.asList("test", "test2"));
ProjectProblemDto projectProblem = newDto(ProjectProblemDto.class).withCode(100).withMessage("message");
SourceStorageDto sourceStorageDto = newDto(SourceStorageDto.class).withType("some type").withParameters(attributes).withLocation("location");
ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName("project").withPath("somePath").withAttributes(projectMap).withType("maven type").withDescription("some project description").withLinks(Collections.singletonList(link)).withMixins(Collections.singletonList("mixin time")).withProblems(Collections.singletonList(projectProblem)).withSource(sourceStorageDto);
EnvironmentRecipeDto environmentRecipe = newDto(EnvironmentRecipeDto.class).withContent("some content").withContentType("some content type").withType("someType");
Map<String, ServerConf2Dto> servers = new HashMap<>();
servers.put("server1Ref", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("http").withProperties(singletonMap("key", "value")));
Map<String, ExtendedMachineDto> machines = new HashMap<>();
machines.put("someMachineName", newDto(ExtendedMachineDto.class).withAgents(Arrays.asList("agent1", "agent2")).withServers(servers).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L)));
EnvironmentDto environmentDto = newDto(EnvironmentDto.class).withRecipe(environmentRecipe).withMachines(machines);
CommandDto commandDto = newDto(CommandDto.class).withType("command type").withName("command name").withCommandLine("command line");
WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("SomeWorkspaceConfig").withDescription("some workspace").withLinks(Collections.singletonList(link)).withDefaultEnv("some Default Env name").withProjects(Collections.singletonList(projectConfigDto)).withEnvironments(singletonMap("name", environmentDto)).withCommands(Collections.singletonList(commandDto));
stackDtoDescriptor.setWorkspaceConfig(workspaceConfigDto);
Gson GSON = new GsonBuilder().create();
GSON.fromJson(stackDtoDescriptor.toString(), StackImpl.class);
}
use of org.eclipse.che.api.core.rest.shared.dto.Link 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 org.eclipse.che.api.core.rest.shared.dto.Link 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 org.eclipse.che.api.core.rest.shared.dto.Link 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 org.eclipse.che.api.core.rest.shared.dto.Link 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