Search in sources :

Example 1 with Link

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);
}
Also used : HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) StackComponentDto(org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto) Gson(com.google.gson.Gson) ServerConf2Dto(org.eclipse.che.api.workspace.shared.dto.ServerConf2Dto) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) List(java.util.List) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) Link(org.eclipse.che.api.core.rest.shared.dto.Link) ProjectProblemDto(org.eclipse.che.api.workspace.shared.dto.ProjectProblemDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Test(org.testng.annotations.Test)

Example 2 with Link

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));
}
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 3 with Link

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);
}
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 4 with Link

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);
}
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 5 with Link

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

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