dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36877
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18856: ExpressionService, getOptionCombosInExpression, regex improvement
------------------------------------------------------------
revno: 18856
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-04-09 19:07:16 +0200
message:
ExpressionService, getOptionCombosInExpression, regex improvement
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.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/expression/ExpressionServiceTest.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/expression/ExpressionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-04-09 17:07:16 +0000
@@ -52,7 +52,6 @@
*
* @author Margrethe Store
* @author Lars Helge Overland
- * @version $Id: ExpressionService.java 6461 2008-11-24 11:32:37Z larshelg $
*/
public interface ExpressionService
{
@@ -73,6 +72,7 @@
final String OPERAND_EXPRESSION = "#\\{(\\w+)\\.?(\\w*)\\}";
final String OPERAND_UID_EXPRESSION = "(\\w+)\\.?(\\w*)";
final String DATA_ELEMENT_TOTAL_EXPRESSION = "#\\{(\\w+)\\}";
+ final String OPTION_COMBO_OPERAND_EXPRESSION = "#\\{(\\w+)\\.(\\w+)\\}";
final String CONSTANT_EXPRESSION = "C\\{(\\w+)\\}";
final String OU_GROUP_EXPRESSION = "OUG\\{(\\w+)\\}";
final String DAYS_EXPRESSION = "\\[days\\]";
@@ -80,6 +80,7 @@
final Pattern OPERAND_PATTERN = Pattern.compile( OPERAND_EXPRESSION );
final Pattern OPERAND_UID_PATTERN = Pattern.compile( OPERAND_UID_EXPRESSION );
final Pattern DATA_ELEMENT_TOTAL_PATTERN = Pattern.compile( DATA_ELEMENT_TOTAL_EXPRESSION );
+ final Pattern OPTION_COMBO_OPERAND_PATTERN = Pattern.compile( OPTION_COMBO_OPERAND_EXPRESSION );
final Pattern CONSTANT_PATTERN = Pattern.compile( CONSTANT_EXPRESSION );
final Pattern OU_GROUP_PATTERN = Pattern.compile( OU_GROUP_EXPRESSION );
final Pattern DAYS_PATTERN = Pattern.compile( DAYS_EXPRESSION );
@@ -197,7 +198,8 @@
Set<OrganisationUnitGroup> getOrganisationUnitGroupsInExpression( String expression );
/**
- * Returns all CategoryOptionCombos in the given expression string.
+ * Returns all CategoryOptionCombos in the given expression string. Only
+ * operands with a category option combo will be included.
*
* @param expression the expression string.
* @return a Set of CategoryOptionCombos included in the expression string.
@@ -206,8 +208,9 @@
/**
* Returns all operands included in an expression string. The operand is on
- * the form #{data-element-id.category-option combo-id}. Requires that the
- * expression has been exploded in order to handle data element totals.
+ * the form #{data-element-id.category-option combo-id}. Only operands with
+ * a category option combo will be included. Requires that the expression
+ * has been exploded in order to handle data element totals.
*
* @param expression The expression string.
* @return A Set of Operands.
=== 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-02-19 09:18:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2015-04-09 17:07:16 +0000
@@ -293,7 +293,7 @@
return groupsInExpression;
}
-
+
@Override
public Set<String> getDataElementTotalUids( String expression )
{
@@ -322,7 +322,7 @@
{
optionCombosInExpression = new HashSet<>();
- final Matcher matcher = OPERAND_PATTERN.matcher( expression );
+ final Matcher matcher = OPTION_COMBO_OPERAND_PATTERN.matcher( expression );
while ( matcher.find() )
{
@@ -349,7 +349,7 @@
{
operandsInExpression = new HashSet<>();
- final Matcher matcher = OPERAND_PATTERN.matcher( expression );
+ final Matcher matcher = OPTION_COMBO_OPERAND_PATTERN.matcher( expression );
while ( matcher.find() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2015-04-09 17:07:16 +0000
@@ -295,6 +295,24 @@
assertTrue( operands.contains( operandA ) );
assertTrue( operands.contains( operandB ) );
+
+ operands = expressionService.getOperandsInExpression( expressionG );
+
+ assertNotNull( operands );
+ assertEquals( 1, operands.size() );
+
+ assertTrue( operands.contains( operandA ) );
+ }
+
+ @Test
+ public void testGetOptionCombosInExpression()
+ {
+ Set<DataElementCategoryOptionCombo> optionCombos = expressionService.getOptionCombosInExpression( expressionG );
+
+ assertNotNull( optionCombos );
+ assertEquals( 1, optionCombos.size() );
+
+ assertTrue( optionCombos.contains( categoryOptionCombo ) );
}
@Test