Java Code Examples for org.springframework.data.domain.Slice#getContent()

The following examples show how to use org.springframework.data.domain.Slice#getContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MySlice.java    From biliob_backend with MIT License 5 votes vote down vote up
public MySlice(Slice<T> slice) {
    this.content = slice.getContent();
    this.number = slice.getNumber();
    this.size = slice.getSize();
    this.last = slice.isLast();
    this.first = slice.isFirst();
    this.numberOfElements = slice.getNumberOfElements();
}
 
Example 2
Source File: EncryptionKeyRotator.java    From credhub with Apache License 2.0 5 votes vote down vote up
public void rotate() {
  final long start = System.currentTimeMillis();
  LOGGER.info("Starting encryption key rotation.");
  int rotatedRecordCount = 0;

  final long startingNotRotatedRecordCount = encryptedValueDataService
    .countAllByCanaryUuid(keySet.getActive().getUuid());

  final List<UUID> inactiveCanaries = keySet.getInactiveUuids();
  Slice<EncryptedValue> valuesEncryptedByOldKey = encryptedValueDataService
    .findByCanaryUuids(inactiveCanaries);
  while (valuesEncryptedByOldKey.hasContent()) {
    for (final EncryptedValue value : valuesEncryptedByOldKey.getContent()) {
      try {
        encryptedValueDataService.rotate(value);
        rotatedRecordCount++;
      } catch (final KeyNotFoundException e) {
        LOGGER.error("key not found for value, unable to rotate");
      }
    }
    valuesEncryptedByOldKey = encryptedValueDataService.findByCanaryUuids(inactiveCanaries);
  }

  final long finish = System.currentTimeMillis();
  final long duration = finish - start;
  final long endingNotRotatedRecordCount = startingNotRotatedRecordCount - rotatedRecordCount;

  if (rotatedRecordCount == 0 && endingNotRotatedRecordCount == 0) {
    LOGGER.info("Found no records in need of encryption key rotation.");
  } else {
    LOGGER.info("Finished encryption key rotation in " + duration + " milliseconds. Details:");
    LOGGER.info("  Successfully rotated " + rotatedRecordCount + " item(s)");
    LOGGER.info("  Skipped " + endingNotRotatedRecordCount
      + " item(s) due to missing master encryption key(s).");
  }

  encryptionKeyCanaryMapper.delete(inactiveCanaries);
}
 
Example 3
Source File: RolloutManagementTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Step("Finish three actions of the rollout group and delete two targets")
private void finishActionAndDeleteTargetsOfFirstRunningGroup(final Rollout createdRollout) {
    // finish group one by finishing targets and deleting targets
    final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
            createdRollout.getId(), Status.RUNNING);
    final List<JpaAction> runningActions = runningActionsSlice.getContent();
    finishAction(runningActions.get(0));
    finishAction(runningActions.get(1));
    finishAction(runningActions.get(2));
    targetManagement.delete(
            Arrays.asList(runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
}
 
Example 4
Source File: RolloutManagementTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Step("Finish one action of the rollout group and delete four targets")
private void finishActionAndDeleteTargetsOfSecondRunningGroup(final Rollout createdRollout) {
    final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
            createdRollout.getId(), Status.RUNNING);
    final List<JpaAction> runningActions = runningActionsSlice.getContent();
    finishAction(runningActions.get(0));
    targetManagement.delete(
            Arrays.asList(runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
                    runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));

}
 
