Search in sources :

Example 1 with ReportGenerateException

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

Example 2 with ReportGenerateException

use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.

the class IdentityReportExecutor 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());
            // 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 = PageRequest.of(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 {
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) FileInputStream(java.io.FileInputStream) Pageable(org.springframework.data.domain.Pageable) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) File(java.io.File)

Example 3 with ReportGenerateException

use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.

the class IdentityRoleByIdentityDeduplicationExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    IdmIdentityFilter filter = new IdmIdentityFilter();
    UUID treeNode = getTreeNode(report);
    if (treeNode != null) {
        filter.setTreeNode(treeNode);
        filter.setRecursively(true);
    } else {
        LOG.info("Tree node id isn't filled. Report will be done for all identities.");
    }
    // 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();
            counter = 0L;
            List<UUID> identities = identityService.findIds(filter, null, IdmBasePermission.READ).getContent();
            if (count == null) {
                count = Long.valueOf(identities.size());
            }
            boolean canContinue = true;
            for (UUID identityId : identities) {
                List<IdmIdentityContractDto> contracts = identityContractService.findAllValidForDate(identityId, LocalDate.now(), null);
                for (IdmIdentityContractDto contract : contracts) {
                    RptIdentityRoleByRoleDeduplicationDto newRecord = createRecordForContracts(contract);
                    if (newRecord != null) {
                        getMapper().writeValue(jGenerator, newRecord);
                    }
                }
                ++counter;
                canContinue = updateState();
                if (!canContinue) {
                    break;
                }
            }
            // 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 : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) RptIdentityRoleByRoleDeduplicationDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) UUID(java.util.UUID) File(java.io.File) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 4 with ReportGenerateException

use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.

the class MonitoringReportExecutor 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();
            // 
            List<IdmMonitoringResultDto> lastResults = monitoringManager.getLastResults(null, null, IdmBasePermission.READ).getContent();
            counter = 0L;
            count = Long.valueOf(lastResults.size());
            boolean canContinue = true;
            for (IdmMonitoringResultDto result : lastResults) {
                IdmMonitoringDto monitoring = getLookupService().lookupEmbeddedDto(result, IdmMonitoringResult_.monitoring);
                // 
                RptMonitoringResultDto resultDto = new RptMonitoringResultDto(result);
                resultDto.setResultMessage(result.getResult().getModel() == null ? null : result.getResult().getModel().getMessage());
                resultDto.setOwnerType(result.getOwnerType());
                resultDto.setOwnerId(result.getOwnerId());
                resultDto.setValue(result.getValue());
                resultDto.setLevel(result.getLevel() == null ? NotificationLevel.SUCCESS : result.getLevel());
                resultDto.setEvaluatorType(result.getEvaluatorType());
                resultDto.setEvaluatorDescription(monitoring.getDescription());
                resultDto.setInstanceId(result.getInstanceId());
                // 
                // write dto into json
                getMapper().writeValue(jGenerator, resultDto);
                // 
                // supports cancel report generating (report extends long running task)
                ++counter;
                canContinue = updateState();
                if (!canContinue) {
                    break;
                }
            }
            // 
            // 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 : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) FileOutputStream(java.io.FileOutputStream) RptMonitoringResultDto(eu.bcvsolutions.idm.rpt.dto.RptMonitoringResultDto) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) File(java.io.File) FileInputStream(java.io.FileInputStream) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 5 with ReportGenerateException

use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException 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

ReportGenerateException (eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)9 File (java.io.File)9 FileInputStream (java.io.FileInputStream)9 FileOutputStream (java.io.FileOutputStream)9 IOException (java.io.IOException)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)6 Pageable (org.springframework.data.domain.Pageable)6 Sort (org.springframework.data.domain.Sort)6 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 UUID (java.util.UUID)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)2 Serializable (java.io.Serializable)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Lists (com.google.common.collect.Lists)1 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1