final Boolean enable, final boolean deleteOnResource,
final PropagationByResource propByRes) {
LOG.debug("Provisioning subject {}:\n{}", subject, propByRes);
final AttributableUtil attrUtil = AttributableUtil.getInstance(subject);
if (!propByRes.get(ResourceOperation.CREATE).isEmpty()
&& vAttrsToBeRemoved != null && vAttrsToBeUpdated != null) {
connObjectUtil.retrieveVirAttrValues(subject, attrUtil);
// update vAttrsToBeUpdated as well
for (AbstractVirAttr virAttr : subject.getVirtualAttributes()) {
final String schema = virAttr.getVirtualSchema().getName();
final AttributeMod attributeMod = new AttributeMod();
attributeMod.setSchema(schema);
attributeMod.setValuesToBeAdded(virAttr.getValues());
vAttrsToBeUpdated.put(schema, attributeMod);
}
}
// Avoid duplicates - see javadoc
propByRes.purge();
LOG.debug("After purge: {}", propByRes);
final List<PropagationTask> tasks = new ArrayList<PropagationTask>();
for (ResourceOperation operation : ResourceOperation.values()) {
for (String resourceName : propByRes.get(operation)) {
final ExternalResource resource = resourceDAO.find(resourceName);
if (resource == null) {
LOG.error("Invalid resource name specified: {}, ignoring...", resourceName);
} else if (attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION).isEmpty()) {
LOG.warn("Requesting propagation for {} but no propagation mapping provided for {}",
attrUtil.getType(), resource);
} else {
PropagationTask task = new PropagationTask();
task.setResource(resource);
task.setObjectClassName(connObjectUtil.fromAttributable(subject).getObjectClassValue());
task.setSubjectType(attrUtil.getType());
if (!deleteOnResource) {
task.setSubjectId(subject.getId());
}
task.setPropagationOperation(operation);
task.setPropagationMode(resource.getPropagationMode());
task.setOldAccountId(propByRes.getOldAccountId(resource.getName()));
Map.Entry<String, Set<Attribute>> preparedAttrs = prepareAttributes(attrUtil, subject, password,
vAttrsToBeRemoved, vAttrsToBeUpdated, enable, resource);
task.setAccountId(preparedAttrs.getKey());
// Check if any of mandatory attributes (in the mapping) is missing or not received any value:
// if so, add special attributes that will be evaluated by PropagationTaskExecutor
List<String> mandatoryMissing = new ArrayList<String>();
List<String> mandatoryNullOrEmpty = new ArrayList<String>();
for (AbstractMappingItem item : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
if (!item.isAccountid()
&& JexlUtil.evaluateMandatoryCondition(item.getMandatoryCondition(), subject)) {
Attribute attr = AttributeUtil.find(item.getExtAttrName(), preparedAttrs.getValue());
if (attr == null) {