oldaplib 0.3.9__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.9 → oldaplib-0.3.11}/PKG-INFO +1 -1
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/objectfactory.py +414 -111
- oldaplib-0.3.11/oldaplib/src/version.py +1 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_objectfactory.py +73 -6
- oldaplib-0.3.11/oldaplib/testdata/instances_test.trig +119 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/pyproject.toml +1 -1
- oldaplib-0.3.9/oldaplib/src/version.py +0 -1
- {oldaplib-0.3.9 → oldaplib-0.3.11}/README.md +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/apps/load_list.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/admin-testing.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/admin.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/example.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/oldap.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/oldap.ttl +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/shared.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/ontologies/standard/.gitsave +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/cachesingleton.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/connection.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/datamodel.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/dtypes/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/dtypes/bnode.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/dtypes/languagein.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/dtypes/namespaceiri.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/dtypes/rdfset.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/dtypes/xsdset.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/action.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/adminpermissions.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/attributeclass.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/datapermissions.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/externalontologyattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/haspropertyattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/language.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/oldaplistattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/oldaplistnodeattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/owlpropertytype.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/permissionsetattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/projectattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/propertyclassattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/resourceclassattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/sparql_result_format.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/userattr.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/enums/xsd_datatypes.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/externalontology.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/globalconfig.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/hasproperty.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/Notify.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/attributechange.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/context.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/convert2datatype.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/irincname.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/json_encoder.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/langstring.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/numeric.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/observable_dict.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/observable_set.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/oldaperror.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/query_processor.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/semantic_version.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/serializeableset.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/serializer.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/singletonmeta.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/helpers/tools.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/iconnection.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/in_project.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/model.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/oldaplist.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/oldaplist_helpers.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/oldaplistnode.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/oldaplogging.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/permissionset.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/project.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/propertyclass.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/resourceclass.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/user.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/userdataclass.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/floatingpoint.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/iri.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_anyuri.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_base64binary.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_boolean.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_byte.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_date.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_datetime.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_datetimestamp.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_decimal.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_double.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_duration.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_float.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gday.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gmonth.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gmonthday.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gyear.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_gyearmonth.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_hexbinary.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_id.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_idref.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_int.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_integer.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_language.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_long.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_name.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_ncname.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_negativeinteger.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_nmtoken.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_nonnegativeinteger.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_nonpositiveinteger.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_normalizedstring.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_positiveinteger.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_qname.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_short.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_string.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_time.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_token.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedbyte.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedint.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedlong.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/src/xsd/xsd_unsignedshort.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/__init__.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_cache.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_connection.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_context.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_datamodel.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_dtypes.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_externalontologies.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_hasproperty.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_in_project.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_langstring.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_language_in.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_observable_dict.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_observable_set.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_oldaplist.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_oldaplist_helpers.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_oldaplistnode.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_permissionset.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_project.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_propertyclass.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_resourceclass.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_semantic_version.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_user.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/test/test_xsd_datatypes.py +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/Gender.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/collections_type.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/connection_test.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/datamodel_test.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/event_type.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/hlist_schema.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/institution_or_building_type.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/language.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/location_type.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/means_of_transportation.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/objectfactory_test.trig +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/playground_list.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/role.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/source_type-1.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/source_type.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/test_move_left_of_toL.yaml +0 -0
- {oldaplib-0.3.9 → oldaplib-0.3.11}/oldaplib/testdata/testlist.yaml +0 -0
- {oldaplib-0.3.9 → 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:
|
|
@@ -443,35 +449,47 @@ class ResourceInstance:
|
|
|
443
449
|
|
|
444
450
|
def get_data_permission(self, context: Context, permission: DataPermission) -> bool:
|
|
445
451
|
permission_query = context.sparql_context
|
|
446
|
-
# language=sparql
|
|
447
452
|
permission_query += f'''
|
|
448
|
-
|
|
449
|
-
FROM oldap:onto
|
|
450
|
-
FROM shared:onto
|
|
451
|
-
FROM {self._graph}:onto
|
|
452
|
-
FROM NAMED oldap:admin
|
|
453
|
-
FROM NAMED {self._graph}:data
|
|
454
|
-
WHERE {{
|
|
455
|
-
BIND({self._iri.toRdf} as ?iri)
|
|
453
|
+
ASK {{
|
|
456
454
|
GRAPH {self._graph}:data {{
|
|
457
|
-
|
|
455
|
+
{self._iri.toRdf} oldap:grantsPermission ?permset .
|
|
458
456
|
}}
|
|
459
|
-
BIND({self._con.userIri.toRdf} as ?user)
|
|
460
457
|
GRAPH oldap:admin {{
|
|
461
|
-
|
|
458
|
+
{self._con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
462
459
|
?permset oldap:givesPermission ?DataPermission .
|
|
463
460
|
?DataPermission oldap:permissionValue ?permval .
|
|
464
461
|
}}
|
|
465
462
|
FILTER(?permval >= {permission.numeric.toRdf})
|
|
466
463
|
}}'''
|
|
464
|
+
|
|
467
465
|
if self._con.in_transaction():
|
|
468
|
-
|
|
466
|
+
result = self._con.transaction_query(permission_query)
|
|
469
467
|
else:
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return res[0]['numOfPermsets'] > 0
|
|
468
|
+
result = self._con.query(permission_query)
|
|
469
|
+
return result['boolean']
|
|
473
470
|
|
|
474
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
|
+
"""
|
|
475
493
|
result, message = self.check_for_permissions(AdminPermission.ADMIN_CREATE)
|
|
476
494
|
if not result:
|
|
477
495
|
raise OldapErrorNoPermission(message)
|
|
@@ -528,6 +546,19 @@ class ResourceInstance:
|
|
|
528
546
|
def read(cls,
|
|
529
547
|
con: IConnection,
|
|
530
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
|
+
"""
|
|
531
562
|
graph = cls.project.projectShortName
|
|
532
563
|
context = Context(name=con.context_name)
|
|
533
564
|
sparql = context.sparql_context
|
|
@@ -576,6 +607,26 @@ class ResourceInstance:
|
|
|
576
607
|
return cls(iri=iri, **kwargs)
|
|
577
608
|
|
|
578
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
|
+
"""
|
|
579
630
|
admin_resources, message = self.check_for_permissions(AdminPermission.ADMIN_RESOURCES)
|
|
580
631
|
|
|
581
632
|
context = Context(name=self._con.context_name)
|
|
@@ -703,16 +754,33 @@ class ResourceInstance:
|
|
|
703
754
|
self.clear_changeset()
|
|
704
755
|
|
|
705
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
|
+
"""
|
|
706
773
|
admin_resources, message = self.check_for_permissions(AdminPermission.ADMIN_RESOURCES)
|
|
707
774
|
|
|
708
775
|
context = Context(name=self._con.context_name)
|
|
709
776
|
inuse = context.sparql_context
|
|
710
|
-
inuse
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
777
|
+
inuse += f"""
|
|
778
|
+
ASK {{
|
|
779
|
+
GRAPH ?g {{
|
|
780
|
+
?res ?prop {self._iri.toRdf} .
|
|
781
|
+
}}
|
|
714
782
|
}}
|
|
715
|
-
|
|
783
|
+
"""
|
|
716
784
|
|
|
717
785
|
context = Context(name=self._con.context_name)
|
|
718
786
|
sparql = context.sparql_context
|
|
@@ -730,9 +798,8 @@ class ResourceInstance:
|
|
|
730
798
|
self._con.transaction_abort()
|
|
731
799
|
raise OldapErrorNoPermission(f'No permission to update resource "{self._iri}"')
|
|
732
800
|
try:
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
if res[0]['nres'] > 0:
|
|
801
|
+
result = self._con.transaction_query(inuse)
|
|
802
|
+
if result['boolean']:
|
|
736
803
|
raise OldapErrorInUse(f'Resource "{self._iri}" is in use and cannot be deleted.')
|
|
737
804
|
except OldapError:
|
|
738
805
|
self._con.transaction_abort()
|
|
@@ -748,6 +815,329 @@ class ResourceInstance:
|
|
|
748
815
|
self._con.transaction_abort()
|
|
749
816
|
raise
|
|
750
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
|
+
|
|
751
1141
|
def toJsonObject(self) -> dict[str, list[str] | str]:
|
|
752
1142
|
result = {'iri': str(self._iri)}
|
|
753
1143
|
for propiri, values in self._values.items():
|
|
@@ -791,9 +1181,6 @@ class ResourceInstanceFactory:
|
|
|
791
1181
|
|
|
792
1182
|
self._datamodel = DataModel.read(con=self._con, project=self._project, ignore_cache=True)
|
|
793
1183
|
|
|
794
|
-
#self._oldap_project = Project.read(self._con, "oldap")
|
|
795
|
-
#self._oldap_datamodel = DataModel.read(con=self._con, project=self._oldap_project)
|
|
796
|
-
|
|
797
1184
|
def createObjectInstance(self, name: Xsd_NCName | str) -> Type: ## ToDo: Get name automatically from IRI
|
|
798
1185
|
classiri = Xsd_QName(self._project.projectShortName, name)
|
|
799
1186
|
resclass = self._datamodel.get(classiri)
|
|
@@ -809,46 +1196,6 @@ class ResourceInstanceFactory:
|
|
|
809
1196
|
'properties': resclass.properties,
|
|
810
1197
|
'superclass': resclass.superclass})
|
|
811
1198
|
|
|
812
|
-
@staticmethod
|
|
813
|
-
def read_data(con: IConnection, projectShortName: Xsd_NCName | str, iri: Iri | str) -> dict[Xsd_QName, Any]:
|
|
814
|
-
if not isinstance(iri, Iri):
|
|
815
|
-
iri = Iri(iri, validate=True)
|
|
816
|
-
if not isinstance(projectShortName, Xsd_NCName):
|
|
817
|
-
graph = Xsd_NCName(projectShortName)
|
|
818
|
-
else:
|
|
819
|
-
graph = projectShortName
|
|
820
|
-
|
|
821
|
-
context = Context(name=con.context_name)
|
|
822
|
-
sparql = context.sparql_context
|
|
823
|
-
sparql += f'''
|
|
824
|
-
SELECT ?predicate ?value
|
|
825
|
-
WHERE {{
|
|
826
|
-
GRAPH {graph}:data {{
|
|
827
|
-
{iri.toRdf} ?predicate ?value .
|
|
828
|
-
{iri.toRdf} oldap:grantsPermission ?permset .
|
|
829
|
-
}}
|
|
830
|
-
GRAPH oldap:admin {{
|
|
831
|
-
{con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
832
|
-
?permset oldap:givesPermission ?DataPermission .
|
|
833
|
-
?DataPermission oldap:permissionValue ?permval .
|
|
834
|
-
}}
|
|
835
|
-
FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})
|
|
836
|
-
}}
|
|
837
|
-
'''
|
|
838
|
-
jsonres = con.query(sparql)
|
|
839
|
-
res = QueryProcessor(context, jsonres)
|
|
840
|
-
data = {}
|
|
841
|
-
for r in res:
|
|
842
|
-
if r['predicate'].is_qname:
|
|
843
|
-
if not data.get(r['predicate'].as_qname):
|
|
844
|
-
data[r['predicate'].as_qname] = []
|
|
845
|
-
data[str(r['predicate'].as_qname)].append(str(r['value']))
|
|
846
|
-
else:
|
|
847
|
-
raise OldapErrorInconsistency(f"Expected QName as predicate, got {r['predicate']}")
|
|
848
|
-
if not data.get('rdf:type'):
|
|
849
|
-
raise OldapErrorNotFound(f'Resource with iri <{iri}> not found.')
|
|
850
|
-
return data
|
|
851
|
-
|
|
852
1199
|
|
|
853
1200
|
def read(self, iri: Iri | str) -> ResourceInstance:
|
|
854
1201
|
if not isinstance(iri, Iri):
|
|
@@ -901,50 +1248,6 @@ class ResourceInstanceFactory:
|
|
|
901
1248
|
Instance = self.createObjectInstance(objtype)
|
|
902
1249
|
return Instance(iri=iri, **kwargs)
|
|
903
1250
|
|
|
904
|
-
def search_fulltext(self, s: str, count_only: bool = False, limit: int = 100, offset: int = 0) -> int | dict[Iri, dict[str, Xsd]]:
|
|
905
|
-
graph = self._project.projectShortName
|
|
906
|
-
context = Context(name=self._con.context_name)
|
|
907
|
-
sparql = context.sparql_context
|
|
908
|
-
if (count_only):
|
|
909
|
-
sparql += "SELECT (COUNT(DISTINCT ?s) as ?numResult)"
|
|
910
|
-
else:
|
|
911
|
-
sparql += "SELECT DISTINCT ?s ?t ?p ?o"
|
|
912
|
-
sparql += f'''
|
|
913
|
-
WHERE {{
|
|
914
|
-
GRAPH {graph}:data {{
|
|
915
|
-
?s ?p ?o .
|
|
916
|
-
?s rdf:type ?t .
|
|
917
|
-
?s oldap:grantsPermission ?permset .
|
|
918
|
-
}}
|
|
919
|
-
FILTER(isLiteral(?o) &&
|
|
920
|
-
(datatype(?o) = xsd:string || datatype(?o) = rdf:langString || lang(?o) != ""))
|
|
921
|
-
FILTER(CONTAINS(LCASE(STR(?o)), "{s}")) # case-insensitive substring match
|
|
922
|
-
GRAPH oldap:admin {{
|
|
923
|
-
{self._con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
924
|
-
?permset oldap:givesPermission ?DataPermission .
|
|
925
|
-
?DataPermission oldap:permissionValue ?permval .
|
|
926
|
-
}}
|
|
927
|
-
FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})
|
|
928
|
-
}}
|
|
929
|
-
'''
|
|
930
|
-
if not count_only:
|
|
931
|
-
sparql += f'LIMIT {limit} OFFSET {offset}'
|
|
932
|
-
jsonres = self._con.query(sparql)
|
|
933
|
-
res = QueryProcessor(context, jsonres)
|
|
934
|
-
if count_only:
|
|
935
|
-
if isinstance(res[0]['numResult'], Xsd_integer):
|
|
936
|
-
tmp = cast(Xsd_integer, res[0]['numResult'])
|
|
937
|
-
return int(tmp)
|
|
938
|
-
else:
|
|
939
|
-
raise OldapErrorInconsistency(f'Expected integer as value, got "{res[0]["numResult"]}"')
|
|
940
|
-
else:
|
|
941
|
-
result: dict[Iri, dict[str, Xsd]] = {}
|
|
942
|
-
for r in res:
|
|
943
|
-
iri = cast(Iri, r['s'])
|
|
944
|
-
resclass = cast(Iri, r['t'])
|
|
945
|
-
result[iri] = {'resclass': resclass, 'property': r['p'], 'value': r['o']}
|
|
946
|
-
return result
|
|
947
|
-
|
|
948
1251
|
|
|
949
1252
|
|
|
950
1253
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.11"
|