Search in sources :

Example 6 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method testCreatedEventsRemoveDuplicatesByProps.

@Test
public void testCreatedEventsRemoveDuplicatesByProps() {
    List<IdmEntityEventDto> highEvents = new ArrayList<>();
    DateTime created = new DateTime();
    UUID ownerId = UUID.randomUUID();
    IdmEntityEventDto highEventOne = new IdmEntityEventDto(UUID.randomUUID());
    highEventOne.setCreated(created.minusMillis(21));
    highEventOne.setPriority(PriorityType.HIGH);
    highEventOne.setOwnerId(ownerId);
    highEventOne.getProperties().put("one", "one");
    highEvents.add(highEventOne);
    IdmEntityEventDto highEventTwo = new IdmEntityEventDto(UUID.randomUUID());
    highEventTwo.setCreated(created.minusMillis(11));
    highEventTwo.setPriority(PriorityType.HIGH);
    highEventTwo.setOwnerId(ownerId);
    highEventTwo.getProperties().put("one", "one");
    highEvents.add(highEventTwo);
    IdmEntityEventDto highEventThree = new IdmEntityEventDto(UUID.randomUUID());
    highEventThree.setCreated(created.minusMillis(2));
    highEventThree.setPriority(PriorityType.HIGH);
    highEventThree.setOwnerId(ownerId);
    highEventThree.getProperties().put("one", "oneU");
    highEvents.add(highEventThree);
    when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.HIGH), any())).thenReturn(new PageImpl<>(highEvents));
    // 
    when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(new ArrayList<>()));
    // 
    List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
    Assert.assertEquals(1, events.size());
    Assert.assertTrue(events.stream().anyMatch(e -> e.getId().equals(highEventTwo.getId())));
    verify(entityEventService).delete(highEventOne);
}
Also used : IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Mock(org.mockito.Mock) HashMap(java.util.HashMap) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) ArrayList(java.util.ArrayList) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) InjectMocks(org.mockito.InjectMocks) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) Mockito.verify(org.mockito.Mockito.verify) Serializable(java.io.Serializable) Matchers.any(org.mockito.Matchers.any) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmEntityEventRepository(eu.bcvsolutions.idm.core.model.repository.IdmEntityEventRepository) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) Assert(org.junit.Assert) PageImpl(org.springframework.data.domain.PageImpl) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) ArrayList(java.util.ArrayList) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 7 with PageImpl

use of org.springframework.data.domain.PageImpl in project ArachneCentralAPI by OHDSI.

the class BaseDataSourceServiceImpl method suggestDataSource.

@Override
public Page<DS> suggestDataSource(final String query, final Long studyId, final Long userId, PageRequest pageRequest) {
    List<DataSourceStatus> BAD_STATUSES = Arrays.asList(DataSourceStatus.DELETED, DataSourceStatus.DECLINED);
    final String[] split = query.trim().split(" ");
    CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<DS> cq = cb.createQuery(getType());
    Root<DS> root = cq.from(getType());
    Subquery sq = cq.subquery(Long.class);
    Root<StudyDataSourceLink> dsLink = sq.from(StudyDataSourceLink.class);
    sq.select(dsLink.get("dataSource").get("id"));
    sq.where(cb.and(cb.equal(dsLink.get("study").get("id"), studyId), cb.not(dsLink.get("status").in(BAD_STATUSES))));
    cq.select(root);
    // TRUE
    Predicate nameClause = cb.conjunction();
    if (split.length > 1 || (split.length == 1 && !split[0].equals(""))) {
        List<Predicate> predictList = new ArrayList<>();
        for (String one : split) {
            predictList.add(cb.like(cb.lower(root.get("name")), one + "%"));
            predictList.add(cb.like(cb.lower(root.get("dataNode").get("name")), one + "%"));
        }
        nameClause = cb.or(predictList.toArray(new Predicate[] {}));
    }
    cq.where(cb.and(cb.not(root.get("id").in(sq)), nameClause, cb.isNull(root.get("deleted")), cb.isTrue(root.get("published")), cb.isFalse(root.get("dataNode").get("virtual"))));
    TypedQuery<DS> typedQuery = this.entityManager.createQuery(cq);
    List<DS> list = typedQuery.setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList();
    return new PageImpl<>(list, pageRequest, list.size());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PageImpl(org.springframework.data.domain.PageImpl) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) ArrayList(java.util.ArrayList) Subquery(javax.persistence.criteria.Subquery) Predicate(javax.persistence.criteria.Predicate) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus)

Example 8 with PageImpl

use of org.springframework.data.domain.PageImpl in project fastjson by alibaba.

the class PageToJSONTest method test_page.

public void test_page() throws Exception {
    List<Post> postList = new ArrayList<Post>();
    {
        postList.add(new Post(1001));
    }
    Page<Post> page = new PageImpl(postList);
    JSONObject obj = (JSONObject) JSON.toJSON(page);
    Assert.assertNotNull(obj);
    Assert.assertEquals(1, obj.getJSONArray("content").size());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList)

Example 9 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricProcessInstanceService method find.

