Search in sources :

Example 6 with Pair

use of org.eclipse.che.commons.lang.Pair in project che by eclipse.

the class PagingUtil method createLinkHeader.

/**
     * Generates link header value from the page object and base uri.
     * <a href="https://tools.ietf.org/html/rfc5988">The Link header spec</a>
     *
     * @param page
     *         the page used to generate link
     * @param uri
     *         the uri which is used for adding {@code skipCount} & {@code maxItems} query parameters
     * @return 'Link' header value
     * @throws NullPointerException
     *         when either {@code page} or {@code uri} is null
     */
public static String createLinkHeader(Page<?> page, URI uri) {
    requireNonNull(page, "Required non-null page");
    requireNonNull(uri, "Required non-null uri");
    final ArrayList<Pair<String, Page.PageRef>> pageRefs = new ArrayList<>(4);
    pageRefs.add(Pair.of("first", page.getFirstPageRef()));
    pageRefs.add(Pair.of("last", page.getLastPageRef()));
    if (page.hasPreviousPage()) {
        pageRefs.add(Pair.of("prev", page.getPreviousPageRef()));
    }
    if (page.hasNextPage()) {
        pageRefs.add(Pair.of("next", page.getNextPageRef()));
    }
    final UriBuilder ub = UriBuilder.fromUri(uri);
    return pageRefs.stream().map(refPair -> format("<%s>; rel=\"%s\"", ub.clone().replaceQueryParam("skipCount", refPair.second.getItemsBefore()).replaceQueryParam("maxItems", refPair.second.getPageSize()).build().toString(), refPair.first)).collect(joining(LINK_HEADER_SEPARATOR));
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) Page(org.eclipse.che.api.core.Page) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) Pair(org.eclipse.che.commons.lang.Pair) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) ArrayList(java.util.ArrayList) Matcher(java.util.regex.Matcher) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) Page(org.eclipse.che.api.core.Page) UriBuilder(javax.ws.rs.core.UriBuilder) Pair(org.eclipse.che.commons.lang.Pair)

Example 7 with Pair

use of org.eclipse.che.commons.lang.Pair in project che by eclipse.

the class FactoryDaoTest method shouldFindFactoryByEmbeddedAttributes.

@Test(dependsOnMethods = "shouldUpdateFactory")
public void shouldFindFactoryByEmbeddedAttributes() throws Exception {
    final List<Pair<String, String>> attributes = ImmutableList.of(Pair.of("policies.match", "match"), Pair.of("policies.create", "perClick"), Pair.of("workspace.defaultEnv", "env1"));
    final FactoryImpl factory1 = factories[1];
    final FactoryImpl factory3 = factories[3];
    factory1.getPolicies().setCreate("perAccount");
    factory3.getPolicies().setMatch("update");
    factoryDao.update(factory1);
    factoryDao.update(factory3);
    final List<FactoryImpl> result = factoryDao.getByAttribute(factories.length, 0, attributes);
    assertEquals(new HashSet<>(result), ImmutableSet.of(factories[0], factories[2], factories[4]));
}
Also used : FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Pair(org.eclipse.che.commons.lang.Pair) Test(org.testng.annotations.Test)

Example 8 with Pair

use of org.eclipse.che.commons.lang.Pair in project che by eclipse.

the class LocalVirtualFileTest method countsMd5Sums.

@Test
public void countsMd5Sums() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder(generateFolderName());
    VirtualFile file1 = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile file2 = folder.createFile(generateFileName(), "xxx");
    root.createFolder(generateFolderName());
    Set<Pair<String, String>> expected = newHashSet(Pair.of(countMd5Sum(file1), file1.getPath().subPath(folder.getPath()).toString()), Pair.of(countMd5Sum(file2), file2.getPath().subPath(folder.getPath()).toString()));
    assertEquals(expected, newHashSet(folder.countMd5Sums()));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Pair(org.eclipse.che.commons.lang.Pair) Test(org.junit.Test)

Example 9 with Pair

use of org.eclipse.che.commons.lang.Pair in project che by eclipse.

the class MavenModelReader method readMavenProject.

public MavenModelReaderResult readMavenProject(File pom, MavenServerManager serverManager) {
    Pair<ModelReadingResult, Pair<List<String>, List<String>>> readResult = readModel(pom);
    MavenModel model = readResult.first.model;
    model = serverManager.interpolateModel(model, pom.getParentFile());
    Pair<List<String>, List<String>> profilesPair = readResult.second;
    return new MavenModelReaderResult(model, profilesPair.first, profilesPair.first, readResult.first.problems, Collections.emptySet());
}
Also used : MavenModel(org.eclipse.che.maven.data.MavenModel) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Pair(org.eclipse.che.commons.lang.Pair)

Example 10 with Pair

use of org.eclipse.che.commons.lang.Pair in project che by eclipse.

the class UserLinksInjectorTest method shouldInjectLinks.

@Test
public void shouldInjectLinks() throws Exception {
    final UserDto userDto = DtoFactory.newDto(UserDto.class).withId("user123").withEmail("user@codenvy.com").withName("user");
    linksInjector.injectLinks(userDto, serviceContext);
    // [rel, method] pairs links
    final Set<Pair<String, String>> links = userDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
    final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", Constants.LINK_REL_SELF), Pair.of("GET", Constants.LINK_REL_CURRENT_USER), Pair.of("GET", Constants.LINK_REL_PROFILE), Pair.of("GET", Constants.LINK_REL_CURRENT_USER_SETTINGS), Pair.of("GET", Constants.LINK_REL_PREFERENCES), Pair.of("POST", Constants.LINK_REL_CURRENT_USER_PASSWORD)));
    assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Also used : InjectMocks(org.mockito.InjectMocks) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Listeners(org.testng.annotations.Listeners) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ServiceContext(org.eclipse.che.api.core.rest.ServiceContext) Mock(org.mockito.Mock) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Mockito.when(org.mockito.Mockito.when) Pair(org.eclipse.che.commons.lang.Pair) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) UriBuilderImpl(org.everrest.core.impl.uri.UriBuilderImpl) HashSet(java.util.HashSet) Arrays.asList(java.util.Arrays.asList) DtoFactory(org.eclipse.che.dto.server.DtoFactory) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Pair(org.eclipse.che.commons.lang.Pair) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Pair (org.eclipse.che.commons.lang.Pair)13 HashSet (java.util.HashSet)5 Test (org.testng.annotations.Test)5 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collectors (java.util.stream.Collectors)3 ServiceContext (org.eclipse.che.api.core.rest.ServiceContext)3 DtoFactory (org.eclipse.che.dto.server.DtoFactory)3 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)2 TypeLiteral (com.google.inject.TypeLiteral)2 List (java.util.List)2 Map (java.util.Map)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)2 UriBuilderImpl (org.everrest.core.impl.uri.UriBuilderImpl)2 Test (org.junit.Test)2 Mock (org.mockito.Mock)2 Mockito.when (org.mockito.Mockito.when)2