dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43845
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22236: adds object error reports wrapper, needed to support xml error responses
------------------------------------------------------------
revno: 22236
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-03-10 20:17:12 +0700
message:
adds object error reports wrapper, needed to support xml error responses
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReports.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReport.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
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceProgramTest.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
=== modified 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 2016-03-10 11:59:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReport.java 2016-03-10 13:17:12 +0000
@@ -29,6 +29,7 @@
*/
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 com.google.common.base.MoreObjects;
@@ -63,14 +64,14 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( isAttribute = true )
public Class<?> getObjectClass()
{
return objectClass;
}
@JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( isAttribute = true )
public Integer getObjectIndex()
{
return objectIndex;
@@ -97,7 +98,8 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlElementWrapper( localName = "errorReports", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "errorReport", namespace = DxfNamespaces.DXF_2_0 )
public List<ErrorReport> getErrorReports()
{
List<ErrorReport> errorReports = new ArrayList<>();
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ObjectErrorReports.java 2016-03-10 13:17:12 +0000
@@ -0,0 +1,83 @@
+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.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "objectErrorReports", namespace = DxfNamespaces.DXF_2_0 )
+public class ObjectErrorReports
+{
+ private Map<Integer, ObjectErrorReport> objectErrorReportsMap = new HashMap<>();
+
+ public ObjectErrorReports()
+ {
+ }
+
+ public void addObjectErrorReports( ObjectErrorReports objectErrorReports )
+ {
+ objectErrorReports.getObjectErrorReports().forEach( this::addObjectErrorReport );
+ }
+
+ public void addObjectErrorReport( ObjectErrorReport objectErrorReport )
+ {
+ if ( !objectErrorReportsMap.containsKey( objectErrorReport.getObjectIndex() ) )
+ {
+ objectErrorReportsMap.put( objectErrorReport.getObjectIndex(), objectErrorReport );
+ }
+ else
+ {
+ objectErrorReportsMap.get( objectErrorReport.getObjectIndex() ).addErrorReports( objectErrorReport.getErrorReports() );
+ }
+ }
+
+ @JsonProperty
+ @JacksonXmlElementWrapper( useWrapping = false, localName = "objectErrorReports", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "objectErrorReport", namespace = DxfNamespaces.DXF_2_0 )
+ public List<ObjectErrorReport> getObjectErrorReports()
+ {
+ return new ArrayList<>( objectErrorReportsMap.values() );
+ }
+
+ public Map<Integer, ObjectErrorReport> getObjectErrorReportsMap()
+ {
+ return objectErrorReportsMap;
+ }
+}
=== 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 11:35:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataImportService.java 2016-03-10 13:17:12 +0000
@@ -74,9 +74,9 @@
ObjectBundle bundle = objectBundleService.create( bundleParams );
ObjectBundleValidation validation = objectBundleService.validate( bundle );
- report.setObjectErrorReports( validation.getObjectErrorReportsMap() );
+ report.setObjectErrorReports( validation.getObjectErrorReports() );
- if ( !(bundleParams.getImportMode().isAtomic() && !validation.getObjectErrorReportsMap().isEmpty()) )
+ if ( !(bundleParams.getImportMode().isAtomic() && !validation.getObjectErrorReports().isEmpty()) )
{
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-08 04:49:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/feedback/ImportReport.java 2016-03-10 13:17:12 +0000
@@ -32,7 +32,7 @@
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.ObjectErrorReport;
+import org.hisp.dhis.feedback.ObjectErrorReports;
import java.util.HashMap;
import java.util.Map;
@@ -45,7 +45,7 @@
{
private ImportStats stats = new ImportStats();
- private Map<Class<?>, Map<Integer, ObjectErrorReport>> objectErrorReports = new HashMap<>();
+ private Map<Class<?>, ObjectErrorReports> objectErrorReports = new HashMap<>();
public ImportReport()
{
@@ -60,12 +60,12 @@
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public Map<Class<?>, Map<Integer, ObjectErrorReport>> getObjectErrorReports()
+ public Map<Class<?>, ObjectErrorReports> getObjectErrorReports()
{
return objectErrorReports;
}
- public void setObjectErrorReports( Map<Class<?>, Map<Integer, ObjectErrorReport>> objectErrorReports )
+ public void setObjectErrorReports( Map<Class<?>, ObjectErrorReports> objectErrorReports )
{
this.objectErrorReports = objectErrorReports;
}
=== 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-08 05:54:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java 2016-03-10 13:17:12 +0000
@@ -32,6 +32,7 @@
import org.hisp.dhis.feedback.ErrorCode;
import org.hisp.dhis.feedback.ErrorReport;
import org.hisp.dhis.feedback.ObjectErrorReport;
+import org.hisp.dhis.feedback.ObjectErrorReports;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,7 +45,7 @@
*/
public class ObjectBundleValidation
{
- private Map<Class<?>, Map<Integer, ObjectErrorReport>> objectErrorReportsMap = new HashMap<>();
+ private Map<Class<?>, ObjectErrorReports> objectErrorReportsMap = new HashMap<>();
public ObjectBundleValidation()
{
@@ -66,31 +67,23 @@
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() );
- }
+ objectErrorReportsMap.put( objectClass, new ObjectErrorReports() );
+ }
+
+ ObjectErrorReports objectErrorReports = objectErrorReportsMap.get( objectClass );
+ objectErrorReports.addObjectErrorReport( objectErrorReport );
}
public List<ObjectErrorReport> getAllObjectErrorReports( Class<?> klass )
{
List<ObjectErrorReport> objectErrorReports = new ArrayList<>();
- Map<Integer, ObjectErrorReport> errorReportMap = objectErrorReportsMap.get( klass );
- errorReportMap.values().forEach( objectErrorReports::add );
+ ObjectErrorReports errorReports = objectErrorReportsMap.get( klass );
+ errorReports.getObjectErrorReports().forEach( objectErrorReports::add );
return objectErrorReports;
}
- public Map<Integer, ObjectErrorReport> getObjectErrorReports( Class<?> klass )
+ public ObjectErrorReports getObjectErrorReports( Class<?> klass )
{
return objectErrorReportsMap.get( klass );
}
@@ -104,7 +97,7 @@
return errorReports;
}
- Collection<ObjectErrorReport> objectErrorReports = objectErrorReportsMap.get( klass ).values();
+ Collection<ObjectErrorReport> objectErrorReports = objectErrorReportsMap.get( klass ).getObjectErrorReports();
for ( ObjectErrorReport objectErrorReport : objectErrorReports )
{
@@ -119,7 +112,7 @@
return errorReports;
}
- public Map<Class<?>, Map<Integer, ObjectErrorReport>> getObjectErrorReportsMap()
+ public Map<Class<?>, ObjectErrorReports> getObjectErrorReports()
{
return objectErrorReportsMap;
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceProgramTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceProgramTest.java 2016-03-10 10:48:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceProgramTest.java 2016-03-10 13:17:12 +0000
@@ -89,7 +89,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -130,7 +130,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -175,8 +175,8 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- System.err.println( validate.getObjectErrorReportsMap() );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ System.err.println( validate.getObjectErrorReports() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
=== 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-10 06:38:17 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-03-10 13:17:12 +0000
@@ -152,7 +152,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
+ assertFalse( validate.getObjectErrorReports().isEmpty() );
List<ObjectErrorReport> objectErrorReports = validate.getAllObjectErrorReports( DataElement.class );
assertFalse( objectErrorReports.isEmpty() );
@@ -209,7 +209,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
+ assertFalse( validate.getObjectErrorReports().isEmpty() );
List<ObjectErrorReport> objectErrorReports = validate.getAllObjectErrorReports( DataElement.class );
assertFalse( objectErrorReports.isEmpty() );
@@ -258,7 +258,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
+ assertFalse( validate.getObjectErrorReports().isEmpty() );
assertEquals( 5, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5002 ).size() );
assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E4000 ).size() );
}
@@ -278,7 +278,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertEquals( 3, validate.getObjectErrorReports( DataElement.class ).size() );
+ assertEquals( 3, validate.getObjectErrorReports( DataElement.class ).getObjectErrorReports().size() );
}
@Test
@@ -317,7 +317,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+ assertFalse( validate.getObjectErrorReports( DataElement.class ).getObjectErrorReports().isEmpty() );
assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
}
@@ -336,7 +336,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+ assertFalse( validate.getObjectErrorReports( DataElement.class ).getObjectErrorReports().isEmpty() );
assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
}
@@ -355,7 +355,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+ assertFalse( validate.getObjectErrorReports( DataElement.class ).getObjectErrorReports().isEmpty() );
assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
}
@@ -374,7 +374,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+ assertFalse( validate.getObjectErrorReports( DataElement.class ).getObjectErrorReports().isEmpty() );
assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
}
@@ -393,7 +393,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertFalse( validate.getObjectErrorReports( DataElement.class ).isEmpty() );
+ assertFalse( validate.getObjectErrorReports( DataElement.class ).getObjectErrorReports().isEmpty() );
assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5001 ).size() );
}
@@ -761,7 +761,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -807,7 +807,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -875,7 +875,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -888,7 +888,7 @@
bundle = objectBundleService.create( params );
validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -942,7 +942,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -981,7 +981,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -1007,7 +1007,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -1055,7 +1055,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );
@@ -1068,7 +1068,7 @@
bundle = objectBundleService.create( params );
validate = objectBundleService.validate( bundle );
- assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+ assertTrue( validate.getObjectErrorReports().isEmpty() );
objectBundleService.commit( bundle );