dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21587
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10248: Import, clearing notifications when starting new import process
------------------------------------------------------------
revno: 10248
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-15 14:13:18 +0100
message:
Import, clearing notifications when starting new import process
modified:
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/ObjectBridge.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/notification/NotifierTest.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
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/webapp/dhis-web-importexport/javascript/importMetaData.js
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js
--
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-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-02-28 15:20:20 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2013-03-15 13:13:18 +0000
@@ -27,12 +27,20 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.scheduling.TaskCategory.METADATA_IMPORT;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
@@ -42,14 +50,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -106,7 +106,10 @@
@Override
public ImportSummary importMetaData( MetaData metaData, ImportOptions importOptions, TaskId taskId )
{
+ notifier.clear( taskId, METADATA_IMPORT ).notify( taskId, METADATA_IMPORT, "Importing meta-data" );
+
ImportSummary importSummary = new ImportSummary();
+
objectBridge.init();
if ( importOptions.isDryRun() )
@@ -114,15 +117,6 @@
objectBridge.setWriteEnabled( false );
}
- if ( taskId != null )
- {
- notifier.notify( taskId, TaskCategory.METADATA_IMPORT, "Importing meta-data" );
- }
- else
- {
- log.info( "User '" + currentUserService.getCurrentUsername() + "' started import at " + new Date() );
- }
-
for ( Map.Entry<Class<? extends IdentifiableObject>, String> entry : ExchangeClasses.getImportMap().entrySet() )
{
Object value = ReflectionUtils.invokeGetterMethod( entry.getValue(), metaData );
@@ -139,7 +133,7 @@
if ( taskId != null )
{
- notifier.notify( taskId, TaskCategory.METADATA_IMPORT, message );
+ notifier.notify( taskId, METADATA_IMPORT, message );
}
else
{
@@ -147,6 +141,7 @@
}
ImportTypeSummary importTypeSummary = doImport( objects, importOptions );
+
// TODO do we need this?
sessionFactory.getCurrentSession().flush();
@@ -178,8 +173,8 @@
if ( taskId != null )
{
- notifier.notify( taskId, TaskCategory.METADATA_IMPORT, NotificationLevel.INFO, "Import done", true ).
- addTaskSummary( taskId, TaskCategory.METADATA_IMPORT, importSummary );
+ notifier.notify( taskId, METADATA_IMPORT, NotificationLevel.INFO, "Import done", true ).
+ addTaskSummary( taskId, METADATA_IMPORT, importSummary );
}
else
{
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java 2013-02-28 15:20:20 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ObjectBridge.java 2013-03-15 13:13:18 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
import java.util.Set;
/**
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/notification/NotifierTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/notification/NotifierTest.java 2012-12-21 12:59:39 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/notification/NotifierTest.java 2013-03-15 13:13:18 +0000
@@ -27,6 +27,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.scheduling.TaskCategory.DATAMART;
+import static org.hisp.dhis.scheduling.TaskCategory.DATAVALUE_IMPORT;
+import static org.hisp.dhis.scheduling.TaskCategory.METADATA_EXPORT;
+import static org.hisp.dhis.scheduling.TaskCategory.METADATA_IMPORT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -34,10 +38,7 @@
import java.util.List;
import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.scheduling.TaskCategory;
import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.system.notification.Notification;
-import org.hisp.dhis.system.notification.Notifier;
import org.hisp.dhis.user.User;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,41 +54,69 @@
private User user = createUser( 'A' );
- private TaskId id1 = new TaskId( TaskCategory.DATAVALUE_IMPORT, user );
- private TaskId id2 = new TaskId( TaskCategory.DATAMART, user );
- private TaskId id3 = new TaskId( TaskCategory.METADATA_IMPORT, user );
+ private TaskId id1 = new TaskId( DATAVALUE_IMPORT, user );
+ private TaskId id2 = new TaskId( DATAMART, user );
+ private TaskId id3 = new TaskId( METADATA_IMPORT, user );
@Test
public void testNotifiy()
{
- notifier.notify( id1, TaskCategory.DATAVALUE_IMPORT, "Import started" );
- notifier.notify( id1, TaskCategory.DATAVALUE_IMPORT, "Import working" );
- notifier.notify( id1, TaskCategory.DATAVALUE_IMPORT, "Import done" );
- notifier.notify( id2, TaskCategory.DATAMART, "Process started" );
- notifier.notify( id2, TaskCategory.DATAMART, "Process done" );
+ notifier.notify( id1, DATAVALUE_IMPORT, "Import started" );
+ notifier.notify( id1, DATAVALUE_IMPORT, "Import working" );
+ notifier.notify( id1, DATAVALUE_IMPORT, "Import done" );
+ notifier.notify( id2, DATAMART, "Process started" );
+ notifier.notify( id2, DATAMART, "Process done" );
- List<Notification> notifications = notifier.getNotifications( id1, TaskCategory.DATAVALUE_IMPORT, null );
+ List<Notification> notifications = notifier.getNotifications( id1, DATAVALUE_IMPORT, null );
assertNotNull( notifications );
assertEquals( 3, notifications.size() );
- notifications = notifier.getNotifications( id2, TaskCategory.DATAMART, null );
+ notifications = notifier.getNotifications( id2, DATAMART, null );
assertNotNull( notifications );
assertEquals( 2, notifications.size() );
- notifications = notifier.getNotifications( id3, TaskCategory.METADATA_IMPORT, null );
+ notifications = notifier.getNotifications( id3, METADATA_IMPORT, null );
assertNotNull( notifications );
assertEquals( 0, notifications.size() );
}
+
+ @Test
+ public void testClearNotifications()
+ {
+ notifier.notify( id1, DATAVALUE_IMPORT, "Import started" );
+ notifier.notify( id1, DATAVALUE_IMPORT, "Import working" );
+ notifier.notify( id1, DATAVALUE_IMPORT, "Import done" );
+ notifier.notify( id2, DATAMART, "Process started" );
+ notifier.notify( id2, DATAMART, "Process done" );
+
+ assertEquals( 3, notifier.getNotifications( id1, DATAVALUE_IMPORT, null ).size() );
+ assertEquals( 2, notifier.getNotifications( id2, DATAMART, null ).size() );
+
+ notifier.clear( id1, METADATA_EXPORT );
+
+ assertEquals( 3, notifier.getNotifications( id1, DATAVALUE_IMPORT, null ).size() );
+ assertEquals( 2, notifier.getNotifications( id2, DATAMART, null ).size() );
+
+ notifier.clear( id1, DATAVALUE_IMPORT );
+
+ assertEquals( 0, notifier.getNotifications( id1, DATAVALUE_IMPORT, null ).size() );
+ assertEquals( 2, notifier.getNotifications( id2, DATAMART, null ).size() );
+
+ notifier.clear( id2, DATAMART );
+
+ assertEquals( 0, notifier.getNotifications( id1, DATAVALUE_IMPORT, null ).size() );
+ assertEquals( 0, notifier.getNotifications( id2, DATAMART, null ).size() );
+ }
@Test
public void testTaskSummary()
{
- notifier.addTaskSummary( id1, TaskCategory.DATAVALUE_IMPORT, new Object() );
+ notifier.addTaskSummary( id1, DATAVALUE_IMPORT, new Object() );
- assertNotNull( notifier.getTaskSummary( id1, TaskCategory.DATAVALUE_IMPORT ) );
- assertNull( notifier.getTaskSummary( id1, TaskCategory.DATAMART ) );
+ assertNotNull( notifier.getTaskSummary( id1, DATAVALUE_IMPORT ) );
+ assertNull( notifier.getTaskSummary( id1, DATAMART ) );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js 2013-03-14 17:20:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js 2013-03-15 13:13:18 +0000
@@ -1773,11 +1773,11 @@
// -----------------------------------------------------------------------------
function pingNotifications( category, tableId, completedCallback )
-{
+{
var lastUid = $( '#' + tableId ).prop( 'lastUid' ); // Store on table property
var param = lastUid ? '&lastUid=' + lastUid : '';
-
+
$.getJSON( '../dhis-web-commons-ajax-json/getNotifications.action?category=' + category + param, function( json )
{
var html = '';
=== 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 2012-07-04 20:16:23 +0000
+++ 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
@@ -54,7 +54,8 @@
private TaskId taskId;
- public ImportMetaDataTask( ImportService importService, ImportOptions importOptions, InputStream inputStream, TaskId taskId )
+ public ImportMetaDataTask( ImportService importService, ImportOptions importOptions, InputStream inputStream,
+ TaskId taskId )
{
this.importService = importService;
this.importOptions = importOptions;
@@ -70,8 +71,10 @@
try
{
// TODO check for XML/JSON
+
metaData = JacksonUtils.fromXml( inputStream, MetaData.class );
- } catch ( IOException e )
+ }
+ catch ( IOException e )
{
log.error( "(IOException) Unable to parse meta-data while reading input stream" );
return;
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/importMetaData.js'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/importMetaData.js 2012-07-04 20:16:23 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/javascript/importMetaData.js 2013-03-15 13:13:18 +0000
@@ -15,7 +15,7 @@
function pingNotificationsTimeout()
{
pingNotifications( 'METADATA_IMPORT', 'notificationTable', displaySummaryLink );
- pingTimeout = setTimeout( "pingNotificationsTimeout()", 1500 );
+ pingTimeout = setTimeout( "pingNotificationsTimeout()", 2000 );
}
function displaySummaryLink()
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js 2013-03-06 10:51:15 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js 2013-03-15 13:13:18 +0000
@@ -29,7 +29,7 @@
function pingNotificationsTimeout()
{
pingNotifications( 'DATAMART', 'notificationTable' );
- setTimeout( "pingNotificationsTimeout()", 2500 );
+ setTimeout( "pingNotificationsTimeout()", 2000 );
}
function toggleDataMart()