Skip to content
Snippets Groups Projects
Commit c995f959 authored by Juan Fuentes's avatar Juan Fuentes
Browse files

Fixes to the tool now running on the dev server

parent 0574589b
No related branches found
No related tags found
No related merge requests found
import os
from ch.systemsx.cisd.openbis.generic.client.web.client.exception import UserFailureException
from ch.ethz.sis.openbis.generic.asapi.v3 import IApplicationServerApi
from ch.systemsx.cisd.openbis.dss.generic.server import DataStoreServer
from ch.systemsx.cisd.common.spring import HttpInvokerUtils;
INVALID_FORMAT_ERROR_MESSAGE = "Invalid format for the folder name, should follow the pattern <ENTITY_KIND>+<SPACE_CODE>+<PROJECT_CODE>[<EXPERIMENT_CODE|<SAMPLE_CODE>]+<OPTIONAL_DATASET_TYPE>+<OPTIONAL_NAME>";
FAILED_TO_PARSE_SAMPLE_ERROR_MESSAGE = "Failed to parse sample";
FAILED_TO_PARSE_EXPERIMENT_ERROR_MESSAGE = "Failed to parse experiment";
SAMPLE_MISSING_ERROR_MESSAGE = "Sample not found";
EXPERIMENT_MISSING_ERROR_MESSAGE = "Experiment not found";
MORE_THAN_ONE_FOLDER_ERROR_MESSAGE = "More than one folder found";
def process(transaction):
incoming = transaction.getIncoming();
folderName = incoming.getName();
if not folderName.startswith('.'):
datasetInfo = folderName.split("+");
entityKind = None;
sample = None;
experiment = None;
datasetType = None;
name = None;
# Parse entity Kind
if len(datasetInfo) >= 1:
entityKind = datasetInfo[0];
else:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + FAILED_TO_PARSE_ERROR_MESSAGE);
# Parse entity Kind Format
if entityKind == "O":
if len(datasetInfo) >= 4:
sampleSpace = datasetInfo[1];
projectCode = datasetInfo[2];
sampleCode = datasetInfo[3];
OPENBISURL = DataStoreServer.getConfigParameters().getServerURL() + "/openbis/openbis"
v3 = HttpInvokerUtils.createServiceStub(IApplicationServerApi, OPENBISURL + IApplicationServerApi.SERVICE_URL, 30 * 1000);
projectSamplesEnabled = v3.getServerInformation(transaction.getOpenBisServiceSessionToken())['project-samples-enabled'] == 'true'
sample = None
if projectSamplesEnabled:
sample = transaction.getSample("/" +sampleSpace + "/" + projectCode + "/" + sampleCode);
else:
sample = transaction.getSample("/" +sampleSpace + "/" + sampleCode);
if sample is None:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + SAMPLE_MISSING_ERROR_MESSAGE);
if len(datasetInfo) >= 5:
datasetType = datasetInfo[4];
if len(datasetInfo) >= 6:
name = datasetInfo[5];
if len(datasetInfo) > 6:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + FAILED_TO_PARSE_SAMPLE_ERROR_MESSAGE);
else:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + FAILED_TO_PARSE_SAMPLE_ERROR_MESSAGE);
if entityKind == "E":
if len(datasetInfo) >= 4:
experimentSpace = datasetInfo[1];
projectCode = datasetInfo[2];
experimentCode = datasetInfo[3];
experiment = transaction.getExperiment("/" +experimentSpace + "/" + projectCode + "/" + experimentCode);
if experiment is None:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + EXPERIMENT_MISSING_ERROR_MESSAGE);
if len(datasetInfo) >= 5:
datasetType = datasetInfo[4];
if len(datasetInfo) >= 6:
name = datasetInfo[5];
if len(datasetInfo) > 6:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + FAILED_TO_PARSE_EXPERIMENT_ERROR_MESSAGE);
else:
raise UserFailureException(INVALID_FORMAT_ERROR_MESSAGE + ":" + FAILED_TO_PARSE_EXPERIMENT_ERROR_MESSAGE);
# Create dataset
dataSet = None;
if datasetType is not None: #Set type if found
dataSet = transaction.createNewDataSet(datasetType);
else:
dataSet = transaction.createNewDataSet();
if name is not None:
dataSet.setPropertyValue("NAME", name); #Set name if found
# Set sample or experiment
if sample is not None:
dataSet.setSample(sample);
else:
dataSet.setExperiment(experiment);
# Move folder to dataset
filesInFolder = incoming.listFiles();
# Discard folders started with a . (hidden files)
itemsInFolder = 0;
datasetItem = None;
for item in filesInFolder:
#Exclude files starting with .
#Exclude Mac .DS_Store
#Exclude Windows Thumbs.db
if (not item.getName().startswith('.')) and (not item.getName() == ".DS_Store") and (not item.getName() == "Thumbs.db"):
itemsInFolder = itemsInFolder + 1;
datasetItem = item;
if itemsInFolder > 1:
raise UserFailureException(MORE_THAN_ONE_FOLDER_ERROR_MESSAGE);
else:
transaction.moveFile(datasetItem.getAbsolutePath(), dataSet);
\ No newline at end of file
incoming-dir = ${incoming-root-dir}/eln-lims-dropbox
incoming-data-completeness-condition = auto-detection
top-level-data-set-handler = ch.systemsx.cisd.etlserver.registrator.api.v2.JythonTopLevelDataSetHandlerV2
script-path = eln-lims-dropbox.py
storage-processor = ch.systemsx.cisd.etlserver.DefaultStorageProcessor
incoming-share-id = 1
h5-folders = ${dataset-uploader.h5-folders:false}
h5ar-folders = ${dataset-uploader.h5ar-folders:true}
File added
This diff is collapsed.
......@@ -9,7 +9,10 @@ dss-rpc.put.ATTACHMENT = eln-lims-dropbox
The information can be retrieved from the database using the next SQL:
SELECT m.name as "tag", ea.perm_id as "experiment"
psql -U postgres -d openbis_standard
\o tags.txt
SELECT '"' || m.name || '" "' || ea.perm_id ||'"'
FROM metaproject_assignments_all ma
LEFT JOIN metaprojects m ON (m.id = ma.mepr_id)
LEFT JOIN experiments_all ea ON (ea.id = ma.expe_id);
......
This diff is collapsed.
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