Search in sources :

Example 21 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class RemoteServiceDescriptor method getLinks.

/** @see ServiceDescriptor#getLinks() */
public List<Link> getLinks() throws ServerException, IOException {
    final List<Link> links = getServiceDescriptor().getLinks();
    // always copy list and links itself!
    final List<Link> copy = new ArrayList<>(links.size());
    for (Link link : links) {
        copy.add(DtoFactory.getInstance().clone(link));
    }
    return copy;
}
Also used : ArrayList(java.util.ArrayList) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 22 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class Service method generateServiceDescriptor.

private ServiceDescriptor generateServiceDescriptor(UriInfo uriInfo, Class<? extends Service> service) {
    final List<Link> links = new ArrayList<>();
    for (Method method : service.getMethods()) {
        final GenerateLink generateLink = method.getAnnotation(GenerateLink.class);
        if (generateLink != null) {
            try {
                links.add(generateLinkForMethod(uriInfo, generateLink.rel(), method));
            } catch (RuntimeException ignored) {
            }
        }
    }
    final Description description = service.getAnnotation(Description.class);
    final ServiceDescriptor dto = createServiceDescriptor().withHref(uriInfo.getRequestUriBuilder().replaceQuery(null).build().toString()).withLinks(links).withVersion(Constants.API_VERSION);
    if (description != null) {
        dto.setDescription(description.value());
    }
    return dto;
}
Also used : Description(org.eclipse.che.api.core.rest.annotations.Description) ServiceDescriptor(org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor) ArrayList(java.util.ArrayList) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) HttpMethod(javax.ws.rs.HttpMethod) Method(java.lang.reflect.Method) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 23 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ServiceDescriptorTest method testLinkInfo.

@Test
public void testLinkInfo() throws Exception {
    Link link = getLink("echo");
    Assert.assertEquals(link.getMethod(), HttpMethod.GET);
    Assert.assertEquals(link.getHref(), SERVICE_URI + "/my_method");
    Assert.assertEquals(link.getProduces(), MediaType.TEXT_PLAIN);
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 24 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class MachineEntityImpl method getTerminalUrl.

public String getTerminalUrl() {
    for (Link link : machineLinks) {
        if (Constants.TERMINAL_REFERENCE.equals(link.getRel())) {
            return link.getHref();
        }
    }
    //should not be
    final String message = "Reference " + Constants.TERMINAL_REFERENCE + " not found in " + machineConfig.getName() + " description";
    Log.error(getClass(), message);
    throw new RuntimeException(message);
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 25 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class MachineEntityImpl method getExecAgentUrl.

public String getExecAgentUrl() {
    for (Link link : machineLinks) {
        if (Constants.EXEC_AGENT_REFERENCE.equals(link.getRel())) {
            return link.getHref();
        }
    }
    //should not be
    final String message = "Reference " + Constants.EXEC_AGENT_REFERENCE + " not found in " + machineConfig.getName() + " description";
    Log.error(getClass(), message);
    throw new RuntimeException(message);
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link)

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