← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22174: handle reference errors in attributeValues and userGroupAccessses

 

------------------------------------------------------------
revno: 22174
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-03-08 14:13:54 +0700
message:
  handle reference errors in attributeValues and userGroupAccessses
modified:
  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/objectbundle/DefaultObjectBundleService.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-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-08 04:49:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java	2016-03-08 07:13:54 +0000
@@ -487,7 +487,7 @@
                     IdentifiableObject refObject = ReflectionUtils.invokeMethod( object, p.getGetterMethod() );
                     IdentifiableObject ref = preheat.get( identifier, refObject );
 
-                    if ( ref == null && refObject != null && !Preheat.isDefault( refObject ) )
+                    if ( ref == null && refObject != null && !Preheat.isDefaultClass( refObject.getClass() ) )
                     {
                         preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002,
                             identifier.getIdentifiersWithName( refObject ), identifier.getIdentifiersWithName( object ), p.getName() ) );
@@ -519,6 +519,22 @@
                 }
             } );
 
+        if ( schema.havePersistedProperty( "attributeValues" ) )
+        {
+            object.getAttributeValues().stream()
+                .filter( attributeValue -> attributeValue.getAttribute() != null && preheat.get( identifier, attributeValue.getAttribute() ) == null )
+                .forEach( attributeValue -> preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002,
+                    identifier.getIdentifiersWithName( attributeValue.getAttribute() ), identifier.getIdentifiersWithName( object ), "attributeValues" ) ) );
+        }
+
+        if ( schema.havePersistedProperty( "userGroupAccesses" ) )
+        {
+            object.getUserGroupAccesses().stream()
+                .filter( userGroupAccess -> userGroupAccess.getUserGroup() != null && preheat.get( identifier, userGroupAccess.getUserGroup() ) == null )
+                .forEach( attributeValue -> preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002,
+                    identifier.getIdentifiersWithName( attributeValue.getUserGroup() ), identifier.getIdentifiersWithName( object ), "userGroupAccesses" ) ) );
+        }
+
         return preheatErrorReports;
     }
 

=== 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-08 04:49:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-03-08 07:13:54 +0000
@@ -181,16 +181,17 @@
                 {
                     IdentifiableObject identifiableObject = iterator.next();
                     IdentifiableObject object = bundle.getPreheat().get( bundle.getPreheatIdentifier(), identifiableObject );
-                    ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
 
                     if ( object != null && object.getId() > 0 )
                     {
+                        ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
                         objectErrorReport.addErrorReport( new ErrorReport( klass, ErrorCode.E5000, bundle.getPreheatIdentifier(),
                             bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) ) );
+                        objectBundleValidation.addObjectErrorReport( objectErrorReport );
+
                         iterator.remove();
                     }
 
-                    objectBundleValidation.addObjectErrorReport( objectErrorReport );
                     idx++;
                 }
             }
@@ -203,16 +204,16 @@
                 {
                     IdentifiableObject identifiableObject = iterator.next();
                     IdentifiableObject object = bundle.getPreheat().get( bundle.getPreheatIdentifier(), identifiableObject );
-                    ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
 
                     if ( object == null )
                     {
+                        ObjectErrorReport objectErrorReport = new ObjectErrorReport( klass, idx );
                         objectErrorReport.addErrorReport( new ErrorReport( klass, ErrorCode.E5001, bundle.getPreheatIdentifier(),
                             bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) ) );
+                        objectBundleValidation.addObjectErrorReport( objectErrorReport );
                         iterator.remove();
                     }
 
-                    objectBundleValidation.addObjectErrorReport( objectErrorReport );
                     idx++;
                 }
             }

=== 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-08 04:49:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-08 07:13:54 +0000
@@ -258,8 +258,10 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
 
+        System.err.println( validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5002 ) );
+
         assertFalse( validate.getObjectErrorReportsMap().isEmpty() );
-        assertEquals( 7, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5002 ).size() );
+        assertEquals( 5, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E5002 ).size() );
         assertEquals( 3, validate.getErrorReportsByCode( DataElement.class, ErrorCode.E4000 ).size() );
     }