Example usage for org.springframework.data.domain Page getContent

List of usage examples for org.springframework.data.domain Page getContent

Introduction

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

Prototype

List<T> getContent();

Source Link

Document

Returns the page content as List .

Usage

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method order by name.
 *//*from w  w  w  .j a  v  a  2s.c o m*/
@Test
public void testGetClustersOrderBysName() {
    final Pageable name = new PageRequest(0, 10, Sort.Direction.DESC, "name");
    final Page<Command> commands = this.service.getCommands(null, null, null, null, name);
    Assert.assertEquals(3, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method order by a collection field should return the order by default value (updated).
 *///from w w w. jav  a  2  s  . c  om
@Ignore
@Test
public void testGetClustersOrderBysCollectionField() {
    final Pageable tags = new PageRequest(0, 10, Sort.Direction.DESC, "tags");
    final Page<Command> commands = this.service.getCommands(null, null, null, null, tags);
    Assert.assertEquals(3, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method./*www .j  a v  a2  s.co  m*/
 */
@Test
public void testGetCommandsByStatuses() {
    final Set<CommandStatus> statuses = Sets.newHashSet(CommandStatus.INACTIVE, CommandStatus.DEPRECATED);
    final Page<Command> commands = this.service.getCommands(null, null, statuses, null, PAGE);
    Assert.assertEquals(2, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method order by an invalid field should return the order by default value (updated).
 *//*ww  w  .  j  av  a2s  .c  o m*/
@Test(expected = PropertyReferenceException.class)
public void testGetClustersOrderBysInvalidField() {
    final Pageable invalid = new PageRequest(0, 10, Sort.Direction.DESC, "I'mNotAValidField");
    final Page<Command> commands = this.service.getCommands(null, null, null, null, invalid);
    Assert.assertEquals(3, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method./*from w w w.j  av a  2 s. c  o  m*/
 */
@Test
public void testGetCommandsByName() {
    final Page<Command> commands = this.service.getCommands(COMMAND_2_NAME, null, null, null, PAGE);
    Assert.assertEquals(1, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method with ascending sort.
 *//*from   www  . ja  va 2  s .  co  m*/
@Test
public void testGetClustersAscending() {
    final Pageable ascending = new PageRequest(0, 10, Sort.Direction.ASC, "updated");
    //Default to order by Updated
    final Page<Command> commands = this.service.getCommands(null, null, null, null, ascending);
    Assert.assertEquals(3, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method.//ww  w . ja v  a 2  s. com
 */
@Test
public void testGetCommandsByUserName() {
    final Page<Command> commands = this.service.getCommands(null, COMMAND_1_USER, null, null, PAGE);
    Assert.assertEquals(2, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java

/**
 * Test the get commands method.//  www .j  av  a 2  s .  c o  m
 */
@Test
public void testGetCommandsByTags() {
    final Set<String> tags = Sets.newHashSet("prod");
    Page<Command> commands = this.service.getCommands(null, null, null, tags, PAGE);
    Assert.assertEquals(3, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new));

    tags.add("pig");
    commands = this.service.getCommands(null, null, null, tags, PAGE);
    Assert.assertEquals(2, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));

    tags.clear();
    tags.add("hive");
    commands = this.service.getCommands(null, null, null, tags, PAGE);
    Assert.assertEquals(1, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));

    tags.add("somethingThatWouldNeverReallyExist");
    commands = this.service.getCommands(null, null, null, tags, PAGE);
    Assert.assertTrue(commands.getContent().isEmpty());

    tags.clear();
    commands = this.service.getCommands(null, null, null, tags, PAGE);
    Assert.assertEquals(3, commands.getNumberOfElements());
    Assert.assertEquals(COMMAND_2_ID,
            commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_3_ID,
            commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new));
    Assert.assertEquals(COMMAND_1_ID,
            commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new));
}

From source file:co.bluepass.web.rest.ClubResource.java

/**
 * Gets all.//from   www  . j  a va2s  . c  om
 *
 * @param offset the offset
 * @param limit  the limit
 * @param name   the name
 * @return the all
 * @throws URISyntaxException the uri syntax exception
 */
@RequestMapping(value = "/clubs", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Club>> getAll(@RequestParam(value = "page", required = false) Integer offset,
        @RequestParam(value = "per_page", required = false) Integer limit,
        @RequestParam(value = "name", required = false) String name) throws URISyntaxException {
    Page<Club> page = null;

    if (StringUtils.isNotEmpty(name)) {
        page = clubRepository.findByNameLike("%" + name + "%",
                PaginationUtil.generatePageRequest(offset, limit, "id", "desc"));
    } else {
        page = clubRepository.findAll(PaginationUtil.generatePageRequest(offset, limit, "id", "desc"));
    }

    for (Club club : page) {
        List<Feature> features = featureRepository.findByClub(club);
        if (features != null && !features.isEmpty()) {
            List<CommonCode> featureList = new ArrayList<CommonCode>();
            for (Feature feature : features) {
                featureList.add(feature.getCode());
            }
            club.setFeatures(featureList);
        }
    }

    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/clubs", offset, limit);
    return new ResponseEntity<List<Club>>(page.getContent(), headers, HttpStatus.OK);
}

From source file:com.excilys.ebi.bank.web.controller.account.operations.OperationsTableConverter.java

@Override
public OperationsTable convert(Page<Operation> source) {

    /*//from www .  ja  v a  2s.  c  om
     * For the brave souls who get this far: You are the chosen ones, the
     * valiant knights of programming who toil away, without rest, fixing
     * our most awful code. To you, true saviors, kings of men, I say this:
     * never gonna give you up, never gonna let you down, never gonna run
     * around and desert you. Never gonna make you cry, never gonna say
     * goodbye. Never gonna tell a lie and hurt you.
     */

    OperationsTable table = new OperationsTable();
    table.setNumber(source.getNumber());
    table.setNumberOfElements(source.getNumberOfElements());
    table.setSize(source.getSize());
    table.setTotalElements(source.getTotalElements());
    table.setTotalPages(source.getTotalPages());
    table.setHasContent(source.hasContent());
    table.setHasNextPage(source.hasNextPage());
    table.setHasPreviousPage(source.hasPreviousPage());
    table.setFirstPage(source.isFirstPage());
    table.setLastPage(source.isLastPage());
    table.setStartIndex(source.getTotalElements() > 0 ? source.getSize() * source.getNumber() + 1 : 0);
    table.setPageIndex(source.getTotalElements() > 0 ? source.getNumber() + 1 : 0);
    table.setEndIndex(source.getSize() * source.getNumber() + source.getNumberOfElements());

    for (Operation operation : source.getContent()) {

        OperationsLine line = new OperationsLine();
        line.setAmount(operation.getAmount());
        line.setDate(operation.getDate().toString("MM/dd/yyyy"));
        line.setName(operation.getName());
        line.setStatus(operation.getStatus().getId());
        table.getLines().add(line);
    }

    for (int i = 0; i < source.getSize() - source.getNumberOfElements(); i++) {
        table.getEmptyLines().add(StringUtils.EMPTY);
    }

    return table;
}