From d4996487c56e1572a37d5b006a73848db398833e Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Tue, 11 Jan 2011 20:14:21 +0000 Subject: [PATCH] [LMS-1949] improved UI for script registration/edition and assignment; extended tests SVN: 19374 --- .../PropertyTypeAssignmentForm.java | 120 +++++++++--------- .../ScriptTypeSelectionWidget.java | 70 ++++++++++ .../AbstractScriptEditRegisterForm.java | 48 ++++++- .../application/ui/script/ScriptEditForm.java | 3 +- .../ui/script/ScriptRegistrationForm.java | 11 +- .../web/client/application/util/GWTUtils.java | 2 +- .../generic/server/business/bo/ScriptBO.java | 3 +- .../generic/shared/basic/dto/ScriptType.java | 9 +- .../openbis/generic/shared/dto/ScriptPE.java | 2 +- .../server/business/bo/ScriptBOTest.java | 36 +++++- .../db/AbstractDAOWithoutContextTest.java | 12 +- .../server/dataaccess/db/ScriptDAOTest.java | 19 ++- 12 files changed, 246 insertions(+), 89 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java index c07d4800b82..89dc609ece9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java @@ -119,9 +119,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements private CheckBox mandatoryCheckbox; - private CheckBox dynamicCheckbox; - - private CheckBox managedCheckbox; + private CheckBox scriptableCheckbox; private SectionSelectionWidget sectionSelectionWidget; @@ -139,6 +137,8 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements private final ScriptChooserField scriptChooser; + private final ScriptTypeSelectionWidget scriptTypeChooser; + public static DatabaseModificationAwareComponent create( final IViewContext<ICommonClientServiceAsync> viewContext, EntityKind entityKind) { @@ -157,6 +157,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements setScrollMode(Scroll.AUTO); add(infoBox = createInfoBox()); add(formPanel = createFormPanel()); + scriptTypeChooser = createScriptTypeChooserField(viewContext); scriptChooser = createScriptChooserField(viewContext, createScriptTypeProvider(), entityKind); } @@ -165,23 +166,24 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements { return new IScriptTypeProvider() { - public ScriptType tryGetScriptType() { - if (dynamicCheckbox.getValue()) - { - return ScriptType.DYNAMIC_PROPERTY; - } else if (managedCheckbox.getValue()) - { - return ScriptType.MANAGED_PROPERTY; - } else - { - return null; - } + return scriptTypeChooser.getSimpleValue(); } }; } + private static ScriptTypeSelectionWidget createScriptTypeChooserField( + IViewContext<ICommonClientServiceAsync> viewContext) + { + ScriptTypeSelectionWidget field = + ScriptTypeSelectionWidget.createPropertyScriptTypes(viewContext); + FieldUtil.setVisibility(false, field); + FieldUtil.markAsMandatory(field); + GWTUtils.autoselect(field); + return field; + } + private static ScriptChooserField createScriptChooserField( final IViewContext<ICommonClientServiceAsync> viewContext, IScriptTypeProvider scriptTypeProvider, EntityKind entityKindOrNull) @@ -295,49 +297,10 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements return result; } - private CheckBox getManagedCheckbox() - { - if (managedCheckbox == null) - { - managedCheckbox = new CheckBoxField(viewContext.getMessage(Dict.MANAGED), false); - managedCheckbox.setValue(false); - managedCheckbox.addListener(Events.Change, new Listener<BaseEvent>() - { - public void handleEvent(BaseEvent be) - { - updateVisibilityOfDynamicRelatedFields(); - } - }); - } - return managedCheckbox; - } - - private CheckBox getDynamicCheckbox() - { - if (dynamicCheckbox == null) - { - dynamicCheckbox = new CheckBoxField(viewContext.getMessage(Dict.DYNAMIC), false); - dynamicCheckbox.setValue(false); - dynamicCheckbox.addListener(Events.Change, new Listener<BaseEvent>() - { - public void handleEvent(BaseEvent be) - { - updateVisibilityOfDynamicRelatedFields(); - } - }); - } - return dynamicCheckbox; - } - - private boolean isScriptable() - { - return dynamicCheckbox.getValue() || managedCheckbox.getValue(); - } - - private void updateVisibilityOfDynamicRelatedFields() + private void updateVisibilityOfScriptRelatedFields() { boolean scriptable = isScriptable(); - FieldUtil.setVisibility(scriptable, scriptChooser); + FieldUtil.setVisibility(scriptable, scriptTypeChooser, scriptChooser); if (defaultValueField != null) { FieldUtil.setVisibility(scriptable == false, defaultValueField.get()); @@ -357,11 +320,33 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements mandatoryCheckbox.setFireChangeEventOnSetValue(false); mandatoryCheckbox.setValue(false); mandatoryCheckbox.addListener(Events.Change, new InfoBoxResetListener(infoBox)); - FieldUtil.setVisibility(dynamicCheckbox.getValue() == false, mandatoryCheckbox); + FieldUtil.setVisibility(isScriptable() == false, mandatoryCheckbox); } return mandatoryCheckbox; } + private CheckBox getScriptableCheckbox() + { + if (scriptableCheckbox == null) + { + scriptableCheckbox = new CheckBoxField(viewContext.getMessage(Dict.SCRIPTABLE), false); + scriptableCheckbox.setValue(false); + scriptableCheckbox.addListener(Events.Change, new Listener<BaseEvent>() + { + public void handleEvent(BaseEvent be) + { + updateVisibilityOfScriptRelatedFields(); + } + }); + } + return scriptableCheckbox; + } + + private boolean isScriptable() + { + return scriptableCheckbox.getValue(); + } + private final FormPanel createFormPanel() { final FormPanel panel = new FormPanel(); @@ -449,8 +434,8 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements DropDownList<?, ?> typeSelectionWidget = getTypeSelectionWidget(); formPanel.add(propertyTypeWidget); formPanel.add(typeSelectionWidget); - formPanel.add(getDynamicCheckbox()); - formPanel.add(getManagedCheckbox()); + formPanel.add(getScriptableCheckbox()); + formPanel.add(scriptTypeChooser); formPanel.add(scriptChooser); formPanel.add(getMandatoryCheckbox()); updatePropertyTypeRelatedFields(); @@ -510,7 +495,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements viewContext.getMessage(Dict.DEFAULT_VALUE_TOOLTIP)); defaultValueField = fieldHolder; defaultValueField.get().show(); - FieldUtil.setVisibility(dynamicCheckbox.getValue() == false, defaultValueField.get()); + FieldUtil.setVisibility(isScriptable() == false, defaultValueField.get()); formPanel.add(defaultValueField.get()); } updateEntityTypePropertyTypeRelatedFields(); @@ -581,7 +566,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements String tryGetScriptNameValue() { - if (dynamicCheckbox.getValue() == false || scriptChooser == null) + if (scriptChooser == null) { return null; } else @@ -590,19 +575,30 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements } } + boolean isDynamic() + { + ScriptType scriptTypeOrNull = scriptTypeChooser.getSimpleValue(); + return scriptTypeOrNull != null && scriptTypeOrNull == ScriptType.DYNAMIC_PROPERTY; + } + + boolean isManaged() + { + ScriptType scriptTypeOrNull = scriptTypeChooser.getSimpleValue(); + return scriptTypeOrNull != null && scriptTypeOrNull == ScriptType.MANAGED_PROPERTY; + } + // private final void submitForm() { if (formPanel.isValid()) { - boolean dynamic = dynamicCheckbox.getValue(); NewETPTAssignment newAssignment = new NewETPTAssignment(entityKind, propertyTypeSelectionWidget.tryGetSelectedPropertyTypeCode(), getSelectedEntityCode(), getMandatoryCheckbox().getValue(), getDefaultValue(), getSectionValue(), getPreviousETPTOrdinal(), - dynamic, false, tryGetScriptNameValue()); + isDynamic(), isManaged(), tryGetScriptNameValue()); viewContext.getService().assignPropertyType(newAssignment, new AssignPropertyTypeCallback(viewContext)); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java new file mode 100644 index 00000000000..3d3590fa3e5 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java @@ -0,0 +1,70 @@ +/* + * Copyright 2008 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.client.web.client.application.ui.property_type; + +import java.util.Arrays; +import java.util.List; + +import com.extjs.gxt.ui.client.widget.form.ComboBox; +import com.extjs.gxt.ui.client.widget.form.SimpleComboBox; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType; + +/** + * A {@link ComboBox} extension using simple strings for selecting a script type. + * + * @author Piotr Buczek + */ +public final class ScriptTypeSelectionWidget extends SimpleComboBox<ScriptType> +{ + /** creates a combo box with all script types */ + public static ScriptTypeSelectionWidget createAllScriptTypes( + final IViewContext<ICommonClientServiceAsync> viewContext) + { + return new ScriptTypeSelectionWidget(viewContext.getMessage(Dict.SCRIPT_TYPE), + viewContext.getMessage(Dict.SCRIPT_TYPE), viewContext.getMessage( + Dict.COMBO_BOX_CHOOSE, "script type"), Arrays.asList(ScriptType.values())); + } + + /** creates a combo box with script types related with property types */ + public static ScriptTypeSelectionWidget createPropertyScriptTypes( + final IViewContext<ICommonClientServiceAsync> viewContext) + { + return new ScriptTypeSelectionWidget(viewContext.getMessage(Dict.SCRIPT_TYPE), + viewContext.getMessage(Dict.SCRIPT_TYPE), viewContext.getMessage( + Dict.COMBO_BOX_CHOOSE, "script type"), Arrays.asList( + ScriptType.DYNAMIC_PROPERTY, ScriptType.MANAGED_PROPERTY)); + } + + private ScriptTypeSelectionWidget(final String fieldLabel, final String toolTip, + final String chooseText, final List<ScriptType> scriptTypes) + { + setFieldLabel(fieldLabel); + setTriggerAction(TriggerAction.ALL); + GWTUtils.setToolTip(this, toolTip); + GWTUtils.setupAutoWidth(this); + setEmptyText(chooseText); + setEditable(false); + setForceSelection(true); + add(scriptTypes); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/AbstractScriptEditRegisterForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/AbstractScriptEditRegisterForm.java index 5f4e7bae029..82869ff5f9b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/AbstractScriptEditRegisterForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/AbstractScriptEditRegisterForm.java @@ -26,6 +26,8 @@ import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.form.FormPanel; import com.extjs.gxt.ui.client.widget.form.SimpleComboValue; import com.extjs.gxt.ui.client.widget.form.TextField; +import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem; +import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; import com.google.gwt.user.client.Element; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; @@ -37,10 +39,12 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.D import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.MultilineVarcharField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ScriptField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type.ScriptTypeSelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.AbstractRegistrationDialog; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Script; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType; /** * {@link AbstractRegistrationForm} for registering and editing scripts. @@ -52,6 +56,8 @@ abstract public class AbstractScriptEditRegisterForm extends AbstractRegistratio protected final IViewContext<ICommonClientServiceAsync> viewContext; + protected final ScriptTypeSelectionWidget scriptTypeChooserOrNull; + protected final TextField<String> nameField; protected final DescriptionField descriptionField; @@ -74,12 +80,31 @@ abstract public class AbstractScriptEditRegisterForm extends AbstractRegistratio this(viewContext, null, entityKindOrNull); } + public AbstractScriptEditRegisterForm(IViewContext<ICommonClientServiceAsync> viewContext, + ScriptTypeSelectionWidget scriptTypeChooser, EntityKind entityKindOrNull) + { + this(viewContext, null, scriptTypeChooser, entityKindOrNull); + } + protected AbstractScriptEditRegisterForm( final IViewContext<ICommonClientServiceAsync> viewContext, TechId scriptIdOrNull, - EntityKind entityKindOrNull) + ScriptTypeSelectionWidget scriptTypeChooserOrNull, EntityKind entityKindOrNull) { super(viewContext, createId(scriptIdOrNull), DEFAULT_LABEL_WIDTH + 20, DEFAULT_FIELD_WIDTH); this.viewContext = viewContext; + + this.scriptTypeChooserOrNull = scriptTypeChooserOrNull; + if (scriptTypeChooserOrNull != null) + { + scriptTypeChooserOrNull.setWidth(200); + final ToolBar toolBar = new ToolBar(); + toolBar.add(new LabelToolItem(scriptTypeChooserOrNull.getFieldLabel() + + GenericConstants.LABEL_SEPARATOR)); + toolBar.add(scriptTypeChooserOrNull); + setTopComponent(toolBar); + scriptTypeChooserOrNull.addSelectionChangedListener(createScriptTypeChangedListener()); + } + this.nameField = new VarcharField(viewContext.getMessage(Dict.NAME), true); this.scriptExecution = new ScriptExecutionFramework(viewContext, asValidable(formPanel), entityKindOrNull); @@ -108,6 +133,27 @@ abstract public class AbstractScriptEditRegisterForm extends AbstractRegistratio }); } + private SelectionChangedListener<SimpleComboValue<ScriptType>> createScriptTypeChangedListener() + { + return new SelectionChangedListener<SimpleComboValue<ScriptType>>() + { + @Override + public void selectionChanged(SelectionChangedEvent<SimpleComboValue<ScriptType>> se) + { + SimpleComboValue<ScriptType> selectedItem = se.getSelectedItem(); + if (selectedItem != null) + { + onScriptTypeChanged(selectedItem.getValue()); + } + } + }; + } + + protected void onScriptTypeChanged(ScriptType scriptType) + { + rightPanel.setVisible(scriptType == ScriptType.DYNAMIC_PROPERTY); + } + private IValidable asValidable(final FormPanel panel) { return new IValidable() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptEditForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptEditForm.java index 3738f78d8c0..27d60f1fa78 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptEditForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptEditForm.java @@ -41,7 +41,7 @@ public class ScriptEditForm extends AbstractScriptEditRegisterForm protected ScriptEditForm(IViewContext<ICommonClientServiceAsync> viewContext, TechId scriptId) { - super(viewContext, scriptId, null); + super(viewContext, scriptId, null, null); this.scriptId = scriptId; } @@ -92,6 +92,7 @@ public class ScriptEditForm extends AbstractScriptEditRegisterForm void setOriginalScript(Script script) { this.originalScript = script; + onScriptTypeChanged(script.getScriptType()); } private final class ScriptEditCallback extends diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptRegistrationForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptRegistrationForm.java index 2517faf4e7c..e4a86c1957a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptRegistrationForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/script/ScriptRegistrationForm.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.script import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type.ScriptTypeSelectionWidget; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Script; @@ -31,13 +32,15 @@ public class ScriptRegistrationForm extends AbstractScriptEditRegisterForm public static ScriptRegistrationForm create( IViewContext<ICommonClientServiceAsync> viewContext, EntityKind entityKindOrNull) { - return new ScriptRegistrationForm(viewContext, entityKindOrNull); + ScriptTypeSelectionWidget scriptTypeChooser = + ScriptTypeSelectionWidget.createAllScriptTypes(viewContext); + return new ScriptRegistrationForm(viewContext, scriptTypeChooser, entityKindOrNull); } protected ScriptRegistrationForm(IViewContext<ICommonClientServiceAsync> viewContext, - EntityKind entityKindOrNull) + ScriptTypeSelectionWidget scriptTypeChooser, EntityKind entityKindOrNull) { - super(viewContext, entityKindOrNull); + super(viewContext, scriptTypeChooser, entityKindOrNull); } @Override @@ -55,6 +58,7 @@ public class ScriptRegistrationForm extends AbstractScriptEditRegisterForm newScript.setDescription(descriptionField.getValue()); newScript.setName(nameField.getValue()); newScript.setScript(scriptField.getValue()); + newScript.setScriptType(scriptTypeChooserOrNull.getSimpleValue()); newScript.setEntityKind(entityKindField.tryGetEntityKind()); return newScript; } @@ -92,5 +96,4 @@ public class ScriptRegistrationForm extends AbstractScriptEditRegisterForm { initGUI(); } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java index b86ce51da85..32c6cc49439 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java @@ -119,7 +119,7 @@ public final class GWTUtils int maxLabelWidth = 0; for (ModelData model : comboBox.getStore().getModels()) { - String displayedString = model.get(displayField); + String displayedString = model.get(displayField).toString(); maxLabelWidth = Math.max(maxLabelWidth, metrics.getWidth(displayedString)); } // It makes sense to limit width of the list because it doesn't look good diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBO.java index 69d129c906b..ad81bb1dc43 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBO.java @@ -113,6 +113,7 @@ public final class ScriptBO extends AbstractBusinessObject implements IScriptBO script.setDescription(newScript.getDescription()); script.setRegistrator(findRegistrator()); script.setScript(newScript.getScript()); + script.setScriptType(newScript.getScriptType()); script.setEntityKind(newScript.getEntityKind()); } @@ -128,7 +129,7 @@ public final class ScriptBO extends AbstractBusinessObject implements IScriptBO script.setScript(updates.getScript()); } getScriptDAO().createOrUpdate(script); - if (scriptChanged) + if (scriptChanged && script.isDynamic()) { for (EntityTypePropertyTypePE assignment : script.getPropertyAssignments()) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ScriptType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ScriptType.java index f6ae54f59b7..ed852a3dcca 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ScriptType.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ScriptType.java @@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; */ public enum ScriptType implements ISerializable { - DYNAMIC_PROPERTY("Dynamic Property"), MANAGED_PROPERTY("Managed Property"); + DYNAMIC_PROPERTY("Dynamic Property Evaluator"), MANAGED_PROPERTY("Managed Property Handler"); private final String description; @@ -36,4 +36,11 @@ public enum ScriptType implements ISerializable { return description; } + + @Override + // used when displayed in combo box + public String toString() + { + return description; + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ScriptPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ScriptPE.java index 8be64606abd..7ce58289155 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ScriptPE.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ScriptPE.java @@ -63,7 +63,7 @@ public class ScriptPE extends HibernateAbstractRegistrationHolder implements IId protected Long id; - private ScriptType scriptType = ScriptType.DYNAMIC_PROPERTY; + private ScriptType scriptType; private String name; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBOTest.java index 4e9c24690a8..85543633e36 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ScriptBOTest.java @@ -69,7 +69,13 @@ public final class ScriptBOTest extends AbstractBOTest } @Test - public final void testDefineAndSave() + public final void testDefineAndSaveDynamicProperty() + { + testDefineAndSave(ScriptType.DYNAMIC_PROPERTY); + testDefineAndSave(ScriptType.MANAGED_PROPERTY); + } + + public final void testDefineAndSave(ScriptType scriptType) { final ScriptBO scriptBO = createScriptBO(); final DatabaseInstancePE instance = createDatabaseInstance(); @@ -78,6 +84,7 @@ public final class ScriptBOTest extends AbstractBOTest newScript.setDescription(DESCRIPTION); newScript.setName(NAME); newScript.setScript(SCRIPT); + newScript.setScriptType(scriptType); final ScriptPE scriptPE = new ScriptPE(); @@ -96,6 +103,7 @@ public final class ScriptBOTest extends AbstractBOTest scriptBO.define(newScript); scriptBO.save(); + assertEquals(scriptType, scriptPE.getScriptType()); assertEquals(newScript.getDescription(), scriptPE.getDescription()); assertEquals(newScript.getName(), scriptPE.getName()); assertEquals(ManagerTestTool.EXAMPLE_SESSION.tryGetPerson(), scriptPE.getRegistrator()); @@ -183,6 +191,12 @@ public final class ScriptBOTest extends AbstractBOTest @Test public void testUpdateScriptNotChanged() throws Exception + { + testUpdateScriptNotChanged(ScriptType.DYNAMIC_PROPERTY); + testUpdateScriptNotChanged(ScriptType.MANAGED_PROPERTY); + } + + public void testUpdateScriptNotChanged(ScriptType scriptType) throws Exception { final ScriptBO scriptBO = createScriptBO(); @@ -199,6 +213,7 @@ public final class ScriptBOTest extends AbstractBOTest scriptPE.setName(name + 1); scriptPE.setScript(script); scriptPE.setDescription(description + 1); + scriptPE.setScriptType(scriptType); context.checking(new Expectations() { @@ -222,9 +237,15 @@ public final class ScriptBOTest extends AbstractBOTest context.assertIsSatisfied(); } - @SuppressWarnings("deprecation") @Test public void testUpdateScriptChanged() throws Exception + { + testUpdateScriptChanged(ScriptType.DYNAMIC_PROPERTY); + testUpdateScriptChanged(ScriptType.MANAGED_PROPERTY); + } + + @SuppressWarnings("deprecation") + public void testUpdateScriptChanged(final ScriptType scriptType) throws Exception { final ScriptBO scriptBO = createScriptBO(); @@ -241,7 +262,7 @@ public final class ScriptBOTest extends AbstractBOTest scriptPE.setName(name + 1); scriptPE.setScript(script + 1); scriptPE.setDescription(description + 1); - scriptPE.setScriptType(ScriptType.DYNAMIC_PROPERTY); + scriptPE.setScriptType(scriptType); final SampleTypePropertyTypePE etpt = new SampleTypePropertyTypePE(); SampleTypePE sampleType = new SampleTypePE(); etpt.setEntityType(sampleType); @@ -256,10 +277,13 @@ public final class ScriptBOTest extends AbstractBOTest one(scriptDAO).createOrUpdate(scriptPE); - one(daoFactory).getEntityPropertyTypeDAO(EntityKind.SAMPLE); - will(returnValue(entityPropertyTypeDAO)); + if (scriptType == ScriptType.DYNAMIC_PROPERTY) + { + one(daoFactory).getEntityPropertyTypeDAO(EntityKind.SAMPLE); + will(returnValue(entityPropertyTypeDAO)); - one(entityPropertyTypeDAO).scheduleDynamicPropertiesEvaluation(etpt); + one(entityPropertyTypeDAO).scheduleDynamicPropertiesEvaluation(etpt); + } } }); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AbstractDAOWithoutContextTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AbstractDAOWithoutContextTest.java index 4ee82110a6f..a41f6c00ac4 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AbstractDAOWithoutContextTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AbstractDAOWithoutContextTest.java @@ -44,6 +44,7 @@ import ch.systemsx.cisd.openbis.generic.server.util.TestInitializer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType; import ch.systemsx.cisd.openbis.generic.shared.dto.AuthorizationGroupPE; import ch.systemsx.cisd.openbis.generic.shared.dto.Code; import ch.systemsx.cisd.openbis.generic.shared.dto.DataTypePE; @@ -53,13 +54,13 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; import ch.systemsx.cisd.openbis.generic.shared.dto.TableNames; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; @@ -230,18 +231,21 @@ public abstract class AbstractDAOWithoutContextTest extends return createSpace(spaceCode, databaseInstance); } - protected ScriptPE createScriptInDB(final String name, String script, String description, + protected ScriptPE createScriptInDB(final ScriptType scriptType, final String name, + String script, String description, ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind kind) { - final ScriptPE result = createScriptPE(name, script, description, kind); + final ScriptPE result = createScriptPE(scriptType, name, script, description, kind); daoFactory.getScriptDAO().createOrUpdate(result); return result; } - protected ScriptPE createScriptPE(final String name, String script, String description, + protected ScriptPE createScriptPE(final ScriptType scriptType, final String name, + String script, String description, ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind kind) { final ScriptPE result = new ScriptPE(); + result.setScriptType(scriptType); result.setName(name); result.setScript(script); result.setDescription(description); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ScriptDAOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ScriptDAOTest.java index 6665a3eee00..e4b27f7aee5 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ScriptDAOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/ScriptDAOTest.java @@ -27,6 +27,7 @@ import org.testng.annotations.Test; import ch.rinn.restrictions.Friend; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType; import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE; import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; @@ -69,7 +70,8 @@ public final class ScriptDAOTest extends AbstractDAOTest AssertJUnit.assertNull(daoFactory.getScriptDAO().tryFindByName(name)); String scriptText = SCRIPT; String description = DESCRIPTION; - final ScriptPE script = createScriptInDB(name, scriptText, description, null); + final ScriptPE script = + createScriptInDB(ScriptType.DYNAMIC_PROPERTY, name, scriptText, description, null); final ScriptPE retrievedScript = daoFactory.getScriptDAO().tryFindByName(name); AssertJUnit.assertNotNull(retrievedScript); assertEquals(script.getRegistrator(), retrievedScript.getRegistrator()); @@ -87,7 +89,9 @@ public final class ScriptDAOTest extends AbstractDAOTest String scriptText = SCRIPT; String description = DESCRIPTION; EntityKind entityKind = EntityKind.SAMPLE; - final ScriptPE script = createScriptInDB(name, scriptText, description, entityKind); + final ScriptPE script = + createScriptInDB(ScriptType.DYNAMIC_PROPERTY, name, scriptText, description, + entityKind); final ScriptPE retrievedScript = daoFactory.getScriptDAO().tryFindByName(name); AssertJUnit.assertNotNull(retrievedScript); assertEquals(script.getRegistrator(), retrievedScript.getRegistrator()); @@ -103,8 +107,8 @@ public final class ScriptDAOTest extends AbstractDAOTest { int initialNumberOfScripts = daoFactory.getScriptDAO().listAllEntities().size(); int scriptNumber = 1; - createScriptInDB(createScriptName(scriptNumber), createScriptText(scriptNumber), - createScriptDescription(scriptNumber), null); + createScriptInDB(ScriptType.DYNAMIC_PROPERTY, createScriptName(scriptNumber), + createScriptText(scriptNumber), createScriptDescription(scriptNumber), null); final List<ScriptPE> scripts = daoFactory.getScriptDAO().listAllEntities(); assertEquals(1 + initialNumberOfScripts, scripts.size()); ScriptPE registered = null; @@ -130,8 +134,8 @@ public final class ScriptDAOTest extends AbstractDAOTest int initialNumberOfScripts = daoFactory.getScriptDAO().listEntities(null, entityKind).size(); int scriptNumber = 1; - createScriptInDB(createScriptName(scriptNumber), createScriptText(scriptNumber), - createScriptDescription(scriptNumber), entityKind); + createScriptInDB(ScriptType.DYNAMIC_PROPERTY, createScriptName(scriptNumber), + createScriptText(scriptNumber), createScriptDescription(scriptNumber), entityKind); final List<ScriptPE> scripts = daoFactory.getScriptDAO().listAllEntities(); assertEquals(1 + initialNumberOfScripts, scripts.size()); for (ScriptPE s : scripts) @@ -144,7 +148,8 @@ public final class ScriptDAOTest extends AbstractDAOTest public final void testDelete() { assertNull(daoFactory.getScriptDAO().tryFindByName(NAME)); - ScriptPE script = createScriptInDB(NAME, SCRIPT, DESCRIPTION, null); + ScriptPE script = + createScriptInDB(ScriptType.DYNAMIC_PROPERTY, NAME, SCRIPT, DESCRIPTION, null); assertNotNull(daoFactory.getScriptDAO().tryFindByName(NAME)); daoFactory.getScriptDAO().delete(script); assertNull(daoFactory.getScriptDAO().tryFindByName(NAME)); -- GitLab