dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37942
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19375: Analytics, centralized code for meta-data
------------------------------------------------------------
revno: 19375
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-06-13 13:43:28 +0200
message:
Analytics, centralized code for meta-data
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseDimensionalObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.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/common/BaseDimensionalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseDimensionalObject.java 2015-03-08 10:23:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseDimensionalObject.java 2015-06-13 11:43:28 +0000
@@ -35,6 +35,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
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.view.DetailedView;
import org.hisp.dhis.common.view.DimensionalView;
@@ -312,6 +313,13 @@
@Override
public String toString()
{
- return "[" + uid + ", type: " + dimensionType + ", items: " + items + ", legend set: " + legendSet + ", filter: " + filter + "]";
+ return MoreObjects.toStringHelper( this )
+ .add( "Dimension", uid )
+ .add( "type", dimensionType )
+ .add( "dimension name", dimensionName )
+ .add( "display name", displayName )
+ .add( "items", items )
+ .add( "legend set", legendSet )
+ .add( "filter", filter ).toString();
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java 2015-04-03 12:51:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/NameableObjectUtils.java 2015-06-13 11:43:28 +0000
@@ -188,13 +188,14 @@
}
/**
- * Returns a mapping between the UID and the short name of the given nameable
- * objects.
+ * Returns a mapping between the UID and the property defined by the given
+ * display property.
*
- * @param objects the v objects.
- * @return mapping between the uid and the short name of the given objects.
+ * @param objects the objects.
+ * @param displayProperty the property to use as value.
+ * @return mapping between the uid and the property of the given objects.
*/
- public static Map<String, String> getUidShortNameMap( Collection<? extends NameableObject> objects )
+ public static Map<String, String> getUidDisplayPropertyMap( Collection<? extends NameableObject> objects, DisplayProperty displayProperty )
{
Map<String, String> map = new HashMap<>();
@@ -202,7 +203,7 @@
{
for ( NameableObject object : objects )
{
- map.put( object.getUid(), object.getDisplayShortName() );
+ map.put( object.getUid(), getDisplayProperty( object, displayProperty ) );
}
}
@@ -243,21 +244,21 @@
/**
* Returns the property of the given object indicated by the given display
- * property.
+ * property. Falls back to name if short name is null.
*
* @param object the object to read the property from.
* @param displayProperty the display property to use.
* @return a property value.
*/
- public static <T extends NameableObject> String getProperty( T object, DisplayProperty displayProperty )
+ public static <T extends NameableObject> String getDisplayProperty( T object, DisplayProperty displayProperty )
{
if ( object != null )
{
- if ( DisplayProperty.SHORTNAME.equals( displayProperty ) )
+ if ( DisplayProperty.SHORTNAME.equals( displayProperty ) && object.getDisplayShortName() != null )
{
return object.getDisplayShortName();
}
- else // NAME
+ else
{
return object.getDisplayName();
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2015-05-26 03:06:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2015-06-13 11:43:28 +0000
@@ -69,7 +69,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static org.hisp.dhis.common.NameableObjectUtils.getProperty;
+import static org.hisp.dhis.common.NameableObjectUtils.getDisplayProperty;
/**
* @author Kristian Nordal
@@ -765,7 +765,7 @@
{
for ( OrganisationUnit unit : organisationUnits )
{
- map.put( getProperty( unit, displayProperty ), unit.getParentNameGraph( roots, includeThis ) );
+ map.put( getDisplayProperty( unit, displayProperty ), unit.getParentNameGraph( roots, includeThis ) );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-05-28 15:04:54 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-13 11:43:28 +0000
@@ -1331,32 +1331,18 @@
}
else
{
- map.put( object.getUid(), NameableObjectUtils.getProperty( object, displayProperty ) );
+ map.put( object.getUid(), NameableObjectUtils.getDisplayProperty( object, displayProperty ) );
}
if ( orgUnitHierarchy )
{
OrganisationUnit unit = (OrganisationUnit) object;
-
- if ( DisplayProperty.SHORTNAME.equals( displayProperty ) )
- {
- map.putAll( NameableObjectUtils.getUidShortNameMap( unit.getAncestors() ) );
- }
- else // NAME
- {
- map.putAll( IdentifiableObjectUtils.getUidNameMap( unit.getAncestors() ) );
- }
+
+ map.putAll( NameableObjectUtils.getUidDisplayPropertyMap( unit.getAncestors(), displayProperty ) );
}
}
- if ( dimension.getDisplayShortName() != null && DisplayProperty.SHORTNAME.equals( displayProperty ) )
- {
- map.put( dimension.getDimension(), dimension.getDisplayShortName() );
- }
- else if ( dimension.getDisplayName() != null ) // NAME TODO use getProperty
- {
- map.put( dimension.getDimension(), dimension.getDisplayName() );
- }
+ map.put( dimension.getDimension(), NameableObjectUtils.getDisplayProperty( dimension, displayProperty ) );
}
return map;
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2015-05-28 15:04:54 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2015-06-13 11:43:28 +0000
@@ -609,7 +609,7 @@
if ( params.hasValueDimension() )
{
- map.put( params.getValue().getUid(), NameableObjectUtils.getProperty( params.getValue(), params.getDisplayProperty() ) );
+ map.put( params.getValue().getUid(), NameableObjectUtils.getDisplayProperty( params.getValue(), params.getDisplayProperty() ) );
}
map.putAll( getUidNameMap( params.getItems(), params.getDisplayProperty() ) );
@@ -627,7 +627,7 @@
for ( QueryItem item : queryItems )
{
- map.put( item.getItem().getUid(), NameableObjectUtils.getProperty( item.getItem(), displayProperty ) );
+ map.put( item.getItem().getUid(), NameableObjectUtils.getDisplayProperty( item.getItem(), displayProperty ) );
}
return map;
@@ -652,17 +652,10 @@
objects.addAll( unit.getAncestors() );
}
- if ( DisplayProperty.SHORTNAME.equals( displayProperty ) )
- {
- map.putAll( NameableObjectUtils.getUidShortNameMap( objects ) );
- }
- else // NAME
- {
- map.putAll( IdentifiableObjectUtils.getUidNameMap( objects ) );
- }
+ map.putAll( NameableObjectUtils.getUidDisplayPropertyMap( objects, displayProperty ) );
}
- map.put( dimension.getDimension(), NameableObjectUtils.getProperty( dimension, displayProperty ) );
+ map.put( dimension.getDimension(), NameableObjectUtils.getDisplayProperty( dimension, displayProperty ) );
}
return map;