@Override
public Page<WorkflowHistoricProcessInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    String processDefinitionId = filter.getProcessDefinitionId();
    String processInstanceId = filter.getProcessInstanceId();
    Map<String, Object> equalsVariables = filter.getEqualsVariables();
    HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
    boolean trimmed = true;
    if (processInstanceId != null) {
        // Process variables will be included only for get by instance ID
        trimmed = false;
        query.includeProcessVariables();
        query.processInstanceId(processInstanceId);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getSuperProcessInstanceId() != null) {
        query.superProcessInstanceId(filter.getSuperProcessInstanceId());
    }
    if (filter.getProcessDefinitionKey() != null) {
        // For case when we have only process id, we will convert him to key
        query.processDefinitionKey(convertProcessIdToKey(filter.getProcessDefinitionKey()));
    }
    if (filter.getName() != null) {
        // with case sensitive
        query.variableValueLike(WorkflowHistoricProcessInstanceService.PROCESS_INSTANCE_NAME, "%" + filter.getName() + "%");
    }
    if (equalsVariables != null) {
        for (Entry<String, Object> entry : equalsVariables.entrySet()) {
            query.variableValueEquals(entry.getKey(), entry.getValue());
        }
    }
    // TODO: refactor and use username/id from filter
    if (!securityService.isAdmin()) {
        // Applicant and Implementer is added to involved user after process
        // (subprocess) started. This modification allow not use OR clause.
        query.involvedUser(securityService.getCurrentId().toString());
    }
    String fieldForSort = null;
    boolean ascSort = false;
    boolean descSort = false;
    if (pageable != null) {
        Sort sort = pageable.getSort();
        if (sort != null) {
            for (Order order : sort) {
                if (!StringUtils.isEmpty(order.getProperty())) {
                    // TODO: now is implemented only one property sort
                    fieldForSort = order.getProperty();
                    if (order.getDirection() == Direction.ASC) {
                        ascSort = true;
                    } else if (order.getDirection() == Direction.DESC) {
                        descSort = true;
                    }
                    break;
                }
            }
        }
    }
    if (WorkflowHistoricProcessInstanceService.SORT_BY_START_TIME.equals(fieldForSort)) {
        query.orderByProcessInstanceStartTime();
    } else if (WorkflowHistoricProcessInstanceService.SORT_BY_END_TIME.equals(fieldForSort)) {
        query.orderByProcessInstanceEndTime();
    } else {
        query.orderByProcessDefinitionId();
        // there must be default order
        query.asc();
    }
    if (ascSort) {
        query.asc();
    }
    if (descSort) {
        query.desc();
    }
    long count = query.count();
    // it's possible that pageable is null
    List<HistoricProcessInstance> processInstances = null;
    if (pageable == null) {
        processInstances = query.list();
    } else {
        processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    }
    List<WorkflowHistoricProcessInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (HistoricProcessInstance instance : processInstances) {
            dtos.add(toResource(instance, trimmed));
        }
    }
    return new PageImpl<WorkflowHistoricProcessInstanceDto>(dtos, pageable, count);
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Example 10 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricTaskInstanceService method find.

@Override
public Page<WorkflowHistoricTaskInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    String processDefinitionId = filter.getProcessDefinitionId();
    String processInstanceId = filter.getProcessInstanceId();
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    query.includeProcessVariables();
    if (filter.getId() != null) {
        query.taskId(filter.getId().toString());
    }
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(filter.getProcessDefinitionKey());
    }
    // historic task instance ... admin can see all historic tasks every time
    if (!securityService.isAdmin()) {
        // TODO Now we don't have detail for historic task. When we need detail, then we will need create different projection (detail can't be read by applicant)
        String loggedUserId = securityService.getCurrentId().toString();
        query.taskInvolvedUser(loggedUserId);
    }
    String fieldForSort = null;
    boolean ascSort = false;
    boolean descSort = false;
    if (pageable != null) {
        Sort sort = pageable.getSort();
        if (sort != null) {
            for (Order order : sort) {
                if (!StringUtils.isEmpty(order.getProperty())) {
                    // TODO: now is implemented only one property sort
                    fieldForSort = order.getProperty();
                    if (order.getDirection() == Direction.ASC) {
                        ascSort = true;
                    } else if (order.getDirection() == Direction.DESC) {
                        descSort = true;
                    }
                    break;
                }
            }
        }
    }
    if (WorkflowHistoricTaskInstanceService.SORT_BY_CREATE_TIME.equals(fieldForSort)) {
        query.orderByTaskCreateTime();
    } else if (WorkflowHistoricTaskInstanceService.SORT_BY_END_TIME.equals(fieldForSort)) {
        query.orderByHistoricTaskInstanceEndTime();
    } else {
        query.orderByProcessDefinitionId();
        // there must be default order
        query.asc();
    }
    if (ascSort) {
        query.asc();
    }
    if (descSort) {
        query.desc();
    }
    long count = query.count();
    List<HistoricTaskInstance> processInstances = null;
    if (pageable == null) {
        processInstances = query.list();
    } else {
        processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    }
    List<WorkflowHistoricTaskInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (HistoricTaskInstance instance : processInstances) {
            dtos.add(toResource(instance));
        }
    }
    return new PageImpl<WorkflowHistoricTaskInstanceDto>(dtos, pageable, count);
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Aggregations

PageImpl (org.springframework.data.domain.PageImpl)18 ArrayList (java.util.ArrayList)9 PageRequest (org.springframework.data.domain.PageRequest)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 List (java.util.List)4 Test (org.junit.Test)4 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)3 IdmProcessedTaskItemFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter)3 UUID (java.util.UUID)3 Page (org.springframework.data.domain.Page)3 Pageable (org.springframework.data.domain.Pageable)3 Sort (org.springframework.data.domain.Sort)3 Order (org.springframework.data.domain.Sort.Order)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)2 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)2 LookupService (eu.bcvsolutions.idm.core.api.service.LookupService)2 Collectors (java.util.stream.Collectors)2 Resources (org.springframework.hateoas.Resources)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Lists (com.google.common.collect.Lists)1