for (ExternalResource resource : getTargetResource(virAttr, type, attrUtil)) {
LOG.debug("Search values into {}", resource.getName());
try {
final List<AbstractMappingItem> mappings = attrUtil.getMappingItems(resource, MappingPurpose.BOTH);
final ConnectorObject connectorObject;
if (externalResources.containsKey(resource.getName())) {
connectorObject = externalResources.get(resource.getName());
} else {
LOG.debug("Perform connection to {}", resource.getName());
final String accountId = attrUtil.getAccountIdItem(resource) == null
? null
: MappingUtil.getAccountIdValue(
owner, resource, attrUtil.getAccountIdItem(resource));
if (StringUtils.isBlank(accountId)) {
throw new IllegalArgumentException("No AccountId found for " + resource.getName());
}
final Connector connector = connFactory.getConnector(resource);
final OperationOptions oo =
connector.getOperationOptions(MappingUtil.getMatchingMappingItems(mappings, type));
connectorObject = connector.getObject(fromAttributable(owner), new Uid(accountId), oo);
externalResources.put(resource.getName(), connectorObject);
}
if (connectorObject != null) {
// ask for searched virtual attribute value
final List<AbstractMappingItem> virAttrMappings =
MappingUtil.getMatchingMappingItems(mappings, schemaName, type);
// the same virtual attribute could be mapped with one or more external attribute
for (AbstractMappingItem mapping : virAttrMappings) {
final Attribute attribute = connectorObject.getAttributeByName(mapping.getExtAttrName());
if (attribute != null && attribute.getValue() != null) {
for (Object obj : attribute.getValue()) {
if (obj != null) {
virAttr.addValue(obj.toString());