From c5aad2cf8ddfe5da192bdfffe46b8a6d37d1c50f Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Thu, 13 Jan 2011 22:20:54 +0000 Subject: [PATCH] LMS-1949 Added evaluator for managed properties. SVN: 19419 --- .../ManagedPropertyEvaluator.java | 74 +++++++++++++++++++ .../ManagedPropertyEvaluatorFactory.java | 32 ++++++++ .../basic/dto/IManagedUiDescription.java | 33 +++++++++ ...ManagedComboBoxInputWidgetDescription.java | 7 +- .../basic/dto/ManagedUiDescription.java | 26 ++++++- .../translator/PropertyTranslatorUtils.java | 6 +- 6 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluator.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluatorFactory.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IManagedUiDescription.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluator.java new file mode 100644 index 00000000000..5cfc66950b5 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluator.java @@ -0,0 +1,74 @@ +/* + * 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.server.business.bo.managed_property; + +import org.apache.log4j.Logger; + +import ch.systemsx.cisd.common.evaluator.Evaluator; +import ch.systemsx.cisd.common.logging.LogCategory; +import ch.systemsx.cisd.common.logging.LogFactory; +import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE; +import ch.systemsx.cisd.openbis.generic.shared.util.TypedTableModelBuilder; + +/** + * Class for evaluating scripts that control managed properties. + * + * @author Chandrasekhar Ramakrishnan + */ +public class ManagedPropertyEvaluator +{ + private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, + ManagedPropertyEvaluator.class); + + private final ScriptPE scriptPE; + + /** + * The name of the script that expects the property to be there and updates it. + */ + private static final String CONFIGURE_OUTPUT_EXPRESSION = "configure_output()"; + + private static final String PROPERTY_VARIABLE_NAME = "property"; + + public ManagedPropertyEvaluator(ScriptPE scriptPE) + { + this.scriptPE = scriptPE; + } + + public void evalConfigureProperty(ManagedEntityProperty managedProperty) + { + if (operationLog.isDebugEnabled()) + { + operationLog.debug(String.format("Evaluating managed property '%s'.", managedProperty)); + } + + Evaluator evaluator = + new Evaluator(CONFIGURE_OUTPUT_EXPRESSION, ScriptUtilityFactory.class, + scriptPE.getScript()); + evaluator.set(PROPERTY_VARIABLE_NAME, managedProperty); + evaluator.eval(); + } + + public static class ScriptUtilityFactory + { + static public TypedTableModelBuilder<ISerializable> createTableBuilder() + { + return new TypedTableModelBuilder<ISerializable>(); + } + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluatorFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluatorFactory.java new file mode 100644 index 00000000000..5ae50da4b36 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/managed_property/ManagedPropertyEvaluatorFactory.java @@ -0,0 +1,32 @@ +/* + * 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.server.business.bo.managed_property; + +import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE; + +/** + * Factory for creating managed property evaluators. (Could do some caching or other cleverness.) + * + * @author Chandrasekhar Ramakrishnan + */ +public class ManagedPropertyEvaluatorFactory +{ + public static ManagedPropertyEvaluator createManagedPropertyEvaluator(ScriptPE scriptPE) + { + return new ManagedPropertyEvaluator(scriptPE); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IManagedUiDescription.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IManagedUiDescription.java new file mode 100644 index 00000000000..c1d158c0eff --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IManagedUiDescription.java @@ -0,0 +1,33 @@ +/* + * 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 ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; + +/** + * The interface exposed to the script. + * + * @author Chandrasekhar Ramakrishnan + */ +public interface IManagedUiDescription +{ + public void useTableOutput(TypedTableModel<ISerializable> tableModel); + + public void addTextInputField(String label); + + public void addComboBoxInputField(String labels, String[] values); +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedComboBoxInputWidgetDescription.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedComboBoxInputWidgetDescription.java index 763f3a1770d..f6cd5594e50 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedComboBoxInputWidgetDescription.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedComboBoxInputWidgetDescription.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.util.ArrayList; +import java.util.List; /** * @author Chandrasekhar Ramakrishnan @@ -25,14 +26,14 @@ public class ManagedComboBoxInputWidgetDescription extends ManagedInputWidgetDes { private static final long serialVersionUID = 1L; - private ArrayList<String> options = new ArrayList<String>(); + private List<String> options = new ArrayList<String>(); - public ArrayList<String> getOptions() + public List<String> getOptions() { return options; } - public void setOptions(ArrayList<String> options) + public void setOptions(List<String> options) { this.options = options; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiDescription.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiDescription.java index a6ed4d72e3d..d19814d2b1e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiDescription.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiDescription.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; +import java.util.Arrays; import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; @@ -25,7 +26,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; * * @author Piotr Buczek */ -public class ManagedUiDescription implements ISerializable +public class ManagedUiDescription implements IManagedUiDescription, ISerializable { private static final long serialVersionUID = ServiceVersionHolder.VERSION; @@ -61,4 +62,27 @@ public class ManagedUiDescription implements ISerializable { inputWidgetDescriptions.add(widgetDescription); } + + public void addTextInputField(String label) + { + ManagedTextInputWidgetDescription inputField = new ManagedTextInputWidgetDescription(); + inputField.setLabel(label); + addInputWidgetDescription(inputField); + } + + public void addComboBoxInputField(String label, String[] values) + { + ManagedComboBoxInputWidgetDescription inputField = + new ManagedComboBoxInputWidgetDescription(); + inputField.setLabel(label); + inputField.setOptions(Arrays.asList(values)); + addInputWidgetDescription(inputField); + } + + public void useTableOutput(TypedTableModel<ISerializable> tableModel) + { + ManagedTableWidgetDescription tableWidget = new ManagedTableWidgetDescription(); + tableWidget.setTableModel(tableModel); + setOutputWidgetDescription(tableWidget); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java index 31c5b5757a2..6e1f64ae34e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java @@ -16,6 +16,8 @@ package ch.systemsx.cisd.openbis.generic.shared.translator; +import ch.systemsx.cisd.openbis.generic.server.business.bo.managed_property.ManagedPropertyEvaluator; +import ch.systemsx.cisd.openbis.generic.server.business.bo.managed_property.ManagedPropertyEvaluatorFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; @@ -79,7 +81,9 @@ final class PropertyTranslatorUtils final ScriptPE script = property.getEntityTypePropertyType().getScript(); assert script != null && script.getScriptType() == ScriptType.MANAGED_PROPERTY; final ManagedEntityProperty result = new ManagedEntityProperty(basicProperty); - // TODO 2011-01-12, Piotr Buczek: fill managed property + ManagedPropertyEvaluator evaluator = + ManagedPropertyEvaluatorFactory.createManagedPropertyEvaluator(script); + evaluator.evalConfigureProperty(result); return result; } -- GitLab