Commit d10bf7af authored by Franziska Koehn's avatar Franziska Koehn
Browse files

'comparision' deleted, new name: extrasource

parent bf4a89f2
{
"root-type":"ext:cSubAssessment",
"comparison_data":{"identifier":["expt_id", "project"],"extra-source":"/data/archive/projects/{project}/experiments/{expt_id}"},
"extra-source":"/data/archive/projects/{project}/experiments/{expt_id}",
"fields":[
{"label":"Subject-ID", "field":"ext:cSubAssessment/SUBJECT_ID", "required":false, "key": "subject_id"},
{"label":"Experiment-ID", "field":"ext:cSubAssessment/EXPT_ID", "required":true, "key": "expt_id"},
......
{
"root-type":"xnat:mrScanData",
"comparison_data":{"identifier":["id","xnat_mrsessiondata_session_id"]},
"REST-API":"/data/archive/projects/{xnat_mrsessiondata_project}/subjects/{xnat_mrsessiondata_subject_id}/experiments/{xnat_mrsessiondata_session_id}/scans/{id}/resources/DICOM/files?format=zip",
"REST-API":"/data/archive/projects/{xnat_mrsessiondata_project}/subjects/{xnat_mrsessiondata_subject_id}/experiments/{xnat_mrsessiondata_session_id}/scans/{id}/resources/<DICOM,NIFTI>/files?format=zip",
"fields":[
{"label":"Type", "field":"xnat:mrScanData/TYPE", "required":true, "key": "type"},
{"label":"Project-ID", "field":"xnat:mrSessionData/PROJECT", "required":true, "key":"xnat_mrsessiondata_project"},
......
{
"root-type":"xnat:mrSessionData",
"comparison_data":{"identifier":["session_id"]},
"fields":[
{"label":"Session-ID", "field":"xnat:mrSessionData/SESSION_ID", "required":false, "key": "session_id"},
{"label":"Date", "field":"xnat:mrSessionData/DATE", "required":false, "key": "date"},
......
{
"root-type":"xnat:projectData",
"comparison_data":{"identifier":["id"]},
"fields":[
{"label":"Project-ID", "field":"xnat:projectData/ID", "required":true, "key": "id"},
{"label":"NAME", "field":"xnat:projectData/NAME", "required":false, "key": "name"},
......
{
"root-type":"xnat:subjectData",
"comparison_data":{"identifier":["subject_id"]},
"fields":[
{"label":"Subject-ID", "field":"xnat:subjectData/SUBJECT_ID", "required":true, "key": "subject_id"},
{"label":"Subject-Label", "field":"xnat:subjectData/SUBJECT_LABEL", "required":false, "key": "subject_label"},
......
......@@ -39,25 +39,13 @@ def get_all(force=False):
return get_all()
get_all.cache = None
def get_comparison_extra_source(root_type):
def get_extra_source(root_type):
for data in get_all():
if data['root-type'] == root_type:
if not 'comparison_data' in data or not data['comparison_data']:
raise NoComparisonDataError("No comparison-data was defined for this datatype")
elif not 'extra-source' in data['comparison_data'] or not data['comparison_data']['extra-source']:
raise NoComparisonDataError("No Source of additional Data was defined for this datatype")
if not 'extra-source' in data:
raise NoExtraSourceError("No Source of additional Data was defined for this datatype")
else:
return data['comparison_data']['extra-source']
def get_comparison_identifier(root_type):
for data in get_all():
if data['root-type'] == root_type:
if not 'comparison_data' in data or not data['comparison_data']:
raise NoComparisonDataError("No comparison-data was defined for this datatype")
elif not 'identifier' in data['comparison_data'] or not data['comparison_data']['identifier']:
raise NoComparisonDataError("No Identifier for this datatype was defined")
else:
return data['comparison_data']['identifier']
return data['extra-source']
def get_rest(root_type):
......
......@@ -38,7 +38,7 @@ class NoRestApiError(Error):
"""Should be raised when no REST-API was defined in the json-file of a root-type"""
pass
class NoComparisonDataError(Error):
class NoExtraSourceError(Error):
"""Should be raised when no comparision was defined in the json-file of a root-type"""
pass
......
......@@ -79,7 +79,7 @@ def set_root_type():
def results(res):
from xsa.datatypereader import get_field_label_by_key
from xsa.datatypereader import get_rest
from xsa.datatypereader import get_comparison_extra_source
from xsa.datatypereader import get_extra_source
from urllib.parse import quote
if state["roottype"] and res is not None:
......@@ -95,7 +95,7 @@ def results(res):
rest_adddata = ""
try:
rest_adddata = get_comparison_extra_source(state["roottype"])
rest_adddata = get_extra_source(state["roottype"])
except:
pass
......@@ -118,16 +118,40 @@ def download():
from xsa.datatypereader import get_rest
import json
from urllib.parse import unquote
import re
res = json.loads(unquote(request.form.get("result")))
url = prepare_rest(res, get_rest(state["roottype"]), state["host"])
base_url = get_rest(state["roottype"])
m = re.search(r"<([\w\d,]+)>",base_url)
if m:
tries = m.group(1).split(",")
to_replace = m.group(0)
else:
tries = (True,)
to_replace = None
for t in tries:
try:
if to_replace:
url, filename = prepare_rest(res, base_url.replace(to_replace, t), state["host"])
else:
url, filename = prepare_rest(res, base_url, state["host"])
creds = state["username"], state["password"]
length, content_iter = download_file_iter(url, creds)
response = Response(content_iter, mimetype='application/zip')
response.headers["Content-Disposition"] = "attachment; filename=%s.zip" % filename #TODO rename file
if length:
response.headers["content-length"] = length
return response
except Exception as e:
print(e)
pass
creds = state["username"], state["password"]
response = Response(download_file_iter(url, creds), mimetype='application/zip')
response.headers["Content-Disposition"] = "attachment; filename=test.zip"#TODO rename file
response = Response(b"", mimetype='application/zip')
response.headers["Content-Disposition"] = "attachment; filename=error"
return response
def adjust_constraints(list, parent):
......@@ -173,8 +197,8 @@ def send_query():
@app.route("/get_adddata", methods=["POST", "GET"])
def get_adddata():
from xsa.queries import query_for_additional_data
from xsa.datatypereader import get_comparison_extra_source
rest = get_comparison_extra_source(state["roottype"])
from xsa.datatypereader import get_extra_source
rest = get_extra_source(state["roottype"])
new_data_sets = []
for result in state["results"]:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment