← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17836: don't report ref errors on userCredentials + other minor fixes

 

------------------------------------------------------------
revno: 17836
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-30 14:05:45 +0100
message:
  don't report ref errors on userCredentials + other minor fixes
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2014-12-30 12:06:44 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2014-12-30 13:05:45 +0000
@@ -33,6 +33,7 @@
 import org.hibernate.SessionFactory;
 import org.hisp.dhis.common.NameableObject.NameableProperty;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.user.UserCredentials;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -873,7 +874,7 @@
         {
             store = identifiableObjectStoreMap.get( clazz.getSuperclass() );
 
-            if ( store == null )
+            if ( store == null && !UserCredentials.class.isAssignableFrom( clazz ) )
             {
                 log.warn( "No IdentifiableObjectStore found for class: " + clazz );
             }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2014-12-30 12:06:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2014-12-30 13:05:45 +0000
@@ -192,6 +192,16 @@
     private void populateIdentifiableObjectMap( Class<?> clazz, IdentifiableProperty property )
     {
         Map<String, IdentifiableObject> map = new HashMap<>();
+        IdentifiableObject identifiableObject;
+
+        try
+        {
+            identifiableObject = (IdentifiableObject) clazz.newInstance();
+        }
+        catch ( InstantiationException | IllegalAccessException ignored )
+        {
+            return;
+        }
 
         if ( preheatCache && IdentifiableObject.class.isAssignableFrom( clazz ) )
         {
@@ -204,11 +214,11 @@
             {
                 uidMap.put( (Class<? extends IdentifiableObject>) clazz, map );
             }
-            else if ( property == IdentifiableProperty.CODE )
+            else if ( property == IdentifiableProperty.CODE && identifiableObject.haveUniqueCode() )
             {
                 codeMap.put( (Class<? extends IdentifiableObject>) clazz, map );
             }
-            else if ( property == IdentifiableProperty.NAME )
+            else if ( property == IdentifiableProperty.NAME && identifiableObject.haveUniqueNames() )
             {
                 if ( !preheatCache )
                 {
@@ -216,32 +226,24 @@
                 }
                 else
                 {
-                    try
-                    {
-                        IdentifiableObject identifiableObject = (IdentifiableObject) clazz.newInstance();
-
-                        if ( identifiableObject.haveUniqueNames() )
-                        {
-                            nameMap.put( (Class<? extends IdentifiableObject>) clazz, map );
-                        }
-                        else
-                        {
-                            // add an empty map here, since we could still have some auto-generated properties
-                            nameMap.put( (Class<? extends IdentifiableObject>) clazz, new HashMap<String, IdentifiableObject>() );
-
-                            // find all auto-generated props and add them
-                            for ( Map.Entry<String, IdentifiableObject> entry : map.entrySet() )
+                    if ( identifiableObject.haveUniqueNames() )
+                    {
+                        nameMap.put( (Class<? extends IdentifiableObject>) clazz, map );
+                    }
+                    else
+                    {
+                        // add an empty map here, since we could still have some auto-generated properties
+                        nameMap.put( (Class<? extends IdentifiableObject>) clazz, new HashMap<String, IdentifiableObject>() );
+
+                        // find all auto-generated props and add them
+                        for ( Map.Entry<String, IdentifiableObject> entry : map.entrySet() )
+                        {
+                            if ( entry.getValue().isAutoGenerated() )
                             {
-                                if ( entry.getValue().isAutoGenerated() )
-                                {
-                                    nameMap.get( clazz ).put( entry.getKey(), entry.getValue() );
-                                }
+                                nameMap.get( clazz ).put( entry.getKey(), entry.getValue() );
                             }
                         }
                     }
-                    catch ( InstantiationException | IllegalAccessException ignored )
-                    {
-                    }
                 }
             }
         }
@@ -459,7 +461,7 @@
                 }
             }
 
-            if ( identifiableObject.getCode() != null )
+            if ( identifiableObject.getCode() != null && identifiableObject.haveUniqueCode() )
             {
                 IdentifiableObject match = getCodeMatch( identifiableObject );
 
@@ -515,7 +517,7 @@
                 }
             }
 
-            if ( identifiableObject.haveUniqueCode() && identifiableObject.getCode() != null )
+            if ( identifiableObject.getCode() != null && identifiableObject.haveUniqueCode() )
             {
                 Map<String, IdentifiableObject> map = codeMap.get( identifiableObject.getClass() );
 
@@ -613,6 +615,11 @@
             map = codeMap.get( identifiableObject.getClass() );
         }
 
+        if ( entity != null && !entity.haveUniqueCode() )
+        {
+            return null;
+        }
+
         if ( !preheatCache && entity == null && identifiableObject.haveUniqueCode() )
         {
             entity = manager.getByCode( identifiableObject.getClass(), identifiableObject.getCode() );
@@ -641,6 +648,11 @@
             map = nameMap.get( identifiableObject.getClass() );
         }
 
+        if ( entity != null && !entity.haveUniqueNames() )
+        {
+            return null;
+        }
+
         if ( !preheatCache && entity == null && identifiableObject.haveUniqueNames() )
         {
             entity = manager.getByName( identifiableObject.getClass(), identifiableObject.getName() );

=== 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	2014-12-30 12:06:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2014-12-30 13:05:45 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.dashboard.DashboardItem;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataelement.DataElementCategoryDimension;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementOperand;
@@ -560,6 +561,7 @@
                 // this is nasty, but we have types in the system which have shortName, but which do -not- require not-null )
                 && !TrackedEntityAttribute.class.isAssignableFrom( object.getClass() )
                 && !TrackedEntity.class.isAssignableFrom( object.getClass() )
+                && !CategoryOptionGroupSet.class.isAssignableFrom( object.getClass() )
                 && !DashboardItem.class.isAssignableFrom( object.getClass() ) )
             {
                 conflict = new ImportConflict( ImportUtils.getDisplayName( object ), "Empty shortName for object " + object );
@@ -831,6 +833,11 @@
 
     private void reportReferenceError( Object object, Object reference )
     {
+        if ( UserCredentials.class.isInstance( object ) || UserCredentials.class.isInstance( reference ) )
+        {
+            return;
+        }
+
         String objectName = object != null ? object.getClass().getSimpleName() : "null";
         String referenceName = reference != null ? reference.getClass().getSimpleName() : "null";