use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processContracts.
private Set<UUID> processContracts(IdmRoleTreeNodeDto automaticRole) {
Set<UUID> processedRoleRequests = new HashSet<>();
//
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setWorkPosition(automaticRole.getTreeNode());
filter.setRecursionType(automaticRole.getRecursionType());
filter.setValidNowOrInFuture(Boolean.TRUE);
//
Pageable pageable = PageRequest.of(0, getPageSize(), new Sort(Direction.ASC, BaseEntity.PROPERTY_ID));
//
boolean canContinue = true;
//
do {
Page<IdmIdentityContractDto> contracts = identityContractService.find(filter, pageable);
//
for (Iterator<IdmIdentityContractDto> i = contracts.iterator(); i.hasNext() && canContinue; ) {
IdmIdentityContractDto contract = i.next();
UUID contractId = contract.getId();
//
if (!requireNewTransaction()) {
processedRoleRequests.addAll(processContract(contract, automaticRole));
} else {
TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//
try {
template.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
processedRoleRequests.addAll(processContract(contract, automaticRole));
}
});
} catch (UnexpectedRollbackException ex) {
// Just log for sure ... exception solved in new transaction, but this lower transaction is marked as roll-back.
LOG.debug("Statefull process [{}] processed contract [{}] failed", getClass().getSimpleName(), contractId, ex);
}
}
//
if (!this.updateState()) {
LOG.debug("Task [{}] was canceled.", getLongRunningTaskId());
// return null => not continue with role removal
return null;
}
}
canContinue &= contracts.hasNext();
pageable = contracts.nextPageable();
//
} while (canContinue);
//
return processedRoleRequests;
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processPositions.
private Set<UUID> processPositions(IdmRoleTreeNodeDto automaticRole) {
Set<UUID> processedRoles = new HashSet<>();
//
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setWorkPosition(automaticRole.getTreeNode());
filter.setRecursionType(automaticRole.getRecursionType());
filter.setValidNowOrInFuture(Boolean.TRUE);
Pageable pageable = PageRequest.of(0, getPageSize(), new Sort(Direction.ASC, BaseEntity.PROPERTY_ID));
boolean canContinue = true;
//
do {
Page<IdmContractPositionDto> positions = contractPositionService.find(filter, pageable);
//
for (Iterator<IdmContractPositionDto> i = positions.iterator(); i.hasNext() && canContinue; ) {
IdmContractPositionDto position = i.next();
UUID contractId = position.getId();
//
if (!requireNewTransaction()) {
processedRoles.addAll(processPosition(position, automaticRole));
} else {
TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//
try {
template.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
processedRoles.addAll(processPosition(position, automaticRole));
}
});
} catch (UnexpectedRollbackException ex) {
// Just log for sure ... exception solved in new transaction, but this lower transaction is marked as roll-back.
LOG.debug("Statefull process [{}] processed contract [{}] failed", getClass().getSimpleName(), contractId, ex);
}
}
//
if (!this.updateState()) {
LOG.debug("Task [{}] was canceled.", getLongRunningTaskId());
// return null => not continue with role removal
return null;
}
}
canContinue &= positions.hasNext();
pageable = positions.nextPageable();
//
} while (canContinue);
//
return processedRoles;
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method search.
@Override
public void search(IcObjectClass objectClass, IcFilter filter, IcResultsHandler handler) {
Assert.notNull(objectClass, "Object class cannot be null!");
Assert.notNull(handler, "Result handler cannot be null for search operation!");
if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
throw new IcException("Only ACCOUNT object class is supported now!");
}
if (filter == null) {
Pageable pageable = PageRequest.of(0, 10);
searchByPage(handler, pageable);
} else {
// TODO: Search by filter
throw new IcException("Virtual system connector does not support search by filter! Filter must be null!. It means search return always all accounts.");
}
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class DefaultAuditService method findRevisions.
@Override
public <T> List<IdmAuditDto> findRevisions(Class<T> classType, UUID entityId) {
IdmAuditFilter filter = new IdmAuditFilter();
filter.setEntityId(entityId);
filter.setType(classType.getName());
Pageable page = PageRequest.of(0, Integer.MAX_VALUE, Direction.ASC, "timestamp", "id");
Page<IdmAuditDto> result = this.find(filter, page);
return result.getContent();
}
use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.
the class ProvisioningOperationReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// prepare temp file for json stream
File temp = getAttachmentManager().createTempFile();
//
try (FileOutputStream 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());
Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, SysProvisioningOperation_.created.getName()));
SysProvisioningOperationFilter filterOperations = new SysProvisioningOperationFilter();
Serializable systemId = formInstance.toSinglePersistentValue(PARAMETER_SYSTEM);
if (systemId != null) {
filterOperations.setSystemId(getParameterConverter().toEntityUuid(systemId.toString(), SysSystemDto.class));
}
//
counter = 0L;
do {
Page<SysProvisioningOperationDto> operations = provisioningOperationService.find(filterOperations, pageable, IdmBasePermission.READ);
if (count == null) {
count = operations.getTotalElements();
}
boolean canContinue = true;
for (Iterator<SysProvisioningOperationDto> i = operations.iterator(); i.hasNext() && canContinue; ) {
// transfer SysProvisioningOperationDto to IdmProvisioningOperationDto and write IdmProvisioningOperationDto into json
RptProvisioningOperationDto idmProvisioningOperationDto = transferSysProvisioningOperationDto(i.next());
getMapper().writeValue(jGenerator, idmProvisioningOperationDto);
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
}
// iterate while next page of identities is available
pageable = operations.hasNext() && canContinue ? operations.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 {
FileUtils.deleteQuietly(temp);
}
}
Aggregations