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

feat(xmlupload): enable migration of resource creation date (DEV-1402) #238

Merged
merged 24 commits into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -77,7 +77,7 @@ test-unittests: ## run unit tests

.PHONY: clean
clean: ## clean local project directories
@rm -rf dist/ build/ site/ dsp_tools.egg-info/
@rm -rf dist/ build/ site/ dsp_tools.egg-info/ id2iri_*_mapping_*.json stashed_*_properties_*.txt

.PHONY: help
help: ## show this help
Expand Down
19 changes: 11 additions & 8 deletions docs/dsp-tools-xmlupload.md
Expand Up @@ -201,14 +201,17 @@ To take `KnownUser` as example:

A `<resource>` element contains all necessary information to create a resource. It has the following attributes:

- `label`: a human-readable, preferably meaningful short name of the resource (required)
- `restype`: the resource type as defined within the ontology (required)
- `id`: a unique, arbitrary string providing a unique ID to the resource in order to be referencable by other resources;
the ID is only used during the import process and later replaced by the IRI used internally by DSP (required)
- `permissions`: a reference to a permission set; the permissions will be applied to the created resource (optional)
- `iri`: a custom IRI used when migrating existing resources (optional)
- `ark`: a version 0 ARK used when migrating existing resources from salsah.org to DSP (optional), it is not possible to
use `iri` and `ark` in the same resource. When `ark` is used, it overrides `iri`.
- `label` (required): a human-readable, preferably meaningful short name of the resource
- `restype` (required): the resource type as defined within the ontology
- `id` (required): a unique, arbitrary string providing a unique ID to the resource in order to be referencable by other
resources; the ID is only used during the import process and later replaced by the IRI used internally by DSP
- `permissions` (optional, but if omitted, users who are lower than a `ProjectAdmin` have no permissions at all, not
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
even view rights): a reference to a permission set; the permissions will be applied to the created resource
- `iri` (optional): a custom IRI, used when migrating existing resources
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
- `ark` (optional): a version 0 ARK, used when migrating existing resources from salsah.org to DSP. It is not possible
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
to use `iri` and `ark` in the same resource. When `ark` is used, it overrides `iri`.
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
- `creationDate` (optional): the creation date of the resource, used when migrating existing resources from salsah.org
to DSP

A complete `<resource>` element may look as follows:

