Skip to content

Commit

Permalink
Support #26
Browse files Browse the repository at this point in the history
-   Adds a predicate handler (URI handler) for slots that describe a single URI
-   Validates the URI per RFC-3986
-   Adds an upgrade step that
    -   Makes the new handler available
    -   Deletes the current "Person" generator's `Photo_file_name` handler
    -   Replaces it with a new `Photo_file_name` handler that uses the URI handler
  • Loading branch information
nutjob4life committed Feb 15, 2024
1 parent 2c3670e commit 748721c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/edrn.rdf/edrn/rdf/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ RESERVED. U.S. Government Sponsorship acknowledged.
provides='.interfaces.IAsserter'
for='.literalpredicatehandler.ILiteralPredicateHandler'
/>
<adapter
factory='.uripredicatehandler.URIAsserter'
provides='.interfaces.IAsserter'
for='.uripredicatehandler.IURIPredicateHandler'
/>
<adapter
factory='.multiliteralpredicatehandler.MultiLiteralAsserter'
provides='.interfaces.IAsserter'
Expand Down
2 changes: 1 addition & 1 deletion src/edrn.rdf/edrn/rdf/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright 2012–2023 California Institute of Technology. ALL RIGHTS
RESERVED. U.S. Government Sponsorship acknowledged.
-->
<metadata>
<version>11</version>
<version>12</version>
<description>EDRN RDF Service</description>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/edrn.rdf/edrn/rdf/profiles/default/types.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright 2008—2012 California Institute of Technology. ALL RIGHTS
Copyright 2008—2024 California Institute of Technology. ALL RIGHTS
RESERVED. U.S. Government Sponsorship acknowledged.
-->
<object name='portal_types' meta_type='Plone Types Tool'>
Expand All @@ -11,6 +11,7 @@ RESERVED. U.S. Government Sponsorship acknowledged.
<object name='edrn.rdf.dmcccommitteerdfgenerator' meta_type='Dexterity FTI' />
<object name='edrn.rdf.dmccprotocolrdfgenerator' meta_type='Dexterity FTI' />
<object name='edrn.rdf.literalpredicatehandler' meta_type='Dexterity FTI' />
<object name='edrn.rdf.uripredicatehandler' meta_type='Dexterity FTI' />
<object name='edrn.rdf.multiliteralpredicatehandler' meta_type='Dexterity FTI' />
<object name='edrn.rdf.multipipepredicatehandler' meta_type='Dexterity FTI' />
<object name='edrn.rdf.referencepredicatehandler' meta_type='Dexterity FTI' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sets of data available at the DMCC by accessing their crummy web service.</prope
<property name='filter_content_types'>True</property>
<property name='allowed_content_types'>
<element value='edrn.rdf.literalpredicatehandler' />
<element value='edrn.rdf.uripredicatehandler' />
<element value='edrn.rdf.multiliteralpredicatehandler' />
<element value='edrn.rdf.multipipepredicatehandler' />
<element value='edrn.rdf.referencepredicatehandler' />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version='1.0' encoding='utf-8'?>
<!--
Copyright 2024 California Institute of Technology. ALL RIGHTS
RESERVED. U.S. Government Sponsorship acknowledged.
-->
<object name='edrn.rdf.uripredicatehandler' meta_type='Dexterity FTI' i18n:domain='edrn.rdf'
xmlns:i18n='http://xml.zope.org/namespaces/i18n'>
<property name='title' i18n:translate=''>URI Predicate Handler</property>
<property name='description' i18n:translate=''>A handler for DMCC web services that maps a singel URI to a single RDF resource reference.</property>
<property name='allow_discussion'>False</property>
<property name='global_allow'>False</property>
<property name='filter_content_types'>True</property>
<property name='allowed_content_types' />
<property name='schema'>edrn.rdf.uripredicatehandler.IURIPredicateHandler</property>
<property name='klass'>plone.dexterity.content.Item</property>
<property name='add_permission'>cmf.AddPortalContent</property>
<property name='behaviors'>
<element value='plone.app.content.interfaces.INameFromTitle' />
</property>
<property name='default_view'>view</property>
<property name='default_view_fallback'>False</property>
<property name='view_methods'>
<element value='view' />
</property>
<alias from='(Default)' to='(dynamic view)' />
<alias from='edit' to='@@edit' />
<alias from='sharing' to='@@sharing' />
<alias from='view' to='(selected layout)' />
<action title='View' action_id='view' category='object' condition_expr='' url_expr='string:${object_url}' visible='True'>
<permission value='View' />
</action>
<action title='Edit' action_id='edit' category='object' condition_expr='' url_expr='string:${object_url}/edit' visible='True'>
<permission value='Modify portal content' />
</action>
</object>
21 changes: 21 additions & 0 deletions src/edrn.rdf/edrn/rdf/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
9 changes: 9 additions & 0 deletions src/edrn.rdf/edrn/rdf/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ RESERVED. U.S. Government Sponsorship acknowledged.
handler='edrn.rdf.upgrades.upgrade10to11'
sortkey='1'
/>
<genericsetup:upgradeStep
source='11'
destination='12'
title='Upgrade 11 to 12'
description='Add new URI predicate handler'
profile='edrn.rdf:default'
handler='edrn.rdf.upgrades.upgrade11to12'
sortkey='1'
/>


</configure>
32 changes: 32 additions & 0 deletions src/edrn.rdf/edrn/rdf/uripredicatehandler.py
Original file line number Diff line number Diff line change
@@ -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 []

0 comments on commit 748721c

Please sign in to comment.