PropagationByResource propByRes = new PropagationByResource();
// 1. virtual attributes to be removed
for (String vAttrToBeRemoved : vAttrsToBeRemoved) {
AbstractVirSchema virtualSchema = getVirtualSchema(vAttrToBeRemoved, attributableUtil.virtualSchemaClass());
if (virtualSchema != null) {
AbstractVirAttr virtualAttribute = attributable.getVirtualAttribute(virtualSchema.getName());
if (virtualAttribute == null) {
LOG.debug("No virtual attribute found for schema {}", virtualSchema.getName());
} else {
attributable.removeVirtualAttribute(virtualAttribute);
virAttrDAO.delete(virtualAttribute);
}
for (SchemaMapping mapping : resourceDAO.findAllMappings()) {
if (virtualSchema.getName().equals(mapping.getIntAttrName())
&& mapping.getIntMappingType() == attributableUtil.virtualIntMappingType()
&& mapping.getResource() != null
&& attributable.getResources().contains(mapping.getResource())) {
propByRes.add(PropagationOperation.UPDATE, mapping.getResource().getName());
// TODO: must be avoided to use virtual attribute as AccountId
if (mapping.isAccountid() && virtualAttribute != null
&& !virtualAttribute.getValues().isEmpty()) {
propByRes.addOldAccountId(mapping.getResource().getName(), virtualAttribute.getValues().get(
0));
}
}
}
}
}
LOG.debug("Virtual attributes to be removed:\n{}", propByRes);
// 2. virtual attributes to be updated
for (AttributeMod vAttrToBeUpdated : vAttrsToBeUpdated) {
AbstractVirSchema virtualSchema = getVirtualSchema(vAttrToBeUpdated.getSchema(), attributableUtil.
virtualSchemaClass());
if (virtualSchema != null) {
for (SchemaMapping mapping : resourceDAO.findAllMappings()) {
if (virtualSchema.getName().equals(mapping.getIntAttrName())
&& mapping.getIntMappingType() == attributableUtil.virtualIntMappingType()
&& mapping.getResource() != null
&& attributable.getResources().contains(mapping.getResource())) {
propByRes.add(PropagationOperation.UPDATE, mapping.getResource().getName());
}
}
AbstractVirAttr virtualAttribute = attributable.getVirtualAttribute(virtualSchema.getName());
if (virtualAttribute == null) {
virtualAttribute = attributableUtil.newVirtualAttribute();
virtualAttribute.setVirtualSchema(virtualSchema);
attributable.addVirtualAttribute(virtualAttribute);