Example 5
Source File: RolloutManagementTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Step("Delete all targets of the rollout group")
private void deleteAllTargetsFromThirdGroup(final Rollout createdRollout) {
    final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
            createdRollout.getId(), Status.SCHEDULED);
    final List<JpaAction> runningActions = runningActionsSlice.getContent();
    targetManagement.delete(Arrays.asList(runningActions.get(0).getTarget().getId(),
            runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
            runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
}
 
Example 6
Source File: QueryIT.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
@Test
public void findByIdLike() {
    Person robertDonat = new Person();
    robertDonat.setId("1940");
    robertDonat.setFirstname("Robert");
    robertDonat.setLastname("Donat");
    this.personMap.put(robertDonat.getId(), robertDonat);

    Person jamesStewart = new Person();
    jamesStewart.setId("1950");
    jamesStewart.setFirstname("James");
    jamesStewart.setLastname("Stewart");
    this.personMap.put(jamesStewart.getId(), jamesStewart);

    Person garyCooper = new Person();
    garyCooper.setId("1960");
    garyCooper.setFirstname("Gary");
    garyCooper.setLastname("Cooper");
    this.personMap.put(garyCooper.getId(), garyCooper);

    Person leonardoDiCaprio = new Person();
    leonardoDiCaprio.setId("2016");
    leonardoDiCaprio.setFirstname("Leonardo");
    leonardoDiCaprio.setLastname("DiCaprio");
    this.personMap.put(leonardoDiCaprio.getId(), leonardoDiCaprio);

    String PATTERN = "19%0";
    String[] EXPECTED_YEARS = {"1940", "1950", "1960"};
    Set<String> expectedYears = new TreeSet<>(asList(EXPECTED_YEARS));

    Pageable pageRequest = PageRequest.of(PAGE_0, SIZE_5);
    Slice<Person> pageResponse = this.personRepository.findByIdLike(PATTERN, pageRequest);
    int slice = 0;
    while (pageResponse != null) {

        assertThat("Slice " + slice + ", has content", pageResponse.hasContent(), equalTo(true));
        List<Person> pageMatches = pageResponse.getContent();
        assertThat("Slice " + slice + ", contains data", pageMatches.size(), greaterThan(0));

        pageMatches.forEach(person -> {
            String year = person.getId();
            assertThat("Year " + year + " expected", expectedYears.contains(year), equalTo(true));
            expectedYears.remove(year);
        });

        if (pageResponse.hasNext()) {
            assertThat("Slice " + slice + ", is full", pageMatches.size(), equalTo(SIZE_5));

            pageRequest = pageResponse.nextPageable();
            pageResponse = this.personRepository.findByIdLike(PATTERN, pageRequest);

            assertThat("Slice " + slice + ", expected next slice", pageResponse, notNullValue());
        } else {
            pageResponse = null;
        }
        slice++;
    }

    assertThat("All years matched", expectedYears, hasSize(0));
}
 
Example 7
Source File: QueryIT.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
@Test
public void findByIdGreaterThanEqualAndFirstnameGreaterThanAndFirstnameLessThanEqual() {
    String[] LASTNAMES = {"Benner"};

    Person bruceBenner2005 = new Person();
    bruceBenner2005.setId("2005");
    bruceBenner2005.setFirstname("Bruce");
    bruceBenner2005.setLastname("Benner");
    this.personMap.put(bruceBenner2005.getId(), bruceBenner2005);

    Person bruceBenner1989 = new Person();
    bruceBenner1989.setId("1989");
    bruceBenner1989.setFirstname("Bruce");
    bruceBenner1989.setLastname("Benner");
    this.personMap.put(bruceBenner1989.getId(), bruceBenner1989);

    Person alecBaldwin = new Person();
    alecBaldwin.setId("2000");
    alecBaldwin.setFirstname("Alec");
    alecBaldwin.setLastname("Bolduin");
    this.personMap.put(alecBaldwin.getId(), alecBaldwin);

    Person harrisonFord = new Person();
    harrisonFord.setId("2010");
    harrisonFord.setFirstname("Harrison");
    harrisonFord.setLastname("Ford");
    this.personMap.put(harrisonFord.getId(), harrisonFord);

    Set<String> lastnames = new TreeSet<>(asList(LASTNAMES));

    Pageable pageRequest = PageRequest.of(PAGE_0, 2);
    Slice<Person> pageResponse = this.personRepository
            .findByIdGreaterThanEqualAndFirstnameGreaterThanAndFirstnameLessThanEqual("1990", "A", "D", pageRequest);
    int slice = 0;
    while (pageResponse != null) {

        assertThat("Slice " + slice + ", has content", pageResponse.hasContent(), equalTo(true));

        List<Person> pageMatches = pageResponse.getContent();

        assertThat("Slice " + slice + ", contains a person", pageMatches.size(), equalTo(2));

        String lastname = pageMatches.get(0).getLastname();
        assertThat("Slice " + slice + ", lastname " + lastname + " expected", lastnames.contains(lastname), equalTo(true));
        lastnames.remove(lastname);

        if (pageResponse.hasNext()) {
            pageRequest = pageResponse.nextPageable();
            pageResponse = this.personRepository
                    .findByIdGreaterThanEqualAndFirstnameGreaterThanAndFirstnameLessThanEqual("1990", "I", "K", pageRequest);
        } else {
            pageResponse = null;
        }
        slice++;
    }

    assertThat("All lastnames matched", lastnames, hasSize(0));
}