final Set<String> membVAttrsToBeRemoved, final Map<String, AttributeMod> membVAttrsToBeUpdated) {
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.getAttr(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:
for (AbstractAttributable attributable : attributables) {
AbstractVirAttr virAttr = attributable.getVirAttr(mappingItem.getIntAttrName());
if (virAttr != null) {
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() + "'");
}
}
if (virAttr.getValues() != null) {
for (String value : virAttr.getValues()) {
attrValue = new UAttrValue();
attrValue.setStringValue(value);
values.add(attrValue);
}
}
}
LOG.debug("Retrieved {} virtual attribute {}"
+ "\n* IntAttrName {}"
+ "\n* IntMappingType {}"
+ "\n* Attribute values {}",
attributable.getClass().getSimpleName(),
virAttr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values);
}
break;
case MembershipVirtualSchema:
for (AbstractAttributable attributable : attributables) {
AbstractVirAttr virAttr = attributable.getVirAttr(mappingItem.getIntAttrName());
if (virAttr != null) {
if (membVAttrsToBeRemoved != null && membVAttrsToBeUpdated != null) {
if (membVAttrsToBeUpdated.containsKey(mappingItem.getIntAttrName())) {
virAttr.setValues(
membVAttrsToBeUpdated.get(mappingItem.getIntAttrName()).getValuesToBeAdded());
} else if (membVAttrsToBeRemoved.contains(mappingItem.getIntAttrName())) {
virAttr.getValues().clear();
} else {
throw new IllegalArgumentException("Don't need to update membership virtual attribute '"
+ mappingItem.getIntAttrName() + "'");
}
}
if (virAttr.getValues() != null) {
for (String value : virAttr.getValues()) {
attrValue = new UAttrValue();
attrValue.setStringValue(value);
values.add(attrValue);
}
}
}
LOG.debug("Retrieved {} virtual attribute {}"
+ "\n* IntAttrName {}"
+ "\n* IntMappingType {}"
+ "\n* Attribute values {}",
attributable.getClass().getSimpleName(),
virAttr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values);
}
break;
case UserDerivedSchema:
case RoleDerivedSchema:
case MembershipDerivedSchema:
for (AbstractAttributable attributable : attributables) {
AbstractDerAttr derAttr = attributable.getDerAttr(mappingItem.getIntAttrName());
if (derAttr != null) {
attrValue = (attributable instanceof SyncopeRole)
? new RAttrValue() : new UAttrValue();
attrValue.setStringValue(derAttr.getValue(attributable.getAttrs()));
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;