Search in sources :

Example 61 with Pageable

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;
}
Also used : TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) Pageable(org.springframework.data.domain.Pageable) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) Sort(org.springframework.data.domain.Sort) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) HashSet(java.util.HashSet)

Example 62 with Pageable

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;
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) UUID(java.util.UUID) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) HashSet(java.util.HashSet)

Example 63 with Pageable

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.");
    }
}
Also used : Pageable(org.springframework.data.domain.Pageable) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 64 with Pageable

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();
}
Also used : Pageable(org.springframework.data.domain.Pageable) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter)

Example 65 with Pageable

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);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Serializable(java.io.Serializable) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) FileInputStream(java.io.FileInputStream) RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) Pageable(org.springframework.data.domain.Pageable) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) File(java.io.File) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Aggregations

Pageable (org.springframework.data.domain.Pageable)172 PageRequest (org.springframework.data.domain.PageRequest)91 Sort (org.springframework.data.domain.Sort)79 Test (org.junit.Test)39 PageImpl (org.springframework.data.domain.PageImpl)24 Collectors (java.util.stream.Collectors)17 Page (org.springframework.data.domain.Page)16 ArrayList (java.util.ArrayList)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 List (java.util.List)11 UUID (java.util.UUID)10 ApiOperation (io.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 Test (org.junit.jupiter.api.Test)9 java.util (java.util)8 Lists (com.google.common.collect.Lists)7 Map (java.util.Map)6 Transactional (org.springframework.transaction.annotation.Transactional)6