Dennis Kao
2013-12-05 d274e4c6703c57aa0f48b39d6a2316c1aed9e737
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeoserverIntegrateConfigJob.java
@@ -10,7 +10,6 @@
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;
@@ -207,6 +206,51 @@
            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) {
@@ -334,6 +378,79 @@
            }
        } 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);
        }
    }
@@ -608,7 +725,7 @@
        return sbLayers.toString();
    }
    protected String[] getTargetStoreTypeNames(Connection connection) {
    protected String[] retrieveTargetStoreAllViewNames(Connection connection) {
        try {
            final int TABLE_NAME_COL = 3;
            List list = new ArrayList();
@@ -652,7 +769,7 @@
            HashMap<String, String> defaultStyles = buildDefaultStylesMapping(mapping);
            try {
                String[] dsFTypeNames =  getTargetStoreTypeNames(connection);
                String[] dsFTypeNames =  retrieveTargetStoreAllViewNames(connection);
                for (String featureTypeName : dsFTypeNames) {
                    FeatureType featureType = null;
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/GeneralDgnConvertPostGISJobContext.java
@@ -287,14 +287,12 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(textElement.getColorIndex()),
                    colorTable.getColorCode(textElement.getColorIndex()),
                    textElement.getFontIndex(),
                    textElement.getJustification(),
                    textElement.getTextHeight(),
                    textElement.getTextWidth(),
                    angle,
                    content,
                    -1
                    content
                }, null);
            } else {
                logger.info("geometry is null." + element.toString());
@@ -320,14 +318,12 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(textNodeElement.getColorIndex()),
                    colorTable.getColorCode(textNodeElement.getColorIndex()),
                    textNodeElement.getFontIndex(),
                    textNodeElement.getJustification(),
                    textNodeElement.getTextNodeHeight(),
                    textNodeElement.getTextNodeLength(),
                    angle,
                    sb.toString(),
                    -1
                    sb.toString()
                }, null);
            } else {
                logger.info("geometry is null." + element.toString());
@@ -341,10 +337,8 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(shapeElement.getColorIndex()),
                    colorTable.getColorCode(shapeElement.getColorIndex()),
                    shapeElement.getWeight(),
                    shapeElement.getLineStyle(),
                    -1
                    shapeElement.getLineStyle()
                }, null);
            } else {
                logger.info("geometry is null." + element.toString());
@@ -358,10 +352,8 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(linestring.getColorIndex()),
                    colorTable.getColorCode(linestring.getColorIndex()),
                    linestring.getWeight(),
                    linestring.getLineStyle(),
                    -1
                    linestring.getLineStyle()
                }, null);
            }
            return null;
@@ -373,10 +365,8 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(line.getColorIndex()),
                    colorTable.getColorCode(line.getColorIndex()),
                    line.getWeight(),
                    line.getLineStyle(),
                    -1
                    line.getLineStyle()
                }, null);
            }
            return null;
@@ -393,10 +383,8 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(arcElement.getColorIndex()),
                    colorTable.getColorCode(arcElement.getColorIndex()),
                    arcElement.getWeight(),
                    arcElement.getLineStyle(),
                    -1
                    arcElement.getLineStyle()
                }, null);
            }
            return null;
@@ -408,10 +396,8 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(arcElement.getColorIndex()),
                    colorTable.getColorCode(arcElement.getColorIndex()),
                    arcElement.getWeight(),
                    arcElement.getLineStyle(),
                    -1
                    arcElement.getLineStyle()
                }, null);
            }
            return null;
@@ -423,10 +409,8 @@
                return SimpleFeatureBuilder.build(featureType, new Object[]{
                    geom,
                    colorTable.getColorCode(complexChainElement.getColorIndex()),
                    colorTable.getColorCode(complexChainElement.getColorIndex()),
                    complexChainElement.getWeight(),
                    complexChainElement.getLineStyle(),
                    -1
                    complexChainElement.getLineStyle()
                }, null);
            }
            return null;