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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations