← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21626: User replication. Including user settings.

 

------------------------------------------------------------
revno: 21626
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-01-06 17:48:58 +0100
message:
  User replication. Including user settings.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.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-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java	2016-01-06 14:25:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java	2016-01-06 16:48:58 +0000
@@ -30,16 +30,17 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.common.AnalyticalObjectService;
+import org.hisp.dhis.common.GenericAnalyticalObjectDeletionHandler;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
-import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  * @author Chau Thu Tran
  */
 public class EventChartDeletionHandler
-    extends DeletionHandler
+    extends GenericAnalyticalObjectDeletionHandler<EventChart>
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -53,6 +54,12 @@
     // -------------------------------------------------------------------------
 
     @Override
+    protected AnalyticalObjectService<EventChart> getAnalyticalObjectService()
+    {
+        return eventChartService;
+    }
+    
+    @Override
     protected String getClassName()
     {
         return EventChart.class.getSimpleName();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java	2016-01-06 14:37:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java	2016-01-06 16:48:58 +0000
@@ -30,16 +30,17 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.common.AnalyticalObjectService;
+import org.hisp.dhis.common.GenericAnalyticalObjectDeletionHandler;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
-import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  * @author Chau Thu Tran
  */
 public class EventReportDeletionHandler
-    extends DeletionHandler
+    extends GenericAnalyticalObjectDeletionHandler<EventReport>
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -59,6 +60,12 @@
     }
 
     @Override
+    protected AnalyticalObjectService<EventReport> getAnalyticalObjectService()
+    {
+        return eventReportService;
+    }
+    
+    @Override
     public void deleteProgramStage( ProgramStage programStage )
     {
         Collection<EventReport> charts = eventReportService.getAllEventReports();

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2016-01-06 16:48:58 +0000
@@ -28,7 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.hisp.dhis.common.CodeGenerator;
@@ -55,6 +54,9 @@
 import org.hisp.dhis.user.UserInvitationStatus;
 import org.hisp.dhis.user.UserQueryParams;
 import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSetting;
+import org.hisp.dhis.user.UserSettingKey;
+import org.hisp.dhis.user.UserSettingService;
 import org.hisp.dhis.user.Users;
 import org.hisp.dhis.webapi.controller.AbstractCrudController;
 import org.hisp.dhis.webapi.utils.ContextUtils;
@@ -74,6 +76,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -100,6 +103,9 @@
 
     @Autowired
     private OrganisationUnitService organisationUnitService;
+    
+    @Autowired
+    private UserSettingService userSettingService;
 
     // -------------------------------------------------------------------------
     // GET
@@ -149,7 +155,7 @@
     protected List<User> getEntity( String uid, WebOptions options )
     {
         List<User> users = Lists.newArrayList();
-        Optional<User> user = Optional.fromNullable( userService.getUser( uid ) );
+        Optional<User> user = Optional.ofNullable( userService.getUser( uid ) );
 
         if ( user.isPresent() )
         {
@@ -345,6 +351,22 @@
         userService.addUserCredentials( credentialsReplica );
         userGroupService.addUserToGroups( userReplica, IdentifiableObjectUtils.getUids( existingUser.getGroups() ) );
 
+        // ---------------------------------------------------------------------
+        // Replicate user settings
+        // ---------------------------------------------------------------------
+
+        List<UserSetting> settings = userSettingService.getUserSettings( existingUser );
+        
+        for ( UserSetting setting : settings )
+        {
+            Optional<UserSettingKey> key = UserSettingKey.getByName( setting.getName() );
+            
+            if ( key.isPresent() )
+            {
+                userSettingService.saveUserSetting( key.get(), setting.getValue(), userReplica );
+            }            
+        }
+        
         response.addHeader( "Location", UserSchemaDescriptor.API_ENDPOINT + "/" + userReplica.getUid() );
         webMessageService.send( WebMessageUtils.created( "User replica created" ), response, request );
     }