Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit 24aba68a authored by Nico Mack's avatar Nico Mack

Bug fixes to PythonExecutor in order to handle TextVariables correctly.

Fixed API issue in Variable.getContentClass method.
parent 17b61ffe
'''
Created on Jan 2, 2018
@author: mack
'''
def ConcatText (A, B):
C = A + B
return C
\ No newline at end of file
......@@ -399,8 +399,10 @@ public class PythonExecutor extends Executor {
LOGGER.info(PARAMETER_TEMPLATE, variable.getName(), (structured != null) ? structured.toString() : "null"); //$NON-NLS-1$
}
} else {
Double numericValue = Double.valueOf(variable.getValue().toString());
engine.set(variable.getName(), new PyFloat(numericValue));
// Double numericValue = Double.valueOf(variable.getValue().toString());
// engine.set(variable.getName(), new PyFloat(numericValue));
PyObject pythonized = Py.java2py(variable.getValue());
engine.set(variable.getName(), pythonized);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(PARAMETER_TEMPLATE, variable.getName(), variable.getValue());
}
......@@ -446,8 +448,8 @@ public class PythonExecutor extends Executor {
variable = this.depythonizeStructuredVariable(spatial, result);
} else {
if (variable.getValue() != null) {
variable.setValueFromObject(result.__tojava__(variable.getContentClass().getClass()));
Object object = result.__tojava__(variable.getContentClass());
variable.setValueFromObject(object);
}
//
......
......@@ -35,6 +35,7 @@ import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
......@@ -121,8 +122,12 @@ public abstract class Variable<V> implements Cloneable {
*/
@SuppressWarnings("unchecked")
public V getContentClass() {
return (V) ((value != null) ? value.getClass() : null);
public Class<V> getContentClass() {
// return (V) ((value != null) ? value.getClass() : null);
return (Class<V>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
/**
......
......@@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals;
import lu.list.itis.dkd.tui.cps.system.Import;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
import lu.list.itis.dkd.tui.cps.variable.TextVariable;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.PropertiesFetcher;
......@@ -41,6 +42,7 @@ public class PythonExecutorTest {
* @throws java.lang.Exception
*/
@Before
@SuppressWarnings("nls")
public void setUp() throws Exception {
this.properties = PropertiesFetcher.fetchProperties("test_properties.properties");
}
......@@ -52,26 +54,27 @@ public class PythonExecutorTest {
public void tearDown() throws Exception {}
@Test
@SuppressWarnings("nls")
public void setSpatialVariableTest() {
SpatialVariable pointA = new SpatialVariable("PointA", "n/a", null); //$NON-NLS-2$
pointA.setValue(pointA.valueFromString("49.6111 , 45, 3.14")); //$NON-NLS-1$
SpatialVariable pointA = new SpatialVariable("PointA", "n/a", null);
pointA.setValue(pointA.valueFromString("49.6111 , 45, 3.14"));
SpatialVariable pointB = new SpatialVariable("PointB", "n/a", null); //$NON-NLS-2$
pointB.setValue(pointB.valueFromString("10.5 , 14.10, 3.14")); //$NON-NLS-1$
SpatialVariable pointB = new SpatialVariable("PointB", "n/a", null);
pointB.setValue(pointB.valueFromString("10.5 , 14.10, 3.14"));
SpatialVariable pointC = new SpatialVariable("PointC", "n/a", null); //$NON-NLS-2$
pointC.setValue(pointC.valueFromString("0,0,0")); //$NON-NLS-1$
SpatialVariable pointC = new SpatialVariable("PointC", "n/a", null);
pointC.setValue(pointC.valueFromString("0,0,0"));
List<Import> imports = new ArrayList<>();
Import funtion = new Import("AddPoints", "Spatial"); //$NON-NLS-1$ //$NON-NLS-2$
Import funtion = new Import("AddPoints", "Spatial");
imports.add(funtion);
PythonExecutor executor = new PythonExecutor(this.properties);
executor.resolve(imports);
executor.set(pointA);
executor.set(pointB);
executor.eval("PointC = AddPoints(PointA,PointB)"); //$NON-NLS-1$
executor.eval("PointC = AddPoints(PointA,PointB)");
executor.get(pointC);
Point coordinates = pointC.getValue();
......@@ -82,4 +85,25 @@ public class PythonExecutorTest {
assertEquals(6.28d, coordinates.getAngle(), 0.0001);
}
@Test
@SuppressWarnings("nls")
public void manipulateTextVariableTest() {
TextVariable textA = new TextVariable("TextA", "Humpty ");
TextVariable textB = new TextVariable("TextB", "Dumpty");
TextVariable textC = new TextVariable("TextC", "");
List<Import> imports = new ArrayList<>();
Import funtion = new Import("ConcatText", "Text");
imports.add(funtion);
PythonExecutor executor = new PythonExecutor(this.properties);
executor.resolve(imports);
executor.set(textA);
executor.set(textB);
executor.eval("TextC = ConcatText(TextA,TextB)");
executor.get(textC);
assertEquals("Humpty Dumpty", textC.getValue());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment