oldaplib 0.3.10__tar.gz → 0.3.12__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.
Files changed (164) hide show
  1. {oldaplib-0.3.10 → oldaplib-0.3.12}/PKG-INFO +1 -1
  2. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/datamodel.py +4 -1
  3. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/objectfactory.py +403 -102
  4. oldaplib-0.3.12/oldaplib/src/version.py +1 -0
  5. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_objectfactory.py +65 -36
  6. oldaplib-0.3.12/oldaplib/testdata/instances_test.trig +119 -0
  7. {oldaplib-0.3.10 → oldaplib-0.3.12}/pyproject.toml +1 -1
  8. oldaplib-0.3.10/oldaplib/src/version.py +0 -1
  9. {oldaplib-0.3.10 → oldaplib-0.3.12}/README.md +0 -0
  10. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/__init__.py +0 -0
  11. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/apps/load_list.py +0 -0
  12. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/admin-testing.trig +0 -0
  13. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/admin.trig +0 -0
  14. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/example.trig +0 -0
  15. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/oldap.trig +0 -0
  16. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/oldap.ttl +0 -0
  17. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/shared.trig +0 -0
  18. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/ontologies/standard/.gitsave +0 -0
  19. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/__init__.py +0 -0
  20. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/cachesingleton.py +0 -0
  21. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/connection.py +0 -0
  22. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/dtypes/__init__.py +0 -0
  23. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/dtypes/bnode.py +0 -0
  24. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/dtypes/languagein.py +0 -0
  25. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/dtypes/namespaceiri.py +0 -0
  26. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/dtypes/rdfset.py +0 -0
  27. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/dtypes/xsdset.py +0 -0
  28. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/__init__.py +0 -0
  29. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/action.py +0 -0
  30. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/adminpermissions.py +0 -0
  31. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/attributeclass.py +0 -0
  32. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/datapermissions.py +0 -0
  33. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/externalontologyattr.py +0 -0
  34. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/haspropertyattr.py +0 -0
  35. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/language.py +0 -0
  36. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/oldaplistattr.py +0 -0
  37. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/oldaplistnodeattr.py +0 -0
  38. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/owlpropertytype.py +0 -0
  39. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/permissionsetattr.py +0 -0
  40. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/projectattr.py +0 -0
  41. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/propertyclassattr.py +0 -0
  42. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/resourceclassattr.py +0 -0
  43. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/sparql_result_format.py +0 -0
  44. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/userattr.py +0 -0
  45. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/enums/xsd_datatypes.py +0 -0
  46. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/externalontology.py +0 -0
  47. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/globalconfig.py +0 -0
  48. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/hasproperty.py +0 -0
  49. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/Notify.py +0 -0
  50. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/__init__.py +0 -0
  51. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/attributechange.py +0 -0
  52. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/context.py +0 -0
  53. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/convert2datatype.py +0 -0
  54. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/irincname.py +0 -0
  55. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/json_encoder.py +0 -0
  56. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/langstring.py +0 -0
  57. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/numeric.py +0 -0
  58. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/observable_dict.py +0 -0
  59. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/observable_set.py +0 -0
  60. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/oldaperror.py +0 -0
  61. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/query_processor.py +0 -0
  62. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/semantic_version.py +0 -0
  63. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/serializeableset.py +0 -0
  64. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/serializer.py +0 -0
  65. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/singletonmeta.py +0 -0
  66. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/helpers/tools.py +0 -0
  67. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/iconnection.py +0 -0
  68. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/in_project.py +0 -0
  69. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/model.py +0 -0
  70. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/oldaplist.py +0 -0
  71. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/oldaplist_helpers.py +0 -0
  72. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/oldaplistnode.py +0 -0
  73. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/oldaplogging.py +0 -0
  74. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/permissionset.py +0 -0
  75. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/project.py +0 -0
  76. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/propertyclass.py +0 -0
  77. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/resourceclass.py +0 -0
  78. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/user.py +0 -0
  79. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/userdataclass.py +0 -0
  80. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/__init__.py +0 -0
  81. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/floatingpoint.py +0 -0
  82. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/iri.py +0 -0
  83. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd.py +0 -0
  84. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_anyuri.py +0 -0
  85. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_base64binary.py +0 -0
  86. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_boolean.py +0 -0
  87. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_byte.py +0 -0
  88. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_date.py +0 -0
  89. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_datetime.py +0 -0
  90. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_datetimestamp.py +0 -0
  91. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_decimal.py +0 -0
  92. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_double.py +0 -0
  93. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_duration.py +0 -0
  94. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_float.py +0 -0
  95. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_gday.py +0 -0
  96. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_gmonth.py +0 -0
  97. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_gmonthday.py +0 -0
  98. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_gyear.py +0 -0
  99. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_gyearmonth.py +0 -0
  100. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_hexbinary.py +0 -0
  101. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_id.py +0 -0
  102. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_idref.py +0 -0
  103. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_int.py +0 -0
  104. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_integer.py +0 -0
  105. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_language.py +0 -0
  106. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_long.py +0 -0
  107. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_name.py +0 -0
  108. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_ncname.py +0 -0
  109. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_negativeinteger.py +0 -0
  110. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_nmtoken.py +0 -0
  111. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_nonnegativeinteger.py +0 -0
  112. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_nonpositiveinteger.py +0 -0
  113. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_normalizedstring.py +0 -0
  114. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_positiveinteger.py +0 -0
  115. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_qname.py +0 -0
  116. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_short.py +0 -0
  117. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_string.py +0 -0
  118. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_time.py +0 -0
  119. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_token.py +0 -0
  120. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_unsignedbyte.py +0 -0
  121. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_unsignedint.py +0 -0
  122. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_unsignedlong.py +0 -0
  123. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/src/xsd/xsd_unsignedshort.py +0 -0
  124. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/__init__.py +0 -0
  125. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_cache.py +0 -0
  126. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_connection.py +0 -0
  127. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_context.py +0 -0
  128. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_datamodel.py +0 -0
  129. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_dtypes.py +0 -0
  130. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_externalontologies.py +0 -0
  131. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_hasproperty.py +0 -0
  132. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_in_project.py +0 -0
  133. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_langstring.py +0 -0
  134. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_language_in.py +0 -0
  135. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_observable_dict.py +0 -0
  136. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_observable_set.py +0 -0
  137. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_oldaplist.py +0 -0
  138. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_oldaplist_helpers.py +0 -0
  139. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_oldaplistnode.py +0 -0
  140. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_permissionset.py +0 -0
  141. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_project.py +0 -0
  142. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_propertyclass.py +0 -0
  143. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_resourceclass.py +0 -0
  144. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_semantic_version.py +0 -0
  145. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_user.py +0 -0
  146. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/test/test_xsd_datatypes.py +0 -0
  147. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/Gender.yaml +0 -0
  148. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/collections_type.yaml +0 -0
  149. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/connection_test.trig +0 -0
  150. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/datamodel_test.trig +0 -0
  151. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/event_type.yaml +0 -0
  152. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/hlist_schema.yaml +0 -0
  153. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/institution_or_building_type.yaml +0 -0
  154. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/language.yaml +0 -0
  155. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/location_type.yaml +0 -0
  156. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/means_of_transportation.yaml +0 -0
  157. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/objectfactory_test.trig +0 -0
  158. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/playground_list.yaml +0 -0
  159. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/role.yaml +0 -0
  160. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/source_type-1.yaml +0 -0
  161. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/source_type.yaml +0 -0
  162. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/test_move_left_of_toL.yaml +0 -0
  163. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testdata/testlist.yaml +0 -0
  164. {oldaplib-0.3.10 → oldaplib-0.3.12}/oldaplib/testit.http +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: oldaplib
3
- Version: 0.3.10
3
+ Version: 0.3.12
4
4
  Summary: Open Media Access Server Library (Linked Open Data middleware/RESTApi)
5
5
  License: GNU Affero General Public License version 3
6
6
  Author: Lukas Rosenthaler
@@ -753,15 +753,18 @@ class DataModel(Model):
753
753
  f.write('\n')
754
754
  f.write(context.turtle_context)
755
755
  f.write(f'\n{blank:{indent * indent_inc}}{self.__graph}:shacl {{\n')
756
- f.write(f'{blank:{(indent + 2) * indent_inc}}{self.__graph}:shapes schema:version {self.__version.toRdf} .\n')
756
+ f.write(f'{blank:{(indent + 1) * indent_inc}}{self.__graph}:shapes schema:version {self.__version.toRdf} .\n')
757
757
  f.write('\n')
758
758
  for qname, onto in self.__extontos.items():
759
759
  f.write(onto.create_shacl(timestamp=timestamp, indent=1))
760
+ f.write('\n\n')
760
761
  for iri, prop in self.__propclasses.items():
761
762
  if not prop.internal:
762
763
  f.write(prop.create_shacl(timestamp=timestamp, indent=1))
764
+ f.write('\n\n')
763
765
  for iri, resclass in self.__resclasses.items():
764
766
  f.write(resclass.create_shacl(timestamp=timestamp, indent=1))
767
+ f.write('\n\n')
765
768
  f.write(f'\n{blank:{indent * indent_inc}}}}\n')
766
769
 
