final Set<String> vAttrsToBeRemoved, final Map<String, AttributeMod> vAttrsToBeUpdated) {
LOG.debug("Get attributes for '{}' and mapping type '{}'", attributables, mappingItem.getIntMappingType());
List<AbstractAttrValue> values = new ArrayList<AbstractAttrValue>();
AbstractAttrValue attrValue;
switch (mappingItem.getIntMappingType()) {
case UserSchema:
case RoleSchema:
case MembershipSchema:
for (AbstractAttributable attributable : attributables) {
final AbstractAttr attr = attributable.getAttribute(mappingItem.getIntAttrName());
if (attr != null) {
if (attr.getUniqueValue() != null) {
values.add(attr.getUniqueValue());
} else if (attr.getValues() != null) {
values.addAll(attr.getValues());
}
}
LOG.debug("Retrieved attribute {}"
+ "\n* IntAttrName {}"
+ "\n* IntMappingType {}"
+ "\n* Attribute values {}",
attr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values);
}
break;
case UserVirtualSchema:
case RoleVirtualSchema:
case MembershipVirtualSchema:
for (AbstractAttributable attributable : attributables) {
AbstractVirAttr virAttr = attributable.getVirtualAttribute(mappingItem.getIntAttrName());
if (virAttr != null) {
if (virAttr.getValues() != null) {
for (String value : virAttr.getValues()) {
attrValue = new UAttrValue();
attrValue.setStringValue(value);
values.add(attrValue);
}
}
if (vAttrsToBeRemoved != null && vAttrsToBeUpdated != null) {
if (vAttrsToBeUpdated.containsKey(mappingItem.getIntAttrName())) {
virAttr.setValues(
vAttrsToBeUpdated.get(mappingItem.getIntAttrName()).getValuesToBeAdded());
} else if (vAttrsToBeRemoved.contains(mappingItem.getIntAttrName())) {
virAttr.getValues().clear();
} else {
throw new IllegalArgumentException("Don't need to update virtual attribute '"
+ mappingItem.getIntAttrName() + "'");
}
}
}
LOG.debug("Retrieved virtual attribute {}"
+ "\n* IntAttrName {}"
+ "\n* IntMappingType {}"
+ "\n* Attribute values {}",
virAttr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values);
}
break;
case UserDerivedSchema:
case RoleDerivedSchema:
case MembershipDerivedSchema:
for (AbstractAttributable attributable : attributables) {
AbstractDerAttr derAttr = attributable.getDerivedAttribute(mappingItem.getIntAttrName());
if (derAttr != null) {
attrValue = (attributable instanceof SyncopeRole)
? new RAttrValue() : new UAttrValue();
attrValue.setStringValue(derAttr.getValue(attributable.getAttributes()));
values.add(attrValue);
}
LOG.debug("Retrieved attribute {}"
+ "\n* IntAttrName {}"
+ "\n* IntMappingType {}"
+ "\n* Attribute values {}",
derAttr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values);
}
break;
case UserId:
case RoleId:
case MembershipId:
for (AbstractAttributable attributable : attributables) {
attrValue = new UAttrValue();
attrValue.setStringValue(attributable.getId().toString());
values.add(attrValue);
}
break;
case Username:
for (AbstractAttributable attributable : attributables) {
if (attributable instanceof SyncopeUser) {
attrValue = new UAttrValue();
attrValue.setStringValue(((SyncopeUser) attributable).getUsername());
values.add(attrValue);
}
}
break;
case RoleName:
for (AbstractAttributable attributable : attributables) {
if (attributable instanceof SyncopeRole) {
attrValue = new RAttrValue();
attrValue.setStringValue(((SyncopeRole) attributable).getName());
values.add(attrValue);
}
}
break;
case RoleOwnerSchema:
for (AbstractAttributable attributable : attributables) {
if (attributable instanceof SyncopeRole) {
SyncopeRole role = (SyncopeRole) attributable;
String roleOwnerValue = null;
if (role.getUserOwner() != null && resource.getUmapping() != null) {
roleOwnerValue = getRoleOwnerValue(resource, role.getUserOwner());
}
if (role.getRoleOwner() != null && resource.getRmapping() != null) {
roleOwnerValue = getRoleOwnerValue(resource, role.getRoleOwner());
}
if (StringUtils.isNotBlank(roleOwnerValue)) {
attrValue = new RAttrValue();
attrValue.setStringValue(roleOwnerValue);
values.add(attrValue);
}
}
}
break;