From 958050610d80aa7f6f121c1ca9520d28337d9528 Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Mon, 20 Jul 2015 15:36:52 -0500 Subject: [PATCH] Omaha #4575 vardict now HashMap intead of String Change-Id: Icd6042a1d9b08d8a33afd41c65a530104bf01c8c Former-commit-id: bffc43fe836827b8cd871f037f0ede093b69a88f --- .../gfe/userPython/utilities/SmartScript.py | 5 +-- .../raytheon/viz/gfe/BaseGfePyController.java | 23 +++---------- .../viz/gfe/procedures/ProcedureRequest.java | 10 +++--- .../gfe/procedures/ProcedureSelectionDlg.java | 5 +-- .../viz/gfe/procedures/ProcedureUtil.java | 7 ++-- .../raytheon/viz/gfe/smarttool/SmartUtil.java | 15 +++++---- .../com/raytheon/viz/gfe/smarttool/Tool.java | 33 ++++++++++--------- .../smarttool/script/SmartToolRequest.java | 12 ++++--- .../script/SmartToolSelectionDlg.java | 11 ++++--- 9 files changed, 58 insertions(+), 63 deletions(-) diff --git a/cave/com.raytheon.viz.gfe/localization/gfe/userPython/utilities/SmartScript.py b/cave/com.raytheon.viz.gfe/localization/gfe/userPython/utilities/SmartScript.py index feb4dca879..f600bbe3f6 100644 --- a/cave/com.raytheon.viz.gfe/localization/gfe/userPython/utilities/SmartScript.py +++ b/cave/com.raytheon.viz.gfe/localization/gfe/userPython/utilities/SmartScript.py @@ -66,6 +66,7 @@ # Jan 13, 2015 3955 randerso Added optional parameter to availableParms to specify desired databases. # Fixed createGrid to accept a DatabaseID for model # Apr 23, 2015 4259 njensen Updated for new JEP API +# Jul 17, 2015 4575 njensen callSmartTool() and callProcedure() send HashMap for varDict ######################################################################## import types, string, time, sys from math import * @@ -1010,7 +1011,7 @@ class SmartScript(BaseTool.BaseTool): else: emptyEditAreaFlag = False if varDict is not None: - varDict = str(varDict) + varDict = JUtil.pyValToJavaObj(varDict) parm = self.getParm(self.__mutableID, elementName, "SFC") if timeRange is None: @@ -1044,7 +1045,7 @@ class SmartScript(BaseTool.BaseTool): from com.raytheon.viz.gfe.procedures import ProcedureUtil if varDict is not None: - varDict = str(varDict) + varDict = JUtil.pyValToJavaObj(varDict) result = ProcedureUtil.callFromSmartScript(self.__dataMgr, name, editArea, timeRange, varDict) diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java index ce3e7a24d1..249f290480 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/BaseGfePyController.java @@ -52,6 +52,7 @@ import com.raytheon.viz.gfe.smartscript.FieldDefinition; * calls from python copying/casting to correct types * Feb 05, 2015 4089 njensen Replaced previous hardening with ensureResultType() * Apr 23, 2015 4259 njensen Updated for new JEP API + * Jul 17, 2015 4575 njensen Changed varDict from String to Map * * * @@ -124,11 +125,13 @@ public abstract class BaseGfePyController extends PythonScriptController { * a string representation of a python dictionary * @throws JepException */ - public void setVarDict(String varDict) throws JepException { + public void setVarDict(Map varDict) throws JepException { if (varDict == null) { jep.eval("varDict = None"); } else { - jep.eval("varDict = " + varDict); + jep.set("varDict", varDict); + jep.eval("import JUtil"); + jep.eval("varDict = JUtil.javaObjToPyVal(varDict)"); } } @@ -157,22 +160,6 @@ public abstract class BaseGfePyController extends PythonScriptController { return fieldDefs; } - public String transformVarDict(Map map) { - String varDict = null; - try { - jep.eval("import JUtil"); - jep.set("varDictMap", map); - jep.eval("temp = JUtil.javaMapToPyDict(varDictMap)"); - varDict = (String) jep.getValue("temp"); - jep.eval("varDictMap = None"); - jep.eval("temp = None"); - } catch (JepException e) { - statusHandler.handle(Priority.PROBLEM, - "Exception while transforming varDict", e); - } - return varDict; - } - /** * Runs the python garbage collector. This should be run at the end of a * procedure or tool in case the custom python used tk. If the python used diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureRequest.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureRequest.java index 38ffa8adbb..b30869a06a 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureRequest.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureRequest.java @@ -19,6 +19,7 @@ **/ package com.raytheon.viz.gfe.procedures; +import java.util.Map; import java.util.concurrent.Semaphore; import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData; @@ -34,7 +35,8 @@ import com.raytheon.viz.gfe.smarttool.PreviewInfo; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Oct 8, 2009 njensen Initial creation + * Oct 08, 2009 njensen Initial creation + * Jul 17, 2015 4575 njensen Changed varDict from String to Map * * * @@ -50,7 +52,7 @@ public class ProcedureRequest extends QueueJobRequest { private TimeRange timeRange; - private String varDict; + private Map varDict; private PreviewInfo preview; @@ -93,11 +95,11 @@ public class ProcedureRequest extends QueueJobRequest { this.timeRange = timeRange; } - public String getVarDict() { + public Map getVarDict() { return varDict; } - public void setVarDict(String varDict) { + public void setVarDict(Map varDict) { this.varDict = varDict; } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureSelectionDlg.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureSelectionDlg.java index 415b56bd35..9918b80c8a 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureSelectionDlg.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureSelectionDlg.java @@ -20,6 +20,7 @@ package com.raytheon.viz.gfe.procedures; import java.util.List; +import java.util.Map; import org.eclipse.swt.widgets.Shell; @@ -38,6 +39,7 @@ import com.raytheon.viz.gfe.ui.runtimeui.SelectionDlg; * ------------ ---------- ----------- -------------------------- * Feb 09, 2010 njensen Initial creation * Dec 09, 2013 #2367 dgilling Use new ProcedureJobPool. + * Jul 17, 2015 4575 njensen Changed varDict from String to Map * * * @@ -64,8 +66,7 @@ public class ProcedureSelectionDlg extends SelectionDlg { ProcedureRequest req = ProcedureUtil.buildProcedureRequest(name, dataMgr); if (req != null) { - String varDict = dataMgr.getProcedureInterface() - .transformVarDict(getValues()); + Map varDict = getValues(); req.setVarDict(varDict); req.setPreview(pi); dataMgr.getProcedureJobPool().schedule(req); diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureUtil.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureUtil.java index 8ace2dd5cd..176e6d0eac 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureUtil.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/procedures/ProcedureUtil.java @@ -47,6 +47,7 @@ import com.raytheon.viz.gfe.smarttool.PreviewInfo; * Feb 09, 2010 njensen Initial creation * Apr 26, 2012 14748 ryu Use edit area and time range from preview info * Dec 09, 2013 #2367 dgilling Use new ProcedureJobPool. + * Jul 17, 2015 4575 njensen Changed varDict from String to Map * * * @@ -79,7 +80,7 @@ public class ProcedureUtil { public static Object callFromSmartScript(final DataManager dm, final String procName, ReferenceData editArea, TimeRange timeRange, - String varDict) { + Map varDict) { PreviewInfo pi = dm.getEditActionProcessor().prepareExecute( "Procedure", procName, editArea, timeRange, false); @@ -109,9 +110,7 @@ public class ProcedureUtil { Map resultMap = sd .getVarDictResult(); if (resultMap != null) { - String userVarDict = dm.getProcedureInterface() - .transformVarDict(resultMap); - req.setVarDict(userVarDict); + req.setVarDict(resultMap); } } else { req.setVarDict(null); diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/SmartUtil.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/SmartUtil.java index 38f3b237b0..422a36f0bf 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/SmartUtil.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/SmartUtil.java @@ -19,6 +19,7 @@ **/ package com.raytheon.viz.gfe.smarttool; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -53,6 +54,7 @@ import com.raytheon.viz.gfe.ui.runtimeui.SelectionDlg; * Jun 25, 2013 16065 ryu Passing outerLevel to smart tool job. * Dec 10, 2013 2367 dgilling Use new SmartToolJobPool. * Jun 05, 2015 4259 njensen Removed LD_PRELOAD check + * Jul 17, 2015 4575 njensen Changed varDict from String to Map * * * @@ -122,9 +124,9 @@ public class SmartUtil { public static Object callFromSmartScript(final DataManager dm, final String toolName, final String elementName, - ReferenceData editArea, TimeRange timeRange, String varDict, - boolean emptyEditAreaFlag, List passErrors, - String missingDataMode, Parm parm) { + ReferenceData editArea, TimeRange timeRange, + Map varDict, boolean emptyEditAreaFlag, + List passErrors, String missingDataMode, Parm parm) { EditAction editAction = new EditAction(toolName, elementName, timeRange, editArea, emptyEditAreaFlag, MissingDataMode.valueFrom(missingDataMode)); @@ -161,14 +163,13 @@ public class SmartUtil { Map resultMap = sd .getVarDictResult(); if (resultMap != null) { - String userVarDict = dm.getSmartToolInterface() - .transformVarDict(resultMap); - req.setVarDict(userVarDict); + req.setVarDict(resultMap); } } else { // set it to something so we don't trigger the null // == user cancelled below - req.setVarDict("{}"); + req.setVarDict(Collections + . emptyMap()); } } catch (JepException e) { statusHandler.handle(Priority.PROBLEM, diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/Tool.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/Tool.java index bf2c07e451..4f0f6d5b07 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/Tool.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/Tool.java @@ -62,7 +62,7 @@ import com.raytheon.viz.gfe.smarttool.script.SmartToolController; /** * Ported from Tool.py - * + * *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
@@ -72,9 +72,10 @@ import com.raytheon.viz.gfe.smarttool.script.SmartToolController;
  * 02/14/2013              mnash       Change QueryScript to use new Python concurrency
  * 02/20/2013        #1597 randerso    Added logging to support GFE Performance metrics
  * 04/10/2013    16028     ryu         Check for null seTime in execute()