767
770
  f.write(f'{blank:{indent * indent_inc}}{self.__graph}:onto {{\n')
@@ -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,333 @@ 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
+ countOnly: 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 countOnly: If True, only the count of matching entities will be returned. Defaults to False.
900
+ :type countOnly: 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 (countOnly):
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 countOnly:
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 countOnly:
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
+ if includeProperties:
1077
+ for index, item in enumerate(includeProperties):
1078
+ sparql += f' ?o{index}'
1079
+ if sortBy:
1080
+ if sortBy == SortBy.CREATED:
1081
+ sparql += ' ?creationDate'
1082
+ if sortBy == SortBy.LASTMOD:
1083
+ sparql += '?lastModificationDate'
1084
+ sparql += f'\n{blank:{indent * indent_inc}}WHERE {{'
1085
+ sparql += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH {graph}:data {{'
1086
+ if sortBy:
1087
+ if sortBy == SortBy.CREATED:
1088
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:creationDate ?creationDate .'
1089
+ if sortBy == SortBy.LASTMOD:
1090
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:lastModificationDate ?lastModificationDate .'
1091
+ if includeProperties:
1092
+ for index, prop in enumerate(includeProperties):
1093
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s {prop} ?o{index} .'
1094
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s rdf:type {resClass} .'
1095
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?s oldap:grantsPermission ?permset .'
1096
+ sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}'
1097
+ sparql += f'\n{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{'
1098
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}{con.userIri.toRdf} oldap:hasPermissions ?permset .'
1099
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?permset oldap:givesPermission ?DataPermission .'
1100
+ sparql += f'\n{blank:{(indent + 2) * indent_inc}}?DataPermission oldap:permissionValue ?permval .'
1101
+ sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}'
1102
+ sparql += f'\n{blank:{(indent + 1) * indent_inc}}FILTER(?permval >= {DataPermission.DATA_VIEW.numeric.toRdf})'
1103
+ sparql += f'\n{blank:{indent * indent_inc}}}}'
1104
+
1105
+ if sortBy:
1106
+ if sortBy == SortBy.CREATED:
1107
+ sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(?creationDate)'
1108
+ if sortBy == SortBy.LASTMOD:
1109
+ sparql += f'\n{blank:{indent * indent_inc}}ORDER BY ASC(?lastModificationDate)'
1110
+ if sortBy == SortBy.PROPVAL:
1111
+ sparql += f'\n{blank:{indent * indent_inc}}ORDER BY'
1112
+ if includeProperties:
1113
+ for index, item in enumerate(includeProperties):
1114
+ sparql += f'\n{blank:{indent * indent_inc}} ?o{index}'
1115
+
1116
+ if not count_only:
1117
+ sparql += f'\n{blank:{indent * indent_inc}}LIMIT {limit} OFFSET {offset}'
1118
+ sparql += '\n'
1119
+
1120
+ try:
1121
+ jsonres = con.query(sparql)
1122
+ except OldapError:
1123
+ print(sparql)
1124
+ raise
1125
+ res = QueryProcessor(context, jsonres)
1126
+ if count_only:
1127
+ return res[0]['numResult']
1128
+ else:
1129
+ result = {}
1130
+ for r in res:
1131
+ tmp = {}
1132
+ if includeProperties:
1133
+ for index, item in enumerate(includeProperties):
1134
+ tmp[item] = r[f'o{index}']
1135
+
1136
+ if sortBy:
1137
+ if sortBy == SortBy.CREATED:
1138
+ tmp[Xsd_QName('oldap:creationDate')] = r['creationDate']
1139
+ if sortBy == SortBy.LASTMOD:
1140
+ tmp[Xsd_QName('oldap:lastModificationDate')] = r['lastModificationDate']
1141
+ result[r['s']] = tmp
1142
+ return result
1143
+
1144
+
742
1145
  def toJsonObject(self) -> dict[str, list[str] | str]:
743
1146
  result = {'iri': str(self._iri)}
744
1147
  for propiri, values in self._values.items():
@@ -797,45 +1200,6 @@ class ResourceInstanceFactory:
797
1200
  'properties': resclass.properties,
798
1201
  'superclass': resclass.superclass})
799
1202
 
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
1203
 
840
1204
  def read(self, iri: Iri | str) -> ResourceInstance:
841
1205
  if not isinstance(iri, Iri):
@@ -888,69 +1252,6 @@ class ResourceInstanceFactory:
888
1252
  Instance = self.createObjectInstance(objtype)
889
1253
  return Instance(iri=iri, **kwargs)
890
1254
 
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
1255
 
955
1256
 
956
1257
 
@@ -0,0 +1 @@
1
+ __version__ = "0.3.12"