Skip to content

Commit

Permalink
feat(xmlupload): add license / copyright as optional attributes in `i…
Browse files Browse the repository at this point in the history
…iif-uri` and `bitstream` (DEV-4355) (#1293)
  • Loading branch information
Nora-Olivia-Ammann authored Nov 28, 2024
1 parent d61d83f commit d401a49
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 29 deletions.
109 changes: 83 additions & 26 deletions src/dsp_tools/resources/schema/data.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<xs:attribute name="encoding" type="encoding_types" use="required"/>
<xs:attribute name="resrefs" type="resrefs_type"/>
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:complexType>

<!-- xml encoding value type -->
Expand All @@ -84,7 +84,7 @@
<xs:attribute name="encoding" fixed="xml" use="required"/>
<xs:attribute name="resrefs" type="resrefs_type"/>
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:complexType>

<!-- formatted text type -->
Expand All @@ -93,15 +93,15 @@
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:complexType>

<!-- unformatted text type -->
<xs:complexType name="unformatted_text_type">
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -111,7 +111,7 @@
<xs:simpleContent>
<xs:extension base="knoracolor_type">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -121,7 +121,7 @@
<xs:simpleContent>
<xs:extension base="knoradate_type">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -131,7 +131,7 @@
<xs:simpleContent>
<xs:extension base="xs:float">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -141,7 +141,7 @@
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -151,7 +151,7 @@
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -161,7 +161,7 @@
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -171,7 +171,7 @@
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -180,7 +180,7 @@
<xs:complexType name="hasSegmentBounds_type">
<xs:sequence />
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="segment_start" type="xs:double" use="required"/>
<xs:attribute name="segment_end" type="xs:double" use="required"/>
</xs:complexType>
Expand All @@ -190,7 +190,7 @@
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -200,7 +200,7 @@
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -210,7 +210,7 @@
<xs:simpleContent>
<xs:extension base="knoratime_type">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -220,7 +220,7 @@
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -230,7 +230,7 @@
<xs:simpleContent>
<xs:extension base="knorauri_type">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -240,7 +240,7 @@
<xs:simpleContent>
<xs:extension base="xs:boolean">
<xs:attribute name="comment" type="xs:string"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down Expand Up @@ -402,7 +402,9 @@
<xs:complexType name="bitstream_type">
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="license" type="xs:IDREF" use="optional"/>
<xs:attribute name="copyright-attribution" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -411,7 +413,9 @@
<xs:complexType name="iiif_uri_type">
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="license" type="xs:IDREF" use="optional"/>
<xs:attribute name="copyright-attribution" type="xs:IDREF" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down Expand Up @@ -447,7 +451,7 @@
</xs:attribute>
<xs:attribute name="restype" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="iri" type="xs:string" use="optional"/>
<xs:attribute name="ark" type="xs:string" use="optional"/>
<xs:attribute name="creation_date" type="xs:dateTime" use="optional"/>
Expand All @@ -461,7 +465,7 @@
</xs:all>
<xs:attribute name="label" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="iri" type="xs:string" use="optional"/>
<xs:attribute name="ark" type="xs:string" use="optional"/>
<xs:attribute name="creation_date" type="xs:dateTime" use="optional"/>
Expand All @@ -477,7 +481,7 @@
</xs:all>
<xs:attribute name="label" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="iri" type="xs:string" use="optional"/>
<xs:attribute name="ark" type="xs:string" use="optional"/>
<xs:attribute name="creation_date" type="xs:dateTime" use="optional"/>
Expand All @@ -491,7 +495,7 @@
</xs:all>
<xs:attribute name="label" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="iri" type="xs:string" use="optional"/>
<xs:attribute name="ark" type="xs:string" use="optional"/>
<xs:attribute name="creation_date" type="xs:dateTime" use="optional"/>
Expand All @@ -510,7 +514,7 @@
</xs:sequence>
<xs:attribute name="label" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="creation_date" type="xs:dateTime" use="optional"/>
</xs:complexType>

Expand All @@ -527,7 +531,7 @@
</xs:sequence>
<xs:attribute name="label" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="permissions" type="xs:IDREF" use="optional"/>
<xs:attribute name="creation_date" type="xs:dateTime" use="optional"/>
</xs:complexType>

Expand Down Expand Up @@ -566,11 +570,46 @@
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>

<!-- copyright-attribution tag -->
<xs:complexType name="copyright_attribution_type">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<!-- copyright-attributions tag -->
<xs:complexType name="copyright_attributions_type">
<xs:sequence>
<xs:element name="copyright-attribution" type="copyright_attribution_type" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<!-- license tag -->
<xs:complexType name="license_type">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="uri" type="xs:string" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<!-- licenses tag -->
<xs:complexType name="licenses_type">
<xs:sequence>
<xs:element name="license" type="license_type" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<!-- complete document -->
<xs:element name="knora">
<xs:complexType>
<xs:sequence>
<xs:element name="permissions" type="permissions_type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="copyright-attributions" type="copyright_attributions_type" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="licenses" type="licenses_type" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice maxOccurs="unbounded">
<xs:element name="resource" type="resource_type" minOccurs="1" maxOccurs="unbounded">
<xs:unique name="UniqueNameAttr_Resource">
Expand Down Expand Up @@ -619,5 +658,23 @@
<xs:selector xpath=".//*"/>
<xs:field xpath="@ark"/>
</xs:unique>
<!-- Define a key constraint for license IDs -->
<xs:key name="licenseIdKey">
<xs:selector xpath="knora/licenses/license"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="licenseIdRef" refer="licenseIdKey">
<xs:selector xpath="knora/resource/*"/>
<xs:field xpath="@license"/>
</xs:keyref>
<!-- Define a key constraint for copyright IDs -->
<xs:key name="copyright-attributionsIdKey">
<xs:selector xpath="knora/copyright-attributions/copyright-attribution"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="copyrightIdRef" refer="copyright-attributionsIdKey">
<xs:selector xpath="knora/resource/*"/>
<xs:field xpath="@copyright-attribution"/>
</xs:keyref>
</xs:element>
</xs:schema>
4 changes: 2 additions & 2 deletions test/integration/commands/excel2xml/test_excel2xml_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_missing_resource_permission(self) -> None:
file = f"{INVALID_EXCEL_DIRECTORY}/missing-resource-permissions.xlsx"
expected_msg = "Missing permissions for resource 'person_0' (Excel row 2)"
expected_xml_validation = regex.escape(
"Element 'resource', attribute 'permissions': " "'' is not a valid value of the atomic type 'xs:NCName'."
"Element 'resource', attribute 'permissions': " "'' is not a valid value of the atomic type 'xs:IDREF'."
)
_, catched_warnings = excel2xml_cli.excel2xml(file, "1234", "excel2xml-invalid")
assert len(catched_warnings) == 2
Expand All @@ -124,7 +124,7 @@ def test_missing_bitstream_permission(self) -> None:
" An attempt to deduce them from the resource permissions failed."
)
expected_xml_validation = regex.escape(
"Element 'bitstream', attribute 'permissions': " "'' is not a valid value of the atomic type 'xs:NCName'."
"Element 'bitstream', attribute 'permissions': " "'' is not a valid value of the atomic type 'xs:IDREF'."
)
_, catched_warnings = excel2xml_cli.excel2xml(file, "1234", "excel2xml-invalid")
assert len(catched_warnings) == 3
Expand Down
11 changes: 11 additions & 0 deletions test/integration/utils/test_xml_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,16 @@ def test_validate_xml_empty_label() -> None:
validate_xml_file(input_file="testdata/invalid-testdata/xml-data/empty-label.xml")


def test_validate_xml_duplicate_license_copyright_id() -> None:
expected_msg = regex.escape(
"The XML file cannot be uploaded due to the following validation error(s):\n"
" Line 11: Element 'copyright-attribution', attribute 'id': 'copyright_id' "
"is not a valid value of the atomic type 'xs:ID'.\n"
" Line 16: Element 'license', attribute 'id': 'license_id' is not a valid value of the atomic type 'xs:ID'."
)
with pytest.raises(InputError, match=expected_msg):
validate_xml_file(input_file="testdata/invalid-testdata/xml-data/duplicate-license-copyright-ids.xml")


if __name__ == "__main__":
pytest.main([__file__])
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='utf-8'?>

<knora xmlns="https://dasch.swiss/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://dasch.swiss/schema ../../../src/dsp_tools/resources/schema/data.xsd"
shortcode="4124"
default-ontology="testonto">

<copyright-attributions>
<copyright-attribution id="copyright_id">Copyright Text</copyright-attribution>
<copyright-attribution id="copyright_id">Copyright Text</copyright-attribution>
</copyright-attributions>

<licenses>
<license id="license_id">license text</license>
<license id="license_id">license text</license>
</licenses>

</knora>
Loading

0 comments on commit d401a49

Please sign in to comment.