Search in sources :

Example 46 with PageRequest

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();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)

Example 47 with PageRequest

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);
    }
}
Also used : MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 48 with PageRequest

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"));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) QSort(org.springframework.data.querydsl.QSort) ArrayList(java.util.ArrayList) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.Test)

Example 49 with PageRequest

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));
    }
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort)

Example 50 with PageRequest

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);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AttachmentState(org.obiba.mica.file.AttachmentState) Pageable(org.springframework.data.domain.Pageable) Async(org.springframework.scheduling.annotation.Async) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5