Browse Source

Bury resource.

Stefano Cossu 7 years ago
parent
commit
00d8d9e5db

+ 7 - 8
lakesuperior/model/ldpr.py

@@ -137,7 +137,7 @@ class Ldpr(metaclass=ABCMeta):
         @param repr_opts (dict) Options used to retrieve the IMR. See
         @param repr_opts (dict) Options used to retrieve the IMR. See
         `parse_rfc7240` for format details.
         `parse_rfc7240` for format details.
         @Param provd_rdf (string) RDF data provided by the client in
         @Param provd_rdf (string) RDF data provided by the client in
-        operations isuch as `PUT` or `POST`, serialized as a string. This sets
+        operations such as `PUT` or `POST`, serialized as a string. This sets
         the `provided_imr` property.
         the `provided_imr` property.
         '''
         '''
         self.uid = g.tbox.uri_to_uuid(uid) \
         self.uid = g.tbox.uri_to_uuid(uid) \
@@ -456,7 +456,7 @@ class Ldpr(metaclass=ABCMeta):
         @param delete_children (boolean) Whether to delete all child resources.
         @param delete_children (boolean) Whether to delete all child resources.
         This is the default.
         This is the default.
         '''
         '''
-        refint = current_app.config['store']['ldp_rs']['referential_integrity']
+        refint = self.rdfly.config['referential_integrity']
         inbound = True if refint else inbound
         inbound = True if refint else inbound
 
 
         children = self.imr[nsc['ldp'].contains * '+'] \
         children = self.imr[nsc['ldp'].contains * '+'] \
@@ -643,7 +643,7 @@ class Ldpr(metaclass=ABCMeta):
         to the tombstone of the resource that used to contain the deleted
         to the tombstone of the resource that used to contain the deleted
         resource. Otherwise the deleted resource becomes a tombstone.
         resource. Otherwise the deleted resource becomes a tombstone.
         '''
         '''
-        self._logger.info('Removing resource {}'.format(self.uid))
+        self._logger.info('Burying resource {}'.format(self.uid))
         # Create a backup snapshot for resurrection purposes.
         # Create a backup snapshot for resurrection purposes.
         self.create_rsrc_snapshot(uuid4())
         self.create_rsrc_snapshot(uuid4())
 
 
@@ -663,7 +663,10 @@ class Ldpr(metaclass=ABCMeta):
         if inbound:
         if inbound:
             for ib_rsrc_uri in self.imr.graph.subjects(None, self.urn):
             for ib_rsrc_uri in self.imr.graph.subjects(None, self.urn):
                 remove_trp = {(ib_rsrc_uri, None, self.urn)}
                 remove_trp = {(ib_rsrc_uri, None, self.urn)}
-                Ldpr(ib_rsrc_uri)._modify_rsrc(self.RES_UPDATED, remove_trp)
+                ib_rsrc = Ldpr(ib_rsrc_uri)
+                # To preserve inbound links in history, create a snapshot
+                ib_rsrc.create_rsrc_snapshot(uuid4())
+                ib_rsrc._modify_rsrc(self.RES_UPDATED, remove_trp)
 
 
         return self.RES_DELETED
         return self.RES_DELETED
 
 
@@ -673,10 +676,6 @@ class Ldpr(metaclass=ABCMeta):
         Remove all traces of a resource and versions.
         Remove all traces of a resource and versions.
         '''
         '''
         self._logger.info('Purging resource {}'.format(self.uid))
         self._logger.info('Purging resource {}'.format(self.uid))
-        imr = self.rdfly.extract_imr(
-                self.uid, incl_inbound=True, strict=False)
-
-        # Remove resource itself.
         self.rdfly.purge_rsrc(self.uid, inbound)
         self.rdfly.purge_rsrc(self.uid, inbound)
 
 
         # @TODO This could be a different event type.
         # @TODO This could be a different event type.

+ 30 - 22
lakesuperior/store_layouts/ldp_rs/rsrc_centric_layout.py

@@ -202,24 +202,7 @@ class RsrcCentricLayout:
 
 
         rsrc = Resource(gr, nsc['fcres'][uid])
         rsrc = Resource(gr, nsc['fcres'][uid])
 
 
-        # Check if resource is a tombstone.
-        if rsrc[RDF.type : nsc['fcsystem'].Tombstone]:
-            if strict:
-                raise TombstoneError(
-                        g.tbox.uri_to_uuid(rsrc.identifier),
-                        rsrc.value(nsc['fcrepo'].created))
-            else:
-                self._logger.info('Tombstone found: {}'.format(uid))
-        elif rsrc.value(nsc['fcsystem'].tombstone):
-            if strict:
-                raise TombstoneError(
-                        g.tbox.uri_to_uuid(
-                            rsrc.value(nsc['fcsystem'].tombstone).identifier),
-                        rsrc.value(nsc['fcrepo'].created))
-            else:
-                self._logger.info('Parent tombstone found: {}'.format(uri))
-
-        return rsrc
+        return self._check_rsrc_status(rsrc, strict)
 
 
 
 
     def ask_rsrc_exists(self, uid):
     def ask_rsrc_exists(self, uid):
