Skip to content
Snippets Groups Projects
Commit d0fb647c authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

Task #9091 - Now functional ID service integration with Identifier constructor

parent f5372072
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,9 @@ import copy
path = expanduser("~/.siplibrc")
user = None
passw = None
host = "lta-ingest-test.lofar.eu:19443"
#host = "lofar-ingest.target.rug.nl:9443"
with open(path,'r') as file:
print "Parsing user credentials from",path
for line in file:
......@@ -19,50 +22,49 @@ with open(path,'r') as file:
user = line.split('=')[1].strip()
if line.startswith("password"):
passw = line.split('=')[1].strip()
if line.startswith("host"):
host = line.split('=')[1].strip()
login_data = {
'j_username' : user,
'j_password' : passw
}
url = 'https://'+user+':'+passw+'@lofar-ingest.target.rug.nl:9443/'
url = 'https://'+user+':'+passw+'@'+host
client = xmlrpclib.ServerProxy(url)
# todo: comment out this testing dict
id_cache = {}
# id_cache = {}
def _call_idservice(source, userlabel=None):
# todo: use this query to momqueryservice
# if userlabel is not None:
# response = client.getUniqueIDForLabel(source, label)
# response = client.getUniqueID(source)
# todo: comment out this mock of the service for testing:
if userlabel in id_cache:
print "using existing", userlabel
response = id_cache.get(userlabel)
else:
print "creating new", userlabel
response = {"version": "version",
"result": "ok",
"error_nr": 0,
"error": "",
"id": uuid.uuid1().int>>64,
"user_label": userlabel,
"data_type": "type",
"data_source": source,
"is_new": True}
if userlabel is not None:
print "keeping copy", userlabel
keeper = copy.deepcopy(response)
keeper["is_new"] = False
id_cache[userlabel] = keeper
response = client.GetUniqueIDForLabel(source, userlabel)
else:
response = client.GetUniqueID(source)
return response
# for testing:
# if userlabel in id_cache:
# print "using existing", userlabel
# response = id_cache.get(userlabel)
# else:
# print "creating new", userlabel
# response = {"version": "version",
# "result": "ok",
# "id": uuid.uuid1().int>>64,
# "user_label": userlabel,
# "data_type": "type",
# "identifier_source": source,
# "is_new": True,
# "error": ''}
# if userlabel is not None:
# print "keeping copy", userlabel
# keeper = copy.deepcopy(response)
# keeper["is_new"] = False
# id_cache[userlabel] = keeper
#
# return response
def create_unique_id(source, userlabel=None):
"""
......@@ -71,9 +73,11 @@ def create_unique_id(source, userlabel=None):
Throws an exception if the given label already exists for the given source.
"""
response = _call_idservice(source, userlabel)
if not response.get("result") == "ok":
raise Exception('An identifier for this userlabel could not be created -> '+str(response.get("error")))
if not response.get("is_new"):
raise Exception('An identifier for this userlabel already exists -> '+str(userlabel))
return response
return response.get('id')
def get_unique_id(source, userlabel):
......@@ -83,9 +87,11 @@ def get_unique_id(source, userlabel):
Throws an exception if the given label does not exist for the given source.
"""
response = _call_idservice(source, userlabel)
if not response.get("result") == "ok":
raise Exception('An identifier for this userlabel could not be retrieved -> '+str(response.get("error")))
if response.get("is_new"):
raise Exception('An identifier for this userlabel does not exist -> '+str(userlabel))
return response
return response.get('id')
......
......@@ -89,10 +89,9 @@ class Identifier(object):
at the time the Identifier is created to allow this lookup to work).
Throws an exception if the given label does not exist for the given source.
"""
unique_id = query.get_unique_id(source, userlabel)
identifier = Identifier.__new__(Identifier)
identifier._setpyxb_identifier(
identifier._set_pyxb_identifier(
ltasip.IdentifierType(
source=str(source),
identifier=str(unique_id),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment