← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14867: fixes for userCredentials, allows proper update of user with userCredentials (added merging, and ...

 

------------------------------------------------------------
revno: 14867
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-15 14:43:20 +0700
message:
  fixes for userCredentials, allows proper update of user with userCredentials (added merging, and special handling in importer)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2014-04-08 19:36:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2014-04-15 07:43:20 +0000
@@ -39,12 +39,14 @@
 import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.common.annotation.Scanned;
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataset.DataSet;
+import org.springframework.util.StringUtils;
 
 import java.util.Collection;
 import java.util.Date;
@@ -94,7 +96,7 @@
      */
     @Scanned
     private Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();
-    
+
     /**
      * Category option group set dimensions to constrain data analytics aggregation.
      */
@@ -363,7 +365,7 @@
 
         return token.equals( this.restoreToken ) && code.equals( this.restoreCode );
     }
-    
+
     /**
      * Returns the dimensions to use as constrains (filters) in data analytics
      * aggregation.
@@ -371,16 +373,16 @@
     public Set<DimensionalObject> getDimensionConstraints()
     {
         Set<DimensionalObject> constraints = new HashSet<DimensionalObject>();
-        
+
         for ( CategoryOptionGroupSet cogs : cogsDimensionConstraints )
         {
             cogs.setDimensionType( DimensionType.CATEGORYOPTION_GROUPSET );
             constraints.add( cogs );
         }
-        
+
         return constraints;
     }
-    
+
     /**
      * Indicates whether this user has dimension constraints.
      */
@@ -447,8 +449,8 @@
     }
 
     @JsonProperty
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public Date getPasswordLastUpdated()
     {
         return passwordLastUpdated;
@@ -460,10 +462,10 @@
     }
 
     @JsonProperty
-    @JsonSerialize(contentAs = BaseIdentifiableObject.class)
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlElementWrapper(localName = "userAuthorityGroups", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty(localName = "userAuthorityGroup", namespace = DxfNamespaces.DXF_2_0)
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "userAuthorityGroups", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "userAuthorityGroup", namespace = DxfNamespaces.DXF_2_0 )
     public Set<UserAuthorityGroup> getUserAuthorityGroups()
     {
         return userAuthorityGroups;
@@ -475,10 +477,10 @@
     }
 
     @JsonProperty
-    @JsonSerialize(contentAs = BaseIdentifiableObject.class)
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlElementWrapper(localName = "cogsDimensionConstraints", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty(localName = "cogsDimensionConstraint", namespace = DxfNamespaces.DXF_2_0)
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "cogsDimensionConstraints", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "cogsDimensionConstraint", namespace = DxfNamespaces.DXF_2_0 )
     public Set<CategoryOptionGroupSet> getCogsDimensionConstraints()
     {
         return cogsDimensionConstraints;
@@ -490,8 +492,8 @@
     }
 
     @JsonProperty
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getUsername()
     {
         return username;
@@ -503,8 +505,8 @@
     }
 
     @JsonProperty
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getOpenId()
     {
         return openId;
@@ -516,8 +518,8 @@
     }
 
     @JsonProperty
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public Date getLastLogin()
     {
         return lastLogin;
@@ -559,8 +561,8 @@
     }
 
     @JsonProperty
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isSelfRegistered()
     {
         return selfRegistered;
@@ -572,8 +574,8 @@
     }
 
     @JsonProperty
-    @JsonView({ DetailedView.class, ExportView.class })
-    @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isDisabled()
     {
         return disabled;
@@ -585,6 +587,28 @@
     }
 
     @Override
+    public void mergeWith( IdentifiableObject other )
+    {
+        super.mergeWith( other );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            UserCredentials userCredentials = (UserCredentials) other;
+
+            openId = userCredentials.getOpenId();
+            disabled = userCredentials.isDisabled();
+            selfRegistered = userCredentials.isSelfRegistered();
+            password = StringUtils.isEmpty( userCredentials.getPassword() ) ? password : userCredentials.getPassword();
+
+            cogsDimensionConstraints.clear();
+            cogsDimensionConstraints.addAll( userCredentials.getCogsDimensionConstraints() );
+
+            userAuthorityGroups.clear();
+            userAuthorityGroups.addAll( userCredentials.getUserAuthorityGroups() );
+        }
+    }
+
+    @Override
     public String toString()
     {
         return "UserCredentials{" +

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-04-02 10:37:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-04-15 07:43:20 +0000
@@ -112,7 +112,7 @@
     @Autowired
     private AclService aclService;
 
-    @Autowired(required = false)
+    @Autowired( required = false )
     private List<ObjectHandler<T>> objectHandlers;
 
     //-------------------------------------------------------------------------------------------------------
@@ -582,7 +582,9 @@
         {
             Map<Field, Collection<Object>> collectionFieldsUserCredentials = detachCollectionFields( userCredentials );
 
+            ((User) persistedObject).getUserCredentials().mergeWith( userCredentials );
             reattachCollectionFields( ((User) persistedObject).getUserCredentials(), collectionFieldsUserCredentials );
+
             sessionFactory.getCurrentSession().saveOrUpdate( ((User) persistedObject).getUserCredentials() );
         }