You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2012/10/23 17:50:24 UTC
svn commit: r1401327 - in
/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core:
propagation/AbstractPropagationTaskExecutor.java
propagation/PropagationManager.java util/ConnObjectUtil.java
Author: ilgrosso
Date: Tue Oct 23 15:50:24 2012
New Revision: 1401327
URL: http://svn.apache.org/viewvc?rev=1401327&view=rev
Log:
[SYNCOPE-130] The set of attributes to be sent over connector for update is now checked against the values returned from the same connector
Modified:
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/AbstractPropagationTaskExecutor.java
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/PropagationManager.java
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java
Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/AbstractPropagationTaskExecutor.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/AbstractPropagationTaskExecutor.java?rev=1401327&r1=1401326&r2=1401327&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/AbstractPropagationTaskExecutor.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/AbstractPropagationTaskExecutor.java Tue Oct 23 15:50:24 2012
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.syncope.core.init.ConnInstanceLoader;
@@ -34,6 +35,7 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.persistence.dao.TaskDAO;
import org.apache.syncope.core.persistence.dao.UserDAO;
import org.apache.syncope.core.util.ApplicationContextProvider;
+import org.apache.syncope.core.util.ConnObjectUtil;
import org.apache.syncope.core.util.NotFoundException;
import org.apache.syncope.types.PropagationMode;
import org.apache.syncope.types.PropagationTaskExecStatus;
@@ -66,6 +68,9 @@ public abstract class AbstractPropagatio
@Autowired
protected ConnInstanceLoader connLoader;
+ @Autowired
+ protected ConnObjectUtil connObjectUtil;
+
/**
* User DAO.
*/
@@ -162,7 +167,6 @@ public abstract class AbstractPropagatio
connector.create(task.getPropagationMode(), ObjectClass.ACCOUNT, attributes, null,
propagationAttempted);
} else {
-
// 1. check if rename is really required
final Name newName = (Name) AttributeUtil.find(Name.NAME, attributes);
@@ -175,11 +179,38 @@ public abstract class AbstractPropagatio
attributes.remove(newName);
}
- LOG.debug("Attributes to be replaced {}", attributes);
+ // 2. check wether anything is actually needing to be propagated, i.e. if there is attribute
+ // difference between beforeObj - just read above from the connector - and the values to
+ // be propagated
+ Map<String, Attribute> originalAttrMap = connObjectUtil.toMap(beforeObj.getAttributes());
+ Map<String, Attribute> updateAttrMap = connObjectUtil.toMap(attributes);
+
+ // Only compare attribute from beforeObj that are also being updated
+ Set<String> skipAttrNames = originalAttrMap.keySet();
+ skipAttrNames.removeAll(updateAttrMap.keySet());
+ for (String attrName : new HashSet<String>(skipAttrNames)) {
+ originalAttrMap.remove(attrName);
+ }
+
+ Set<Attribute> originalAttrs = new HashSet<Attribute>(originalAttrMap.values());
- // 2. update with a new "normalized" attribute set
- connector.update(task.getPropagationMode(), ObjectClass.ACCOUNT, beforeObj.getUid(),
- attributes, null, propagationAttempted);
+ if (originalAttrs.equals(attributes)) {
+ LOG.debug("Don't need to propagate anything: {} is equal to {}", originalAttrs, attributes);
+ } else {
+ LOG.debug("Attributes that would be updated {}", attributes);
+
+ Set<Attribute> strictlyModified = new HashSet<Attribute>();
+ for (Attribute attr : attributes) {
+ if (!originalAttrs.contains(attr)) {
+ strictlyModified.add(attr);
+ }
+ }
+
+ LOG.debug("Attributes that will be actually propagated for update {}", strictlyModified);
+
+ connector.update(task.getPropagationMode(), ObjectClass.ACCOUNT, beforeObj.getUid(),
+ strictlyModified, null, propagationAttempted);
+ }
}
break;
Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/PropagationManager.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/PropagationManager.java?rev=1401327&r1=1401326&r2=1401327&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/PropagationManager.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/PropagationManager.java Tue Oct 23 15:50:24 2012
@@ -511,7 +511,7 @@ public class PropagationManager {
tasks.add(task);
- LOG.debug("Execution started for {}", task);
+ LOG.debug("PropagationTasl created: {}", task);
}
}
}
Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java?rev=1401327&r1=1401326&r2=1401327&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java Tue Oct 23 15:50:24 2012
@@ -398,4 +398,25 @@ public class ConnObjectUtil {
return result;
}
+
+ /**
+ * Transform a
+ * <code>Collection</code> of {@link Attribute} instances into a {@link Map}. The key to each element in the map is
+ * the <i>name</i> of an
+ * <code>Attribute</code>. The value of each element in the map is the
+ * <code>Attribute</code> instance with that name. <br/> Different from the original because: <ul> <li>map keys are
+ * transformed toUpperCase()</li> <li>returned map is mutable</li> </ul>
+ *
+ * @param attributes set of attribute to transform to a map.
+ * @return a map of string and attribute.
+ *
+ * @see org.identityconnectors.framework.common.objects.AttributeUtil#toMap(java.util.Collection)
+ */
+ public Map<String, Attribute> toMap(final Collection<? extends Attribute> attributes) {
+ final Map<String, Attribute> map = new HashMap<String, Attribute>();
+ for (Attribute attr : attributes) {
+ map.put(attr.getName().toUpperCase(), attr);
+ }
+ return map;
+ }
}