← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18738: various fixes to programAttribute import/export, adds methods to schemaValdiator to only check fo...

 

------------------------------------------------------------
revno: 18738
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-30 16:25:24 +0700
message:
  various fixes to programAttribute import/export, adds methods to schemaValdiator to only check for persisted properties, other minor fixes
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java	2015-03-30 09:25:24 +0000
@@ -33,6 +33,7 @@
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.base.MoreObjects;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.view.DetailedView;
@@ -159,4 +160,15 @@
         this.allowFutureDate = allowFutureDate;
     }
 
+    @Override
+    public String toString()
+    {
+        return MoreObjects.toStringHelper( this )
+            .add( "id", id )
+            .add( "attribute", attribute )
+            .add( "displayInList", displayInList )
+            .add( "mandatory", mandatory )
+            .add( "allowFutureDate", allowFutureDate )
+            .toString();
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java	2015-03-30 06:57:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/ProgramStageDataElementSchemaDescriptor.java	2015-03-30 09:25:24 +0000
@@ -52,8 +52,8 @@
     public Schema getSchema()
     {
         Schema schema = new Schema( ProgramStageDataElement.class, SINGULAR, PLURAL );
-        // schema.setApiEndpoint( API_ENDPOINT );
-        schema.setOrder( 1510 );
+        schema.setApiEndpoint( API_ENDPOINT );
+        schema.setOrder( 1509 );
 
         schema.getAuthorities().add( new Authority( AuthorityType.CREATE, Lists.newArrayList( "F_PROGRAMSTAGE_ADD" ) ) );
         schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_PROGRAMSTAGE_DELETE" ) ) );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2015-03-30 06:57:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2015-03-30 09:25:24 +0000
@@ -585,7 +585,8 @@
         }
 
         if ( (object.getName() == null || object.getName().length() == 0)
-            && !DashboardItem.class.isInstance( object ) && !Translation.class.isInstance( object ) )
+            && !DashboardItem.class.isInstance( object ) && !Translation.class.isInstance( object )
+            && !ProgramStageDataElement.class.isInstance( object ) )
         {
             conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty name for object " + object );
         }
@@ -599,7 +600,8 @@
                 && !TrackedEntityAttribute.class.isAssignableFrom( object.getClass() )
                 && !TrackedEntity.class.isAssignableFrom( object.getClass() )
                 && !CategoryOptionGroupSet.class.isAssignableFrom( object.getClass() )
-                && !DashboardItem.class.isAssignableFrom( object.getClass() ) )
+                && !DashboardItem.class.isAssignableFrom( object.getClass() )
+                && !ProgramStageDataElement.class.isAssignableFrom( object.getClass() ) )
             {
                 conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty shortName for object " + object );
             }
@@ -1235,18 +1237,8 @@
                     ReflectionUtils.invokeSetterMethod( "programAttributes", object, programTrackedEntityAttributes );
                 }
 
-                for ( ProgramTrackedEntityAttribute trackedEntityAttribute : programTrackedEntityAttributes )
-                {
-                    if ( sessionFactory.getCurrentSession().contains( trackedEntityAttribute ) )
-                    {
-                        sessionFactory.getCurrentSession().delete( trackedEntityAttribute );
-                    }
-
-                    programTrackedEntityAttributeSet.add( trackedEntityAttribute );
-                }
-
+                programTrackedEntityAttributeSet.addAll( programTrackedEntityAttributes );
                 programTrackedEntityAttributes.clear();
-                sessionFactory.getCurrentSession().flush();
             }
 
             return programTrackedEntityAttributeSet;
