PropagationByResource propByRes = new PropagationByResource();
// 1. virtual attributes to be removed
for (String vAttrToBeRemoved : vAttrsToBeRemoved) {
AbstractVirSchema virSchema = getVirtualSchema(vAttrToBeRemoved, attrUtil.virSchemaClass());
if (virSchema != null) {
AbstractVirAttr virAttr = attributable.getVirtualAttribute(virSchema.getName());
if (virAttr == null) {
LOG.debug("No virtual attribute found for schema {}", virSchema.getName());
} else {
attributable.removeVirtualAttribute(virAttr);
virAttrDAO.delete(virAttr);
}
for (ExternalResource resource : resourceDAO.findAll()) {
for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
if (virSchema.getName().equals(mapItem.getIntAttrName())
&& mapItem.getIntMappingType() == attrUtil.virIntMappingType()
&& attributable.getResources().contains(resource)) {
propByRes.add(ResourceOperation.UPDATE, resource.getName());
// Using virtual attribute as AccountId must be avoided
if (mapItem.isAccountid() && virAttr != null && !virAttr.getValues().isEmpty()) {
propByRes.addOldAccountId(resource.getName(), virAttr.getValues().get(0));
}
}
}
}
}
}
LOG.debug("Virtual attributes to be removed:\n{}", propByRes);
// 2. virtual attributes to be updated
for (AttributeMod vAttrToBeUpdated : vAttrsToBeUpdated) {
AbstractVirSchema virSchema = getVirtualSchema(vAttrToBeUpdated.getSchema(), attrUtil.virSchemaClass());
if (virSchema != null) {
for (ExternalResource resource : resourceDAO.findAll()) {
for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
if (virSchema.getName().equals(mapItem.getIntAttrName())
&& mapItem.getIntMappingType() == attrUtil.virIntMappingType()
&& attributable.getResources().contains(resource)) {
propByRes.add(ResourceOperation.UPDATE, resource.getName());
}
}
}
AbstractVirAttr virAttr = attributable.getVirtualAttribute(virSchema.getName());
if (virAttr == null) {
virAttr = attrUtil.newVirAttr();
virAttr.setVirtualSchema(virSchema);
attributable.addVirtualAttribute(virAttr);
}