Skip to content
Snippets Groups Projects
Commit c5aad2cf authored by cramakri's avatar cramakri
Browse files

LMS-1949 Added evaluator for managed properties.

SVN: 19419
parent 6c0c0208
No related branches found
No related tags found
No related merge requests found
/*
* 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>();
}
}
}
/*
* 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);
}
}
/*
* 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);
}
......@@ -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;
}
......
......@@ -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);
}
}
......@@ -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;
}
......
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