Skip to content

Commit

Permalink
Merge pull request #67 from scossu/development
Browse files Browse the repository at this point in the history
alpha15
  • Loading branch information
scossu committed Apr 27, 2018
2 parents 4dbefaf + c94eee7 commit 1d914c1
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 177 deletions.
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LAKEsuperior
============

|build status| |docs|
|build status| |docs| |pypi|

LAKEsuperior is an alternative `Fedora
Repository <http://fedorarepository.org>`__ implementation.
Expand Down Expand Up @@ -65,3 +65,7 @@ including installation instructions.
.. |docs| image:: https://readthedocs.org/projects/lakesuperior/badge/
:alt: Documentation Status
:target: https://lakesuperior.readthedocs.io/en/latest/?badge=latest

.. |pypi| image:: https://badge.fury.io/py/lakesuperior.svg
:alt: PyPI Package
:target: https://badge.fury.io/py/lakesuperior
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0a14
1.0.0a15
46 changes: 25 additions & 21 deletions lakesuperior/api/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get(uid, repr_options={}):
- incl_children: include children URIs. Default: True.
- embed_children: Embed full graph of all child resources. Default: False
"""
rsrc = LdpFactory.from_stored(uid, repr_options)
rsrc = LdpFactory.from_stored(uid, repr_opts=repr_options)
# Load graph before leaving the transaction.
rsrc.imr

Expand Down Expand Up @@ -292,7 +292,7 @@ def create_version(uid, ver_uid):


@transaction(True)
def delete(uid, soft=True):
def delete(uid, soft=True, inbound=True):
"""
Delete a resource.
Expand All @@ -306,27 +306,22 @@ def delete(uid, soft=True):
inbound = True if refint else inbound
repr_opts = {'incl_inbound' : True} if refint else {}

children = env.app_globals.rdfly.get_descendants(uid)

rsrc = LdpFactory.from_stored(uid, repr_opts, strict=soft)
if soft:
rsrc = LdpFactory.from_stored(uid, repr_opts)
ret = rsrc.bury_rsrc(inbound)

for child_uri in children:
try:
child_rsrc = LdpFactory.from_stored(
env.app_globals.rdfly.uri_to_uid(child_uri),
repr_opts={'incl_children' : False})
except (TombstoneError, ResourceNotExistsError):
continue
child_rsrc.bury_rsrc(inbound, tstone_pointer=rsrc.uri)
return rsrc.bury(inbound)
else:
ret = env.app_globals.rdfly.forget_rsrc(uid, inbound)
for child_uri in children:
child_uid = env.app_globals.rdfly.uri_to_uid(child_uri)
ret = env.app_globals.rdfly.forget_rsrc(child_uid, inbound)
return rsrc.forget(inbound)


@transaction(True)
def revert_to_version(uid, ver_uid):
"""
Restore a resource to a previous version state.
return ret
:param str uid: Resource UID.
:param str ver_uid: Version UID.
"""
return LdpFactory.from_stored(uid).revert_to_version(ver_uid)


@transaction(True)
Expand All @@ -336,4 +331,13 @@ def resurrect(uid):
:param str uid: Resource UID.
"""
return LdpFactory.from_stored(uid).resurrect_rsrc()
try:
rsrc = LdpFactory.from_stored(uid)
except TombstoneError as e:
if e.uid != uid:
raise
else:
return LdpFactory.from_stored(uid, strict=False).resurrect()
else:
raise InvalidResourceError(
uid, msg='Resource {} is not dead.'.format(uid))
6 changes: 0 additions & 6 deletions lakesuperior/dictionaries/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'dcterms' : rdflib.namespace.DCTERMS,
'ebucore' : Namespace(
'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#'),
#'fcrconfig' : Namespace('http://fedora.info/definitions/v4/config#'),
'fcrepo' : Namespace('http://fedora.info/definitions/v4/repository#'),
'fcadmin' : Namespace('info:fcsystem/graph/admin'),
'fcres' : Namespace('info:fcres'),
Expand All @@ -22,25 +21,20 @@
'foaf': Namespace('http://xmlns.com/foaf/0.1/'),
'iana' : Namespace('http://www.iana.org/assignments/relation/'),
'ldp' : Namespace('http://www.w3.org/ns/ldp#'),
# This is used in the layout attribute router.
'pcdm': Namespace('http://pcdm.org/models#'),
'premis' : Namespace('http://www.loc.gov/premis/rdf/v1#'),
'rdf' : rdflib.namespace.RDF,
'rdfs' : rdflib.namespace.RDFS,
'webac' : Namespace('http://www.w3.org/ns/auth/acl#'),
'xml' : Namespace('http://www.w3.org/XML/1998/namespace'),
'xsd' : rdflib.namespace.XSD,
'xsi' : Namespace('http://www.w3.org/2001/XMLSchema-instance'),
}

ns_collection = core_namespaces.copy()
custom_ns = {pfx: Namespace(ns) for pfx, ns in config['namespaces'].items()}
ns_collection.update(custom_ns)

ns_mgr = NamespaceManager(Graph())
ns_pfx_sparql = {}

# Collection of prefixes in a dict.
for ns,uri in ns_collection.items():
ns_mgr.bind(ns, uri, override=False)
#ns_pfx_sparql[ns] = 'PREFIX {}: <{}>'.format(ns, uri)
4 changes: 2 additions & 2 deletions lakesuperior/endpoints/ldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def post_resource(parent_uid):
uri = g.tbox.uid_to_uri(uid)
hdr = {'Location' : uri}

if mimetype and not is_rdf:
if mimetype and rdf_fmt is None:
hdr['Link'] = '<{0}/fcr:metadata>; rel="describedby"; anchor="{0}"'\
.format(uri)

Expand Down Expand Up @@ -446,7 +446,7 @@ def patch_version(uid, ver_uid):
:param str ver_uid: Version UID.
"""
try:
LdpFactory.from_stored(uid).revert_to_version(ver_uid)
rsrc_api.revert_to_version(uid, rsrc_uid)
except ResourceNotExistsError as e:
return str(e), 404
except InvalidResourceError as e:
Expand Down
14 changes: 5 additions & 9 deletions lakesuperior/model/ldp_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def new_container(uid):


@staticmethod
def from_stored(uid, repr_opts={}, **kwargs):
def from_stored(uid, ver_label=None, repr_opts={}, strict=True, **kwargs):
"""
Create an instance for retrieval purposes.
Expand All @@ -52,15 +52,11 @@ def from_stored(uid, repr_opts={}, **kwargs):
N.B. The resource must exist.
:param uid: UID of the instance.
:param str uid: UID of the instance.
"""
#logger.info('Retrieving stored resource: {}'.format(uid))
imr_urn = nsc['fcres'][uid]

rsrc_meta = rdfly.get_metadata(uid)
#logger.debug('Extracted metadata: {}'.format(
# pformat(set(rsrc_meta))))
rdf_types = set(rsrc_meta[imr_urn : RDF.type])
# This will blow up if strict is True and the resource is a tombstone.
rsrc_meta = rdfly.get_metadata(uid, strict=strict)
rdf_types = set(rsrc_meta[nsc['fcres'][uid] : RDF.type])

if LDP_NR_TYPE in rdf_types:
logger.info('Resource is a LDP-NR.')
Expand Down

0 comments on commit 1d914c1

Please sign in to comment.