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

LMS-2033 Fixed problems when experiment is registered in the same transaction.

SVN: 19921
parent 44ba6fe3
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ public final class IdentifiedDataStrategy implements IDataStoreStrategy ...@@ -40,7 +40,7 @@ public final class IdentifiedDataStrategy implements IDataStoreStrategy
static final String STORAGE_LAYOUT_ERROR_MSG_PREFIX = "Serious error in data store layout: "; static final String STORAGE_LAYOUT_ERROR_MSG_PREFIX = "Serious error in data store layout: ";
IdentifiedDataStrategy() public IdentifiedDataStrategy()
{ {
} }
......
...@@ -26,6 +26,7 @@ import ch.systemsx.cisd.etlserver.DataSetRegistrationAlgorithm; ...@@ -26,6 +26,7 @@ import ch.systemsx.cisd.etlserver.DataSetRegistrationAlgorithm;
import ch.systemsx.cisd.etlserver.DataSetRegistrationAlgorithm.DataSetRegistrationAlgorithmState; import ch.systemsx.cisd.etlserver.DataSetRegistrationAlgorithm.DataSetRegistrationAlgorithmState;
import ch.systemsx.cisd.etlserver.DataSetRegistrationAlgorithmRunner; import ch.systemsx.cisd.etlserver.DataSetRegistrationAlgorithmRunner;
import ch.systemsx.cisd.etlserver.IDataStoreStrategy; import ch.systemsx.cisd.etlserver.IDataStoreStrategy;
import ch.systemsx.cisd.etlserver.IdentifiedDataStrategy;
import ch.systemsx.cisd.etlserver.TopLevelDataSetRegistratorGlobalState; import ch.systemsx.cisd.etlserver.TopLevelDataSetRegistratorGlobalState;
import ch.systemsx.cisd.etlserver.registrator.AbstractOmniscientTopLevelDataSetRegistrator.OmniscientTopLevelDataSetRegistratorState; import ch.systemsx.cisd.etlserver.registrator.AbstractOmniscientTopLevelDataSetRegistrator.OmniscientTopLevelDataSetRegistratorState;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetRegistrationTransaction; import ch.systemsx.cisd.etlserver.registrator.api.v1.IDataSetRegistrationTransaction;
...@@ -213,6 +214,28 @@ public class DataSetRegistrationService<T extends DataSetInformation> implements ...@@ -213,6 +214,28 @@ public class DataSetRegistrationService<T extends DataSetInformation> implements
return algorithm; return algorithm;
} }
/**
* Create a storage algorithm for storing an individual data set, bypassing the detection of
* whether the data set's owner is in the db. This is used if the owner will be registered in
* the same transaction. This is internally used by transactions. Other clients may find it
* useful as well.
*/
public DataSetStorageAlgorithm<T> createStorageAlgorithmWithIdentifiedStrategy(
File dataSetFile, DataSetRegistrationDetails<T> dataSetDetails)
{
TopLevelDataSetRegistratorGlobalState globalContext = registratorContext.getGlobalState();
T dataSetInformation = dataSetDetails.getDataSetInformation();
dataSetInformation.setShareId(globalContext.getShareId());
IDataStoreStrategy strategy = new IdentifiedDataStrategy();
DataSetStorageAlgorithm<T> algorithm =
new DataSetStorageAlgorithm<T>(dataSetFile, dataSetDetails, strategy,
registratorContext.getStorageProcessor(),
globalContext.getDataSetValidator(), globalContext.getDssCode(),
registratorContext.getFileOperations(), globalContext.getMailClient());
return algorithm;
}
public IEntityOperationService<T> getEntityRegistrationService() public IEntityOperationService<T> getEntityRegistrationService()
{ {
return new DefaultEntityOperationService<T>(registrator); return new DefaultEntityOperationService<T>(registrator);
......
...@@ -260,7 +260,16 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -260,7 +260,16 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
{ {
File contents = dataSet.getDataSetContents(); File contents = dataSet.getDataSetContents();
DataSetRegistrationDetails<T> details = dataSet.getRegistrationDetails(); DataSetRegistrationDetails<T> details = dataSet.getRegistrationDetails();
algorithms.add(registrationService.createStorageAlgorithm(contents, details));
// The experiment does not yet exist
if (experimentsToBeRegistered.contains(dataSet.getExperiment()))
{
algorithms.add(registrationService
.createStorageAlgorithmWithIdentifiedStrategy(contents, details));
} else
{
algorithms.add(registrationService.createStorageAlgorithm(contents, details));
}
} }
DataSetStorageAlgorithmRunner<T> runner = DataSetStorageAlgorithmRunner<T> runner =
...@@ -306,20 +315,21 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -306,20 +315,21 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
List<NewSample> sampleRegistrations = convertSamplesToBeRegistered(); List<NewSample> sampleRegistrations = convertSamplesToBeRegistered();
// experiment updates not yet supported // experiment updates not yet supported
List<ExperimentUpdatesDTO> experimentUpdates = List<ExperimentUpdatesDTO> experimentUpdates = new ArrayList<ExperimentUpdatesDTO>();
new ArrayList<ExperimentUpdatesDTO>();
AtomicEntityOperationDetails<T> registrationDetails = AtomicEntityOperationDetails<T> registrationDetails =
new AtomicEntityOperationDetails<T>(experimentUpdates, new AtomicEntityOperationDetails<T>(experimentUpdates, experimentRegistrations,
experimentRegistrations, sampleUpdates, sampleRegistrations, sampleUpdates, sampleRegistrations, dataSetRegistrations);
dataSetRegistrations);
return registrationDetails; return registrationDetails;
} }
private List<NewExperiment> convertExperimentsToBeRegistered() { private List<NewExperiment> convertExperimentsToBeRegistered()
{
List<NewExperiment> result = new ArrayList<NewExperiment>(); List<NewExperiment> result = new ArrayList<NewExperiment>();
for (Experiment apiExperiment : experimentsToBeRegistered) { for (Experiment apiExperiment : experimentsToBeRegistered)
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment = apiExperiment.getExperiment(); {
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment experiment =
apiExperiment.getExperiment();
NewExperiment newExperiment = new NewExperiment(); NewExperiment newExperiment = new NewExperiment();
newExperiment.setIdentifier(experiment.getIdentifier()); newExperiment.setIdentifier(experiment.getIdentifier());
newExperiment.setPermID(experiment.getPermId()); newExperiment.setPermID(experiment.getPermId());
...@@ -349,12 +359,14 @@ abstract class AbstractTransactionState<T extends DataSetInformation> ...@@ -349,12 +359,14 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
return result; return result;
} }
private List<SampleUpdatesDTO> convertSamplesToBeUpdated() { private List<SampleUpdatesDTO> convertSamplesToBeUpdated()
{
List<SampleUpdatesDTO> result = new ArrayList<SampleUpdatesDTO>(); List<SampleUpdatesDTO> result = new ArrayList<SampleUpdatesDTO>();
for (Sample apiSample : samplesToBeRegistered) { for (Sample apiSample : samplesToBeRegistered)
{
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample = ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample =
apiSample.getSample(); apiSample.getSample();
List<NewAttachment> attachments = Collections.emptyList(); List<NewAttachment> attachments = Collections.emptyList();
SampleUpdatesDTO sampleUpdate = new SampleUpdatesDTO(TechId.create(sample), // db id SampleUpdatesDTO sampleUpdate = new SampleUpdatesDTO(TechId.create(sample), // db id
sample.getProperties(), // List<IEntityProperty> sample.getProperties(), // List<IEntityProperty>
......
...@@ -359,11 +359,11 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -359,11 +359,11 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
assertEquals(DATA_SET_TYPE, dataSet1.getDataSetType()); 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), ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID),
datasetLocation1), dataSet1 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);
assertEquals(new File(new File(stagingDir, DATA_SET_CODE + 1), "sub_data_set_1"), assertEquals(new File(new File(stagingDir, DATA_SET_CODE + 1), "sub_data_set_1"),
...@@ -376,11 +376,11 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -376,11 +376,11 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
assertEquals(DATA_SET_TYPE, dataSet2.getDataSetType()); assertEquals(DATA_SET_TYPE, dataSet2.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), ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID),
datasetLocation2), dataSet2 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);
assertEquals(new File(new File(stagingDir, DATA_SET_CODE + 2), "sub_data_set_2"), assertEquals(new File(new File(stagingDir, DATA_SET_CODE + 2), "sub_data_set_2"),
...@@ -416,8 +416,7 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -416,8 +416,7 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
MockStorageProcessor.instance.dataSetInfoString); MockStorageProcessor.instance.dataSetInfoString);
} }
// TODO KE: 2011-02-11 Make this test run @Test
//@Test
public void testTransactionWithNewExperiment() public void testTransactionWithNewExperiment()
{ {
setUpHomeDataBaseExpectations(); setUpHomeDataBaseExpectations();
...@@ -427,8 +426,6 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -427,8 +426,6 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
properties.setProperty(DataSetRegistrationService.STAGING_DIR, stagingDir.getPath()); properties.setProperty(DataSetRegistrationService.STAGING_DIR, stagingDir.getPath());
createHandler(properties, false, true); createHandler(properties, false, true);
createData(); createData();
final ExperimentIdentifier experimentIdentifier =
ExperimentIdentifierFactory.parse("/SPACE/PROJECT/EXP");
final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails = final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =
new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>(); new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();
context.checking(new Expectations() context.checking(new Expectations()
...@@ -440,9 +437,6 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -440,9 +437,6 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
one(openBisService).createDataSetCode(); one(openBisService).createDataSetCode();
will(returnValue(EXPERIMENT_PERM_ID)); will(returnValue(EXPERIMENT_PERM_ID));
one(openBisService).tryToGetExperiment(experimentIdentifier);
will(returnValue(null));
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).performEntityOperations(with(atomicatOperationDetails)); one(openBisService).performEntityOperations(with(atomicatOperationDetails));
...@@ -725,7 +719,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest ...@@ -725,7 +719,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractFileSystemTest
new ThreadParameters(threadProperties, "jython-handler-test"); new ThreadParameters(threadProperties, "jython-handler-test");
TopLevelDataSetRegistratorGlobalState globalState = TopLevelDataSetRegistratorGlobalState globalState =
new TopLevelDataSetRegistratorGlobalState("dss", ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID, new TopLevelDataSetRegistratorGlobalState("dss",
ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID,
workingDirectory, openBisService, mailClient, dataSetValidator, true, workingDirectory, openBisService, mailClient, dataSetValidator, true,
threadParameters); threadParameters);
return globalState; return globalState;
......
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