← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21920: minor validation changes, adds PreheatValidation/ObjectBundleValidation classes to handle preheat...

 

------------------------------------------------------------
revno: 21920
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-10 10:08:09 +0700
message:
  minor validation changes, adds PreheatValidation/ObjectBundleValidation classes to handle preheat/object-bundle validations
removed:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/MissingReference.java
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.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-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.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/ObjectBundleService.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/preheat/InvalidReference.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java	2016-02-10 03:08:09 +0000
@@ -0,0 +1,94 @@
+package org.hisp.dhis.preheat;
+
+/*
+ * 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.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.base.MoreObjects;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.schema.Property;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "invalidReference", namespace = DxfNamespaces.DXF_2_0 )
+public class InvalidReference
+{
+    private PreheatIdentifier identifier;
+
+    private IdentifiableObject refObject;
+
+    private Property property;
+
+    public InvalidReference( PreheatIdentifier identifier, IdentifiableObject refObject, Property property )
+    {
+        this.identifier = identifier;
+        this.refObject = refObject;
+        this.property = property;
+    }
+
+    public PreheatIdentifier getIdentifier()
+    {
+        return identifier;
+    }
+
+    public void setIdentifier( PreheatIdentifier identifier )
+    {
+        this.identifier = identifier;
+    }
+
+    public IdentifiableObject getRefObject()
+    {
+        return refObject;
+    }
+
+    public void setRefObject( IdentifiableObject refObject )
+    {
+        this.refObject = refObject;
+    }
+
+    public Property getProperty()
+    {
+        return property;
+    }
+
+    public void setProperty( Property property )
+    {
+        this.property = property;
+    }
+
+    @Override
+    public String toString()
+    {
+        return MoreObjects.toStringHelper( this )
+            .add( "identifier", identifier )
+            .add( "refObject", refObject )
+            .toString();
+    }
+}

=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/MissingReference.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/MissingReference.java	2016-02-09 05:50:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/MissingReference.java	1970-01-01 00:00:00 +0000
@@ -1,107 +0,0 @@
-package org.hisp.dhis.preheat;
-
-/*
- * 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 com.google.common.base.Objects;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.schema.Property;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "missingReference", namespace = DxfNamespaces.DXF_2_0 )
-public class MissingReference
-{
-    private PreheatIdentifier identifier;
-
-    private String value;
-
-    private Property property;
-
-    public MissingReference( PreheatIdentifier identifier, String value, Property property )
-    {
-        this.identifier = identifier;
-        this.value = value;
-        this.property = property;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public PreheatIdentifier getIdentifier()
-    {
-        return identifier;
-    }
-
-    public void setIdentifier( PreheatIdentifier identifier )
-    {
-        this.identifier = identifier;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public String getValue()
-    {
-        return value;
-    }
-
-    public void setValue( String value )
-    {
-        this.value = value;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public String getPropertyName()
-    {
-        return property.getName() + " (collection: " + property.isCollection() + ")";
-    }
-
-    public Property getProperty()
-    {
-        return property;
-    }
-
-    public void setProperty( Property property )
-    {
-        this.property = property;
-    }
-
-    @Override
-    public String toString()
-    {
-        return Objects.toStringHelper( this )
-            .add( "identifier", identifier )
-            .add( "value", value )
-            .add( "propertyName", getPropertyName() )
-            .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-02-09 05:50:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java	2016-02-10 03:08:09 +0000
@@ -77,7 +77,7 @@
      * @param preheat    Preheat Cache to use
      * @param identifier Use this identifier type to check references
      */
