|
@@ -32,10 +32,20 @@ class Timeout(Error):
|
|
|
pass
|
|
|
|
|
|
|
|
|
-class Object(object):
|
|
|
+class EntityContainer(object):
|
|
|
def __init__(self, root):
|
|
|
- self.identifier = root.find('./entities/entity/digitalObjectIdentifier').text
|
|
|
- self.note = root.find('./entities/entity/note').text
|
|
|
+ self.entities = {e.tag: e.text for e in root.findall('./entities/entity/*')}
|
|
|
+
|
|
|
+
|
|
|
+class Object(EntityContainer):
|
|
|
+ def __init__(self, root):
|
|
|
+ super(Object, self).__init__(root)
|
|
|
+ self.id = self.entities['baseId']
|
|
|
+ self.uuid = self.entities['digitalObjectIdentifier']
|
|
|
+ self.investigation = root.find('entities/entity/investigation/investigationId').text
|
|
|
+
|
|
|
+ node = root.find('entities/entity/uploader/userId')
|
|
|
+ self.uploader = node.text if node is not None else None
|
|
|
|
|
|
|
|
|
class Organization(object):
|
|
@@ -56,21 +66,27 @@ class Credentials(object):
|
|
|
self.secret = entities['rest.secret']
|
|
|
|
|
|
|
|
|
-class Ingest(object):
|
|
|
+class Ingest(EntityContainer):
|
|
|
def __init__(self, root):
|
|
|
- self.staging_url = None
|
|
|
+ super(Ingest, self).__init__(root)
|
|
|
+ self.id = self.entities.get('id')
|
|
|
+ self.staging_url = self.entities.get('stagingUrl')
|
|
|
+ self.object_uuid = self.entities.get('digitalObjectUuid')
|
|
|
+ self.owner_uuid = self.entities.get('owernUuid')
|
|
|
|
|
|
- node = root.find('./entities/entity/stagingUrl')
|
|
|
|
|
|
- if node is not None:
|
|
|
- self.staging_url = node.text
|
|
|
+class Investigation(EntityContainer):
|
|
|
+ def __init__(self, root):
|
|
|
+ super(Investigation, self).__init__(root)
|
|
|
+ self.object_ids = [e.text for e in root.findall('./entities/entity/digitalObjects/digitalObject/baseId')]
|
|
|
+ self.uuid = self.entities.get('uniqueIdentifier')
|
|
|
|
|
|
|
|
|
-class AccessPoint(object):
|
|
|
+class AccessPoint(EntityContainer):
|
|
|
def __init__(self, root):
|
|
|
- entities = {e.tag: e.text for e in root.findall('./entities/entity/*')}
|
|
|
- self.url = entities['remoteBaseUrl']
|
|
|
- self.identifier = entities['uniqueIdentifier']
|
|
|
+ super(AccessPoint, self).__init__(root)
|
|
|
+ self.url = self.entities['remoteBaseUrl']
|
|
|
+ self.identifier = self.entities['uniqueIdentifier']
|
|
|
|
|
|
|
|
|
class Client(object):
|
|
@@ -98,12 +114,32 @@ class Client(object):
|
|
|
def get_ingest(self, oid):
|
|
|
return Ingest(self.get_response(self.url('staging/ingests', oid)))
|
|
|
|
|
|
+ def get_ingests(self, limit=None):
|
|
|
+ return [self.get_ingest(oid) for oid in self.get_ingest_ids(limit)]
|
|
|
+
|
|
|
+ def get_investigation_ids(self, limit=None):
|
|
|
+ return self.get_collection('basemetadata/investigations', 'investigationId', limit)
|
|
|
+
|
|
|
+ def get_investigation(self, oid):
|
|
|
+ return Investigation(self.get_response(self.url('basemetadata/investigations', oid)))
|
|
|
+
|
|
|
+ def get_investigations(self, limit=None):
|
|
|
+ return [self.get_investigation(oid) for oid in self.get_investigation_ids(limit)]
|
|
|
+
|
|
|
def get_object_ids(self, limit=None, since=None):
|
|
|
return self.get_collection('basemetadata/digitalObjects', 'baseId', limit)
|
|
|
|
|
|
def get_object(self, oid):
|
|
|
return Object(self.get_response(self.url('basemetadata/digitalObjects', oid)))
|
|
|
|
|
|
+ def get_objects(self, limit=None):
|
|
|
+ return [self.get_object(oid) for oid in self.get_object_ids(limit)]
|
|
|
+
|
|
|
+ def create_object(self, investigation_id, label=None, uploader_id=None, note=None):
|
|
|
+ url = self.url('basemetadata/investigations', investigation_id, 'digitalObjects')
|
|
|
+ params = dict(label=label, uploader_id=uploader_id, note=note)
|
|
|
+ response = requests.post(url, data=params)
|
|
|
+
|
|
|
def get_organization(self, oid):
|
|
|
return Organization(self.get_response(self.url('dataorganization/organization', oid)))
|
|
|
|