Skip to content
Snippets Groups Projects
Commit 6a0d20b4 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2033] - implemented createNewSample(), createNewExperiment(),...

[LMS-2033] - implemented createNewSample(), createNewExperiment(), getSampleForUpdate() in DataSetRegistrationTransaction
- added convenience getter/settter methods in the ISample/IExperiment interfaces

SVN: 19900
parent ddca9b10
No related branches found
No related tags found
No related merge requests found
Showing
with 508 additions and 132 deletions
...@@ -218,6 +218,8 @@ public class DataSetStorageAlgorithm<T extends DataSetInformation> ...@@ -218,6 +218,8 @@ public class DataSetStorageAlgorithm<T extends DataSetInformation>
data.setFileFormatType(registrationDetails.getFileFormatType()); data.setFileFormatType(registrationDetails.getFileFormatType());
data.setMeasured(registrationDetails.isMeasuredData()); data.setMeasured(registrationDetails.isMeasuredData());
data.setDataStoreCode(dataStoreCode); data.setDataStoreCode(dataStoreCode);
data.setExperimentIdentifierOrNull(dataSetInformation.getExperimentIdentifier());
data.setSampleIdentifierOrNull(dataSetInformation.getSampleIdentifier());
File dataFile = ((StoredState<T>) state).getDataFile(); File dataFile = ((StoredState<T>) state).getDataFile();
......
...@@ -23,7 +23,6 @@ import java.util.List; ...@@ -23,7 +23,6 @@ import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import ch.systemsx.cisd.base.exceptions.InterruptedExceptionUnchecked; import ch.systemsx.cisd.base.exceptions.InterruptedExceptionUnchecked;
import ch.systemsx.cisd.common.exceptions.HighLevelException;
import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
...@@ -110,10 +109,6 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation> ...@@ -110,10 +109,6 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation>
// Runs or throws a throwable // Runs or throws a throwable
runStorageProcessors(); runStorageProcessors();
} catch (final HighLevelException ex)
{
rollbackDuringStorageProcessorRun(ex);
return Collections.emptyList();
} catch (final Throwable throwable) } catch (final Throwable throwable)
{ {
rollbackDuringStorageProcessorRun(throwable); rollbackDuringStorageProcessorRun(throwable);
...@@ -125,10 +120,6 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation> ...@@ -125,10 +120,6 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation>
// Runs or throw a throwable // Runs or throw a throwable
registerDataSetsInApplicationServer(); registerDataSetsInApplicationServer();
} catch (final HighLevelException ex)
{
rollbackDuringMetadataRegistration(ex);
return Collections.emptyList();
} catch (final Throwable throwable) } catch (final Throwable throwable)
{ {
rollbackDuringMetadataRegistration(throwable); rollbackDuringMetadataRegistration(throwable);
......
...@@ -24,12 +24,10 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.AtomicEntityOperationDeta ...@@ -24,12 +24,10 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.AtomicEntityOperationDeta
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; 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.dss.generic.shared.dto.DataSetRegistrationInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationResult; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationResult;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
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.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO;
public class DefaultEntityOperationService<T extends DataSetInformation> implements public class DefaultEntityOperationService<T extends DataSetInformation> implements
IEntityOperationService<T> IEntityOperationService<T>
...@@ -44,36 +42,29 @@ public class DefaultEntityOperationService<T extends DataSetInformation> impleme ...@@ -44,36 +42,29 @@ public class DefaultEntityOperationService<T extends DataSetInformation> impleme
public AtomicEntityOperationResult performOperationsInApplcationServer( public AtomicEntityOperationResult performOperationsInApplcationServer(
AtomicEntityOperationDetails<T> registrationDetails) AtomicEntityOperationDetails<T> registrationDetails)
{ {
ArrayList<Experiment> experimentsCreated = new ArrayList<Experiment>();
ArrayList<Sample> samplesUpdated = new ArrayList<Sample>();
ArrayList<Sample> samplesCreated = new ArrayList<Sample>();
ArrayList<ExternalData> dataSetsCreated = new ArrayList<ExternalData>();
IEncapsulatedOpenBISService openBisService = IEncapsulatedOpenBISService openBisService =
registrator.getGlobalState().getOpenBisService(); registrator.getGlobalState().getOpenBisService();
List<NewExperiment> experimentRegistrations =
registrationDetails.getExperimentRegistrations();
for (NewExperiment experiment : experimentRegistrations)
{
openBisService.registerExperiment(experiment);
ExperimentIdentifier experimentIdentifier =
new ExperimentIdentifierFactory(experiment.getIdentifier()).createIdentifier();
experimentsCreated.add(openBisService.tryToGetExperiment(experimentIdentifier));
}
List<DataSetRegistrationInformation<T>> dataSetRegistrations = return openBisService.performEntityOperations(convert(registrationDetails));
registrationDetails.getDataSetRegistrations(); }
for (DataSetRegistrationInformation<T> dataSetRegistration : dataSetRegistrations)
private ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails convert(
AtomicEntityOperationDetails<T> details)
{
List<NewExperiment> experimentRegistrations = details.getExperimentRegistrations();
List<SampleUpdatesDTO> sampleUpdates = details.getSampleUpdates();
List<NewSample> sampleRegistrations = details.getSampleRegistrations();
List<NewExternalData> dataSetRegistrations = new ArrayList<NewExternalData>();
for (DataSetRegistrationInformation<?> dsRegistration : details.getDataSetRegistrations())
{ {
openBisService.registerDataSet(dataSetRegistration.getDataSetInformation(), NewExternalData newExternalData = dsRegistration.getExternalData();
dataSetRegistration.getExternalData()); dataSetRegistrations.add(newExternalData);
dataSetsCreated.add(openBisService.tryGetDataSet(dataSetRegistration
.getDataSetInformation().getDataSetCode()));
} }
return new AtomicEntityOperationResult(experimentsCreated, samplesUpdated, samplesCreated, return new ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails(
dataSetsCreated); experimentRegistrations, sampleUpdates, sampleRegistrations, dataSetRegistrations);
} }
} }
\ No newline at end of file
...@@ -23,4 +23,20 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1; ...@@ -23,4 +23,20 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1;
*/ */
public interface IExperiment extends IExperimentImmutable public interface IExperiment extends IExperimentImmutable
{ {
/**
* Set the value for a property.
*
* @throws IllegalArgumentException if no property for code <code>propertyCode</code> is found.
*/
void setPropertyValue(String propertyCode, String propertyValue);
/**
* Set the code for this experiment.
*/
void setCode(String code);
/**
* Set the experiment type for this experiment.
*/
void setType(String experimentType);
} }
...@@ -17,14 +17,35 @@ ...@@ -17,14 +17,35 @@
package ch.systemsx.cisd.etlserver.registrator.api.v1; package ch.systemsx.cisd.etlserver.registrator.api.v1;
/** /**
* Read-only interface to an existing experiment. * Read-only interface to an existing experiment.
* *
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
*/ */
public interface IExperimentImmutable public interface IExperimentImmutable
{ {
/**
* Return the experiment identifier of this experiment.
*/
String getExperimentIdentifier();
/** /**
* Return true if the experiment is in openBIS. * Return true if the experiment is in openBIS.
*/ */
boolean isExistingExperiment(); boolean isExistingExperiment();
/**
* Return the code for this experiment. May be null.
*/
String getCode();
/**
* Return the type for this experiment. May be null.
*/
String getType();
/**
* Return the value of a property specified by a code. May return null of no such property with
* code <code>propertyCode</code> is found.
*/
String getPropertyValue(String propertyCode);
} }
...@@ -22,4 +22,26 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1; ...@@ -22,4 +22,26 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1;
public interface ISample extends ISampleImmutable public interface ISample extends ISampleImmutable
{ {
/**
* Set the experiment for this sample. The experiment need not be immutable, but the immutable
* one is the superclass.
*/
void setExperiment(IExperimentImmutable experiment);
/**
* Set the code for this sample.
*/
void setCode(String code);
/**
* Set the type for this sample.
*/
void setType(String type);
/**
* Set the value for a property.
*
* @throws IllegalArgumentException if no property for code <code>propertyCode</code> is found.
*/
void setPropertyValue(String propertyCode, String propertyValue);
} }
...@@ -23,8 +23,35 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1; ...@@ -23,8 +23,35 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1;
*/ */
public interface ISampleImmutable public interface ISampleImmutable
{ {
/**
* Return the identifier for this sample.
*/
String getSampleIdentifier();
/**
* Return the code for this sample. May be null.
*/
String getCode();
/**
* Return the experiment for this sample. May be null.
*/
IExperimentImmutable getExperiment();
/**
* Return the type for this sample. May be null.
*/
String getType();
/** /**
* Return true if the sample exists in the database. * Return true if the sample exists in the database.
*/ */
boolean isExistingSample(); boolean isExistingSample();
/**
* Return the value of a property specified by a code. May return null of no such property with
* code <code>propertyCode</code> is found.
*/
String getPropertyValue(String propertyCode);
} }
...@@ -18,8 +18,10 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; ...@@ -18,8 +18,10 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import ch.systemsx.cisd.common.exceptions.NotImplementedException;
import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationDetails; import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationDetails;
import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationService; import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationService;
...@@ -33,10 +35,16 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; ...@@ -33,10 +35,16 @@ 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.AtomicEntityOperationDetails;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; 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.dss.generic.shared.dto.DataSetRegistrationInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentUpdatesDTO; 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.SampleUpdatesDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory;
/** /**
* Abstract superclass for the states a DataSetRegistrationTransaction can be in. * Abstract superclass for the states a DataSetRegistrationTransaction can be in.
...@@ -86,6 +94,10 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -86,6 +94,10 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
private final List<Experiment> experimentsToBeRegistered = new ArrayList<Experiment>(); private final List<Experiment> experimentsToBeRegistered = new ArrayList<Experiment>();
private final List<Sample> samplesToBeRegistered = new ArrayList<Sample>();
private final List<Sample> samplesToBeUpdated = new ArrayList<Sample>();
public LiveTransactionState(DataSetRegistrationTransaction<T> parent, public LiveTransactionState(DataSetRegistrationTransaction<T> parent,
RollbackStack rollbackStack, File workingDirectory, File stagingDirectory, RollbackStack rollbackStack, File workingDirectory, File stagingDirectory,
DataSetRegistrationService<T> registrationService, DataSetRegistrationService<T> registrationService,
...@@ -134,26 +146,39 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -134,26 +146,39 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
public ISample getSampleForUpdate(String sampleIdentifierString) public ISample getSampleForUpdate(String sampleIdentifierString)
{ {
// TODO Auto-generated method stub SampleIdentifier sampleIdentifier =
return null; new SampleIdentifierFactory(sampleIdentifierString).createIdentifier();
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample =
openBisService.tryGetSampleWithExperiment(sampleIdentifier);
// TODO KE: Ask Sekhar if we should throw an exception or simply return NULL
if (sample == null)
{
throw new IllegalArgumentException("Could not find sample with identifier"
+ sampleIdentifierString);
}
Sample result = new Sample(sample);
samplesToBeUpdated.add(result);
return result;
} }
public ISample createNewSample(String sampleIdentifierString) public ISample createNewSample(String sampleIdentifierString)
{ {
// TODO Auto-generated method stub // TODO KE: should we create a new method with a more sensible name (createPermId())
return null; String permId = openBisService.createDataSetCode();
Sample sample = new Sample(sampleIdentifierString, permId);
samplesToBeRegistered.add(sample);
return sample;
} }
public IExperiment getExperimentForUpdate(String experimentIdentifierString) public IExperiment getExperimentForUpdate(String experimentIdentifierString)
{ {
// TODO Auto-generated method stub throw new NotImplementedException();
return null;
} }
public IExperiment createNewExperiment(String experimentIdentifierString) public IExperiment createNewExperiment(String experimentIdentifierString)
{ {
String permID = openBisService.createDataSetCode(); String permId = openBisService.createDataSetCode();
Experiment experiment = new Experiment(experimentIdentifierString, permID); Experiment experiment = new Experiment(experimentIdentifierString, permId);
experimentsToBeRegistered.add(experiment); experimentsToBeRegistered.add(experiment);
return experiment; return experiment;
} }
...@@ -275,11 +300,14 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -275,11 +300,14 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
AtomicEntityOperationDetails<T> createEntityOperationDetails( AtomicEntityOperationDetails<T> createEntityOperationDetails(
List<DataSetRegistrationInformation<T>> dataSetRegistrations) List<DataSetRegistrationInformation<T>> dataSetRegistrations)
{ {
ArrayList<NewExperiment> experimentRegistrations = new ArrayList<NewExperiment>();
ArrayList<ExperimentUpdatesDTO> experimentUpdates = List<NewExperiment> experimentRegistrations = convertExperimentsToBeRegistered();
List<SampleUpdatesDTO> sampleUpdates = convertSamplesToBeUpdated();
List<NewSample> sampleRegistrations = convertSamplesToBeRegistered();
// experiment updates not yet supported
List<ExperimentUpdatesDTO> experimentUpdates =
new ArrayList<ExperimentUpdatesDTO>(); new ArrayList<ExperimentUpdatesDTO>();
ArrayList<SampleUpdatesDTO> sampleUpdates = new ArrayList<SampleUpdatesDTO>();
ArrayList<NewSample> sampleRegistrations = new ArrayList<NewSample>();
AtomicEntityOperationDetails<T> registrationDetails = AtomicEntityOperationDetails<T> registrationDetails =
new AtomicEntityOperationDetails<T>(experimentUpdates, new AtomicEntityOperationDetails<T>(experimentUpdates,
...@@ -288,6 +316,60 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -288,6 +316,60 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
return registrationDetails; return registrationDetails;
} }
private List<NewExperiment> convertExperimentsToBeRegistered() {
List<NewExperiment> result = new ArrayList<NewExperiment>();
for (Experiment apiExperiment : experimentsToBeRegistered) {
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment = apiExperiment.getExperiment();
NewExperiment newExperiment = new NewExperiment();
newExperiment.setIdentifier(experiment.getIdentifier());
newExperiment.setPermID(experiment.getPermId());
IEntityProperty[] properties =
experiment.getProperties().toArray(new IEntityProperty[0]);
newExperiment.setProperties(properties);
result.add(newExperiment);
}
return result;
}
private List<NewSample> convertSamplesToBeRegistered()
{
List<NewSample> result = new ArrayList<NewSample>();
for (Sample apiSample : samplesToBeRegistered)
{
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample =
apiSample.getSample();
NewSample newSample = new NewSample();
newSample.setIdentifier(sample.getIdentifier());
newSample.setPermID(sample.getPermId());
IEntityProperty[] properties =
sample.getProperties().toArray(new IEntityProperty[0]);
newSample.setProperties(properties);
newSample.setExperimentIdentifier(sample.getExperiment().getIdentifier());
}
return result;
}
private List<SampleUpdatesDTO> convertSamplesToBeUpdated() {
List<SampleUpdatesDTO> result = new ArrayList<SampleUpdatesDTO>();
for (Sample apiSample : samplesToBeRegistered) {
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample =
apiSample.getSample();
List<NewAttachment> attachments = Collections.emptyList();
SampleUpdatesDTO sampleUpdate = new SampleUpdatesDTO(TechId.create(sample), // db id
sample.getProperties(), // List<IEntityProperty>
ExperimentIdentifierFactory.parse(sample.getExperiment().getIdentifier()), // ExperimentIdentifier
attachments, // Collection<NewAttachment>
sample.getModificationDate(), // Sample version
SampleIdentifierFactory.parse(sample.getIdentifier()), // Sample Identifier
sample.getContainer().getIdentifier(), // Container Identifier
null // Parent Identifiers
);
result.add(sampleUpdate);
}
return result;
}
@Override @Override
public boolean isCommitted() public boolean isCommitted()
{ {
......
...@@ -27,6 +27,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; ...@@ -27,6 +27,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
/** /**
* A generic class that represents a data set for the registration API. Can be subclassed. * A generic class that represents a data set for the registration API. Can be subclassed.
...@@ -148,7 +149,7 @@ public class DataSet<T extends DataSetInformation> implements IDataSet ...@@ -148,7 +149,7 @@ public class DataSet<T extends DataSetInformation> implements IDataSet
protected void setExperiment(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment exp) protected void setExperiment(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment exp)
{ {
registrationDetails.getDataSetInformation().setExperiment(exp); registrationDetails.getDataSetInformation().setExperiment(exp);
ExperimentIdentifier experimentId = new ExperimentIdentifier(exp); ExperimentIdentifier experimentId = ExperimentIdentifierFactory.parse(exp.getIdentifier());
registrationDetails.getDataSetInformation().setExperimentIdentifier(experimentId); registrationDetails.getDataSetInformation().setExperimentIdentifier(experimentId);
} }
} }
...@@ -179,7 +179,7 @@ public class DataSetRegistrationTransaction<T extends DataSetInformation> implem ...@@ -179,7 +179,7 @@ public class DataSetRegistrationTransaction<T extends DataSetInformation> implem
{ {
SampleIdentifier sampleIdentifier = SampleIdentifier sampleIdentifier =
new SampleIdentifierFactory(sampleIdentifierString).createIdentifier(); new SampleIdentifierFactory(sampleIdentifierString).createIdentifier();
return new Sample(openBisService.tryGetSampleWithExperiment(sampleIdentifier)); return new SampleImmutable(openBisService.tryGetSampleWithExperiment(sampleIdentifier));
} }
public ISample getSampleForUpdate(String sampleIdentifierString) public ISample getSampleForUpdate(String sampleIdentifierString)
......
...@@ -16,7 +16,13 @@ ...@@ -16,7 +16,13 @@
package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; 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.IExperiment; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/** /**
* Implementation of {@link IExperiment}. * Implementation of {@link IExperiment}.
...@@ -31,6 +37,9 @@ class Experiment extends ExperimentImmutable implements IExperiment ...@@ -31,6 +37,9 @@ class Experiment extends ExperimentImmutable implements IExperiment
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment = getExperiment(); ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment = getExperiment();
experiment.setIdentifier(identifier); experiment.setIdentifier(identifier);
experiment.setPermId(permID); experiment.setPermId(permID);
List<IEntityProperty> properties = new ArrayList<IEntityProperty>();
experiment.setProperties(properties);
} }
@Override @Override
...@@ -39,6 +48,22 @@ class Experiment extends ExperimentImmutable implements IExperiment ...@@ -39,6 +48,22 @@ class Experiment extends ExperimentImmutable implements IExperiment
return false; return false;
} }
public void setCode(String code)
{
getExperiment().setCode(code);
}
public void setPropertyValue(String propertyCode, String propertyValue)
{
EntityHelper.createOrUpdateProperty(getExperiment(), propertyCode, propertyValue);
}
public void setType(String experimentType)
{
ExperimentType type = new ExperimentType();
type.setCode(experimentType);
getExperiment().setExperimentType(type);
}
} }
...@@ -18,6 +18,7 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; ...@@ -18,6 +18,7 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/** /**
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
...@@ -26,14 +27,15 @@ class ExperimentImmutable implements IExperimentImmutable ...@@ -26,14 +27,15 @@ class ExperimentImmutable implements IExperimentImmutable
{ {
private final ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment; private final ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment;
public ExperimentImmutable(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment) public ExperimentImmutable(
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment)
{ {
this.experiment = experiment; this.experiment = experiment;
} }
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment getExperiment() public String getExperimentIdentifier()
{ {
return experiment; return experiment.getIdentifier();
} }
public boolean isExistingExperiment() public boolean isExistingExperiment()
...@@ -51,4 +53,29 @@ class ExperimentImmutable implements IExperimentImmutable ...@@ -51,4 +53,29 @@ class ExperimentImmutable implements IExperimentImmutable
throw new UserFailureException("Experiment does not exist."); throw new UserFailureException("Experiment does not exist.");
} }
} }
public ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment getExperiment()
{
return experiment;
}
public String getPropertyValue(String propertyCode)
{
return EntityHelper.tryFindPropertyValue(experiment, propertyCode);
}
public String getCode()
{
return experiment.getCode();
}
public String getType()
{
if (experiment.getExperimentType() != null)
{
return experiment.getExperimentType().getCode();
}
return null;
}
} }
...@@ -16,40 +16,51 @@ ...@@ -16,40 +16,51 @@
package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.ISample; import ch.systemsx.cisd.etlserver.registrator.api.v1.ISample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/** /**
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
*/ */
public class Sample implements ISample public class Sample extends SampleImmutable implements ISample
{ {
private final ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample;
public Sample(String sampleIdentifier, String permId)
{
super(new ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample());
getSample().setIdentifier(sampleIdentifier);
getSample().setPermId(permId);
}
public Sample(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample) public Sample(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample)
{ {
this.sample = sample; super(sample);
} }
public ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample getSample() public void setExperiment(IExperimentImmutable experiment)
{ {
return sample; ExperimentImmutable exp = (ExperimentImmutable) experiment;
getSample().setExperiment(exp.getExperiment());
} }
public boolean isExistingSample() public void setCode(String code)
{ {
return null != sample; getSample().setCode(code);
} }
/** public void setPropertyValue(String propertyCode, String propertyValue)
* Throw an exception if the sample does not exist
*/
protected void checkExists()
{ {
if (false == isExistingSample()) EntityHelper.createOrUpdateProperty(getSample(), propertyCode, propertyValue);
{ }
throw new UserFailureException("Sample does not exist.");
} public void setType(String type)
{
SampleType sampleType = new SampleType();
sampleType.setCode(type);
getSample().setSampleType(sampleType);
} }
} }
/*
* 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 ch.systemsx.cisd.common.exceptions.UserFailureException;
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.util.EntityHelper;
/**
* @author Chandrasekhar Ramakrishnan
*/
public class SampleImmutable implements ISampleImmutable
{
private final ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample;
public SampleImmutable(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample)
{
this.sample = sample;
}
public IExperimentImmutable getExperiment()
{
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment =
sample.getExperiment();
return (null != experiment) ? new ExperimentImmutable(experiment) : null;
}
public String getSampleIdentifier()
{
return sample.getIdentifier();
}
public String getCode()
{
return sample.getCode();
}
public ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample getSample()
{
return sample;
}
public boolean isExistingSample()
{
return null != sample;
}
/**
* Throw an exception if the sample does not exist
*/
protected void checkExists()
{
if (false == isExistingSample())
{
throw new UserFailureException("Sample does not exist.");
}
}
public String getPropertyValue(String propertyCode)
{
return EntityHelper.tryFindPropertyValue(sample, propertyCode);
}
public String getType()
{
if (sample.getSampleType() != null)
{
return sample.getSampleType().getCode();
}
return null;
}
}
...@@ -34,6 +34,7 @@ import ch.systemsx.cisd.openbis.generic.shared.ResourceNames; ...@@ -34,6 +34,7 @@ import ch.systemsx.cisd.openbis.generic.shared.ResourceNames;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.OpenBisServiceFactory; import ch.systemsx.cisd.openbis.generic.shared.api.v1.OpenBisServiceFactory;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationResult;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance;
...@@ -50,6 +51,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; ...@@ -50,6 +51,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails;
import ch.systemsx.cisd.openbis.generic.shared.dto.ListSamplesByPropertyCriteria; import ch.systemsx.cisd.openbis.generic.shared.dto.ListSamplesByPropertyCriteria;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; 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.NewProperty;
...@@ -465,5 +467,11 @@ public final class EncapsulatedOpenBISService implements IEncapsulatedOpenBISSer ...@@ -465,5 +467,11 @@ public final class EncapsulatedOpenBISService implements IEncapsulatedOpenBISSer
dataSetOrNull.setShareId(Constants.DEFAULT_SHARE_ID); dataSetOrNull.setShareId(Constants.DEFAULT_SHARE_ID);
} }
} }
public AtomicEntityOperationResult performEntityOperations(
AtomicEntityOperationDetails operationDetails)
{
return service.performEntityOperations(session.getToken(), operationDetails);
}
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; ...@@ -23,6 +23,7 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationResult;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance;
...@@ -39,6 +40,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; ...@@ -39,6 +40,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails;
import ch.systemsx.cisd.openbis.generic.shared.dto.ListSamplesByPropertyCriteria; import ch.systemsx.cisd.openbis.generic.shared.dto.ListSamplesByPropertyCriteria;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; 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.NewProperty;
...@@ -367,4 +369,12 @@ public interface IEncapsulatedOpenBISService ...@@ -367,4 +369,12 @@ public interface IEncapsulatedOpenBISService
@ManagedAuthentication @ManagedAuthentication
public Sample updateSampleAndRegisterDataSet(SampleUpdatesDTO newSample, public Sample updateSampleAndRegisterDataSet(SampleUpdatesDTO newSample,
NewExternalData externalData); NewExternalData externalData);
/**
* {@link IETLLIMSService#performEntityOperations(String, AtomicEntityOperationDetails)}
*/
@ManagedAuthentication
public AtomicEntityOperationResult performEntityOperations(
AtomicEntityOperationDetails operationDetails);
} }
\ No newline at end of file
...@@ -65,11 +65,11 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationRe ...@@ -65,11 +65,11 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationRe
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.ExperimentBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.ExperimentBuilder;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData;
import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat; import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
/** /**
...@@ -88,6 +88,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -88,6 +88,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
private static final DataSetType DATA_SET_TYPE = new DataSetType("O1"); private static final DataSetType DATA_SET_TYPE = new DataSetType("O1");
private static final String EXPERIMENT_PERM_ID = "experiment-perm-id";
private JythonTopLevelDataSetHandler<DataSetInformation> handler; private JythonTopLevelDataSetHandler<DataSetInformation> handler;
private Mockery context; private Mockery context;
...@@ -152,9 +154,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -152,9 +154,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
createData(); createData();
ExperimentBuilder builder = new ExperimentBuilder().identifier("/SPACE/PROJECT/EXP"); ExperimentBuilder builder = new ExperimentBuilder().identifier("/SPACE/PROJECT/EXP");
final Experiment experiment = builder.getExperiment(); final Experiment experiment = builder.getExperiment();
final RecordingMatcher<DataSetInformation> dataSetInfo = final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =
new RecordingMatcher<DataSetInformation>(); new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();
final RecordingMatcher<NewExternalData> dataSet = new RecordingMatcher<NewExternalData>();
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
...@@ -167,30 +168,28 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -167,30 +168,28 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE, one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,
new File(new File(stagingDir, DATA_SET_CODE), "sub_data_set_1")); new File(new File(stagingDir, DATA_SET_CODE), "sub_data_set_1"));
one(openBisService).registerDataSet(with(dataSetInfo), with(dataSet)); one(openBisService).performEntityOperations(with(atomicatOperationDetails));
one(openBisService).tryGetDataSet(DATA_SET_CODE); will(returnValue(new AtomicEntityOperationResult()));
ExternalData externalData = new ExternalData();
externalData.setCode(DATA_SET_CODE);
will(returnValue(externalData));
} }
}); });
handler.handle(markerFile); handler.handle(markerFile);
assertEquals(1, MockStorageProcessor.instance.incomingDirs.size()); assertEquals(1, MockStorageProcessor.instance.incomingDirs.size());
assertEquals(DATA_SET_CODE, dataSetInfo.recordedObject().getDataSetCode()); assertEquals(1, atomicatOperationDetails.recordedObject().getDataSetRegistrations().size());
assertEquals(DATA_SET_TYPE, dataSetInfo.recordedObject().getDataSetType());
assertEquals(experiment.getIdentifier(), dataSetInfo.recordedObject() NewExternalData dataSet =
.getExperimentIdentifier().toString()); atomicatOperationDetails.recordedObject().getDataSetRegistrations().get(0);
assertEquals(DATA_SET_CODE, dataSet.recordedObject().getCode());
assertEquals(DATA_SET_TYPE, dataSet.recordedObject().getDataSetType()); assertEquals(DATA_SET_CODE, dataSet.getCode());
assertEquals(DATA_SET_TYPE, dataSet.getDataSetType());
File datasetLocation = File datasetLocation =
DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE, DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID, ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID,
DATABASE_INSTANCE_UUID); DATABASE_INSTANCE_UUID);
assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory, assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID), datasetLocation), dataSet.recordedObject() ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID),
.getLocation()); datasetLocation), dataSet.getLocation());
assertEquals(1, MockStorageProcessor.instance.calledCommitCount); assertEquals(1, MockStorageProcessor.instance.calledCommitCount);
assertEquals(datasetLocation, MockStorageProcessor.instance.rootDirs.get(0)); assertEquals(datasetLocation, MockStorageProcessor.instance.rootDirs.get(0));
File incomingDir = MockStorageProcessor.instance.incomingDirs.get(0); File incomingDir = MockStorageProcessor.instance.incomingDirs.get(0);
...@@ -271,8 +270,9 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -271,8 +270,9 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE, one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,
new File(new File(stagingDir, DATA_SET_CODE), "sub_data_set_1")); new File(new File(stagingDir, DATA_SET_CODE), "sub_data_set_1"));
one(openBisService).registerDataSet(with(new IsAnything<DataSetInformation>()), one(openBisService)
with(new IsAnything<NewExternalData>())); .performEntityOperations(
with(new IsAnything<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>()));
will(throwException(new AssertionError("Fail"))); will(throwException(new AssertionError("Fail")));
} }
}); });
...@@ -300,11 +300,10 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -300,11 +300,10 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
} }
@Test @Test
public void testTwoSimpleTransactions() public void testTwoSimpleDataSets()
{ {
setUpHomeDataBaseExpectations(); setUpHomeDataBaseExpectations();
Properties properties = Properties properties = createThreadProperties(SCRIPTS_FOLDER + "two-simple-datasets.py");
createThreadProperties(SCRIPTS_FOLDER + "two-simple-transactions.py");
final File stagingDir = new File(workingDirectory, "staging"); final File stagingDir = new File(workingDirectory, "staging");
properties.setProperty(DataSetRegistrationService.STAGING_DIR, stagingDir.getPath()); properties.setProperty(DataSetRegistrationService.STAGING_DIR, stagingDir.getPath());
createHandler(properties, false, true); createHandler(properties, false, true);
...@@ -313,12 +312,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -313,12 +312,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
final Experiment experiment1 = builder1.getExperiment(); final Experiment experiment1 = builder1.getExperiment();
ExperimentBuilder builder2 = new ExperimentBuilder().identifier("/SPACE/PROJECT/EXP2"); ExperimentBuilder builder2 = new ExperimentBuilder().identifier("/SPACE/PROJECT/EXP2");
final Experiment experiment2 = builder2.getExperiment(); final Experiment experiment2 = builder2.getExperiment();
final RecordingMatcher<DataSetInformation> dataSetInfo1 = final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> operations =
new RecordingMatcher<DataSetInformation>(); new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();
final RecordingMatcher<NewExternalData> dataSet1 = new RecordingMatcher<NewExternalData>();
final RecordingMatcher<DataSetInformation> dataSetInfo2 =
new RecordingMatcher<DataSetInformation>();
final RecordingMatcher<NewExternalData> dataSet2 = new RecordingMatcher<NewExternalData>();
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
...@@ -332,12 +327,6 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -332,12 +327,6 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE, one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,
new File(new File(stagingDir, DATA_SET_CODE + 1), "sub_data_set_1")); new File(new File(stagingDir, DATA_SET_CODE + 1), "sub_data_set_1"));
one(openBisService).registerDataSet(with(dataSetInfo1), with(dataSet1));
one(openBisService).tryGetDataSet(DATA_SET_CODE + 1);
ExternalData externalData = new ExternalData();
externalData.setCode(DATA_SET_CODE + 1);
will(returnValue(externalData));
one(openBisService).createDataSetCode(); one(openBisService).createDataSetCode();
will(returnValue(DATA_SET_CODE + 2)); will(returnValue(DATA_SET_CODE + 2));
...@@ -349,12 +338,9 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -349,12 +338,9 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE, one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,
new File(new File(stagingDir, DATA_SET_CODE + 2), "sub_data_set_2")); new File(new File(stagingDir, DATA_SET_CODE + 2), "sub_data_set_2"));
one(openBisService).registerDataSet(with(dataSetInfo2), with(dataSet2));
one(openBisService).tryGetDataSet(DATA_SET_CODE + 2); one(openBisService).performEntityOperations(with(operations));
externalData = new ExternalData(); will(returnValue(new AtomicEntityOperationResult()));
externalData.setCode(DATA_SET_CODE + 2);
will(returnValue(externalData));
} }
}); });
...@@ -362,17 +348,21 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -362,17 +348,21 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
assertEquals(2, MockStorageProcessor.instance.incomingDirs.size()); assertEquals(2, MockStorageProcessor.instance.incomingDirs.size());
assertEquals(2, MockStorageProcessor.instance.calledCommitCount); assertEquals(2, MockStorageProcessor.instance.calledCommitCount);
assertEquals(DATA_SET_CODE + 1, dataSetInfo1.recordedObject().getDataSetCode()); assertEquals(2, operations.recordedObject().getDataSetRegistrations().size());
assertEquals(DATA_SET_TYPE, dataSetInfo1.recordedObject().getDataSetType());
assertEquals(experiment1.getIdentifier(), dataSetInfo1.recordedObject() NewExternalData dataSet1 = operations.recordedObject().getDataSetRegistrations().get(0);
.getExperimentIdentifier().toString()); NewExternalData dataSet2 = operations.recordedObject().getDataSetRegistrations().get(1);
assertEquals(DATA_SET_CODE + 1, dataSet1.recordedObject().getCode());
assertEquals(DATA_SET_TYPE, dataSet1.recordedObject().getDataSetType()); assertEquals(experiment1.getIdentifier(), dataSet1.getExperimentIdentifierOrNull()
.toString());
assertEquals(DATA_SET_CODE + 1, dataSet1.getCode());
assertEquals(DATA_SET_TYPE, dataSet1.getDataSetType());
File datasetLocation1 = File datasetLocation1 =
DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE + 1, DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE + 1,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID, DATABASE_INSTANCE_UUID); ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID, DATABASE_INSTANCE_UUID);
assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory, assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID), datasetLocation1), dataSet1.recordedObject() ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID),
datasetLocation1), dataSet1
.getLocation()); .getLocation());
assertEquals(datasetLocation1, MockStorageProcessor.instance.rootDirs.get(0)); assertEquals(datasetLocation1, MockStorageProcessor.instance.rootDirs.get(0));
File incomingDir1 = MockStorageProcessor.instance.incomingDirs.get(0); File incomingDir1 = MockStorageProcessor.instance.incomingDirs.get(0);
...@@ -380,17 +370,16 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -380,17 +370,16 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
incomingDir1); incomingDir1);
assertEquals("hello world1", assertEquals("hello world1",
FileUtilities.loadToString(new File(datasetLocation1, "read1.me")).trim()); FileUtilities.loadToString(new File(datasetLocation1, "read1.me")).trim());
assertEquals(DATA_SET_CODE + 2, dataSetInfo2.recordedObject().getDataSetCode()); assertEquals(experiment2.getIdentifier(), dataSet2.getExperimentIdentifierOrNull()
assertEquals(DATA_SET_TYPE, dataSetInfo2.recordedObject().getDataSetType()); .toString());
assertEquals(experiment2.getIdentifier(), dataSetInfo2.recordedObject() assertEquals(DATA_SET_CODE + 2, dataSet2.getCode());
.getExperimentIdentifier().toString()); assertEquals(DATA_SET_TYPE, dataSet2.getDataSetType());
assertEquals(DATA_SET_CODE + 2, dataSet2.recordedObject().getCode());
assertEquals(DATA_SET_TYPE, dataSet2.recordedObject().getDataSetType());
File datasetLocation2 = File datasetLocation2 =
DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE + 2, DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE + 2,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID, DATABASE_INSTANCE_UUID); ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID, DATABASE_INSTANCE_UUID);
assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory, assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID), datasetLocation2), dataSet2.recordedObject() ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID),
datasetLocation2), dataSet2
.getLocation()); .getLocation());
assertEquals(datasetLocation2, MockStorageProcessor.instance.rootDirs.get(1)); assertEquals(datasetLocation2, MockStorageProcessor.instance.rootDirs.get(1));
File incomingDir2 = MockStorageProcessor.instance.incomingDirs.get(1); File incomingDir2 = MockStorageProcessor.instance.incomingDirs.get(1);
...@@ -427,6 +416,66 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -427,6 +416,66 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
MockStorageProcessor.instance.dataSetInfoString); MockStorageProcessor.instance.dataSetInfoString);
} }
// TODO KE: 2011-02-11 Make this test run
//@Test
public void testTransactionWithNewExperiment()
{
setUpHomeDataBaseExpectations();
Properties properties =
createThreadProperties(SCRIPTS_FOLDER + "transaction-with-new-experiment.py");
final File stagingDir = new File(workingDirectory, "staging");
properties.setProperty(DataSetRegistrationService.STAGING_DIR, stagingDir.getPath());
createHandler(properties, false, true);
createData();
final ExperimentIdentifier experimentIdentifier =
ExperimentIdentifierFactory.parse("/SPACE/PROJECT/EXP");
final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =
new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();
context.checking(new Expectations()
{
{
one(openBisService).createDataSetCode();
will(returnValue(DATA_SET_CODE));
one(openBisService).createDataSetCode();
will(returnValue(EXPERIMENT_PERM_ID));
one(openBisService).tryToGetExperiment(experimentIdentifier);
will(returnValue(null));
one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,
new File(new File(stagingDir, DATA_SET_CODE), "sub_data_set_1"));
one(openBisService).performEntityOperations(with(atomicatOperationDetails));
will(returnValue(new AtomicEntityOperationResult()));
}
});
handler.handle(markerFile);
assertEquals(1, MockStorageProcessor.instance.incomingDirs.size());
assertEquals(1, atomicatOperationDetails.recordedObject().getDataSetRegistrations().size());
NewExternalData dataSet =
atomicatOperationDetails.recordedObject().getDataSetRegistrations().get(0);
assertEquals(DATA_SET_CODE, dataSet.getCode());
assertEquals(DATA_SET_TYPE, dataSet.getDataSetType());
File datasetLocation =
DatasetLocationUtil.getDatasetLocationPath(workingDirectory, DATA_SET_CODE,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID,
DATABASE_INSTANCE_UUID);
assertEquals(FileUtilities.getRelativeFile(new File(workingDirectory,
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID),
datasetLocation),
dataSet.getLocation());
assertEquals(1, MockStorageProcessor.instance.calledCommitCount);
assertEquals(datasetLocation, MockStorageProcessor.instance.rootDirs.get(0));
File incomingDir = MockStorageProcessor.instance.incomingDirs.get(0);
assertEquals(new File(new File(stagingDir, DATA_SET_CODE), "sub_data_set_1"), incomingDir);
context.assertIsSatisfied();
}
@Test @Test
public void testScriptDies() public void testScriptDies()
{ {
......
...@@ -50,13 +50,14 @@ import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; ...@@ -50,13 +50,14 @@ import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable;
import ch.systemsx.cisd.etlserver.validation.IDataSetValidator; import ch.systemsx.cisd.etlserver.validation.IDataSetValidator;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AtomicEntityOperationResult;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails;
import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat; import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
...@@ -157,7 +158,6 @@ public class DataSetRegistrationTransactionTest extends AbstractFileSystemTestCa ...@@ -157,7 +158,6 @@ public class DataSetRegistrationTransactionTest extends AbstractFileSystemTestCa
rollbackQueueFiles = listRollbackQueueFiles(); rollbackQueueFiles = listRollbackQueueFiles();
assertEquals(0, rollbackQueueFiles.length); assertEquals(0, rollbackQueueFiles.length);
// Commented out for the moment.
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
...@@ -365,14 +365,15 @@ public class DataSetRegistrationTransactionTest extends AbstractFileSystemTestCa ...@@ -365,14 +365,15 @@ public class DataSetRegistrationTransactionTest extends AbstractFileSystemTestCa
.createIdentifier()); .createIdentifier());
will(returnValue(experiment)); will(returnValue(experiment));
exactly(1).of(openBisService).registerDataSet( exactly(1).of(openBisService).performEntityOperations(
with(any(DataSetInformation.class)), with(any(AtomicEntityOperationDetails.class)));
with(any(NewExternalData.class))); will(returnValue(new AtomicEntityOperationResult()));
} }
} }
}); });
} }
private void setUpDataSetValidatorExpectations() private void setUpDataSetValidatorExpectations()
{ {
File dataSetDir = new File(stagingDirectory, DATA_SET_CODE + "1"); File dataSetDir = new File(stagingDirectory, DATA_SET_CODE + "1");
......
...@@ -2,5 +2,9 @@ transaction = service.transaction(incoming, factory) ...@@ -2,5 +2,9 @@ transaction = service.transaction(incoming, factory)
dataSet = transaction.createNewDataSet() dataSet = transaction.createNewDataSet()
transaction.moveFile(incoming.getPath() + '/sub_data_set_1', dataSet) transaction.moveFile(incoming.getPath() + '/sub_data_set_1', dataSet)
dataSet.setDataSetType('O1') dataSet.setDataSetType('O1')
dataSet.setExperiment(transaction.createNewExperiment('/SPACE/PROJECT/EXP'))
experiment = transaction.createNewExperiment('/SPACE/PROJECT/EXP')
experiment.setPropertyValue('propCode', 'propValue')
dataSet.setExperiment(experiment)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment