← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7157: Implemented basic error handling for datavalueset web api resource

 

------------------------------------------------------------
revno: 7157
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-06-03 17:04:33 +0200
message:
  Implemented basic error handling for datavalueset web api resource
added:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java
modified:
  dhis-2/dhis-dxf2/pom.xml
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java
  dhis-2/dhis-support/dhis-support-xml/pom.xml
  dhis-2/pom.xml


--
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/pom.xml'
--- dhis-2/dhis-dxf2/pom.xml	2012-05-10 09:57:03 +0000
+++ dhis-2/dhis-dxf2/pom.xml	2012-06-03 15:04:33 +0000
@@ -40,6 +40,10 @@
 	  <groupId>net.sf.opencsv</groupId>
 	  <artifactId>opencsv</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.amplecode</groupId>
+      <artifactId>staxwax</artifactId>
+    </dependency>
 	
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-06-01 14:14:32 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-06-03 15:04:33 +0000
@@ -49,6 +49,8 @@
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
 import org.amplecode.staxwax.factory.XMLFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.DataElement;
@@ -61,6 +63,7 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.importsummary.ImportCount;
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.importexport.ImportStrategy;
@@ -84,6 +87,8 @@
 public class DefaultDataValueSetService
     implements DataValueSetService
 {
+    private static final Log log = LogFactory.getLog( DefaultDataValueSetService.class );
+    
     private static final String ERROR_INVALID_DATA_SET = "Invalid data set: ";
     private static final String ERROR_INVALID_PERIOD = "Invalid period: ";
     private static final String ERROR_INVALID_ORG_UNIT = "Invalid org unit: ";
@@ -186,8 +191,9 @@
         }
         catch ( RuntimeException ex )
         {
-            notifier.notify( id, DATAVALUE_IMPORT, ERROR, "Unfortunately the process failed, check the logs", true );            
-            throw ex;
+            log.error( ex );
+            notifier.notify( id, DATAVALUE_IMPORT, ERROR, "Unfortunately the process failed, check the logs", true );
+            return new ImportSummary( ImportStatus.ERROR, "The import process failed: " + ex.getMessage() );
         }
     }
 
@@ -200,8 +206,9 @@
         }
         catch ( RuntimeException ex )
         {
-            notifier.clear( id, DATAVALUE_IMPORT ).notify( id, DATAVALUE_IMPORT, ERROR, "Unfortunately the process failed, check the logs", true );            
-            throw ex;
+            log.error( ex );
+            notifier.clear( id, DATAVALUE_IMPORT ).notify( id, DATAVALUE_IMPORT, ERROR, "Unfortunately the process failed, check the logs", true );
+            return new ImportSummary( ImportStatus.ERROR, "The import process failed: " + ex.getMessage() );
         }
     }
 
@@ -337,11 +344,13 @@
             }
         }
         
+        batchHandler.flush();
+
         int ignores = totalCount - importCount - updateCount;
         
         summary.setDataValueCount( new ImportCount( importCount, updateCount, ignores ) );
-        
-        batchHandler.flush();
+        summary.setStatus( ImportStatus.SUCCESS );
+        summary.setDescription( "Import process completed successfully" );
         
         notifier.notify( id, DATAVALUE_IMPORT, INFO, "Import done", true ).addTaskSummary( id, DATAVALUE_IMPORT, summary );
         

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java	2012-06-03 15:04:33 +0000
@@ -0,0 +1,34 @@
+package org.hisp.dhis.dxf2.importsummary;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+public enum ImportStatus
+{
+    SUCCESS,
+    ERROR
+}

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java	2012-06-02 21:19:29 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java	2012-06-03 15:04:33 +0000
@@ -38,6 +38,8 @@
 @JacksonXmlRootElement( localName = "importSummary" )
 public class ImportSummary
 {
+    private ImportStatus status;
+    
     private String description;
     
     private ImportCount dataValueCount;
@@ -46,6 +48,28 @@
 
     private String dataSetComplete;
 
+    public ImportSummary()
+    {
+    }
+    
+    public ImportSummary( ImportStatus status, String description )
+    {
+        this.status = status;
+        this.description = description;
+    }
+    
+    @JsonProperty
+    @JacksonXmlProperty
+    public ImportStatus getStatus()
+    {
+        return status;
+    }
+
+    public void setStatus( ImportStatus status )
+    {
+        this.status = status;
+    }
+
     @JsonProperty
     @JacksonXmlProperty
     public String getDescription()

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java	2012-04-12 12:39:47 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java	2012-06-03 15:04:33 +0000
@@ -133,7 +133,7 @@
         
         return this;
     }
-
+    
     @Override
     public Notifier addTaskSummary( TaskId id, TaskCategory category, Object taskSummary )
     {

=== modified file 'dhis-2/dhis-support/dhis-support-xml/pom.xml'
--- dhis-2/dhis-support/dhis-support-xml/pom.xml	2012-05-10 09:57:03 +0000
+++ dhis-2/dhis-support/dhis-support-xml/pom.xml	2012-06-03 15:04:33 +0000
@@ -25,6 +25,10 @@
     <!-- Other -->
 
     <dependency>
+      <groupId>org.amplecode</groupId>
+      <artifactId>staxwax</artifactId>
+    </dependency>
+    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
     </dependency>

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2012-05-16 09:55:42 +0000
+++ dhis-2/pom.xml	2012-06-03 15:04:33 +0000
@@ -58,7 +58,7 @@
     <repository>
       <id>amplecode_maven2_repo</id>
       <name>AmpleCode Maven 2 repository</name>
-      <url>http://www.amplecode.org/maven2</url>
+      <url>http://maven.dhis2.org/amplecode-local</url>
     </repository>
     <repository>
       <id>dhis.uio.no</id>
@@ -453,6 +453,11 @@
         <version>1.7.1</version>
       </dependency>
       <dependency>
+        <groupId>org.amplecode</groupId>
+        <artifactId>staxwax</artifactId>
+        <version>1.0.9</version>
+      </dependency>
+      <dependency>
         <groupId>com.lowagie</groupId>
         <artifactId>itext</artifactId>
         <version>2.1.7</version>