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 0000000000000000000000000000000000000000..5cfc66950b57349f20b534d10184eedace2e6d94 --- /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 0000000000000000000000000000000000000000..5ae50da4b36d631336af01ba7e32f439172e76c2 --- /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 0000000000000000000000000000000000000000..c1d158c0eff715c1297c7839c2113834c4fffaf2 --- /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 763f3a1770db607fc657e4bd3cb40fe18ee3236e..f6cd5594e50e44d48f17c05514e46494edd89f94 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 a6ed4d72e3dc06dd3d2b5dbe79e3e1cd1865768c..d19814d2b1e13541e3619aaa12b2df9bce7820be 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 31c5b5757a2e32c9b670360f34150f2c76dd0785..6e1f64ae34ede4403d0b84b823bee0150ec7d9ec 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; }