+ * Jul 17, 2015  4575      njensen     Changed varDict from String to Map
  *
  * 
- * + * * @author njensen * @version 1.0 */ @@ -110,7 +111,7 @@ public class Tool { /** * Constructor - * + * * @param aParmMgr * the parm manager * @param aToolName @@ -143,7 +144,7 @@ public class Tool { /** * Returns the objects that should be passed to the smart tool in python - * + * * @param args * the names of the arguments * @param gridTimeRange @@ -226,7 +227,7 @@ public class Tool { /** * Returns the attribute for a particular parm's name - * + * * @param arg * the name of the parm * @param attrStr @@ -261,7 +262,7 @@ public class Tool { /** * Returns the grid data for the specified parameters - * + * * @param arg * the name of the parm * @param mode @@ -310,7 +311,7 @@ public class Tool { /** * Returns the grid history corresponding to the parm name and time range - * + * * @param arg * the name of the parm * @param gridTimeRange @@ -350,7 +351,7 @@ public class Tool { /** * Returns the grid info corresponding to the parm name and time range - * + * * @param arg * the name of the parm * @param gridTimeRange @@ -384,7 +385,7 @@ public class Tool { /** * Executes a smart tool - * + * * @param toolName * the name of the tool * @param inputParm @@ -397,9 +398,9 @@ public class Tool { * @throws SmartToolException */ public void execute(String toolName, Parm inputParm, - final ReferenceData editArea, TimeRange timeRange, String varDict, - MissingDataMode missingDataMode, IProgressMonitor monitor) - throws SmartToolException { + final ReferenceData editArea, TimeRange timeRange, + Map varDict, MissingDataMode missingDataMode, + IProgressMonitor monitor) throws SmartToolException { ITimer timer = TimeUtil.getTimer(); timer.start(); @@ -491,8 +492,8 @@ public class Tool { final Date timeInfluence; Date seTime = DataManagerUIFactory.getCurrentInstance() .getSpatialDisplayManager().getSpatialEditorTime(); - if (seTime != null && - grids.length == 1 && grid.getGridTime().contains(seTime)) { + if (seTime != null && grids.length == 1 + && grid.getGridTime().contains(seTime)) { timeInfluence = seTime; } else { timeInfluence = grid.getGridTime().getStart(); @@ -581,7 +582,7 @@ public class Tool { /** * Executes the numeric smart tool - * + * * @param parmToEdit * the parm to edit * @param first @@ -653,7 +654,7 @@ public class Tool { /** * Cleans up a smart tool execution or failure and displays any missing data * message - * + * * @param parmToEdit * the parm to edit * @param save diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolRequest.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolRequest.java index 4f48fb3e1e..0146842db2 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolRequest.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolRequest.java @@ -19,6 +19,7 @@ **/ package com.raytheon.viz.gfe.smarttool.script; +import java.util.Map; import java.util.concurrent.Semaphore; import com.raytheon.uf.viz.core.jobs.QueueJobRequest; @@ -27,7 +28,7 @@ import com.raytheon.viz.gfe.smarttool.PreviewInfo; /** * Request to run a smart tool off the UI thread - * + * *
  *
  * SOFTWARE HISTORY
@@ -35,9 +36,10 @@ import com.raytheon.viz.gfe.smarttool.PreviewInfo;
  * ------------ ---------- ----------- --------------------------
  * Jan 19, 2010            njensen     Initial creation
  * Jun 25, 2013  16065     ryu         Adding outerLevel attribute
+ * Jul 17, 2015  4575      njensen     Changed varDict from String to Map
  *
  * 
- * + * * @author njensen * @version 1.0 */ @@ -46,7 +48,7 @@ public class SmartToolRequest extends QueueJobRequest { private Parm inputParm; - private String varDict; + private Map varDict; private PreviewInfo preview; @@ -75,11 +77,11 @@ public class SmartToolRequest extends QueueJobRequest { this.inputParm = inputParm; } - public String getVarDict() { + public Map getVarDict() { return varDict; } - public void setVarDict(String varDict) { + public void setVarDict(Map varDict) { this.varDict = varDict; } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolSelectionDlg.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolSelectionDlg.java index 40f88306ec..cbbeb27dfc 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolSelectionDlg.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/smarttool/script/SmartToolSelectionDlg.java @@ -20,6 +20,7 @@ package com.raytheon.viz.gfe.smarttool.script; import java.util.List; +import java.util.Map; import org.eclipse.swt.widgets.Shell; @@ -37,9 +38,10 @@ import com.raytheon.viz.gfe.ui.runtimeui.SelectionDlg; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Feb 9, 2010 njensen Initial creation - * Jun 25, 2013 16065 ryu Passing outerLevel to tool job - * Dec 10, 2013 #2367 dgilling Use new SmartToolJobPool. + * Feb 09, 2010 njensen Initial creation + * Jun 25, 2013 16065 ryu Passing outerLevel to tool job + * Dec 10, 2013 #2367 dgilling Use new SmartToolJobPool. + * Jul 17, 2015 4575 njensen Changed varDict from String to Map * * * @@ -66,8 +68,7 @@ public class SmartToolSelectionDlg extends SelectionDlg { SmartToolRequest req = SmartUtil.buildSmartToolRequest(dataMgr, pi, true); if (req != null) { - String varDict = dataMgr.getSmartToolInterface() - .transformVarDict(getValues()); + Map varDict = getValues(); req.setVarDict(varDict); dataMgr.getSmartToolJobPool().schedule(req); }