syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/4] syncope git commit: [SYNCOPE-1057] More complete AnyPatch generation for update during pull
Date Wed, 05 Apr 2017 10:42:24 GMT
Repository: syncope
Updated Branches:
  refs/heads/2_0_X 0eedeb182 -> 29aaecbb9
  refs/heads/master 76c79169e -> fe07e12dc


[SYNCOPE-1057] More complete AnyPatch generation for update during pull


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/c712af10
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/c712af10
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/c712af10

Branch: refs/heads/2_0_X
Commit: c712af10a373744151297750b88ceba6d70b9478
Parents: 0eedeb1
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Wed Apr 5 12:03:24 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Wed Apr 5 12:03:24 2017 +0200

----------------------------------------------------------------------
 .../syncope/common/lib/AnyOperations.java       | 16 +++--
 .../java/utils/ConnObjectUtils.java             | 67 ++++++++++++++++----
 2 files changed, 64 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/c712af10/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java b/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
index 15a85d3..277d921 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
@@ -400,15 +400,17 @@ public final class AnyOperations {
         // 2. ownership
         result.setUserOwner(
                 replacePatchItem(updated.getUserOwner(), original.getUserOwner(), new StringReplacePatchItem()));
-        result.setGroupOwner(replacePatchItem(updated.getGroupOwner(), original.getGroupOwner(),
-                new StringReplacePatchItem()));
+        result.setGroupOwner(
+                replacePatchItem(updated.getGroupOwner(), original.getGroupOwner(), new StringReplacePatchItem()));
 
-        // 3. dynamic membership
-        result.setUDynMembershipCond(updated.getUDynMembershipCond());
-        result.getADynMembershipConds().putAll(updated.getADynMembershipConds());
+        if (!incremental) {
+            // 3. dynamic membership
+            result.setUDynMembershipCond(updated.getUDynMembershipCond());
+            result.getADynMembershipConds().putAll(updated.getADynMembershipConds());
 
-        // 4. type extensions
-        result.getTypeExtensions().addAll(updated.getTypeExtensions());
+            // 4. type extensions
+            result.getTypeExtensions().addAll(updated.getTypeExtensions());
+        }
 
         return result;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/c712af10/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/ConnObjectUtils.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/ConnObjectUtils.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/ConnObjectUtils.java
index 786dbf3..fbd7c32 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/ConnObjectUtils.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/ConnObjectUtils.java
@@ -116,7 +116,10 @@ public class ConnObjectUtils {
      */
     @Transactional(readOnly = true)
     public <T extends AnyTO> T getAnyTO(
-            final ConnectorObject obj, final PullTask pullTask, final Provision provision,
final AnyUtils anyUtils) {
+            final ConnectorObject obj,
+            final PullTask pullTask,
+            final Provision provision,
+            final AnyUtils anyUtils) {
 
         T anyTO = getAnyTOFromConnObject(obj, pullTask, provision, anyUtils);
 
@@ -170,40 +173,80 @@ public class ConnObjectUtils {
      */
     @SuppressWarnings("unchecked")
     @Transactional(readOnly = true)
-    public <T extends AnyPatch> T getAnyPatch(final String key, final ConnectorObject
obj,
-            final AnyTO original, final PullTask pullTask, final Provision provision, final
AnyUtils anyUtils) {
+    public <T extends AnyPatch> T getAnyPatch(
+            final String key,
+            final ConnectorObject obj,
+            final AnyTO original,
+            final PullTask pullTask,
+            final Provision provision,
+            final AnyUtils anyUtils) {
 
         AnyTO updated = getAnyTOFromConnObject(obj, pullTask, provision, anyUtils);
         updated.setKey(key);
 
+        T anyPatch = null;
         if (null != anyUtils.getAnyTypeKind()) {
             switch (anyUtils.getAnyTypeKind()) {
                 case USER:
+                    UserTO originalUser = (UserTO) original;
+                    UserTO updatedUser = (UserTO) updated;
+
+                    if (StringUtils.isBlank(updatedUser.getUsername())) {
+                        updatedUser.setUsername(originalUser.getUsername());
+                    }
+
                     // update password if and only if password is really changed
                     User user = userDAO.authFind(key);
-                    if (StringUtils.isBlank(((UserTO) updated).getPassword())
-                            || ENCRYPTOR.verify(((UserTO) updated).getPassword(),
+                    if (StringUtils.isBlank(updatedUser.getPassword())
+                            || ENCRYPTOR.verify(updatedUser.getPassword(),
                                     user.getCipherAlgorithm(), user.getPassword())) {
 
-                        ((UserTO) updated).setPassword(null);
+                        updatedUser.setPassword(null);
                     }
-                    return (T) AnyOperations.diff(((UserTO) updated), ((UserTO) original),
true);
+
+                    updatedUser.setSecurityQuestion(updatedUser.getSecurityQuestion());
+                    updatedUser.setMustChangePassword(originalUser.isMustChangePassword());
+
+                    anyPatch = (T) AnyOperations.diff(updatedUser, originalUser, true);
+                    break;
 
                 case GROUP:
-                    return (T) AnyOperations.diff(((GroupTO) updated), ((GroupTO) original),
true);
+                    GroupTO originalGroup = (GroupTO) original;
+                    GroupTO updatedGroup = (GroupTO) updated;
+
+                    if (StringUtils.isBlank(updatedGroup.getName())) {
+                        updatedGroup.setName(originalGroup.getName());
+                    }
+                    updatedGroup.setUserOwner(originalGroup.getUserOwner());
+                    updatedGroup.setGroupOwner(originalGroup.getGroupOwner());
+                    updatedGroup.getTypeExtensions().addAll(originalGroup.getTypeExtensions());
+
+                    anyPatch = (T) AnyOperations.diff(updatedGroup, originalGroup, true);
+                    break;
 
                 case ANY_OBJECT:
-                    return (T) AnyOperations.diff(((AnyObjectTO) updated), ((AnyObjectTO)
original), true);
+                    AnyObjectTO originalAnyObject = (AnyObjectTO) original;
+                    AnyObjectTO updatedAnyObject = (AnyObjectTO) updated;
+
+                    if (StringUtils.isBlank(updatedAnyObject.getName())) {
+                        updatedAnyObject.setName(originalAnyObject.getName());
+                    }
+
+                    anyPatch = (T) AnyOperations.diff(updatedAnyObject, originalAnyObject,
true);
+                    break;
 
                 default:
             }
         }
 
-        return null;
+        return anyPatch;
     }
 
-    private <T extends AnyTO> T getAnyTOFromConnObject(final ConnectorObject obj,
-            final PullTask pullTask, final Provision provision, final AnyUtils anyUtils)
{
+    private <T extends AnyTO> T getAnyTOFromConnObject(
+            final ConnectorObject obj,
+            final PullTask pullTask,
+            final Provision provision,
+            final AnyUtils anyUtils) {
 
         T anyTO = anyUtils.newAnyTO();
         anyTO.setType(provision.getAnyType().getKey());


Mime
View raw message