dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41827
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21351: ExpressionService.getValue. Accepting DimensionalItemObjects instead of DataElementOperands.
------------------------------------------------------------
revno: 21351
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-07 00:17:32 +0100
message:
ExpressionService.getValue. Accepting DimensionalItemObjects instead of DataElementOperands.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.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/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2015-11-23 14:22:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2015-12-06 23:17:32 +0000
@@ -159,7 +159,18 @@
@Override
public String getDimensionItem()
{
- return dataElement.getUid() + SEPARATOR + categoryOptionCombo.getUid();
+ String item = null;
+
+ if ( dataElement != null )
+ {
+ item = dataElement.getUid() + ( categoryOptionCombo != null ? ( SEPARATOR + categoryOptionCombo.getUid() ) : StringUtils.EMPTY );
+ }
+ else if ( dataElementId != null )
+ {
+ item = dataElementId + ( optionComboId != null ? ( SEPARATOR + optionComboId ) : StringUtils.EMPTY );
+ }
+
+ return item;
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-12-05 15:33:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-12-06 23:17:32 +0000
@@ -34,6 +34,7 @@
import java.util.Set;
import java.util.regex.Pattern;
+import org.hisp.dhis.common.DimensionalItemObject;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementOperand;
@@ -49,8 +50,12 @@
* <ul>
* <li>Data element operands on the form #{dataelementuid.categoryoptioncombouid}</li>
* <li>Data element totals on the form #{dataelementuid}</li>
+ * <li>Program data elements on the form D{programuid.dataelementuid}</li>
+ * <li>Program tracked entity attribute on the form A{programuid.attributeuid}</li>
+ * <li>Program indicators on the form I{programindicatoruid}</li>
* <li>Constants on the form C{constantuid}</li>
- * <li>Days in aggregation period as the symbol D{}</li>
+ * <li>Organisation unit group member counts on the form OUG{orgunitgroupuid}</li>
+ * <li>Days in aggregation period as the symbol [days]</li>
* </ul>
*
* @author Margrethe Store
@@ -71,8 +76,11 @@
String DAYS_DESCRIPTION = "[Number of days]";
String NULL_REPLACEMENT = "0";
String SPACE = " ";
+ String DAYS_SYMBOL = "[days]";
+ String VARIABLE_EXPRESSION = "(#|D|A|I)\\{(([a-zA-Z]\\w{10})\\.?(\\w*))\\}";
String OPERAND_EXPRESSION = "#\\{([a-zA-Z]\\w{10})\\.?(\\w*)\\}";
+ String PROGRAM_DATA_ELEMENT_EXPRESSION = "D\\{([a-zA-Z]\\w{10})\\.?([a-zA-Z]\\w{10})\\}";
String OPERAND_UID_EXPRESSION = "([a-zA-Z]\\w{10})\\.?(\\w*)";
String DATA_ELEMENT_TOTAL_EXPRESSION = "#\\{([a-zA-Z]\\w{10})\\}";
String OPTION_COMBO_OPERAND_EXPRESSION = "#\\{([a-zA-Z]\\w{10})\\.([a-zA-Z]\\w{10})\\}";
@@ -80,15 +88,15 @@
String OU_GROUP_EXPRESSION = "OUG\\{([a-zA-Z]\\w{10})\\}";
String DAYS_EXPRESSION = "\\[days\\]";
+ Pattern VARIABLE_PATTERN = Pattern.compile( VARIABLE_EXPRESSION );
Pattern OPERAND_PATTERN = Pattern.compile( OPERAND_EXPRESSION );
Pattern OPERAND_UID_PATTERN = Pattern.compile( OPERAND_UID_EXPRESSION );
+ Pattern PROGRAM_DATA_ELEMENT_PATTERN = Pattern.compile( PROGRAM_DATA_ELEMENT_EXPRESSION );
Pattern DATA_ELEMENT_TOTAL_PATTERN = Pattern.compile( DATA_ELEMENT_TOTAL_EXPRESSION );
Pattern OPTION_COMBO_OPERAND_PATTERN = Pattern.compile( OPTION_COMBO_OPERAND_EXPRESSION );
Pattern CONSTANT_PATTERN = Pattern.compile( CONSTANT_EXPRESSION );
Pattern OU_GROUP_PATTERN = Pattern.compile( OU_GROUP_EXPRESSION );
Pattern DAYS_PATTERN = Pattern.compile( DAYS_EXPRESSION );
-
- String DAYS_SYMBOL = "[days]";
/**
* Adds a new Expression to the database.
@@ -138,7 +146,7 @@
* @param orgUnitCountMap the map of organisation unit counts.
* @return the calculated value as a double.
*/
- Double getIndicatorValue( Indicator indicator, Period period, Map<DataElementOperand, Double> valueMap,
+ Double getIndicatorValue( Indicator indicator, Period period, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap );
/**
@@ -155,7 +163,7 @@
* @param days the number of days to use in the calculation.
* @return the calculated value as a double.
*/
- Double getExpressionValue( Expression expression, Map<DataElementOperand, Double> valueMap,
+ Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days );
/**
@@ -175,7 +183,7 @@
* not all children had a value.)
* @return the calculated value as a double.
*/
- Double getExpressionValue( Expression expression, Map<DataElementOperand, Double> valueMap,
+ Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, Set<DataElementOperand> incompleteValues );
/**
@@ -360,7 +368,7 @@
* @param missingValueStrategy the strategy to use when data values are missing
* when calculating the expression. Strategy defaults to NEVER_SKIP if null.
*/
- String generateExpression( String expression, Map<DataElementOperand, Double> valueMap,
+ String generateExpression( String expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, MissingValueStrategy missingValueStrategy );
/**
=== 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-11-22 17:08:47 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-12-06 23:17:32 +0000
@@ -270,7 +270,7 @@
{
String permKey = DimensionItem.asItemKey( dimensionItems );
- Map<DataElementOperand, Double> valueMap = permutationOperandValueMap.get( permKey );
+ Map<? extends DimensionalItemObject, Double> valueMap = permutationOperandValueMap.get( permKey );
if ( valueMap == null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2015-10-20 19:03:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2015-12-06 23:17:32 +0000
@@ -46,10 +46,12 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.DimensionalItemObject;
import org.hisp.dhis.common.GenericStore;
import org.hisp.dhis.common.ListMap;
import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
@@ -71,6 +73,8 @@
import org.hisp.dhis.validation.ValidationRule;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.collect.Sets;
+
/**
* The expression is a string describing a formula containing data element ids
* and category option combo ids. The formula can potentially contain references
@@ -167,7 +171,7 @@
// -------------------------------------------------------------------------
@Override
- public Double getIndicatorValue( Indicator indicator, Period period, Map<DataElementOperand, Double> valueMap,
+ public Double getIndicatorValue( Indicator indicator, Period period, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap )
{
if ( indicator == null || indicator.getExplodedNumeratorFallback() == null || indicator.getExplodedDenominatorFallback() == null )
@@ -210,14 +214,14 @@
}
@Override
- public Double getExpressionValue( Expression expression, Map<DataElementOperand, Double> valueMap,
+ public Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days )
{
return getExpressionValue( expression, valueMap, constantMap, orgUnitCountMap, days, null );
}
@Override
- public Double getExpressionValue( Expression expression, Map<DataElementOperand, Double> valueMap,
+ public Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, Set<DataElementOperand> incompleteValues )
{
String expressionString = generateExpression( expression.getExplodedExpressionFallback(), valueMap, constantMap,
@@ -863,28 +867,34 @@
@Override
@Transactional
- public String generateExpression( String expression, Map<DataElementOperand, Double> valueMap,
+ public String generateExpression( String expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, MissingValueStrategy missingValueStrategy )
{
return generateExpression( expression, valueMap, constantMap, orgUnitCountMap, days, missingValueStrategy, null );
}
- private String generateExpression( String expression, Map<DataElementOperand, Double> valueMap,
+ private String generateExpression( String expression, Map<? extends DimensionalItemObject, Double> valueMap,
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, MissingValueStrategy missingValueStrategy, Set<DataElementOperand> incompleteValues )
{
if ( expression == null || expression.isEmpty() )
{
return null;
}
+
+ Map<String, Double> dimensionItemValueMap = valueMap.entrySet().stream().
+ collect( Collectors.toMap( e -> e.getKey().getDimensionItem(), e -> e.getValue() ) );
+
+ Set<String> incompleteItems = incompleteValues != null ? incompleteValues.
+ stream().map( i -> i.getDimensionItem() ).collect( Collectors.toSet() ) : Sets.newHashSet();
missingValueStrategy = missingValueStrategy == null ? NEVER_SKIP : missingValueStrategy;
// ---------------------------------------------------------------------
- // Operands
+ // DimensionalItemObjects
// ---------------------------------------------------------------------
StringBuffer sb = new StringBuffer();
- Matcher matcher = OPERAND_PATTERN.matcher( expression );
+ Matcher matcher = VARIABLE_PATTERN.matcher( expression );
int matchCount = 0;
int valueCount = 0;
@@ -893,11 +903,11 @@
{
matchCount++;
- DataElementOperand operand = DataElementOperand.getOperand( matcher.group() );
-
- final Double value = valueMap.get( operand );
-
- boolean missingValue = value == null || ( incompleteValues != null && incompleteValues.contains( operand ) );
+ String dimItem = matcher.group( 2 );
+
+ final Double value = dimensionItemValueMap.get( dimItem );
+
+ boolean missingValue = value == null || incompleteItems.contains( dimItem );
if ( missingValue && SKIP_IF_ANY_VALUE_MISSING.equals( missingValueStrategy ) )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java 2015-11-30 03:36:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java 2015-12-06 23:17:32 +0000
@@ -709,16 +709,14 @@
for ( String s : approvalStrings )
{
- System.out.println( " \"" + s + "\"" + ( ++count < approvalStrings.length ? "," : " }," ) );
+ System.out.println( "\"" + s + "\"" + ( ++count < approvalStrings.length ? "," : " }," ) );
}
String username = mockUserService.getCurrentUsername();
- System.out.println( " userApprovalsAndPermissions( "
+ System.out.println( "userApprovalsAndPermissions( "
+ username.substring( 0, 1 ).toLowerCase() + username.substring( 1, username.length() )
+ ", workflowAll, periodA, null ) );" );
-
- System.out.println();
}
@SuppressWarnings("unused")
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2015-11-27 08:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2015-12-06 23:17:32 +0000
@@ -379,7 +379,6 @@
}
else if ( EnrollmentStatus.COMPLETED == enrollment.getStatus() )
{
- System.out.println("It is completed...");
programInstanceService.completeProgramInstanceStatus( programInstance );
}
else
=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2015-12-04 08:18:34 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2015-12-06 23:17:32 +0000
@@ -315,14 +315,13 @@
public org.hisp.dhis.api.mobile.model.LWUITmodel.MobileModel getAllDataForOrgUnitLWUIT(
@PathVariable String clientVersion, @PathVariable int id )
{
- System.out.println("Start getting model");
org.hisp.dhis.api.mobile.model.LWUITmodel.MobileModel mobileModel = new org.hisp.dhis.api.mobile.model.LWUITmodel.MobileModel();
mobileModel.setClientVersion( clientVersion );
OrganisationUnit unit = getUnit( id );
mobileModel.setPrograms( programService.getProgramsLWUIT( unit ) );
mobileModel.setServerCurrentDate( new Date() );
mobileModel.setRelationshipTypes( programService.getAllRelationshipTypes() );
- System.out.println("Finish all data");
+
return mobileModel;
}