dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41936
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21403: Expression service, reusing util method
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 21403 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-12-10 12:14:51 +0100
message:
Expression service, reusing util method
modified:
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/AnalyticsSecurityManager.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/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-12-08 21:44:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-12-10 11:14:51 +0000
@@ -179,14 +179,6 @@
Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, Set<DataElementOperand> incompleteValues );
/**
- * Returns the uids of the data element totals in the given expression.
- *
- * @param expression the expression.
- * @return a set of data element uids.
- */
- Set<String> getDataElementTotalUids( String expression );
-
- /**
* Returns all data elements included in the given expression string.
*
* @param expression the expression string.
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsSecurityManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsSecurityManager.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsSecurityManager.java 2015-12-10 10:41:17 +0000
@@ -38,7 +38,7 @@
/**
* Decides whether the current user has privileges to execute the given query.
*
- * @param params the data query params.
+ * @param params the data query parameters.
* @throws IllegalQueryException if the current user does not have privileges
* to execute the given query.
*/
@@ -48,19 +48,23 @@
* Adds relevant data approval levels to the given query if system is configured
* to hide unapproved data from analytics and if there are relevant approval
* levels for current user. Populates the approvalLevels property of the given
- * query and sets the level poperty of each related organisation unit.
+ * query and sets the level property of each related organisation unit.
*
- * @param params the data query params.
+ * @param params the data query parameters.
+ * @throws IllegalQueryException is the specified approval level does not exist.
*/
void applyDataApprovalConstraints( DataQueryParams params );
/**
- * Applies dimension constraints to the given params. Dimension constraints
+ * Applies dimension constraints to the given parameters. Dimension constraints
* with all accessible dimension items will be added as filters to this query.
* If current user has no dimension constraints, no action is taken. If the
* constraint dimensions are already specified with accessible items in the
* query, no action is taken. If the current user does not have accessible
* items in any dimension constraint, an IllegalQueryException is thrown.
+ *
+ * @param pamrams the data query parameters.
+ * @throws IllegalQueryException is the specified approval level does not exist.
*/
void applyDimensionConstraints( DataQueryParams params );
}
=== 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-12-10 09:51:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-12-10 10:41:17 +0000
@@ -181,7 +181,18 @@
queryPlanner.validate( params );
params.conform();
-
+
+ return getAggregatedDataValueGridInternal( params );
+ }
+
+ /**
+ * Returns a grid with aggregated data.
+ *
+ * @param params the data query parameters.
+ * @return a grid with aggregated data.
+ */
+ private Grid getAggregatedDataValueGridInternal( DataQueryParams params )
+ {
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
=== 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-12-09 17:42:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2015-12-10 11:14:51 +0000
@@ -55,6 +55,7 @@
import org.hisp.dhis.common.DimensionalItemObject;
import org.hisp.dhis.common.GenericStore;
import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.RegexUtils;
import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
import org.hisp.dhis.constant.Constant;
import org.hisp.dhis.constant.ConstantService;
@@ -316,25 +317,7 @@
return groupsInExpression;
}
-
- @Override
- public Set<String> getDataElementTotalUids( String expression )
- {
- Set<String> uids = new HashSet<>();
-
- if ( expression != null )
- {
- final Matcher matcher = DATA_ELEMENT_TOTAL_PATTERN.matcher( expression );
-
- while ( matcher.find() )
- {
- uids.add( matcher.group( 1 ) );
- }
- }
-
- return uids;
- }
-
+
@Override
@Transactional
public Set<DataElementCategoryOptionCombo> getOptionCombosInExpression( String expression )
@@ -694,8 +677,8 @@
for ( ValidationRule rule : validationRules )
{
- dataElementTotals.addAll( getDataElementTotalUids( rule.getLeftSide().getExpression() ) );
- dataElementTotals.addAll( getDataElementTotalUids( rule.getRightSide().getExpression() ) );
+ dataElementTotals.addAll( RegexUtils.getMatches( DATA_ELEMENT_TOTAL_PATTERN, rule.getLeftSide().getExpression(), 1 ) );
+ dataElementTotals.addAll( RegexUtils.getMatches( DATA_ELEMENT_TOTAL_PATTERN, rule.getRightSide().getExpression(), 1 ) );
}
if ( !dataElementTotals.isEmpty() )
@@ -713,7 +696,7 @@
}
}
}
-
+
private String explodeExpression( String expression, ListMap<String, String> dataElementOptionComboMap )
{
if ( expression == null || expression.isEmpty() )
@@ -991,8 +974,7 @@
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
-
-
+
private boolean operandIsTotal( Matcher matcher )
{
return matcher != null && StringUtils.trimToEmpty( matcher.group( 2 ) ).isEmpty();
=== 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-12-09 17:24:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2015-12-10 11:14:51 +0000
@@ -327,19 +327,6 @@
}
@Test
- public void testGetDataElementTotalUids()
- {
- Set<String> uids = new HashSet<>();
- Set<String> empty = new HashSet<>();
-
- uids.add( dataElementB.getUid() );
- uids.add( dataElementC.getUid() );
-
- assertEquals( uids, expressionService.getDataElementTotalUids( expressionG ) );
- assertEquals( empty, expressionService.getDataElementTotalUids( expressionA ) );
- }
-
- @Test
public void testGetOperandsInExpression()
{
Set<DataElementOperand> operands = expressionService.getOperandsInExpression( expressionA );