use of eu.bcvsolutions.idm.vs.dto.VsAttributeValueDto in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method getWishConnectorObject.
@Override
public VsConnectorObjectDto getWishConnectorObject(VsRequestDto request) {
LOG.info(MessageFormat.format("Start read wish connector object [{0}].", request));
Assert.notNull(request, "VS request cannot be null!");
List<VsAttributeDto> resultAttributes = new ArrayList<>();
IcConnectorObject realConnectorObject = this.getVsConnectorObject(request);
IcConnectorObject currentObject = realConnectorObject != null ? realConnectorObject : new IcConnectorObjectImpl();
IcConnectorObject changeObject = request.getConnectorObject() != null ? request.getConnectorObject() : new IcConnectorObjectImpl();
List<IcAttribute> currentAttributes = currentObject.getAttributes();
List<IcAttribute> changedAttributes = request.getConnectorObject().getAttributes();
// First add all new attributes
changedAttributes.forEach(changedAttribute -> {
if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
VsAttributeDto vsAttribute = new VsAttributeDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
});
}
} else {
vsAttribute.setValue(new VsAttributeValueDto(changedAttribute.getValue(), null, VsValueChangeType.ADDED));
}
resultAttributes.add(vsAttribute);
}
});
// Second add all already exists attributes
currentAttributes.forEach(currentAttribute -> {
VsAttributeDto vsAttribute;
// Attribute was changed
if (changeObject.getAttributeByName(currentAttribute.getName()) != null) {
vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), true);
IcAttribute changedAttribute = changeObject.getAttributeByName(currentAttribute.getName());
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
} else {
vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
}
});
}
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, VsValueChangeType.REMOVED));
}
});
}
} else {
Object changedValue = changedAttribute.getValue();
Object currentValue = currentAttribute.getValue();
if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentObject)) || (currentValue != null && currentValue.equals(changedValue))) {
vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, null));
} else {
vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, VsValueChangeType.UPDATED));
}
}
} else {
// Attribute was not changed
vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), false);
if (currentAttribute.isMultiValue()) {
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
});
}
} else {
vsAttribute.setValue(new VsAttributeValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
}
}
resultAttributes.add(vsAttribute);
});
BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
// result list
if (!configuration.isDisableSupported()) {
VsAttributeDto enableAttribute = resultAttributes.stream().filter(attribute -> attribute.getName().equals(IcAttributeInfo.ENABLE)).findFirst().orElse(null);
if (enableAttribute != null) {
resultAttributes.remove(enableAttribute);
}
}
VsConnectorObjectDto wishObject = new VsConnectorObjectDto();
wishObject.setUid(request.getUid());
wishObject.setAttributes(resultAttributes);
return wishObject;
}
Aggregations