← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14604: set CREATE stragy for POSTs, and UPDATE strategy for PUTs in crudController (and userController)

 

------------------------------------------------------------
revno: 14604
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-04-02 18:36:07 +0700
message:
  set CREATE stragy for POSTs, and UPDATE strategy for PUTs in crudController (and userController)
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2014-04-02 05:00:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2014-04-02 11:36:07 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dxf2.timer.SystemNanoTimer;
 import org.hisp.dhis.dxf2.timer.Timer;
+import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.system.notification.NotificationLevel;
 import org.hisp.dhis.system.notification.Notifier;
@@ -91,13 +92,14 @@
     //-------------------------------------------------------------------------------------------------------
 
     @Override
-    public <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object )
+    public <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object, ImportStrategy importStrategy )
     {
         User user = userService.getUser( userUid );
 
         ImportOptions importOptions = new ImportOptions();
         importOptions.setDryRun( false );
         importOptions.setPreheatCache( false );
+        importOptions.setImportStrategy( importStrategy.toString() );
 
         objectBridge.setWriteEnabled( !importOptions.isDryRun() );
         objectBridge.setPreheatCache( importOptions.isPreheatCache() );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java	2014-04-02 05:00:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java	2014-04-02 11:36:07 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.scheduling.TaskId;
 import org.springframework.stereotype.Service;
 
@@ -38,7 +39,7 @@
 @Service
 public interface ImportService
 {
-    <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object );
+    <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object, ImportStrategy importStrategy );
 
     ImportSummary importMetaData( String userUid, MetaData metaData );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-04-02 10:43:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-04-02 11:36:07 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.hibernate.exception.CreateAccessDeniedException;
 import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
 import org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException;
+import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.system.util.ReflectionUtils;
@@ -271,7 +272,7 @@
         }
 
         T parsed = renderService.fromXml( request.getInputStream(), getEntityClass() );
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.CREATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 
@@ -284,7 +285,7 @@
         }
 
         T parsed = renderService.fromJson( request.getInputStream(), getEntityClass() );
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.CREATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 
@@ -313,7 +314,7 @@
         T parsed = renderService.fromXml( request.getInputStream(), getEntityClass() );
         ((BaseIdentifiableObject) parsed).setUid( uid );
 
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 
@@ -338,7 +339,7 @@
         T parsed = renderService.fromJson( request.getInputStream(), getEntityClass() );
         ((BaseIdentifiableObject) parsed).setUid( uid );
 
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java	2014-04-02 10:51:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java	2014-04-02 11:36:07 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.dxf2.metadata.ImportTypeSummary;
 import org.hisp.dhis.hibernate.exception.CreateAccessDeniedException;
 import org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException;
+import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.security.PasswordManager;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserService;
@@ -62,7 +63,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping(value = UserController.RESOURCE_PATH)
+@RequestMapping( value = UserController.RESOURCE_PATH )
 public class UserController
     extends AbstractCrudController<User>
 {
@@ -75,15 +76,15 @@
     private PasswordManager passwordManager;
 
     @Override
-    @PreAuthorize("hasRole('ALL') or hasRole('F_USER_VIEW')")
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_USER_VIEW')" )
     public String getObjectList( @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request )
     {
         return super.getObjectList( parameters, model, response, request );
     }
 
     @Override
-    @PreAuthorize("hasRole('ALL') or hasRole('F_USER_VIEW')")
-    public String getObject( @PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model,
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_USER_VIEW')" )
+    public String getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters, Model model,
         HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         return super.getObject( uid, parameters, model, request, response );
@@ -140,7 +141,7 @@
             user.getUserCredentials().getPassword() );
         user.getUserCredentials().setPassword( encodePassword );
 
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), user );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), user, ImportStrategy.CREATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 
@@ -159,7 +160,7 @@
             user.getUserCredentials().getPassword() );
         user.getUserCredentials().setPassword( encodePassword );
 
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), user );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), user, ImportStrategy.CREATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 
@@ -192,7 +193,7 @@
             parsed.getUserCredentials().getPassword() );
         parsed.getUserCredentials().setPassword( encodePassword );
 
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 
@@ -221,7 +222,7 @@
             parsed.getUserCredentials().getPassword() );
         parsed.getUserCredentials().setPassword( encodePassword );
 
-        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed );
+        ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
         renderService.toJson( response.getOutputStream(), summary );
     }
 }