@@ -1260,14 +1252,17 @@
         private void saveProgramTrackedEntityAttributes( T object, Collection<ProgramTrackedEntityAttribute>
             programTrackedEntityAttributes )
         {
-            for ( ProgramTrackedEntityAttribute programTrackedEntityAttribute : programTrackedEntityAttributes )
+            List<ProgramTrackedEntityAttribute> programTrackedEntityAttributeList = ReflectionUtils.invokeGetterMethod( "programAttributes", object );
+
+            if ( programTrackedEntityAttributeList != null )
             {
-                Map<Field, Object> identifiableObjects = detachFields( programTrackedEntityAttribute );
-                reattachFields( programTrackedEntityAttribute, identifiableObjects, user );
-                sessionFactory.getCurrentSession().save( programTrackedEntityAttribute );
+                for ( ProgramTrackedEntityAttribute programTrackedEntityAttribute : programTrackedEntityAttributes )
+                {
+                    Map<Field, Object> identifiableObjects = detachFields( programTrackedEntityAttribute );
+                    reattachFields( programTrackedEntityAttribute, identifiableObjects, user );
+                    programTrackedEntityAttributeList.add( programTrackedEntityAttribute );
+                }
             }
-
-            ReflectionUtils.invokeSetterMethod( "programAttributes", object, programTrackedEntityAttributes );
         }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java	2015-03-26 11:50:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java	2015-03-30 09:25:24 +0000
@@ -53,6 +53,12 @@
     @Override
     public List<ValidationViolation> validate( Object object )
     {
+        return validate( object, true );
+    }
+
+    @Override
+    public List<ValidationViolation> validate( Object object, boolean persisted )
+    {
         if ( object == null || schemaService.getSchema( object.getClass() ) == null )
         {
             return new ArrayList<>();
@@ -64,6 +70,11 @@
 
         for ( Property property : schema.getProperties() )
         {
+            if ( persisted && !property.isPersisted() )
+            {
+                continue;
+            }
+
             Object value = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
 
             if ( value == null )

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaValidator.java	2015-03-30 09:25:24 +0000
@@ -38,6 +38,17 @@
     /**
      * Validate object against its schema, the object is required to be non-null and have a schema associated with it.
      *
+     * @param object    Object to validate
+     * @param persisted Only include persisted properties
+     * @return WebMessage containing validation response
+     */
+    List<ValidationViolation> validate( Object object, boolean persisted );
+
+    /**
+     * Validate object against its schema, the object is required to be non-null and have a schema associated with it.
+     *
+     * Only persisted values will be checked.
+     *
      * @param object Object to validate
      * @return WebMessage containing validation response
      */

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2015-03-27 16:20:32 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2015-03-30 09:25:24 +0000
@@ -24,11 +24,11 @@
     <property name="dateOfEnrollmentDescription" type="text" />
 
     <property name="dateOfIncidentDescription" type="text" />
-	
+
     <set name="programStages" order-by="sortOrder" cascade="all">
-		<key column="programid" />
-		<one-to-many class="org.hisp.dhis.program.ProgramStage" />
-	</set>
+      <key column="programid" />
+      <one-to-many class="org.hisp.dhis.program.ProgramStage" />
+    </set>
 
     <set name="organisationUnits" table="program_organisationunits">
       <key column="programid" foreign-key="fk_program_organisationunits_programid" />
@@ -48,7 +48,7 @@
 
     <property name="onlyEnrollOnce" />
 
-    <list name="programAttributes" cascade="save-update,delete-orphan">
+    <list name="programAttributes" cascade="all-delete-orphan">
       <key column="programid" />
       <list-index column="sort_order" base="1" />
       <one-to-many class="org.hisp.dhis.program.ProgramTrackedEntityAttribute" />
@@ -62,10 +62,10 @@
         column="userroleid" foreign-key="fk_program_userroles" />
     </set>
 
-	<set name="programIndicators" inverse="true">
-	  <key column="programid" />
-	  <one-to-many class="org.hisp.dhis.program.ProgramIndicator" />
-	</set>
+    <set name="programIndicators" inverse="true">
+      <key column="programid" />
+      <one-to-many class="org.hisp.dhis.program.ProgramIndicator" />
+    </set>
 
     <set name="instanceReminders" order-by="daysAllowedSendMessage" cascade="all">
       <key column="programid" />