Pārlūkot izejas kodu

Clean up redundant methods and parameters.

Stefano Cossu 6 gadi atpakaļ
vecāks
revīzija
d6e3cc17bd
3 mainītis faili ar 14 papildinājumiem un 70 dzēšanām
  1. 4 7
      lakesuperior/api/resource.py
  2. 0 11
      lakesuperior/model/ldp_nr.py
  3. 10 52
      lakesuperior/model/ldpr.py

+ 4 - 7
lakesuperior/api/resource.py

@@ -229,13 +229,10 @@ def update(uid, update_str, is_metadata=False):
     If False, and the resource being updated is a LDP-NR, an error is raised.
     '''
     rsrc = LdpFactory.from_stored(uid)
-    if LDP_NR_TYPE in rsrc.ldp_types:
-        if is_metadata:
-            rsrc.patch_metadata(update_str)
-        else:
-            raise InvalidResourceError(uid)
-    else:
-        rsrc.patch(update_str)
+    if LDP_NR_TYPE in rsrc.ldp_types and not is_metadata:
+        raise InvalidResourceError(uid)
+
+    rsrc.sparql_update(update_str)
 
     return rsrc
 

+ 0 - 11
lakesuperior/model/ldp_nr.py

@@ -88,17 +88,6 @@ class LdpNr(Ldpr):
             return ev_type
 
 
-    def patch_metadata(self, update_str):
-        '''
-        Update resource metadata by applying a SPARQL-UPDATE query.
-
-        @param update_str (string) SPARQL-Update staements.
-        '''
-        self.handling = 'lenient' # FCREPO does that and Hyrax requires it.
-
-        return self._sparql_update(update_str)
-
-
     ## PROTECTED METHODS ##
 
     def _add_srv_mgd_triples(self, create=False):

+ 10 - 52
lakesuperior/model/ldpr.py

@@ -211,33 +211,6 @@ class Ldpr(metaclass=ABCMeta):
         self._metadata = rsrc
 
 
-    @property
-    def stored_or_new_imr(self):
-        '''
-        Extract an in-memory resource for harmless manipulation and output.
-
-        If the resource is not stored (yet), initialize a new IMR with basic
-        triples.
-
-        @return rdflib.resource.Resource
-        '''
-        if not hasattr(self, '_imr'):
-            if hasattr(self, '_imr_options'):
-                #logger.debug('IMR options:{}'.format(self._imr_options))
-                imr_options = self._imr_options
-            else:
-                imr_options = {}
-            options = dict(imr_options, strict=True)
-            try:
-                self._imr = rdfly.extract_imr(self.uid, **options)
-            except ResourceNotExistsError:
-                self._imr = Resource(Graph(), self.uri)
-                for t in self.base_types:
-                    self.imr.add(RDF.type, t)
-
-        return self._imr
-
-
     @property
     def out_graph(self):
         '''
@@ -399,24 +372,6 @@ class Ldpr(metaclass=ABCMeta):
         return ev_type
 
 
-    def put(self):
-        '''
-        https://www.w3.org/TR/ldp/#ldpr-HTTP_PUT
-        '''
-        return self.create_or_replace()
-
-
-    def patch(self, update_str):
-        '''
-        Update an existing resource by applying a SPARQL-UPDATE query.
-
-        @param update_str (string) SPARQL-Update staements.
-        '''
-        self.handling = 'lenient' # FCREPO does that and Hyrax requires it.
-
-        return self._sparql_update(update_str)
-
-
     def bury_rsrc(self, inbound, tstone_pointer=None):
         '''
         Delete a single resource and create a tombstone.
@@ -510,7 +465,7 @@ class Ldpr(metaclass=ABCMeta):
             (self.uri, nsc['fcrepo'].hasVersion, ver_uri),
             (self.uri, nsc['fcrepo'].hasVersions, nsc['fcres'][vers_uid]),
         }
-        self._modify_rsrc(RES_UPDATED, add_trp=rsrc_add_gr, notify=False)
+        self._modify_rsrc(RES_UPDATED, add_trp=rsrc_add_gr)
 
         return ver_uid
 
@@ -608,7 +563,7 @@ class Ldpr(metaclass=ABCMeta):
 
 
     def _modify_rsrc(
-            self, ev_type, remove_trp=set(), add_trp=set(), notify=True):
+            self, ev_type, remove_trp=set(), add_trp=set()):
         '''
         Low-level method to modify a graph for a single resource.
 
@@ -616,14 +571,17 @@ class Ldpr(metaclass=ABCMeta):
         store that needs to be notified should be performed by invoking this
         method.
 
-        @param ev_type (string) The type of event (create, update, delete).
+        @param ev_type (string|None) The type of event (create, update,
+        delete) or None. In the latter case, no notification is sent.
         @param remove_trp (set) Triples to be removed.
         @param add_trp (set) Triples to be added.
-        @param notify (boolean) Whether to send a message about the change.
         '''
         rdfly.modify_rsrc(self.uid, remove_trp, add_trp)
 
-        if notify and env.config['application'].get('messaging'):
+        if (
+                ev_type is not None
+                and env.config['application'].get('messaging')
+                and not self.disable_checks):
             logger.debug('Enqueuing message for {}'.format(self.uid))
             self._enqueue_msg(ev_type, remove_trp, add_trp)
 
@@ -857,7 +815,7 @@ class Ldpr(metaclass=ABCMeta):
         return add_trp
 
 
-    def _sparql_update(self, update_str, notify=True):
+    def sparql_update(self, update_str):
         '''
         Apply a SPARQL update to a resource.
 
@@ -868,7 +826,7 @@ class Ldpr(metaclass=ABCMeta):
         self.handling = 'lenient' # FCREPO does that and Hyrax requires it.
         delta = self._sparql_delta(update_str)
 
-        return self._modify_rsrc(RES_UPDATED, *delta, notify=notify)
+        return self._modify_rsrc(RES_UPDATED, *delta)
 
 
     def _sparql_delta(self, q):