Search in sources :

Example 6 with SysAttributeDifferenceDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportExecutor method createAccountDifferences.

/**
 * Starts the provisioning in the dry run for single account. Results of the
 * calculated provisioning is used for differences evaluation and highlight.
 *
 * @param account
 * @param identity
 * @param selectedAttributeNames
 * @return
 */
private List<SysAttributeDifferenceDto> createAccountDifferences(AccAccountDto account, IdmIdentityDto identity, List<String> selectedAttributeNames) {
    EventContext<AccAccountDto> eventCtx = provisioningService.doProvisioning(account, identity, ImmutableMap.of(ProvisioningService.DRY_RUN_PROPERTY_NAME, Boolean.TRUE));
    EventResult<AccAccountDto> result = eventCtx.getLastResult();
    if (result == null) {
        throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", account.getId(), "system", account.getSystem(), "operationType", "DRY_RUN", "objectClass", ""));
    }
    ProvisioningOperation provisioningOperation = (ProvisioningOperation) result.getEvent().getProperties().get(EventResult.EVENT_PROPERTY_RESULT);
    if (provisioningOperation == null) {
        throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", account.getId(), "system", account.getSystem(), "operationType", "DRY_RUN", "objectClass", ""));
    }
    ProvisioningContext context = provisioningOperation.getProvisioningContext();
    context = filterAttributes(context, selectedAttributeNames);
    if (context == null) {
        throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", account.getId(), "system", account.getSystem(), "operationType", "DRY_RUN", "objectClass", ""));
    }
    List<SysAttributeDifferenceDto> differences = provisioningArchiveService.evaluateProvisioningDifferences(context.getSystemConnectorObject(), context.getConnectorObject());
    return differences;
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ProvisioningOperation(eu.bcvsolutions.idm.acc.domain.ProvisioningOperation) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto)

Example 7 with SysAttributeDifferenceDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportExecutor method removeUnchangedMultivalues.

/*
	 * Method removes unchanged values of multivalue attributes.
	 * It increases clarity of the output. 
	 */
private List<SysAttributeDifferenceDto> removeUnchangedMultivalues(List<SysAttributeDifferenceDto> differences, boolean removeUnchanged) {
    if (CollectionUtils.isEmpty(differences) || !removeUnchanged) {
        return differences;
    }
    List<SysAttributeDifferenceDto> result = new ArrayList<>();
    for (SysAttributeDifferenceDto value : differences) {
        if (!value.isMultivalue()) {
            result.add(value);
            continue;
        }
        if (!value.isChanged()) {
            value.setValues(new ArrayList<SysAttributeDifferenceValueDto>());
            result.add(value);
            continue;
        }
        List<SysAttributeDifferenceValueDto> subValues = value.getValues();
        subValues = subValues.stream().filter(val -> {
            return val.getChange() != null;
        }).collect(Collectors.toList());
        value.setValues(subValues);
        result.add(value);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto)

Example 8 with SysAttributeDifferenceDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportXlsxRenderer method renderMultiValueCell.

/**
 * Multi value cell renderer.
 */
private Cell renderMultiValueCell(Cell cell, SysAttributeDifferenceDto attribute) {
    XSSFRichTextString content = new XSSFRichTextString();
    // also defines the order of change types
    SysValueChangeType[] changeTypes = { SysValueChangeType.ADDED, SysValueChangeType.REMOVED, null };
    List<List<SysAttributeDifferenceValueDto>> valueList = Arrays.stream(changeTypes).map(type -> {
        return attribute.getValues().stream().filter(val -> type == val.getChange()).collect(Collectors.toList());
    }).collect(Collectors.toList());
    for (int i = 0; i < changeTypes.length; i++) {
        SysValueChangeType changeType = changeTypes[i];
        List<SysAttributeDifferenceValueDto> values = valueList.get(i);
        for (int j = 0; j < values.size(); ++j) {
            SysAttributeDifferenceValueDto value = values.get(j);
            content.append(Objects.toString(value.getValue()), getTextFont(cell, changeType));
            if (j >= values.size() - 1 && i >= changeTypes.length - 1) {
                continue;
            }
            content.append(NEW_LINE);
        }
    }
    cell.setCellValue(content);
    return cell;
}
Also used : Arrays(java.util.Arrays) FillPatternType(org.apache.poi.ss.usermodel.FillPatternType) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto) RptChangesOnSystemRecordDto(eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto) HashMap(java.util.HashMap) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) StringUtils(org.apache.commons.lang3.StringUtils) HSSFColor(org.apache.poi.hssf.util.HSSFColor) ArrayList(java.util.ArrayList) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) CollectionUtils(org.apache.commons.collections.CollectionUtils) IndexedColors(org.apache.poi.ss.usermodel.IndexedColors) Map(java.util.Map) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) Cell(org.apache.poi.ss.usermodel.Cell) JsonToken(com.fasterxml.jackson.core.JsonToken) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Description(org.springframework.context.annotation.Description) Sheet(org.apache.poi.ss.usermodel.Sheet) JsonParser(com.fasterxml.jackson.core.JsonParser) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) Collectors(java.util.stream.Collectors) RptChangesOnSystemState(eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemState) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) AbstractXlsxRenderer(eu.bcvsolutions.idm.rpt.api.renderer.AbstractXlsxRenderer) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Row(org.apache.poi.ss.usermodel.Row) SysValueChangeType(eu.bcvsolutions.idm.acc.domain.SysValueChangeType) RendererRegistrar(eu.bcvsolutions.idm.rpt.api.renderer.RendererRegistrar) InputStream(java.io.InputStream) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) SysValueChangeType(eu.bcvsolutions.idm.acc.domain.SysValueChangeType) ArrayList(java.util.ArrayList) List(java.util.List) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto)

