← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10268: report conflict if user is not allowed to update object

 

------------------------------------------------------------
revno: 10268
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-03-16 21:22:03 +0700
message:
  report conflict if user is not allowed to update object
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.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/common/SharingUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java	2013-03-16 05:57:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java	2013-03-16 14:22:03 +0000
@@ -195,8 +195,10 @@
      */
     public static boolean canWrite( User user, IdentifiableObject object )
     {
-        if ( sharingOverrideAuthority( user ) || object.getUser() == null || user.equals( object.getUser() ) ||
-            AccessStringHelper.canWrite( object.getPublicAccess() ) )
+        if ( sharingOverrideAuthority( user )
+            || object.getUser() == null
+            || object.getUser().equals( user )
+            || AccessStringHelper.canWrite( object.getPublicAccess() ) )
         {
             return true;
         }
@@ -228,8 +230,10 @@
      */
     public static boolean canRead( User user, IdentifiableObject object )
     {
-        if ( sharingOverrideAuthority( user ) || object.getUser() == null || user.equals( object.getUser() ) ||
-            AccessStringHelper.canRead( object.getPublicAccess() ) )
+        if ( sharingOverrideAuthority( user )
+            || object.getUser() == null
+            || object.getUser().equals( user )
+            || AccessStringHelper.canRead( object.getPublicAccess() ) )
         {
             return true;
         }
@@ -308,7 +312,7 @@
 
     private static boolean sharingOverrideAuthority( User user )
     {
-        return user != null && user.getUserCredentials().getAllAuthorities().contains( SHARING_OVERRIDE_AUTHORITY );
+        return user == null || user.getUserCredentials().getAllAuthorities().contains( SHARING_OVERRIDE_AUTHORITY );
     }
 
     private SharingUtils()

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2013-03-16 11:27:06 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2013-03-16 14:22:03 +0000
@@ -36,8 +36,8 @@
 import org.hisp.dhis.system.notification.NotificationLevel;
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.ReflectionUtils;
-import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
@@ -73,7 +73,7 @@
     private HibernateCacheManager cacheManager;
 
     @Autowired
-    private CurrentUserService currentUserService;
+    private UserService userService;
 
     @Autowired
     private SessionFactory sessionFactory;
@@ -86,26 +86,28 @@
     //-------------------------------------------------------------------------------------------------------
 
     @Override
-    public ImportSummary importMetaData( User user, MetaData metaData, TaskId taskId )
-    {
-        return importMetaData( user, metaData, ImportOptions.getDefaultImportOptions(), taskId );
-    }
-
-    @Override
-    public ImportSummary importMetaData( User user, MetaData metaData )
-    {
-        return importMetaData( user, metaData, ImportOptions.getDefaultImportOptions() );
-    }
-
-    @Override
-    public ImportSummary importMetaData( User user, MetaData metaData, ImportOptions importOptions )
-    {
-        return importMetaData( user, metaData, importOptions, null );
-    }
-
-    @Override
-    public ImportSummary importMetaData( User user, MetaData metaData, ImportOptions importOptions, TaskId taskId )
-    {
+    public ImportSummary importMetaData( String userUid, MetaData metaData, TaskId taskId )
+    {
+        return importMetaData( userUid, metaData, ImportOptions.getDefaultImportOptions(), taskId );
+    }
+
+    @Override
+    public ImportSummary importMetaData( String userUid, MetaData metaData )
+    {
+        return importMetaData( userUid, metaData, ImportOptions.getDefaultImportOptions() );
+    }
+
+    @Override
+    public ImportSummary importMetaData( String userUid, MetaData metaData, ImportOptions importOptions )
+    {
+        return importMetaData( userUid, metaData, importOptions, null );
+    }
+
+    @Override
+    public ImportSummary importMetaData( String userUid, MetaData metaData, ImportOptions importOptions, TaskId taskId )
+    {
+        User user = userService.getUser( userUid );
+
         log.info( "User '" + user.getUsername() + "' started import at " + new Date() );
 
         notifier.clear( taskId ).notify( taskId, "Importing meta-data" );
@@ -142,7 +144,7 @@
                             log.info( message );
                         }
 
-                        ImportTypeSummary importTypeSummary = doImport( objects, importOptions );
+                        ImportTypeSummary importTypeSummary = doImport( user, objects, importOptions );
 
                         // TODO do we need this?
                         sessionFactory.getCurrentSession().flush();
@@ -216,7 +218,7 @@
         return null;
     }
 
-    private <T> ImportTypeSummary doImport( List<T> objects, ImportOptions importOptions )
+    private <T> ImportTypeSummary doImport( User user, List<T> objects, ImportOptions importOptions )
     {
         if ( !objects.isEmpty() && objects.get( 0 ) != null )
         {
@@ -224,7 +226,7 @@
 
             if ( importer != null )
             {
-                return importer.importObjects( objects, importOptions );
+                return importer.importObjects( user, objects, importOptions );
             }
             else
             {

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java	2013-03-16 11:27:06 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java	2013-03-16 14:22:03 +0000
@@ -28,7 +28,6 @@
  */
 
 import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.user.User;
 import org.springframework.stereotype.Service;
 
 /**
@@ -37,11 +36,11 @@
 @Service
 public interface ImportService
 {
-    ImportSummary importMetaData( User user, MetaData metaData );
-
-    ImportSummary importMetaData( User user, MetaData metaData, TaskId taskId );
-
-    ImportSummary importMetaData( User user, MetaData metaData, ImportOptions importOptions );
-
-    ImportSummary importMetaData( User user, MetaData metaData, ImportOptions importOptions, TaskId taskId );
+    ImportSummary importMetaData( String userUid, MetaData metaData );
+
+    ImportSummary importMetaData( String userUid, MetaData metaData, TaskId taskId );
+
+    ImportSummary importMetaData( String userUid, MetaData metaData, ImportOptions importOptions );
+
+    ImportSummary importMetaData( String userUid, MetaData metaData, ImportOptions importOptions, TaskId taskId );
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java	2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportSummary.java	2013-03-16 14:22:03 +0000
@@ -102,4 +102,13 @@
     {
         importCount.incrementIgnored( n );
     }
+
+    @Override
+    public String toString()
+    {
+        return "ImportSummary{" +
+            "importCount=" + importCount +
+            ", importTypeSummaries=" + importTypeSummaries +
+            '}';
+    }
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java	2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportTypeSummary.java	2013-03-16 14:22:03 +0000
@@ -112,4 +112,14 @@
     {
         importCount.incrementIgnored();
     }
+
+    @Override
+    public String toString()
+    {
+        return "ImportTypeSummary{" +
+            "type='" + type + '\'' +
+            ", importCount=" + importCount +
+            ", importConflicts=" + importConflicts +
+            '}';
+    }
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java	2012-06-05 15:36:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Importer.java	2013-03-16 14:22:03 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.user.User;
+
 import java.util.List;
 
 /**
@@ -44,7 +46,7 @@
      * @param options Import options
      * @return ImportConflict instance if a conflict occurred, if not null
      */
-    ImportTypeSummary importObject( T object, ImportOptions options );
+    ImportTypeSummary importObject( User user, T object, ImportOptions options );
 
     /**
      * Import a collection of objects.
@@ -53,7 +55,7 @@
      * @param options Import options
      * @return List of all the ImportConflicts encountered
      */
-    ImportTypeSummary importObjects( List<T> objects, ImportOptions options );
+    ImportTypeSummary importObjects( User user, List<T> objects, ImportOptions options );
 
     /**
      * Can this importer handle a certain Class type?

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-03-01 12:56:34 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-03-16 14:22:03 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.NameableObject;
+import org.hisp.dhis.common.SharingUtils;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementOperandService;
 import org.hisp.dhis.dataentryform.DataEntryForm;
@@ -58,6 +59,7 @@
 import org.hisp.dhis.system.util.CollectionUtils;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.hisp.dhis.system.util.functional.Function1;
+import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.lang.reflect.Field;
@@ -417,12 +419,21 @@
     /**
      * Update idObject from old => new.
      *
+     * @param user
      * @param object          Object to import
      * @param persistedObject The current version of the idObject
      * @return An ImportConflict instance if there was a conflict, otherwise null
      */
-    protected boolean updateObject( T object, T persistedObject )
+    protected boolean updateObject( User user, T object, T persistedObject )
     {
+        if ( !SharingUtils.canUpdate( user, persistedObject ) )
+        {
+            summaryType.getImportConflicts().add(
+                new ImportConflict( ImportUtils.getDisplayName( object ), "You do not have update access to object." ) );
+
+            return false;
+        }
+
         NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects();
         nonIdentifiableObjects.extract( object );
         nonIdentifiableObjects.delete( persistedObject );
@@ -440,11 +451,6 @@
         log.debug( "Starting update of object " + ImportUtils.getDisplayName( persistedObject ) + " (" + persistedObject.getClass()
             .getSimpleName() + ")" );
 
-        if ( persistedObject.getName().contains( "java" ) )
-        {
-            System.err.println( "clazz: " + persistedObject.getClass().getName() + ", persistedObject: " + persistedObject );
-        }
-
         objectBridge.updateObject( persistedObject );
 
         if ( !options.isDryRun() )
@@ -475,7 +481,7 @@
     //-------------------------------------------------------------------------------------------------------
 
     @Override
-    public ImportTypeSummary importObjects( List<T> objects, ImportOptions options )
+    public ImportTypeSummary importObjects( User user, List<T> objects, ImportOptions options )
     {
         this.options = options;
         this.summaryType = new ImportTypeSummary( importerClass.getSimpleName() );
@@ -490,7 +496,7 @@
         for ( T object : objects )
         {
             ObjectHandlerUtils.preObjectHandlers( object, objectHandlers );
-            importObjectLocal( object );
+            importObjectLocal( user, object );
             ObjectHandlerUtils.postObjectHandlers( object, objectHandlers );
         }
 
@@ -500,13 +506,13 @@
     }
 
     @Override
-    public ImportTypeSummary importObject( T object, ImportOptions options )
+    public ImportTypeSummary importObject( User user, T object, ImportOptions options )
     {
         this.options = options;
         this.summaryType = new ImportTypeSummary( importerClass.getSimpleName() );
 
         ObjectHandlerUtils.preObjectHandlers( object, objectHandlers );
-        importObjectLocal( object );
+        importObjectLocal( user, object );
         ObjectHandlerUtils.postObjectHandlers( object, objectHandlers );
 
         return summaryType;
@@ -522,11 +528,11 @@
     // Helpers
     //-------------------------------------------------------------------------------------------------------
 
-    private void importObjectLocal( T object )
+    private void importObjectLocal( User user, T object )
     {
         if ( validateIdentifiableObject( object ) )
         {
-            startImport( object );
+            startImport( user, object );
         }
         else
         {
@@ -534,7 +540,7 @@
         }
     }
 
-    private void startImport( T object )
+    private void startImport( User user, T object )
     {
         T oldObject = objectBridge.getObject( object );
 
@@ -547,7 +553,7 @@
         }
         else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) )
         {
-            if ( updateObject( object, oldObject ) )
+            if ( updateObject( user, object, oldObject ) )
             {
                 summaryType.incrementUpdated();
             }
@@ -556,7 +562,7 @@
         {
             if ( oldObject != null )
             {
-                if ( updateObject( object, oldObject ) )
+                if ( updateObject( user, object, oldObject ) )
                 {
                     summaryType.incrementUpdated();
                 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java	2013-03-16 11:27:06 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java	2013-03-16 14:22:03 +0000
@@ -31,7 +31,6 @@
 import org.hisp.dhis.dxf2.metadata.ImportService;
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.user.User;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -39,7 +38,7 @@
 public class ImportMetaDataTask
     implements Runnable
 {
-    private User user;
+    private String userUid;
 
     private ImportService importService;
 
@@ -49,9 +48,9 @@
 
     private MetaData metaData;
 
-    public ImportMetaDataTask( User user, ImportService importService, ImportOptions importOptions, TaskId taskId, MetaData metaData )
+    public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions, TaskId taskId, MetaData metaData )
     {
-        this.user = user;
+        this.userUid = userUid;
         this.importService = importService;
         this.importOptions = importOptions;
         this.taskId = taskId;
@@ -61,6 +60,6 @@
     @Override
     public void run()
     {
-        importService.importMetaData( user, metaData, importOptions, taskId );
+        importService.importMetaData( userUid, metaData, importOptions, taskId );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java	2013-03-16 11:27:06 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2MetaDataProducer.java	2013-03-16 14:22:03 +0000
@@ -62,7 +62,7 @@
         Dxf2MetaDataEndpoint endpoint = (Dxf2MetaDataEndpoint) this.getEndpoint();
         MetaData metadata = JacksonUtils.fromXml( (InputStream) exchange.getIn().getBody(), MetaData.class );
 
-        ImportSummary summary = endpoint.getImportService().importMetaData( user, metadata, endpoint.getImportOptions() );
+        ImportSummary summary = endpoint.getImportService().importMetaData( user.getUid(), metadata, endpoint.getImportOptions() );
         exchange.getOut().setBody( JacksonUtils.toXmlAsString( summary ) );
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-03-14 08:04:13 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-03-16 14:22:03 +0000
@@ -212,7 +212,7 @@
         if ( !isWriteAllowed( object ) )
         {
             AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_CREATE_DENIED );
-            throw new AccessDeniedException( "You do not have write access to object" );
+            throw new AccessDeniedException( "You do not have write access to object." );
         }
 
         if ( currentUserService.getCurrentUser() != null && SharingUtils.isSupported( clazz ) )
@@ -240,7 +240,7 @@
             else
             {
                 AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_CREATE_DENIED );
-                throw new AccessDeniedException( "You are not allowed to create public or private objects of this kind" );
+                throw new AccessDeniedException( "You are not allowed to create public or private objects of this kind." );
             }
         }
 
@@ -254,7 +254,7 @@
         if ( !isUpdateAllowed( object ) )
         {
             AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_UPDATE_DENIED );
-            throw new AccessDeniedException( "You do not have update access to object" );
+            throw new AccessDeniedException( "You do not have update access to object." );
         }
 
         AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_UPDATE );
@@ -270,7 +270,7 @@
         if ( !isReadAllowed( object ) )
         {
             AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_READ_DENIED );
-            throw new AccessDeniedException( "You do not have read access to object with id " + id );
+            throw new AccessDeniedException( "You do not have read access to object with id " + id + "." );
         }
 
         // AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_READ );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java	2013-03-16 11:27:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java	2013-03-16 14:22:03 +0000
@@ -228,7 +228,7 @@
 
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
-        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser(), importService, importOptions, taskId, metaData ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, taskId, metaData ) );
 
         response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
         response.setStatus( HttpServletResponse.SC_NO_CONTENT );
@@ -242,7 +242,7 @@
 
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
-        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser(), importService, importOptions, taskId, metaData ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, taskId, metaData ) );
 
         response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
         response.setStatus( HttpServletResponse.SC_NO_CONTENT );
@@ -259,7 +259,7 @@
 
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
-        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser(), importService, importOptions, taskId, metaData ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, taskId, metaData ) );
 
         response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
         response.setStatus( HttpServletResponse.SC_NO_CONTENT );
