oldaplib 0.3.26__py3-none-any.whl → 0.3.28__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.
@@ -4,6 +4,7 @@
4
4
  @prefix sh: <http://www.w3.org/ns/shacl#> .
5
5
  @prefix owl: <http://www.w3.org/2002/07/owl#> .
6
6
  @prefix dcterms: <http://purl.org/dc/terms/> .
7
+ @prefix dcmitype: <http://purl.org/dc/dcmitype/> .
7
8
  @prefix schema: <http://schema.org/> .
8
9
  @prefix oldap: <http://oldap.org/base#> .
9
10
 
@@ -109,6 +110,90 @@ shared:shacl {
109
110
  # Media object
110
111
  ###############################################################################
111
112
 
113
+ # dcmitype:CollectionShape a sh:NodeShape ;
114
+ # sh:targetClass shared:Collection ;
115
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
116
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
117
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
118
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
119
+ # oldap:externalOntology "true"^^xsd:boolean ;
120
+ # rdfs:label "Collection"@en, "Sammlung"@de, "Collection"@fr, "Collezione"@it ;
121
+ # sh:property [
122
+ # sh:path rdf:type ;
123
+ # ] .
124
+ #
125
+ # dcmitype:DatasetShape a sh:NodeShape ;
126
+ # sh:targetClass shared:Dataset ;
127
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
128
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
129
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
130
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
131
+ # oldap:externalOntology "true"^^xsd:boolean ;
132
+ # rdfs:label "Dataset"@en, "Dataset"@de, "Dataset"@fr, "Dataset"@it ;
133
+ # sh:property [
134
+ # sh:path rdf:type ;
135
+ # ] .
136
+ #
137
+ # dcmitype:StillImageShape a sh:NodeShape ;
138
+ # sh:targetClass shared:StillImage ;
139
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
140
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
141
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
142
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
143
+ # oldap:externalOntology "true"^^xsd:boolean ;
144
+ # rdfs:label "StillImage"@en, "Standbild"@de, "Image fixe"@fr, "Immagine fissa"@it ;
145
+ # sh:property [
146
+ # sh:path rdf:type ;
147
+ # ] .
148
+ #
149
+ # dcmitype:ImageShape a sh:NodeShape ;
150
+ # sh:targetClass shared:Image ;
151
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
152
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
153
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
154
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
155
+ # oldap:externalOntology "true"^^xsd:boolean ;
156
+ # rdfs:label "Image"@en, "Bild"@de, "Image"@fr, "Immagine"@it ;
157
+ # sh:property [
158
+ # sh:path rdf:type ;
159
+ # ] .
160
+ #
161
+ # dcmitype:MovingImageShape a sh:NodeShape ;
162
+ # sh:targetClass shared:MovingImage ;
163
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
164
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
165
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
166
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
167
+ # oldap:externalOntology "true"^^xsd:boolean ;
168
+ # rdfs:label "MovingImage"@en, "Bewegtbild"@de, "Image animée"@fr, "Immagine in movimento"@it ;
169
+ # sh:property [
170
+ # sh:path rdf:type ;
171
+ # ] .
172
+ #
173
+ # dcmitype:SoundShape a sh:NodeShape ;
174
+ # sh:targetClass shared:Sound ;
175
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
176
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
177
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
178
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
179
+ # oldap:externalOntology "true"^^xsd:boolean ;
180
+ # rdfs:label "Sound"@en, "Ton"@de, "Son"@fr, "Sound"@it ;
181
+ # sh:property [
182
+ # sh:path rdf:type ;
183
+ # ] .
184
+ #
185
+ # dcmitype:TextShape a sh:NodeShape ;
186
+ # sh:targetClass shared:Text ;
187
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
188
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
189
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
190
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
191
+ # oldap:externalOntology "true"^^xsd:boolean ;
192
+ # rdfs:label "Text"@en, "Text"@de, "Texte"@fr, "Testo"@it ;
193
+ # sh:property [
194
+ # sh:path rdf:type ;
195
+ # ] .
196
+
112
197
  shared:MediaObjectShape a sh:NodeShape ;
113
198
  sh:targetClass shared:MediaObject ;
114
199
  dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
@@ -117,12 +202,33 @@ shared:shacl {
117
202
  dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
118
203
  oldap:externalOntology "false"^^xsd:boolean ;
119
204
  rdfs:label "MediaObject"@en, "Medienobjekt"@de, "MediaObject"@fr, "MediaObject"@it ;
120
- rdfs:comment "Page of a book"@en, "Seite eines Buches"@de ;
121
205
  sh:closed "true"^^xsd:boolean ;
122
206
  sh:node oldap:ThingShape ;
123
207
  sh:property [
124
208
  sh:path rdf:type ;
125
209
  ] ;
210
+ sh:property [
211
+ sh:path dcterms:type ;
212
+ dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
213
+ dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
214
+ dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
215
+ dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
216
+ oldap:statementProperty "false"^^xsd:boolean ;
217
+ oldap:externalOntology "false"^^xsd:boolean ;
218
+ sh:nodeKind sh:IRI ;
219
+ sh:in (
220
+ dcmitype:Collection
221
+ dcmitype:Dataset
222
+ dcmitype:StillImage
223
+ dcmitype:Image
224
+ dcmitype:MovingImage
225
+ dcmitype:Sound
226
+ dcmitype:Text
227
+ ) ;
228
+ sh:minCount 1 ;
229
+ sh:maxCount 1 ;
230
+ sh:order "0.5"^^xsd:decimal ;
231
+ ] ;
126
232
  sh:property [
127
233
  sh:path shared:originalName ;
128
234
  schema:version "0.1.0"^^xsd:string ;
@@ -193,6 +299,9 @@ shared:shacl {
193
299
  oldap:externalOntology "false"^^xsd:boolean ;
194
300
  sh:datatype xsd:string ;
195
301
  sh:in ( 'iiif' 'http' 'custom') ;
302
+ sh:minCount "1"^^xsd:integer ;
303
+ sh:maxCount "1"^^xsd:integer ;
304
+ sh:order "4.0"^^xsd:decimal ;
196
305
  ] ;
197
306
  sh:property [
198
307
  sh:path shared:path ;
@@ -203,7 +312,10 @@ shared:shacl {
203
312
  oldap:statementProperty "false"^^xsd:boolean ;
204
313
  oldap:externalOntology "false"^^xsd:boolean ;
205
314
  sh:datatype xsd:string ;
206
- ] .
315
+ sh:minCount "1"^^xsd:integer ;
316
+ sh:maxCount "1"^^xsd:integer ;
317
+ sh:order "4.0"^^xsd:decimal ;
318
+ ] .
207
319
  }
208
320
 
209
321
  shared:onto {
@@ -338,6 +450,15 @@ shared:onto {
338
450
  # Media object
339
451
  ###########################################################################
340
452
 
453
+ # shared:mediaType rdf:type owl:ObjectProperty ;
454
+ # dcterms:creator <https://orcid.org/0000-0003-1681-4036> ;
455
+ # dcterms:created "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime ;
456
+ # dcterms:contributor <https://orcid.org/0000-0003-1681-4036> ;
457
+ # dcterms:modified "2025-11-21T00:15:09.037880+01:00"^^xsd:dateTime .
458
+ # #owl:subPropertyOf dcterms:type ;
459
+ # rdfs:domain shared:MediaObject ;
460
+ # rdfs:range rdfs:Class ;
461
+
341
462
  shared:originalName rdf:type owl:DatatypeProperty ;
342
463
  rdfs:domain shared:MediaObject ;
343
464
  rdfs:range xsd:string ;
@@ -395,6 +516,12 @@ shared:onto {
395
516
  rdfs:label "MediaObject"@en, "Medienobjekt"@de, "MediaObject"@fr, "MediaObject"@it ;
396
517
  rdfs:comment "Page of a book"@en, "Seite eines Buches"@de ;
397
518
  rdfs:subClassOf oldap:Thing ,
519
+ [
520
+ rdf:type owl:Restriction ;
521
+ owl:onProperty dcterms:type ;
522
+ owl:qualifiedCardinality "1"^^xsd:nonNegativeInteger ;
523
+ owl:onClass rdfs:Class ;
524
+ ] ,
398
525
  [
399
526
  rdf:type owl:Restriction ;
400
527
  owl:onProperty shared:originalName ;
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  import os
3
- from time import sleep
3
+ import time
4
4
 
5
5
  import bcrypt
6
6
  import jwt
@@ -338,80 +338,52 @@ class Connection(IConnection):
338
338
  if not req.ok:
339
339
  raise OldapError(req.text)
340
340
 
341
+
342
+
341
343
  def upload_turtle(self, filename: str, graphname: Optional[str] = None) -> None:
342
344
  """
343
- Uploads a turtle or trig file to the specified repository. This function sends the file to the triplestore for
344
- import and does not wait for the completion of the import process. The process itself may continue for some time
345
- after the command is issued.
346
-
347
- :param filename: Name of the file to be uploaded.
348
- :type filename: str
349
- :param graphname: Optional; the name of the RDF-graph into which the data is to be imported.
350
- :type graphname: str or None
351
- :return: None
352
- :rtype: None
353
- :raises OldapError: Raised when there are issues with the repository or during the HTTP request.
354
- """
355
- # if not self._userdata:
356
- # raise OldapErrorNoPermission("No permission")
357
- # actor = self._userdata
358
- # sysperms = actor.inProject.get(QName('oldap:SystemProject'))
359
- # is_root: bool = False
360
- # if sysperms and AdminPermission.ADMIN_OLDAP in sysperms:
361
- # is_root = True
362
- # if not is_root:
363
- # raise OldapErrorNoPermission("No permission")
345
+ Upload a TTL/TRiG file to GraphDB using the RDF4J /statements endpoint.
364
346
 
347
+ This call is synchronous: when it returns without error, the data is loaded.
348
+ """
365
349
  logger = get_logger()
366
- with open(filename, encoding="utf-8") as f:
367
- content = f.read()
368
- ext = Path(filename).suffix
369
- mime = ""
370
- if ext == ".ttl":
371
- mime = "text/turtle"
372
- elif ext == ".trig":
373
- mime = "application/x-trig"
374
-
375
- ct = datetime.now().astimezone()
376
- ts = ct.timestamp()
377
- data = {
378
- "name": f'Data from "{filename}"',
379
- "status": None,
380
- "message": "",
381
- "context": graphname,
382
- "replaceGraphs": [],
383
- "baseURI": None,
384
- "forceSerial": False,
385
- "type": "text",
386
- "format": mime,
387
- "data": content,
388
- "timestamp": ts,
389
- "parserSettings": {
390
- "preserveBNodeIds": False,
391
- "failOnUnknownDataTypes": False,
392
- "verifyDataTypeValues": False,
393
- "normalizeDataTypeValues": False,
394
- "failOnUnknownLanguageTags": False,
395
- "verifyLanguageTags": True,
396
- "normalizeLanguageTags": True,
397
- "stopOnError": True
398
- }
399
- }
400
- jsondata = json.dumps(data)
401
- headers = {
402
- "Accept": "application/json, text/plain, */*",
403
- "Content-Type": "application/json; charset=utf-8"
404
- }
405
- url = f"{self._server}/rest/repositories/{self._repo}/import/upload/text"
406
- auth = HTTPBasicAuth(self._dbuser, self._dbpassword) if self._dbuser and self._dbpassword else None
407
- req = requests.post(url,
408
- headers=headers,
409
- data=jsondata,
410
- auth=auth)
411
- if not req.ok:
412
- logger.error(f'Upload of file "{filename}" failed: {req.text}')
413
- raise OldapError(req.text)
414
- logger.info(f'File "{filename}" uploaded.')
350
+
351
+ ext = Path(filename).suffix.lower()
352
+ if ext == ".ttl":
353
+ mime = "text/turtle"
354
+ elif ext == ".trig":
355
+ # use the standard MIME type for TriG
356
+ mime = "application/trig"
357
+ else:
358
+ raise OldapError(f"Unsupported RDF extension: {ext}")
359
+
360
+ with open(filename, "rb") as f:
361
+ data = f.read()
362
+
363
+ # RDF4J / GraphDB statements endpoint
364
+ url = f"{self._server.rstrip('/')}/repositories/{self._repo}/statements"
365
+
366
+ # Optional context: only use this if you really want to force
367
+ # all triples into a single named graph. For TriG you usually
368
+ # leave this empty so the quads' graph IRIs are respected.
369
+ params = {}
370
+ if graphname:
371
+ # GraphDB expects the context IRI wrapped in < > and URL-encoded
372
+ params["context"] = f"<{graphname}>"
373
+
374
+ auth = HTTPBasicAuth(self._dbuser, self._dbpassword) if self._dbuser and self._dbpassword else None
375
+ headers = {
376
+ "Content-Type": mime,
377
+ "Accept": "text/plain" # or */*, result body is usually empty
378
+ }
379
+
380
+ resp = requests.post(url, params=params, headers=headers, data=data, auth=auth)
381
+
382
+ if not resp.ok:
383
+ logger.error(f'Upload of file "{filename}" failed: {resp.status_code} {resp.text}')
384
+ raise OldapError(resp.text)
385
+
386
+ logger.info(f'File "{filename}" uploaded synchronously via /statements.')
415
387
 
416
388
  def query(self, query: str, format: SparqlResultFormat = SparqlResultFormat.JSON) -> Any:
417
389
  """
oldaplib/src/datamodel.py CHANGED
@@ -1,7 +1,8 @@
1
+ import io
1
2
  from copy import deepcopy
2
3
  from dataclasses import dataclass
3
4
  from datetime import datetime
4
- from typing import Dict, List, Optional, Union, Any, Self
5
+ from typing import Dict, List, Optional, Union, Any, Self, TextIO
5
6
 
6
7
  from oldaplib.src.cachesingleton import CacheSingleton, CacheSingletonRedis
7
8
  from oldaplib.src.dtypes.namespaceiri import NamespaceIRI
@@ -723,57 +724,58 @@ class DataModel(Model):
723
724
  cache = CacheSingletonRedis()
724
725
  cache.delete(Xsd_QName(self._project.projectShortName, 'shacl'))
725
726
 
726
-
727
- def write_as_trig(self, filename: str, indent: int = 0, indent_inc: int = 4) -> None:
727
+ def __to_trig_format(self, f: TextIO, indent: int = 0, indent_inc: int = 4) -> None:
728
728
  """
729
- Write the complete datamodel in the trig format to a file.
730
-
731
- This method serializes the complete datamodel, including its SHACL
732
- shapes and OWL ontology, and writes the resulting data in the trig
733
- format to the specified file.
734
-
735
- :param filename: The path of the file where the trig data will be
736
- written
737
- :type filename: str
738
- :param indent: Start level of indentation for serialized data. Defaults
739
- to 0
740
- :type indent: int
741
- :param indent_inc: Number of characters to increment for each indent
742
- level. Defaults to 4
743
- :type indent_inc: int
729
+ Generates and writes TriG-formatted RDF data to the given TextIO object. The method constructs
730
+ SHACL and OWL ontology representations based on the internal state and configuration of the
731
+ object. SHACL validation shapes, ontology metadata, and RDF structure are included. This
732
+ method is primarily used for exporting RDF data in a standard, compliant format.
733
+
734
+ :param f: The output stream (e.g., a file or any TextIO object) where the generated TriG
735
+ data will be written.
736
+ :param indent: The base indentation level applied when formatting the output.
737
+ :param indent_inc: The number of spaces added for each level of indentation to format
738
+ nested structures cleanly.
744
739
  :return: None
745
740
  """
741
+ timestamp = Xsd_dateTime.now()
742
+ blank = ''
743
+ context = Context(name=self._con.context_name)
744
+ f.write('\n')
745
+ f.write(context.turtle_context)
746
+ f.write(f'\n{blank:{indent * indent_inc}}{self.__graph}:shacl {{\n')
747
+ f.write(f'{blank:{(indent + 1) * indent_inc}}{self.__graph}:shapes schema:version {self.__version.toRdf} .\n')
748
+ f.write('\n')
749
+ for qname, onto in self.__extontos.items():
750
+ f.write(onto.create_shacl(timestamp=timestamp, indent=1))
751
+ f.write('\n\n')
752
+ for iri, prop in self.__propclasses.items():
753
+ if not prop.internal:
754
+ f.write(prop.create_shacl(timestamp=timestamp, indent=1))
755
+ f.write('\n\n')
756
+ for iri, resclass in self.__resclasses.items():
757
+ f.write(resclass.create_shacl(timestamp=timestamp, indent=1))
758
+ f.write('\n\n')
759
+ f.write(f'\n{blank:{indent * indent_inc}}}}\n')
760
+
761
+ f.write(f'{blank:{indent * indent_inc}}{self.__graph}:onto {{\n')
762
+ f.write(f'{blank:{(indent + 2) * indent_inc}}{self.__graph}:ontology owl:type owl:Ontology ;\n')
763
+ f.write(f'{blank:{(indent + 2) * indent_inc}}owl:versionInfo {self.__version.toRdf} .\n')
764
+ f.write('\n')
765
+ for iri, prop in self.__propclasses.items():
766
+ f.write(prop.create_owl_part1(timestamp=timestamp, indent=2))
767
+ for iri, resclass in self.__resclasses.items():
768
+ f.write(resclass.create_owl(timestamp=timestamp))
769
+ f.write(f'{blank:{indent * indent_inc}}}}\n')
770
+
771
+ def write_as_trig(self, filename: str, indent: int = 0, indent_inc: int = 4) -> None:
746
772
  with open(filename, 'w') as f:
747
- timestamp = Xsd_dateTime.now()
748
- blank = ''
749
- context = Context(name=self._con.context_name)
750
- f.write('\n')
751
- f.write(context.turtle_context)
752
- f.write(f'\n{blank:{indent * indent_inc}}{self.__graph}:shacl {{\n')
753
- f.write(f'{blank:{(indent + 1) * indent_inc}}{self.__graph}:shapes schema:version {self.__version.toRdf} .\n')
754
- f.write('\n')
755
- for qname, onto in self.__extontos.items():
756
- f.write(onto.create_shacl(timestamp=timestamp, indent=1))
757
- f.write('\n\n')
758
- for iri, prop in self.__propclasses.items():
759
- if not prop.internal:
760
- f.write(prop.create_shacl(timestamp=timestamp, indent=1))
761
- f.write('\n\n')
762
- for iri, resclass in self.__resclasses.items():
763
- f.write(resclass.create_shacl(timestamp=timestamp, indent=1))
764
- f.write('\n\n')
765
- f.write(f'\n{blank:{indent * indent_inc}}}}\n')
766
-
767
- f.write(f'{blank:{indent * indent_inc}}{self.__graph}:onto {{\n')
768
- f.write(f'{blank:{(indent + 2) * indent_inc}}{self.__graph}:ontology owl:type owl:Ontology ;\n')
769
- f.write(f'{blank:{(indent + 2) * indent_inc}}owl:versionInfo {self.__version.toRdf} .\n')
770
- f.write('\n')
771
- for iri, prop in self.__propclasses.items():
772
- f.write(prop.create_owl_part1(timestamp=timestamp, indent=2))
773
- for iri, resclass in self.__resclasses.items():
774
- f.write(resclass.create_owl(timestamp=timestamp))
775
- f.write(f'{blank:{indent * indent_inc}}}}\n')
773
+ self.__to_trig_format(f, indent=indent, indent_inc=indent_inc)
776
774
 
775
+ def write_as_str(self, indent: int = 0, indent_inc: int = 4) -> str:
776
+ f = io.StringIO()
777
+ self.__to_trig_format(f, indent=indent, indent_inc=indent_inc)
778
+ return f.getvalue()
777
779
 
778
780
 
779
781
 
@@ -48,6 +48,7 @@ class ContextSingleton(type):
48
48
  Xsd_NCName('schema'): NamespaceIRI('http://schema.org/'),
49
49
  #Xsd_NCName('dc'): NamespaceIRI('http://purl.org/dc/elements/1.1/'),
50
50
  Xsd_NCName('dcterms'): NamespaceIRI('http://purl.org/dc/terms/'),
51
+ Xsd_NCName('dcmitype'): NamespaceIRI('http://purl.org/dc/dcmitype/'),
51
52
  #Xsd_NCName('foaf'): NamespaceIRI('http://xmlns.com/foaf/0.1/'),
52
53
  Xsd_NCName('oldap'): NamespaceIRI('http://oldap.org/base#'),
53
54
  Xsd_NCName('shared'): NamespaceIRI('http://oldap.org/shared#')
@@ -63,6 +64,7 @@ class ContextSingleton(type):
63
64
  NamespaceIRI('http://schema.org/'): Xsd_NCName('schema'),
64
65
  #NamespaceIRI('http://purl.org/dc/elements/1.1/'): Xsd_NCName('dc'),
65
66
  NamespaceIRI('http://purl.org/dc/terms/'): Xsd_NCName('dcterms'),
67
+ NamespaceIRI('http://purl.org/dc/dcmitype/'): Xsd_NCName('dcmitype'),
66
68
  #NamespaceIRI('http://xmlns.com/foaf/0.1/'): Xsd_NCName('foaf'),
67
69
  NamespaceIRI('http://oldap.org/base#'): Xsd_NCName('oldap'),
68
70
  NamespaceIRI('http://oldap.org/shared#'): Xsd_NCName('shared'),
@@ -237,7 +239,7 @@ class Context(metaclass=ContextSingleton):
237
239
  return Xsd_QName(prefix, fragment, validate=validate)
238
240
  return None
239
241
 
240
- def qname2iri(self, qname: Xsd_QName | str, validate: bool = True) -> NamespaceIRI:
242
+ def qname2iri(self, qname: Xsd_QName | str, validate: bool = True) -> Xsd_anyURI:
241
243
  """
242
244
  Convert a QName into a IRI string.
243
245
 
@@ -231,8 +231,25 @@ class ResourceInstance:
231
231
  return # TODO: LangString does not yet allow multiple entries of the same language...
232
232
  if property.get(PropClassAttr.IN):
233
233
  #for val in values:
234
- if not values in property[PropClassAttr.IN]:
235
- raise OldapErrorValue(f'Property {property} with IN={property[PropClassAttr.IN]} has invalid value "{val}"')
234
+ if property.datatype is None: # no defined datatype, e.h.sh:IRI
235
+ tmpinset = {str(x) for x in property[PropClassAttr.IN]}
236
+ if isinstance(values, (list, tuple, set, ObservableSet)):
237
+ for val in values:
238
+ if not str(val) in tmpinset:
239
+ raise OldapErrorValue(
240
+ f'Property {property} with IN={property[PropClassAttr.IN]} has invalid value "{val}"')
241
+ else:
242
+ if not str(values) in tmpinset:
243
+ raise OldapErrorValue(f'Property {property.property_class_iri} with IN={property[PropClassAttr.IN]} has invalid value "{values}"')
244
+ else:
245
+ if isinstance(values, (list, tuple, set, ObservableSet)):
246
+ for val in values:
247
+ if not val in property[PropClassAttr.IN]:
248
+ raise OldapErrorValue(
249
+ f'Property {property} with IN={property[PropClassAttr.IN]} has invalid value "{val}"')
250
+ else:
251
+ if not values in property[PropClassAttr.IN]:
252
+ raise OldapErrorValue(f'Property {property.property_class_iri} with IN={property[PropClassAttr.IN]} has invalid value "{values}"')
236
253
  if property.get(PropClassAttr.MIN_LENGTH):
237
254
  for val in values:
238
255
  l = 0
@@ -1156,9 +1173,9 @@ class ResourceInstance:
1156
1173
  WHERE {{
1157
1174
  VALUES ?inputImageId {{ {mediaObjectId.toRdf} }}
1158
1175
 
1176
+ ?subject rdf:type shared:MediaObject .
1159
1177
  GRAPH ?graph {{
1160
1178
  ?subject shared:imageId ?inputImageId .
1161
- ?subject rdf:type shared:MediaObject .
1162
1179
  ?subject shared:originalName ?originalName .
1163
1180
  ?subject shared:originalMimeType ?originalMimeType .
1164
1181
  ?subject shared:serverUrl ?serverUrl .
@@ -1182,13 +1199,13 @@ class ResourceInstance:
1182
1199
  if len(res) == 0 or len(res) > 1:
1183
1200
  raise OldapErrorNotFound(f'Media object with id {mediaObjectId} not found.')
1184
1201
  return {'iri': res[0]['subject'],
1185
- 'originalName': res[0]['originalName'],
1186
- 'originalMimeType': res[0]['originalMimeType'],
1187
- 'serverUrl': res[0]['serverUrl'],
1188
- 'protocol': res[0]['protocol'],
1202
+ 'shared:originalName': res[0]['originalName'],
1203
+ 'shared:originalMimeType': res[0]['originalMimeType'],
1204
+ 'shared:serverUrl': res[0]['serverUrl'],
1205
+ 'shared:protocol': res[0]['protocol'],
1189
1206
  'graph': res[0]['graph'],
1190
- 'path': res[0]['path'],
1191
- 'permval': res[0]['permval']}
1207
+ 'shared:path': res[0]['path'],
1208
+ 'oldap:permissionValue': res[0]['permval']}
1192
1209
 
1193
1210
 
1194
1211
  def toJsonObject(self) -> dict[str, list[str] | str]:
oldaplib/src/oldaplist.py CHANGED
@@ -725,6 +725,7 @@ class OldapList(Model):
725
725
  self.clear_changeset()
726
726
 
727
727
  cache = CacheSingletonRedis()
728
+ cache.delete(Xsd_QName(self.project.projectShortName, 'shacl'))
728
729
  cache.set(self.__iri, self)
729
730
 
730
731
  def update(self, indent: int = 0, indent_inc: int = 4) -> None:
@@ -798,6 +799,7 @@ class OldapList(Model):
798
799
  #
799
800
  cache = CacheSingletonRedis()
800
801
  cache.delete(self.__iri)
802
+ cache.delete(Xsd_QName(self.project.projectShortName, 'shacl'))
801
803
 
802
804
 
803
805
  def in_use_queries(self) -> (str, str):
@@ -190,6 +190,21 @@ class PermissionSet(Model):
190
190
  def qname(self) -> Xsd_QName:
191
191
  return self.__permset_iri
192
192
 
193
+ def trig_to_str(self, created: Xsd_dateTime, modified: Xsd_dateTime, indent: int = 0, indent_inc: int = 4):
194
+ blank = ''
195
+ sparql = ''
196
+ sparql += f'{blank:{indent * indent_inc}} {self.__permset_iri.toRdf} a oldap:PermissionSet'
197
+ sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
198
+ sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:created {created.toRdf}'
199
+ sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
200
+ sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}dcterms:modified {modified.toRdf}'
201
+ for attr, value in self._attributes.items():
202
+ if attr.value.prefix == 'virtual' or not value:
203
+ continue
204
+ sparql += f' ;\n{blank:{(indent + 1) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
205
+ return sparql
206
+
207
+
193
208
  def create(self, indent: int = 0, indent_inc: int = 4) -> None:
194
209
  """
195
210
  Creates and stores a permission set in the triple store.
@@ -236,15 +251,16 @@ class PermissionSet(Model):
236
251
  sparql += f'{blank:{indent * indent_inc}}INSERT DATA {{\n'
237
252
  sparql += f'{blank:{(indent + 1) * indent_inc}}GRAPH oldap:admin {{\n'
238
253
 
239
- sparql += f'{blank:{(indent + 2) * indent_inc}} {self.__permset_iri.toRdf} a oldap:PermissionSet'
240
- sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
241
- sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:created {timestamp.toRdf}'
242
- sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
243
- sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:modified {timestamp.toRdf}'
244
- for attr, value in self._attributes.items():
245
- if attr.value.prefix == 'virtual' or not value:
246
- continue
247
- sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
254
+ sparql += self.trig_to_str(created=timestamp, modified=timestamp, indent=indent + 2, indent_inc=indent_inc)
255
+ # sparql += f'{blank:{(indent + 2) * indent_inc}} {self.__permset_iri.toRdf} a oldap:PermissionSet'
256
+ # sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:creator {self._con.userIri.toRdf}'
257
+ # sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:created {timestamp.toRdf}'
258
+ # sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:contributor {self._con.userIri.toRdf}'
259
+ # sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}dcterms:modified {timestamp.toRdf}'
260
+ # for attr, value in self._attributes.items():
261
+ # if attr.value.prefix == 'virtual' or not value:
262
+ # continue
263
+ # sparql += f' ;\n{blank:{(indent + 3) * indent_inc}}{attr.value.toRdf} {value.toRdf}'
248
264
  sparql += f'\n{blank:{(indent + 1) * indent_inc}}}}\n'
249
265
  sparql += f'{blank:{indent * indent_inc}}}}\n'
250
266
 
@@ -307,6 +323,7 @@ class PermissionSet(Model):
307
323
  :raises OldapErrorInconsistency: Raised if the permission set contains inconsistencies
308
324
  in its data during retrieval.
309
325
  """
326
+ context = Context(name=con.context_name)
310
327
  if qname:
311
328
  permset_iri = Xsd_QName(qname, validate=True)
312
329
  elif permissionSetId and definedByProject:
@@ -325,7 +342,6 @@ class PermissionSet(Model):
325
342
  if tmp is not None:
326
343
  tmp.update_notifier()
327
344
  return tmp
328
- context = Context(name=con.context_name)
329
345
  sparql = context.sparql_context
330
346
  sparql += f"""
331
347
  SELECT ?permset ?p ?o