Search in sources :

Example 6 with ReportGenerateException

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

the class TestFilterReportExecutor method generateData.

@Override
@SuppressWarnings("rawtypes")
protected IdmAttachmentDto generateData(RptReportDto report) {
    try {
        IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
        // 
        List usernames = (List) formInstance.toPersistentValues(IdmIdentity_.username.getName());
        List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
            return ObjectUtils.isEmpty(usernames) || usernames.contains(identity.getUsername());
        }).collect(Collectors.toList());
        return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
    } catch (FileNotFoundException | JsonProcessingException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Description(org.springframework.context.annotation.Description) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) ObjectUtils(org.springframework.util.ObjectUtils) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) AbstractReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor) FileNotFoundException(java.io.FileNotFoundException) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 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 8 with ReportGenerateException

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

the class IdentityEavReportExecutor 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 {
            jGenerator.writeStartArray();
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
            counter = 0L;
            // take configuration
            Serializable eavValueSerializable = formInstance.toSinglePersistentValue(PARAMETER_EAV_VALUE);
            String eavValue = eavValueSerializable != null ? eavValueSerializable.toString() : null;
            Serializable disabledSerializable = formInstance.toSinglePersistentValue(IdmIdentityFilter.PARAMETER_DISABLED);
            String disabled = disabledSerializable != null ? disabledSerializable.toString() : null;
            UUID definitionUUID = UUID.fromString(formInstance.toSinglePersistentValue(PARAMETER_FORM_DEFINITION).toString());
            IdmFormDefinitionDto definition = formService.getDefinition(definitionUUID);
            // 
            if (!definition.getType().equals(IdmIdentity.class.getName())) {
                throw new ResultCodeException(RptResultCode.REPORT_WRONG_DEFINITION, ImmutableMap.of("firstType", definition.getType(), "secondType", IdmIdentity.class.getName()));
            }
            // 
            String eavCode = (String) formInstance.toMultiValueMap().getFirst(PARAMETER_FORM_ATTRIBUTE);
            if (eavCode == null) {
                throw new ResultCodeException(RptResultCode.REPORT_NO_FORM_ATTRIBUTE, ImmutableMap.of("code", "null"));
            }
            IdmFormAttributeDto formAttribute = definition.getMappedAttributeByCode(eavCode);
            if (formAttribute == null) {
                throw new ResultCodeException(RptResultCode.REPORT_NO_FORM_ATTRIBUTE, ImmutableMap.of("code", eavCode));
            }
            // 
            IdmIdentityFilter identityFilter = new IdmIdentityFilter();
            if (disabled != null) {
                identityFilter.setDisabled(Boolean.valueOf(disabled));
            }
            // 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(identityFilter, 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; ) {
                    writeValues(i.next(), formAttribute, eavValue, jGenerator);
                    canContinue = updateState();
                    if (!canContinue) {
                        break;
                    }
                }
                pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
            } while (pageable != null);
            // 
            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) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) FileInputStream(java.io.FileInputStream) Pageable(org.springframework.data.domain.Pageable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) File(java.io.File)

Example 9 with ReportGenerateException

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

the class IdentityIncompatibleRoleReportExecutor 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
            Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
            // 
            counter = 0L;
            do {
                Page<IdmIdentityDto> identities = identityService.find(null, pageable, IdmBasePermission.READ);
                if (count == null) {
                    count = identities.getTotalElements();
                }
                boolean canContinue = true;
                for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
                    IdmIdentityDto identity = i.next();
                    // search assigned roles
                    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
                    filter.setIdentityId(identity.getId());
                    // direct roles only
                    filter.setDirectRole(Boolean.TRUE);
                    List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null, IdmBasePermission.READ).getContent();
                    // search incompatible roles
                    Set<ResolvedIncompatibleRoleDto> incompatibleRoles = incompatibleRoleService.resolveIncompatibleRoles(identityRoles.stream().map(ir -> ir.getRole()).collect(Collectors.toList()));
                    for (ResolvedIncompatibleRoleDto resolvedIncompatibleRole : incompatibleRoles) {
                        // add item into report
                        RptIdentityIncompatibleRoleDto reportItem = new RptIdentityIncompatibleRoleDto();
                        reportItem.setIdentity(identity);
                        reportItem.setDirectRole(resolvedIncompatibleRole.getDirectRole());
                        reportItem.setIncompatibleRole(resolvedIncompatibleRole.getIncompatibleRole());
                        // dtos in embedded cannot be parsed from json automatically as objects => aaet them into report dto directly
                        IdmRoleDto superior = DtoUtils.getEmbedded(resolvedIncompatibleRole.getIncompatibleRole(), IdmIncompatibleRole_.superior);
                        IdmRoleDto sub = DtoUtils.getEmbedded(resolvedIncompatibleRole.getIncompatibleRole(), IdmIncompatibleRole_.sub);
                        reportItem.setSuperior(superior);
                        reportItem.setSub(sub);
                        // 
                        getMapper().writeValue(jGenerator, reportItem);
                    }
                    // 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 : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) FileInputStream(java.io.FileInputStream) RptIdentityIncompatibleRoleDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityIncompatibleRoleDto) Pageable(org.springframework.data.domain.Pageable) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) File(java.io.File)

Example 10 with ReportGenerateException

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

the class ChangesOnSystemReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    // get system related configuration
    MultiValueMap<String, UUID> configuration = parseAttributeConfig(report);
    SysSystemDto systemDto = getSystemById(configuration.getFirst(PARAMETER_SYSTEM));
    SysSystemMappingDto systemMapping = getSystemMappingById(configuration.getFirst(PARAMETER_SYSTEM_MAPPING));
    List<SysSystemAttributeMappingDto> attributes = getAttributesById(configuration.get(PARAMETER_MAPPING_ATTRIBUTES), systemMapping);
    List<String> selectedAttributeNames = getSelectedAttributeNames(attributes).stream().sorted().collect(Collectors.toList());
    // list of identities to report
    Set<UUID> identities = getReportedIdentities(report);
    boolean skipUnchangedMultivalue = getSkipUnchangedValues(report);
    AccAccountFilter filterAccount = new AccAccountFilter();
    filterAccount.setSystemId(systemDto.getId());
    filterAccount.setEntityType(SystemEntityType.IDENTITY);
    File temp = getAttachmentManager().createTempFile();
    try (FileOutputStream outputStream = new FileOutputStream(temp)) {
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // start of root object
            jGenerator.writeStartObject();
            // write attribute names
            jGenerator.writeFieldName(ATTRIBUTE_NAME_JSON_KEY);
            getMapper().writeValue(jGenerator, selectedAttributeNames);
            // create and write records
            jGenerator.writeFieldName(RECORDS_JSON_KEY);
            jGenerator.writeStartArray();
            createReportData(jGenerator, filterAccount, identities, systemDto.getId(), selectedAttributeNames, skipUnchangedMultivalue);
            jGenerator.writeEndArray();
            // end of root object
            jGenerator.writeEndObject();
        } finally {
            jGenerator.close();
        }
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException e) {
        throw new ReportGenerateException(report.getName(), e);
    } finally {
        FileUtils.deleteQuietly(temp);
    }
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) FileInputStream(java.io.FileInputStream) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) UUID(java.util.UUID) File(java.io.File)

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