1
|
import hashlib
|
2
|
import urllib2
|
3
|
|
4
|
from flask import json
|
5
|
|
6
|
|
7
|
class DLIRelation(object):
|
8
|
def __init__(self, entity):
|
9
|
|
10
|
m = hashlib.md5()
|
11
|
m.update("%s::%s" % (entity['targetPID']['id'], entity['targetPID']['type']))
|
12
|
self.relatedDnetId = m.hexdigest()
|
13
|
|
14
|
self.targetPID = entity['targetPID']['id']
|
15
|
self.targetPIDType = entity['targetPID']['type']
|
16
|
if "targetType" in entity:
|
17
|
self.relatedEntityType = entity['targetType']
|
18
|
if "relationSemantics" in entity:
|
19
|
self.typeOfRelation = entity['relationSemantics']
|
20
|
if "targetTitle" in entity:
|
21
|
self.related_title = entity['targetTitle']
|
22
|
self.authors = []
|
23
|
if 'authors' in entity:
|
24
|
for author in entity['authors']:
|
25
|
self.authors.append(author)
|
26
|
self.relation_provenance = []
|
27
|
if 'relationProvenance' in entity:
|
28
|
for provenance in entity['relationProvenance']:
|
29
|
item = {'name': provenance['datasource'], 'completionStatus': provenance['completionStatus'],
|
30
|
'provisionMode': provenance['provisionMode'],
|
31
|
'collectionDate': provenance['collectionDate']}
|
32
|
self.relation_provenance.append(item)
|
33
|
|
34
|
|
35
|
class DLIObject(object):
|
36
|
def __init__(self, id, basepath):
|
37
|
self.identifier = ""
|
38
|
self.pid = ""
|
39
|
self.pid_type = ""
|
40
|
self.resolved_url = ""
|
41
|
self.completionStatus = ""
|
42
|
self.provenance_record = []
|
43
|
self.objectType = "unknown"
|
44
|
self.title = ""
|
45
|
self.date = ""
|
46
|
self.authors = []
|
47
|
self.relations = []
|
48
|
try:
|
49
|
request = urllib2.urlopen("%s/mvc/ui/dli/dli_objectStore/retrieveObject.do?id=%s" % (basepath, id))
|
50
|
data = json.loads(request.read())
|
51
|
self.pid = data['pid']
|
52
|
self.identifier = id
|
53
|
self.pid_type = data['pidType']
|
54
|
|
55
|
if 'resolvedTypes' in data:
|
56
|
if self.pid_type in data['resolvedTypes']:
|
57
|
self.resolved_url = data['resolvedTypes'][self.pid_type] % self.pid
|
58
|
|
59
|
if "titles" in data:
|
60
|
if len(data['titles']) > 0:
|
61
|
self.title = data['titles'][0].replace('["','').replace('"]','')
|
62
|
self.authors = data['authors']
|
63
|
if 'type' in data:
|
64
|
self.objectType = data['type']
|
65
|
self.completionStatus = data['completionStatus']
|
66
|
if 'date' in data:
|
67
|
self.date = data['date']
|
68
|
if 'datasourceProvenance' in data:
|
69
|
for provenance in data['datasourceProvenance']:
|
70
|
item = {'name': provenance['datasource'], 'completionStatus': provenance['completionStatus'],
|
71
|
'provisionMode': provenance['provisionMode'],
|
72
|
'collectionDate': provenance['collectionDate']}
|
73
|
|
74
|
if 'datasourceId' in provenance:
|
75
|
item['datasourceId'] = provenance['datasourceId']
|
76
|
|
77
|
if 'publisher' in provenance:
|
78
|
item['publisher'] =provenance['publisher']
|
79
|
if 'publisherId' in provenance:
|
80
|
item['publisherId'] =provenance['publisherId']
|
81
|
|
82
|
self.provenance_record.append(item)
|
83
|
if 'relations' in data:
|
84
|
for rels in data['relations']:
|
85
|
self.relations.append(DLIRelation(rels))
|
86
|
except Exception as e:
|
87
|
print "error on request object"
|
88
|
print e
|