Expand Down
8 changes: 8 additions & 0 deletions knora/dsplib/models/resource.py
Expand Up @@ -71,6 +71,7 @@ class ResourceInstance(Model):
_iri: Optional[str]
_ark: Optional[str]
_version_ark: Optional[str]
_creationDate: Optional[str]
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
_label: Optional[str]
_permissions: Optional[Permissions]
_user_permission: Optional[PermissionValue]
Expand All @@ -82,6 +83,7 @@ def __init__(self,
iri: Optional[str] = None,
ark: Optional[str] = None,
version_ark: Optional[str] = None,
creationDate: Optional[str] = None,
label: Optional[str] = None,
permissions: Optional[Permissions] = None,
user_permission: Optional[PermissionValue] = None,
Expand All @@ -93,6 +95,7 @@ def __init__(self,
self._iri = iri
self._ark = ark
self._version_ark = version_ark
self._creationDate = creationDate
self._label = label
self._permissions = permissions
self._user_permission = user_permission
Expand Down Expand Up @@ -286,6 +289,11 @@ def toJsonLdObj(self, action: Actions) -> Any:
tmp[property_name] = value.toJsonLdObj(action)

tmp['@context'] = self.context
if self._creationDate:
tmp['knora-api:creationDate'] = {
'@type': 'xsd:dateTimeStamp',
'@value': self._creationDate
}
return tmp

def create(self) -> 'ResourceInstance':
Expand Down
4 changes: 3 additions & 1 deletion knora/dsplib/models/xmlresource.py
Expand Up @@ -2,10 +2,10 @@

from lxml import etree

from knora.dsplib.models.xmlbitstream import XMLBitstream
from knora.dsplib.models.helpers import BaseError
from knora.dsplib.models.permission import Permissions
from knora.dsplib.models.value import KnoraStandoffXml
from knora.dsplib.models.xmlbitstream import XMLBitstream
from knora.dsplib.models.xmlproperty import XMLProperty


Expand All @@ -18,6 +18,7 @@ class XMLResource:
_label: str
_restype: str
_permissions: Optional[str]
_creationDate: Optional[str]
_bitstream: Optional[XMLBitstream]
_properties: list[XMLProperty]

Expand All @@ -35,6 +36,7 @@ def __init__(self, node: etree.Element, default_ontology: str) -> None:
self._id = node.attrib['id']
self._iri = node.attrib.get('iri')
self._ark = node.attrib.get('ark')
self._creationDate = node.attrib.get('creationDate')
self._label = node.attrib['label']
# get the resource type which is in format namespace:resourcetype, p.ex. rosetta:Image
tmp_res_type = node.attrib['restype'].split(':')
Expand Down
4 changes: 4 additions & 0 deletions knora/dsplib/schemas/data.xsd
Expand Up @@ -413,6 +413,7 @@
<xs:attribute name="iri" type="xs:string" use="optional"/>
<xs:attribute name="permissions" type="xs:NCName" use="optional"/>
<xs:attribute name="ark" type="xs:string" use="optional"/>
<xs:attribute name="creationDate" type="xs:dateTime" use="optional"/>
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
</xs:complexType>

<!-- annotation tag -->
Expand All @@ -424,6 +425,7 @@
<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="creationDate" type="xs:dateTime" use="optional"/>
</xs:complexType>

<!-- region tag -->
Expand All @@ -437,6 +439,7 @@
<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="creationDate" type="xs:dateTime" use="optional"/>
</xs:complexType>

<!-- link tag -->
Expand All @@ -448,6 +451,7 @@
<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="creationDate" type="xs:dateTime" use="optional"/>
</xs:complexType>

<!-- data type for knora shortcode -->
Expand Down
1 change: 1 addition & 0 deletions knora/dsplib/utils/xml_upload.py
Expand Up @@ -396,6 +396,7 @@ def _upload_resources(
label=resource.label,
iri=resource_iri,
permissions=permissions_lookup.get(resource.permissions),
creationDate=resource._creationDate,
bitstream=resource_bitstream,
values=properties
),
Expand Down
12 changes: 8 additions & 4 deletions testdata/test-data-systematic.xml
Expand Up @@ -32,7 +32,8 @@

<resource label="TestthingOhnePermissions"
restype=":TestThing2"
id="test_thing_0">
id="test_thing_0"
creationDate="2019-01-09T15:45:54.502951Z">
<text-prop name=":hasText">
<text encoding="utf8">Dies ist ein TestThing ohne Angabe von permissions</text>
</text-prop>
Expand All @@ -43,7 +44,8 @@

<annotation label="Annotation to TestthingOhnePermissions"
id="annotation_1"
permissions="res-default">
permissions="res-default"
creationDate="2005-10-23T13:45:12.01-14:00">
<text-prop name="hasComment">
<text encoding="utf8" permissions="prop-default">This is an annotation to TestthingOhnePermissions.</text>
<text encoding="utf8" permissions="prop-default">Second comment</text>
Expand Down Expand Up @@ -294,7 +296,8 @@

<region label="Region in image"
id="region_1"
permissions="res-restricted">
permissions="res-restricted"
creationDate="1999-12-31T23:59:59.9999999+01:00">
jnussbaum marked this conversation as resolved.
Show resolved Hide resolved
<color-prop name="hasColor">
<color permissions="prop-restricted">#5d1f1e</color>
</color-prop>
Expand Down Expand Up @@ -627,7 +630,8 @@

<link label="Link between 'Second Testthing', 'Compoundthing' and 'Partofthing-1'"
id="link_obj_1"
permissions="res-default">
permissions="res-default"
creationDate="1970-10-23T03:45:12-13:30">
<text-prop name="hasComment">
<text permissions="prop-default" encoding="xml">
A link object can link together an arbitrary number of resources from any resource class.
Expand Down