Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

In this page you can find the example usage for org.springframework.data.domain PageImpl PageImpl.

Prototype

public PageImpl(List<T> content) 

Source Link

Document

Creates a new PageImpl with the given content.

Usage

From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryImpl.java

@Override
public Page<T> findAllByFilter(Filter filter, Pageable pageable, String projectName, String owner) {
    if (filter == null || pageable == null || projectName == null || owner == null) {
        return new PageImpl<>(new ArrayList<>());
    }//from   w ww .  ja  va  2 s  .  co m
    Query query = QueryBuilder.newBuilder().with(filter).with(pageable).build();
    query.addCriteria(getAllEntitiesCriteria(projectName, owner));
    return findPage(query, pageable);
}

From source file:de.appsolve.padelcampus.admin.controller.general.AdminGeneralModulesController.java

@Override
public ModelAndView showIndex(HttpServletRequest request, Pageable pageable,
        @RequestParam(required = false, name = "search") String search) {
    Page<Module> all = new PageImpl<>(moduleDAO.findAllRootModules());
    return getIndexView(all);
}

From source file:com.frank.search.solr.repository.support.SimpleSolrRepository.java

@Override
public Iterable<T> findAll() {
    int itemCount = (int) this.count();
    if (itemCount == 0) {
        return new PageImpl<T>(Collections.<T>emptyList());
    }/* ww w. jav  a  2  s .co  m*/
    return this.findAll(new SolrPageRequest(0, itemCount));
}

From source file:com.real.apps.shuttle.controller.VehicleControllerTest.java

@Test
public void shouldReturnThePageOfAllVehiclesWhenWorldIsLoggedIn() throws Exception {
    String licenseNumber = "Test License Number To List";
    final Vehicle vehicle = new Vehicle();
    vehicle.setLicenseNumber(licenseNumber);
    List<Vehicle> vehicles = Arrays.asList(vehicle);
    final Page<Vehicle> page = new PageImpl<>(vehicles);
    controller.setService(service);//from ww  w . java 2 s. c om

    context.checking(new Expectations() {
        {
            oneOf(service).page(skip, limit);
            will(returnValue(page));
        }
    });

    mockMvc.perform(get("/" + VIEW_PAGE + "/" + skip + "/" + limit).with(user(world(ObjectId.get()))))
            .andExpect(status().isOk()).andExpect(jsonPath("$.content[0].licenseNumber").value(licenseNumber));
    context.assertIsSatisfied();
}

From source file:io.pivotal.strepsirrhini.chaosloris.web.EventControllerTest.java

@Test
public void list() throws Exception {
    Application application = new Application(UUID.randomUUID());
    application.setId(-1L);//from w ww . j av  a  2s. co m

    Schedule schedule = new Schedule("0 0 * * * *", "hourly");
    schedule.setId(-2L);

    Chaos chaos = new Chaos(application, 0.2, schedule);
    chaos.setId(-3L);

    Event event = new Event(chaos, Instant.EPOCH, Collections.emptyList(), Integer.MIN_VALUE);
    event.setId(-4L);

    when(this.eventRepository.findAll(new PageRequest(0, 20)))
            .thenReturn(new PageImpl<>(Collections.singletonList(event)));

    this.mockMvc.perform(get("/events").accept(HAL_JSON)).andExpect(status().isOk())
            .andExpect(jsonPath("$.page").exists()).andExpect(jsonPath("$._embedded.events").value(hasSize(1)))
            .andExpect(jsonPath("$._links.self").exists());
}

From source file:it.reply.orchestrator.service.DeploymentServiceTest.java

@Test
public void getDeploymentsSuccessful() throws Exception {
    List<Deployment> deployments = ControllerTestUtils.createDeployments(5, false);

    Mockito.when(deploymentRepository.findAll((Pageable) null))
            .thenReturn(new PageImpl<Deployment>(deployments));

    Page<Deployment> pagedDeployment = deploymentService.getDeployments(null);

    Assert.assertEquals(pagedDeployment.getContent(), deployments);

}

From source file:curly.artifact.ArtifactServiceImpl.java

@Loggable
@SuppressWarnings("unused")
@HystrixCommand//from ww  w .jav  a 2 s .  c  om
private Optional<Page<Artifact>> defaultFindAll(Pageable pageable) {
    log.trace("Falling back with empty collection");
    return Optional.of(new PageImpl<>(Collections.emptyList()));
}

From source file:org.openlmis.fulfillment.service.referencedata.PeriodReferenceDataServiceTest.java

@Test
public void shouldFindPeriodsByIds() {
    // given/*from   w  w  w .j a va 2  s.c  om*/
    UUID id = UUID.randomUUID();
    UUID id2 = UUID.randomUUID();
    List<UUID> ids = Arrays.asList(id, id2);

    ProcessingPeriodDto period = generateInstance();
    period.setId(id);
    ProcessingPeriodDto anotherPeriod = generateInstance();
    anotherPeriod.setId(id2);

    Map<String, Object> payload = new HashMap<>();
    payload.put("id", ids);
    ResponseEntity response = mock(ResponseEntity.class);

    // when
    when(response.getBody()).thenReturn(new PageDto<>(new PageImpl<>(Arrays.asList(period, anotherPeriod))));
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class),
            any(ParameterizedTypeReference.class))).thenReturn(response);

    List<ProcessingPeriodDto> periods = service.findByIds(ids);

    // then
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(),
            any(ParameterizedTypeReference.class));
    assertTrue(periods.contains(period));
    assertTrue(periods.contains(anotherPeriod));

    String actualUrl = uriCaptor.getValue().toString();
    assertTrue(actualUrl.startsWith(service.getServiceUrl() + service.getUrl()));
    assertTrue(actualUrl.contains(id.toString()));
    assertTrue(actualUrl.contains(id2.toString()));

    assertAuthHeader(entityCaptor.getValue());
}

From source file:com.github.lothar.security.acl.elasticsearch.repository.AclElasticsearchRepository.java

@Override
public Iterable<T> findAll(Sort sort) {
    int itemCount = (int) this.count();
    if (itemCount == 0) {
        return new PageImpl<T>(Collections.<T>emptyList());
    }/*from  w w w  . j av  a  2s .c om*/
    SearchQuery query = new NativeSearchQueryBuilder() //
            .withQuery(and(matchAllQuery(), aclFilter())) //
            .withPageable(new PageRequest(0, itemCount, sort)) //
            .build();
    return elasticsearchOperations.queryForPage(query, getEntityClass());
}

From source file:org.apereo.openlrs.storage.inmemory.InMemoryStorage.java

@Override
public Page<OpenLRSEntity> findByContext(String context, Pageable pageable) {
    Collection<OpenLRSEntity> values = store.values();
    if (values != null && !values.isEmpty()) {
        List<OpenLRSEntity> filtered = null;
        for (OpenLRSEntity entity : values) {
            if (entity.toJSON().contains(context)) {
                if (filtered == null) {
                    filtered = new ArrayList<OpenLRSEntity>();
                }//  www .  j  a v  a2 s . c  o  m

                filtered.add(entity);
            }
        }
        if (filtered != null) {
            return new PageImpl<OpenLRSEntity>(filtered);
        }
    }
    return null;
}