oldaplib 0.3.10__tar.gz → 0.3.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {oldaplib-0.3.10 → oldaplib-0.3.11}/PKG-INFO +1 -1
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/objectfactory.py +399 -102
- oldaplib-0.3.11/oldaplib/src/version.py +1 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_objectfactory.py +73 -8
- oldaplib-0.3.11/oldaplib/testdata/instances_test.trig +119 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/pyproject.toml +1 -1
- oldaplib-0.3.10/oldaplib/src/version.py +0 -1
- {oldaplib-0.3.10 → oldaplib-0.3.11}/README.md +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/apps/load_list.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/admin-testing.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/admin.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/example.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/oldap.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/oldap.ttl +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/shared.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/ontologies/standard/.gitsave +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/cachesingleton.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/connection.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/datamodel.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/dtypes/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/dtypes/bnode.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/dtypes/languagein.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/dtypes/namespaceiri.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/dtypes/rdfset.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/dtypes/xsdset.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/action.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/adminpermissions.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/attributeclass.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/datapermissions.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/externalontologyattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/haspropertyattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/language.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/oldaplistattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/oldaplistnodeattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/owlpropertytype.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/permissionsetattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/projectattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/propertyclassattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/resourceclassattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/sparql_result_format.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/userattr.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/enums/xsd_datatypes.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/externalontology.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/globalconfig.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/hasproperty.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/Notify.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/attributechange.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/context.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/convert2datatype.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/irincname.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/json_encoder.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/langstring.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/numeric.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/observable_dict.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/observable_set.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/oldaperror.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/query_processor.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/semantic_version.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/serializeableset.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/serializer.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/singletonmeta.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/helpers/tools.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/iconnection.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/in_project.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/model.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/oldaplist.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/oldaplist_helpers.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/oldaplistnode.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/oldaplogging.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/permissionset.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/project.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/propertyclass.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/resourceclass.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/user.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/userdataclass.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/floatingpoint.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/iri.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_anyuri.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_base64binary.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_boolean.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_byte.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_date.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_datetime.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_datetimestamp.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_decimal.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_double.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_duration.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_float.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gday.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gmonth.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gmonthday.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gyear.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gyearmonth.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_hexbinary.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_id.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_idref.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_int.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_integer.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_language.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_long.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_name.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_ncname.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_negativeinteger.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_nmtoken.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_nonnegativeinteger.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_nonpositiveinteger.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_normalizedstring.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_positiveinteger.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_qname.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_short.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_string.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_time.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_token.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedbyte.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedint.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedlong.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedshort.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/__init__.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_cache.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_connection.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_context.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_datamodel.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_dtypes.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_externalontologies.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_hasproperty.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_in_project.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_langstring.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_language_in.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_observable_dict.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_observable_set.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_oldaplist.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_oldaplist_helpers.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_oldaplistnode.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_permissionset.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_project.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_propertyclass.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_resourceclass.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_semantic_version.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_user.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/test/test_xsd_datatypes.py +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/Gender.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/collections_type.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/connection_test.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/datamodel_test.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/event_type.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/hlist_schema.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/institution_or_building_type.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/language.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/location_type.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/means_of_transportation.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/objectfactory_test.trig +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/playground_list.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/role.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/source_type-1.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/source_type.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/test_move_left_of_toL.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testdata/testlist.yaml +0 -0
- {oldaplib-0.3.10 → oldaplib-0.3.11}/oldaplib/testit.http +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import re
|
|
2
|
+
from enum import Flag, auto
|
|
2
3
|
from functools import partial
|
|
3
4
|
from typing import Type, Any, Self, cast
|
|
4
5
|
|
|
@@ -31,6 +32,11 @@ from oldaplib.src.xsd.xsd_qname import Xsd_QName
|
|
|
31
32
|
|
|
32
33
|
ValueType = LangString | ObservableSet | Xsd
|
|
33
34
|
|
|
35
|
+
class SortBy(Flag):
|
|
36
|
+
PROPVAL = auto()
|
|
37
|
+
CREATED = auto()
|
|
38
|
+
LASTMOD = auto()
|
|
39
|
+
|
|
34
40
|
|
|
35
41
|
#@strict
|
|
36
42
|
class ResourceInstance:
|
|
@@ -463,6 +469,27 @@ class ResourceInstance:
|
|
|
463
469
|
return result['boolean']
|
|
464
470
|
|
|
465
471
|
def create(self, indent: int = 0, indent_inc: int = 4) -> str:
|
|
472
|
+
"""
|
|
473
|
+
Generates an RDF/SPARQL INSERT DATA query for creating a resource with associated
|
|
474
|
+
metadata and verifies permissions before execution.
|
|
475
|
+
|
|
476
|
+
This method first checks for the necessary permissions to create a resource.
|
|
477
|
+
It assigns metadata such as the creation and modification information if
|
|
478
|
+
the resource name matches specific criteria. It ensures that no resource
|
|
479
|
+
with the same IRI exists before proceeding with the resource creation.
|
|
480
|
+
If a conflict is detected, an error is raised. The method finalizes the
|
|
481
|
+
creation of the resource by executing a SPARQL query in a transactional context.
|
|
482
|
+
|
|
483
|
+
:param indent: The current level of indentation (default is 0).
|
|
484
|
+
:type indent: int
|
|
485
|
+
:param indent_inc: The incremental spaces per indentation level (default is 4).
|
|
486
|
+
:type indent_inc: int
|
|
487
|
+
:return: A string representing the RDF/SPARQL query for creation.
|
|
488
|
+
:rtype: str
|
|
489
|
+
:raises OldapErrorNoPermission: If the user does not have the required permissions to create the resource.
|
|
490
|
+
:raises OldapErrorAlreadyExists: If a resource with the same IRI already exists.
|
|
491
|
+
:raises OldapError: For errors encountered during the SPARQL transaction execution.
|
|
492
|
+
"""
|
|
466
493
|
result, message = self.check_for_permissions(AdminPermission.ADMIN_CREATE)
|
|
467
494
|
if not result:
|
|
468
495
|
raise OldapErrorNoPermission(message)
|
|
@@ -519,6 +546,19 @@ class ResourceInstance:
|
|
|
519
546
|
def read(cls,
|
|
520
547
|
con: IConnection,
|
|
521
548
|
iri: Iri) -> Self:
|
|
549
|
+
"""
|
|
550
|
+
Reads an object of the specific class type from the RDF data source using the provided connection
|
|
551
|
+
and IRI. Validates that the retrieved RDF data matches the expected class type and ensures proper
|
|
552
|
+
permissions have been granted to access the resource.
|
|
553
|
+
|
|
554
|
+
:param con: The connection object to the data source (IConnection).
|
|
555
|
+
:param iri: The IRI of the resource to read (Iri).
|
|
556
|
+
:return: An object of the invoking class loaded with data from the RDF resource.
|
|
557
|
+
|
|
558
|
+
:raises OldapErrorInconsistency: If an expected QName is not found or if the retrieved object type
|
|
559
|
+
does not match the expected class type.
|
|
560
|
+
:raises OldapErrorNotFound: If the resource associated with the provided IRI is not found.
|
|
561
|
+
"""
|
|
522
562
|
graph = cls.project.projectShortName
|
|
523
563
|
context = Context(name=con.context_name)
|
|
524
564
|
sparql = context.sparql_context
|
|
@@ -567,6 +607,26 @@ class ResourceInstance:
|
|
|
567
607
|
return cls(iri=iri, **kwargs)
|
|
568
608
|
|
|
569
609
|
def update(self, indent: int = 0, indent_inc: int = 4) -> None:
|
|
610
|
+
"""
|
|
611
|
+
Updates the current resource by creating and executing SPARQL queries to modify, insert, or
|
|
612
|
+
delete data based on the changeset. This method also verifies user permissions and ensures
|
|
613
|
+
data consistency using timestamps. It commits modifications within a transaction while
|
|
614
|
+
rolling back changes upon encountering errors.
|
|
615
|
+
|
|
616
|
+
The `update` method processes changes in resource attributes specified in a changeset. It
|
|
617
|
+
constructs appropriate SPARQL queries for CREATE, MODIFY, and DELETE actions for each
|
|
618
|
+
field. Additionally, it updates the last modification timestamp for the resource and records
|
|
619
|
+
the user performing the update. If permissions are insufficient or an update fails, the
|
|
620
|
+
transaction is aborted.
|
|
621
|
+
|
|
622
|
+
:param indent: The initial level of indentation for the generated SPARQL queries.
|
|
623
|
+
:type indent: int
|
|
624
|
+
:param indent_inc: The incremental level of indentation for nested sections in SPARQL
|
|
625
|
+
queries.
|
|
626
|
+
:type indent_inc: int
|
|
627
|
+
:return: None
|
|
628
|
+
:rtype: None
|
|
629
|
+
"""
|
|
570
630
|
admin_resources, message = self.check_for_permissions(AdminPermission.ADMIN_RESOURCES)
|
|
571
631
|
|
|
572
632
|
context = Context(name=self._con.context_name)
|
|
@@ -694,6 +754,22 @@ class ResourceInstance:
|
|
|
694
754
|
self.clear_changeset()
|
|
695
755
|
|
|
696
756
|
def delete(self) -> None:
|
|
757
|
+
"""
|
|
758
|
+
Deletes the specified resource represented by the object's IRI from the associated graph
|
|
759
|
+
if the proper permissions are granted and the resource is not in use. This method initiates
|
|
760
|
+
a transactional sequence to ensure data consistency and rollback in case of an error.
|
|
761
|
+
The process includes checking permissions, querying whether the resource is in use,
|
|
762
|
+
and finally issuing a SPARQL DELETE query to remove the resource.
|
|
763
|
+
|
|
764
|
+
Raises appropriate exceptions if the resource is in use, permissions are insufficient,
|
|
765
|
+
or any other transaction-related error occurs.
|
|
766
|
+
|
|
767
|
+
:raises OldapErrorNoPermission: If the user lacks the necessary permissions to
|
|
768
|
+
delete the resource.
|
|
769
|
+
:raises OldapErrorInUse: If the resource is currently in use and cannot be deleted.
|
|
770
|
+
:raises OldapError: If any error occurs during transaction start, query, update,
|
|
771
|
+
or commit phases.
|
|
772
|
+
"""
|
|
697
773
|
admin_resources, message = self.check_for_permissions(AdminPermission.ADMIN_RESOURCES)
|
|
698
774
|
|
|
699
775
|
context = Context(name=self._con.context_name)
|
|
@@ -739,6 +815,329 @@ class ResourceInstance:
|
|
|
739
815
|
self._con.transaction_abort()
|
|
740
816
|
raise
|
|
741
817
|
|
|
818
|
+
@staticmethod
|
|
819
|
+
def read_data(con: IConnection, projectShortName: Xsd_NCName | str, iri: Iri | str) -> dict[Xsd_QName, Any]:
|
|
820
|
+
"""
|
|
821
|
+
Reads and processes data from a given IConnection instance based on a specified
|
|
822
|
+
project short name and a resource IRI. This method fetches the data from a graph
|
|
823
|
+
in the RDF database, verifies user permissions, and returns selected data in a
|
|
824
|
+
dictionary format.
|
|
825
|
+
|
|
826
|
+
:param con: The connection object used to query the RDF data.
|
|
827
|
+
:type con: IConnection
|
|
828
|
+
:param projectShortName: The short name of the project used to identify the graph
|
|
829
|
+
in the RDF store. Accepts either Xsd_NCName or a string.
|
|
830
|
+
:param iri: The IRI of the resource being queried. Accepts either Iri or a string.
|
|
831
|
+
:return: A dictionary mapping predicates to their associated values from the
|
|
832
|
+
selected resource.
|
|
833
|
+
:rtype: dict[Xsd_QName, Any]
|
|
834
|
+
:raises OldapErrorInconsistency: If a non-QName predicate is found in the results.
|
|
835
|
+
:raises OldapErrorNotFound: If the resource with the given IRI is not found.
|
|
836
|
+
"""
|
|
837
|
+
if not isinstance(iri, Iri):
|
|
838
|
+
iri = Iri(iri, validate=True)
|
|
839
|
+
if not isinstance(projectShortName, Xsd_NCName):
|
|
840
|
+
graph = Xsd_NCName(projectShortName)
|
|
841
|
+
else:
|
|
842
|
+
graph = projectShortName
|
|
843
|
+
|
|
844
|
+
context = Context(name=con.context_name)
|
|
845
|
+
sparql = context.sparql_context
|
|
846
|
+
sparql += f'''
|
|
847
|
+
SELECT ?predicate ?value
|
|
848
|
+
WHERE {{
|
|
849
|
+
GRAPH {graph}:data {{
|
|
850
|
+
{iri.toRdf} ?predicate ?value .
|
|
851
|
+
{iri.toRdf} oldap:grantsPermission ?permset .
|
|
852
|
+
}}
|
|
853
|
+
GRAPH oldap:admin {{
|
|
854
|
+
{con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
855
|
+
?permset oldap:givesPermission ?DataPermission .
|
|
856
|
+
?DataPermission oldap:permissionValue ?permval .
|
|
857
|
+
}}
|
|
858
|
+
FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})
|
|
859
|
+
}}
|
|
860
|
+
'''
|
|
861
|
+
jsonres = con.query(sparql)
|
|
862
|
+
res = QueryProcessor(context, jsonres)
|
|
863
|
+
data = {}
|
|
864
|
+
for r in res:
|
|
865
|
+
if r['predicate'].is_qname:
|
|
866
|
+
if not data.get(r['predicate'].as_qname):
|
|
867
|
+
data[r['predicate'].as_qname] = []
|
|
868
|
+
data[str(r['predicate'].as_qname)].append(str(r['value']))
|
|
869
|
+
else:
|
|
870
|
+
raise OldapErrorInconsistency(f"Expected QName as predicate, got {r['predicate']}")
|
|
871
|
+
if not data.get('rdf:type'):
|
|
872
|
+
raise OldapErrorNotFound(f'Resource with iri <{iri}> not found.')
|
|
873
|
+
return data
|
|
874
|
+
|
|
875
|
+
@staticmethod
|
|
876
|
+
def search_fulltext(con: IConnection,
|
|
877
|
+
projectShortName: Xsd_NCName | str,
|
|
878
|
+
s: str,
|
|
879
|
+
resClass: Xsd_QName | str | None = None,
|
|
880
|
+
count_only: bool = False,
|
|
881
|
+
sortBy: SortBy | None = None,
|
|
882
|
+
limit: int = 100,
|
|
883
|
+
offset: int = 0,
|
|
884
|
+
indent: int = 0, indent_inc: int = 4) -> int | dict[Iri, dict[str, Xsd]]:
|
|
885
|
+
"""
|
|
886
|
+
Search for entities in a project using a full-text search query, with optional filters and sorting
|
|
887
|
+
based on resource class and properties.
|
|
888
|
+
|
|
889
|
+
:param con: The connection instance to interact with the SPARQL endpoint or database.
|
|
890
|
+
:type con: IConnection
|
|
891
|
+
:param projectShortName: The project short name (identifier). Can be provided as an Xsd_NCName or a
|
|
892
|
+
string. If a string, it is automatically validated and converted to an Xsd_NCName.
|
|
893
|
+
:type projectShortName: Xsd_NCName | str
|
|
894
|
+
:param s: The full-text search query to identify entities matching the specified string values.
|
|
895
|
+
:type s: str
|
|
896
|
+
:param resClass: An optional entity class (Xsd_QName) used to filter results. If provided as a string,
|
|
897
|
+
it is validated and converted to Xsd_QName.
|
|
898
|
+
:type resClass: Xsd_QName | str | None
|
|
899
|
+
:param count_only: If True, only the count of matching entities will be returned. Defaults to False.
|
|
900
|
+
:type count_only: bool
|
|
901
|
+
:param sortBy: Optional sorting criterion for the results, such as creation date, last modification date,
|
|
902
|
+
or property values. Defaults to None.
|
|
903
|
+
:type sortBy: SortBy | None
|
|
904
|
+
:param limit: The maximum number of records to return when count_only is False. Defaults to 100.
|
|
905
|
+
:type limit: int
|
|
906
|
+
:param offset: The number of records to skip for paginated queries. Defaults to 0.
|
|
907
|
+
:type offset: int
|
|
908
|
+
:param indent: Initial indentation level for the generated SPARQL query. Defaults to 0.
|
|
909
|
+
:type indent: int
|
|
910
|
+
:param indent_inc: Incremental indentation used during SPARQL query generation. Defaults to 4.
|
|
911
|
+
:type indent_inc: int
|
|
912
|
+
:return: If count_only is True, an integer representing the count of matching entities. If count_only is
|
|
913
|
+
False, a dictionary with entity IRIs as keys and their respective property-to-value mappings
|
|
914
|
+
as values.
|
|
915
|
+
:rtype: int | dict[Iri, dict[str, Xsd]]
|
|
916
|
+
|
|
917
|
+
The SPARQL generated is as follows
|
|
918
|
+
|
|
919
|
+
```sparql
|
|
920
|
+
SELECT DISTINCT ?s ?t ?p ?o ?creationDate
|
|
921
|
+
WHERE {
|
|
922
|
+
GRAPH test:data {
|
|
923
|
+
?s oldap:creationDate ?creationDate .
|
|
924
|
+
?s ?p ?o .
|
|
925
|
+
?s rdf:type ?t .
|
|
926
|
+
?s rdf:type test:Book .
|
|
927
|
+
?s oldap:grantsPermission ?permset .
|
|
928
|
+
}
|
|
929
|
+
FILTER(isLiteral(?o) && (datatype(?o) = xsd:string || datatype(?o) = rdf:langString || lang(?o) != ""))
|
|
930
|
+
FILTER(CONTAINS(LCASE(STR(?o)), "gaga")) # case-insensitive substring match
|
|
931
|
+
GRAPH oldap:admin {
|
|
932
|
+
<https://orcid.org/0000-0003-1681-4036> oldap:hasPermissions ?permset .
|
|
933
|
+
?permset oldap:givesPermission ?DataPermission .
|
|
934
|
+
?DataPermission oldap:permissionValue ?permval .
|
|
935
|
+
}
|
|
936
|
+
FILTER(?permval >= "2"^^xsd:integer)
|
|
937
|
+
}
|
|
938
|
+
ORDER BY ASC(?creationDate)LIMIT 100 OFFSET 0
|
|
939
|
+
```
|
|
940
|
+
"""
|
|
941
|
+
if not isinstance(projectShortName, Xsd_NCName):
|
|
942
|
+
graph = Xsd_NCName(projectShortName, validate=True)
|
|
943
|
+
else:
|
|
944
|
+
graph = projectShortName
|
|
945
|
+
if resClass and not isinstance(resClass, Xsd_QName):
|
|
946
|
+
resClass = Xsd_QName(resClass, validate=True)
|
|
947
|
+
|
|
948
|
+
blank = ''
|
|
949
|
+
context = Context(name=con.context_name)
|
|
950
|
+
sparql = context.sparql_context
|
|
951
|
+
|
|
952
|
+
if (count_only):
|
|
953
|
+
sparql += f'{blank:{indent * indent_inc}}SELECT (COUNT(DISTINCT ?s) as ?numResult)'
|
|
954
|
+
else:
|
|
955
|
+
sparql += f'{blank:{indent * indent_inc}}SELECT DISTINCT ?s ?t ?p ?o'
|
|
956
|
+
if sortBy:
|
|
957
|
+
if sortBy == SortBy.CREATED:
|
|
958
|
+
sparql += ' ?creationDate'
|
|
959
|
+
if sortBy == SortBy.LASTMOD:
|
|
960
|
+
sparql += '?lastModificationDate'
|
|
961
|
+
sparql += f'\n{blank:{indent * indent_inc}}WHERE {{'
|
|
962
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH {graph}:data {{'
|
|
963
|
+
if sortBy:
|
|
964
|
+
if sortBy == SortBy.CREATED:
|
|
965
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:creationDate ?creationDate .'
|
|
966
|
+
if sortBy == SortBy.LASTMOD:
|
|
967
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:lastModificationDate ?lastModificationDate .'
|
|
968
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s ?p ?o .'
|
|
969
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s rdf:type ?t .'
|
|
970
|
+
if resClass:
|
|
971
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s rdf:type {resClass} .'
|
|
972
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:grantsPermission ?permset .'
|
|
973
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}'
|
|
974
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}FILTER(isLiteral(?o) && (datatype(?o) = xsd:string || datatype(?o) = rdf:langString || lang(?o) != ""))'
|
|
975
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}FILTER(CONTAINS(LCASE(STR(?o)), "{s}")) # case-insensitive substring match'
|
|
976
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{'
|
|
977
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}{con.userIri.toRdf} oldap:hasPermissions ?permset .'
|
|
978
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?permset oldap:givesPermission ?DataPermission .'
|
|
979
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?DataPermission oldap:permissionValue ?permval .'
|
|
980
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}'
|
|
981
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})'
|
|
982
|
+
sparql += f'\n{blank:{indent * indent_inc}}}}'
|
|
983
|
+
|
|
984
|
+
if sortBy:
|
|
985
|
+
if sortBy == SortBy.CREATED:
|
|
986
|
+
sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(?creationDate)'
|
|
987
|
+
if sortBy == SortBy.LASTMOD:
|
|
988
|
+
sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(?lastModificationDate)'
|
|
989
|
+
if sortBy == SortBy.PROPVAL:
|
|
990
|
+
sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(LCASE(STR(?o)))'
|
|
991
|
+
|
|
992
|
+
if not count_only:
|
|
993
|
+
sparql += f'\n{blank:{indent * indent_inc}}LIMIT {limit} OFFSET {offset}'
|
|
994
|
+
sparql += '\n'
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
try:
|
|
998
|
+
jsonres = con.query(sparql)
|
|
999
|
+
except OldapError:
|
|
1000
|
+
print(sparql)
|
|
1001
|
+
raise
|
|
1002
|
+
res = QueryProcessor(context, jsonres)
|
|
1003
|
+
if count_only:
|
|
1004
|
+
return res[0]['numResult']
|
|
1005
|
+
else:
|
|
1006
|
+
result = {}
|
|
1007
|
+
for r in res:
|
|
1008
|
+
tmp = {
|
|
1009
|
+
r['p']: r['o'],
|
|
1010
|
+
Xsd_QName('owl:Class'): r['t']
|
|
1011
|
+
}
|
|
1012
|
+
if sortBy:
|
|
1013
|
+
if sortBy == SortBy.CREATED:
|
|
1014
|
+
tmp['oldap:creationDate'] = r['creationDate'],
|
|
1015
|
+
if sortBy == SortBy.LASTMOD:
|
|
1016
|
+
tmp['oldap:lastModificationDate'] = r['lastModificationDate']
|
|
1017
|
+
result[r['s']] = tmp
|
|
1018
|
+
return result
|
|
1019
|
+
|
|
1020
|
+
@staticmethod
|
|
1021
|
+
def all_resources(con: IConnection,
|
|
1022
|
+
projectShortName: Xsd_NCName | str,
|
|
1023
|
+
resClass: Xsd_QName | str,
|
|
1024
|
+
includeProperties: list[Xsd_QName] | None = None,
|
|
1025
|
+
count_only: bool = False,
|
|
1026
|
+
sortBy: SortBy | None = None,
|
|
1027
|
+
limit: int = 100,
|
|
1028
|
+
offset: int = 0,
|
|
1029
|
+
indent: int = 0, indent_inc: int = 4) -> dict[Iri, dict[str, Xsd]]:
|
|
1030
|
+
"""
|
|
1031
|
+
Retrieves all resources matching the specified parameters from a data store using a SPARQL query.
|
|
1032
|
+
Depending on the `count_only` flag, it can return either a count of matching resources or detailed
|
|
1033
|
+
information about each resource.
|
|
1034
|
+
|
|
1035
|
+
:param con: The connection object used to execute the SPARQL query.
|
|
1036
|
+
:type con: IConnection
|
|
1037
|
+
:param projectShortName: The short name of the project being queried.
|
|
1038
|
+
:type projectShortName: Xsd_NCName | str
|
|
1039
|
+
:param resClass: The resource class to filter the results by.
|
|
1040
|
+
:type resClass: Xsd_QName | str
|
|
1041
|
+
:param includeProperties: A list of resource properties to include in the query and results.
|
|
1042
|
+
:type includeProperties: list[Xsd_QName] | None
|
|
1043
|
+
:param count_only: If True, returns only the count of matching resources. Defaults to False.
|
|
1044
|
+
:type count_only: bool
|
|
1045
|
+
:param sortBy: The sorting criterion for the results. Defaults to None.
|
|
1046
|
+
:type sortBy: SortBy | None
|
|
1047
|
+
:param limit: The maximum number of results to retrieve. Defaults to 100.
|
|
1048
|
+
:type limit: int
|
|
1049
|
+
:param offset: The starting point for result retrieval in pagination. Defaults to 0.
|
|
1050
|
+
:type offset: int
|
|
1051
|
+
:param indent: The initial level of indentation for the SPARQL query strings. Defaults to 0.
|
|
1052
|
+
:type indent: int
|
|
1053
|
+
:param indent_inc: The incremental level of indentation for the SPARQL query strings. Defaults to 4.
|
|
1054
|
+
:type indent_inc: int
|
|
1055
|
+
:return: A dictionary where keys are resource IRIs and values are dictionaries containing resource
|
|
1056
|
+
properties and their corresponding values. If `count_only` is True, returns the total count of
|
|
1057
|
+
matching resources as an integer.
|
|
1058
|
+
:rtype: dict[Iri, dict[str, Xsd]]
|
|
1059
|
+
:raises OldapError: If there is an error during query execution in the connection object.
|
|
1060
|
+
"""
|
|
1061
|
+
if not isinstance(projectShortName, Xsd_NCName):
|
|
1062
|
+
graph = Xsd_NCName(projectShortName, validate=True)
|
|
1063
|
+
else:
|
|
1064
|
+
graph = projectShortName
|
|
1065
|
+
if not isinstance(resClass, Xsd_QName):
|
|
1066
|
+
resClass = Xsd_QName(resClass, validate=True)
|
|
1067
|
+
|
|
1068
|
+
blank = ''
|
|
1069
|
+
context = Context(name=con.context_name)
|
|
1070
|
+
sparql = context.sparql_context
|
|
1071
|
+
|
|
1072
|
+
if (count_only):
|
|
1073
|
+
sparql += f'{blank:{indent * indent_inc}}SELECT (COUNT(DISTINCT ?s) as ?numResult)'
|
|
1074
|
+
else:
|
|
1075
|
+
sparql += f'{blank:{indent * indent_inc}}SELECT DISTINCT ?s'
|
|
1076
|
+
for index, item in enumerate(includeProperties):
|
|
1077
|
+
sparql += f' ?o{index}'
|
|
1078
|
+
if sortBy:
|
|
1079
|
+
if sortBy == SortBy.CREATED:
|
|
1080
|
+
sparql += ' ?creationDate'
|
|
1081
|
+
if sortBy == SortBy.LASTMOD:
|
|
1082
|
+
sparql += '?lastModificationDate'
|
|
1083
|
+
sparql += f'\n{blank:{indent * indent_inc}}WHERE {{'
|
|
1084
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH {graph}:data {{'
|
|
1085
|
+
if sortBy:
|
|
1086
|
+
if sortBy == SortBy.CREATED:
|
|
1087
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:creationDate ?creationDate .'
|
|
1088
|
+
if sortBy == SortBy.LASTMOD:
|
|
1089
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:lastModificationDate ?lastModificationDate .'
|
|
1090
|
+
for index, prop in enumerate(includeProperties):
|
|
1091
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s {prop} ?o{index} .'
|
|
1092
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s rdf:type {resClass} .'
|
|
1093
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:grantsPermission ?permset .'
|
|
1094
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}'
|
|
1095
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{'
|
|
1096
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}{con.userIri.toRdf} oldap:hasPermissions ?permset .'
|
|
1097
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?permset oldap:givesPermission ?DataPermission .'
|
|
1098
|
+
sparql += f'\n{blank:{(indent + 2) * indent_inc}}?DataPermission oldap:permissionValue ?permval .'
|
|
1099
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}'
|
|
1100
|
+
sparql += f'\n{blank:{(indent + 1) * indent_inc}}FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})'
|
|
1101
|
+
sparql += f'\n{blank:{indent * indent_inc}}}}'
|
|
1102
|
+
|
|
1103
|
+
if sortBy:
|
|
1104
|
+
if sortBy == SortBy.CREATED:
|
|
1105
|
+
sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(?creationDate)'
|
|
1106
|
+
if sortBy == SortBy.LASTMOD:
|
|
1107
|
+
sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(?lastModificationDate)'
|
|
1108
|
+
if sortBy == SortBy.PROPVAL:
|
|
1109
|
+
sparql += f'\n{blank:{indent * indent_inc}}ORDER BY'
|
|
1110
|
+
for index, item in enumerate(includeProperties):
|
|
1111
|
+
sparql += f'\n{blank:{indent * indent_inc}} ?o{index}'
|
|
1112
|
+
|
|
1113
|
+
if not count_only:
|
|
1114
|
+
sparql += f'\n{blank:{indent * indent_inc}}LIMIT {limit} OFFSET {offset}'
|
|
1115
|
+
sparql += '\n'
|
|
1116
|
+
|
|
1117
|
+
try:
|
|
1118
|
+
jsonres = con.query(sparql)
|
|
1119
|
+
except OldapError:
|
|
1120
|
+
print(sparql)
|
|
1121
|
+
raise
|
|
1122
|
+
res = QueryProcessor(context, jsonres)
|
|
1123
|
+
if count_only:
|
|
1124
|
+
return res[0]['numResult']
|
|
1125
|
+
else:
|
|
1126
|
+
result = {}
|
|
1127
|
+
for r in res:
|
|
1128
|
+
tmp = {}
|
|
1129
|
+
for index, item in enumerate(includeProperties):
|
|
1130
|
+
tmp[item] = r[f'o{index}']
|
|
1131
|
+
|
|
1132
|
+
if sortBy:
|
|
1133
|
+
if sortBy == SortBy.CREATED:
|
|
1134
|
+
tmp[Xsd_QName('oldap:creationDate')] = r['creationDate']
|
|
1135
|
+
if sortBy == SortBy.LASTMOD:
|
|
1136
|
+
tmp[Xsd_QName('oldap:lastModificationDate')] = r['lastModificationDate']
|
|
1137
|
+
result[r['s']] = tmp
|
|
1138
|
+
return result
|
|
1139
|
+
|
|
1140
|
+
|
|
742
1141
|
def toJsonObject(self) -> dict[str, list[str] | str]:
|
|
743
1142
|
result = {'iri': str(self._iri)}
|
|
744
1143
|
for propiri, values in self._values.items():
|
|
@@ -797,45 +1196,6 @@ class ResourceInstanceFactory:
|
|
|
797
1196
|
'properties': resclass.properties,
|
|
798
1197
|
'superclass': resclass.superclass})
|
|
799
1198
|
|
|
800
|
-
@staticmethod
|
|
801
|
-
def read_data(con: IConnection, projectShortName: Xsd_NCName | str, iri: Iri | str) -> dict[Xsd_QName, Any]:
|
|
802
|
-
if not isinstance(iri, Iri):
|
|
803
|
-
iri = Iri(iri, validate=True)
|
|
804
|
-
if not isinstance(projectShortName, Xsd_NCName):
|
|
805
|
-
graph = Xsd_NCName(projectShortName)
|
|
806
|
-
else:
|
|
807
|
-
graph = projectShortName
|
|
808
|
-
|
|
809
|
-
context = Context(name=con.context_name)
|
|
810
|
-
sparql = context.sparql_context
|
|
811
|
-
sparql += f'''
|
|
812
|
-
SELECT ?predicate ?value
|
|
813
|
-
WHERE {{
|
|
814
|
-
GRAPH {graph}:data {{
|
|
815
|
-
{iri.toRdf} ?predicate ?value .
|
|
816
|
-
{iri.toRdf} oldap:grantsPermission ?permset .
|
|
817
|
-
}}
|
|
818
|
-
GRAPH oldap:admin {{
|
|
819
|
-
{con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
820
|
-
?permset oldap:givesPermission ?DataPermission .
|
|
821
|
-
?DataPermission oldap:permissionValue ?permval .
|
|
822
|
-
}}
|
|
823
|
-
FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})
|
|
824
|
-
}}
|
|
825
|
-
'''
|
|
826
|
-
jsonres = con.query(sparql)
|
|
827
|
-
res = QueryProcessor(context, jsonres)
|
|
828
|
-
data = {}
|
|
829
|
-
for r in res:
|
|
830
|
-
if r['predicate'].is_qname:
|
|
831
|
-
if not data.get(r['predicate'].as_qname):
|
|
832
|
-
data[r['predicate'].as_qname] = []
|
|
833
|
-
data[str(r['predicate'].as_qname)].append(str(r['value']))
|
|
834
|
-
else:
|
|
835
|
-
raise OldapErrorInconsistency(f"Expected QName as predicate, got {r['predicate']}")
|
|
836
|
-
if not data.get('rdf:type'):
|
|
837
|
-
raise OldapErrorNotFound(f'Resource with iri <{iri}> not found.')
|
|
838
|
-
return data
|
|
839
1199
|
|
|
840
1200
|
def read(self, iri: Iri | str) -> ResourceInstance:
|
|
841
1201
|
if not isinstance(iri, Iri):
|
|
@@ -888,69 +1248,6 @@ class ResourceInstanceFactory:
|
|
|
888
1248
|
Instance = self.createObjectInstance(objtype)
|
|
889
1249
|
return Instance(iri=iri, **kwargs)
|
|
890
1250
|
|
|
891
|
-
@staticmethod
|
|
892
|
-
def search_fulltext(con: IConnection,
|
|
893
|
-
projectShortName: Xsd_NCName | str,
|
|
894
|
-
s: str,
|
|
895
|
-
count_only: bool = False,
|
|
896
|
-
limit: int = 100,
|
|
897
|
-
offset: int = 0) -> int | dict[Iri, dict[str, Xsd]]:
|
|
898
|
-
if not isinstance(projectShortName, Xsd_NCName):
|
|
899
|
-
graph = Xsd_NCName(projectShortName)
|
|
900
|
-
else:
|
|
901
|
-
graph = projectShortName
|
|
902
|
-
context = Context(name=con.context_name)
|
|
903
|
-
sparql = context.sparql_context
|
|
904
|
-
if (count_only):
|
|
905
|
-
sparql += "SELECT (COUNT(DISTINCT ?s) as ?numResult)"
|
|
906
|
-
else:
|
|
907
|
-
sparql += "SELECT DISTINCT ?s ?t ?p ?o"
|
|
908
|
-
sparql += f'''
|
|
909
|
-
WHERE {{
|
|
910
|
-
GRAPH {graph}:data {{
|
|
911
|
-
?s ?p ?o .
|
|
912
|
-
?s rdf:type ?t .
|
|
913
|
-
?s oldap:grantsPermission ?permset .
|
|
914
|
-
}}
|
|
915
|
-
FILTER(isLiteral(?o) &&
|
|
916
|
-
(datatype(?o) = xsd:string || datatype(?o) = rdf:langString || lang(?o) != ""))
|
|
917
|
-
FILTER(CONTAINS(LCASE(STR(?o)), "{s}")) # case-insensitive substring match
|
|
918
|
-
GRAPH oldap:admin {{
|
|
919
|
-
{con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
920
|
-
?permset oldap:givesPermission ?DataPermission .
|
|
921
|
-
?DataPermission oldap:permissionValue ?permval .
|
|
922
|
-
}}
|
|
923
|
-
FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})
|
|
924
|
-
}}
|
|
925
|
-
'''
|
|
926
|
-
if not count_only:
|
|
927
|
-
sparql += f'LIMIT {limit} OFFSET {offset}'
|
|
928
|
-
try:
|
|
929
|
-
jsonres = con.query(sparql)
|
|
930
|
-
except OldapError:
|
|
931
|
-
print(sparql)
|
|
932
|
-
raise
|
|
933
|
-
res = QueryProcessor(context, jsonres)
|
|
934
|
-
if count_only:
|
|
935
|
-
return res[0]['numResult']
|
|
936
|
-
else:
|
|
937
|
-
return {Iri(r['s']): {r['p']: r['o']} for r in res}
|
|
938
|
-
# jsonres = con.query(sparql)
|
|
939
|
-
# res = QueryProcessor(context, jsonres)
|
|
940
|
-
# if count_only:
|
|
941
|
-
# if isinstance(res[0]['numResult'], Xsd_integer):
|
|
942
|
-
# tmp = cast(Xsd_integer, res[0]['numResult'])
|
|
943
|
-
# return int(tmp)
|
|
944
|
-
# else:
|
|
945
|
-
# raise OldapErrorInconsistency(f'Expected integer as value, got "{res[0]["numResult"]}"')
|
|
946
|
-
# else:
|
|
947
|
-
# result: dict[Iri, dict[str, Xsd]] = {}
|
|
948
|
-
# for r in res:
|
|
949
|
-
# iri = cast(Iri, r['s'])
|
|
950
|
-
# resclass = cast(Iri, r['t'])
|
|
951
|
-
# result[iri] = {'resclass': resclass, 'property': r['p'], 'value': r['o']}
|
|
952
|
-
# return result
|
|
953
|
-
|
|
954
1251
|
|
|
955
1252
|
|
|
956
1253
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.11"
|
|
@@ -8,7 +8,7 @@ from time import sleep
|
|
|
8
8
|
|
|
9
9
|
from oldaplib.src.cachesingleton import CacheSingletonRedis
|
|
10
10
|
from oldaplib.src.datamodel import DataModel
|
|
11
|
-
from oldaplib.src.objectfactory import ResourceInstanceFactory
|
|
11
|
+
from oldaplib.src.objectfactory import ResourceInstanceFactory, SortBy, ResourceInstance
|
|
12
12
|
from oldaplib.src.connection import Connection
|
|
13
13
|
from oldaplib.src.enums.action import Action
|
|
14
14
|
from oldaplib.src.enums.datapermissions import DataPermission
|
|
@@ -357,7 +357,7 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
357
357
|
pubDate="2001-01-01",
|
|
358
358
|
grantsPermission=Iri('oldap:GenericView'))
|
|
359
359
|
b.create()
|
|
360
|
-
data =
|
|
360
|
+
data = ResourceInstance.read_data(con=self._connection, iri=b.iri, projectShortName='test')
|
|
361
361
|
self.assertEqual(data['rdf:type'], ['test:Book'])
|
|
362
362
|
self.assertEqual(data['test:title'], ['The Life and Times of Scrooge'])
|
|
363
363
|
self.assertEqual(data['test:author'], ['test:TuomasHolopainen'])
|
|
@@ -638,19 +638,84 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
638
638
|
|
|
639
639
|
project = Project.read(con=self._connection, projectIri_SName='test')
|
|
640
640
|
factory = ResourceInstanceFactory(con=self._connection, project=project)
|
|
641
|
+
|
|
642
|
+
Person = factory.createObjectInstance('Person')
|
|
643
|
+
persons = []
|
|
644
|
+
for i in range(4):
|
|
645
|
+
if i % 2 == 0:
|
|
646
|
+
familyName = 'Gaga' + random_string()
|
|
647
|
+
else:
|
|
648
|
+
familyName = random_string()
|
|
649
|
+
p = Person(familyName=familyName,
|
|
650
|
+
givenName=random_string(),
|
|
651
|
+
grantsPermission=Iri('oldap:GenericView'))
|
|
652
|
+
p.create()
|
|
653
|
+
persons.append(p.iri)
|
|
654
|
+
|
|
641
655
|
Book = factory.createObjectInstance('Book')
|
|
642
656
|
for i in range(10):
|
|
643
|
-
|
|
644
|
-
|
|
657
|
+
title = f'These are {random_string()} Tales from the Wood'
|
|
658
|
+
if i % 2 == 0:
|
|
659
|
+
title = 'GAGA' + title
|
|
660
|
+
b = Book(title=title,
|
|
661
|
+
author=persons[i % 4],
|
|
645
662
|
pubDate="1995-09-27",
|
|
646
663
|
grantsPermission=Iri('oldap:GenericView'))
|
|
647
664
|
b.create()
|
|
648
|
-
res = ResourceInstanceFactory.search_fulltext(con=self._connection,
|
|
649
|
-
projectShortName='test',
|
|
650
|
-
s='tales')
|
|
651
665
|
|
|
666
|
+
|
|
667
|
+
res = ResourceInstance.search_fulltext(con=self._connection,
|
|
668
|
+
projectShortName='test',
|
|
669
|
+
resClass='test:Book',
|
|
670
|
+
s='gaga',
|
|
671
|
+
sortBy=SortBy.CREATED)
|
|
672
|
+
|
|
673
|
+
self.assertEqual(len(res), 5)
|
|
652
674
|
for x, y in res.items():
|
|
653
|
-
|
|
675
|
+
self.assertEqual(y[Xsd_QName("owl:Class")], Xsd_QName('test:Book'))
|
|
676
|
+
|
|
677
|
+
res = ResourceInstance.search_fulltext(con=self._connection,
|
|
678
|
+
projectShortName='test',
|
|
679
|
+
s='gaga',
|
|
680
|
+
sortBy=SortBy.CREATED)
|
|
681
|
+
|
|
682
|
+
self.assertEqual(len(res), 7)
|
|
683
|
+
for x, y in res.items():
|
|
684
|
+
self.assertTrue(y[Xsd_QName("owl:Class")] in {Xsd_QName('test:Book'), Xsd_QName('test:Person')})
|
|
685
|
+
|
|
686
|
+
def test_search_resource_B(self):
|
|
687
|
+
|
|
688
|
+
def random_string(length=12):
|
|
689
|
+
chars = string.ascii_letters + string.digits
|
|
690
|
+
return ''.join(random.choices(chars, k=length))
|
|
691
|
+
|
|
692
|
+
project = Project.read(con=self._connection, projectIri_SName='test')
|
|
693
|
+
factory = ResourceInstanceFactory(con=self._connection, project=project)
|
|
694
|
+
Page = factory.createObjectInstance('Page')
|
|
695
|
+
for i in range(1, 11):
|
|
696
|
+
b = Page(pageNum=Xsd_positiveInteger(i),
|
|
697
|
+
pageDesignation=f'Seite {i}',
|
|
698
|
+
pageContent=random_string(16),
|
|
699
|
+
pageInBook=Xsd_QName('test', 'gaga', validate=False),
|
|
700
|
+
grantsPermission=Iri('oldap:GenericView'))
|
|
701
|
+
b.create()
|
|
702
|
+
|
|
703
|
+
Person = factory.createObjectInstance('Person')
|
|
704
|
+
for i in range(4):
|
|
705
|
+
p = Person(familyName=random_string(),
|
|
706
|
+
givenName=random_string(),
|
|
707
|
+
grantsPermission=Iri('oldap:GenericView'))
|
|
708
|
+
p.create()
|
|
709
|
+
|
|
710
|
+
res = ResourceInstance.all_resources(con=self._connection,
|
|
711
|
+
projectShortName='test',
|
|
712
|
+
resClass='test:Page',
|
|
713
|
+
includeProperties=[Xsd_QName('test:pageNum'), Xsd_QName('test:pageContent')],
|
|
714
|
+
sortBy = SortBy.CREATED)
|
|
715
|
+
self.assertEqual(len(res), 10)
|
|
716
|
+
for r in res:
|
|
717
|
+
self.assertEqual(len(res[r]), 3)
|
|
718
|
+
|
|
654
719
|
|
|
655
720
|
|
|
656
721
|
if __name__ == '__main__':
|