use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method findDuplicities.
/**
* Find duplicity requests. All request in state IN_PROGRESS for same UID and
* system. For all operation types.
*
* @param request
* @return
*/
@Override
public List<VsRequestDto> findDuplicities(String uid, UUID systemId) {
VsRequestFilter filter = new VsRequestFilter();
filter.setUid(uid);
filter.setSystemId(systemId);
filter.setState(VsRequestState.IN_PROGRESS);
Sort sort = new Sort(Direction.DESC, VsRequest_.created.getName());
return this.find(filter, new PageRequest(0, Integer.MAX_VALUE, sort)).getContent();
}
use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testRemoveDuplicateEventsForTheSameOwner.
@Test
public void testRemoveDuplicateEventsForTheSameOwner() {
List<IdmEntityEventDto> events = new ArrayList<>();
try {
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.disable(EntityEventDeleteExecutedProcessor.class);
int count = 10;
//
// create events
MockOwner mockOwner = new MockOwner();
for (int i = 0; i < count; i++) {
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType(mockOwner.getClass().getCanonicalName());
entityEvent.setEventType("empty");
entityEvent.setOwnerId((UUID) mockOwner.getId());
entityEvent.setContent(mockOwner);
entityEvent.setInstanceId(configurationService.getInstanceId());
entityEvent.setResult(new OperationResultDto(OperationState.CREATED));
entityEvent.setPriority(PriorityType.NORMAL);
events.add(entityEventService.save(entityEvent));
}
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType(MockOwner.class.getCanonicalName());
filter.setStates(Lists.newArrayList(OperationState.CREATED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
//
// execute
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// wait for executed events
helper.waitForResult(res -> {
return entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements() != 0;
}, 1000, Integer.MAX_VALUE);
//
// check what happened
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
Assert.assertEquals(1, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
} finally {
// the last one
entityEventService.delete(events.get(9));
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.enable(EntityEventDeleteExecutedProcessor.class);
}
}
use of org.springframework.data.domain.PageRequest in project spring-data-mongodb by spring-projects.
the class AbstractPersonRepositoryIntegrationTests method shouldSupportSortingWithQSortByQueryDslOrderSpecifier.
// DATAMONGO-1085
@Test
public void shouldSupportSortingWithQSortByQueryDslOrderSpecifier() throws Exception {
repository.deleteAll();
List<Person> persons = new ArrayList<Person>();
for (int i = 0; i < 3; i++) {
Person person = new Person(String.format("Siggi %s", i), "Bar", 30);
person.setAddress(new Address(String.format("Street %s", i), "12345", "SinCity"));
persons.add(person);
}
repository.saveAll(persons);
PageRequest pageRequest = PageRequest.of(0, 2, new QSort(person.address.street.desc()));
Iterable<Person> result = repository.findAll(pageRequest);
assertThat(result, is(Matchers.<Person>iterableWithSize(2)));
assertThat(result.iterator().next().getFirstname(), is("Siggi 2"));
}
use of org.springframework.data.domain.PageRequest in project plumdo-work by wengwh.
the class BaseResource method getPageable.
protected Pageable getPageable(Map<String, String> requestParams) {
int page = 1;
if (requestParams.containsKey("pageNum")) {
page = ObjectUtils.convertToInteger(requestParams.get("pageNum"), 1);
}
int size = 10;
if (requestParams.containsKey("pageSize")) {
size = ObjectUtils.convertToInteger(requestParams.get("pageSize"), 10);
}
Order order = null;
if (ObjectUtils.isNotEmpty(requestParams.get("sortName"))) {
String sortName = requestParams.get("sortName");
String sortOrder = requestParams.get("sortOrder");
if (ObjectUtils.isEmpty(sortOrder) || sortOrder.equals("desc")) {
order = new Order(Direction.DESC, sortName);
} else {
order = new Order(Direction.ASC, sortName);
}
}
if (order == null) {
return new PageRequest(page - 1, size);
} else {
return new PageRequest(page - 1, size, new Sort(order));
}
}
use of org.springframework.data.domain.PageRequest in project mica2 by obiba.
the class FileIndexer method reIndexAll.
@Async
@Subscribe
public void reIndexAll(IndexFilesEvent event) {
if (indexer.hasIndex(Indexer.ATTACHMENT_DRAFT_INDEX))
indexer.dropIndex(Indexer.ATTACHMENT_DRAFT_INDEX);
if (indexer.hasIndex(Indexer.ATTACHMENT_PUBLISHED_INDEX))
indexer.dropIndex(Indexer.ATTACHMENT_PUBLISHED_INDEX);
Pageable pageRequest = new PageRequest(0, 100);
Page<AttachmentState> attachments;
do {
attachments = attachmentStateRepository.findAll(pageRequest);
attachments.forEach(a -> {
if (FileUtils.isDirectory(a))
return;
indexer.index(Indexer.ATTACHMENT_DRAFT_INDEX, a);
if (a.getPublishedAttachment() != null) {
indexer.index(Indexer.ATTACHMENT_PUBLISHED_INDEX, a);
}
});
} while ((pageRequest = attachments.nextPageable()) != null);
}
Aggregations