-    <T extends IdentifiableObject> List<MissingReference> checkReferences( T object, Preheat preheat, PreheatIdentifier identifier );
+    <T extends IdentifiableObject> PreheatValidation checkReferences( T object, Preheat preheat, PreheatIdentifier identifier );
 
     /**
      * Connects id object references on a given object using a given identifier + a preheated Preheat cache.

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java	2016-02-10 03:08:09 +0000
@@ -0,0 +1,57 @@
+package org.hisp.dhis.preheat;
+
+/*
+ * 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 org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.schema.Property;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class PreheatValidation
+{
+    private List<InvalidReference> invalidReferences = new ArrayList<>();
+
+    public PreheatValidation()
+    {
+    }
+
+    public void addInvalidReference( PreheatIdentifier identifier, IdentifiableObject refObject, Property property )
+    {
+        invalidReferences.add( new InvalidReference( identifier, refObject, property ) );
+    }
+
+    public List<InvalidReference> getInvalidReferences()
+    {
+        return invalidReferences;
+    }
+}

=== 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-02-09 05:50:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java	2016-02-10 03:08:09 +0000
@@ -41,7 +41,6 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -222,13 +221,13 @@
 
     @Override
     @SuppressWarnings( "unchecked" )
-    public <T extends IdentifiableObject> List<MissingReference> checkReferences( T object, Preheat preheat, PreheatIdentifier identifier )
+    public <T extends IdentifiableObject> PreheatValidation checkReferences( T object, Preheat preheat, PreheatIdentifier identifier )
     {
-        List<MissingReference> missingReferences = new ArrayList<>();
+        PreheatValidation preheatValidation = new PreheatValidation();
 
         if ( object == null )
         {
-            return missingReferences;
+            return preheatValidation;
         }
 
         Schema schema = schemaService.getDynamicSchema( object.getClass() );
@@ -242,7 +241,7 @@
 
                     if ( ref == null && refObject != null )
                     {
-                        missingReferences.add( new MissingReference( identifier, identifier.getIdentifier( refObject ), p ) );
+                        preheatValidation.addInvalidReference( identifier, refObject, p );
                     }
                 }
                 else
@@ -256,7 +255,7 @@
 
                         if ( ref == null && refObject != null )
                         {
-                            missingReferences.add( new MissingReference( identifier, identifier.getIdentifier( refObject ), p ) );
+                            preheatValidation.addInvalidReference( identifier, refObject, p );
                         }
                     }
 
@@ -264,7 +263,7 @@
                 }
             } );
 
-        return missingReferences;
+        return preheatValidation;
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java	2016-02-09 05:50:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java	2016-02-10 03:08:09 +0000
@@ -500,11 +500,11 @@
 
         preheatService.validate( params );
         Preheat preheat = preheatService.preheat( params );
-        List<MissingReference> missingReferences = preheatService.checkReferences( dataElementGroup, preheat, PreheatIdentifier.UID );
-        assertEquals( 3, missingReferences.size() );
-        assertEquals( PreheatIdentifier.UID, missingReferences.get( 0 ).getIdentifier() );
-        assertEquals( PreheatIdentifier.UID, missingReferences.get( 1 ).getIdentifier() );
-        assertEquals( PreheatIdentifier.UID, missingReferences.get( 2 ).getIdentifier() );
+        List<InvalidReference> invalidReferences = preheatService.checkReferences( dataElementGroup, preheat, PreheatIdentifier.UID ).getInvalidReferences();
+        assertEquals( 3, invalidReferences.size() );
+        assertEquals( PreheatIdentifier.UID, invalidReferences.get( 0 ).getIdentifier() );
+        assertEquals( PreheatIdentifier.UID, invalidReferences.get( 1 ).getIdentifier() );
+        assertEquals( PreheatIdentifier.UID, invalidReferences.get( 2 ).getIdentifier() );
     }
 
     @Test

=== 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-02-08 08:44:43 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-02-10 03:08:09 +0000
@@ -66,9 +66,10 @@
     }
 
     @Override
-    public void validate( ObjectBundle bundle )
+    public ObjectBundleValidation validate( ObjectBundle bundle )
     {
-
+        ObjectBundleValidation objectBundleValidation = new ObjectBundleValidation();
+        return objectBundleValidation;
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java	2016-02-08 07:21:53 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleService.java	2016-02-10 03:08:09 +0000
@@ -46,7 +46,7 @@
      *
      * @param bundle Bundle to validate
      */
-    void validate( ObjectBundle bundle );
+    ObjectBundleValidation validate( ObjectBundle bundle );
 
     /**
      * Commits objects from bundle into persistence store if bundle mode COMMIT is enabled.

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java	2016-02-10 03:08:09 +0000
@@ -0,0 +1,65 @@
+package org.hisp.dhis.dxf2.metadata2.objectbundle;
+
+/*
+ * 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 org.hisp.dhis.preheat.InvalidReference;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "objectBundleValidation", namespace = DxfNamespaces.DXF_2_0 )
+public class ObjectBundleValidation
+{
+    private List<InvalidReference> missingReferences = new ArrayList<>();
+
+    public ObjectBundleValidation()
+    {
+    }
+
+    @JsonProperty
+    @JacksonXmlElementWrapper( localName = "missingReferences", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "missingReference", namespace = DxfNamespaces.DXF_2_0 )
+    public List<InvalidReference> getMissingReferences()
+    {
+        return missingReferences;
+    }
+
+    public void setMissingReferences( List<InvalidReference> missingReferences )
+    {
+        this.missingReferences = missingReferences;
+    }
+}