← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18259: Maintenance. Impl function for recreating all SQL views in database

 

------------------------------------------------------------
revno: 18259
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-02-13 16:23:56 +0100
message:
  Maintenance. Impl function for recreating all SQL views in database
modified:
  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/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewStore.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/maintenance.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/maintenanceForm.vm


--
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/SqlViewService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2015-02-12 19:37:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2015-02-13 15:23:56 +0000
@@ -47,7 +47,7 @@
     final Pattern VARIABLE_PATTERN = Pattern.compile( VARIABLE_EXPRESSION );
     
     // -------------------------------------------------------------------------
-    // SqlView
+    // CRUD
     // -------------------------------------------------------------------------
 
     int saveSqlView( SqlView sqlView );
@@ -75,13 +75,15 @@
     int getSqlViewCountByName( String name );
     
     // -------------------------------------------------------------------------
-    // SqlView Expanded
+    // SQL view
     // -------------------------------------------------------------------------
 
     boolean viewTableExists( String viewTableName );
 
-    String createViewTable( SqlView sqlViewInstance );
+    String createViewTable( SqlView sqlView );
 
+    void createAllViews();
+    
     void dropViewTable( String viewName );
     
     /**

=== 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-12 19:37:50 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2015-02-13 15:23:56 +0000
@@ -151,9 +151,23 @@
     }
 
     @Override
-    public String createViewTable( SqlView sqlViewInstance )
-    {
-        return sqlViewStore.createViewTable( sqlViewInstance );
+    public String createViewTable( SqlView sqlView )
+    {
+        return sqlViewStore.createViewTable( sqlView );
+    }
+    
+    @Override
+    public void createAllViews()
+    {
+        Collection<SqlView> views = getAllSqlViews();
+        
+        for ( SqlView view : views )
+        {
+            if ( !view.isQuery() )
+            {
+                createViewTable( view );
+            }
+        }
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewStore.java	2015-02-12 09:28:20 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewStore.java	2015-02-13 15:23:56 +0000
@@ -84,13 +84,13 @@
     }
 
     @Override
-    public String createViewTable( SqlView sqlViewInstance )
+    public String createViewTable( SqlView sqlView )
     {
-        String viewName = sqlViewInstance.getViewName();
+        String viewName = sqlView.getViewName();
 
         dropViewTable( viewName );
 
-        final String sql = PREFIX_CREATEVIEW_QUERY + statementBuilder.columnQuote( viewName ) + " AS " + sqlViewInstance.getSqlQuery();
+        final String sql = PREFIX_CREATEVIEW_QUERY + statementBuilder.columnQuote( viewName ) + " AS " + sqlView.getSqlQuery();
 
         log.debug( "Create view SQL: " + sql );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java	2015-01-22 11:43:31 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java	2015-02-13 15:23:56 +0000
@@ -42,6 +42,7 @@
 import org.hisp.dhis.schema.Property;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.sqlview.SqlViewService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -50,6 +51,7 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 
 import javax.servlet.http.HttpServletResponse;
+
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Collection;
@@ -89,6 +91,9 @@
 
     @Autowired
     private RenderService renderService;
+    
+    @Autowired
+    private SqlViewService sqlViewService;
 
     @RequestMapping( value = "/periodPruning", method = { RequestMethod.PUT, RequestMethod.POST } )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
@@ -104,6 +109,13 @@
         maintenanceService.deleteZeroDataValues();
     }
 
+    @RequestMapping( value = "/createSqlViews", method = { RequestMethod.PUT, RequestMethod.POST } )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
+    public void createSqlViews()
+    {
+        sqlViewService.createAllViews();
+    }
+    
     @RequestMapping( value = "/categoryOptionComboUpdate", method = { RequestMethod.PUT, RequestMethod.POST } )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
     public void updateCategoryOptionCombos()

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java	2015-01-23 17:23:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java	2015-02-13 15:23:56 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.datamart.DataMartManager;
 import org.hisp.dhis.maintenance.MaintenanceService;
 import org.hisp.dhis.resourcetable.ResourceTableService;
+import org.hisp.dhis.sqlview.SqlViewService;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
@@ -120,6 +121,13 @@
         this.categoryService = categoryService;
     }
 
+    private SqlViewService sqlViewService;
+
+    public void setSqlViewService( SqlViewService sqlViewService )
+    {
+        this.sqlViewService = sqlViewService;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -173,6 +181,13 @@
         this.removeExpiredInvitations = removeExpiredInvitations;
     }
 
+    private boolean createSqlViews;
+    
+    public void setCreateSqlViews( boolean createSqlViews )
+    {
+        this.createSqlViews = createSqlViews;
+    }
+
     private boolean updateCategoryOptionCombos;
 
     public void setUpdateCategoryOptionCombos( boolean updateCategoryOptionCombos )
@@ -256,6 +271,13 @@
             log.info( "'" + username + "': Removed expired invitations" );
         }
         
+        if ( createSqlViews )
+        {
+            sqlViewService.createAllViews();
+            
+            log.info( "'" + username + "': Created SQL views" );
+        }
+        
         if ( updateCategoryOptionCombos )
         {
             categoryService.updateAllOptionCombos();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java	2015-02-13 15:23:56 +0000
@@ -95,15 +95,15 @@
             return ERROR;
         }
 
-        SqlView sqlViewInstance = sqlViewService.getSqlView( id );
-
-        String viewName = sqlViewInstance.getViewName();
-
-        message = sqlViewService.createViewTable( sqlViewInstance );
+        SqlView sqlView = sqlViewService.getSqlView( id );
+
+        String viewName = sqlView.getViewName();
+
+        message = sqlViewService.createViewTable( sqlView );
 
         if ( message != null && !message.isEmpty() )
         {
-            message = i18n.getString( "failed_to_create_view_table_for" ) + ": " + sqlViewInstance.getName()
+            message = i18n.getString( "failed_to_create_view_table_for" ) + ": " + sqlView.getName()
                 + "<br/><br/>" + i18n.getString( "error_at" ) + ": " + message;
 
             return ERROR;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2015-01-23 17:23:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2015-02-13 15:23:56 +0000
@@ -15,6 +15,7 @@
     <property name="dataMartManager" ref="org.hisp.dhis.datamart.DataMartManager" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+    <property name="sqlViewService" ref="org.hisp.dhis.sqlview.SqlViewService" />
   </bean>
 
   <!-- Cache -->

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2015-02-11 22:32:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2015-02-13 15:23:56 +0000
@@ -126,6 +126,7 @@
 select_the_org_unit_to_eliminate=Select the organisation unit to eliminate
 not_selected=Not selected
 select_the_org_unit_to_keep=Select the organisation unit to keep
+create_sql_views=Create SQL views
 merge=Merge
 reset=Reset
 confirm=Confirm

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/maintenance.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/maintenance.js	2015-01-13 15:01:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/maintenance.js	2015-02-13 15:23:56 +0000
@@ -8,10 +8,11 @@
     var dataSetCompleteness = $( "#dataSetCompleteness" ).is( ":checked" );
     var prunePeriods = $( "#prunePeriods" ).is( ":checked" );
     var removeExpiredInvitations = $( "#removeExpiredInvitations" ).is( ":checked" );
+    var createSqlViews = $( "#createSqlViews" ).is( ":checked" );
     var updateCategoryOptionCombos = $( "#updateCategoryOptionCombos" ).is( ":checked" );
     
-    if ( clearAnalytics || clearDataMart || dataMartIndex || zeroValues || 
-    	dataSetCompleteness || prunePeriods || removeExpiredInvitations || updateCategoryOptionCombos )
+    if ( clearAnalytics || clearDataMart || dataMartIndex || zeroValues || dataSetCompleteness || 
+    	prunePeriods || removeExpiredInvitations || createSqlViews || updateCategoryOptionCombos )
     {
         setHeaderWaitMessage( i18n_performing_maintenance );
         
@@ -22,6 +23,7 @@
             "&dataSetCompleteness=" + dataSetCompleteness +
             "&prunePeriods=" + prunePeriods +
             "&removeExpiredInvitations=" + removeExpiredInvitations +
+            "&createSqlViews=" + createSqlViews +
             "&updateCategoryOptionCombos=" + updateCategoryOptionCombos;
         
 		$.ajax({

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/maintenanceForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/maintenanceForm.vm	2015-01-13 15:01:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/maintenanceForm.vm	2015-02-13 15:23:56 +0000
@@ -42,6 +42,11 @@
 </p>
 
 <p>
+	<input type="checkbox" id="createSqlViews"/>
+	<label for="createSqlViews">$i18n.getString( "create_sql_views" )</label>
+</p>
+
+<p>
     <input type="checkbox" id="updateCategoryOptionCombos"/>
     <label for="updateCategoryOptionCombos">$i18n.getString( "update_category_option_combos" )</label>
 </p>