dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40839
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20791: Using POST for program indicator validation
------------------------------------------------------------
revno: 20791
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-10-20 09:16:41 +0200
message:
Using POST for program indicator validation
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementValueTypesFilter.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js
--
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/ValueType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java 2015-10-19 14:51:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java 2015-10-20 07:16:41 +0000
@@ -29,12 +29,12 @@
*/
import java.util.Date;
-import java.util.List;
+import java.util.Set;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.trackedentity.TrackedEntityInstance;
-import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
/**
* @author Lars Helge Overland
@@ -63,13 +63,13 @@
FILE_RESOURCE( String.class ),
COORDINATE( String.class);
- public static final List<ValueType> INTEGER_TYPES = Lists.newArrayList(
+ public static final Set<ValueType> INTEGER_TYPES = Sets.newHashSet(
INTEGER, INTEGER_POSITIVE, INTEGER_NEGATIVE, INTEGER_ZERO_OR_POSITIVE );
- public static final List<ValueType> NUMERIC_TYPES = Lists.newArrayList(
+ public static final Set<ValueType> NUMERIC_TYPES = Sets.newHashSet(
INTEGER, INTEGER_POSITIVE, INTEGER_NEGATIVE, INTEGER_ZERO_OR_POSITIVE, NUMBER, UNIT_INTERVAL, PERCENTAGE );
- public static final List<ValueType> TEXT_TYPES = Lists.newArrayList(
+ public static final Set<ValueType> TEXT_TYPES = Sets.newHashSet(
TEXT, LONG_TEXT, LETTER, COORDINATE );
private final Class<?> javaClass;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2015-10-12 10:18:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2015-10-20 07:16:41 +0000
@@ -186,7 +186,7 @@
* @param valueTypes The value types.
* @return all DataElements with the given value types.
*/
- List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes );
+ List<DataElement> getDataElementsByValueTypes( Collection<ValueType> valueTypes );
/**
* Returns all DataElements with the given type.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2015-09-15 09:54:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2015-10-20 07:16:41 +0000
@@ -101,7 +101,7 @@
* @param valueTypes The value types.
* @return all DataElements with the given value types.
*/
- List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes );
+ List<DataElement> getDataElementsByValueTypes( Collection<ValueType> valueTypes );
/**
* Returns all DataElements with the given value type.
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java 2015-09-23 12:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java 2015-10-20 07:16:41 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.analytics.AggregationType;
import org.hisp.dhis.analytics.AnalyticsTable;
@@ -175,11 +177,11 @@
populateTable( table, "cast(dv.value as " + dbl + ")", "null", ValueType.NUMERIC_TYPES, intClause, approvalClause );
- populateTable( table, "1", "null", Lists.newArrayList( ValueType.BOOLEAN, ValueType.TRUE_ONLY ), "dv.value = 'true'", approvalClause );
-
- populateTable( table, "0", "null", Lists.newArrayList( ValueType.BOOLEAN ), "dv.value = 'false'", approvalClause );
-
- populateTable( table, "1", "null", Lists.newArrayList( ValueType.TRUE_ONLY ), "dv.value = 'true'", approvalClause );
+ populateTable( table, "1", "null", Sets.newHashSet( ValueType.BOOLEAN, ValueType.TRUE_ONLY ), "dv.value = 'true'", approvalClause );
+
+ populateTable( table, "0", "null", Sets.newHashSet( ValueType.BOOLEAN ), "dv.value = 'false'", approvalClause );
+
+ populateTable( table, "1", "null", Sets.newHashSet( ValueType.TRUE_ONLY ), "dv.value = 'true'", approvalClause );
populateTable( table, "null", "dv.value", ValueType.TEXT_TYPES, null, approvalClause );
}
@@ -197,7 +199,7 @@
* @param whereClause where clause to constrain data query.
*/
private void populateTable( AnalyticsTable table, String valueExpression,
- String textValueExpression, List<ValueType> valueTypes, String whereClause, String approvalClause )
+ String textValueExpression, Set<ValueType> valueTypes, String whereClause, String approvalClause )
{
final String start = DateUtils.getMediumDateString( table.getPeriod().getStartDate() );
final String end = DateUtils.getMediumDateString( table.getPeriod().getEndDate() );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2015-10-12 10:18:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2015-10-20 07:16:41 +0000
@@ -205,7 +205,7 @@
}
@Override
- public List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes )
+ public List<DataElement> getDataElementsByValueTypes( Collection<ValueType> valueTypes )
{
return i18n( i18nService, dataElementStore.getDataElementsByValueTypes( valueTypes ) );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2015-09-15 09:54:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2015-10-20 07:16:41 +0000
@@ -94,7 +94,7 @@
@Override
@SuppressWarnings( "unchecked" )
- public List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes )
+ public List<DataElement> getDataElementsByValueTypes( Collection<ValueType> valueTypes )
{
return getCriteria( Restrictions.in( "valueType", valueTypes ) ).list();
}
=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java 2015-10-19 19:38:17 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java 2015-10-20 07:16:41 +0000
@@ -193,7 +193,7 @@
{
if ( ex.getMessage().contains( "divide error" ) )
{
- return true; //TODO Masking bug in Jexl, fix
+ return true; //TODO division by zero masking
}
return false;
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementValueTypesFilter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementValueTypesFilter.java 2015-09-07 08:51:58 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementValueTypesFilter.java 2015-10-20 07:16:41 +0000
@@ -28,21 +28,21 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Set;
+
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.commons.filter.Filter;
import org.hisp.dhis.dataelement.DataElement;
-import java.util.List;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public class DataElementValueTypesFilter
implements Filter<DataElement>
{
- private List<ValueType> valueTypes;
+ private Set<ValueType> valueTypes;
- public DataElementValueTypesFilter( List<ValueType> valueTypes )
+ public DataElementValueTypesFilter( Set<ValueType> valueTypes )
{
this.valueTypes = valueTypes;
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-09-24 14:38:17 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-10-20 07:16:41 +0000
@@ -466,4 +466,20 @@
{
return value != null && HEX_COLOR_PATTERN.matcher( value ).matches();
}
+
+ public static String getSubstitutionValue( ValueType valueType )
+ {
+ if ( valueType.isNumeric() )
+ {
+ return "1";
+ }
+ else if ( valueType.isDate() )
+ {
+ return "'2000-01-01'";
+ }
+ else
+ {
+ return "A";
+ }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java 2015-09-08 15:03:31 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java 2015-10-20 07:16:41 +0000
@@ -39,12 +39,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
+
+import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
/**
* @author Lars Helge Overland
@@ -60,8 +61,8 @@
@Autowired
private I18nManager i18nManager;
- @RequestMapping( value = "/expression/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
- public void getExpressionDescription( @RequestParam String expression, HttpServletResponse response )
+ @RequestMapping( value = "/expression/description", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE )
+ public void getExpressionDescription( @RequestBody String expression, HttpServletResponse response )
throws IOException
{
I18n i18n = i18nManager.getI18n();
@@ -80,8 +81,8 @@
webMessageService.sendJson( message, response );
}
- @RequestMapping( value = "/filter/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
- public void validateFilter( @RequestParam String expression, HttpServletResponse response )
+ @RequestMapping( value = "/filter/description", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE )
+ public void validateFilter( @RequestBody String expression, HttpServletResponse response )
throws IOException
{
I18n i18n = i18nManager.getI18n();
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-10-19 13:43:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-10-20 07:16:41 +0000
@@ -140,14 +140,18 @@
}
else
{
- $.getJSON('../api/programIndicators/' + type + '/description', {
- expression: expression
- }, function( json ) {
- if( 'OK' == json.status ){
- setInnerHTML(type + '-description', json.description);
- }
- else {
- setInnerHTML(type + '-description', json.message);
+ $.ajax({
+ url: '../api/programIndicators/' + type + '/description',
+ type: 'post',
+ data: expression,
+ contentType: 'text/plain',
+ success: function( json ) {
+ if ('OK' == json.status) {
+ setInnerHTML(type + '-description', json.description);
+ }
+ else {
+ setInnerHTML(type + '-description', json.message);
+ }
}
});
}