@@ -276,7 +276,7 @@
 
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
-        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser(), importService, importOptions, taskId, metaData ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, taskId, metaData ) );
 
         response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
         response.setStatus( HttpServletResponse.SC_NO_CONTENT );
@@ -291,7 +291,7 @@
 
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
-        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser(), importService, importOptions, taskId, metaData ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, taskId, metaData ) );
 
         response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
         response.setStatus( HttpServletResponse.SC_NO_CONTENT );
@@ -306,7 +306,7 @@
 
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
-        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser(), importService, importOptions, taskId, metaData ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, taskId, metaData ) );
 
         response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
         response.setStatus( HttpServletResponse.SC_NO_CONTENT );

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2013-03-15 16:33:34 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/dxf2/MetaDataImportAction.java	2013-03-16 14:22:03 +0000
@@ -27,10 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.dxf2.metadata.ImportService;
 import org.hisp.dhis.importexport.ImportStrategy;
@@ -43,7 +40,9 @@
 import org.hisp.dhis.user.CurrentUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import com.opensymphony.xwork2.Action;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -63,7 +62,7 @@
 
     @Autowired
     private Scheduler scheduler;
-    
+
     @Autowired
     private Notifier notifier;
 
@@ -104,7 +103,7 @@
         TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
 
         notifier.clear( taskId );
