← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22244: minor refactor of stats feedback in dxf2 importer

 

------------------------------------------------------------
revno: 22244
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-03-11 10:24:27 +0700
message:
  minor refactor of stats feedback in dxf2 importer
removed:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/Stats.java
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeErrorReport.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeStats.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReports.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataImportService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/feedback/ImportReport.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.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/feedback/ObjectErrorReports.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReports.java	2016-03-10 13:43:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReports.java	2016-03-11 03:24:27 +0000
@@ -29,6 +29,7 @@
  */
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonValue;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@@ -45,8 +46,6 @@
 @JacksonXmlRootElement( localName = "objectErrorReports", namespace = DxfNamespaces.DXF_2_0 )
 public class ObjectErrorReports
 {
-    private Stats stats = new Stats();
-
     private Map<Integer, ObjectErrorReport> objectErrorReportsMap = new HashMap<>();
 
     public ObjectErrorReports()
@@ -71,13 +70,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public Stats getStats()
-    {
-        return stats;
-    }
-
-    @JsonProperty
+    @JsonValue
     @JacksonXmlElementWrapper( useWrapping = false, localName = "objectErrorReports", namespace = DxfNamespaces.DXF_2_0 )
     @JacksonXmlProperty( localName = "objectErrorReport", namespace = DxfNamespaces.DXF_2_0 )
     public List<ObjectErrorReport> getObjectErrorReports()

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeErrorReport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeErrorReport.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeErrorReport.java	2016-03-11 03:24:27 +0000
@@ -0,0 +1,74 @@
+package org.hisp.dhis.feedback;
+
+/*
+ * Copyright (c) 2004-2016, 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.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "objectTypeErrorReport", namespace = DxfNamespaces.DXF_2_0 )
+public class ObjectTypeErrorReport
+{
+    private final Class<?> klass;
+
+    private final ObjectErrorReports objectErrorReports;
+
+    private final ObjectTypeStats objectTypeStats = new ObjectTypeStats();
+
+    public ObjectTypeErrorReport( Class<?> klass, ObjectErrorReports objectErrorReports )
+    {
+        this.klass = klass;
+        this.objectErrorReports = objectErrorReports;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( isAttribute = true )
+    public Class<?> getKlass()
+    {
+        return klass;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ObjectErrorReports getObjectErrorReports()
+    {
+        return objectErrorReports;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public ObjectTypeStats getObjectTypeStats()
+    {
+        return objectTypeStats;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeStats.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeStats.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectTypeStats.java	2016-03-11 03:24:27 +0000
@@ -0,0 +1,109 @@
+package org.hisp.dhis.feedback;
+
+/*
+ * Copyright (c) 2004-2016, 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.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "stats", namespace = DxfNamespaces.DXF_2_0 )
+public class ObjectTypeStats
+{
+    private int created;
+
+    private int updated;
+
+    private int deleted;
+
+    private int ignored;
+
+    public ObjectTypeStats()
+    {
+    }
+
+    public void merge( ObjectTypeStats stats )
+    {
+        created += stats.getCreated();
+        updated += stats.getUpdated();
+        deleted += stats.getDeleted();
+        ignored += stats.getIgnored();
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public int getCreated()
+    {
+        return created;
+    }
+
+    public void incCreated()
+    {
+        created++;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public int getUpdated()
+    {
+        return updated;
+    }
+
+    public void incUpdated()
+    {
+        updated++;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public int getDeleted()
+    {
+        return deleted;
+    }
+
+    public void incDeleted()
+    {
+        deleted++;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public int getIgnored()
+    {
+        return ignored;
+    }
+
+    public void incIgnored()
+    {
+        ignored++;
+    }
+}

=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/Stats.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/Stats.java	2016-03-10 14:02:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/Stats.java	1970-01-01 00:00:00 +0000
@@ -1,109 +0,0 @@
-package org.hisp.dhis.feedback;
-
-/*
- * Copyright (c) 2004-2016, 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.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "stats", namespace = DxfNamespaces.DXF_2_0 )
-public class Stats
-{
-    private int created;
-
-    private int updated;
-
-    private int deleted;
-
-    private int ignored;
-
-    public Stats()
-    {
-    }
-
-    public void merge( Stats stats )
-    {
-        created += stats.getCreated();
-        updated += stats.getUpdated();
-        deleted += stats.getDeleted();
-        ignored += stats.getIgnored();
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getCreated()
-    {
-        return created;
-    }
-
-    public void incCreated()
-    {
-        created++;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getUpdated()
-    {
-        return updated;
-    }
-
-    public void incUpdated()
-    {
-        updated++;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getDeleted()
-    {
-        return deleted;
-    }
-
-    public void incDeleted()
-    {
-        deleted++;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getIgnored()
-    {
-        return ignored;
-    }
-
-    public void incIgnored()
-    {
-        ignored++;
-    }
-}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataImportService.java	2016-03-10 13:17:12 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataImportService.java	2016-03-11 03:24:27 +0000
@@ -31,6 +31,7 @@
 import com.google.common.base.Enums;
 import org.hisp.dhis.common.MergeMode;
 import org.hisp.dhis.dxf2.metadata2.feedback.ImportReport;
+import org.hisp.dhis.feedback.ObjectTypeErrorReport;
 import org.hisp.dhis.dxf2.metadata2.objectbundle.ObjectBundle;
 import org.hisp.dhis.dxf2.metadata2.objectbundle.ObjectBundleMode;
 import org.hisp.dhis.dxf2.metadata2.objectbundle.ObjectBundleParams;
@@ -74,7 +75,19 @@
         ObjectBundle bundle = objectBundleService.create( bundleParams );
 
         ObjectBundleValidation validation = objectBundleService.validate( bundle );
-        report.setObjectErrorReports( validation.getObjectErrorReports() );
+        validation.getObjectErrorReports().forEach( ( klass, objectErrorReports ) -> {
+            if ( !report.getImportTypeReportMap().containsKey( klass ) )
+            {
+                ObjectTypeErrorReport objectTypeErrorReport = new ObjectTypeErrorReport( klass, objectErrorReports );
+                report.getImportTypeReportMap().put( klass, objectTypeErrorReport );
+            }
+            else
+            {
+                ObjectTypeErrorReport objectTypeErrorReport = report.getImportTypeReportMap().get( klass );
+                objectTypeErrorReport.getObjectErrorReports().addObjectErrorReports( objectErrorReports );
+            }
+
+        } );
 
         if ( !(bundleParams.getImportMode().isAtomic() && !validation.getObjectErrorReports().isEmpty()) )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/feedback/ImportReport.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/feedback/ImportReport.java	2016-03-10 13:43:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/feedback/ImportReport.java	2016-03-11 03:24:27 +0000
@@ -29,13 +29,15 @@
  */
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.feedback.ObjectErrorReports;
-import org.hisp.dhis.feedback.Stats;
+import org.hisp.dhis.feedback.ObjectTypeErrorReport;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -44,30 +46,22 @@
 @JacksonXmlRootElement( localName = "importReport", namespace = DxfNamespaces.DXF_2_0 )
 public class ImportReport
 {
-    private Map<Class<?>, ObjectErrorReports> objectErrorReports = new HashMap<>();
+    private final Map<Class<?>, ObjectTypeErrorReport> importTypeReportMap = new HashMap<>();
 
     public ImportReport()
     {
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public Stats getStats()
-    {
-        Stats stats = new Stats();
-        objectErrorReports.values().forEach( errorReports -> stats.merge( errorReports.getStats() ) );
-        return stats;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public Map<Class<?>, ObjectErrorReports> getObjectErrorReports()
-    {
-        return objectErrorReports;
-    }
-
-    public void setObjectErrorReports( Map<Class<?>, ObjectErrorReports> objectErrorReports )
-    {
-        this.objectErrorReports = objectErrorReports;
+    @JacksonXmlElementWrapper( localName = "importTypeReports", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "importTypeReport", namespace = DxfNamespaces.DXF_2_0 )
+    public List<ObjectTypeErrorReport> getImportTypeReports()
+    {
+        return new ArrayList<>( importTypeReportMap.values() );
+    }
+
+    public Map<Class<?>, ObjectTypeErrorReport> getImportTypeReportMap()
+    {
+        return importTypeReportMap;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java	2016-03-10 14:02:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java	2016-03-11 03:24:27 +0000
@@ -72,7 +72,6 @@
 
         ObjectErrorReports objectErrorReports = objectErrorReportsMap.get( objectClass );
         objectErrorReports.addObjectErrorReport( objectErrorReport );
-        objectErrorReports.getStats().incIgnored();
     }
 
     public List<ObjectErrorReport> getAllObjectErrorReports( Class<?> klass )