← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22170: Added ObjectErrorReport, bundles together all error reports for an object (also includes type and...

 

------------------------------------------------------------
revno: 22170
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-03-08 11:49:20 +0700
message:
  Added ObjectErrorReport, bundles together all error reports for an object (also includes type and index in payload array)
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReport.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.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/DefaultObjectBundleService.java
  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/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReport.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReport.java	2016-03-08 04:49:20 +0000
@@ -0,0 +1,113 @@
+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.google.common.base.MoreObjects;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ObjectErrorReport
+{
+    private final Class<?> objectClass;
+
+    private Integer objectIndex;
+
+    private Map<ErrorCode, List<ErrorReport>> errorReportsByCode = new HashMap<>();
+
+    public ObjectErrorReport( Class<?> objectClass )
+    {
+        this.objectClass = objectClass;
+    }
+
+    public ObjectErrorReport( Class<?> objectClass, Integer objectIndex )
+    {
+        this.objectClass = objectClass;
+        this.objectIndex = objectIndex;
+    }
+
+    public Class<?> getObjectClass()
+    {
+        return objectClass;
+    }
+
+    public Integer getObjectIndex()
+    {
+        return objectIndex;
+    }
+
+    public void addErrorReports( List<? extends ErrorReport> errorReports )
+    {
+        errorReports.forEach( this::addErrorReport );
+    }
+
+    public void addErrorReport( ErrorReport errorReport )
+    {
+        if ( !errorReportsByCode.containsKey( errorReport.getErrorCode() ) )
+        {
+            errorReportsByCode.put( errorReport.getErrorCode(), new ArrayList<>() );
+        }
+
+        errorReportsByCode.get( errorReport.getErrorCode() ).add( errorReport );
+    }
+
+    public List<ErrorCode> getErrorCodes()
+    {
+        return new ArrayList<>( errorReportsByCode.keySet() );
+    }
+
+    public List<ErrorReport> getErrorReports()
+    {
+        List<ErrorReport> errorReports = new ArrayList<>();
+        errorReportsByCode.values().forEach( errorReports::addAll );
+
+        return errorReports;
+    }
+
+    public Map<ErrorCode, List<ErrorReport>> getErrorReportsByCode()
+    {
+        return errorReportsByCode;
+    }
+
+
+    @Override
+    public String toString()
+    {
+        return MoreObjects.toStringHelper( this )
+            .add( "objectClass", objectClass )
+            .add( "objectIndex", objectIndex )
+            .add( "errorReportsByCode", errorReportsByCode )
+            .toString();
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java	2016-03-01 09:29:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java	2016-03-08 04:49:20 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.feedback.ObjectErrorReport;
 
 import java.util.Collection;
 import java.util.List;
@@ -86,7 +87,7 @@
      * @param preheat    Preheat Cache to use
      * @param identifier Use this identifier type to check references
      */
-    List<List<PreheatErrorReport>> checkReferences( List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier );
+    List<ObjectErrorReport> checkReferences( List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier );
 
     /**
      * Checks but does not connect any references, returns check report

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java	2016-03-03 05:13:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java	2016-03-08 04:49:20 +0000
@@ -35,6 +35,7 @@
 import org.hisp.dhis.common.MergeMode;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.feedback.ErrorCode;
+import org.hisp.dhis.feedback.ObjectErrorReport;
 import org.hisp.dhis.query.Query;
 import org.hisp.dhis.query.QueryService;
 import org.hisp.dhis.query.Restrictions;
@@ -437,12 +438,29 @@
     }
 
     @Override
-    public List<List<PreheatErrorReport>> checkReferences( List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier )
+    public List<ObjectErrorReport> checkReferences( List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier )
     {
-        List<List<PreheatErrorReport>> preheatErrorReports = new ArrayList<>();
-        objects.forEach( object -> preheatErrorReports.add( checkReferences( object, preheat, identifier ) ) );
-
-        return preheatErrorReports;
+        List<ObjectErrorReport> objectErrorReports = new ArrayList<>();
+
+        if ( objects.isEmpty() )
+        {
+            return objectErrorReports;
+        }
+
+        for ( int i = 0; i < objects.size(); i++ )
+        {
+            IdentifiableObject object = objects.get( i );
+            List<PreheatErrorReport> errorReports = checkReferences( object, preheat, identifier );
+
+            if ( errorReports.isEmpty() ) continue;
+
+            ObjectErrorReport objectErrorReport = new ObjectErrorReport( object.getClass(), i );
+            objectErrorReport.addErrorReports( errorReports );
+            objectErrorReports.add( objectErrorReport );
+
+        }
+
+        return objectErrorReports;
     }
 
     @Override

=== 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-04 08:58:53 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataImportService.java	2016-03-08 04:49:20 +0000
@@ -72,7 +72,7 @@
         ObjectBundle bundle = objectBundleService.create( bundleParams );
 
         ObjectBundleValidation validation = objectBundleService.validate( bundle );
-        report.setErrorReports( validation.getErrorReports() );
+        report.setObjectErrorReports( validation.getObjectErrorReportsMap() );
 
         objectBundleService.commit( bundle );
 

=== 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-02 07:56:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/feedback/ImportReport.java	2016-03-08 04:49:20 +0000
@@ -32,12 +32,9 @@
 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.ErrorCode;
-import org.hisp.dhis.feedback.ErrorReport;
+import org.hisp.dhis.feedback.ObjectErrorReport;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -48,7 +45,7 @@
 {
     private ImportStats stats = new ImportStats();
 
-    private Map<Class<?>, Map<ErrorCode, List<ErrorReport>>> errorReports = new HashMap<>();
+    private Map<Class<?>, Map<Integer, ObjectErrorReport>> objectErrorReports = new HashMap<>();
 
     public ImportReport()
     {
@@ -61,65 +58,15 @@
         return stats;
     }
 
-    public void addErrorReports( List<ErrorReport> errorReports )
-    {
-        errorReports.forEach( this::addErrorReport );
-    }
-
-    public <T extends ErrorReport> void addErrorReport( T errorReport )
-    {
-        if ( !errorReports.containsKey( errorReport.getMainKlass() ) )
-        {
-            errorReports.put( errorReport.getMainKlass(), new HashMap<>() );
-        }
-
-        if ( !errorReports.get( errorReport.getMainKlass() ).containsKey( errorReport.getErrorCode() ) )
-        {
-            errorReports.get( errorReport.getMainKlass() ).put( errorReport.getErrorCode(), new ArrayList<>() );
-        }
-
-        errorReports.get( errorReport.getMainKlass() ).get( errorReport.getErrorCode() ).add( errorReport );
-    }
-
-    public void addErrorReport( Class<?> mainKlass, ErrorCode errorCode, Object... args )
-    {
-        ErrorReport errorReport = new ErrorReport( mainKlass, errorCode, args );
-        addErrorReport( errorReport );
-    }
-
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public Map<Class<?>, Map<ErrorCode, List<ErrorReport>>> getErrorReports()
-    {
-        return errorReports;
-    }
-
-    public Map<ErrorCode, List<ErrorReport>> getErrorReports( Class<?> klass )
-    {
-        Map<ErrorCode, List<ErrorReport>> map = errorReports.get( klass );
-
-        if ( map == null )
-        {
-            return new HashMap<>();
-        }
-
-        return map;
-    }
-
-    public List<ErrorReport> getErrorReports( Class<?> klass, ErrorCode errorCode )
-    {
-        Map<ErrorCode, List<ErrorReport>> map = errorReports.get( klass );
-
-        if ( !map.containsKey( errorCode ) )
-        {
-            return new ArrayList<>();
-        }
-
-        return map.get( errorCode );
-    }
-
-    public void setErrorReports( Map<Class<?>, Map<ErrorCode, List<ErrorReport>>> errorReports )
-    {
-        this.errorReports = errorReports;
+    public Map<Class<?>, Map<Integer, ObjectErrorReport>> getObjectErrorReports()
+    {
+        return objectErrorReports;
+    }
+
+    public void setObjectErrorReports( Map<Class<?>, Map<Integer, ObjectErrorReport>> objectErrorReports )
+    {
+        this.objectErrorReports = objectErrorReports;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-03-04 08:58:53 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-03-08 04:49:20 +0000
@@ -38,8 +38,8 @@
 import org.hisp.dhis.dxf2.metadata2.objectbundle.hooks.ObjectBundleHook;
 import org.hisp.dhis.feedback.ErrorCode;
 import org.hisp.dhis.feedback.ErrorReport;
+import org.hisp.dhis.feedback.ObjectErrorReport;
 import org.hisp.dhis.preheat.Preheat;
-import org.hisp.dhis.preheat.PreheatErrorReport;
 import org.hisp.dhis.preheat.PreheatIdentifier;
 import org.hisp.dhis.preheat.PreheatMode;
 import org.hisp.dhis.preheat.PreheatParams;
@@ -175,55 +175,70 @@
             if ( bundle.getImportMode().isCreate() )
             {
                 Iterator<IdentifiableObject> iterator = bundle.getObjects().get( klass ).iterator();
+                int idx = 0;
 
                 while ( iterator.hasNext() )
                 {
                     IdentifiableObject identifiableObject = iterator.next();
                     IdentifiableObject object = bundle.getPreheat().get( bundle.getPreheatIdentifier(), identifiableObject );
+                    ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
 
                     if ( object != null && object.getId() > 0 )
                     {
-                        objectBundleValidation.addErrorReport( klass, ErrorCode.E5000, bundle.getPreheatIdentifier(),
-                            bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) );
+                        objectErrorReport.addErrorReport( new ErrorReport( klass, ErrorCode.E5000, bundle.getPreheatIdentifier(),
+                            bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) ) );
                         iterator.remove();
                     }
+
+                    objectBundleValidation.addObjectErrorReport( objectErrorReport );
+                    idx++;
                 }
             }
             else if ( bundle.getImportMode().isUpdate() || bundle.getImportMode().isDelete() )
             {
                 Iterator<IdentifiableObject> iterator = bundle.getObjects().get( klass ).iterator();
+                int idx = 0;
 
                 while ( iterator.hasNext() )
                 {
                     IdentifiableObject identifiableObject = iterator.next();
                     IdentifiableObject object = bundle.getPreheat().get( bundle.getPreheatIdentifier(), identifiableObject );
+                    ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
 
                     if ( object == null )
                     {
-                        objectBundleValidation.addErrorReport( klass, ErrorCode.E5001, bundle.getPreheatIdentifier(),
-                            bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) );
+                        objectErrorReport.addErrorReport( new ErrorReport( klass, ErrorCode.E5001, bundle.getPreheatIdentifier(),
+                            bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) ) );
                         iterator.remove();
                     }
+
+                    objectBundleValidation.addObjectErrorReport( objectErrorReport );
+                    idx++;
                 }
             }
 
-            List<List<PreheatErrorReport>> referencesErrorReports = preheatService.checkReferences( bundle.getObjects().get( klass ), bundle.getPreheat(), bundle.getPreheatIdentifier() );
-            referencesErrorReports.forEach( objectBundleValidation::addErrorReports ); // collapsing for now, we might want to give pr object ref list
+            List<ObjectErrorReport> objectErrorReports = preheatService.checkReferences( bundle.getObjects().get( klass ), bundle.getPreheat(), bundle.getPreheatIdentifier() );
+            objectBundleValidation.addObjectErrorReports( objectErrorReports );
 
             if ( !bundle.getImportMode().isDelete() )
             {
                 Iterator<IdentifiableObject> iterator = bundle.getObjects().get( klass ).iterator();
+                int idx = 0;
 
                 while ( iterator.hasNext() )
                 {
                     IdentifiableObject object = iterator.next();
                     List<ErrorReport> validationErrorReports = schemaValidator.validate( object );
+                    ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
 
                     if ( !validationErrorReports.isEmpty() )
                     {
-                        objectBundleValidation.addErrorReports( validationErrorReports );
+                        objectErrorReport.addErrorReports( validationErrorReports );
                         iterator.remove();
                     }
+
+                    objectBundleValidation.addObjectErrorReport( objectErrorReport );
+                    idx++;
                 }
             }
         }

=== 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-03 01:20:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java	2016-03-08 04:49:20 +0000
@@ -30,8 +30,10 @@
 
 import org.hisp.dhis.feedback.ErrorCode;
 import org.hisp.dhis.feedback.ErrorReport;
+import org.hisp.dhis.feedback.ObjectErrorReport;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -41,64 +43,83 @@
  */
 public class ObjectBundleValidation
 {
-    private Map<Class<?>, Map<ErrorCode, List<ErrorReport>>> errorReports = new HashMap<>();
+    private Map<Class<?>, Map<Integer, ObjectErrorReport>> objectErrorReportsMap = new HashMap<>();
 
     public ObjectBundleValidation()
     {
     }
 
-    public void addErrorReports( List<? extends ErrorReport> errorReports )
-    {
-        errorReports.forEach( this::addErrorReport );
-    }
-
-    public <T extends ErrorReport> void addErrorReport( T errorReport )
-    {
-        if ( !errorReports.containsKey( errorReport.getMainKlass() ) )
-        {
-            errorReports.put( errorReport.getMainKlass(), new HashMap<>() );
-        }
-
-        if ( !errorReports.get( errorReport.getMainKlass() ).containsKey( errorReport.getErrorCode() ) )
-        {
-            errorReports.get( errorReport.getMainKlass() ).put( errorReport.getErrorCode(), new ArrayList<>() );
-        }
-
-        errorReports.get( errorReport.getMainKlass() ).get( errorReport.getErrorCode() ).add( errorReport );
-    }
-
-    public void addErrorReport( Class<?> mainKlass, ErrorCode errorCode, Object... args )
-    {
-        ErrorReport errorReport = new ErrorReport( mainKlass, errorCode, args );
-        addErrorReport( errorReport );
-    }
-
-    public Map<Class<?>, Map<ErrorCode, List<ErrorReport>>> getErrorReports()
-    {
+    public void addObjectErrorReports( List<ObjectErrorReport> objectErrorReports )
+    {
+        objectErrorReports.forEach( this::addObjectErrorReport );
+    }
+
+    public void addObjectErrorReport( ObjectErrorReport objectErrorReport )
+    {
+        if ( objectErrorReport == null || objectErrorReport.getErrorCodes().isEmpty() )
+        {
+            return;
+        }
+
+        Class<?> objectClass = objectErrorReport.getObjectClass();
+
+        if ( !objectErrorReportsMap.containsKey( objectClass ) )
+        {
+            objectErrorReportsMap.put( objectClass, new HashMap<>() );
+        }
+
+        Map<Integer, ObjectErrorReport> indexMap = objectErrorReportsMap.get( objectClass );
+
+        if ( !indexMap.containsKey( objectErrorReport.getObjectIndex() ) )
+        {
+            indexMap.put( objectErrorReport.getObjectIndex(), objectErrorReport );
+        }
+        else
+        {
+            indexMap.get( objectErrorReport.getObjectIndex() ).addErrorReports( objectErrorReport.getErrorReports() );
+        }
+    }
+
+    public List<ObjectErrorReport> getAllObjectErrorReports( Class<?> klass )
+    {
+        List<ObjectErrorReport> objectErrorReports = new ArrayList<>();
+        Map<Integer, ObjectErrorReport> errorReportMap = objectErrorReportsMap.get( klass );
+        errorReportMap.values().forEach( objectErrorReports::add );
+
+        return objectErrorReports;
+    }
+
+    public Map<Integer, ObjectErrorReport> getObjectErrorReports( Class<?> klass )
+    {
+        return objectErrorReportsMap.get( klass );
+    }
+
+    public List<ErrorReport> getErrorReportsByCode( Class<?> klass, ErrorCode errorCode )
+    {
+        List<ErrorReport> errorReports = new ArrayList<>();
+
+        if ( !objectErrorReportsMap.containsKey( klass ) )
+        {
+            return errorReports;
+        }
+
+        Collection<ObjectErrorReport> objectErrorReports = objectErrorReportsMap.get( klass ).values();
+
+        for ( ObjectErrorReport objectErrorReport : objectErrorReports )
+        {
+            List<ErrorReport> byCode = objectErrorReport.getErrorReportsByCode().get( errorCode );
+
+            if ( byCode != null )
+            {
+                errorReports.addAll( byCode );
+            }
+        }
+
         return errorReports;
     }
 
-    public Map<ErrorCode, List<ErrorReport>> getErrorReports( Class<?> klass )
-    {
-        Map<ErrorCode, List<ErrorReport>> map = errorReports.get( klass );
-
-        if ( map == null )
-        {
-            return new HashMap<>();
-        }
-
-        return map;
-    }
-
-    public List<ErrorReport> getErrorReports( Class<?> klass, ErrorCode errorCode )
-    {
-        Map<ErrorCode, List<ErrorReport>> map = errorReports.get( klass );
-
-        if ( !map.containsKey( errorCode ) )
-        {
-            return new ArrayList<>();
-        }
-
-        return map.get( errorCode );
+    public Map<Class<?>, Map<Integer, ObjectErrorReport>> getObjectErrorReportsMap()
+    {
+        return objectErrorReportsMap;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-04 06:13:25 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-08 04:49:20 +0000
@@ -42,6 +42,7 @@
 import org.hisp.dhis.dxf2.metadata2.MetadataExportService;
 import org.hisp.dhis.feedback.ErrorCode;
 import org.hisp.dhis.feedback.ErrorReport;
+import org.hisp.dhis.feedback.ObjectErrorReport;
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.node.NodeService;
 import org.hisp.dhis.option.Option;
@@ -151,33 +152,37 @@
 
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
-        assertFalse( validate.getErrorReports().isEmpty() );
-
-        Map<ErrorCode, List<ErrorReport>> dataElementErrorReport = validate.getErrorReports().get( DataElement.class );
-        assertFalse( dataElementErrorReport.isEmpty() );
-
-        for ( ErrorCode errorCode : dataElementErrorReport.keySet() )
+        assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
+
+        List<ObjectErrorReport> objectErrorReports = validate.getAllObjectErrorReports( DataElement.class );
+        assertFalse( objectErrorReports.isEmpty() );
+
+        for ( ObjectErrorReport objectErrorReport : objectErrorReports )
         {
-            List<ErrorReport> errorReports = dataElementErrorReport.get( errorCode );
-            assertFalse( errorReports.isEmpty() );
-
-            for ( ErrorReport errorReport : errorReports )
+            for ( ErrorCode errorCode : objectErrorReport.getErrorCodes() )
             {
-                assertTrue( PreheatErrorReport.class.isInstance( errorReport ) );
-                PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
-                assertEquals( PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier() );
-
-                if ( DataElementCategoryCombo.class.isInstance( preheatErrorReport.getValue() ) )
-                {
-                    assertEquals( "p0KPaWEg3cf", preheatErrorReport.getObjectReference().getUid() );
-                }
-                else if ( User.class.isInstance( preheatErrorReport.getValue() ) )
-                {
-                    assertEquals( "GOLswS44mh8", preheatErrorReport.getObjectReference().getUid() );
-                }
-                else if ( OptionSet.class.isInstance( preheatErrorReport.getValue() ) )
-                {
-                    assertEquals( "pQYCiuosBnZ", preheatErrorReport.getObjectReference().getUid() );
+                List<ErrorReport> errorReports = objectErrorReport.getErrorReportsByCode().get( errorCode );
+
+                assertFalse( errorReports.isEmpty() );
+
+                for ( ErrorReport errorReport : errorReports )
+                {
+                    assertTrue( PreheatErrorReport.class.isInstance( errorReport ) );
+                    PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
+                    assertEquals( PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier() );
+
+                    if ( DataElementCategoryCombo.class.isInstance( preheatErrorReport.getValue() ) )
+                    {
+                        assertEquals( "p0KPaWEg3cf", preheatErrorReport.getObjectReference().getUid() );
+                    }
+                    else if ( User.class.isInstance( preheatErrorReport.getValue() ) )
+                    {
+                        assertEquals( "GOLswS44mh8", preheatErrorReport.getObjectReference().getUid() );
+                    }
+                    else if ( OptionSet.class.isInstance( preheatErrorReport.getValue() ) )
+                    {
+                        assertEquals( "pQYCiuosBnZ", preheatErrorReport.getObjectReference().getUid() );
+                    }
                 }
             }
         }
@@ -204,33 +209,37 @@
 
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
-        assertFalse( validate.getErrorReports().isEmpty() );
-
-        Map<ErrorCode, List<ErrorReport>> dataElementErrorReport = validate.getErrorReports().get( DataElement.class );
-        assertFalse( dataElementErrorReport.isEmpty() );
-
-        for ( ErrorCode errorCode : dataElementErrorReport.keySet() )
+        assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
+
+        List<ObjectErrorReport> objectErrorReports = validate.getAllObjectErrorReports( DataElement.class );
+        assertFalse( objectErrorReports.isEmpty() );
+
+        for ( ObjectErrorReport objectErrorReport : objectErrorReports )
         {
-            List<ErrorReport> errorReports = dataElementErrorReport.get( errorCode );
-            assertFalse( errorReports.isEmpty() );
-
-            for ( ErrorReport errorReport : errorReports )
+            for ( ErrorCode errorCode : objectErrorReport.getErrorCodes() )
             {
-                assertTrue( PreheatErrorReport.class.isInstance( errorReport ) );
-                PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
-                assertEquals( PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier() );
-
-                if ( DataElementCategoryCombo.class.isInstance( preheatErrorReport.getValue() ) )
-                {
-                    assertFalse( true );
-                }
-                else if ( User.class.isInstance( preheatErrorReport.getValue() ) )
-                {
-                    assertEquals( "GOLswS44mh8", preheatErrorReport.getObjectReference().getUid() );
-                }
-                else if ( OptionSet.class.isInstance( preheatErrorReport.getValue() ) )
-                {
-                    assertFalse( true );
+                List<ErrorReport> errorReports = objectErrorReport.getErrorReportsByCode().get( errorCode );
+
+                assertFalse( errorReports.isEmpty() );
+
+                for ( ErrorReport errorReport : errorReports )
+                {
+                    assertTrue( PreheatErrorReport.class.isInstance( errorReport ) );
+                    PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
+                    assertEquals( PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier() );
+
+                    if ( DataElementCategoryCombo.class.isInstance( preheatErrorReport.getValue() ) )
+                    {
+                        assertFalse( true );
+                    }
+                    else if ( User.class.isInstance( preheatErrorReport.getValue() ) )
+                    {
+                        assertEquals( "GOLswS44mh8", preheatErrorReport.getObjectReference().getUid() );
+                    }
+                    else if ( OptionSet.class.isInstance( preheatErrorReport.getValue() ) )
+                    {
+                        assertFalse( true );
+                    }
                 }
             }
         }
@@ -249,8 +258,9 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertFalse( validate.getErrorReports().isEmpty() );
-        assertEquals( 2, validate.getErrorReports().get( DataElement.class ).size() );
+        assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
+        assertEquals( 7, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5002 ).size() );
+        assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E4000 ).size() );
     }
 
     @Test
@@ -268,7 +278,7 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
+        assertEquals( 3, validate.getObjectErrorReports( DataElement.class ).size() );
     }
 
     @Test
@@ -287,8 +297,8 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertEquals( 1, validate.getErrorReports( DataElement.class ).get( ErrorCode.E5001 ).size() );
-        assertFalse( validate.getErrorReports( DataElement.class ).get( ErrorCode.E4000 ).isEmpty() );
+        assertEquals( 1, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
+        assertFalse( validate.getErrorReportsByCode( DataElement.class, ErrorCode.E4000 ).isEmpty() );
         assertEquals( 0, bundle.getObjects().get( DataElement.class ).size() );
     }
 
@@ -307,8 +317,8 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
-        assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
+        assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+        assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
     }
 
     @Test
@@ -326,8 +336,8 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
-        assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
+        assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+        assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
     }
 
     @Test
@@ -345,8 +355,8 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
-        assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
+        assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+        assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
     }
 
     @Test
@@ -364,8 +374,8 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
-        assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
+        assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+        assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
     }
 
     @Test
@@ -383,8 +393,8 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
-        assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
-        assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
+        assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+        assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
     }
 
     @Test