[PATCH 7 of 7 saem_ref] [ark] Insert "external" ARK identifiers into ark table

Philippe Pepiot philippe.pepiot at logilab.fr
Wed Feb 21 16:23:14 CET 2018


On 21/02/2018, Denis Laxalde wrote:
> Denis Laxalde a écrit :
> > # HG changeset patch
> > # User Denis Laxalde <denis.laxalde at logilab.fr>
> > # Date 1519209844 -3600
> > #      Wed Feb 21 11:44:04 2018 +0100
> > # Node ID b8c00334e6183131d1e4a985b7d2816850a97e89
> > # Parent  4e2b908a791f0250f1bc26f460ecad8b5bb3574b
> > # Available At http://hg.logilab.org/review/cubes/saem_ref
> > #              hg pull http://hg.logilab.org/review/cubes/saem_ref -r b8c00334e618
> > # EXP-Topic ark/unique-overall
> > [ark] Insert "external" ARK identifiers into ark table
> > 
> > When calling set_ark_and_cwuri() (from a hook upon entity addition or
> > from a dataimport metadata generator), we now insert a record into "ark"
> > table when an "ark" value is specified in entity.cw_edited (meaning the
> > ARK identifier is externally given). Insertion is handled through a new
> > insert_ark() helper function in ark module. Afterwards, the value
> > returned by insert_ark() is used to update cw_edited dict to ensure
> > consistency with parsed value (in particular, users may specify the
> > "ark:/" scheme, which we do not store).
> > 
> > When an external ARK identifier is given, we only check it is correctly
> > formatted but don't check for our internal constraints (presence of a
> > prefix and control character, etc.).
> > 
> > By inserting external ARK identifiers in this "ark" table, we can now
> > ensure uniqueness of values across entity types, thus solving a major
> > integrity bug.
> > 
> > diff --git a/cubicweb_saem_ref/ark.py b/cubicweb_saem_ref/ark.py
> > --- a/cubicweb_saem_ref/ark.py
> > +++ b/cubicweb_saem_ref/ark.py
> > @@ -74,3 +74,17 @@ def generate_qualified_ark(cnx, naan, na
> >      )
> >      qualifier, = cu.fetchone()
> >      return qualifier
> > +
> > +
> > +def insert_ark(cnx, naan, name, qualifier=None):
> > +    """Insert a record in "ark" table from specified values."""
> > +    if qualifier is None:
> > +        qualifier = 'DEFAULT'
> > +    cnx.system_sql(
> > +        'INSERT INTO ark VALUES (%s, %s, %s);',
> > +        (naan, name, qualifier),
> > +    )
> 
> I'm not sure that passing 'DEFAULT' would yield the expected result but
> don't know how to do this either. If someone has an idea...
> 

Yes, this will insert 'DEFAULT' as qualifier which is not what you want.

Unless there is a psycopg2 trick for this I think you have to write two
different sql for qualifier is None and qualifier is not None.

> > +    ark = u'/'.join([naan, name])
> > +    if qualifier != 'DEFAULT':
> > +        ark += '/' + qualifier
> > +    return ark
> 



More information about the saem-devel mailing list