diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DefaultEntityOperationService.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DefaultEntityOperationService.java index 3bec4d7aea7ca604af0dc1b84cba666e97d688b7..9188f312dd57ce6fc80b5256537d4db943fcc83c 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DefaultEntityOperationService.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DefaultEntityOperationService.java @@ -29,6 +29,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace; import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationResult; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; @@ -77,8 +78,9 @@ public class DefaultEntityOperationService<T extends DataSetInformation> impleme List<NewExperiment> experimentRegistrations = details.getExperimentRegistrations(); List<SampleUpdatesDTO> sampleUpdates = details.getSampleUpdates(); List<NewSample> sampleRegistrations = details.getSampleRegistrations(); - List<NewExternalData> dataSetRegistrations = new ArrayList<NewExternalData>(); + List<DataSetUpdatesDTO> dataSetUpdates = details.getDataSetUpdates(); + List<NewExternalData> dataSetRegistrations = new ArrayList<NewExternalData>(); for (DataSetRegistrationInformation<?> dsRegistration : details.getDataSetRegistrations()) { NewExternalData newExternalData = dsRegistration.getExternalData(); @@ -87,8 +89,8 @@ public class DefaultEntityOperationService<T extends DataSetInformation> impleme return new ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails( details.tryUserIdOrNull(), spaceRegistrations, projectRegistrations, - experimentRegistrations, sampleUpdates, - sampleRegistrations, dataSetRegistrations); + experimentRegistrations, sampleUpdates, sampleRegistrations, dataSetRegistrations, + dataSetUpdates); } } \ No newline at end of file diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSet.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSet.java index edc65c817ee6f8a3b7ba043c5f679f7a37558049..080a01a5fcaa33955f488d4a21fe6bf5d961293d 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSet.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSet.java @@ -16,105 +16,24 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1; -import java.util.List; - import ch.systemsx.cisd.openbis.generic.shared.Constants; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType; /** * @author Chandrasekhar Ramakrishnan */ -public interface IDataSet +public interface IDataSet extends IDataSetUpdatable { - /** - * Get the data set code of the data set - * - * @return The code of this data set. - */ - public String getDataSetCode(); - - /** - * Get the experiment for this data set. This can only be null at initialization time, and will - * be non-null for a valid data set. - * - * @return The experiment for this data set (will be non-null for a valid data set) - */ - IExperimentImmutable getExperiment(); - - /** - * Set the experiment for this data set. The experiment may also be set by setting the sample. - * - * @param experiment The experiment for this data set. Need not actually be immutable, but the - * immutable one is the supertype. - */ - void setExperiment(IExperimentImmutable experiment); - - /** - * Get the sample for this data set, if there is one. - * - * @return A sample or null. - */ - ISampleImmutable getSample(); - - /** - * Set the sample for this data set. Will also set the experiment, since the sample must have an - * experiment. - * - * @param sampleOrNull The sample to use. Need not actually be immutable, but the immutable one - * is the supertype. - */ - void setSample(ISampleImmutable sampleOrNull); - - /** - * The file format type of the data set. Defaults to the default specified in - * {@link FileFormatType}. - * <p> - * This property is undefined for container data sets. - * - * @return The code of the {@link FileFormatType} for this data set. - */ - public String getFileFormatType(); - - /** - * Set the file format type. - * <p> - * This property is undefined for container data sets. - * - * @param fileFormatTypeCode The code of the desired {@link FileFormatType}. - */ - public void setFileFormatType(String fileFormatTypeCode); - - /** - * Return true if the data set is measured data. Defaults to true. - * - * @return True if the data set is measured data, false otherwise. - */ - public boolean isMeasuredData(); /** * Set whether the data is measured or not. */ public void setMeasuredData(boolean measuredData); - /** - * Get the data set type. This is only null during initialization and is non-null for a valid - * data set. - */ - public String getDataSetType(); - /** * Set the data set type. */ public void setDataSetType(String dataSetTypeCode); - /** - * Returns the speed hint. If it hasn't been set by {@link #setSpeedHint(int)} the default value - * {@link Constants#DEFAULT_SPEED_HINT} will be returned. - * <p> - * This property is undefined for container data sets. - */ - public int getSpeedHint(); - /** * Sets the speed hint for the data set. The speed hint is a negative or positive number with an * absolute value less than or equal {@link Constants#MAX_SPEED}. @@ -123,36 +42,11 @@ public interface IDataSet * <code>speedHint</code>. A negative value means that the data set should be stored in a * storage with speed <= <code>abs(speedHint)</code>. The speed hint might be ignored. * <p> + * If no speed hint has been set the default value {@link Constants#DEFAULT_SPEED_HINT} is + * assumed. + * <p> * This property is undefined for container data sets. */ public void setSpeedHint(int speedHint); - /** - * Get the value for a property. - */ - public String getPropertyValue(String propertyCode); - - /** - * Set the value for a property. - */ - public void setPropertyValue(String propertyCode, String propertyValue); - - /** Sets the parents of the dataset. */ - public void setParentDatasets(List<String> parentDatasetCodes); - - /** Gets the parents of the dataset. */ - public List<String> getParentDatasets(); - - // Methods relating to container data sets which contain other data sets - /** Return true if this data set contains other data sets. */ - public boolean isContainerDataSet(); - - /** - * Get the codes for contained data sets. This is empty if {@link #isContainerDataSet()} returns - * false. - */ - public List<String> getContainedDataSetCodes(); - - /** Set the codes for contained data sets. */ - public void setContainedDataSetCodes(List<String> containedDataSetCodes); } diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetImmutable.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetImmutable.java new file mode 100644 index 0000000000000000000000000000000000000000..259acceccd6d86bbd9cae2364ae0e2e7fbf6518c --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetImmutable.java @@ -0,0 +1,99 @@ +/* + * 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.etlserver.registrator.api.v1; + +import java.util.List; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType; + +/** + * A data set that has already been stored in openBIS. + * + * @author Chandrasekhar Ramakrishnan + */ +public interface IDataSetImmutable +{ + /** + * Get the data set code of the data set + * + * @return The code of this data set. + */ + public String getDataSetCode(); + + /** + * Get the experiment for this data set. This can only be null at initialization time, and will + * be non-null for a valid data set. + * + * @return The experiment for this data set (will be non-null for a valid data set) + */ + IExperimentImmutable getExperiment(); + + /** + * Get the sample for this data set, if there is one. + * + * @return A sample or null. + */ + ISampleImmutable getSample(); + + /** + * The file format type of the data set. Defaults to the default specified in + * {@link FileFormatType}. + * <p> + * This property is undefined for container data sets. + * + * @return The code of the {@link FileFormatType} for this data set. + */ + public String getFileFormatType(); + + /** + * Return true if the data set is measured data. Defaults to true. + * + * @return True if the data set is measured data, false otherwise. + */ + public boolean isMeasuredData(); + + /** + * Get the data set type. This is only null during initialization and is non-null for a valid + * data set. + */ + public String getDataSetType(); + + /** + * Returns the speed hint. + * <p> + * This property is undefined for container data sets. + */ + public int getSpeedHint(); + + /** + * Get the value for a property. + */ + public String getPropertyValue(String propertyCode); + + /** Gets the parents of the dataset. */ + public List<String> getParentDatasets(); + + /** Return true if this data set contains other data sets. */ + public boolean isContainerDataSet(); + + /** + * Get the codes for contained data sets. This is empty if {@link #isContainerDataSet()} returns + * false. + */ + public List<String> getContainedDataSetCodes(); + +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetRegistrationTransaction.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetRegistrationTransaction.java index 6d5a2c885e6832baf29fb927a53fb179219ff822..59002bd77077012eb323a57a5c3c0d089bf7db03 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetRegistrationTransaction.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetRegistrationTransaction.java @@ -39,7 +39,7 @@ public interface IDataSetRegistrationTransaction IDataSet createNewDataSet(); /** - * Create a new data set with the specified type. + * Create a new data set with the specified code. */ IDataSet createNewDataSet(String dataSetType); @@ -47,6 +47,21 @@ public interface IDataSetRegistrationTransaction * Create a new data set with the specified type and code. */ IDataSet createNewDataSet(String dataSetType, String dataSetCode); + + /** + * Get a data set from the openBIS AS. Returns null if the data set does not exist. + * + * @return A data set or null + */ + IDataSetImmutable getDataSet(String dataSetCode); + + /** + * Get a data set from the openBIS AS for the purpose of modifying it. Returns null if the data + * set does not exist. + * + * @return A data set or null + */ + IDataSetUpdatable getDataSetForUpdate(String dataSetCode); /** * Get a sample from the openBIS AS. Returns null if the sample does not exist. diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetUpdatable.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetUpdatable.java new file mode 100644 index 0000000000000000000000000000000000000000..509d323c239db160381956c0f02b7dd288c18af4 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IDataSetUpdatable.java @@ -0,0 +1,65 @@ +/* + * 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.etlserver.registrator.api.v1; + +import java.util.List; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType; + +/** + * @author Chandrasekhar Ramakrishnan + */ +public interface IDataSetUpdatable extends IDataSetImmutable +{ + + /** + * Set the experiment for this data set. The experiment may also be set by setting the sample. + * + * @param experiment The experiment for this data set. Need not actually be immutable, but the + * immutable one is the supertype. + */ + void setExperiment(IExperimentImmutable experiment); + + /** + * Set the sample for this data set. Will also set the experiment, since the sample must have an + * experiment. + * + * @param sampleOrNull The sample to use. Need not actually be immutable, but the immutable one + * is the supertype. + */ + void setSample(ISampleImmutable sampleOrNull); + + /** + * Set the file format type. + * <p> + * This property is undefined for container data sets. + * + * @param fileFormatTypeCode The code of the desired {@link FileFormatType}. + */ + public void setFileFormatType(String fileFormatTypeCode); + + /** + * Set the value for a property. + */ + public void setPropertyValue(String propertyCode, String propertyValue); + + /** Sets the parents of the dataset. */ + public void setParentDatasets(List<String> parentDatasetCodes); + + /** Set the codes for contained data sets. */ + public void setContainedDataSetCodes(List<String> containedDataSetCodes); +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java index c572f792f8dddf166dde74d190055cbde7b65791..d2fdff508001368a2243d390bb02c94ef4a1deed 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java @@ -28,6 +28,8 @@ import ch.systemsx.cisd.etlserver.registrator.DataSetStorageAlgorithm; import ch.systemsx.cisd.etlserver.registrator.DataSetStorageAlgorithmRunner; import ch.systemsx.cisd.etlserver.registrator.IDataSetRegistrationDetailsFactory; import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSet; +import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetImmutable; +import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetUpdatable; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperiment; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; import ch.systemsx.cisd.etlserver.registrator.api.v1.IProject; @@ -38,10 +40,12 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.AtomicEntityOperationDetails; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetRegistrationInformation; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; @@ -92,7 +96,11 @@ abstract class AbstractTransactionState<T extends DataSetInformation> private final IDataSetRegistrationDetailsFactory<T> registrationDetailsFactory; - private final ArrayList<DataSet<T>> registeredDataSets = new ArrayList<DataSet<T>>(); + private final List<DataSet<T>> registeredDataSets = + new ArrayList<DataSet<T>>(); + + private final List<DataSetUpdatable> dataSetsToBeUpdated = + new ArrayList<DataSetUpdatable>(); private final List<Experiment> experimentsToBeRegistered = new ArrayList<Experiment>(); @@ -212,6 +220,32 @@ abstract class AbstractTransactionState<T extends DataSetInformation> return dataSet; } + public IDataSetImmutable getDataSet(String dataSetCode) + { + ExternalData dataSet = openBisService.tryGetDataSet(dataSetCode); + if (dataSet == null) + { + return null; + } else + { + return new DataSetImmutable(dataSet); + } + } + + public IDataSetUpdatable getDataSetForUpdate(String dataSetCode) + { + ExternalData dataSet = openBisService.tryGetDataSet(dataSetCode); + if (dataSet == null) + { + return null; + } else + { + DataSetUpdatable result = new DataSetUpdatable(dataSet); + dataSetsToBeUpdated.add(result); + return result; + } + } + public ISample getSampleForUpdate(String sampleIdentifierString) { SampleIdentifier sampleIdentifier = @@ -402,6 +436,7 @@ abstract class AbstractTransactionState<T extends DataSetInformation> List<NewExperiment> experimentRegistrations = convertExperimentsToBeRegistered(); List<SampleUpdatesDTO> sampleUpdates = convertSamplesToBeUpdated(); List<NewSample> sampleRegistrations = convertSamplesToBeRegistered(); + List<DataSetUpdatesDTO> dataSetUpdates = convertDataSetsToBeUpdated(); // experiment updates not yet supported List<ExperimentUpdatesDTO> experimentUpdates = new ArrayList<ExperimentUpdatesDTO>(); @@ -409,7 +444,8 @@ abstract class AbstractTransactionState<T extends DataSetInformation> AtomicEntityOperationDetails<T> registrationDetails = new AtomicEntityOperationDetails<T>(getUserId(), spaceRegistrations, projectRegistrations, experimentUpdates, experimentRegistrations, - sampleUpdates, sampleRegistrations, dataSetRegistrations); + sampleUpdates, sampleRegistrations, dataSetRegistrations, + dataSetUpdates); return registrationDetails; } @@ -463,6 +499,16 @@ abstract class AbstractTransactionState<T extends DataSetInformation> return result; } + private List<DataSetUpdatesDTO> convertDataSetsToBeUpdated() + { + List<DataSetUpdatesDTO> result = new ArrayList<DataSetUpdatesDTO>(); + for (DataSetUpdatable dataSet : dataSetsToBeUpdated) + { + result.add(ConversionUtils.convertToDataSetUpdatesDTO(dataSet)); + } + return result; + } + @Override public boolean isCommitted() { @@ -474,6 +520,7 @@ abstract class AbstractTransactionState<T extends DataSetInformation> { return false; } + } private static abstract class TerminalTransactionState<T extends DataSetInformation> extends diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/ConversionUtils.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/ConversionUtils.java index baf34e3093f169e84b629f64abe74a3474b0112a..d2920bbd4b573b7ae03f58c78c8717f7ea1ef50a 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/ConversionUtils.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/ConversionUtils.java @@ -29,6 +29,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.NewContainerDataSet; import ch.systemsx.cisd.openbis.generic.shared.dto.NewDataSet; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; @@ -178,4 +179,10 @@ public class ConversionUtils return new NewProject(apiProject.getProjectIdentifier(), apiProject.getDescription()); } + public static DataSetUpdatesDTO convertToDataSetUpdatesDTO(DataSetUpdatable dataSet) + { + // TODO KE: implement + return null; + } + } diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetImmutable.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetImmutable.java new file mode 100644 index 0000000000000000000000000000000000000000..44a19dab346afa924c6462f6e3354a0514d0cb50 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetImmutable.java @@ -0,0 +1,122 @@ +/* + * 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.etlserver.registrator.api.v1.impl; + +import java.util.Collections; +import java.util.List; + +import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetImmutable; +import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; +import ch.systemsx.cisd.etlserver.registrator.api.v1.ISampleImmutable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Code; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper; + +/** + * A data set that has already been stored in openBIS. + * + * @author Chandrasekhar Ramakrishnan + */ +public class DataSetImmutable implements IDataSetImmutable +{ + protected final ExternalData dataSet; + + public DataSetImmutable(ExternalData dataSet) + { + this.dataSet = dataSet; + } + + public String getDataSetCode() + { + return dataSet.getCode(); + } + + public IExperimentImmutable getExperiment() + { + return new ExperimentImmutable(dataSet.getExperiment()); + } + + public ISampleImmutable getSample() + { + ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample = dataSet.getSample(); + if (sample == null) + { + return null; + } else + { + return new SampleImmutable(sample); + } + } + + public String getFileFormatType() + { + if (isContainerDataSet()) + { + return null; + } else + { + return dataSet.tryGetAsDataSet().getFileFormatType().getCode(); + } + } + + public boolean isMeasuredData() + { + return dataSet.isDerived() == false; + } + + public int getSpeedHint() + { + if (isContainerDataSet()) + { + return Integer.MIN_VALUE; + } else + { + return dataSet.tryGetAsDataSet().getSpeedHint(); + } + } + + public String getDataSetType() + { + return dataSet.getDataSetType().getCode(); + } + + public String getPropertyValue(String propertyCode) + { + return EntityHelper.tryFindPropertyValue(dataSet, propertyCode); + } + + public List<String> getParentDatasets() + { + return Code.extractCodes(dataSet.getParents()); + } + + public boolean isContainerDataSet() + { + return dataSet.isContainer(); + } + + public List<String> getContainedDataSetCodes() + { + if (isContainerDataSet()) + { + return Code.extractCodes(dataSet.tryGetAsContainerDataSet().getContainedDataSets()); + } else + { + return Collections.emptyList(); + } + } +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetRegistrationTransaction.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetRegistrationTransaction.java index e31481806c8ff08ba9766612746066b255ddedee..fecbacdba6f6ce22ec81725fdd7e3cc4c9b14a72 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetRegistrationTransaction.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetRegistrationTransaction.java @@ -34,7 +34,9 @@ import ch.systemsx.cisd.etlserver.registrator.IDataSetOnErrorActionDecision.Erro import ch.systemsx.cisd.etlserver.registrator.IDataSetRegistrationDetailsFactory; import ch.systemsx.cisd.etlserver.registrator.IEntityOperationService; import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSet; +import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetImmutable; import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetRegistrationTransaction; +import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetUpdatable; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperiment; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; import ch.systemsx.cisd.etlserver.registrator.api.v1.IProject; @@ -202,6 +204,17 @@ public class DataSetRegistrationTransaction<T extends DataSetInformation> implem return getStateAsLiveState().createNewDataSet(registrationDetails); } + public IDataSetImmutable getDataSet(String dataSetCode) + { + return getStateAsLiveState().getDataSet(dataSetCode); + } + + public IDataSetUpdatable getDataSetForUpdate(String dataSetCode) + { + return getStateAsLiveState().getDataSetForUpdate(dataSetCode); + } + + public ISampleImmutable getSample(String sampleIdentifierString) { SampleIdentifier sampleIdentifier = diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetUpdatable.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetUpdatable.java new file mode 100644 index 0000000000000000000000000000000000000000..a4eaa09b69902573608df0f628e2ad89596ab052 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/DataSetUpdatable.java @@ -0,0 +1,126 @@ +/* + * 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.etlserver.registrator.api.v1.impl; + +import java.util.ArrayList; +import java.util.List; + +import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetUpdatable; +import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; +import ch.systemsx.cisd.etlserver.registrator.api.v1.ISampleImmutable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType; +import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper; + +/** + * A data set already existing in the openBIS database, that is changed as part of the registration + * process of another data set. + * + * @author Kaloyan Enimanev + */ +public class DataSetUpdatable extends DataSetImmutable implements IDataSetUpdatable +{ + public DataSetUpdatable(ExternalData dataSet) + { + super(dataSet); + } + + public void setExperiment(IExperimentImmutable experiment) + { + if (experiment == null) + { + dataSet.setExperiment(null); + } else + { + ExperimentImmutable exp = (ExperimentImmutable) experiment; + dataSet.setExperiment(exp.getExperiment()); + } + } + + public void setSample(ISampleImmutable sampleOrNull) + { + if (sampleOrNull == null) + { + dataSet.setSample(null); + } else + { + SampleImmutable samp = (SampleImmutable) sampleOrNull; + dataSet.setSample(samp.getSample()); + setExperiment(sampleOrNull.getExperiment()); + } + } + + public void setFileFormatType(String fileFormatTypeCode) + { + if (isContainerDataSet()) + { + // ignore + } else + { + FileFormatType fileFormatType = new FileFormatType(); + fileFormatType.setCode(fileFormatTypeCode); + dataSet.tryGetAsDataSet().setFileFormatType(fileFormatType); + } + } + + public void setPropertyValue(String propertyCode, String propertyValue) + { + EntityHelper.createOrUpdateProperty(dataSet, propertyCode, propertyValue); + } + + public void setParentDatasets(List<String> parentDatasetCodes) + { + List<ExternalData> dummyParents = createDummyDataSetsFromCodes(parentDatasetCodes); + dataSet.setParents(dummyParents); + } + + public void setContainedDataSetCodes(List<String> containedDataSetCodes) + { + if (isContainerDataSet()) + { + List<ExternalData> dummyDataSets = createDummyDataSetsFromCodes(containedDataSetCodes); + dataSet.tryGetAsContainerDataSet().setContainedDataSets(dummyDataSets); + } else + { + // ignored + } + } + + private List<ExternalData> createDummyDataSetsFromCodes(List<String> containedDataSetCodes) + { + List<ExternalData> dummies = new ArrayList<ExternalData>(); + if (containedDataSetCodes != null) + { + for (String code : containedDataSetCodes) + { + ExternalData dummy = new ExternalData(); + dummy.setCode(code); + dummies.add(dummy); + } + } + return dummies; + } + + /** + * Only visible to internal implementation classes. Not part of the public interface. + */ + public ExternalData getExternalData() + { + return dataSet; + } + +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/dto/AtomicEntityOperationDetails.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/dto/AtomicEntityOperationDetails.java index 97a3896011ceccc3c116252806ae018bb12e6683..218a7ae9dc7dbebad8d4a307acc779b1917f31ba 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/dto/AtomicEntityOperationDetails.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/dto/AtomicEntityOperationDetails.java @@ -24,6 +24,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; @@ -40,26 +41,29 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen // The userid on whose behalf the operations are done. private final String userIdOrNull; - private final ArrayList<NewSpace> spaceRegistrations; + private final List<NewSpace> spaceRegistrations; - private final ArrayList<NewProject> projectRegistrations; + private final List<NewProject> projectRegistrations; - private final ArrayList<ExperimentUpdatesDTO> experimentUpdates; + private final List<ExperimentUpdatesDTO> experimentUpdates; - private final ArrayList<NewExperiment> experimentRegistrations; + private final List<NewExperiment> experimentRegistrations; - private final ArrayList<SampleUpdatesDTO> sampleUpdates; + private final List<SampleUpdatesDTO> sampleUpdates; - private final ArrayList<NewSample> sampleRegistrations; + private final List<NewSample> sampleRegistrations; - private final ArrayList<DataSetRegistrationInformation<T>> dataSetRegistrations; + private final List<DataSetRegistrationInformation<T>> dataSetRegistrations; + + private final List<DataSetUpdatesDTO> dataSetUpdates; public AtomicEntityOperationDetails(String userIdOrNull, List<NewSpace> spaceRegistrations, List<NewProject> projectRegistrations, List<ExperimentUpdatesDTO> experimentUpdates, List<NewExperiment> experimentRegistrations, List<SampleUpdatesDTO> sampleUpdates, List<NewSample> sampleRegistrations, - List<DataSetRegistrationInformation<T>> dataSetRegistrations) + List<DataSetRegistrationInformation<T>> dataSetRegistrations, + List<DataSetUpdatesDTO> dataSetUpdates) { this.userIdOrNull = userIdOrNull; this.spaceRegistrations = new ArrayList<NewSpace>(spaceRegistrations); @@ -70,6 +74,7 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen this.sampleRegistrations = new ArrayList<NewSample>(sampleRegistrations); this.dataSetRegistrations = new ArrayList<DataSetRegistrationInformation<T>>(dataSetRegistrations); + this.dataSetUpdates = new ArrayList<DataSetUpdatesDTO>(dataSetUpdates); } public String tryUserIdOrNull() @@ -77,37 +82,42 @@ public class AtomicEntityOperationDetails<T extends DataSetInformation> implemen return userIdOrNull; } - public ArrayList<ExperimentUpdatesDTO> getExperimentUpdates() + public List<ExperimentUpdatesDTO> getExperimentUpdates() { return experimentUpdates; } - public ArrayList<NewExperiment> getExperimentRegistrations() + public List<NewExperiment> getExperimentRegistrations() { return experimentRegistrations; } - public ArrayList<SampleUpdatesDTO> getSampleUpdates() + public List<SampleUpdatesDTO> getSampleUpdates() { return sampleUpdates; } - public ArrayList<NewSample> getSampleRegistrations() + public List<NewSample> getSampleRegistrations() { return sampleRegistrations; } - public ArrayList<DataSetRegistrationInformation<T>> getDataSetRegistrations() + public List<DataSetRegistrationInformation<T>> getDataSetRegistrations() { return dataSetRegistrations; } - public ArrayList<NewSpace> getSpaceRegistrations() + public List<DataSetUpdatesDTO> getDataSetUpdates() + { + return dataSetUpdates; + } + + public List<NewSpace> getSpaceRegistrations() { return spaceRegistrations; } - public ArrayList<NewProject> getProjectRegistrations() + public List<NewProject> getProjectRegistrations() { return projectRegistrations; } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISServiceTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISServiceTest.java index 4c77907a26804576db5c71b4111150648ad45841..6d86c4aaccf6dfa79a31634cfbdf63d5a612bb36 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISServiceTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISServiceTest.java @@ -37,6 +37,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace; import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; @@ -160,7 +161,7 @@ public class EncapsulatedOpenBISServiceTest new AtomicEntityOperationDetails(null, Arrays.<NewSpace> asList(), Arrays.<NewProject> asList(), Arrays.<NewExperiment> asList(), Arrays.<SampleUpdatesDTO> asList(), Arrays.<NewSample> asList(), - Arrays.asList(data)); + Arrays.asList(data), Arrays.<DataSetUpdatesDTO> asList()); context.checking(new Expectations() { { diff --git a/eu_basysbio/source/java/eu/basysbio/cisd/dss/IDataSetUploader.java b/eu_basysbio/source/java/eu/basysbio/cisd/dss/IDataSetUploader.java index 3648117dea1aacba62da7945989e43fc334abe42..01743c09a6609c4a1a5972bd79286d3bc3f12cd8 100644 --- a/eu_basysbio/source/java/eu/basysbio/cisd/dss/IDataSetUploader.java +++ b/eu_basysbio/source/java/eu/basysbio/cisd/dss/IDataSetUploader.java @@ -21,8 +21,6 @@ import java.io.File; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; /** - * TODO KE : How is this different from ch.systemsx.cisd.etlserver.IDataSetUploader ? - * * @author Franz-Josef Elmer */ interface IDataSetUploader diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java index 9e1c73081edab38945bcb49923edd2049a2e8a7e..7fc6b6cadd29e5b8d97700f9038bdb427590f444 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java @@ -93,6 +93,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetShareId; import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePropertyTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.DataStorePE; import ch.systemsx.cisd.openbis.generic.shared.dto.DataStoreServerInfo; import ch.systemsx.cisd.openbis.generic.shared.dto.DataStoreServicePE; @@ -632,7 +633,8 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET assert sessionToken != null : "Unspecified session token."; assert newSample != null : "Unspecified new sample."; - SamplePE samplePE = registerSampleInternal(sessionToken, newSample, userIDOrNull); + final Session session = getSession(sessionToken); + SamplePE samplePE = registerSampleInternal(session, newSample, userIDOrNull); return samplePE.getId(); } @@ -963,12 +965,11 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET assert newSample != null : "Unspecified new sample."; // Register the Sample - SamplePE samplePE = registerSampleInternal(sessionToken, newSample, userIdOrNull); + final Session session = getSession(sessionToken); + SamplePE samplePE = registerSampleInternal(session, newSample, userIdOrNull); // Register the data set registerDataSetInternal(sessionToken, externalData, samplePE); - - final Session session = getSession(sessionToken); Sample result = SampleTranslator.translate(Collections.singletonList(samplePE), session.getBaseIndexURL()).get(0); @@ -1030,15 +1031,15 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET assert dataSetCode != null : "Data set code not specified."; } - private SamplePE registerSampleInternal(String sessionToken, NewSample newSample, + private SamplePE registerSampleInternal(Session session, NewSample newSample, String userIdOrNull) { - final Session session = getSession(sessionToken); final ISampleBO sampleBO = businessObjectFactory.createSampleBO(session); sampleBO.define(newSample); if (userIdOrNull != null) { - sampleBO.getSample().setRegistrator(getOrCreatePerson(sessionToken, userIdOrNull)); + sampleBO.getSample().setRegistrator( + getOrCreatePerson(session.getSessionToken(), userIdOrNull)); } sampleBO.save(); SamplePE samplePE = sampleBO.getSample(); @@ -1084,24 +1085,27 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET public AtomicEntityOperationResult performEntityOperations(String sessionToken, AtomicEntityOperationDetails operationDetails) { + final Session session = getSession(sessionToken); - List<Space> spacesCreated = createSpaces(sessionToken, operationDetails); + List<Space> spacesCreated = createSpaces(session, operationDetails); - List<Project> projectsCreated = createProjects(sessionToken, operationDetails); + List<Project> projectsCreated = createProjects(session, operationDetails); - List<Experiment> experimentsCreated = createExperiments(sessionToken, operationDetails); + List<Experiment> experimentsCreated = createExperiments(session, operationDetails); - List<Sample> samplesCreated = createSamples(sessionToken, operationDetails); + List<Sample> samplesCreated = createSamples(session, operationDetails); - List<Sample> samplesUpdated = updateSamples(sessionToken, operationDetails); + List<Sample> samplesUpdated = updateSamples(session, operationDetails); - List<ExternalData> dataSetsCreated = createDataSets(sessionToken, operationDetails); + List<ExternalData> dataSetsCreated = createDataSets(session, operationDetails); + + List<ExternalData> dataSetsUpdated = updateDataSets(session, operationDetails); return new AtomicEntityOperationResult(spacesCreated, projectsCreated, experimentsCreated, - samplesUpdated, samplesCreated, dataSetsCreated); + samplesUpdated, samplesCreated, dataSetsCreated, dataSetsUpdated); } - private List<Space> createSpaces(String sessionToken, + private List<Space> createSpaces(Session session, AtomicEntityOperationDetails operationDetails) { ArrayList<SpacePE> spacePEsCreated = new ArrayList<SpacePE>(); @@ -1109,24 +1113,23 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET for (NewSpace newSpace : newSpaces) { SpacePE spacePE = - registerSpaceInternal(sessionToken, newSpace, + registerSpaceInternal(session, newSpace, operationDetails.tryUserIdOrNull()); spacePEsCreated.add(spacePE); } return GroupTranslator.translate(spacePEsCreated); } - private SpacePE registerSpaceInternal(String sessionToken, NewSpace newSpace, + private SpacePE registerSpaceInternal(Session session, NewSpace newSpace, String registratorUserIdOrNull) { // create space - Session session = getSession(sessionToken); IGroupBO groupBO = businessObjectFactory.createGroupBO(session); groupBO.define(newSpace.getCode(), newSpace.getDescription()); if (registratorUserIdOrNull != null) { groupBO.getGroup().setRegistrator( - getOrCreatePerson(sessionToken, registratorUserIdOrNull)); + getOrCreatePerson(session.getSessionToken(), registratorUserIdOrNull)); } groupBO.save(); @@ -1149,7 +1152,7 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET } - private List<Project> createProjects(String sessionToken, + private List<Project> createProjects(Session session, AtomicEntityOperationDetails operationDetails) { ArrayList<ProjectPE> projectPEsCreated = new ArrayList<ProjectPE>(); @@ -1157,17 +1160,16 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET for (NewProject newProject : newProjects) { ProjectPE projectPE = - registerProjectInternal(sessionToken, newProject, + registerProjectInternal(session, newProject, operationDetails.tryUserIdOrNull()); projectPEsCreated.add(projectPE); } return ProjectTranslator.translate(projectPEsCreated); } - private ProjectPE registerProjectInternal(String sessionToken, NewProject newProject, + private ProjectPE registerProjectInternal(Session session, NewProject newProject, String registratorUserIdOrNull) { - Session session = getSession(sessionToken); IProjectBO projectBO = businessObjectFactory.createProjectBO(session); ProjectIdentifier identifier = new ProjectIdentifierFactory(newProject.getIdentifier()).createIdentifier(); @@ -1175,14 +1177,14 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET if (registratorUserIdOrNull != null) { projectBO.getProject().setRegistrator( - getOrCreatePerson(sessionToken, registratorUserIdOrNull)); + getOrCreatePerson(session.getSessionToken(), registratorUserIdOrNull)); } projectBO.save(); return projectBO.getProject(); } - private List<Sample> createSamples(String sessionToken, + private List<Sample> createSamples(Session session, AtomicEntityOperationDetails operationDetails) { ArrayList<SamplePE> samplePEsCreated = new ArrayList<SamplePE>(); @@ -1190,18 +1192,16 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET for (NewSample newSample : newSamples) { SamplePE samplePE = - registerSampleInternal(sessionToken, newSample, + registerSampleInternal(session, newSample, operationDetails.tryUserIdOrNull()); samplePEsCreated.add(samplePE); } - final Session session = getSession(sessionToken); return SampleTranslator.translate(samplePEsCreated, session.getBaseIndexURL()); } - private List<Sample> updateSamples(String sessionToken, + private List<Sample> updateSamples(Session session, AtomicEntityOperationDetails operationDetails) { - final Session session = getSession(sessionToken); ArrayList<SamplePE> samplePEsUpdated = new ArrayList<SamplePE>(); List<SampleUpdatesDTO> sampleUpdates = operationDetails.getSampleUpdates(); for (SampleUpdatesDTO sampleUpdate : sampleUpdates) @@ -1212,12 +1212,11 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET return SampleTranslator.translate(samplePEsUpdated, session.getBaseIndexURL()); } - private List<ExternalData> createDataSets(String sessionToken, + private List<ExternalData> createDataSets(Session session, AtomicEntityOperationDetails operationDetails) { - final Session session = getSession(sessionToken); ArrayList<DataPE> dataSetsCreated = new ArrayList<DataPE>(); - ArrayList<? extends NewExternalData> dataSetRegistrations = + List<? extends NewExternalData> dataSetRegistrations = operationDetails.getDataSetRegistrations(); ArrayList<NewContainerDataSet> containerRegistrations = @@ -1242,6 +1241,25 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET return DataSetTranslator.translate(dataSetsCreated, "", session.getBaseIndexURL()); } + private List<ExternalData> updateDataSets(Session session, + AtomicEntityOperationDetails operationDetails) + { + List<DataPE> dataSetsUpdated = new ArrayList<DataPE>(); + for (DataSetUpdatesDTO dataSet : operationDetails.getDataSetUpdates()) + { + DataPE updatedDataSet = updateDataSetInternal(session, dataSet); + dataSetsUpdated.add(updatedDataSet); + } + return DataSetTranslator.translate(dataSetsUpdated, "", session.getBaseIndexURL()); + } + + private DataPE updateDataSetInternal(Session session, DataSetUpdatesDTO dataSet) + { + IDataBO dataBO = businessObjectFactory.createDataBO(session); + dataBO.update(dataSet); + return dataBO.getData(); + } + private void registerDatasetInternal(final Session session, ArrayList<DataPE> dataSetsCreated, NewExternalData dataSet) { @@ -1258,17 +1276,18 @@ public class ETLService extends AbstractCommonServer<IETLService> implements IET dataSetsCreated.add(dataBO.getData()); } - private ArrayList<Experiment> createExperiments(String sessionToken, + private ArrayList<Experiment> createExperiments(Session session, AtomicEntityOperationDetails operationDetails) { ArrayList<Experiment> experimentsCreated = new ArrayList<Experiment>(); List<NewExperiment> experimentRegistrations = operationDetails.getExperimentRegistrations(); for (NewExperiment experiment : experimentRegistrations) { - registerExperiment(sessionToken, experiment); + registerExperiment(session.getSessionToken(), experiment); ExperimentIdentifier experimentIdentifier = new ExperimentIdentifierFactory(experiment.getIdentifier()).createIdentifier(); - experimentsCreated.add(tryToGetExperiment(sessionToken, experimentIdentifier)); + experimentsCreated.add(tryToGetExperiment(session.getSessionToken(), + experimentIdentifier)); } return experimentsCreated; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java index 64d2c7fd338a5477437815fe82e45375edb646d3..ab5f5ede932a0ef5b554b39d92b46005144835ac 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java @@ -43,24 +43,27 @@ public class AtomicEntityOperationDetails implements Serializable // This is always an empty list, since it is not currently possible to update experiments from // the DSS - private final ArrayList<ExperimentUpdatesDTO> experimentUpdates; + private final List<ExperimentUpdatesDTO> experimentUpdates; - private final ArrayList<NewSpace> spaceRegistrations; + private final List<NewSpace> spaceRegistrations; - private final ArrayList<NewProject> projectRegistrations; + private final List<NewProject> projectRegistrations; - private final ArrayList<NewExperiment> experimentRegistrations; + private final List<NewExperiment> experimentRegistrations; - private final ArrayList<SampleUpdatesDTO> sampleUpdates; + private final List<SampleUpdatesDTO> sampleUpdates; - private final ArrayList<NewSample> sampleRegistrations; + private final List<NewSample> sampleRegistrations; - private final ArrayList<? extends NewExternalData> dataSetRegistrations; + private final List<? extends NewExternalData> dataSetRegistrations; + private final List<DataSetUpdatesDTO> dataSetUpdates; + public AtomicEntityOperationDetails(String userIdOrNull, List<NewSpace> spaceRegistrations, List<NewProject> projectRegistrations, List<NewExperiment> experimentRegistrations, List<SampleUpdatesDTO> sampleUpdates, List<NewSample> sampleRegistrations, - List<? extends NewExternalData> dataSetRegistrations) + List<? extends NewExternalData> dataSetRegistrations, + List<DataSetUpdatesDTO> dataSetUpdates) { this.userIdOrNull = userIdOrNull; this.spaceRegistrations = new ArrayList<NewSpace>(spaceRegistrations); @@ -70,6 +73,7 @@ public class AtomicEntityOperationDetails implements Serializable this.sampleUpdates = new ArrayList<SampleUpdatesDTO>(sampleUpdates); this.sampleRegistrations = new ArrayList<NewSample>(sampleRegistrations); this.dataSetRegistrations = new ArrayList<NewExternalData>(dataSetRegistrations); + this.dataSetUpdates = new ArrayList<DataSetUpdatesDTO>(dataSetUpdates); } public String tryUserIdOrNull() @@ -77,37 +81,42 @@ public class AtomicEntityOperationDetails implements Serializable return userIdOrNull; } - public ArrayList<ExperimentUpdatesDTO> getExperimentUpdates() + public List<ExperimentUpdatesDTO> getExperimentUpdates() { return experimentUpdates; } - public ArrayList<NewExperiment> getExperimentRegistrations() + public List<NewExperiment> getExperimentRegistrations() { return experimentRegistrations; } - public ArrayList<SampleUpdatesDTO> getSampleUpdates() + public List<SampleUpdatesDTO> getSampleUpdates() { return sampleUpdates; } - public ArrayList<NewSample> getSampleRegistrations() + public List<NewSample> getSampleRegistrations() { return sampleRegistrations; } - public ArrayList<? extends NewExternalData> getDataSetRegistrations() + public List<? extends NewExternalData> getDataSetRegistrations() { return dataSetRegistrations; } - public ArrayList<NewSpace> getSpaceRegistrations() + public List<DataSetUpdatesDTO> getDataSetUpdates() + { + return dataSetUpdates; + } + + public List<NewSpace> getSpaceRegistrations() { return spaceRegistrations; } - public ArrayList<NewProject> getProjectRegistrations() + public List<NewProject> getProjectRegistrations() { return projectRegistrations; } @@ -124,7 +133,7 @@ public class AtomicEntityOperationDetails implements Serializable sb.append("sampleUpdates", sampleUpdates); sb.append("sampleRegistrations", sampleRegistrations); sb.append("dataSetRegistrations", dataSetRegistrations); + sb.append("dataSetUpdates", dataSetUpdates); return sb.toString(); } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationResult.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationResult.java index af90e30306ac0349b1a93d669b5470847809b5c4..1e7bf47897ec11a350db9853d6d76e6507979251 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationResult.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationResult.java @@ -50,17 +50,20 @@ public class AtomicEntityOperationResult implements Serializable private final ArrayList<ExternalData> dataSetsCreated; + private final ArrayList<ExternalData> dataSetsUpdated; + public AtomicEntityOperationResult() { this(Collections.<Space> emptyList(), Collections.<Project> emptyList(), Collections.<Experiment> emptyList(), Collections.<Sample> emptyList(), Collections - .<Sample> emptyList(), Collections.<ExternalData> emptyList()); + .<Sample> emptyList(), Collections.<ExternalData> emptyList(), Collections + .<ExternalData> emptyList()); } public AtomicEntityOperationResult(List<Space> spacesCreated, List<Project> projectsCreated, - List<Experiment> experimentsCreated, - List<Sample> samplesUpdated, List<Sample> samplesCreated, - List<ExternalData> dataSetsCreated) + List<Experiment> experimentsCreated, List<Sample> samplesUpdated, + List<Sample> samplesCreated, List<ExternalData> dataSetsCreated, + List<ExternalData> dataSetsUpdated) { this.spacesCreated = new ArrayList<Space>(spacesCreated); this.projectsCreated = new ArrayList<Project>(projectsCreated); @@ -69,6 +72,7 @@ public class AtomicEntityOperationResult implements Serializable this.samplesUpdated = new ArrayList<Sample>(samplesUpdated); this.samplesCreated = new ArrayList<Sample>(samplesCreated); this.dataSetsCreated = new ArrayList<ExternalData>(dataSetsCreated); + this.dataSetsUpdated = new ArrayList<ExternalData>(dataSetsUpdated); } public ArrayList<Experiment> getExperimentsUpdated() @@ -96,6 +100,11 @@ public class AtomicEntityOperationResult implements Serializable return dataSetsCreated; } + public ArrayList<ExternalData> getDataSetsUpdated() + { + return dataSetsUpdated; + } + public ArrayList<Space> getSpacesCreated() { return spacesCreated; 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 448978744a695b2072617efab552dd67adaad24b..b12fc1907881aeccde85ca1d1d2e602c17ac0c5c 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 @@ -52,4 +52,9 @@ public class DataSetUpdatesDTO extends BasicDataSetUpdates this.experimentIdentifierOrNull = experimentIdentifierOrNull; } + @Override + public String toString() + { + return getDatasetId().toString(); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewDataSet.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewDataSet.java index 74d11fba1a0201388d628cbc11c7a59f5aa819b7..8563ca095b40ad5622c4bc95cef6961af2aac022 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewDataSet.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewDataSet.java @@ -23,6 +23,7 @@ public class NewDataSet extends NewExternalData { private static final long serialVersionUID = 1L; + // TODO KE: Sekhar, should we delete the dead code ?! // The following fields and methods should eventually be moved here, but it's too difficult to // do this now. diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java index d77ba062187297e2e31426b2d308016fa7ae9201..818cbfb4b9502a148505bcc76e61e54e6e166c15 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java @@ -1373,17 +1373,6 @@ public final class CommonServerTest extends AbstractServerTestCase context.assertIsSatisfied(); } - private ExternalDataPE createDataSet(String code, String type) - { - ExternalDataPE externalData = new ExternalDataPE(); - externalData.setCode(code); - DataSetTypePE dataSetType = new DataSetTypePE(); - dataSetType.setCode(type); - dataSetType.setDatabaseInstance(homeDatabaseInstance); - externalData.setDataSetType(dataSetType); - return externalData; - } - @Test public void testUploadDataSets() { diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceTest.java index f8aa3466495fdd32041fa3ce52012f0ca62c969d..62e2d313715d917ddaabd33084cca89ede988cf4 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceTest.java @@ -64,7 +64,9 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataStoreBuild import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.ExperimentBuilder; import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails; import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationResult; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.DataStorePE; import ch.systemsx.cisd.openbis.generic.shared.dto.DataStoreServerInfo; import ch.systemsx.cisd.openbis.generic.shared.dto.DataTypePE; @@ -912,6 +914,13 @@ public class ETLServiceTest extends AbstractServerTestCase externalData.setMeasured(true); externalData.setSampleIdentifierOrNull(newSampleIdentifier); + final String updatedDataSetCode = "updateDataSetCode"; + final DataSetUpdatesDTO dataSetUpdate = new DataSetUpdatesDTO(); + dataSetUpdate.setDatasetId(CommonTestUtils.TECH_ID); + dataSetUpdate.setFileFormatTypeCode("new-file-format"); + dataSetUpdate.setModifiedContainedDatasetCodesOrNull(new String[] + { "c1", "c2" }); + context.checking(new Expectations() { { @@ -961,12 +970,26 @@ public class ETLServiceTest extends AbstractServerTestCase } }); + context.checking(new Expectations() + { + { + exactly(1).of(boFactory).createDataBO(SESSION); + will(returnValue(dataBO)); + + one(dataBO).update(dataSetUpdate); + one(dataBO).getData(); + final DataPE updatedDataSet = createDataSet(updatedDataSetCode, "type"); + will(returnValue(updatedDataSet)); + } + }); + AtomicEntityOperationDetails details = new AtomicEntityOperationDetails(null, new ArrayList<NewSpace>(), new ArrayList<NewProject>(), new ArrayList<NewExperiment>(), Collections.singletonList(sampleUpdate), Collections.singletonList(newSample), - Collections.singletonList(externalData)); + Collections.singletonList(externalData), + Collections.singletonList(dataSetUpdate)); AtomicEntityOperationResult result = createService().performEntityOperations(SESSION_TOKEN, details); @@ -979,6 +1002,7 @@ public class ETLServiceTest extends AbstractServerTestCase assertEquals(newSample.getIdentifier(), result.getSamplesCreated().get(0).getIdentifier()); assertEquals(experiment.getIdentifier(), result.getSamplesCreated().get(0).getExperiment() .getIdentifier()); + assertEquals(updatedDataSetCode, result.getDataSetsUpdated().get(0).getCode()); context.assertIsSatisfied(); } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java index 073a00327261dea55bff7440825536fb6c36007b..190fac09602cf2fea4c71f646597dfbe1e1c9f3b 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java @@ -70,9 +70,12 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IVocabularyDAO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.IPermIdDAO; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataStorePE; import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE; 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.PersonPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; @@ -368,4 +371,17 @@ public abstract class AbstractServerTestCase extends AssertJUnit newExperiment.setSamples(samples); return newExperiment; } + + protected ExternalDataPE createDataSet(String code, String type) + { + ExternalDataPE externalData = new ExternalDataPE(); + externalData.setCode(code); + DataSetTypePE dataSetType = new DataSetTypePE(); + dataSetType.setCode(type); + dataSetType.setDatabaseInstance(homeDatabaseInstance); + externalData.setDataSetType(dataSetType); + externalData.setDataStore(new DataStorePE()); + return externalData; + } + } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/AtomicEntityOperationDetailsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/AtomicEntityOperationDetailsTest.java index f2a31cf8099ff0d6a04696d818a2965d5e310ecd..bcde99654f13964f64dc0927e77910b53c7b71ad 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/AtomicEntityOperationDetailsTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/AtomicEntityOperationDetailsTest.java @@ -17,11 +17,14 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.util.ArrayList; +import java.util.List; import org.testng.AssertJUnit; import org.testng.annotations.Test; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; @@ -62,10 +65,15 @@ public class AtomicEntityOperationDetailsTest extends AssertJUnit .createIdentifier()); dataSetRegistrations.add(newExternalData); + List<DataSetUpdatesDTO> dataSetUpdates = new ArrayList<DataSetUpdatesDTO>(); + DataSetUpdatesDTO dataSetUpdate = new DataSetUpdatesDTO(); + dataSetUpdate.setDatasetId(new TechId(1L)); + dataSetUpdates.add(dataSetUpdate); + AtomicEntityOperationDetails details = new AtomicEntityOperationDetails(null, spaceRegistrations, projectRegistrations, experimentRegistrations, sampleUpdates, sampleRegistrations, - dataSetRegistrations); + dataSetRegistrations, dataSetUpdates); assertEquals( "AtomicEntityOperationDetails[userIdOrNull=<null>" @@ -75,7 +83,8 @@ public class AtomicEntityOperationDetailsTest extends AssertJUnit + ",experimentRegistrations=[/SPACE/PROJECT/EXP-ID1, /SPACE/PROJECT/EXP-ID2]" + ",sampleUpdates=[]" + ",sampleRegistrations=[/SPACE/SAMPLE-ID1, /SPACE/SAMPLE-ID2]" - + ",dataSetRegistrations=[NewExternalData[code=DATA-SET-CODE,type=<null>,fileFormat=<null>,properties=[]]]]", + + ",dataSetRegistrations=[NewExternalData[code=DATA-SET-CODE,type=<null>,fileFormat=<null>,properties=[]]]" + + ",dataSetUpdates=[1]]", details.toString()); }