Example 9 with SysAttributeDifferenceDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportXlsxRenderer method renderRecord.

/**
 * Methods renders single record
 */
private void renderRecord(int lineIdx, Sheet sheet, RptChangesOnSystemRecordDto record, Map<String, Integer> attributeOrder) {
    if (record == null) {
        LOG.warn("Trying to render null record!");
        return;
    }
    Row row = sheet.createRow(lineIdx);
    row.setHeight((short) -1);
    int cellIdx;
    // render status
    XSSFRichTextString content = new XSSFRichTextString();
    RptChangesOnSystemState state = record.getState();
    cellIdx = attributeOrder.get(STATUS_COLUMN_NAME);
    Cell cell = row.createCell(cellIdx);
    content.append(state.toString());
    cell.setCellValue(content);
    cell.setCellStyle(getStatusCellStyle(sheet, state));
    // render record key/identifier
    XSSFFont boldFont = ((XSSFWorkbook) sheet.getWorkbook()).createFont();
    boldFont.setBold(true);
    String key = record.getIdentifier();
    content = new XSSFRichTextString();
    cellIdx = attributeOrder.get(KEY_COLUMN_NAME);
    cell = row.createCell(cellIdx);
    content.append(Objects.toString(key, ""), boldFont);
    cell.setCellValue(content);
    if (state == RptChangesOnSystemState.FAILED) {
        cellIdx++;
        cell = row.createCell(cellIdx);
        content = new XSSFRichTextString();
        XSSFFont font = getTextFont(cell, SysValueChangeType.REMOVED);
        content.append(Objects.toString(record.getError(), ""), font);
        cell.setCellValue(content);
        return;
    }
    List<SysAttributeDifferenceDto> differences = record.getAttributeDifferences();
    if (CollectionUtils.isEmpty(differences)) {
        return;
    }
    for (SysAttributeDifferenceDto diff : differences) {
        Integer colIdx = attributeOrder.get(diff.getName());
        if (colIdx == null) {
            continue;
        }
        cell = row.createCell(colIdx);
        if (diff.isMultivalue()) {
            renderMultiValueCell(cell, diff);
        } else {
            renderSingleValueCell(cell, diff, state);
        }
    }
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RptChangesOnSystemState(eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemState) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) Cell(org.apache.poi.ss.usermodel.Cell)

Example 10 with SysAttributeDifferenceDto

use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto 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

SysAttributeDifferenceDto (eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto)13 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)5 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)4 SysAttributeDifferenceValueDto (eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto)4 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 SysValueChangeType (eu.bcvsolutions.idm.acc.domain.SysValueChangeType)3 List (java.util.List)3 UUID (java.util.UUID)3 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)2 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)2 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 SysProvisioningArchiveService (eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService)2 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)2