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

LMS-1502 Work on handling CINA bundle data sets.

SVN: 16335
parent d2528bf8
No related branches found
No related tags found
No related merge requests found
Showing
with 316 additions and 36 deletions
......@@ -19,7 +19,6 @@ package ch.systemsx.cisd.cina.dss;
import java.io.File;
import java.util.Properties;
import ch.systemsx.cisd.cina.dss.info.EntityRegistrationSuccessEmail;
import ch.systemsx.cisd.common.mail.IMailClient;
import ch.systemsx.cisd.etlserver.AbstractDelegatingStorageProcessor;
import ch.systemsx.cisd.etlserver.IStorageProcessor;
......@@ -35,18 +34,9 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
*/
public class StorageProcessor extends AbstractDelegatingStorageProcessor
{
private String defaultEmailAddress = "root@localhost";
private static final String DEFAULT_EMAIL_ADDRESS_KEY = "default-email";
public StorageProcessor(Properties properties)
{
super(properties);
if (properties.containsKey(DEFAULT_EMAIL_ADDRESS_KEY))
{
defaultEmailAddress = properties.getProperty(DEFAULT_EMAIL_ADDRESS_KEY);
}
}
public StorageProcessor(IStorageProcessor delegatedProcessor)
......@@ -59,25 +49,10 @@ public class StorageProcessor extends AbstractDelegatingStorageProcessor
final ITypeExtractor typeExtractor, final IMailClient mailClient,
final File incomingDataSetDirectory, final File rootDir)
{
// Create the email first because the email looks into the directory to determine its
// content.
EntityRegistrationSuccessEmail successEmail =
new EntityRegistrationSuccessEmail(dataSetInformation, incomingDataSetDirectory);
File answer =
super.storeData(dataSetInformation, typeExtractor, mailClient,
incomingDataSetDirectory, rootDir);
String emailAddress = dataSetInformation.tryGetUploadingUserEmail();
if (emailAddress == null)
{
emailAddress = defaultEmailAddress;
}
mailClient.sendMessageWithAttachment(successEmail.getSubject(), successEmail
.getContentMimeText(), successEmail.getContentMimeAttachmentFileName(),
successEmail.getContentMimeAttachmentContent(), null, null, emailAddress);
return answer;
}
......
/*
* Copyright 2010 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.cina.dss.bundle;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import ch.systemsx.cisd.cina.shared.metadata.BundleMetadataExtractor;
import ch.systemsx.cisd.cina.shared.metadata.ImageMetadataExtractor;
import ch.systemsx.cisd.cina.shared.metadata.ReplicaMetadataExtractor;
import ch.systemsx.cisd.etlserver.IDataSetHandler;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
/**
* Helper class for processing bundle data sets.
*
* @author Chandrasekhar Ramakrishnan
*/
class BundleDataSetHelper
{
static class BundleRegistrationGlobalState
{
private final IDataSetHandler delegator;
private final IEncapsulatedOpenBISService openbisService;
private final SampleType replicaSampleType;
private final DataSetTypeWithVocabularyTerms imageDataSetType;
BundleRegistrationGlobalState(IDataSetHandler delegator,
IEncapsulatedOpenBISService openbisService, SampleType replicaSampleType,
DataSetTypeWithVocabularyTerms imageDataSetType)
{
this.delegator = delegator;
this.openbisService = openbisService;
this.replicaSampleType = replicaSampleType;
this.imageDataSetType = imageDataSetType;
}
IDataSetHandler getDelegator()
{
return delegator;
}
IEncapsulatedOpenBISService getOpenbisService()
{
return openbisService;
}
SampleType getReplicaSampleType()
{
return replicaSampleType;
}
DataSetTypeWithVocabularyTerms getImageDataSetType()
{
return imageDataSetType;
}
}
private final BundleRegistrationGlobalState globalState;
// Invocation-specific State
private final String sessionOwnerUserId;
private final File dataSet;
private final ArrayList<DataSetInformation> dataSetInformation;
BundleDataSetHelper(BundleRegistrationGlobalState globalState, String sessionOwnerUserId,
File dataSet)
{
this.globalState = globalState;
this.sessionOwnerUserId = sessionOwnerUserId;
this.dataSet = dataSet;
this.dataSetInformation = new ArrayList<DataSetInformation>();
}
/**
*
*/
public void process()
{
// Register the bundle as one data set
List<DataSetInformation> bigDataSet = getDelegator().handleDataSet(dataSet);
dataSetInformation.addAll(bigDataSet);
if (dataSetInformation.isEmpty())
{
return;
}
BundleMetadataExtractor bundleMetadata = new BundleMetadataExtractor(dataSet);
for (ReplicaMetadataExtractor replicaMetadata : bundleMetadata.getMetadataExtractors())
{
handleDerivedDataSets(replicaMetadata);
}
}
/**
* Get all the data set information that has been created as a result of {@link #process}. Only
* makes sense to invoke after process has been called
*/
public ArrayList<DataSetInformation> getDataSetInformation()
{
return dataSetInformation;
}
private void handleDerivedDataSets(ReplicaMetadataExtractor replicaMetadata)
{
SampleType replicaSampleType = globalState.getReplicaSampleType();
long sampleCodeSuffix = getOpenbisService().drawANewUniqueID();
String sampleCode =
String.format("%s%d", replicaSampleType.getGeneratedCodePrefix(), sampleCodeSuffix);
SampleIdentifier parentIdentifier = getBigDataSetInformation().getSampleIdentifier();
// Register a sample with this ID of type GRID_REPLICA, derived from the GRID_TEMPLATE
// registered by the client
SampleIdentifier identifier =
new SampleIdentifier(parentIdentifier.getSpaceLevel(), sampleCode);
NewSample sample =
new NewSample(identifier.toString(), replicaSampleType,
parentIdentifier.toString(), "");
getOpenbisService().registerSample(sample, sessionOwnerUserId);
// Register all the data sets derived from this sample
for (ImageMetadataExtractor imageMetadata : replicaMetadata.getMetadataExtractors())
{
handleDerivedDataSet(identifier.toString(), imageMetadata);
}
}
private void handleDerivedDataSet(String sampleId, ImageMetadataExtractor imageMetadata)
{
// Register a data set for the image
}
/**
* Get the "big data set" -- the one that is the parent of all the derived data sets I register
*/
private DataSetInformation getBigDataSetInformation()
{
// The big data set is the first one registered.
return dataSetInformation.get(0);
}
private IDataSetHandler getDelegator()
{
return globalState.getDelegator();
}
private IEncapsulatedOpenBISService getOpenbisService()
{
return globalState.getOpenbisService();
}
}
/*
* Copyright 2010 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.cina.dss.bundle;
import java.io.File;
import java.util.List;
import java.util.Properties;
import ch.systemsx.cisd.cina.dss.bundle.BundleDataSetHelper.BundleRegistrationGlobalState;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
import ch.systemsx.cisd.etlserver.IDataSetHandler;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
/**
* @author Chandrasekhar Ramakrishnan
*/
public class CinaBundleDataSetHandler implements IDataSetHandler
{
private final IDataSetHandler delegator;
private final IEncapsulatedOpenBISService openbisService;
private final BundleRegistrationGlobalState bundleRegistrationGlobalState;
public CinaBundleDataSetHandler(Properties parentProperties, IDataSetHandler delegator,
IEncapsulatedOpenBISService openbisService)
{
this.delegator = delegator;
this.openbisService = openbisService;
this.bundleRegistrationGlobalState = createBundleRegistrationGlobalState();
}
public List<DataSetInformation> handleDataSet(File dataSet)
{
BundleDataSetHelper helper =
new BundleDataSetHelper(bundleRegistrationGlobalState, null, dataSet);
helper.process();
return helper.getDataSetInformation();
}
private BundleRegistrationGlobalState createBundleRegistrationGlobalState()
{
SampleType replicaSampleType =
openbisService.getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
DataSetTypeWithVocabularyTerms imageDataSetType =
openbisService.getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
return new BundleRegistrationGlobalState(delegator, openbisService, replicaSampleType,
imageDataSetType);
}
}
......@@ -17,6 +17,7 @@
package ch.systemsx.cisd.cina.dss.bundle;
import java.io.File;
import java.util.Properties;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
......@@ -29,14 +30,19 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
*
* @author Chandrasekhar Ramakrishnan
*/
public class CinaDataSetInfoExtractor implements IDataSetInfoExtractor
public class CinaBundleDataSetInfoExtractor implements IDataSetInfoExtractor
{
public CinaBundleDataSetInfoExtractor(final Properties globalProperties)
{
}
public DataSetInformation getDataSetInformation(File incomingDataSetPath,
IEncapsulatedOpenBISService openbisService) throws UserFailureException,
EnvironmentFailureException
{
return new DataSetInformation();
}
DataSetInformation result = new DataSetInformation();
return result;
}
}
......@@ -17,7 +17,9 @@
package ch.systemsx.cisd.cina.dss.bundle;
import java.io.File;
import java.util.Properties;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
import ch.systemsx.cisd.etlserver.ITypeExtractor;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType;
......@@ -26,13 +28,16 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.LocatorType;
/**
* @author Chandrasekhar Ramakrishnan
*/
public class CinaTypeExtractor implements ITypeExtractor
public class CinaBundleTypeExtractor implements ITypeExtractor
{
private static final String BUNDLE_DATA_SET_TYPE = "BUNDLE";
public CinaBundleTypeExtractor(final Properties properties)
{
}
public DataSetType getDataSetType(File incomingDataSetPath)
{
return new DataSetType(BUNDLE_DATA_SET_TYPE);
return new DataSetType(CinaConstants.BUNDLE_DATA_SET_TYPE_CODE);
}
public FileFormatType getFileFormatType(File incomingDataSetPath)
......
......@@ -36,7 +36,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
/**
* CINA uses the data store server to register experiments and samples in addition to data sets. The
* CinaDataSetInfoExtractor follows the conventions agreed to by the CINA project to determine if
* CinaBundleDataSetInfoExtractor follows the conventions agreed to by the CINA project to determine if
* the file represents an experiment, sample, or data set and takes according action.
* <p>
* In the case of data representing experiments and samples, the extractor may need to register the
......
/*
* Copyright 2010 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.cina.shared.constants;
/**
* @author Chandrasekhar Ramakrishnan
*/
public class CinaConstants
{
public static final String BUNDLE_DATA_SET_TYPE_CODE = "BUNDLE";
public static final String IMAGE_DATA_SET_TYPE_CODE = "IMAGE";
public final static String REPLICA_SAMPLE_TYPE_CODE = "GRID_REPLICA";
public static final String DIMENSION_PREFIX = "Dimension";
public static final String SIZE_PREFIX = "Size";
// No need to instantiate this class
private CinaConstants()
{
}
}
......@@ -20,6 +20,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.Map;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
import ch.systemsx.cisd.cina.shared.labview.LVData;
import ch.systemsx.cisd.cina.shared.labview.LVDataParser;
......@@ -36,14 +37,14 @@ public class ImageMetadataExtractor
private LVData lvdata;
private static final String METADATA_FILE_NAME = "metadata.xml";
private final static String METADATA_FILE_NAME = "metadata.xml";
private static final HashMap<String, String> prefixMap;
private final static HashMap<String, String> prefixMap;
static
{
prefixMap = new HashMap<String, String>();
prefixMap.put("Pixelsize (nm)", "Size");
prefixMap.put("Image dimension (px)", "Dimension");
prefixMap.put("Pixelsize (nm)", CinaConstants.SIZE_PREFIX);
prefixMap.put("Image dimension (px)", CinaConstants.DIMENSION_PREFIX);
}
public static boolean doesFolderContainImageMetadata(File folder)
......@@ -108,6 +109,11 @@ public class ImageMetadataExtractor
return metadataMap;
}
public File getFolder()
{
return folder;
}
private void checkPrepared()
{
assert lvdata != null;
......
......@@ -118,6 +118,11 @@ public class ReplicaMetadataExtractor
return metadataExtractors;
}
public File getFolder()
{
return folder;
}
private void checkPrepared()
{
assert lvdata != null;
......
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