oldaplib 0.3.9__py3-none-any.whl → 0.3.10__py3-none-any.whl
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/src/objectfactory.py +50 -44
- oldaplib/src/version.py +1 -1
- oldaplib/test/test_objectfactory.py +3 -1
- {oldaplib-0.3.9.dist-info → oldaplib-0.3.10.dist-info}/METADATA +1 -1
- {oldaplib-0.3.9.dist-info → oldaplib-0.3.10.dist-info}/RECORD +6 -6
- {oldaplib-0.3.9.dist-info → oldaplib-0.3.10.dist-info}/WHEEL +0 -0
oldaplib/src/objectfactory.py
CHANGED
|
@@ -443,33 +443,24 @@ class ResourceInstance:
|
|
|
443
443
|
|
|
444
444
|
def get_data_permission(self, context: Context, permission: DataPermission) -> bool:
|
|
445
445
|
permission_query = context.sparql_context
|
|
446
|
-
# language=sparql
|
|
447
446
|
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)
|
|
447
|
+
ASK {{
|
|
456
448
|
GRAPH {self._graph}:data {{
|
|
457
|
-
|
|
449
|
+
{self._iri.toRdf} oldap:grantsPermission ?permset .
|
|
458
450
|
}}
|
|
459
|
-
BIND({self._con.userIri.toRdf} as ?user)
|
|
460
451
|
GRAPH oldap:admin {{
|
|
461
|
-
|
|
452
|
+
{self._con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
462
453
|
?permset oldap:givesPermission ?DataPermission .
|
|
463
454
|
?DataPermission oldap:permissionValue ?permval .
|
|
464
455
|
}}
|
|
465
456
|
FILTER(?permval >= {permission.numeric.toRdf})
|
|
466
457
|
}}'''
|
|
458
|
+
|
|
467
459
|
if self._con.in_transaction():
|
|
468
|
-
|
|
460
|
+
result = self._con.transaction_query(permission_query)
|
|
469
461
|
else:
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return res[0]['numOfPermsets'] > 0
|
|
462
|
+
result = self._con.query(permission_query)
|
|
463
|
+
return result['boolean']
|
|
473
464
|
|
|
474
465
|
def create(self, indent: int = 0, indent_inc: int = 4) -> str:
|
|
475
466
|
result, message = self.check_for_permissions(AdminPermission.ADMIN_CREATE)
|
|
@@ -707,12 +698,13 @@ class ResourceInstance:
|
|
|
707
698
|
|
|
708
699
|
context = Context(name=self._con.context_name)
|
|
709
700
|
inuse = context.sparql_context
|
|
710
|
-
inuse
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
701
|
+
inuse += f"""
|
|
702
|
+
ASK {{
|
|
703
|
+
GRAPH ?g {{
|
|
704
|
+
?res ?prop {self._iri.toRdf} .
|
|
705
|
+
}}
|
|
714
706
|
}}
|
|
715
|
-
|
|
707
|
+
"""
|
|
716
708
|
|
|
717
709
|
context = Context(name=self._con.context_name)
|
|
718
710
|
sparql = context.sparql_context
|
|
@@ -730,9 +722,8 @@ class ResourceInstance:
|
|
|
730
722
|
self._con.transaction_abort()
|
|
731
723
|
raise OldapErrorNoPermission(f'No permission to update resource "{self._iri}"')
|
|
732
724
|
try:
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
if res[0]['nres'] > 0:
|
|
725
|
+
result = self._con.transaction_query(inuse)
|
|
726
|
+
if result['boolean']:
|
|
736
727
|
raise OldapErrorInUse(f'Resource "{self._iri}" is in use and cannot be deleted.')
|
|
737
728
|
except OldapError:
|
|
738
729
|
self._con.transaction_abort()
|
|
@@ -791,9 +782,6 @@ class ResourceInstanceFactory:
|
|
|
791
782
|
|
|
792
783
|
self._datamodel = DataModel.read(con=self._con, project=self._project, ignore_cache=True)
|
|
793
784
|
|
|
794
|
-
#self._oldap_project = Project.read(self._con, "oldap")
|
|
795
|
-
#self._oldap_datamodel = DataModel.read(con=self._con, project=self._oldap_project)
|
|
796
|
-
|
|
797
785
|
def createObjectInstance(self, name: Xsd_NCName | str) -> Type: ## ToDo: Get name automatically from IRI
|
|
798
786
|
classiri = Xsd_QName(self._project.projectShortName, name)
|
|
799
787
|
resclass = self._datamodel.get(classiri)
|
|
@@ -849,7 +837,6 @@ class ResourceInstanceFactory:
|
|
|
849
837
|
raise OldapErrorNotFound(f'Resource with iri <{iri}> not found.')
|
|
850
838
|
return data
|
|
851
839
|
|
|
852
|
-
|
|
853
840
|
def read(self, iri: Iri | str) -> ResourceInstance:
|
|
854
841
|
if not isinstance(iri, Iri):
|
|
855
842
|
iri = Iri(iri, validate=True)
|
|
@@ -901,9 +888,18 @@ class ResourceInstanceFactory:
|
|
|
901
888
|
Instance = self.createObjectInstance(objtype)
|
|
902
889
|
return Instance(iri=iri, **kwargs)
|
|
903
890
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
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)
|
|
907
903
|
sparql = context.sparql_context
|
|
908
904
|
if (count_only):
|
|
909
905
|
sparql += "SELECT (COUNT(DISTINCT ?s) as ?numResult)"
|
|
@@ -920,7 +916,7 @@ class ResourceInstanceFactory:
|
|
|
920
916
|
(datatype(?o) = xsd:string || datatype(?o) = rdf:langString || lang(?o) != ""))
|
|
921
917
|
FILTER(CONTAINS(LCASE(STR(?o)), "{s}")) # case-insensitive substring match
|
|
922
918
|
GRAPH oldap:admin {{
|
|
923
|
-
{
|
|
919
|
+
{con.userIri.toRdf} oldap:hasPermissions ?permset .
|
|
924
920
|
?permset oldap:givesPermission ?DataPermission .
|
|
925
921
|
?DataPermission oldap:permissionValue ?permval .
|
|
926
922
|
}}
|
|
@@ -929,21 +925,31 @@ class ResourceInstanceFactory:
|
|
|
929
925
|
'''
|
|
930
926
|
if not count_only:
|
|
931
927
|
sparql += f'LIMIT {limit} OFFSET {offset}'
|
|
932
|
-
|
|
928
|
+
try:
|
|
929
|
+
jsonres = con.query(sparql)
|
|
930
|
+
except OldapError:
|
|
931
|
+
print(sparql)
|
|
932
|
+
raise
|
|
933
933
|
res = QueryProcessor(context, jsonres)
|
|
934
934
|
if count_only:
|
|
935
|
-
|
|
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"]}"')
|
|
935
|
+
return res[0]['numResult']
|
|
940
936
|
else:
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
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
|
|
947
953
|
|
|
948
954
|
|
|
949
955
|
|
oldaplib/src/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.3.
|
|
1
|
+
__version__ = "0.3.10"
|
|
@@ -645,7 +645,9 @@ class TestObjectFactory(unittest.TestCase):
|
|
|
645
645
|
pubDate="1995-09-27",
|
|
646
646
|
grantsPermission=Iri('oldap:GenericView'))
|
|
647
647
|
b.create()
|
|
648
|
-
res =
|
|
648
|
+
res = ResourceInstanceFactory.search_fulltext(con=self._connection,
|
|
649
|
+
projectShortName='test',
|
|
650
|
+
s='tales')
|
|
649
651
|
|
|
650
652
|
for x, y in res.items():
|
|
651
653
|
print(x, y)
|
|
@@ -59,7 +59,7 @@ oldaplib/src/helpers/tools.py,sha256=sNbiOLucTGNFzZmiWwPLFOb80VTXQH0Zd9uCGubhzAk
|
|
|
59
59
|
oldaplib/src/iconnection.py,sha256=XlOc2Kh4tK_UOHydLQwlWjUFLUze-Aq_vEZpf9KS1-s,3677
|
|
60
60
|
oldaplib/src/in_project.py,sha256=2KuhHPj8DNveFRBeImrRfxlCOYhBK-mcxXYUp6s--j8,10672
|
|
61
61
|
oldaplib/src/model.py,sha256=VACR3T6zJYFaE5J1PFFdP0OSwhbu4sahoLMWg6_L_rE,19267
|
|
62
|
-
oldaplib/src/objectfactory.py,sha256=
|
|
62
|
+
oldaplib/src/objectfactory.py,sha256=RIKm45-fApX1--fW_G5NzDzdnoCbW08e4Sb2fgufViI,47088
|
|
63
63
|
oldaplib/src/oldaplist.py,sha256=sGAvEEJukRCjM70G0NFaR-L9YPleQTOtdWGExj3oYL8,42933
|
|
64
64
|
oldaplib/src/oldaplist_helpers.py,sha256=1Gur0nS1PCKb9iUtCKPUFDOYjw6vvAwYpe-G3DdxlEc,14213
|
|
65
65
|
oldaplib/src/oldaplistnode.py,sha256=NnC2juEGTtEkDO6OlB9PjSw_zTF-wSsRUgEk-6VV9DA,87344
|
|
@@ -70,7 +70,7 @@ oldaplib/src/propertyclass.py,sha256=pnaDsmyGKQnJaaOHXA0XyLcp4zn1b1vC9sLbjXls4lM
|
|
|
70
70
|
oldaplib/src/resourceclass.py,sha256=EIxyd7Z_w59wDxWLXCaLvhhvh5SjLEUWb8gqmZz8LLM,102046
|
|
71
71
|
oldaplib/src/user.py,sha256=Z4GXPRkaHXx3glUpPXQdFqYMxQPOuqayDwkTAE5RGjU,48820
|
|
72
72
|
oldaplib/src/userdataclass.py,sha256=FbZkcRt0pKbOeqsZ7HbpwoKE-XPWH2AqpHG1GcsrBPo,12364
|
|
73
|
-
oldaplib/src/version.py,sha256=
|
|
73
|
+
oldaplib/src/version.py,sha256=88sMV1NYWroy2-572uHnugaP-FYZbIQpcERC-gtfC5s,22
|
|
74
74
|
oldaplib/src/xsd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
75
75
|
oldaplib/src/xsd/floatingpoint.py,sha256=rDReKqh0mXyc4F5wslgTUxbeGf3-PGERyughj5_62YI,8852
|
|
76
76
|
oldaplib/src/xsd/iri.py,sha256=w1Dr0z-REi7yPe3GPGnyzGrLVMvLY03kEeK-AmZ9sxw,8383
|
|
@@ -126,7 +126,7 @@ oldaplib/test/test_hasproperty.py,sha256=r991g8kBTfv1CGs9Hf0fli-AUp7Ob7rOHWYD74h
|
|
|
126
126
|
oldaplib/test/test_in_project.py,sha256=DYT-guwRQ9crnfEt7cQZxoEMxThin7QeymNce3jaZx4,7779
|
|
127
127
|
oldaplib/test/test_langstring.py,sha256=37BeKiQzj63G-SyS_paK_SEG7ulRbGrE89Mz40UB_bE,15146
|
|
128
128
|
oldaplib/test/test_language_in.py,sha256=ELqHO-YIsZSCPF3E3rWde4J7rERL7En7sV_pzQ00zgs,8826
|
|
129
|
-
oldaplib/test/test_objectfactory.py,sha256=
|
|
129
|
+
oldaplib/test/test_objectfactory.py,sha256=J9EIu7Ln-G-vzNhvFGKw-mnhXug1EVWs_20petgPoB4,34613
|
|
130
130
|
oldaplib/test/test_observable_dict.py,sha256=GxD0sM0nsVfVRBu92SFGkJ6--YXq4ibBWI4IpjZZzDU,1396
|
|
131
131
|
oldaplib/test/test_observable_set.py,sha256=JWZSoAsr8XIEBXPVgSVJjQQEEc8uSAme5IrFYLYVVXw,6313
|
|
132
132
|
oldaplib/test/test_oldaplist.py,sha256=9wo3tEOHt5bIuXyvSSyTzjhtdKrQHiiAA6EfVBuq4wI,20114
|
|
@@ -157,6 +157,6 @@ oldaplib/testdata/source_type.yaml,sha256=dSihKikw3O-IlGf6anj5KWMoBYLaweLVF1Zojm
|
|
|
157
157
|
oldaplib/testdata/test_move_left_of_toL.yaml,sha256=2m1OSQrQFlsCQxeJrjzBAO74LMprNDo_HuyrYGsOeXI,787
|
|
158
158
|
oldaplib/testdata/testlist.yaml,sha256=AT11nXEG81Sfyb-tr1gQV0H_dZBrOCcFuHf7YtL8P2g,1994
|
|
159
159
|
oldaplib/testit.http,sha256=qW7mnr6aNLXFG6lQdLgyhXILOPN6qc5iFVZclLyVvkY,303
|
|
160
|
-
oldaplib-0.3.
|
|
161
|
-
oldaplib-0.3.
|
|
162
|
-
oldaplib-0.3.
|
|
160
|
+
oldaplib-0.3.10.dist-info/METADATA,sha256=l6lpn1epR1VxIa_BuW-Tu3DMD4GkMjw08gxRW4RUepk,2855
|
|
161
|
+
oldaplib-0.3.10.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
162
|
+
oldaplib-0.3.10.dist-info/RECORD,,
|
|
File without changes
|