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

LMS-1502 Import CINA bundle data sets, with sub-data sets referencing the...

LMS-1502 Import CINA bundle data sets, with sub-data sets referencing the original using hard links.

SVN: 16371
parent 5cbe51c8
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,15 @@ public interface IDataSetHandlerRpc extends IDataSetHandler ...@@ -41,6 +41,15 @@ public interface IDataSetHandlerRpc extends IDataSetHandler
public List<DataSetInformation> handleDataSet(final File dataSet, public List<DataSetInformation> handleDataSet(final File dataSet,
final DataSetInformation template); final DataSetInformation template);
/**
* Create a (hard) link to an file or folder within an existing data set and handle that.
*
* @param dataSetComponent A file within a data set
* @param template A template containing information for the data sets to register
*/
public List<DataSetInformation> linkAndHandleDataSet(File dataSetComponent,
DataSetInformation template);
/** /**
* Returns the session context for the current user. * Returns the session context for the current user.
*/ */
......
...@@ -32,8 +32,10 @@ import org.apache.log4j.Logger; ...@@ -32,8 +32,10 @@ import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.common.filesystem.FastRecursiveHardLinkMaker;
import ch.systemsx.cisd.common.filesystem.FileOperations; import ch.systemsx.cisd.common.filesystem.FileOperations;
import ch.systemsx.cisd.common.filesystem.IFileOperations; import ch.systemsx.cisd.common.filesystem.IFileOperations;
import ch.systemsx.cisd.common.filesystem.IImmutableCopier;
import ch.systemsx.cisd.common.io.ConcatenatedFileOutputStreamWriter; import ch.systemsx.cisd.common.io.ConcatenatedFileOutputStreamWriter;
import ch.systemsx.cisd.common.mail.IMailClient; import ch.systemsx.cisd.common.mail.IMailClient;
import ch.systemsx.cisd.common.utilities.IDelegatedActionWithResult; import ch.systemsx.cisd.common.utilities.IDelegatedActionWithResult;
...@@ -92,6 +94,8 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -92,6 +94,8 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
private final IDataSetHandler handler; private final IDataSetHandler handler;
private final IImmutableCopier copier;
private DataSetInformation override; private DataSetInformation override;
PutDataSetExecutor(PutDataSetService service, IETLServerPlugin plugin, String sessionToken, PutDataSetExecutor(PutDataSetService service, IETLServerPlugin plugin, String sessionToken,
...@@ -102,6 +106,7 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -102,6 +106,7 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
this.sessionToken = sessionToken; this.sessionToken = sessionToken;
this.newDataSet = newDataSet; this.newDataSet = newDataSet;
this.inputStream = inputStream; this.inputStream = inputStream;
this.copier = FastRecursiveHardLinkMaker.tryCreate();
this.dataSetDir = new File(service.getIncomingDir(), newDataSet.getDataSetFolderName()); this.dataSetDir = new File(service.getIncomingDir(), newDataSet.getDataSetFolderName());
if (dataSetDir.exists()) if (dataSetDir.exists())
{ {
...@@ -166,7 +171,7 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -166,7 +171,7 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
override = newOverride; override = newOverride;
} }
RegistrationHelper helper = new RegistrationHelper(service, plugin, dataSetDir); RegistrationHelper helper = new RegistrationHelper(service, plugin, dataSet);
helper.prepare(); helper.prepare();
if (helper.hasDataSetBeenIdentified()) if (helper.hasDataSetBeenIdentified())
{ {
...@@ -183,11 +188,48 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -183,11 +188,48 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
return Collections.singletonList(helper.getDataSetInformation()); return Collections.singletonList(helper.getDataSetInformation());
} }
public List<DataSetInformation> linkAndHandleDataSet(File dataSetComponent,
DataSetInformation newOverride)
{
File incomingDir = service.getIncomingDir();
// Make a hard link to the file within the data set
boolean success;
success = copier.copyImmutably(dataSetComponent, incomingDir, null);
if (success == false)
{
throw new EnvironmentFailureException("Couldn't create a hard-link copy of '"
+ dataSetComponent.getAbsolutePath() + "' in folder '"
+ service.getIncomingDir().getAbsolutePath() + "'.");
}
File linkedFile = new File(incomingDir, dataSetComponent.getName());
// Register the component of the data set
try
{
return handleDataSet(linkedFile, newOverride);
} finally
{
deleteDir(linkedFile);
}
}
public SessionContextDTO getSessionContext() public SessionContextDTO getSessionContext()
{ {
return getOpenBisService().tryGetSession(sessionToken); return getOpenBisService().tryGetSession(sessionToken);
} }
public File getFileForExternalData(ExternalData externalData)
{
File dataSetFile = new File(service.getStoreRootDirectory(), externalData.getLocation());
return DefaultStorageProcessor.getOriginalDirectory(dataSetFile);
}
public String getDataStoreCode()
{
return service.getDataStoreCode();
}
private void createDefaultOverride() private void createDefaultOverride()
{ {
override = new DataSetInformation(); override = new DataSetInformation();
...@@ -251,10 +293,15 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -251,10 +293,15 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
} }
private void deleteDataSetDir() private void deleteDataSetDir()
{
deleteDir(dataSetDir);
}
private void deleteDir(File dirToDelete)
{ {
try try
{ {
FileUtils.deleteDirectory(dataSetDir); FileUtils.deleteDirectory(dirToDelete);
} catch (IOException ex) } catch (IOException ex)
{ {
getOperationLog().error("Could not delete data set directory " + dataSetDir, ex); getOperationLog().error("Could not delete data set directory " + dataSetDir, ex);
...@@ -529,7 +576,7 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -529,7 +576,7 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
// Override / extend information extracted with our override // Override / extend information extracted with our override
dataSetInfo.setExperimentIdentifier(override.getExperimentIdentifier()); dataSetInfo.setExperimentIdentifier(override.getExperimentIdentifier());
SampleIdentifier sampleIdOrNull = dataSetInfo.getSampleIdentifier(); SampleIdentifier sampleIdOrNull = override.getSampleIdentifier();
if (sampleIdOrNull != null) if (sampleIdOrNull != null)
{ {
dataSetInfo.setSampleCode(sampleIdOrNull.getSampleCode()); dataSetInfo.setSampleCode(sampleIdOrNull.getSampleCode());
...@@ -552,10 +599,4 @@ class PutDataSetExecutor implements IDataSetHandlerRpc ...@@ -552,10 +599,4 @@ class PutDataSetExecutor implements IDataSetHandlerRpc
return dataSetInfo; return dataSetInfo;
} }
} }
public File getFileForExternalData(ExternalData externalData)
{
File dataSetFile = new File(service.getStoreRootDirectory(), externalData.getLocation());
return DefaultStorageProcessor.getOriginalDirectory(dataSetFile);
}
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package ch.systemsx.cisd.cina.dss.bundle; package ch.systemsx.cisd.cina.dss.bundle;
import java.io.File; import java.io.File;
import java.util.Collections;
import ch.systemsx.cisd.cina.shared.metadata.BundleMetadataExtractor; import ch.systemsx.cisd.cina.shared.metadata.BundleMetadataExtractor;
import ch.systemsx.cisd.cina.shared.metadata.ImageMetadataExtractor; import ch.systemsx.cisd.cina.shared.metadata.ImageMetadataExtractor;
...@@ -81,7 +82,6 @@ class BundleDataSetHelperRpc extends BundleDataSetHelper ...@@ -81,7 +82,6 @@ class BundleDataSetHelperRpc extends BundleDataSetHelper
BundleMetadataExtractor bundleMetadata = new BundleMetadataExtractor(bundle); BundleMetadataExtractor bundleMetadata = new BundleMetadataExtractor(bundle);
bundleMetadata.prepare(); bundleMetadata.prepare();
System.out.println(bundleMetadata.getMetadataExtractors());
for (ReplicaMetadataExtractor replicaMetadata : bundleMetadata.getMetadataExtractors()) for (ReplicaMetadataExtractor replicaMetadata : bundleMetadata.getMetadataExtractors())
{ {
handleDerivedDataSets(replicaMetadata); handleDerivedDataSets(replicaMetadata);
...@@ -145,18 +145,27 @@ class BundleDataSetHelperRpc extends BundleDataSetHelper ...@@ -145,18 +145,27 @@ class BundleDataSetHelperRpc extends BundleDataSetHelper
{ {
// Register a data set for the image // Register a data set for the image
File imageDataSet = imageMetadata.getFolder(); File imageDataSet = imageMetadata.getFolder();
IDataSetHandler delegator = getDelegator(); DataSetInformation imageDataSetInfo = new DataSetInformation();
if (delegator instanceof IDataSetHandlerRpc) imageDataSetInfo.setSampleCode(sampleId.getSampleCode());
{ imageDataSetInfo.setSpaceCode(sampleId.getSpaceLevel().getSpaceCode());
DataSetInformation template = new DataSetInformation(); imageDataSetInfo.setInstanceCode(sampleId.getSpaceLevel().getDatabaseInstanceCode());
template.setSampleCode(sampleId.getSampleCode()); imageDataSetInfo.setDataSetType(globalState.getImageDataSetType().getDataSetType());
template.setSpaceCode(sampleId.getSpaceLevel().getSpaceCode()); imageDataSetInfo.setParentDataSetCodes(Collections.singletonList(getBigDataSetInformation()
template.setInstanceCode(sampleId.getSpaceLevel().getDatabaseInstanceCode()); .getDataSetCode()));
// ((IDataSetHandlerRpc) delegator).handleDataSet(imageDataSet, template);
} else // NewExternalData data = new NewExternalData();
{ // data.setExtractableData(imageDataSetInfo.getExtractableData());
delegator.handleDataSet(imageDataSet); // data.setLocatorType(new LocatorType(LocatorType.DEFAULT_LOCATOR_TYPE_CODE));
} // data.setDataSetType(imageDataSetInfo.getDataSetType());
// data.setFileFormatType(new FileFormatType(FileFormatType.DEFAULT_FILE_FORMAT_TYPE_CODE));
// data.setMeasured(true);
// data.setDataStoreCode(delegatorRpc.getDataStoreCode());
// data.setComplete(BooleanOrUnknown.T);
// data.setLocation(delegatorRpc.getStoreRelativePath(imageDataSet));
// data.setStorageFormat(StorageFormat.PROPRIETARY);
// getOpenbisService().registerDataSet(imageDataSetInfo, data);
delegatorRpc.linkAndHandleDataSet(imageDataSet, imageDataSetInfo);
} }
/** /**
......
...@@ -89,8 +89,6 @@ public class BundleMetadataExtractor ...@@ -89,8 +89,6 @@ public class BundleMetadataExtractor
return; return;
} }
System.out.println(file);
if (false == ReplicaMetadataExtractor.doesFolderContainReplicaMetadata(file)) if (false == ReplicaMetadataExtractor.doesFolderContainReplicaMetadata(file))
{ {
return; return;
......
...@@ -91,11 +91,11 @@ public class CinaBundleDataSetHandlerTest extends AbstractFileSystemTestCase ...@@ -91,11 +91,11 @@ public class CinaBundleDataSetHandlerTest extends AbstractFileSystemTestCase
{ {
final DataSetInformation dataSetInformation = new DataSetInformation(); final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode("Derived"); dataSetInformation.setDataSetCode("Derived");
dataSetInformation.setSampleCode("2"); dataSetInformation.setSampleCode("" + uniqueId++);
dataSetInformation.setSpaceCode("Space"); dataSetInformation.setSpaceCode("Space");
dataSetInformation.setInstanceCode("Test"); dataSetInformation.setInstanceCode("Test");
allowing(delegator).handleDataSet(with(new File(path)), allowing(delegator).linkAndHandleDataSet(with(new File(path)),
with(any(DataSetInformation.class))); with(any(DataSetInformation.class)));
will(returnValue(Collections.singletonList(dataSetInformation))); will(returnValue(Collections.singletonList(dataSetInformation)));
} }
......
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