diff --git a/src/edrn.rdf/edrn/rdf/configure.zcml b/src/edrn.rdf/edrn/rdf/configure.zcml index fb48911..e626be8 100644 --- a/src/edrn.rdf/edrn/rdf/configure.zcml +++ b/src/edrn.rdf/edrn/rdf/configure.zcml @@ -98,6 +98,11 @@ RESERVED. U.S. Government Sponsorship acknowledged. provides='.interfaces.IAsserter' for='.literalpredicatehandler.ILiteralPredicateHandler' /> + - 11 + 12 EDRN RDF Service profile-plone.app.dexterity:default diff --git a/src/edrn.rdf/edrn/rdf/profiles/default/types.xml b/src/edrn.rdf/edrn/rdf/profiles/default/types.xml index 74326e6..eb68336 100644 --- a/src/edrn.rdf/edrn/rdf/profiles/default/types.xml +++ b/src/edrn.rdf/edrn/rdf/profiles/default/types.xml @@ -1,6 +1,6 @@ @@ -11,6 +11,7 @@ RESERVED. U.S. Government Sponsorship acknowledged. + diff --git a/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.simpledmccrdfgenerator.xml b/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.simpledmccrdfgenerator.xml index 1de4315..7b615b1 100644 --- a/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.simpledmccrdfgenerator.xml +++ b/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.simpledmccrdfgenerator.xml @@ -14,6 +14,7 @@ sets of data available at the DMCC by accessing their crummy web service.True + diff --git a/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.uripredicatehandler.xml b/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.uripredicatehandler.xml new file mode 100644 index 0000000..0bb06b2 --- /dev/null +++ b/src/edrn.rdf/edrn/rdf/profiles/default/types/edrn.rdf.uripredicatehandler.xml @@ -0,0 +1,35 @@ + + + + URI Predicate Handler + A handler for DMCC web services that maps a singel URI to a single RDF resource reference. + False + False + True + + edrn.rdf.uripredicatehandler.IURIPredicateHandler + plone.dexterity.content.Item + cmf.AddPortalContent + + + + view + False + + + + + + + + + + + + + + diff --git a/src/edrn.rdf/edrn/rdf/upgrades.py b/src/edrn.rdf/edrn/rdf/upgrades.py index 8e506d7..fde3812 100644 --- a/src/edrn.rdf/edrn/rdf/upgrades.py +++ b/src/edrn.rdf/edrn/rdf/upgrades.py @@ -166,3 +166,24 @@ def upgrade10to11(setupTool, logger=None): if logger is None: logger = logging.getLogger(PACKAGE_NAME) setupTool.runImportStepFromProfile(DEFAULT_PROFILE, 'typeinfo') + + +def upgrade11to12(setupTool, logger=None): + if logger is None: + logger = logging.getLogger(PACKAGE_NAME) + setupTool.runImportStepFromProfile(DEFAULT_PROFILE, 'typeinfo') + portal = plone.api.portal.get() + generator = portal.unrestrictedTraverse('rdf-generators/person-generator') + try: + generator.manage_delObject('Photo_file_name') + except AttributeError: + # no photo file handler found, so no worries + pass + handler = createContentInContainer( + generator, + 'edrn.rdf.uripredicatehandler', + title='Photo_file_name', + description='A URL to a photograph of the person', + predicateURI='http://xmlns.com/foaf/0.1/img' + ) + publish(handler, plone.api.portal.get_tool('portal_workflow')) diff --git a/src/edrn.rdf/edrn/rdf/upgrades.zcml b/src/edrn.rdf/edrn/rdf/upgrades.zcml index 16e179c..af794c2 100644 --- a/src/edrn.rdf/edrn/rdf/upgrades.zcml +++ b/src/edrn.rdf/edrn/rdf/upgrades.zcml @@ -85,6 +85,15 @@ RESERVED. U.S. Government Sponsorship acknowledged. handler='edrn.rdf.upgrades.upgrade10to11' sortkey='1' /> + \ No newline at end of file diff --git a/src/edrn.rdf/edrn/rdf/uripredicatehandler.py b/src/edrn.rdf/edrn/rdf/uripredicatehandler.py new file mode 100644 index 0000000..e89eb2c --- /dev/null +++ b/src/edrn.rdf/edrn/rdf/uripredicatehandler.py @@ -0,0 +1,32 @@ +# encoding: utf-8 +# Copyright 2024 California Institute of Technology. ALL RIGHTS +# RESERVED. U.S. Government Sponsorship acknowledged. + +from .predicatehandler import ISimplePredicateHandler +from Acquisition import aq_inner +from rfc3986_validator import validate_rfc3986 +import rdflib, logging + +_logger = logging.getLogger(__name__) + + +class IURIPredicateHandler(ISimplePredicateHandler): + '''A handler for DMCC web services that contains single URI references.''' + pass + + +class URIAsserter(object): + '''Describes subjects using a predicate with a single complementary references to some other URI.''' + def __init__(self, context): + self.context = context + + def characterize(self, obj): + context = aq_inner(self.context) + + if validate_rfc3986(obj): + return [(rdflib.URIRef(context.predicateURI), rdflib.URIRef(obj))] + else: + _logger.warning( + "Got an invalid URI «%s» for %s which won't be put into RDF", obj, self.context.title + ) + return []