Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update dsp-tools to work with API version 16.0.0 #117

Merged
merged 7 commits into from Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 9 additions & 17 deletions knora/dsplib/models/listnode.py
Expand Up @@ -184,7 +184,7 @@ def __init__(self,
self._project = project.id if isinstance(project, Project) else str(project) if project is not None else None
self._id = str(id) if id is not None else None
self._label = LangString(label)
self._comments = LangString(comments)
self._comments = LangString(comments) if comments is not None else None
irinaschubert marked this conversation as resolved.
Show resolved Hide resolved
self._name = str(name) if name is not None else None
if parent and isinstance(parent, ListNode):
self._parent = parent.id
Expand Down Expand Up @@ -416,25 +416,27 @@ def toJsonObj(self, action: Actions, listIri: str = None) -> Any:
Creates a JSON-object from the ListNode instance that can be used to call Knora

:param action: Action the object is used for (Action.CREATE or Action.UPDATE)
:param listIri: The IRI of the list node, only used for update action
:return: JSON-object

"""

tmp = {}

if action == Actions.Create:
if self._project is None:
raise BaseError("There must be a project id given!")
tmp['projectIri'] = self._project
if self._label.isEmpty():
raise BaseError("There must be a valid ListNode label!")
tmp['labels'] = self._label.toJsonObj()
if not self._comments.isEmpty():
if self._comments:
tmp['comments'] = self._comments.toJsonObj()
else:
tmp['comments'] = []
if self._name is not None:
tmp['name'] = self._name
if self._parent is not None:
if self._parent:
tmp['parentNodeIri'] = self._parent

elif action == Actions.Update:
if self.id is None:
raise BaseError("There must be a node id given!")
Expand All @@ -446,19 +448,9 @@ def toJsonObj(self, action: Actions, listIri: str = None) -> Any:
tmp['labels'] = self._label.toJsonObj()
if not self._comments.isEmpty() and 'comments' in self._changed:
tmp['comments'] = self._comments.toJsonObj()
if self._name is not None and 'name' in self._changed:
if self._name and 'name' in self._changed:
tmp['name'] = self._name
#
# temporary fix for bug in dsp-api which prevents labels from having
# escaped double-quotes in the string, e.g. "this \"label\" not works"!
# The double quotes will be replaced by single quotes...
#
if tmp.get('labels'):
print(tmp['labels'])
tmp['labels'] = [{'language': ele['language'], 'value': ele['value'].replace('"', "'")} for ele in
tmp['labels']]
# tmp['labels'] = {k: v.replace('"', "'") for k, v in tmp['labels'].items()}
# End of FIX

return tmp

def create(self) -> 'ListNode':
Expand Down
2 changes: 1 addition & 1 deletion knora/dsplib/utils/onto_create_ontology.py
Expand Up @@ -321,7 +321,7 @@ def create_ontology(input_file: str,
print("Creating resource class failed:", err.message)
exit(105)
newresclasses[newresclass.id] = newresclass
if verbose is not None:
if verbose:
print("New resource class:")
newresclass.print()

Expand Down
15 changes: 8 additions & 7 deletions knora/dsplib/utils/xml_upload.py
Expand Up @@ -10,7 +10,7 @@
from knora.dsplib.models.group import Group
from knora.dsplib.models.permission import Permissions
from knora.dsplib.models.project import Project
from knora.dsplib.models.resource import ResourceInstanceFactory
from knora.dsplib.models.resource import ResourceInstanceFactory, ResourceInstance
from knora.dsplib.models.sipi import Sipi
from knora.dsplib.models.value import KnoraStandoffXml

Expand Down Expand Up @@ -613,10 +613,11 @@ def xml_upload(input_file: str, server: str, user: str, password: str, imgdir: s
bitstream = None

# create the resource on the server
instance = res_classes[resource.restype](con=con, label=resource.label,
permissions=permissions_lookup.get(resource.permissions),
bitstream=bitstream,
values=resource.get_propvals(res_iri_lookup,
permissions_lookup)).create()
instance: ResourceInstance = res_classes[resource.restype](con=con, label=resource.label,
permissions=permissions_lookup.get(
resource.permissions),
bitstream=bitstream,
values=resource.get_propvals(res_iri_lookup,
permissions_lookup)).create()
res_iri_lookup[resource.id] = instance.iri
print("Created resource: ", instance.label, " (", resource.id, ") with IRI ", instance.iri)
print("Created resource:", instance.label, "(", resource.id, ") with IRI", instance.iri)
6 changes: 3 additions & 3 deletions test/e2e/test_tools.py
Expand Up @@ -37,7 +37,7 @@ def test_get(self) -> None:
server=self.server,
user=self.user,
password='test',
verbose=True)
verbose=False)

with open('_anything-onto.json') as f:
onto_json_str = f.read()
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_create_ontology(self) -> None:
server=self.server,
user=self.user,
password='test',
verbose=True,
verbose=False,
dump=True)

def test_xml_upload(self) -> None:
Expand All @@ -117,7 +117,7 @@ def test_xml_upload(self) -> None:
password='test',
imgdir='testdata/bitstreams',
sipi='http://0.0.0.0:1024',
verbose=True,
verbose=False,
validate_only=False)


Expand Down