diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/EntityTypePropertyType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/EntityTypePropertyType.java index 33c2a1c34dbd67dca2941954a7c7c1b3b6f27688..9245476b39f7d2f331aa3d28662a729122605231 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/EntityTypePropertyType.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/EntityTypePropertyType.java @@ -48,6 +48,8 @@ public abstract class EntityTypePropertyType<T extends EntityType> implements Se private boolean showInEditView; + private Boolean showRawValue; + private Script script; public Script getScript() @@ -131,6 +133,16 @@ public abstract class EntityTypePropertyType<T extends EntityType> implements Se this.showInEditView = showInEditView; } + public Boolean getShowRawValue() + { + return showRawValue; + } + + public void setShowRawValue(Boolean showRawValue) + { + this.showRawValue = showRawValue; + } + public final boolean isMandatory() { return mandatory; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java index 2425e63e66a48d6c411059f5e1564c7dec398af7..748b6cf295c7c21ead44a608d1ac9f8d1c4a9881 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java @@ -89,6 +89,11 @@ public class ManagedPropertyEvaluator */ private static final String INPUT_WIDGETS_FUNCTION = "inputWidgets"; + /** + * The name of the function that returns <code>true</code> if the raw value should be shown. + */ + private static final String SHOW_RAW_VALUE_FUNCTION = "showRawValue"; + /** * The name of the function that expects a map of bindings. */ @@ -106,6 +111,8 @@ public class ManagedPropertyEvaluator private final boolean updateFromBatchFunctionDefined; + private final Boolean showRawValue; + private List<IManagedInputWidgetDescription> inputWidgetDescriptions; public ManagedPropertyEvaluator(String scriptExpression) @@ -115,6 +122,7 @@ public class ManagedPropertyEvaluator boolean batchColumnNamesFunctionDefined = evaluator.hasFunction(BATCH_COLUMN_NAMES_FUNCTION); boolean inputWidgetsFunctionDefined = evaluator.hasFunction(INPUT_WIDGETS_FUNCTION); + showRawValue = evalFunctionShowRawValue(); checkCombinationsOfDefinedFunctions(batchColumnNamesFunctionDefined, inputWidgetsFunctionDefined); columnNames = new ArrayList<String>(); @@ -141,7 +149,10 @@ public class ManagedPropertyEvaluator } IManagedInputWidgetDescription widgetDescription = (IManagedInputWidgetDescription) widget; - inputWidgetDescriptions.add(widgetDescription); + if (inputWidgetsAllowed()) + { + inputWidgetDescriptions.add(widgetDescription); + } if (batchColumnNamesFunctionDefined == false) { String code = widgetDescription.getCode(); @@ -163,7 +174,7 @@ public class ManagedPropertyEvaluator String code = columnName.toUpperCase(); uniqunessChecker.check(code); columnNames.add(code); - if (inputWidgetsFunctionDefined == false) + if (inputWidgetsFunctionDefined == false && inputWidgetsAllowed()) { inputWidgetDescriptions .add(descriptionFactory.createTextInputField(columnName)); @@ -172,6 +183,11 @@ public class ManagedPropertyEvaluator } } + private boolean inputWidgetsAllowed() + { + return showRawValue == null || showRawValue == false; + } + private void checkCombinationsOfDefinedFunctions(boolean batchColumnNamesFunctionDefined, boolean inputWidgetsFunctionDefined) { @@ -191,6 +207,23 @@ public class ManagedPropertyEvaluator } } + private Boolean evalFunctionShowRawValue() + { + boolean showRawValueFunctionDefined = evaluator.hasFunction(SHOW_RAW_VALUE_FUNCTION); + if (showRawValueFunctionDefined == false) + { + return null; + } + Object result = evaluator.evalFunction(SHOW_RAW_VALUE_FUNCTION); + if (result instanceof Boolean == false) + { + throw new EvaluatorException("Function '" + SHOW_RAW_VALUE_FUNCTION + + "' doesn't return a boolean values but an object of type '" + + result.getClass().getName() + "'."); + } + return (Boolean) result; + } + private List<?> evalFunction(String functionName) { Object result = evaluator.evalFunction(functionName); @@ -230,6 +263,11 @@ public class ManagedPropertyEvaluator evaluator.evalFunction(UPDATE_FROM_UI_FUNCTION, action); } + public Boolean getShowRawValue() + { + return showRawValue; + } + public List<String> getBatchColumnNames() { return columnNames; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AbstractEntityTypePropertyTypeTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AbstractEntityTypePropertyTypeTranslator.java index ffeb418067925efee4048adc5f33d63e02a35ded..e7b4d18c69491b2ac0cdaa498136e16ca42649a1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AbstractEntityTypePropertyTypeTranslator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/AbstractEntityTypePropertyTypeTranslator.java @@ -26,9 +26,11 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityTypePropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Script; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; +import ch.systemsx.cisd.openbis.generic.shared.managed_property.ManagedPropertyEvaluator; import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils; /** @@ -92,9 +94,17 @@ abstract public class AbstractEntityTypePropertyTypeTranslator<ET extends Entity result.setOrdinal(etptPE.getOrdinal()); result.setSection(etptPE.getSection()); result.setDynamic(etptPE.isDynamic()); - result.setManaged(etptPE.isManaged()); - result.setShownInEditView(etptPE.isShownInEditView()); - result.setScript(ScriptTranslator.translate(etptPE.getScript())); + boolean managed = etptPE.isManaged(); + result.setManaged(managed); + boolean shownInEditView = etptPE.isShownInEditView(); + result.setShownInEditView(shownInEditView); + Script script = ScriptTranslator.translate(etptPE.getScript()); + if (script != null && managed && shownInEditView) + { + ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script.getScript()); + result.setShowRawValue(evaluator.getShowRawValue()); + } + result.setScript(script); return result; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java index a210d97928f50070db4d6730c77f09228ba983e2..aee95e6fb16ab9f0fa7f3e98054587e0af103085 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java @@ -35,7 +35,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework. import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.PropertyTypeRenderer; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.PropertyFieldFactory; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.lang.StringEscapeUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; @@ -84,7 +83,7 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp { assert properties != null : "Undefined properties."; assert propertyFields == null : "Already initialized."; - List<S> shownEtpts = getEtptsShownInEditView(entityTypesPropertyTypes); + List<S> shownEtpts = getEtptsShownInEditView(entityTypesPropertyTypes, true); this.propertyFields = createPropertyFields(shownEtpts, createInitialProperties(properties)); } @@ -92,7 +91,7 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp public void initWithoutProperties(final List<S> entityTypesPropertyTypes) { assert propertyFields == null : "Already initialized."; - List<S> shownEtpts = getEtptsShownInEditView(entityTypesPropertyTypes); + List<S> shownEtpts = getEtptsShownInEditView(entityTypesPropertyTypes, false); this.propertyFields = createPropertyFields(shownEtpts, createInitialProperties(new ArrayList<IEntityProperty>())); @@ -143,10 +142,10 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp PropertyType propertyType = etpt.getPropertyType(); final String label = PropertyTypeRenderer.getDisplayName(propertyType, propertyTypes); final String propertyTypeCode = propertyType.getCode(); - List<IManagedInputWidgetDescription> widgetDescriptions = - inputWidgetDescriptions.get(propertyTypeCode); - if (widgetDescriptions != null && widgetDescriptions.isEmpty() == false) + if (hasInputWidgets(etpt)) { + List<IManagedInputWidgetDescription> widgetDescriptions = + inputWidgetDescriptions.get(propertyTypeCode); field = createManagedPropertySection(label, isMandatory, widgetDescriptions); } else { @@ -156,15 +155,17 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp } field.get().setData(ETPT, etpt); GWTUtils.setToolTip(field.get(), propertyTypeCode); - // Hide any properties that are not to be shown in edit/update views (unless in debugging - // mode) - if (etpt.isShownInEditView() == false && isDebuggingModeEnabled() == false) - { - FieldUtil.setVisibility(false, field.get()); - } return field; } + private boolean hasInputWidgets(S etpt) + { + PropertyType propertyType = etpt.getPropertyType(); + List<IManagedInputWidgetDescription> widgetDescriptions = + inputWidgetDescriptions.get(propertyType.getCode()); + return widgetDescriptions != null && widgetDescriptions.isEmpty() == false; + } + private DatabaseModificationAwareField<?> createManagedPropertySection(String label, boolean isMandatory, List<IManagedInputWidgetDescription> widgetDescriptions) { @@ -172,11 +173,6 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp label, isMandatory, widgetDescriptions)); } - private boolean isDebuggingModeEnabled() - { - return viewContext.getDisplaySettingsManager().isDebuggingModeEnabled(); - } - private String getId() { return id; @@ -329,12 +325,12 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp } } - private List<S> getEtptsShownInEditView(List<S> allEntityTypesPropertyTypes) + private List<S> getEtptsShownInEditView(List<S> allEntityTypesPropertyTypes, boolean editForm) { ArrayList<S> result = new ArrayList<S>(); for (S etpt : allEntityTypesPropertyTypes) { - if (etpt.isShownInEditView()) + if (shownInForm(etpt, editForm)) { result.add(etpt); } @@ -342,4 +338,22 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp return result; } + private boolean shownInForm(S etpt, boolean editForm) + { + if (etpt.isShownInEditView() == false) + { + return false; + } + if (etpt.isManaged() == false) + { + return true; + } + Boolean showRawValue = etpt.getShowRawValue(); + if (editForm) + { + return showRawValue == null || showRawValue; + } + return showRawValue == null || showRawValue || hasInputWidgets(etpt); + } + } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java index 92eb390811117679e8c19b998716eaaf4b7cb6b7..666aa968d7c4e2e39b087be348bf85fd963022c0 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java @@ -423,6 +423,64 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit assertEquals(1, inputWidgetDescriptions.size()); } + @Test + public void testGetShowRawValueForUndefinedShowRawValueFunction() + { + ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(""); + + assertEquals(null, evaluator.getShowRawValue()); + } + + @Test + public void testGetShowRawValueForDefinedShowRawValueFunctionWhichReturnsTrue() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def showRawValue():\n return True"); + + assertEquals(Boolean.TRUE, evaluator.getShowRawValue()); + } + + @Test + public void testGetShowRawValueForDefinedShowRawValueFunctionWhichReturnsFalse() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def showRawValue():\n return False"); + + assertEquals(Boolean.FALSE, evaluator.getShowRawValue()); + } + + @Test(expectedExceptionsMessageRegExp = "Function 'showRawValue' doesn't return " + + "a boolean values but an object of type 'java.lang.Integer'.", expectedExceptions = EvaluatorException.class) + public void testShowRawValueFunctionWhichReturnsWrongTypeOfData() + { + new ManagedPropertyEvaluator("def showRawValue():\n return 42"); + } + + @Test + public void testEmptyInputWidgetsIfRawValueShouldBeShownButBatchColumnNamesDefined() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator("def showRawValue():\n return True\n" + + "def batchColumnNames():\n return ['A']\n" + + "def updateFromBatchInput():\n None"); + + assertEquals("[A]", evaluator.getBatchColumnNames().toString()); + assertEquals("[]", evaluator.getInputWidgetDescriptions().toString()); + } + + @Test + public void testEmptyInputWidgetsIfRawValueShouldBeShownButInputWidgetsDefined() + { + ManagedPropertyEvaluator evaluator = + new ManagedPropertyEvaluator( + "def showRawValue():\n return True\n" + + "def inputWidgets():\n return [inputWidgetFactory().createTextInputField('A')]\n" + + "def updateFromBatchInput():\n None"); + + assertEquals("[A]", evaluator.getBatchColumnNames().toString()); + assertEquals("[]", evaluator.getInputWidgetDescriptions().toString()); + } + @Test public void testUpdateFromBatchInputWithNoScript() {