| | |
| | | import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; |
| | | import it.geosolutions.geoserver.rest.GeoServerRESTReader; |
| | | import it.geosolutions.geoserver.rest.decoder.*; |
| | | import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; |
| | | import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; |
| | | import it.geosolutions.geoserver.rest.encoder.GSLayerGroupEncoder; |
| | | import it.geosolutions.geoserver.rest.encoder.GSLayerGroupEncoder23; |
| | |
| | | updateCurrentRepositoryStatus(connection, currentTargetSchema, |
| | | DataReposVersionManager.VSSTATUS_LINKVIEW); |
| | | |
| | | String currentTargetThemesName = retrieveCurrentThemeName(connection, |
| | | DataReposVersionManager.VSSTATUS_READY); |
| | | if (currentTargetThemesName == null) { |
| | | logger.info("Cannot found themes that status is VSSTATUS_READY[" + |
| | | DataReposVersionManager.VSSTATUS_READY + "]"); |
| | | return; |
| | | } |
| | | |
| | | resetThemesBaseView(connection, ownerName, currentTargetThemesName); |
| | | |
| | | XGeosDataConfigMapping configMapping = getConfigMapping(); |
| | | String[] allView = retrieveTargetStoreAllViewNames(connection); |
| | | TreeSet<String> allViewNames = new TreeSet<String>(); |
| | | if (allView != null) { |
| | | allViewNames.addAll(Arrays.asList(allView)); |
| | | } |
| | | List values = (List) configMapping.getMapping().get("pgOMS"); |
| | | for (Object value : values) { |
| | | XGeosDataConfig xgeosConfig = (XGeosDataConfig) value; |
| | | short tid = xgeosConfig.getFSC(); |
| | | short cid = xgeosConfig.getCOMP(); |
| | | StringBuilder sbTable = new StringBuilder("fsc-"); |
| | | sbTable.append(tid).append("-c-"); |
| | | sbTable.append(cid); |
| | | |
| | | int index = realTableNames.indexOf(sbTable.toString()); |
| | | if (index == -1) { |
| | | logger.debug("pgOMS LayerView Cannot found-" + xgeosConfig.toString()); |
| | | continue; |
| | | } |
| | | |
| | | StringBuilder sbView = new StringBuilder("fsc-"); |
| | | sbView.append(tid).append("-c"); |
| | | sbView.append(cid).append("-l"); |
| | | sbView.append(xgeosConfig.getLEV()).append("-w"); |
| | | sbView.append(xgeosConfig.getWEIGHT()); |
| | | String viewName = sbView.toString(); |
| | | if (allViewNames.contains(viewName)) { |
| | | resetThemesPostgisDataView(connection, ownerName, null, viewName); |
| | | } |
| | | } |
| | | |
| | | updateCurrentThemeStatus(connection, currentTargetThemesName, |
| | | DataReposVersionManager.VSSTATUS_LINKVIEW); |
| | | |
| | | // String[] featureNames = dataStore.getTypeNames(); |
| | | // logger.info("featureNames[] size = " + featureNames.length); |
| | | } catch (IOException e) { |
| | |
| | | } |
| | | } catch (SQLException e) { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private void resetThemesBaseView(Connection connection, String ownerName, String currentThemesName) |
| | | throws SQLException { |
| | | String viewName = "xpwtheme" + FDYNCOLOR_SUFFIX; |
| | | String tableName = currentThemesName + FDYNCOLOR_SUFFIX; |
| | | PrintfFormat pf = new PrintfFormat("CREATE OR REPLACE VIEW \"%s\" AS SELECT * FROM \"%s\""); |
| | | String sql = pf.sprintf(new Object[]{viewName, tableName}); |
| | | Statement stmt = connection.createStatement(); |
| | | try { |
| | | stmt.execute(sql); |
| | | pf = new PrintfFormat(ALTER_VIEWSQL + ownerName); |
| | | sql = pf.sprintf(viewName); |
| | | stmt.execute(sql); |
| | | |
| | | viewName = "xpwtheme" + FOWNER_SUFFIX; |
| | | tableName = currentThemesName + FOWNER_SUFFIX; |
| | | pf = new PrintfFormat("CREATE OR REPLACE VIEW \"%s\" AS SELECT * FROM \"%s\""); |
| | | sql = pf.sprintf(new Object[]{viewName, tableName}); |
| | | |
| | | stmt.execute(sql); |
| | | pf = new PrintfFormat(ALTER_VIEWSQL + ownerName); |
| | | sql = pf.sprintf(viewName); |
| | | stmt.execute(sql); |
| | | } catch (SQLException e) { |
| | | // logger.warn(e.getMessage(), e); |
| | | logger.info(sql == null ? "SQL=NULL" : "SQL=" + sql); |
| | | throw e; |
| | | } finally { |
| | | stmt.close(); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void resetThemesPostgisDataView(Connection connection, String ownerName, |
| | | String currentSchema, String viewName) throws SQLException { |
| | | String themeViewName = viewName + "-oms"; |
| | | // PrintfFormat pf = new PrintfFormat(CREATE_VIEWSQL); |
| | | // String sql = pf.sprintf(new Object[]{viewName, schemaName, tableName}); |
| | | ResultSet rs = null; |
| | | Statement stmt = connection.createStatement(); |
| | | |
| | | try { |
| | | StringBuilder sbSQL = new StringBuilder("CREATE OR REPLACE VIEW \""); |
| | | sbSQL.append(themeViewName).append("\" AS SELECT "); |
| | | |
| | | rs = connection.getMetaData().getColumns(null, currentSchema, viewName, "%"); |
| | | while (rs.next()) { |
| | | String fieldName = rs.getString("COLUMN_NAME"); |
| | | sbSQL.append("t." + fieldName).append(", "); |
| | | } |
| | | sbSQL.append("fc.dyncolor, fo.fowner FROM "); |
| | | if (currentSchema != null) |
| | | sbSQL.append("\"").append(currentSchema).append("\".\"").append(viewName).append("\" AS t,"); |
| | | else |
| | | sbSQL.append("\"").append(viewName).append("\" AS t,"); |
| | | sbSQL.append("xpwtheme").append(FDYNCOLOR_SUFFIX).append(" AS fc,"); |
| | | sbSQL.append("xpwtheme").append(FOWNER_SUFFIX).append(" AS fo WHERE "); |
| | | sbSQL.append("t.tid = fc.tid AND t.oid = fc.oid AND"); |
| | | sbSQL.append("t.tid = fo.tid AND t.oid = fo.oid"); |
| | | |
| | | // sbSQL.delete(sbSQL.length() - 2, sbSQL.length()); |
| | | String sql = sbSQL.toString(); |
| | | stmt.execute(sql); |
| | | sbSQL.delete(0, sbSQL.length()); |
| | | |
| | | PrintfFormat pf = new PrintfFormat(ALTER_VIEWSQL + ownerName); |
| | | sql = pf.sprintf(themeViewName); |
| | | stmt.execute(sql); |
| | | } finally { |
| | | JDBCUtils.close(rs); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | } |
| | | |
| | |
| | | return sbLayers.toString(); |
| | | } |
| | | |
| | | protected String[] getTargetStoreTypeNames(Connection connection) { |
| | | protected String[] retrieveTargetStoreAllViewNames(Connection connection) { |
| | | try { |
| | | final int TABLE_NAME_COL = 3; |
| | | List list = new ArrayList(); |
| | |
| | | HashMap<String, String> defaultStyles = buildDefaultStylesMapping(mapping); |
| | | |
| | | try { |
| | | String[] dsFTypeNames = getTargetStoreTypeNames(connection); |
| | | String[] dsFTypeNames = retrieveTargetStoreAllViewNames(connection); |
| | | |
| | | for (String featureTypeName : dsFTypeNames) { |
| | | FeatureType featureType = null; |