Skip to content
Snippets Groups Projects

Upload ontology file

Merged Fabien Amarger requested to merge topic/default/upload_ontology into branch/default
Files
7
+ 24
1
@@ -20,7 +20,7 @@
from datetime import datetime, timedelta
import logging
from cubicweb.server.hook import Hook
from cubicweb.server.hook import Hook, match_rtype
from cubicweb.predicates import is_instance
from cubicweb_s3storage.storages import S3Storage
@@ -24,5 +24,6 @@
from cubicweb.predicates import is_instance
from cubicweb_s3storage.storages import S3Storage
from rdflib import Graph
from cubicweb_rodolf.import_data import import_data, launch_import_procedure
@@ -27,5 +28,6 @@
from cubicweb_rodolf.import_data import import_data, launch_import_procedure
from cubicweb_rodolf.process_helpers import upload_graph_to_virtuoso_endpoint
RODOLF_IMPORT_DELTA = timedelta(
@@ -92,3 +94,24 @@
import_data, import_process_eid=self.entity.eid
)
self._cw.commit()
class UploadOntologyHook(Hook):
__regid__ = "rodolf.upload-ontology-hook"
__select__ = Hook.__select__ & match_rtype("ontology_file")
events = ("after_add_relation",)
def __call__(self):
ontology_graph = Graph()
file = self._cw.entity_from_eid(self.eidto)
procedure = self._cw.entity_from_eid(self.eidfrom)
ontology_graph.parse(
data=file.data.read(),
format=file.data_format,
)
upload_graph_to_virtuoso_endpoint(
procedure,
ontology_graph,
f"urn:rodolf:{procedure.eid}:ontology",
file.download_file_name(),
)
Loading