← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18229: Sql view, renamed strange method

 

------------------------------------------------------------
revno: 18229
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-02-11 23:50:44 +0100
message:
  Sql view, renamed strange method
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
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/AddSqlViewAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/UpdateSqlViewAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.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-11 22:32:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java	2015-02-11 22:50:44 +0000
@@ -129,6 +129,16 @@
 
         return map;
     }
+    
+    public SqlView cleanSqlQuery()
+    {
+        sqlQuery = sqlQuery.
+            replaceAll( "\\s*;\\s+", ";" ).
+            replaceAll( ";+", ";" ).
+            replaceAll( "\\s+", " " ).trim();
+        
+        return this;
+    }
 
     // -------------------------------------------------------------------------
     // Getters and setters

=== 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-11 22:32:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2015-02-11 22:50:44 +0000
@@ -67,8 +67,6 @@
     
     Collection<SqlView> getAllSqlViewsNoAcl();
 
-    String makeUpForQueryStatement( String query );
-
     int getSqlViewCountByName( String name );
     
     // -------------------------------------------------------------------------

=== 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-11 22:32:01 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2015-02-11 22:50:44 +0000
@@ -136,12 +136,6 @@
     }
 
     @Override
-    public String makeUpForQueryStatement( String query )
-    {
-        return query.replaceAll( "\\s*;\\s+", ";" ).replaceAll( ";+", ";" ).replaceAll( "\\s+", " " ).trim();
-    }
-
-    @Override
     public int getSqlViewCountByName( String name )
     {
         return sqlViewStore.getCountLikeName( name );

=== 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-11 22:32:01 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java	2015-02-11 22:50:44 +0000
@@ -154,8 +154,8 @@
     {
         SqlView sqlViewA = createSqlView( 'A', SQL1 );
 
-        sqlViewA.setSqlQuery( sqlViewService.makeUpForQueryStatement( sqlViewA.getSqlQuery() ) );
-
+        sqlViewA.cleanSqlQuery();
+        
         int idA = sqlViewService.saveSqlView( sqlViewA );
 
         assertEquals( sqlViewService.getSqlView( "SqlViewA" ).getId(), idA );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/AddSqlViewAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/AddSqlViewAction.java	2015-02-11 22:32:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/AddSqlViewAction.java	2015-02-11 22:50:44 +0000
@@ -95,10 +95,10 @@
 
         sqlView.setName( reduceWhiteSpaces( name ) );
         sqlView.setDescription( reduceWhiteSpaces( description ) );
-        sqlView.setSqlQuery( sqlViewService.makeUpForQueryStatement( sqlquery ) );
+        sqlView.setSqlQuery( sqlquery );
         sqlView.setQuery( query );
 
-        sqlViewService.saveSqlView( sqlView );
+        sqlViewService.saveSqlView( sqlView.cleanSqlQuery() );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/UpdateSqlViewAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/UpdateSqlViewAction.java	2015-02-11 22:32:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/UpdateSqlViewAction.java	2015-02-11 22:50:44 +0000
@@ -93,10 +93,10 @@
         SqlView sqlView = sqlViewService.getSqlView( id );
 
         sqlView.setDescription( description.replaceAll( "\\s+", " " ).trim() );
-        sqlView.setSqlQuery( sqlViewService.makeUpForQueryStatement( sqlquery ) );
+        sqlView.setSqlQuery( sqlquery );
         sqlView.setQuery( query );
 
-        sqlViewService.updateSqlView( sqlView );
+        sqlViewService.updateSqlView( sqlView.cleanSqlQuery() );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java	2015-02-11 22:32:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java	2015-02-11 22:50:44 +0000
@@ -148,11 +148,9 @@
 
         final String ignoredRegex = this.setUpIgnoredRegex();
 
-        sqlquery = sqlViewService.makeUpForQueryStatement( sqlquery );
-
         for ( String s : sqlquery.split( SEMICOLON ) )
         {
-            String tmp = new String( s.toLowerCase() );
+            String tmp = new String( s.toLowerCase() ).trim();
 
             if ( !s.matches( REGEX_SELECT_QUERY ) || tmp.contains( INTO ) )
             {