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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations