dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18033
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7439: made dxf2 import/export service notification aware
------------------------------------------------------------
revno: 7439
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-06-27 18:59:59 +0300
message:
made dxf2 import/export service notification aware
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.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/ExportService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.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/scheduling/TaskCategory.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java 2012-04-12 12:39:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java 2012-06-27 15:59:59 +0000
@@ -34,5 +34,6 @@
{
DATAMART,
DATAVALUE_IMPORT,
- METADATA_IMPORT
+ METADATA_IMPORT,
+ METADATA_EXPORT
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-05-28 21:23:50 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2012-06-27 15:59:59 +0000
@@ -31,6 +31,10 @@
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
+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.springframework.beans.factory.annotation.Autowired;
@@ -61,6 +65,9 @@
@Autowired
private CurrentUserService currentUserService;
+ @Autowired
+ private Notifier notifier;
+
//-------------------------------------------------------------------------------------------------------
// ExportService Implementation
//-------------------------------------------------------------------------------------------------------
@@ -68,18 +75,35 @@
@Override
public MetaData getMetaData()
{
- return getMetaData( Options.getDefaultOptions() );
+ return getMetaData( Options.getDefaultOptions(), null );
+ }
+
+ @Override
+ public MetaData getMetaData( TaskId taskId )
+ {
+ return getMetaData( Options.getDefaultOptions(), taskId );
}
@Override
public MetaData getMetaData( Options options )
{
+ return getMetaData( Options.getDefaultOptions(), null );
+ }
+
+ @Override
+ public MetaData getMetaData( Options options, TaskId taskId )
+ {
MetaData metaData = new MetaData();
log.info( "User '" + currentUserService.getCurrentUsername() + "' started export at " + new Date() );
Date lastUpdated = options.getLastUpdated();
+ if ( taskId != null )
+ {
+ notifier.notify( taskId, TaskCategory.METADATA_EXPORT, "Exporting meta-data" );
+ }
+
for ( Map.Entry<Class<? extends IdentifiableObject>, String> entry : ExchangeClasses.getExportMap().entrySet() )
{
if ( !options.isEnabled( entry.getValue() ) )
@@ -105,12 +129,24 @@
continue;
}
- log.info( "Exporting " + idObjects.size() + " " + StringUtils.capitalize( entry.getValue() ) );
+ String message = "Exporting " + idObjects.size() + " " + StringUtils.capitalize( entry.getValue() );
+
+ log.info( message );
+
+ if ( taskId != null )
+ {
+ notifier.notify( taskId, TaskCategory.METADATA_EXPORT, message );
+ }
ReflectionUtils.invokeSetterMethod( entry.getValue(), metaData, new ArrayList<IdentifiableObject>( idObjects ) );
}
- log.info( "Finished export at " + new Date() );
+ log.info( "Export done at " + new Date() );
+
+ if ( taskId != null )
+ {
+ notifier.notify( taskId, TaskCategory.METADATA_IMPORT, NotificationLevel.INFO, "Export done", true );
+ }
return metaData;
}
=== 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 2012-06-23 15:51:43 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-06-27 15:59:59 +0000
@@ -32,6 +32,10 @@
import org.hibernate.SessionFactory;
import org.hisp.dhis.cache.HibernateCacheManager;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
+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.springframework.beans.factory.annotation.Autowired;
@@ -68,11 +72,20 @@
@Autowired
private SessionFactory sessionFactory;
+ @Autowired
+ private Notifier notifier;
+
//-------------------------------------------------------------------------------------------------------
// ImportService Implementation
//-------------------------------------------------------------------------------------------------------
@Override
+ public ImportSummary importMetaData( MetaData metaData, TaskId taskId )
+ {
+ return importMetaData( metaData, ImportOptions.getDefaultImportOptions(), null );
+ }
+
+ @Override
public ImportSummary importMetaData( MetaData metaData )
{
return importMetaData( metaData, ImportOptions.getDefaultImportOptions() );
@@ -81,6 +94,12 @@
@Override
public ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions )
{
+ return importMetaData( metaData, importOptions, null );
+ }
+
+ @Override
+ public ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions, TaskId taskId )
+ {
ImportSummary importSummary = new ImportSummary();
objectBridge.init();
@@ -91,6 +110,11 @@
log.info( "User '" + currentUserService.getCurrentUsername() + "' started import at " + new Date() );
+ if(taskId != null)
+ {
+ notifier.notify( taskId, TaskCategory.METADATA_IMPORT, "Importing meta-data" );
+ }
+
for ( Map.Entry<Class<? extends IdentifiableObject>, String> entry : ExchangeClasses.getImportMap().entrySet() )
{
Object value = ReflectionUtils.invokeGetterMethod( entry.getValue(), metaData );
@@ -103,7 +127,14 @@
if ( !objects.isEmpty() )
{
- log.info( "Importing " + objects.size() + " " + StringUtils.capitalize( entry.getValue() ) );
+ String message = "Importing " + objects.size() + " " + StringUtils.capitalize( entry.getValue() );
+
+ log.info( message );
+
+ if(taskId != null)
+ {
+ notifier.notify( taskId, TaskCategory.METADATA_IMPORT, message );
+ }
ImportTypeSummary importTypeSummary = doImport( objects, importOptions );
@@ -133,7 +164,13 @@
cacheManager.clearCache();
objectBridge.destroy();
- log.info( "Finished import at " + new Date() );
+ log.info( "Import done at " + new Date() );
+
+ if(taskId != null)
+ {
+ notifier.notify( taskId, TaskCategory.METADATA_IMPORT, NotificationLevel.INFO, "Import done", true ).
+ addTaskSummary( taskId, TaskCategory.METADATA_IMPORT, importSummary );
+ }
return importSummary;
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java 2012-05-26 14:32:28 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExportService.java 2012-06-27 15:59:59 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.scheduling.TaskId;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -34,5 +36,9 @@
{
MetaData getMetaData();
+ MetaData getMetaData(TaskId taskId);
+
MetaData getMetaData( Options options );
+
+ MetaData getMetaData( Options options, TaskId taskId );
}
=== 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 2012-06-05 15:36:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java 2012-06-27 15:59:59 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.scheduling.TaskId;
import org.springframework.stereotype.Service;
/**
@@ -37,5 +38,9 @@
{
ImportSummary importMetaData( MetaData metaData );
+ ImportSummary importMetaData( MetaData metaData, TaskId taskId );
+
ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions );
+
+ ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions, TaskId taskId );
}