From bd96022efba2cf71fe844fe5d169adf448994a36 Mon Sep 17 00:00:00 2001 From: AWIPS User Date: Tue, 21 Jul 2015 09:46:37 -0600 Subject: [PATCH] rollback GFE text product Configurator or else things break. this solves the PSQLException: ERROR: column 'region' does not exist / DataAccessLayerException: Unable to execute SQL update statement Former-commit-id: 760ff2eb5332903077f8239325e508316b9fbc25 [formerly 859477ae7ff01e4424098477d4cc69158bc55101] [formerly 7a31213289da488e8abe962b52d49374ff0f3675 [formerly 5cc5a3eb819f0dbfe53bf837c064c15c4e5894e9]] Former-commit-id: 7a31213289da488e8abe962b52d49374ff0f3675 Former-commit-id: 41123feae3fb48cd0dd9ce405c9868f8de9616e6 --- .../plugin/gfe/textproducts/Configurator.java | 122 ++++-------------- 1 file changed, 23 insertions(+), 99 deletions(-) diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/textproducts/Configurator.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/textproducts/Configurator.java index e349746416..253143435d 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/textproducts/Configurator.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/textproducts/Configurator.java @@ -21,7 +21,7 @@ package com.raytheon.edex.plugin.gfe.textproducts; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,14 +32,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.utility.ProtectedFiles; -import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil; -import com.raytheon.uf.common.dataquery.db.QueryResult; -import com.raytheon.uf.common.dataquery.db.QueryResultRow; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.python.PyUtil; import com.raytheon.uf.common.python.PythonScript; @@ -49,7 +45,6 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.util.FileUtil; import com.raytheon.uf.edex.database.cluster.ClusterLockUtils; import com.raytheon.uf.edex.database.cluster.ClusterTask; -import com.raytheon.uf.edex.database.tasks.SqlQueryTask; /** * Generate and configure text products when needed. @@ -64,13 +59,11 @@ import com.raytheon.uf.edex.database.tasks.SqlQueryTask; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Jul 7, 2008 1222 jelkins Initial creation - * Jul 24, 2012 #944 dgilling Fix text product template generation + * Jul 7, 2008 1222 jelkins Initial creation + * Jul 24,2012 #944 dgilling Fix text product template generation * to create textProducts and textUtilities. - * Sep 07, 2012 #1150 dgilling Fix isConfigured to check for textProducts + * Sep 07,2012 #1150 dgilling Fix isConfigured to check for textProducts * and textUtilities dirs. - * Oct 20, 2014 #3685 randerso Added code to generate SiteCFG.py from GIS database - * Cleaned up how protected file updates are returned * * * @@ -82,8 +75,6 @@ public class Configurator { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(Configurator.class); - private static final String CWA_QUERY = "select wfo, region, fullstaid, citystate, city, state from mapdata.cwa order by wfo;"; - private static final String CONFIG_TEXT_PRODUCTS_TASK = "GfeConfigureTextProducts"; private String siteID; @@ -192,79 +183,26 @@ public class Configurator { */ @SuppressWarnings("unchecked") public void execute() { - if (isConfigured()) { - statusHandler.info("All text products are up to date"); - return; - } - IPathManager pathMgr = PathManagerFactory.getPathManager(); - LocalizationContext context = pathMgr.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED); - context.setContextName(siteID); - - // regenerate siteCFG.py - LocalizationFile lf = null; - try { - lf = pathMgr.getLocalizationFile(context, - FileUtil.join("python", "gfe", "SiteCFG.py")); - - SqlQueryTask task = new SqlQueryTask(CWA_QUERY, "maps"); - QueryResult results = task.execute(); - try (PrintWriter out = new PrintWriter(lf.openOutputStream())) { - out.println("##"); - out.println("# Contains information about products, regions, etc. for each site"); - out.println("# in the country."); - out.println("# region= two-letter regional identifier, mainly used for installation of"); - out.println("# text product templates"); - out.println("SiteInfo= {"); - for (QueryResultRow row : results.getRows()) { - String wfo = (String) row.getColumn(0); - String region = (String) row.getColumn(1); - String fullStationID = (String) row.getColumn(2); - String wfoCityState = (String) row.getColumn(3); - String wfoCity = (String) row.getColumn(4); - String state = (String) row.getColumn(5); - - out.println(formatEntry(wfo, region, fullStationID, - wfoCityState, wfoCity, state)); - - // Add in AFC's dual domain sites - if (wfo.equals("AFC")) { - out.println(formatEntry("AER", region, fullStationID, - wfoCityState, wfoCity, state)); - out.println(formatEntry("ALU", region, fullStationID, - wfoCityState, wfoCity, state)); - } - } - - // Add in the national centers since they - // aren't in the shape file - out.println(formatEntry("NH1", "NC", "KNHC", - "National Hurricane Center Miami FL", "Miami", "")); - out.println(formatEntry("NH2", "NC", "KNHC", - "National Hurricane Center Miami FL", "Miami", "")); - out.println(formatEntry("ONA", "NC", "KWBC", - "Ocean Prediction Center Washington DC", - "Washington DC", "")); - out.println(formatEntry("ONP", "NC", "KWBC", - "Ocean Prediction Center Washington DC", - "Washington DC", "")); - - out.println("}"); - } // out is closed here - - lf.save(); - } catch (Exception e) { - statusHandler.error(e.getLocalizedMessage(), e); - } - PythonScript python = null; + List preEvals = new ArrayList(); + IPathManager pathMgr = PathManagerFactory.getPathManager(); LocalizationContext edexCx = pathMgr.getContext( LocalizationType.EDEX_STATIC, LocalizationLevel.BASE); + LocalizationContext commonCx = pathMgr.getContext( + LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); String filePath = pathMgr.getFile(edexCx, "textproducts" + File.separator + "Generator.py").getPath(); - String commonPython = GfePyIncludeUtil.getCommonPythonIncludePath(); + String textProductPath = pathMgr.getFile(edexCx, + "textProducts.Generator").getPath(); + String jutilPath = pathMgr.getFile(commonCx, "python").getPath(); + + // Add some getters we need "in the script" that we want hidden + preEvals.add("from JUtil import pylistToJavaStringList"); + preEvals.add("from textproducts.Generator import Generator"); + preEvals.add("generator = Generator()"); + preEvals.add("def getProtectedData():\n return pylistToJavaStringList(generator.getProtectedFiles())"); Map argList = new HashMap(); argList.put("siteId", siteID); @@ -272,18 +210,20 @@ public class Configurator { try { python = new PythonScript(filePath, PyUtil.buildJepIncludePath( - pythonDirectory, commonPython), this.getClass() - .getClassLoader()); + pythonDirectory, textProductPath, jutilPath), this + .getClass().getClassLoader(), preEvals); // Open the Python interpreter using the designated script. - protectedFilesList = (List) python.execute("runFromJava", - argList); + python.execute("generator.create", argList); + protectedFilesList = (List) python.execute( + "getProtectedData", null); updateProtectedFile(); updateLastRuntime(); } catch (JepException e) { statusHandler.handle(Priority.PROBLEM, "Error Configuring Text Products", e); + e.printStackTrace(); } finally { if (python != null) { python.dispose(); @@ -291,22 +231,6 @@ public class Configurator { } } - private String formatEntry(String wfo, String region, String fullStationID, - String wfoCityState, String wfoCity, String state) { - StringBuilder sb = new StringBuilder(); - sb.append(" '").append(wfo).append("': {\n"); - sb.append(" 'region': '").append(region).append("',\n"); - sb.append(" 'fullStationID': '").append(fullStationID) - .append("',\n"); - sb.append(" 'wfoCityState': '").append(wfoCityState) - .append("',\n"); - sb.append(" 'wfoCity': '").append(wfoCity).append("',\n"); - sb.append(" 'state': '").append(state).append("',\n"); - sb.append(" },"); - - return sb.toString(); - } - /** * Update the protected files. */