dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35774
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18308: SQL view, fix to validation related to line breaks
------------------------------------------------------------
revno: 18308
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-02-18 13:16:29 +0100
message:
SQL view, fix to validation related to line breaks
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java
dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.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/sqlview/SqlView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2015-02-17 23:04:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2015-02-18 12:16:29 +0000
@@ -56,7 +56,6 @@
extends BaseIdentifiableObject
{
public static final String PREFIX_VIEWNAME = "_view";
- public static final String REGEX_SELECT_QUERY = "^(?i)\\s*select\\s{1,}.+$";
public static final Set<String> PROTECTED_TABLES = Sets.newHashSet( "users", "userinfo",
"trackedentityinstance", "trackedentityattribute", "trackedentityattributevalue", "relationship" );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java 2015-02-13 15:23:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java 2015-02-18 12:16:29 +0000
@@ -43,8 +43,12 @@
public interface SqlViewService
{
final String ID = SqlViewService.class.getName();
+
final String VARIABLE_EXPRESSION = "\\$\\{(\\w+)\\}";
- final Pattern VARIABLE_PATTERN = Pattern.compile( VARIABLE_EXPRESSION );
+ final String SELECT_EXPRESSION = "^(?i)\\s*select\\s+.+";
+
+ final Pattern VARIABLE_PATTERN = Pattern.compile( VARIABLE_EXPRESSION, Pattern.DOTALL );
+ final Pattern SELECT_PATTERN = Pattern.compile( SELECT_EXPRESSION, Pattern.DOTALL );
// -------------------------------------------------------------------------
// CRUD
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2015-02-13 15:23:56 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2015-02-18 12:16:29 +0000
@@ -246,7 +246,7 @@
final Set<String> sqlVars = getVariables( sqlView.getSqlQuery() );
final String sql = sqlView.getSqlQuery();
- if ( !sqlView.getSqlQuery().matches( SqlView.REGEX_SELECT_QUERY ) )
+ if ( !SELECT_PATTERN.matcher( sqlView.getSqlQuery() ).matches() )
{
violation = "SQL query must be a select query";
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java 2015-02-17 23:04:46 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java 2015-02-18 12:16:29 +0000
@@ -283,4 +283,12 @@
sqlViewService.validateSqlView( sqlView, null, null );
}
+
+ @Test
+ public void testValidateSuccessC()
+ {
+ SqlView sqlView = new SqlView( "Name", "SELECT a.dataelementid as dsd_id,a.name as dsd_name,b.dataelementid as ta_id,b.ta_name FROM dataelement a", false );
+
+ sqlViewService.validateSqlView( sqlView, null, null );
+ }
}