-        
+
         InputStream in = new FileInputStream( upload );
         in = StreamUtils.wrapAndCheckCompressionFormat( in );
 
@@ -112,7 +111,7 @@
         importOptions.setStrategy( strategy.toString() );
         importOptions.setDryRun( dryRun );
 
-        scheduler.executeTask( new ImportMetaDataTask( importService, importOptions, in, taskId ) );
+        scheduler.executeTask( new ImportMetaDataTask( currentUserService.getCurrentUser().getUid(), importService, importOptions, in, taskId ) );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java	2013-03-15 13:13:18 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java	2013-03-16 14:22:03 +0000
@@ -54,24 +54,26 @@
 
     private TaskId taskId;
 
-    public ImportMetaDataTask( ImportService importService, ImportOptions importOptions, InputStream inputStream,
+    private String userUid;
+
+    public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions, InputStream inputStream,
         TaskId taskId )
     {
         this.importService = importService;
         this.importOptions = importOptions;
         this.inputStream = inputStream;
         this.taskId = taskId;
+        this.userUid = userUid;
     }
 
     @Override
     public void run()
     {
-        MetaData metaData = null;
+        MetaData metaData;
 
         try
         {
             // TODO check for XML/JSON
-            
             metaData = JacksonUtils.fromXml( inputStream, MetaData.class );
         }
         catch ( IOException e )
@@ -80,6 +82,6 @@
             return;
         }
 
-        importService.importMetaData( metaData, importOptions, taskId );
+        importService.importMetaData( userUid, metaData, importOptions, taskId );
     }
 }