use of org.springframework.data.domain.Pageable in project goci by EBISPOT.
the class SolrIndexer method mapAssociations.
Integer mapAssociations() {
Sort sort = new Sort(new Sort.Order("id"));
Pageable pager = new PageRequest(0, pageSize, sort);
Page<Association> associationPage = associationService.findPublishedAssociations(pager);
associationMapper.map(associationPage.getContent());
while (associationPage.hasNext()) {
if (maxPages != -1 && associationPage.getNumber() >= maxPages - 1) {
break;
}
pager = pager.next();
associationPage = associationService.findPublishedAssociations(pager);
associationMapper.map(associationPage.getContent());
if (sysOutLogging) {
System.out.print(".");
}
}
return (int) associationPage.getTotalElements();
}
use of org.springframework.data.domain.Pageable in project goci by EBISPOT.
the class SolrIndexer method mapStudies.
Integer mapStudies() {
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "publicationDate"));
Pageable pager = new PageRequest(0, pageSize, sort);
Page<Study> studyPage = studyService.findPublishedStudies(pager);
studyMapper.map(studyPage.getContent());
while (studyPage.hasNext()) {
if (maxPages != -1 && studyPage.getNumber() >= maxPages - 1) {
break;
}
pager = pager.next();
studyPage = studyService.findPublishedStudies(pager);
studyMapper.map(studyPage.getContent());
if (sysOutLogging) {
System.out.print(".");
}
}
return (int) studyPage.getTotalElements();
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method search.
@Override
public ResourcesWrapper<WorkflowTaskInstanceDto> search(WorkflowFilterDto filter) {
Pageable pageable = null;
// get pageable setting from filter - backward compatibility
if (StringUtils.isNotEmpty(filter.getSortByFields())) {
Sort sort = null;
if (filter.isSortAsc()) {
sort = new Sort(Direction.ASC, filter.getSortByFields());
} else {
sort = new Sort(Direction.DESC, filter.getSortByFields());
}
pageable = new PageRequest(filter.getPageNumber(), filter.getPageSize(), sort);
} else {
pageable = new PageRequest(filter.getPageNumber(), filter.getPageSize());
}
filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
Page<WorkflowTaskInstanceDto> page = this.find(filter, pageable);
return new ResourcesWrapper<>(page.getContent(), page.getTotalElements(), page.getTotalPages(), filter.getPageNumber(), filter.getPageSize());
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class SchedulerController method find.
/**
* Finds scheduled tasks
*
* @return all tasks
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCHEDULER_READ + "')")
@ApiOperation(value = "Search scheduled tasks", nickname = "searchSchedulerTasks", tags = { SchedulerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }) })
@ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "string", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "string", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") })
public Resources<Task> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters, @PageableDefault Pageable pageable) {
String text = getParameterConverter().toString(parameters, DataFilter.PARAMETER_TEXT);
List<Task> tasks = schedulerService.getAllTasks().stream().filter(task -> {
// filter - like name or description only
return StringUtils.isEmpty(text) || task.getTaskType().getSimpleName().toLowerCase().contains(text.toLowerCase()) || (task.getDescription() != null && task.getDescription().toLowerCase().contains(text.toLowerCase()));
}).sorted((taskOne, taskTwo) -> {
Sort sort = pageable.getSort();
if (pageable.getSort() == null) {
return 0;
}
int compareAscValue = 0;
boolean asc = true;
// "naive" sort implementation
if (sort.getOrderFor(PROPERTY_TASK_TYPE) != null) {
asc = sort.getOrderFor(PROPERTY_TASK_TYPE).isAscending();
compareAscValue = taskOne.getTaskType().getSimpleName().compareTo(taskTwo.getTaskType().getSimpleName());
}
if (sort.getOrderFor(PROPERTY_DESCRIPTION) != null) {
asc = sort.getOrderFor(PROPERTY_DESCRIPTION).isAscending();
compareAscValue = taskOne.getDescription().compareTo(taskTwo.getDescription());
}
if (sort.getOrderFor(PROPERTY_INSTANCE_ID) != null) {
asc = sort.getOrderFor(PROPERTY_INSTANCE_ID).isAscending();
compareAscValue = taskOne.getInstanceId().compareTo(taskTwo.getInstanceId());
}
return asc ? compareAscValue : compareAscValue * -1;
}).collect(Collectors.toList());
// "naive" pagination
int first = pageable.getPageNumber() * pageable.getPageSize();
int last = pageable.getPageSize() + first;
List<Task> taskPage = tasks.subList(first < tasks.size() ? first : tasks.size() > 0 ? tasks.size() - 1 : 0, last < tasks.size() ? last : tasks.size());
//
return pageToResources(new PageImpl(taskPage, pageable, tasks.size()), Task.class);
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class IdentityReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
File temp = null;
FileOutputStream outputStream = null;
try {
// prepare temp file for json stream
temp = getAttachmentManager().createTempFile();
outputStream = new FileOutputStream(temp);
// write into json stream
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
// json will be array of identities
jGenerator.writeStartArray();
// form instance has useful methods to transform form values
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
// initialize filter by given form - transform to multi value map
// => form attribute defined above will be automaticaly mapped to identity filter
IdmIdentityFilter filter = new IdmIdentityFilter(formInstance.toMultiValueMap());
// report extends long running task - show progress by count and counter lrt attributes
counter = 0L;
// find a first page of identities
Pageable pageable = new PageRequest(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
do {
Page<IdmIdentityDto> identities = identityService.find(filter, pageable, IdmBasePermission.READ);
if (count == null) {
// report extends long running task - show progress by count and counter lrt attributes
count = identities.getTotalElements();
}
boolean canContinue = true;
for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
// write single identity into json
getMapper().writeValue(jGenerator, i.next());
//
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
}
// iterate while next page of identities is available
pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
} while (pageable != null);
//
// close array of identities
jGenerator.writeEndArray();
} finally {
// close json stream
jGenerator.close();
}
// save create temp file with array of identities in json as attachment
return createAttachment(report, new FileInputStream(temp));
} catch (IOException ex) {
throw new ReportGenerateException(report.getName(), ex);
} finally {
// just for sure - jGenerator should close stream itself
IOUtils.closeQuietly(outputStream);
FileUtils.deleteQuietly(temp);
}
}
Aggregations