Search in sources :

Example 36 with Link

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

the class UserLinksInjector method injectLinks.

public UserDto injectLinks(UserDto userDto, ServiceContext serviceContext) {
    final UriBuilder uriBuilder = serviceContext.getBaseUriBuilder();
    final List<Link> links = new ArrayList<>(6);
    links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(UserService.class).path(UserService.class, "getById").build(userDto.getId()).toString(), null, APPLICATION_JSON, LINK_REL_SELF));
    links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(UserService.class).path(UserService.class, "getCurrent").build().toString(), null, APPLICATION_JSON, LINK_REL_CURRENT_USER));
    links.add(LinksHelper.createLink(HttpMethod.POST, uriBuilder.clone().path(UserService.class).path(UserService.class, "updatePassword").build().toString(), APPLICATION_FORM_URLENCODED, null, LINK_REL_CURRENT_USER_PASSWORD));
    links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(ProfileService.class).path(ProfileService.class, "getById").build(userDto.getId()).toString(), null, APPLICATION_JSON, LINK_REL_PROFILE));
    links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(UserService.class).path(UserService.class, "getSettings").build().toString(), null, APPLICATION_JSON, LINK_REL_CURRENT_USER_SETTINGS));
    links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(PreferencesService.class).path(PreferencesService.class, "find").build().toString(), null, APPLICATION_JSON, LINK_REL_PREFERENCES));
    return userDto.withLinks(links);
}
Also used : ArrayList(java.util.ArrayList) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 37 with Link

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

the class SshService method injectLinks.

private SshPairDto injectLinks(SshPairDto sshPairDto) {
    final UriBuilder uriBuilder = getServiceContext().getServiceUriBuilder();
    final Link getPairsLink = LinksHelper.createLink("GET", uriBuilder.clone().path(getClass(), "getPairs").build(sshPairDto.getService()).toString(), APPLICATION_JSON, LINK_REL_GET_PAIR);
    final Link removePairLink = LinksHelper.createLink("DELETE", uriBuilder.clone().path(getClass(), "removePair").build(sshPairDto.getService(), sshPairDto.getName()).toString(), APPLICATION_JSON, LINK_REL_REMOVE_PAIR);
    final Link getPairLink = LinksHelper.createLink("GET", uriBuilder.clone().path(getClass(), "getPair").build(sshPairDto.getService(), sshPairDto.getName()).toString(), APPLICATION_JSON, LINK_REL_GET_PAIR);
    return sshPairDto.withLinks(Arrays.asList(getPairsLink, removePairLink, getPairLink));
}
Also used : 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 38 with Link

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

the class MachineItemTest method shouldReturnTerminalUrl.

@Test
public void shouldReturnTerminalUrl() {
    String terminalHref = "terminalHref";
    Link someLink = mock(Link.class);
    Link terminalLink = mock(Link.class);
    List<Link> links = new ArrayList<>(2);
    links.add(someLink);
    links.add(terminalLink);
    when(terminalLink.getHref()).thenReturn(terminalHref);
    when(terminalLink.getRel()).thenReturn(TERMINAL_REFERENCE);
    when(descriptor.getLinks()).thenReturn(links);
    machine = new MachineItem(descriptor);
    String terminalUrl = machine.getTerminalUrl();
    assertEquals(terminalHref, terminalUrl);
}
Also used : ArrayList(java.util.ArrayList) Link(org.eclipse.che.api.core.rest.shared.dto.Link) Test(org.junit.Test)

Example 39 with Link

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

the class OAuthAuthenticationService method getRegisteredAuthenticators.

/**
     * Gets list of installed OAuth authenticators.
     *
     * @return list of installed OAuth authenticators
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Set<OAuthAuthenticatorDescriptor> getRegisteredAuthenticators() {
    Set<OAuthAuthenticatorDescriptor> result = new HashSet<>();
    final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder().clone().path(getClass());
    for (String name : providers.getRegisteredProviderNames()) {
        final List<Link> links = new LinkedList<>();
        links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(getClass(), "authenticate").build().toString(), null, null, "Authenticate URL", newDto(LinkParameter.class).withName("oauth_provider").withRequired(true).withDefaultValue(name), newDto(LinkParameter.class).withName("mode").withRequired(true).withDefaultValue("federated_login")));
        result.add(newDto(OAuthAuthenticatorDescriptor.class).withName(name).withLinks(links));
    }
    return result;
}
Also used : OAuthAuthenticatorDescriptor(org.eclipse.che.security.oauth.shared.dto.OAuthAuthenticatorDescriptor) LinkParameter(org.eclipse.che.api.core.rest.shared.dto.LinkParameter) UriBuilder(javax.ws.rs.core.UriBuilder) LinkedList(java.util.LinkedList) Link(org.eclipse.che.api.core.rest.shared.dto.Link) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with Link

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

the class RemoteOAuthTokenProvider method getToken.

/** {@inheritDoc} */
@Override
public OAuthToken getToken(String oauthProviderName, String userId) throws IOException {
    if (userId.isEmpty()) {
        return null;
    }
    try {
        UriBuilder ub = UriBuilder.fromUri(apiEndpoint).path(OAuthAuthenticationService.class).path(OAuthAuthenticationService.class, "token").queryParam("oauth_provider", oauthProviderName);
        Link getTokenLink = DtoFactory.newDto(Link.class).withHref(ub.build().toString()).withMethod("GET");
        return httpJsonRequestFactory.fromLink(getTokenLink).request().asDto(OAuthToken.class);
    } catch (NotFoundException ne) {
        LOG.warn("Token not found for user {}", userId);
        return null;
    } catch (ServerException | UnauthorizedException | ForbiddenException | ConflictException | BadRequestException e) {
        LOG.warn("Exception on token retrieval, message : {}", e.getLocalizedMessage());
        return null;
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) 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