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(xmlupload): provide a helpful error message if default-ontology in XML file doesn't exist (DEV-2577) #489

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Changes from all 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
32 changes: 32 additions & 0 deletions src/dsp_tools/utils/xml_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,33 @@ def parse_xml_file(input_file: Union[str, Path, etree._ElementTree[Any]]) -> etr
return tree.getroot()


def _check_if_onto_name_exists(
resclass_name_2_type: dict[str, type],
ontoname: str,
shortcode: str,
) -> None:
"""
Check if the "default-ontology" of the <knora> tag of the XML file exists on the DSP server.

Args:
resclass_name_2_type: infos about the resource classes that exist on the DSP server for the current ontology
ontoname: name of the ontology as referenced in the XML file
shortcode: shortcode of the project as referenced in the XML file

Raises:
UserError: if the ontology does not exist on the DSP server
"""
existing_onto_names = {x.split(":")[0] for x in resclass_name_2_type}
existing_onto_names.remove("knora-api")
if ontoname not in existing_onto_names:
err_msg = (
f"ERROR: The <knora> tag of your XML file references the default-ontology '{ontoname}', "
f"but the project {shortcode} on the DSP server contains only the ontologies {existing_onto_names}"
Nora-Olivia-Ammann marked this conversation as resolved.
Show resolved Hide resolved
)
logger.error(err_msg)
raise UserError(err_msg)


def _check_consistency_with_ontology(
resources: list[XMLResource],
resclass_name_2_type: dict[str, type],
Expand Down Expand Up @@ -401,6 +428,11 @@ def _check_consistency_with_ontology(
)
logger.error(err_msg)
raise UserError(err_msg)
_check_if_onto_name_exists(
resclass_name_2_type=resclass_name_2_type,
ontoname=ontoname,
shortcode=shortcode,
)
knora_properties = resclass_name_2_type[resources[0].restype].knora_properties # type: ignore[attr-defined]

for resource in resources:
Expand Down