Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(xmlupload): prevent crash + improve error message when cardinalit…
…ies are wrong (DEV-1559) #267
  • Loading branch information
jnussbaum committed Dec 12, 2022
1 parent c11edc5 commit 7bfd82f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions knora/dsplib/models/resource.py
Expand Up @@ -103,9 +103,9 @@ def __init__(self,
self._user_permission = user_permission

if self.baseclass in self.baseclasses_with_bitstream and bitstream is None:
raise BaseError(f"ERROR Baseclass '{self.baseclass}' requires a bitstream value!")
raise BaseError(f"ERROR in resource with label '{self._label}': Baseclass '{self.baseclass}' requires a bitstream value")
if self.baseclass not in self.baseclasses_with_bitstream and bitstream:
raise BaseError(f"ERROR Baseclass '{self.baseclass}' does not allow a bitstream value!")
raise BaseError(f"ERROR in resource with label '{self._label}': Baseclass '{self.baseclass}' does not allow a bitstream value")
if self.baseclass in self.baseclasses_with_bitstream and bitstream:
self._bitstream = bitstream
else:
Expand All @@ -124,7 +124,7 @@ def __init__(self,
for val in value:
# check if cardinality allows multiple values for a property
if cardinality == Cardinality.C_0_1 or cardinality == Cardinality.C_1:
raise BaseError(f"ERROR Ontology does not allow multiple values for '{property_name}'!")
raise BaseError(f"ERROR in resource with label '{self._label}': Ontology does not allow multiple values for '{property_name}'")

if type(val) is Value:
self._values[property_name].append(val)
Expand Down Expand Up @@ -156,11 +156,11 @@ def __init__(self,
self._values[property_name] = value_type(value)
else:
if cardinality == Cardinality.C_1 or cardinality == Cardinality.C_1_n:
raise BaseError(f"ERROR The ontology does require at least one value for '{property_name}'!")
raise BaseError(f"ERROR in resource with label '{self._label}': The ontology requires at least one value for '{property_name}'")

for property_name in values:
if property_name not in self.knora_properties and not self.properties.get(property_name):
raise BaseError(f"ERROR Property '{property_name}' is not part of ontology!")
raise BaseError(f"ERROR in resource with label '{self._label}': Property '{property_name}' is not part of ontology")

def value(self, item) -> Optional[list[Value]]:
if self._values.get(item):
Expand Down
18 changes: 9 additions & 9 deletions knora/dsplib/utils/xml_upload.py
Expand Up @@ -518,16 +518,16 @@ def _upload_resources(
# create the resource in DSP
resclass_type = resclass_name_2_type[resource.restype]
properties = resource.get_propvals(id2iri_mapping, permissions_lookup)
resource_instance: ResourceInstance = resclass_type(
con=con,
label=resource.label,
iri=resource_iri,
permissions=permissions_lookup.get(resource.permissions), # type: ignore
creation_date=resource.creation_date,
bitstream=resource_bitstream,
values=properties
)
try:
resource_instance: ResourceInstance = resclass_type(
con=con,
label=resource.label,
iri=resource_iri,
permissions=permissions_lookup.get(resource.permissions), # type: ignore
creation_date=resource.creation_date,
bitstream=resource_bitstream,
values=properties
)
resource_creation_start = datetime.now()
created_resource: ResourceInstance = try_network_action(
action=lambda: resource_instance.create(),
Expand Down

0 comments on commit 7bfd82f

Please sign in to comment.