diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetUploadForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetUploadForm.java index e2603aab96d2d39a7b8fa327f1281c624b6d0cfe..034db59a20ed9eaa5c5b6a60fa5946330eb84926 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetUploadForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetUploadForm.java @@ -76,7 +76,7 @@ public class DataSetUploadForm extends AbstractRegistrationForm private final DataSetParentsArea parentsArea; - // + // public DataSetUploadForm(IViewContext<ICommonClientServiceAsync> viewContext) { @@ -124,7 +124,7 @@ public class DataSetUploadForm extends AbstractRegistrationForm private void updateFieldsVisibility() { - boolean connectedWithSample = connectedWithSampleCheckbox.getValue(); + boolean connectedWithSample = isConnectedWithSample(); FieldUtil.setVisibility(connectedWithSample, sampleChooser.getField()); FieldUtil.setVisibility(connectedWithSample == false, experimentChooser.getField(), parentsArea); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DataSetUpdates.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DataSetUpdates.java index 11eec96184a8e1f25465ef4cd282b2e97baf08b1..4d46a896d1bb69a16b70f2b4116cff33c607e14c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DataSetUpdates.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DataSetUpdates.java @@ -33,15 +33,18 @@ public class DataSetUpdates extends BasicDataSetUpdates private String sampleIdentifierOrNull; + private String experimentIdentifierOrNull; + public DataSetUpdates() { } public DataSetUpdates(TechId sampleId, List<IEntityProperty> properties, Date version, - String sampleIdentifierOrNull) + String sampleIdentifierOrNull, String experimentIdentifierOrNull) { super(sampleId, properties, version); this.sampleIdentifierOrNull = sampleIdentifierOrNull; + this.experimentIdentifierOrNull = experimentIdentifierOrNull; } public String getSampleIdentifierOrNull() @@ -54,4 +57,14 @@ public class DataSetUpdates extends BasicDataSetUpdates this.sampleIdentifierOrNull = sampleIdentifierOrNull; } + public String getExperimentIdentifierOrNull() + { + return experimentIdentifierOrNull; + } + + public void setExperimentIdentifierOrNull(String experimentIdentifierOrNull) + { + this.experimentIdentifierOrNull = experimentIdentifierOrNull; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBO.java index 2b82ecce0312631a8cd294959fa354bde2f88769..264f839c7c459d4888ccd7e8d84710fd92a68ff4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBO.java @@ -50,18 +50,20 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.FileFormatTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty; 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.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.dto.types.DataSetTypeCode; import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils; /** - * @author Franz-Josef Elmer + * @author Franz-Josef Elmer */ @Friend(toClasses = DataPE.class) public class ExternalDataBO extends AbstractExternalDataBusinessObject implements IExternalDataBO @@ -295,11 +297,23 @@ public class ExternalDataBO extends AbstractExternalDataBusinessObject implement { throwModifiedEntityException("Data set"); } - updateProperties(updates.getProperties()); - updateSample(updates.getSampleIdentifierOrNull()); - updateParents(updates.getModifiedParentDatasetCodesOrNull()); - // TODO 2009-09-10, Piotr Buczek: write updateExperiment when we allow to change it + final SampleIdentifier sampleIdentifierOrNull = updates.getSampleIdentifierOrNull(); + if (sampleIdentifierOrNull != null) + { + // update sample and indirectly experiment + updateSample(updates.getSampleIdentifierOrNull()); + // remove connections with parents + // (new colelction is needed bacause old one will be removed) + removeParents(new ArrayList<DataPE>(externalData.getParents())); + } else + { + updateExperiment(updates.getExperimentIdentifierOrNull()); + updateParents(updates.getModifiedParentDatasetCodesOrNull()); + // remove connection with sample + externalData.setSample(null); + } updateFileFormatType(updates.getFileFormatTypeCode()); + updateProperties(updates.getProperties()); entityPropertiesConverter.checkMandatoryProperties(externalData.getProperties(), externalData.getDataSetType()); validateAndSave(); @@ -479,36 +493,52 @@ public class ExternalDataBO extends AbstractExternalDataBusinessObject implement private void updateSample(SampleIdentifier sampleIdentifierOrNull) { - SamplePE sampleOrNull = null; - if (sampleIdentifierOrNull != null) - { - sampleOrNull = tryToGetSampleByIdentifier(sampleIdentifierOrNull); - } + assert sampleIdentifierOrNull != null; + SamplePE newSample = getSampleByIdentifier(sampleIdentifierOrNull); SamplePE previousSampleOrNull = externalData.tryGetSample(); - if ((sampleOrNull == null && previousSampleOrNull == null) - || (sampleOrNull != null && sampleOrNull.equals(previousSampleOrNull))) + if (newSample.equals(previousSampleOrNull)) { return; // nothing to change } - if (sampleOrNull != null) + if (newSample.getGroup() == null) { - if (sampleOrNull.getGroup() == null) - { - throw createWrongSampleException(sampleOrNull, "the sample is shared"); - } - ExperimentPE experiment = sampleOrNull.getExperiment(); - if (experiment == null) - { - throw createWrongSampleException(sampleOrNull, - "the sample is not connected to any experiment"); - } - // move dataset to the experiment if needed - if (experiment.equals(externalData.getExperiment()) == false) - { - externalData.setExperiment(experiment); - } + throw createWrongSampleException(newSample, "the new sample is shared"); + } + ExperimentPE experiment = newSample.getExperiment(); + if (experiment == null) + { + throw createWrongSampleException(newSample, + "the new sample is not connected to any experiment"); + } + // move dataset to the experiment if needed + if (experiment.equals(externalData.getExperiment()) == false) + { + externalData.setExperiment(experiment); + } + externalData.setSample(newSample); + } + + private void updateExperiment(ExperimentIdentifier experimentIdentifierOrNull) + { + assert experimentIdentifierOrNull != null; + ExperimentPE experiment = getExperimentByIdentifier(experimentIdentifierOrNull); + externalData.setExperiment(experiment); + } + + private ExperimentPE getExperimentByIdentifier(final ExperimentIdentifier identifier) + { + assert identifier != null : "Experiment identifier unspecified."; + final ProjectPE project = + getProjectDAO().tryFindProject(identifier.getDatabaseInstanceCode(), + identifier.getGroupCode(), identifier.getProjectCode()); + if (project == null) + { + throw new UserFailureException("Unkown experiment because of unkown project: " + + identifier); } - externalData.setSample(sampleOrNull); + final ExperimentPE exp = + getExperimentDAO().tryFindByCodeAndProject(project, identifier.getExperimentCode()); + return exp; } private void updateFileFormatType(String fileFormatTypeCode) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetUpdatesDTO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetUpdatesDTO.java index 8e88027baa0c2485268c78c702df7186478b10f7..448978744a695b2072617efab552dd67adaad24b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetUpdatesDTO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetUpdatesDTO.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.shared.dto; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.BasicDataSetUpdates; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ServiceVersionHolder; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; /** @@ -29,6 +30,8 @@ public class DataSetUpdatesDTO extends BasicDataSetUpdates private SampleIdentifier sampleIdentifierOrNull; + private ExperimentIdentifier experimentIdentifierOrNull; + public SampleIdentifier getSampleIdentifierOrNull() { return sampleIdentifierOrNull; @@ -39,4 +42,14 @@ public class DataSetUpdatesDTO extends BasicDataSetUpdates this.sampleIdentifierOrNull = sampleIdentifierOrNull; } + public ExperimentIdentifier getExperimentIdentifierOrNull() + { + return experimentIdentifierOrNull; + } + + public void setExperimentIdentifierOrNull(ExperimentIdentifier experimentIdentifierOrNull) + { + this.experimentIdentifierOrNull = experimentIdentifierOrNull; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditForm.java index c2249fa7648947e4ec4cebc9a42b0b240a0a8013..8e7e554ff703ebba4048803c6f5e3860c784e731 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditForm.java @@ -21,6 +21,10 @@ import static ch.systemsx.cisd.openbis.generic.client.web.client.application.fra import java.util.ArrayList; import java.util.List; +import com.extjs.gxt.ui.client.Events; +import com.extjs.gxt.ui.client.event.FieldEvent; +import com.extjs.gxt.ui.client.event.Listener; + import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; @@ -30,11 +34,16 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework. import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.FileFormatTypeSelectionWidget; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.FileFormatTypeSelectionWidget.FileFormatTypeModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.CheckBoxField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ExperimentChooserField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserField; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ExperimentChooserField.ExperimentChooserFieldAdaptor; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserField.SampleChooserFieldAdaptor; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataSetUpdates; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSetWithEntityTypes; import ch.systemsx.cisd.openbis.generic.shared.basic.IIdentifiable; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetRelationshipRole; @@ -57,14 +66,25 @@ public final class GenericDataSetEditForm extends { private static final String SAMPLE_FIELD_ID_SUFFIX = "sample_field"; + private static final String EXPERIMENT_FIELD_ID_SUFFIX = "experiment_field"; + private final String simpleId; private FileFormatTypeSelectionWidget fileFormatTypeSelectionWidget; - private SampleChooserFieldAdaptor sampleField; + private CheckBoxField connectedWithSampleCheckbox; + + // two options: + // 1. connected with sample + private SampleChooserFieldAdaptor sampleChooser; + + // 2. not connected with sample + private ExperimentChooserFieldAdaptor experimentChooser; private DataSetParentsArea parentsArea; + // + private ExternalData originalDataSet; public static DatabaseModificationAwareComponent create( @@ -99,15 +119,32 @@ public final class GenericDataSetEditForm extends result.setDatasetId(techIdOrNull); result.setProperties(extractProperties()); result.setVersion(originalDataSet.getModificationDate()); - result.setModifiedParentDatasetCodesOrNull(extractParentDatasetCodes()); - result.setSampleIdentifierOrNull(extractSampleIdentifier()); result.setFileFormatTypeCode(extractFileFormatTypeCode()); + if (isConnectedWithSample()) + { + result.setSampleIdentifierOrNull(extractSampleIdentifier()); + } else + { + result.setExperimentIdentifierOrNull(extractExperimentIdentifier()); + result.setModifiedParentDatasetCodesOrNull(extractParentDatasetCodes()); + } return result; } + private Boolean isConnectedWithSample() + { + return connectedWithSampleCheckbox.getValue(); + } + private String extractSampleIdentifier() { - return sampleField.getValue(); + return sampleChooser.getValue(); + } + + private String extractExperimentIdentifier() + { + ExperimentIdentifier identifierOrNull = experimentChooser.tryToGetValue(); + return identifierOrNull == null ? null : identifierOrNull.getIdentifier(); } protected String[] extractParentDatasetCodes() @@ -147,9 +184,11 @@ public final class GenericDataSetEditForm extends private void updateOriginalValues(String[] parentCodes) { updatePropertyFieldsOriginalValues(); - sampleField.updateOriginalValue(); + sampleChooser.updateOriginalValue(); + experimentChooser.updateOriginalValue(); parentsArea.setParentCodes(parentCodes); fileFormatTypeSelectionWidget.updateOriginalValue(fileFormatTypeSelectionWidget.getValue()); + connectedWithSampleCheckbox.updateOriginalValue(connectedWithSampleCheckbox.getValue()); } @Override @@ -166,8 +205,10 @@ public final class GenericDataSetEditForm extends ArrayList<DatabaseModificationAwareField<?>> fields = new ArrayList<DatabaseModificationAwareField<?>>(); // TODO 2009-08-01, Piotr Buczek: add other fields specified in LMS-1003 + fields.add(wrapUnaware(connectedWithSampleCheckbox)); + fields.add(wrapUnaware(sampleChooser.getField())); + fields.add(wrapUnaware(experimentChooser.getField())); fields.add(wrapUnaware(parentsArea)); - fields.add(wrapUnaware(sampleField.getField())); fields.add(wrapUnaware(fileFormatTypeSelectionWidget)); return fields; } @@ -175,14 +216,24 @@ public final class GenericDataSetEditForm extends @Override protected void createEntitySpecificFormFields() { + this.connectedWithSampleCheckbox = createConnectedWithSampleCheckbox(); + this.sampleChooser = createSampleField(); + this.experimentChooser = createExperimentChooserField(); this.parentsArea = createParentsArea(); - this.sampleField = createSampleField(); this.fileFormatTypeSelectionWidget = createFileFormatTypeField(); } - private DataSetParentsArea createParentsArea() + private CheckBoxField createConnectedWithSampleCheckbox() { - return new DataSetParentsArea(viewContext, simpleId); + CheckBoxField result = new CheckBoxField("Connected with Sample", false); + result.addListener(Events.Change, new Listener<FieldEvent>() + { + public void handleEvent(FieldEvent be) + { + updateFieldsVisibility(); + } + }); + return result; } private SampleChooserFieldAdaptor createSampleField() @@ -191,12 +242,29 @@ public final class GenericDataSetEditForm extends String originalSampleOrNull = originalDataSet.getSampleIdentifier(); // one cannot select a sample from shared group or a sample that has no experiment final SampleChooserFieldAdaptor result = - SampleChooserField.create(label, false, originalSampleOrNull, false, true, + SampleChooserField.create(label, true, originalSampleOrNull, false, true, viewContext.getCommonViewContext()); result.getField().setId(createChildId(SAMPLE_FIELD_ID_SUFFIX)); return result; } + private ExperimentChooserFieldAdaptor createExperimentChooserField() + { + String label = viewContext.getMessage(Dict.EXPERIMENT); + ExperimentIdentifier originalExperiment = + ExperimentIdentifier.createIdentifier(originalDataSet.getExperiment()); + final ExperimentChooserFieldAdaptor result = + ExperimentChooserField.create(label, true, originalExperiment, viewContext + .getCommonViewContext()); + result.getField().setId(createChildId(EXPERIMENT_FIELD_ID_SUFFIX)); + return result; + } + + private DataSetParentsArea createParentsArea() + { + return new DataSetParentsArea(viewContext, simpleId); + } + private FileFormatTypeSelectionWidget createFileFormatTypeField() { final FileFormatTypeSelectionWidget result = @@ -208,17 +276,28 @@ public final class GenericDataSetEditForm extends @Override protected void initializeFormFields() { + boolean connectedWithSample = StringUtils.isEmpty(sampleChooser.getValue()) == false; + connectedWithSampleCheckbox.setValue(connectedWithSample); + updateFieldsVisibility(); + propertiesEditor.initWithProperties(originalDataSet.getDataSetType() .getAssignedPropertyTypes(), originalDataSet.getProperties()); codeField.setValue(originalDataSet.getCode()); fileFormatTypeSelectionWidget.setValue(new FileFormatTypeModel(originalDataSet .getFileFormatType())); - // parents Area - parentsArea.setEnabled(false); + // sample and experiment fields are initialized when they are created parentsArea.setValue(viewContext.getMessage(Dict.LOAD_IN_PROGRESS)); loadParentsInBackground(); } + private void updateFieldsVisibility() + { + boolean connectedWithSample = isConnectedWithSample(); + FieldUtil.setVisibility(connectedWithSample, sampleChooser.getField()); + FieldUtil.setVisibility(connectedWithSample == false, experimentChooser.getField(), + parentsArea); + } + private void setOriginalData(ExternalData data) { this.originalDataSet = data; @@ -270,7 +349,10 @@ public final class GenericDataSetEditForm extends protected void process(ResultSetWithEntityTypes<ExternalData> result) { parentsArea.setParents(result.getResultSet().getList()); - parentsArea.setEnabled(true); + if (parentsArea.isVisible()) + { + parentsArea.setEnabled(true); + } } } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java index 2ef7a67ed169fd57a24aaa866eb8db941e32aa7a..c64afd596f11816be19a02a13a3703a7cf504e0a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java @@ -85,7 +85,7 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.ResourceNames; /** * The {@link IGenericClientService} implementation. * - * @author Franz-Josef Elmer + * @author Franz-Josef Elmer */ @Component(value = ResourceNames.GENERIC_PLUGIN_SERVICE) public final class GenericClientService extends AbstractClientService implements @@ -501,6 +501,9 @@ public final class GenericClientService extends AbstractClientService implements String sampleIdentifierOrNull = updates.getSampleIdentifierOrNull(); updatesDTO.setSampleIdentifierOrNull(sampleIdentifierOrNull == null ? null : SampleIdentifierFactory.parse(sampleIdentifierOrNull)); + String experimentIdentifierOrNull = updates.getExperimentIdentifierOrNull(); + updatesDTO.setExperimentIdentifierOrNull(experimentIdentifierOrNull == null ? null + : new ExperimentIdentifierFactory(experimentIdentifierOrNull).createIdentifier()); updatesDTO.setFileFormatTypeCode(updates.getFileFormatTypeCode()); return updatesDTO; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBOTest.java index 15593240ab541f2932e1a69e4f08f4e71700adbe..f51a82e6ddba5424fd7d449f33c4566c64db7018 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExternalDataBOTest.java @@ -55,7 +55,9 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.types.DataSetTypeCode; import ch.systemsx.cisd.openbis.generic.shared.dto.types.ProcedureTypeCode; @@ -78,6 +80,10 @@ public class ExternalDataBOTest extends AbstractBOTest private static final SampleIdentifier SAMPLE_IDENTIFIER = new SampleIdentifier(GROUP_IDENTIFIER, "EXAMPLE_SAMPLE"); + private static final ExperimentIdentifier EXPERIMENT_IDENTIFIER = + new ExperimentIdentifier(new ProjectIdentifier(GROUP_IDENTIFIER, + ManagerTestTool.EXAMPLE_PROJECT.getCode()), "EXPERIMENT_CODE"); + private static final String DATA_STORE_CODE = "dss1"; private static final String PARENT_CODE = "parent"; @@ -285,8 +291,9 @@ public class ExternalDataBOTest extends AbstractBOTest { final SamplePE sample = new SamplePE(); sample.setCode(SAMPLE_IDENTIFIER.getSampleCode()); - final ExternalDataPE dataSet = createDataSet(sample); - DataSetUpdatesDTO dataSetUpdatesDTO = createDataSetUpdates(dataSet); + final ExternalDataPE dataSet = createDataSet(sample, null); + DataSetUpdatesDTO dataSetUpdatesDTO = + createDataSetUpdates(dataSet, SAMPLE_IDENTIFIER, null); prepareForUpdate(dataSet, sample); context.checking(new Expectations() { @@ -313,14 +320,16 @@ public class ExternalDataBOTest extends AbstractBOTest @Test public void testUpdateWithDataSetAsItsOwnParent() { - final SamplePE sample = new SamplePE(); - sample.setCode(SAMPLE_IDENTIFIER.getSampleCode()); - final ExternalDataPE dataSet = createDataSet(sample); - DataSetUpdatesDTO dataSetUpdatesDTO = createDataSetUpdates(dataSet); + final ExperimentPE experiment = new ExperimentPE(); + experiment.setCode(EXPERIMENT_IDENTIFIER.getExperimentCode()); + + final ExternalDataPE dataSet = createDataSet(null, experiment); + DataSetUpdatesDTO dataSetUpdatesDTO = + createDataSetUpdates(dataSet, null, EXPERIMENT_IDENTIFIER); String[] parentCodes = { dataSet.getCode() }; dataSetUpdatesDTO.setModifiedParentDatasetCodesOrNull(parentCodes); - prepareForUpdate(dataSet, sample); + prepareForUpdate(dataSet, experiment); IExternalDataBO dataBO = createExternalDataBO(); try @@ -338,14 +347,16 @@ public class ExternalDataBOTest extends AbstractBOTest @Test public void testUpdateWithNonExistingParentDataSet() { - final SamplePE sample = new SamplePE(); - sample.setCode(SAMPLE_IDENTIFIER.getSampleCode()); - final ExternalDataPE dataSet = createDataSet(sample); - DataSetUpdatesDTO dataSetUpdatesDTO = createDataSetUpdates(dataSet); + final ExperimentPE experiment = new ExperimentPE(); + experiment.setCode(EXPERIMENT_IDENTIFIER.getExperimentCode()); + + final ExternalDataPE dataSet = createDataSet(null, experiment); + DataSetUpdatesDTO dataSetUpdatesDTO = + createDataSetUpdates(dataSet, null, EXPERIMENT_IDENTIFIER); String[] parentCodes = { PARENT_CODE }; dataSetUpdatesDTO.setModifiedParentDatasetCodesOrNull(parentCodes); - prepareForUpdate(dataSet, sample); + prepareForUpdate(dataSet, experiment); context.checking(new Expectations() { { @@ -397,23 +408,53 @@ public class ExternalDataBOTest extends AbstractBOTest }); } - private DataSetUpdatesDTO createDataSetUpdates(final ExternalDataPE dataSet) + private void prepareForUpdate(final ExternalDataPE dataSet, final ExperimentPE experiment) + { + context.checking(new Expectations() + { + { + one(externalDataDAO).tryGetByTechId(TECH_ID, ExternalDataBO.PROPERTY_TYPES); + will(returnValue(dataSet)); + + ExperimentIdentifier identifier = EXPERIMENT_IDENTIFIER; + + one(daoFactory).getProjectDAO(); + will(returnValue(projectDAO)); + one(projectDAO).tryFindProject(identifier.getDatabaseInstanceCode(), + identifier.getGroupCode(), identifier.getProjectCode()); + will(returnValue(ManagerTestTool.EXAMPLE_PROJECT)); + + one(daoFactory).getExperimentDAO(); + will(returnValue(experimentDAO)); + one(experimentDAO).tryFindByCodeAndProject(ManagerTestTool.EXAMPLE_PROJECT, + identifier.getExperimentCode()); + will(returnValue(experiment)); + } + }); + } + + private DataSetUpdatesDTO createDataSetUpdates(final ExternalDataPE dataSet, + final SampleIdentifier sampleIdentifierOrNull, + final ExperimentIdentifier experimentIdentifierOrNull) { DataSetUpdatesDTO dataSetUpdatesDTO = new DataSetUpdatesDTO(); dataSetUpdatesDTO.setDatasetId(TECH_ID); dataSetUpdatesDTO.setVersion(dataSet.getModificationDate()); - dataSetUpdatesDTO.setSampleIdentifierOrNull(SAMPLE_IDENTIFIER); + dataSetUpdatesDTO.setSampleIdentifierOrNull(sampleIdentifierOrNull); + dataSetUpdatesDTO.setExperimentIdentifierOrNull(experimentIdentifierOrNull); dataSetUpdatesDTO.setFileFormatTypeCode(FILE_FORMAT_TYPE.getCode()); return dataSetUpdatesDTO; } - private ExternalDataPE createDataSet(final SamplePE sample) + private ExternalDataPE createDataSet(final SamplePE sampleOrNull, + final ExperimentPE experimentOrNull) { final ExternalDataPE dataSet = new ExternalDataPE(); dataSet.setId(TECH_ID.getId()); dataSet.setCode(DATA_SET_CODE); dataSet.setModificationDate(PRODUCTION_DATE); - dataSet.setSample(sample); + dataSet.setSample(sampleOrNull); + dataSet.setExperiment(experimentOrNull); return dataSet; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditorTest.java index 53929fed970685d97c615932c66bc92c0f1feb61..f93a2b77d55506b53386c6de11d67fcd4eb74d78 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/GenericDataSetEditorTest.java @@ -35,9 +35,10 @@ import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.Pro * * @author Piotr Buczek */ +// TODO 2009-10-07, Piotr Buczek: add tests where sample/experiment is modified public class GenericDataSetEditorTest extends AbstractGWTTestCase { - private static final String DS_WITH_DIRECT_SAMPLE_CONNECTION_CODE = "20081105092158673-1"; + // private static final String DS_WITH_DIRECT_SAMPLE_CONNECTION_CODE = "20081105092158673-1"; private static final String DS_WITH_MANY_PARENTS_CODE = "20081105092259000-9"; @@ -87,26 +88,6 @@ public class GenericDataSetEditorTest extends AbstractGWTTestCase launchTest(20 * SECOND); } - // This test is needed among system tests because a deferred trigger is executed - // just before commit and another test in DAO layer uses manual commit that is unnatural. - public final void testAddDataSetParentFailWithDeferredTriggerError() - { - final String modifiedDataSetCode = DS_WITH_DIRECT_SAMPLE_CONNECTION_CODE; - final String addedParentCode = "20081105092159111-1"; - - prepareShowDataSetEditor(modifiedDataSetCode); - - remoteConsole.prepare(new FillDataSetEditForm().modifyParents(addedParentCode)); - FailureExpectation failureExpectation = - new FailureExpectation(GenericDataSetEditForm.UpdateDataSetCallback.class) - .with("ERROR: Insert/Update of Data Set (Code: " - + modifiedDataSetCode - + ") failed because it cannot be connected with a Sample and a parent Data Set at the same time."); - remoteConsole.prepare(failureExpectation); - - launchTest(20 * SECOND); - } - private void prepareShowDataSetEditor(String dataSetCode) { // Open data set editor by simulating 3 steps: