Browse Source

Legacy pairtree split option (unsure if it will be necessary to
introduce)

Stefano Cossu 6 years ago
parent
commit
deec682ea6
4 changed files with 22 additions and 4 deletions
  1. 1 1
      README.md
  2. 4 0
      etc.skeleton/application.yml
  3. 10 3
      lakesuperior/endpoints/ldp.py
  4. 7 0
      lakesuperior/toolbox.py

+ 1 - 1
README.md

@@ -79,4 +79,4 @@ for a rudimentary road map and status.
 The design documents are in the [doc/pdf](doc/pdf) folder. *@TODO needs update*
 
 [1]: However if your client splits pairtrees upstream, such as Hyrax does, that
-obviously needs to change to get rid of the path segmants.
+obviously needs to change to get rid of the path segments.

+ 4 - 0
etc.skeleton/application.yml

@@ -43,6 +43,10 @@ store:
         #password: <set me>
         #ssl_verify: false
 
+        # This mimics Fedora4 behavior which segments an identifier on POST.
+        # Hyrax will break if this is off.
+        legacy_ptree_split: False
+
     # The path used to persist LDP-NR (bitstreams).
     # This is for now a POSIX filesystem. Other solutions such as HDFS may be
     # possible in the future.

+ 10 - 3
lakesuperior/endpoints/ldp.py

@@ -277,9 +277,16 @@ def uuid_for_post(parent_uuid=None, slug=None):
     This may raise an exception resulting in a 404 if the parent is not
     found or a 409 if the parent is not a valid container.
     '''
+    def split_if_legacy(uuid):
+        if current_app.config['store']['ldp_rs']['legacy_ptree_split']:
+            uuid = Toolbox().split_uuid(uuid)
+        return uuid
+
     # Shortcut!
     if not slug and not parent_uuid:
-        return str(uuid4())
+        uuid = split_if_legacy(str(uuid4()))
+
+        return uuid
 
     parent = Ldpr.outbound_inst(parent_uuid, repr_opts={'incl_children' : False})
 
@@ -305,11 +312,11 @@ def uuid_for_post(parent_uuid=None, slug=None):
     if slug:
         cnd_uuid = pfx + slug
         if current_app.rdfly.ask_rsrc_exists(nsc['fcres'][cnd_uuid]):
-            uuid = pfx + str(uuid4())
+            uuid = pfx + split_if_legacy(str(uuid4()))
         else:
             uuid = cnd_uuid
     else:
-        uuid = pfx + str(uuid4())
+        uuid = pfx + split_if_legacy(str(uuid4()))
 
     return uuid
 

+ 7 - 0
lakesuperior/toolbox.py

@@ -240,4 +240,11 @@ class Toolbox:
 
         return hash
 
+    def split_uuid(self, uuid):
+        '''
+        Split a UUID into pairtree segments. This mimics FCREPO4 behavior.
+        '''
+        path = '{}/{}/{}/{}/{}'.format(uuid[:2], uuid[2:4],
+                uuid[4:6], uuid[6:8], uuid)
 
+        return path