Search in sources :

Example 1 with SysAttributeDifferenceValueDto

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

the class DefaultSysProvisioningArchiveService method evaluateProvisioningDifferences.

@Override
public List<SysAttributeDifferenceDto> evaluateProvisioningDifferences(IcConnectorObject current, IcConnectorObject changed) {
    List<SysAttributeDifferenceDto> resultAttributes = new ArrayList<>();
    IcConnectorObject currentObject = current != null ? current : new IcConnectorObjectImpl();
    IcConnectorObject changedObject = changed != null ? changed : new IcConnectorObjectImpl();
    List<IcAttribute> currentAttributes = currentObject.getAttributes();
    List<IcAttribute> changedAttributes = changedObject.getAttributes();
    changedAttributes.forEach(changedAttribute -> {
        if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
            SysAttributeDifferenceDto vsAttribute = new SysAttributeDifferenceDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
            if (changedAttribute.isMultiValue()) {
                if (changedAttribute.getValues() != null) {
                    changedAttribute.getValues().forEach(value -> {
                        vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, null, SysValueChangeType.ADDED));
                    });
                }
            } else {
                vsAttribute.setValue(new SysAttributeDifferenceValueDto(changedAttribute.getValue(), null, SysValueChangeType.ADDED));
            }
            resultAttributes.add(vsAttribute);
        }
    });
    // Second add all already existing attributes
    currentAttributes.forEach(currentAttribute -> {
        SysAttributeDifferenceDto vsAttribute;
        // Attribute was changed
        if (changedObject.getAttributeByName(currentAttribute.getName()) != null) {
            IcAttribute changedAttribute = changedObject.getAttributeByName(currentAttribute.getName());
            boolean isMultivalue = isIcAttributeMultivalue(currentAttribute, changedAttribute);
            vsAttribute = new SysAttributeDifferenceDto(currentAttribute.getName(), isMultivalue, true);
            if (isMultivalue) {
                vsAttribute.setChanged(false);
                if (changedAttribute.getValues() != null) {
                    changedAttribute.getValues().forEach(value -> {
                        if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
                            vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, value, null));
                        } else {
                            vsAttribute.setChanged(true);
                            vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, null, SysValueChangeType.ADDED));
                        }
                    });
                }
                if (currentAttribute.getValues() != null) {
                    currentAttribute.getValues().forEach(value -> {
                        if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
                            vsAttribute.setChanged(true);
                            vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, value, SysValueChangeType.REMOVED));
                        }
                    });
                }
            } else {
                Object changedValue = changedAttribute.getValue();
                Object currentValue = currentAttribute.getValue();
                if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentValue)) || (currentValue != null && currentValue.equals(changedValue))) {
                    vsAttribute.setValue(new SysAttributeDifferenceValueDto(changedValue, currentValue, null));
                } else {
                    vsAttribute.setValue(new SysAttributeDifferenceValueDto(changedValue, currentValue, SysValueChangeType.UPDATED));
                }
            }
        } else {
            // Attribute was not changed
            boolean isMultivalue = isIcAttributeMultivalue(currentAttribute, null);
            vsAttribute = new SysAttributeDifferenceDto(currentAttribute.getName(), isMultivalue, false);
            if (isMultivalue) {
                if (currentAttribute.getValues() != null) {
                    currentAttribute.getValues().forEach(value -> {
                        vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, value, null));
                    });
                }
            } else {
                vsAttribute.setValue(new SysAttributeDifferenceValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
            }
        }
        resultAttributes.add(vsAttribute);
    });
    return resultAttributes;
}
Also used : IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto)

Example 2 with SysAttributeDifferenceValueDto

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method differenceObjectMultipleTest.

@Test
public void differenceObjectMultipleTest() {
    String attrName = getHelper().createName();
    IcAttributeImpl icAttributeOne = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTRemoved"));
    IcConnectorObject connObjectOld = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeOne));
    IcAttributeImpl icAttributeTwo = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTNew"));
    IcConnectorObject connObjectNew = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeTwo));
    List<SysAttributeDifferenceDto> diffs = service.evaluateProvisioningDifferences(connObjectOld, connObjectNew);
    List<SysAttributeDifferenceValueDto> values = diffs.get(0).getValues();
    Assert.assertEquals(1, diffs.size());
    Assert.assertTrue(diffs.get(0).isMultivalue());
    Assert.assertTrue(diffs.get(0).isChanged());
    Assert.assertNotNull(values);
    Assert.assertEquals(3, values.size());
    SysAttributeDifferenceValueDto value;
    value = values.stream().filter(item -> item.getChange() == null).findFirst().orElse(null);
    Assert.assertNotNull(value);
    Assert.assertEquals("TESTExisting", value.getValue());
    Assert.assertEquals("TESTExisting", value.getOldValue());
    value = values.stream().filter(item -> item.getChange() == SysValueChangeType.ADDED).findFirst().orElse(null);
    Assert.assertNotNull(value);
    Assert.assertEquals("TESTNew", value.getValue());
    Assert.assertEquals(null, value.getOldValue());
    value = values.stream().filter(item -> item.getChange() == SysValueChangeType.REMOVED).findFirst().orElse(null);
    Assert.assertNotNull(value);
    Assert.assertEquals("TESTRemoved", value.getValue());
    Assert.assertEquals("TESTRemoved", value.getOldValue());
}
Also used : ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) Page(org.springframework.data.domain.Page) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) SysProvisioningAttributeRepository(eu.bcvsolutions.idm.acc.repository.SysProvisioningAttributeRepository) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Assert.assertFalse(org.junit.Assert.assertFalse) SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) DefaultAccTestHelper(eu.bcvsolutions.idm.acc.DefaultAccTestHelper) SysValueChangeType(eu.bcvsolutions.idm.acc.domain.SysValueChangeType) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with SysAttributeDifferenceValueDto

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

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

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

the class ChangesOnSystemReportXlsxRenderer method renderSingleValueCell.

/**
 * Single value cell renderer
 */
private Cell renderSingleValueCell(Cell cell, SysAttributeDifferenceDto attribute, RptChangesOnSystemState recordState) {
    boolean isCreated = RptChangesOnSystemState.ADDED == recordState;
    XSSFRichTextString content = new XSSFRichTextString();
    SysAttributeDifferenceValueDto value = attribute.getValue();
    if (attribute.isChanged()) {
        XSSFFont systemFont = getTextFont(cell, SysValueChangeType.REMOVED);
        XSSFFont idmFont = getTextFont(cell, SysValueChangeType.ADDED);
        if (!isCreated) {
            content.append(SYSTEM_VALUE, systemFont);
            content.append(Objects.toString(value.getOldValue()), systemFont);
            content.append(NEW_LINE);
        }
        content.append(IDM_VALUE, idmFont);
        content.append(Objects.toString(value.getValue()), idmFont);
        cell.getCellStyle().setWrapText(true);
        cell.setCellValue(content);
    } else {
        content.append(Objects.toString(value.getValue()), getTextFont(cell, null));
        cell.setCellValue(content);
    }
    return cell;
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto)

Aggregations

SysAttributeDifferenceValueDto (eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto)5 SysAttributeDifferenceDto (eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto)4 ArrayList (java.util.ArrayList)3 SysValueChangeType (eu.bcvsolutions.idm.acc.domain.SysValueChangeType)2 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)2 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)2 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)2 List (java.util.List)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 DefaultAccTestHelper (eu.bcvsolutions.idm.acc.DefaultAccTestHelper)1 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)1 ProvisioningEventType (eu.bcvsolutions.idm.acc.domain.ProvisioningEventType)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)1 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1