Search in sources :

Example 1 with RptChangesOnSystemRecordDto

use of eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportXlsxRenderer method render.

@Override
public InputStream render(RptReportDto report) {
    try (JsonParser jParser = getMapper().getFactory().createParser(getReportData(report))) {
        List<String> headerNames = new ArrayList<String>();
        JsonToken token = null;
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet(REPORT_SHEET_NAME);
        sheet.setDefaultColumnWidth(15);
        // parse and render attributes' name
        token = getJsonNodeByName(jParser, ChangesOnSystemReportExecutor.ATTRIBUTE_NAME_JSON_KEY);
        if (token != null) {
            headerNames = getMapper().readValue(jParser, new TypeReference<List<String>>() {
            });
        }
        Map<String, Integer> attributeOrder = renderHeader(sheet, headerNames);
        // parse and render attribute record
        token = getJsonNodeByName(jParser, ChangesOnSystemReportExecutor.RECORDS_JSON_KEY);
        int recordIdx = 1;
        while (token != null && token != JsonToken.END_ARRAY && !jParser.isClosed()) {
            RptChangesOnSystemRecordDto record = getMapper().readValue(jParser, RptChangesOnSystemRecordDto.class);
            renderRecord(recordIdx, sheet, record, attributeOrder);
            token = jParser.nextValue();
            recordIdx++;
        }
        // cell autofitting
        for (int index = 0; index < attributeOrder.size() + 1; index++) {
            sheet.autoSizeColumn(index);
        }
        // close and return input stream
        return getInputStream(workbook);
    } catch (Exception ex) {
        throw new ReportRenderException(report.getName(), ex);
    }
}
Also used : RptChangesOnSystemRecordDto(eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto) ArrayList(java.util.ArrayList) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) JsonToken(com.fasterxml.jackson.core.JsonToken) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with RptChangesOnSystemRecordDto

use of eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportExecutor method createReportData.

/**
 * Creates report object for saving to output json file. It invokes record
 * generating for every account/identity
 *
 * @param changeDataDto
 * @param accountFilter
 * @param identityIds
 * @param systemId
 * @param attributes
 * @return
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonGenerationException
 */
private void createReportData(JsonGenerator jGenerator, AccAccountFilter accountFilter, Set<UUID> identityIds, UUID systemId, List<String> selectedAttributeNames, boolean skipUnchangedMultivalue) throws IOException {
    if (identityIds == null) {
        // null indicates that no identity explicitly specified from report config
        List<UUID> accountIds = accountService.findIds(accountFilter, null).getContent();
        IdmIdentityDto identity = null;
        String key = null;
        for (UUID accountId : accountIds) {
            Pair<AccAccountDto, IdmIdentityDto> pair = findIdentityAndAccount(systemId, accountId, null);
            AccAccountDto account = pair.getLeft();
            identity = pair.getRight();
            key = createKey(account, identity);
            RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
            record.setIdentifier(key);
            if (identity == null) {
                record.setState(RptChangesOnSystemState.NO_ENTITY_FOR_ACCOUNT);
                record.setAttributeDifferences(new ArrayList<SysAttributeDifferenceDto>());
            // dry run provisioning cannot be performed without identity
            } else {
                try {
                    List<SysAttributeDifferenceDto> differences = createAccountDifferences(account, identity, selectedAttributeNames);
                    differences = removeUnchangedMultivalues(differences, skipUnchangedMultivalue);
                    record.setAttributeDifferences(differences);
                    record.setState(createRecordState(differences));
                } catch (Exception e) {
                    record.setState(RptChangesOnSystemState.FAILED);
                    record.setIdentifier(key);
                    record.setError(ExceptionUtils.getStackTrace(e));
                }
            }
            getMapper().writeValue(jGenerator, record);
        }
    } else {
        for (UUID identityId : identityIds) {
            IdmIdentityDto identity = identityService.get(identityId);
            if (identity == null) {
                LOG.info("Wrong user UUID [{}] inserted.", identityId);
                continue;
            }
            accountFilter.setIdentityId(identityId);
            List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
            if (accounts.isEmpty()) {
                String key = createKey(null, identity);
                RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
                record.setIdentifier(key);
                record.setState(RptChangesOnSystemState.NO_ACCOUNT_FOR_ENTITY);
                record.setAttributeDifferences(new ArrayList<SysAttributeDifferenceDto>());
                getMapper().writeValue(jGenerator, record);
                continue;
            }
            for (AccAccountDto account : accounts) {
                String key = createKey(account, identity);
                try {
                    List<SysAttributeDifferenceDto> differences = createAccountDifferences(account, identity, selectedAttributeNames);
                    differences = removeUnchangedMultivalues(differences, skipUnchangedMultivalue);
                    RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
                    record.setIdentifier(key);
                    record.setAttributeDifferences(differences);
                    record.setState(createRecordState(differences));
                    getMapper().writeValue(jGenerator, record);
                } catch (Exception e) {
                    RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
                    record.setState(RptChangesOnSystemState.FAILED);
                    record.setIdentifier(key);
                    record.setError(ExceptionUtils.getStackTrace(e));
                    getMapper().writeValue(jGenerator, record);
                }
            }
        }
    }
}
Also used : RptChangesOnSystemRecordDto(eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException)

Aggregations

ReportRenderException (eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException)2 RptChangesOnSystemRecordDto (eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 SysAttributeDifferenceDto (eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ReportGenerateException (eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1