Get EAV of code list item.

This script can be used as a transformation script in the provisioning mapping. It is designed for scenarios where the transformed attribute is mapped directly to an identity EAV attribute containing the code of a code list item. In such cases, `attributeValue` already provides the item code used to identify the corresponding record in the code list.

Once the matching code list item is found, the script reads the value of the required EAV attribute from that code list item and returns it for further mapping to the target system.

Example use case: a user has the code of a code list item stored in an identity EAV attribute. Another value related to this item is stored in the EAV attributes of the corresponding code list record. During provisioning, the script uses the item code from `attributeValue`, finds the matching code list item, and returns the value of the selected EAV attribute to the target system.

import eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto;
import org.apache.commons.lang3.StringUtils;
 
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("getEAVofCodeListItem");
 
String eavCode = 'EAVcode1';
 
if (entity == null || entity.getId() == null) {
    return null;
}
 
// Getting the code of the code list item from the EAV attribute
String itemCode = attributeValue;
if (itemCode == null) {
    log.error("User " + entity.getId() + " does not have code list item");
    return null;
}
 
// Loading the code list
IdmCodeListDto codeList = codeListService.getByCode("codeListCode");
if (codeList == null) {
    return null;
}
 
// Searching for the code list item by its code
IdmCodeListItemDto item = codeListItemService.getItem(codeList.getId(), itemCode);
if (item == null) {
    log.error("Can not find an item" + attributeValue + " for user " + entity.getId() + " in code list");
    return null;
}
 
// Loading all EAV values from the found code list item
def values = item.getEavs()?.collectMany { it?.getValues() ?: [] }
if (values == null || values.isEmpty()) {
    log.error("No EAV for code list item " + attributeValue + ".");
    return null;
}
 
// Searching for the EAV attribute with code "EAVcode1"
def eavValue = values.find {
    it?.embedded?.formAttribute?.code == eavCode
}
 
if (eavValue == null || eavValue.isEmpty()) {
    log.error("No EAVcode1 for itemCode " + attributeValue + " .");
    return null;
}
 
String eavOfCodeListItem = eavValue?.value?.toString()
return StringUtils.isBlank(eavOfCodeListItem) ? null : eavOfCodeListItem

Service

import eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto;
import eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto;
import org.apache.commons.lang3.StringUtils;

Class

formService

codeListService

codeListItemService
  • by kiml