← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19088: utility methods on Schema to get persisted/non-persisted properties

 

------------------------------------------------------------
revno: 19088
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-05-05 10:54:59 +0600
message:
  utility methods on Schema to get persisted/non-persisted properties
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.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-api/src/main/java/org/hisp/dhis/schema/Schema.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2015-04-29 07:11:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2015-05-05 04:54:59 +0000
@@ -43,6 +43,7 @@
 import org.springframework.core.Ordered;
 import org.springframework.util.StringUtils;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -147,6 +148,16 @@
     private Map<String, Property> propertyMap = Maps.newHashMap();
 
     /**
+     * Map of all persisted properties, cached on first request.
+     */
+    private Map<String, Property> persistedProperties;
+
+    /**
+     * Map of all persisted properties, cached on first request.
+     */
+    private Map<String, Property> nonPersistedProperties;
+
+    /**
      * Used for sorting of schema list when doing metadata import/export.
      */
     private int order = Ordered.LOWEST_PRECEDENCE;
@@ -394,6 +405,42 @@
         this.propertyMap = propertyMap;
     }
 
+    public Map<String, Property> getPersistedProperties()
+    {
+        if ( persistedProperties == null )
+        {
+            persistedProperties = new HashMap<>();
+
+            for ( Map.Entry<String, Property> entry : getPropertyMap().entrySet() )
+            {
+                if ( entry.getValue().isPersisted() )
+                {
+                    persistedProperties.put( entry.getKey(), entry.getValue() );
+                }
+            }
+        }
+
+        return persistedProperties;
+    }
+
+    public Map<String, Property> getNonPersistedProperties()
+    {
+        if ( nonPersistedProperties == null )
+        {
+            nonPersistedProperties = new HashMap<>();
+
+            for ( Map.Entry<String, Property> entry : getPropertyMap().entrySet() )
+            {
+                if ( !entry.getValue().isPersisted() )
+                {
+                    nonPersistedProperties.put( entry.getKey(), entry.getValue() );
+                }
+            }
+        }
+
+        return nonPersistedProperties;
+    }
+
     public void addProperty( Property property )
     {
         if ( property == null || property.getName() == null || propertyMap.containsKey( property.getName() ) )