This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository echobase. See http://git.codelutin.com/echobase.git commit c22d33f3490f37d69582150563fed60747996af5 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Jan 14 15:34:19 2015 +0100 refs-50 #6457: Proposer de rafraichir les données spatiales sur la page de visualisation des données spatiales --- .../services/service/UserDbPersistenceService.java | 33 +++++++++++++ .../service/spatial/SpatialDataService.java | 57 +++++++++++++--------- .../ui/actions/spatial/RefreshSpatialViews.java | 6 ++- .../ifremer/echobase/ui/actions/spatial/Show.java | 19 ++++++++ .../src/main/webapp/WEB-INF/jsp/spatial/show.jsp | 36 +++++++++----- 5 files changed, 115 insertions(+), 36 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java index 6fc2c2f..8498c6c 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java @@ -82,6 +82,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.Collection; import java.util.Date; import java.util.List; @@ -862,4 +866,33 @@ public class UserDbPersistenceService extends EchoBaseServiceSupport { "Could not find class from id: " + id, e); } } + + public long countTable(String tableName) { + + CountTableRows query = new CountTableRows(tableName); + Long count = findSingleResult(query); + return count; + + } + + private static class CountTableRows extends TopiaSqlQuery<Long> { + + public final String tableName; + + private CountTableRows(String tableName) { + this.tableName = tableName; + } + + @Override + public PreparedStatement prepareQuery(Connection connection) throws SQLException { + String hql = "SELECT count(*) FROM "+tableName; + PreparedStatement result = connection.prepareStatement(hql); + return result; + } + + @Override + public Long prepareResult(ResultSet set) throws SQLException { + return set.getLong(1); + } + } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/SpatialDataService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/SpatialDataService.java index 676df49..13c2f8d 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/SpatialDataService.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/SpatialDataService.java @@ -71,53 +71,66 @@ public class SpatialDataService extends EchoBaseServiceSupport { } /** + * @return {@code true} if there is some postgis data to compute. + * @since 2.8 + */ + public boolean isSpatialDataToComputeExist() { + + boolean result = false; + if (persistenceContext.isSpatialStructureFound()) { + + long nbCellTemp = persistenceService.countTable("echobase_cell_spatial_temp"); + long nbOperationTemp = persistenceService.countTable("echobase_operation_spatial_temp"); + result = nbCellTemp + nbOperationTemp > 0; + } + + return result; + + } + + /** * To update the {@code echobase_cell_spatial} table from the filled - * table {@code echobase_cell_sptaial_temp}. + * table {@code echobase_cell_spatial_temp}. + * + * To update the {@code echobase_operation_spatial} table from the filled + * table {@code echobase_operation_spatial_temp}. + * + * To rebuild the gis views. * - * @since 2.2 + * @since 2.8 */ - public void updatePostgisTable() { + public void updatePostgisData() { if (persistenceContext.isSpatialStructureFound()) { // try the update only for postgresql try { + long time = TimeLog.getTime(); if (log.isInfoEnabled()) { log.info("Will try to compute operation spatial data from temp table..."); } persistenceService.executeSQL("SELECT echobase_fill_operation_spatial_table();"); + TILE_LOG.log(time, "updatePostgisData::echobase_fill_operation_spatial_table"); + + time = TimeLog.getTime(); if (log.isInfoEnabled()) { log.info("Will try to compute cell spatial data from temp table..."); } persistenceService.executeSQL("SELECT echobase_fill_cell_spatial_table();"); - persistenceService.commit(); - } catch (Exception e) { - throw new EchoBaseTechnicalException("Could not compute spatial data", e); - } - } - } + TILE_LOG.log(time, "updatePostgisData::echobase_fill_cell_spatial_table"); - - /** - * To update all posgis materialized views.. - * - * @since 2.6 - */ - public void updatePostgisViews() { - - if (persistenceContext.isSpatialStructureFound()) { - - // try the update only for postgresql - try { + time = TimeLog.getTime(); if (log.isInfoEnabled()) { log.info("Will try to refresh all spatial views..."); } persistenceService.executeSQL("SELECT echobase_refresh_views();"); + TILE_LOG.log(time, "updatePostgisData::echobase_refresh_views"); persistenceService.commit(); } catch (Exception e) { - throw new EchoBaseTechnicalException("Could not refresh spatial views", e); + throw new EchoBaseTechnicalException("Could not compute spatial data", e); } } + } protected void executeSqlScript(String scriptPath) { diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/RefreshSpatialViews.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/RefreshSpatialViews.java index debd6eb..8ec04d5 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/RefreshSpatialViews.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/RefreshSpatialViews.java @@ -42,7 +42,11 @@ public class RefreshSpatialViews extends EchoBaseActionSupport { @Override public String execute() throws Exception { - spatialDataService.updatePostgisViews(); + if (spatialDataService.isSpatialDataToComputeExist()) { + + spatialDataService.updatePostgisData(); + + } return SUCCESS; } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/Show.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/Show.java index e396e76..bb71d80 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/Show.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/spatial/Show.java @@ -24,6 +24,7 @@ package fr.ifremer.echobase.ui.actions.spatial; import fr.ifremer.echobase.entities.EchoBaseUserPersistenceContext; import fr.ifremer.echobase.persistence.JdbcConfiguration; import fr.ifremer.echobase.services.service.spatial.GisService; +import fr.ifremer.echobase.services.service.spatial.SpatialDataService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,6 +47,9 @@ public class Show extends EchoBaseActionSupport { protected transient GisService gisService; @Inject + protected transient SpatialDataService spatialDataService; + + @Inject protected transient EchoBaseUserPersistenceContext userPersistenceContext; /** @@ -64,6 +68,11 @@ public class Show extends EchoBaseActionSupport { protected boolean gisSupport; /** + * Is there some spatial data to compute + */ + protected boolean spatialDataToComputeExists; + + /** * Url to access to gis. */ protected String lizmapUrl; @@ -80,6 +89,10 @@ public class Show extends EchoBaseActionSupport { return spatialSupport; } + public boolean isSpatialDataToComputeExists() { + return spatialDataToComputeExists; + } + public boolean isGisSupport() { return gisSupport; } @@ -103,6 +116,12 @@ public class Show extends EchoBaseActionSupport { log.info("Spatial structure found."); } + spatialDataToComputeExists = spatialDataService.isSpatialDataToComputeExist(); + + if (log.isInfoEnabled()) { + log.info("Is there some spatial data to compute? "+ spatialDataToComputeExists); + } + gisSupport = getEchoBaseApplicationContext().isGisSupport(); if (gisSupport) { diff --git a/echobase-ui/src/main/webapp/WEB-INF/jsp/spatial/show.jsp b/echobase-ui/src/main/webapp/WEB-INF/jsp/spatial/show.jsp index af2c3da..3e5bd0e 100644 --- a/echobase-ui/src/main/webapp/WEB-INF/jsp/spatial/show.jsp +++ b/echobase-ui/src/main/webapp/WEB-INF/jsp/spatial/show.jsp @@ -32,20 +32,30 @@ <s:if test="spatialStructureFound"> <%-- db has spatial structures --%> - <s:form namespace="/spatial"> - <div class="toolbar"> - <ul class="toolbar floatRight"> - <li> - <s:submit action='refreshSpatialViews' key="echobase.action.reloadSpatialData"/> - </li> - </ul> - </div> - </s:form> + + <s:if test="spatialDataToComputeExists"> + + <%-- there is some postigs data to compute --%> + + <s:form namespace="/spatial"> + <div class="toolbar"> + <ul class="toolbar floatRight"> + <li> + <s:submit action='refreshSpatialViews' key="echobase.action.reloadSpatialData"/> + </li> + </ul> + </div> + </s:form> + + </s:if> <s:if test="gisSupport"> + <p> + TODO Show voyage links to lizmap + </p> <%-- Application has gis support --%> - <iframe id="spatialViewContent" src="${lizmapUrl}"></iframe> + <%--<iframe id="spatialViewContent" src="${lizmapUrl}"></iframe>--%> </s:if> <s:else> @@ -53,9 +63,9 @@ <%-- Application has no gis support --%> <p class="fontsize11"> <s:text name="echobase.message.application.no.gis.support"/> - <s:a href="%{getDocumentation('install.html', 'Visualisation_des_donnes_spatialises')}" target='#doc'> - <s:text name="echobase.message.gis.install"/> - </s:a> + <s:a href="%{getDocumentation('install.html', 'Visualisation_des_donnes_spatialises')}" target='#doc'> + <s:text name="echobase.message.gis.install"/> + </s:a> </p> </s:else> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.