Skip to content
Snippets Groups Projects
Commit 552c9ff9 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

server now sends information about dataset types

parent 67d1e560
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,8 @@ def load_jupyter_server_extension(nb_server_app):
"""
# load the configuration file
#print(dir(nb_server_app))
print(nb_server_app.config_file_paths)
config = _load_configuration()
if config is not None:
for conn in config['connections']:
......@@ -51,6 +53,7 @@ def load_jupyter_server_extension(nb_server_app):
base_url = web_app.settings['base_url']
# DataSet download
web_app.add_handlers(
host_pattern,
[(url_path_join(
......@@ -106,19 +109,33 @@ def register_connection(connection_info):
verify_certificates = conn.verify_certificates
)
conn.openbis = openbis
conn.ds_types = {}
openbis.login(
username = conn.username,
password = conn.password
)
conn.status = 'connected'
print('connected to {}'.format(conn.name))
except Exception as exc:
conn.status = 'FAILED: {}'.format(exc)
print('ERROR: could not connected to {}. Reason: {}'.format(conn.name, exc))
raise exc
try:
# add dataset types to the connection
dataset_types = conn.openbis.get_dataset_types()
dts = dataset_types.df.to_dict(orient='records')
for dt in dts:
dataset_type = conn.openbis.get_dataset_type(dt['code'])
pa = dataset_type.get_propertyAssignments()
pa_dict = pa.to_dict(orient='records')
dt['propertyAssignments'] = pa_dict
conn.ds_types = dts
except Exception as e:
print('ERROR: {}'.format(e))
def check_connection(connection_name):
"""Checks whether connection is valid and session is still active
......@@ -157,10 +174,12 @@ class OpenBISHandler(IPythonHandler):
"""
connections= []
for conn in openbis_connections.values():
connections.append({
'name' : conn.name,
'url' : conn.url,
'status' : conn.status,
'name' : conn.name,
'url' : conn.url,
'status' : conn.status,
'ds_types': conn.ds_types,
})
self.write({
......@@ -188,7 +207,9 @@ class SampleHandler(IPythonHandler):
sample = conn.openbis.get_sample(permId)
except Exception as exc:
print(exc)
self.send_error( reason = 'No such sample found: {}'.format(permId) )
self.send_error( reason = 'No such sample: {}'.format(permId) )
if sample is None:
return
datasets = sample.get_datasets().df
datasets.replace({np.nan:None}, inplace=True) # replace NaN with None, otherwise we cannot convert it correctly
......
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