dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43827
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22223: support update of validation rules (and left/right side) + tests
------------------------------------------------------------
revno: 22223
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-03-10 13:38:17 +0700
message:
support update of validation rules (and left/right side) + tests
modified:
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/hooks/DataSetObjectBundleHook.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/ValidationRuleObjectBundleHook.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-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-09 07:55:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-10 06:38:17 +0000
@@ -342,8 +342,6 @@
String msg = "Created object '" + bundle.getPreheatIdentifier().getIdentifiersWithName( object ) + "'";
log.debug( msg );
}
-
- sessionFactory.getCurrentSession().flush();
}
}
@@ -373,8 +371,6 @@
String msg = "Updated object '" + bundle.getPreheatIdentifier().getIdentifiersWithName( persistedObject ) + "'";
log.debug( msg );
}
-
- sessionFactory.getCurrentSession().flush();
}
}
@@ -396,8 +392,6 @@
String msg = "Deleted object '" + bundle.getPreheatIdentifier().getIdentifiersWithName( object ) + "'";
log.debug( msg );
}
-
- sessionFactory.getCurrentSession().flush();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/DataSetObjectBundleHook.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/DataSetObjectBundleHook.java 2016-03-09 10:26:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/DataSetObjectBundleHook.java 2016-03-10 06:38:17 +0000
@@ -70,6 +70,7 @@
public void postUpdate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
{
if ( !DataSet.class.isInstance( identifiableObject ) ) return;
+ if ( !objectBundle.getObjectReferences().containsKey( Section.class ) ) return;
DataSet dataSet = (DataSet) identifiableObject;
Map<String, Object> references = objectBundle.getObjectReferences( Section.class ).get( dataSet.getUid() );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/ValidationRuleObjectBundleHook.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/ValidationRuleObjectBundleHook.java 2016-03-10 06:06:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/ValidationRuleObjectBundleHook.java 2016-03-10 06:38:17 +0000
@@ -64,7 +64,17 @@
{
if ( !ValidationRule.class.isInstance( identifiableObject ) ) return;
ValidationRule validationRule = (ValidationRule) identifiableObject;
- validationRule.setLeftSide( null );
- validationRule.setRightSide( null );
+
+ Expression leftSide = validationRule.getLeftSide();
+ Expression rightSide = validationRule.getRightSide();
+
+ preheatService.connectReferences( leftSide, objectBundle.getPreheat(), objectBundle.getPreheatIdentifier() );
+ preheatService.connectReferences( rightSide, objectBundle.getPreheat(), objectBundle.getPreheatIdentifier() );
+
+ sessionFactory.getCurrentSession().save( leftSide );
+ sessionFactory.getCurrentSession().save( rightSide );
+
+ validationRule.setLeftSide( leftSide );
+ validationRule.setRightSide( rightSide );
}
}
=== 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:20:15 +0000
+++ 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
@@ -1025,17 +1025,21 @@
assertFalse( userRoles.isEmpty() );
assertEquals( 2, validationRules.size() );
- ValidationRule validationRule1 = validationRules.get( 0 );
+ ValidationRule validationRule1 = manager.get( ValidationRule.class, "ztzsVjSIWg7" );
assertNotNull( validationRule1.getLeftSide() );
assertNotNull( validationRule1.getRightSide() );
assertFalse( validationRule1.getLeftSide().getDataElementsInExpression().isEmpty() );
assertFalse( validationRule1.getRightSide().getDataElementsInExpression().isEmpty() );
+ assertEquals( "jocQSivF2ry", validationRule1.getLeftSide().getDataElementsInExpression().iterator().next().getUid() );
+ assertEquals( "X0ypiOyoDbw", validationRule1.getRightSide().getDataElementsInExpression().iterator().next().getUid() );
- ValidationRule validationRule2 = validationRules.get( 1 );
+ ValidationRule validationRule2 = manager.get( ValidationRule.class, "TGvH4Hiyduc" );
assertNotNull( validationRule2.getLeftSide() );
assertNotNull( validationRule2.getRightSide() );
assertFalse( validationRule2.getLeftSide().getDataElementsInExpression().isEmpty() );
assertFalse( validationRule2.getRightSide().getDataElementsInExpression().isEmpty() );
+ assertEquals( "jocQSivF2ry", validationRule2.getLeftSide().getDataElementsInExpression().iterator().next().getUid() );
+ assertEquals( "X0ypiOyoDbw", validationRule2.getRightSide().getDataElementsInExpression().iterator().next().getUid() );
}
@Test
@@ -1054,6 +1058,49 @@
assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
objectBundleService.commit( bundle );
+
+ metadata = renderService.fromMetadata( new ClassPathResource( "dxf2/metadata_with_vr_update.json" ).getInputStream(), RenderFormat.JSON );
+
+ params = new ObjectBundleParams();
+ params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+ params.setImportMode( ImportStrategy.UPDATE );
+ params.setObjects( metadata );
+
+ bundle = objectBundleService.create( params );
+ validate = objectBundleService.validate( bundle );
+ assertTrue( validate.getObjectErrorReportsMap().isEmpty() );
+
+ objectBundleService.commit( bundle );
+
+ List<DataSet> dataSets = manager.getAll( DataSet.class );
+ List<OrganisationUnit> organisationUnits = manager.getAll( OrganisationUnit.class );
+ List<DataElement> dataElements = manager.getAll( DataElement.class );
+ List<UserAuthorityGroup> userRoles = manager.getAll( UserAuthorityGroup.class );
+ List<User> users = manager.getAll( User.class );
+ List<ValidationRule> validationRules = manager.getAll( ValidationRule.class );
+
+ assertFalse( dataSets.isEmpty() );
+ assertFalse( organisationUnits.isEmpty() );
+ assertFalse( dataElements.isEmpty() );
+ assertFalse( users.isEmpty() );
+ assertFalse( userRoles.isEmpty() );
+ assertEquals( 2, validationRules.size() );
+
+ ValidationRule validationRule1 = manager.get( ValidationRule.class, "ztzsVjSIWg7" );
+ assertNotNull( validationRule1.getLeftSide() );
+ assertNotNull( validationRule1.getRightSide() );
+ assertFalse( validationRule1.getLeftSide().getDataElementsInExpression().isEmpty() );
+ assertFalse( validationRule1.getRightSide().getDataElementsInExpression().isEmpty() );
+ assertEquals( "vAczVs4mxna", validationRule1.getLeftSide().getDataElementsInExpression().iterator().next().getUid() );
+ assertEquals( "X0ypiOyoDbw", validationRule1.getRightSide().getDataElementsInExpression().iterator().next().getUid() );
+
+ ValidationRule validationRule2 = manager.get( ValidationRule.class, "TGvH4Hiyduc" );
+ assertNotNull( validationRule2.getLeftSide() );
+ assertNotNull( validationRule2.getRightSide() );
+ assertFalse( validationRule2.getLeftSide().getDataElementsInExpression().isEmpty() );
+ assertFalse( validationRule2.getRightSide().getDataElementsInExpression().isEmpty() );
+ assertEquals( "jocQSivF2ry", validationRule2.getLeftSide().getDataElementsInExpression().iterator().next().getUid() );
+ assertEquals( "vAczVs4mxna", validationRule2.getRightSide().getDataElementsInExpression().iterator().next().getUid() );
}
private void defaultSetup()