@@ -231,7 +214,7 @@ class RsrcCentricLayout:
                 meta_gr[nsc['fcres'][uid] : RDF.type : nsc['fcrepo'].Resource])
                 meta_gr[nsc['fcres'][uid] : RDF.type : nsc['fcrepo'].Resource])
 
 
 
 
-    def get_metadata(self, uid, ver_uid=None):
+    def get_metadata(self, uid, ver_uid=None, strict=True):
         '''
         '''
         This is an optimized query to get everything the application needs to
         This is an optimized query to get everything the application needs to
         insert new contents, and nothing more.
         insert new contents, and nothing more.
@@ -239,11 +222,12 @@ class RsrcCentricLayout:
         if ver_uid:
         if ver_uid:
             uid = self.snapshot_uid(uid, ver_uid)
             uid = self.snapshot_uid(uid, ver_uid)
         gr = self.ds.graph(nsc['fcadmin'][uid]) | Graph()
         gr = self.ds.graph(nsc['fcadmin'][uid]) | Graph()
+        rsrc = Resource(gr, nsc['fcres'][uid])
 
 
-        return Resource(gr, nsc['fcres'][uid])
+        return self._check_rsrc_status(rsrc, strict)
 
 
 
 
-    def get_version_info(self, uid):
+    def get_version_info(self, uid, strict=True):
         '''
         '''
         Get all metadata about a resource's versions.
         Get all metadata about a resource's versions.
         '''
         '''
@@ -262,9 +246,12 @@ class RsrcCentricLayout:
           }
           }
         }'''
         }'''
 
 
-        return self._parse_construct(qry, init_bindings={
+        gr = self._parse_construct(qry, init_bindings={
             'ag': nsc['fcadmin'][uid],
             'ag': nsc['fcadmin'][uid],
             's': nsc['fcres'][uid]})
             's': nsc['fcres'][uid]})
+        rsrc = Resource(gr, nsc['fcres'][uid])
+
+        return self._check_rsrc_status(rsrc, strict)
 
 
 
 
     def get_inbound_rel(self, uri):
     def get_inbound_rel(self, uri):
@@ -397,6 +384,27 @@ class RsrcCentricLayout:
 
 
     ## PROTECTED MEMBERS ##
     ## PROTECTED MEMBERS ##
 
 
+    def _check_rsrc_status(self, rsrc, strict):
+        # Check if resource is a tombstone.
+        if rsrc[RDF.type : nsc['fcsystem'].Tombstone]:
+            if strict:
+                raise TombstoneError(
+                        g.tbox.uri_to_uuid(rsrc.identifier),
+                        rsrc.value(nsc['fcrepo'].created))
+            else:
+                self._logger.info('Tombstone found: {}'.format(uid))
+        elif rsrc.value(nsc['fcsystem'].tombstone):
+            if strict:
+                raise TombstoneError(
+                        g.tbox.uri_to_uuid(
+                            rsrc.value(nsc['fcsystem'].tombstone).identifier),
+                        rsrc.value(nsc['fcrepo'].created))
+            else:
+                self._logger.info('Parent tombstone found: {}'.format(uri))
+
+        return rsrc
+
+
     def _parse_construct(self, qry, init_bindings={}):
     def _parse_construct(self, qry, init_bindings={}):
         '''
         '''
         Parse a CONSTRUCT query and return a Graph.
         Parse a CONSTRUCT query and return a Graph.

+ 5 - 4
tests/endpoints/test_ldp.py

@@ -278,10 +278,11 @@ class TestLdp:
         frag_qry = 'INSERT {{ <{}#frag> a <urn:ns:A> . }} WHERE {{}}'\
         frag_qry = 'INSERT {{ <{}#frag> a <urn:ns:A> . }} WHERE {{}}'\
                 .format(uri)
                 .format(uri)
 
 
-        assert self.client.patch(
-            path, data=nossr_qry,
-            headers={'content-type' : 'application/sparql-update'}
-        ).status_code == 412
+        # @TODO Leave commented until a decision is made about SSR.
+        #assert self.client.patch(
+        #    path, data=nossr_qry,
+        #    headers={'content-type' : 'application/sparql-update'}
+        #).status_code == 412
 
 
         assert self.client.patch(
         assert self.client.patch(
             path, data=abs_qry,
             path, data=abs_qry,