Skip to content
Snippets Groups Projects
Commit e63ff873 authored by buczekp's avatar buczekp
Browse files

refactoring: extracted creation of input fields for managed properties to a factory

SVN: 19954
parent f9c413a0
No related branches found
No related tags found
No related merge requests found
Showing
with 251 additions and 125 deletions
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package ch.systemsx.cisd.openbis.generic.shared.basic.dto; package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable;
...@@ -77,36 +76,12 @@ public class ManagedUiActionDescription implements IManagedUiAction, ISerializab ...@@ -77,36 +76,12 @@ public class ManagedUiActionDescription implements IManagedUiAction, ISerializab
this.inputWidgets = widgetDescriptions; this.inputWidgets = widgetDescriptions;
} }
public void addInputWidgetDescription(IManagedInputWidgetDescription widgetDescription) public void addInputWidgets(IManagedInputWidgetDescription... widgetDescriptions)
{ {
inputWidgets.add(widgetDescription); for (IManagedInputWidgetDescription widget : widgetDescriptions)
} {
inputWidgets.add(widget);
public IManagedInputWidgetDescription addTextInputField(String label) }
{
ManagedTextInputWidgetDescription inputField = new ManagedTextInputWidgetDescription();
inputField.setLabel(label);
addInputWidgetDescription(inputField);
return inputField;
}
public IManagedInputWidgetDescription addMultilineTextInputField(String label)
{
ManagedMultilineTextInputWidgetDescription inputField =
new ManagedMultilineTextInputWidgetDescription();
inputField.setLabel(label);
addInputWidgetDescription(inputField);
return inputField;
}
public IManagedInputWidgetDescription addComboBoxInputField(String label, String[] values)
{
ManagedComboBoxInputWidgetDescription inputField =
new ManagedComboBoxInputWidgetDescription();
inputField.setLabel(label);
inputField.setOptions(Arrays.asList(values));
addInputWidgetDescription(inputField);
return inputField;
} }
public String getInputValue(String inputLabel) public String getInputValue(String inputLabel)
......
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import java.util.Arrays;
import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory;
/**
* @author Piotr Buczek
*/
public class ManagedUiActionDescriptionFactory implements IManagedInputWidgetDescriptionFactory,
ISerializable
{
private static final long serialVersionUID = ServiceVersionHolder.VERSION;
// for serialization
public ManagedUiActionDescriptionFactory()
{
}
public IManagedInputWidgetDescription createTextInputField(String label)
{
ManagedTextInputWidgetDescription inputField = new ManagedTextInputWidgetDescription();
inputField.setLabel(label);
return inputField;
}
public IManagedInputWidgetDescription createMultilineTextInputField(String label)
{
ManagedMultilineTextInputWidgetDescription inputField =
new ManagedMultilineTextInputWidgetDescription();
inputField.setLabel(label);
return inputField;
}
public IManagedInputWidgetDescription createComboBoxInputField(String label, String[] values)
{
ManagedComboBoxInputWidgetDescription inputField =
new ManagedComboBoxInputWidgetDescription();
inputField.setLabel(label);
inputField.setOptions(Arrays.asList(values));
return inputField;
}
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.shared.basic.dto.api;
import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable;
/**
* Factory for creation of instances of {@link IManagedInputWidgetDescription}.
* <p>
* All methods of this interface are part of the Managed Properties API.
*
* @author Piotr Buczek
*/
public interface IManagedInputWidgetDescriptionFactory extends ISerializable
{
/**
* @return a text input field with given <var>label</var>
*/
IManagedInputWidgetDescription createTextInputField(String label);
/**
* @return a multiline input field with given <var>label</var>
*/
IManagedInputWidgetDescription createMultilineTextInputField(String label);
/**
* @return a combo box input field with given <var>label</var> and specified list of selectable
* <var>values</var>.
*/
IManagedInputWidgetDescription createComboBoxInputField(String labels, String[] values);
}
...@@ -21,11 +21,7 @@ import java.util.List; ...@@ -21,11 +21,7 @@ import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable;
/** /**
* <pre> * Description of action that a user can perform on the client side.
* action has
* - name (both for display and usage)
* - description (for tooltip/message shown in dialog)
* </pre>
* <p> * <p>
* All methods of this interface are part of the Managed Properties API. * All methods of this interface are part of the Managed Properties API.
* *
...@@ -47,23 +43,10 @@ public interface IManagedUiAction extends ISerializable ...@@ -47,23 +43,10 @@ public interface IManagedUiAction extends ISerializable
public IManagedUiAction setDescription(String description); public IManagedUiAction setDescription(String description);
/** /**
* Adds a text input field with given <var>label</var> to input widgets that will be used in * Adds specified input widget descriptions that will be used in user interface for modifcation
* user interface for modifcation of a managed property. * of a managed property.
*/ */
public IManagedInputWidgetDescription addTextInputField(String label); public void addInputWidgets(IManagedInputWidgetDescription... widgets);
/**
* Adds a multiline text with given <var>label</var> input field to input widgets that will be
* used in user interface for modification of the managed property.
*/
public IManagedInputWidgetDescription addMultilineTextInputField(String label);
/**
* Adds a combo box input field with given <var>label</var> to input widgets that will be used
* in user interface for modification of the managed property. The combo box will contain list
* of provided <var>values</var>.
*/
public IManagedInputWidgetDescription addComboBoxInputField(String labels, String[] values);
/** /**
* Returns list of objects describing input widgets that will be used in user interface user * Returns list of objects describing input widgets that will be used in user interface user
......
...@@ -5,6 +5,9 @@ import javax.annotation.Resource; ...@@ -5,6 +5,9 @@ import javax.annotation.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import ch.systemsx.cisd.openbis.generic.shared.ResourceNames; import ch.systemsx.cisd.openbis.generic.shared.ResourceNames;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedUiActionDescriptionFactory;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.ValidationException; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.ValidationException;
import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IElement; import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IElement;
import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IElementFactory; import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IElementFactory;
...@@ -22,6 +25,9 @@ import ch.systemsx.cisd.openbis.generic.shared.managed_property.structured.XmlSt ...@@ -22,6 +25,9 @@ import ch.systemsx.cisd.openbis.generic.shared.managed_property.structured.XmlSt
@Component(value = ResourceNames.MANAGED_PROPERTY_SCRIPT_UTILITY_FACTORY) @Component(value = ResourceNames.MANAGED_PROPERTY_SCRIPT_UTILITY_FACTORY)
public class ManagedPropertyFunctions public class ManagedPropertyFunctions
{ {
private static final IManagedInputWidgetDescriptionFactory INPUT_WIDGET_FACTORY_INSTANCE =
new ManagedUiActionDescriptionFactory();
private static final IElementFactory ELEMENT_FACTORY_INSTANCE = new ElementFactory(); private static final IElementFactory ELEMENT_FACTORY_INSTANCE = new ElementFactory();
private static final IStructuredPropertyConverter STRUCTURED_PROPERTY_CONVERTER_INSTANCE = private static final IStructuredPropertyConverter STRUCTURED_PROPERTY_CONVERTER_INSTANCE =
...@@ -65,6 +71,14 @@ public class ManagedPropertyFunctions ...@@ -65,6 +71,14 @@ public class ManagedPropertyFunctions
return new ValidationException(message); return new ValidationException(message);
} }
/**
* @return a factory object that can be used to create {@link IManagedInputWidgetDescription}-s.
*/
public static IManagedInputWidgetDescriptionFactory inputWidgetFactory()
{
return INPUT_WIDGET_FACTORY_INSTANCE;
}
/** /**
* @return a factory object that can be used to create {@link IElement}-s. * @return a factory object that can be used to create {@link IElement}-s.
*/ */
......
...@@ -16,10 +16,15 @@ ...@@ -16,10 +16,15 @@
package ch.systemsx.cisd.openbis.generic.shared; package ch.systemsx.cisd.openbis.generic.shared;
import java.io.File;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils;
import ch.systemsx.cisd.authentication.Principal; import ch.systemsx.cisd.authentication.Principal;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentContentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentContentPE;
...@@ -411,4 +416,16 @@ public class CommonTestUtils ...@@ -411,4 +416,16 @@ public class CommonTestUtils
propertyPE.setEntityTypePropertyType(entityTypePropertyTypePE); propertyPE.setEntityTypePropertyType(entityTypePropertyTypePE);
propertyPE.setValue(value); propertyPE.setValue(value);
} }
public static String getResourceAsString(String path, String resource)
{
File file = new File(path, resource);
try
{
return FileUtils.readFileToString(file);
} catch (IOException ioex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ioex);
}
}
} }
...@@ -26,11 +26,13 @@ import org.testng.annotations.Test; ...@@ -26,11 +26,13 @@ import org.testng.annotations.Test;
import ch.systemsx.cisd.common.evaluator.EvaluatorException; import ch.systemsx.cisd.common.evaluator.EvaluatorException;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedComboBoxInputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedComboBoxInputWidgetDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedTableWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedTableWidgetDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedOutputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedOutputWidgetDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedUiAction; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedUiAction;
...@@ -45,6 +47,15 @@ import ch.systemsx.cisd.openbis.generic.shared.util.SimpleTableModelBuilder; ...@@ -45,6 +47,15 @@ import ch.systemsx.cisd.openbis.generic.shared.util.SimpleTableModelBuilder;
*/ */
public class ManagedPropertyEvaluatorTest extends AssertJUnit public class ManagedPropertyEvaluatorTest extends AssertJUnit
{ {
private static final String UPDATE_FROM_UI_TEST_PY = "updateFromUI-test.py";
private static final String CONFIGURE_UI_OUTPUT_TEST_PY = "configureUIOutput-test.py";
private static final String CONFIGURE_UI_INPUT_TEST_PY = "configureUIInput-test.py";
private static final String SCRIPT_FOLDER =
"sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/";
@Test @Test
public void testEmptyScript() public void testEmptyScript()
{ {
...@@ -70,23 +81,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit ...@@ -70,23 +81,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit
{ {
IManagedProperty managedProperty = new ManagedProperty(); IManagedProperty managedProperty = new ManagedProperty();
managedProperty.setOwnTab(false); managedProperty.setOwnTab(false);
ManagedPropertyEvaluator evaluator =
new ManagedPropertyEvaluator("def configureUI():\n" String script =
+ " tableBuilder = createTableBuilder()\n" + "\n" CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, CONFIGURE_UI_OUTPUT_TEST_PY);
+ " tableBuilder.addHeader('column1')\n" ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script);
+ " tableBuilder.addHeader('column2')\n"
+ " tableBuilder.addHeader('column3')\n" + "\n"
+ " row1 = tableBuilder.addRow()\n"
+ " row1.setCell('column1','v1')\n" + " row1.setCell('column2', 1)\n"
+ " row1.setCell('column3', 1.5)\n" + "\n"
+ " row2 = tableBuilder.addRow()\n"
+ " row2.setCell('column1','v2')\n" + " row2.setCell('column2', 2)\n"
+ " row2.setCell('column3', 2.5)\n"
+ " row3 = tableBuilder.addRow()\n"
+ " row3.setCell('column1','v3')\n" + "\n"
+ " property.setOwnTab(True)\n"
+ " uiDesc = property.getUiDescription()\n"
+ " uiDesc.useTableOutput(tableBuilder.getTableModel())");
evaluator.configureUI(managedProperty); evaluator.configureUI(managedProperty);
assertEquals(true, managedProperty.isOwnTab()); assertEquals(true, managedProperty.isOwnTab());
IManagedOutputWidgetDescription outputWidgetDescripion = IManagedOutputWidgetDescription outputWidgetDescripion =
...@@ -139,15 +138,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit ...@@ -139,15 +138,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit
{ {
IManagedProperty managedProperty = new ManagedProperty(); IManagedProperty managedProperty = new ManagedProperty();
managedProperty.setOwnTab(false); managedProperty.setOwnTab(false);
ManagedPropertyEvaluator evaluator =
new ManagedPropertyEvaluator( String script =
"def configureUI():\n" CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, CONFIGURE_UI_INPUT_TEST_PY);
+ " uiAction = property.getUiDescription().addAction('Create')\n" ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script);
+ " uiAction.addTextInputField('t1')\n"
+ " uiAction.addTextInputField('t2').setValue('default 2')\n"
+ " uiAction.addTextInputField('t3').setDescription('description 3')\n"
+ " uiAction.addMultilineTextInputField('multi').setValue('default m').setDescription('multiline')\n"
+ " uiAction.addComboBoxInputField('combo', ['v1', 'v2', 'v3']).setMandatory(True).setDescription('select from list')\n");
evaluator.configureUI(managedProperty); evaluator.configureUI(managedProperty);
assertEquals(false, managedProperty.isOwnTab()); assertEquals(false, managedProperty.isOwnTab());
...@@ -186,47 +181,37 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit ...@@ -186,47 +181,37 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit
{ {
IManagedProperty managedProperty = new ManagedProperty(); IManagedProperty managedProperty = new ManagedProperty();
IManagedUiDescription uiDescription = managedProperty.getUiDescription(); IManagedUiDescription uiDescription = managedProperty.getUiDescription();
IManagedInputWidgetDescriptionFactory widgetFactory =
ManagedPropertyFunctions.inputWidgetFactory();
IManagedUiAction action1 = uiDescription.addAction("a1"); IManagedUiAction action1 = uiDescription.addAction("a1");
action1.addTextInputField("t1"); IManagedInputWidgetDescription action1w1 = widgetFactory.createTextInputField("t1");
action1.addTextInputField("t2").setValue("v2"); IManagedInputWidgetDescription action1w2 =
action1.addMultilineTextInputField("multi").setValue("multi\nline\ninput"); widgetFactory.createTextInputField("t2").setValue("v2");
action1.addComboBoxInputField("combo", new String[] IManagedInputWidgetDescription action1w3 =
{ "cv1", "cv2", "cv3" }).setValue("cv1"); widgetFactory.createMultilineTextInputField("multi").setValue("multi\nline\ninput");
IManagedInputWidgetDescription action1w4 =
widgetFactory.createComboBoxInputField("combo", new String[]
{ "cv1", "cv2", "cv3" }).setValue("cv1");
action1.addInputWidgets(action1w1, action1w2, action1w3, action1w4);
assertEquals(null, action1.getInputValue("t1")); assertEquals(null, action1.getInputValue("t1"));
assertEquals("v2", action1.getInputValue("t2")); assertEquals("v2", action1.getInputValue("t2"));
assertEquals(null, action1.getInputValue("t3")); assertEquals(null, action1.getInputValue("t3"));
IManagedUiAction action2 = uiDescription.addAction("a2"); IManagedUiAction action2 = uiDescription.addAction("a2");
action2.addTextInputField("t1").setValue("v11"); IManagedInputWidgetDescription action2w1 =
action2.addTextInputField("t2").setValue("v22"); widgetFactory.createTextInputField("t1").setValue("v11");
IManagedInputWidgetDescription action2w2 =
widgetFactory.createTextInputField("t2").setValue("v22");
action2.addInputWidgets(action2w1, action2w2);
assertEquals("v11", action2.getInputValue("t1")); assertEquals("v11", action2.getInputValue("t1"));
assertEquals("v22", action2.getInputValue("t2")); assertEquals("v22", action2.getInputValue("t2"));
assertEquals(null, action2.getInputValue("t3")); assertEquals(null, action2.getInputValue("t3"));
IManagedUiAction action3 = uiDescription.addAction("a3"); IManagedUiAction action3 = uiDescription.addAction("a3");
ManagedPropertyEvaluator evaluator = String script = CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, UPDATE_FROM_UI_TEST_PY);
new ManagedPropertyEvaluator( ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script);
"def updateFromUI(action):\n"
+ " if action.getName() == 'a1':\n"
+ " value = 'a1|'\n"
+ " for input in action.getInputWidgetDescriptions():\n"
+ " inputValue = input.getValue();\n"
+ " if inputValue is None:\n "
+ " inputValue = 'null'\n"
+ " value = value + input.getLabel() + '=' + inputValue + '|'\n"
+ " property.setValue(value)\n"
+ " elif action.getName() == 'a2':\n"
+ " value = 'a2!'\n"
+ " for input in action.getInputWidgetDescriptions():\n"
+ " inputValue = input.getValue();\n"
+ " if inputValue is None:\n "
+ " inputValue = 'null'\n"
+ " value = value + input.getLabel() + '=' + inputValue + '!'\n"
+ " property.setValue(value)\n"
+ " else:\n"
+ " raise ValidationException('action ' + action.getName() + ' is not supported')\n");
evaluator.updateFromUI(managedProperty, action1); evaluator.updateFromUI(managedProperty, action1);
assertNotNull(managedProperty.getValue()); assertNotNull(managedProperty.getValue());
......
def configureUI():
factory = inputWidgetFactory()
widgets = [
factory.createTextInputField('t1'),
factory.createTextInputField('t2')\
.setValue('default 2'),
factory.createTextInputField('t3')\
.setDescription('description 3'),
factory.createMultilineTextInputField('multi')\
.setValue('default m')\
.setDescription('multiline'),
factory.createComboBoxInputField('combo', ['v1', 'v2', 'v3'])\
.setMandatory(True)\
.setDescription('select from list')
]
uiAction = property.getUiDescription().addAction('Create')
uiAction.addInputWidgets(widgets)
\ No newline at end of file
def configureUI():
tableBuilder = createTableBuilder()
tableBuilder.addHeader('column1')
tableBuilder.addHeader('column2')
tableBuilder.addHeader('column3')
row1 = tableBuilder.addRow()
row1.setCell('column1','v1')
row1.setCell('column2', 1)
row1.setCell('column3', 1.5)
row2 = tableBuilder.addRow()
row2.setCell('column1','v2')
row2.setCell('column2', 2)
row2.setCell('column3', 2.5)
row3 = tableBuilder.addRow()
row3.setCell('column1','v3')
property.setOwnTab(True)
uiDesc = property.getUiDescription()
uiDesc.useTableOutput(tableBuilder.getTableModel())
\ No newline at end of file
...@@ -16,15 +16,12 @@ ...@@ -16,15 +16,12 @@
package ch.systemsx.cisd.openbis.generic.shared.managed_property.structured; package ch.systemsx.cisd.openbis.generic.shared.managed_property.structured;
import java.io.File;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils;
import org.testng.AssertJUnit; import org.testng.AssertJUnit;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty;
...@@ -48,7 +45,8 @@ public class StructuredPropertyConverterPythonTest extends AssertJUnit ...@@ -48,7 +45,8 @@ public class StructuredPropertyConverterPythonTest extends AssertJUnit
public void testAPIUsageFromJython() public void testAPIUsageFromJython()
{ {
IManagedProperty managedProperty = new ManagedEntityProperty(new EntityProperty()); IManagedProperty managedProperty = new ManagedEntityProperty(new EntityProperty());
String script = getResourceAsString("structured-property-test.py"); String script =
CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, "structured-property-test.py");
ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script); ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script);
evaluator.configureUI(managedProperty); evaluator.configureUI(managedProperty);
...@@ -60,19 +58,4 @@ public class StructuredPropertyConverterPythonTest extends AssertJUnit ...@@ -60,19 +58,4 @@ public class StructuredPropertyConverterPythonTest extends AssertJUnit
assertEquals(3, elements.size()); assertEquals(3, elements.size());
} }
/**
* if this becomes a common pattern, we might factor it out.
*/
private String getResourceAsString(String resource)
{
File file = new File(SCRIPT_FOLDER, resource);
try
{
return FileUtils.readFileToString(file);
} catch (IOException ioex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ioex);
}
}
} }
def updateFromUI(action):
if action.getName() == 'a1':
value = 'a1|'
for input in action.getInputWidgetDescriptions():
inputValue = input.getValue()
if inputValue is None:
inputValue = 'null'
value = value + input.getLabel() + '=' + inputValue + '|'
property.setValue(value)
elif action.getName() == 'a2':
value = 'a2!'
for input in action.getInputWidgetDescriptions():
inputValue = input.getValue()
if inputValue is None:
inputValue = 'null'
value = value + input.getLabel() + '=' + inputValue + '!'
property.setValue(value)
else:
raise ValidationException('action ' + action.getName() + ' is not supported')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment