瀏覽代碼

Support fixed IDs in submission.

scossu 4 小時之前
父節點
當前提交
5e14fd16e9
共有 2 個文件被更改,包括 26 次插入24 次删除
  1. 7 5
      src/submission.lua
  2. 19 19
      test/sample_submission/demo01/pkar_submission.csv

+ 7 - 5
src/submission.lua

@@ -107,9 +107,7 @@ local function generate_sip(ll_path)
                     :format(i, row_n))
             prev_path = row.source_path
             -- New row.
-            sip[i] = {id = "par:" .. idgen()}
-            -- Add to path to URI map for later referencing.
-            path_to_uri[row.source_path] = sip[i].id
+            sip[i] = {}
             for k, v in pairs(row) do
                 if not v then goto cont1 end  -- skip empty strings.
                 if pkar.config.md.single_values[k] then sip[i][k] = v
@@ -117,6 +115,10 @@ local function generate_sip(ll_path)
                 else sip[i][k] = {v} end
                 ::cont1::
             end
+            -- Normalize provided ID or generate random ID if not provided.
+            sip[i].id = "par:" .. ((sip[i].id or {})[0] or idgen())
+            -- Add to path to URI map for later referencing.
+            path_to_uri[row.source_path] = sip[i].id
         else
             -- Continuation of values from a previous row.
             if i < 1 then
@@ -126,8 +128,7 @@ local function generate_sip(ll_path)
             else
                 for k, v in pairs(row) do
                     if not v then goto cont2 end  -- skip empty strings.
-                    if pkar.config.md.single_values[k] then
-                        -- It doesn't make much sense to overwrite, maybe throw an error?
+                    if k == "id" or pkar.config.md.single_values[k] then
                         error(
                             ("On CSV row #%d: field %s is single-valued.")
                             :format(row_n, k))
@@ -180,6 +181,7 @@ local function generate_sip(ll_path)
         end
         ::skip::
     end
+    logger:debug("Parsed SIP: ", pp.write(sip))
 
     return sip
 end

+ 19 - 19
test/sample_submission/demo01/pkar_submission.csv

@@ -1,19 +1,19 @@
-"source_path","ext_id","content_type","label","alt_label","description","location","date","has_member","pref_rep","long_description"
-"demo_collection","coll0001","collection","My Demo Collection","My Beautiful  Collection","Some random stuff from my hard drive.",,2025-07-28,,"demo_collection/demo_postcard/front/54321.jpg","demo_collection/description.md"
-,,,,"My Aunt's Beautiful Collection","Old B/W photos.",,,,,
-,,,,,"More description to demonstrate how multi-valued fields are filled.",,,,,
-,,,,,"""id"" fields have been left blank to let the system auto-generate them.",,,,,
-"demo_collection/demo_postcard","art0001","postcard","Example Postcard","This is an alternative label","Note that recto and verso representations have been named front and back, to emphasize that the ordering is not alphabetical.",,2025-06-10,,,
-,,,,,,,,,,
-"demo_collection/demo_postcard/front",,"brick","Recto",,"A windy spring day in Capo Falcone, Sardinia","Capo Falcone (SS) Italy",2004-04-12,,,
-,,,,,,"https://www.openstreetmap.org/#map=18/40.9696884/8.2020324",,,,
-"demo_collection/demo_postcard/front/54321.jpg","file0001","still_image_file",,,,,,,,
-"demo_collection/demo_postcard/back",,"brick","Verso",,"Wandering around somewhere in Tirana, 2006.","Tirana, Albania",2006-05-05,,,
-,,,,,,"https://www.openstreetmap.org/relation/1250106",,,,
-"demo_collection/demo_postcard/back/567890.jpg","file0002","still_image_file",,,,,,,,
-"demo_collection/single_image","art0002","still_image","Preparing kebab at Aqil's during curfew",,"Nothing much to do under curfew but cooking, eating, singing, dancing, playing cards, smoking water pipe, and occasionally playing soccer in the street when the Merkava didn't get in the way.","Nablus, Palestine",2002-08-16,,,
-,,,,,,"https://www.openstreetmap.org/#map=19/32.221597/35.260929",,,,
-"demo_collection/single_image/0685_04.jpg","file0003","still_image_file",,,,,,,,
-"coll2","coll0002","collection","Second collection",,"Collection made by reusing files from another collection.",,,"demo_collection/single_image/0685_04.jpg","demo_collection/single_image/0685_04.jpg",
-,,,,,,,,"demo_collection/demo_postcard/front/54321.jpg",,
-"demo_collection/description.md",,"file","Collection description",,,,,,,
+"source_path","id","ext_id","content_type","label","alt_label","description","location","date","has_member","pref_rep","long_description"
+"demo_collection","neCotOV03zeeoDwy","coll0001","collection","My Demo Collection","My Beautiful  Collection","Some random stuff from my hard drive.",,2025-07-28,,"demo_collection/demo_postcard/front/54321.jpg","demo_collection/description.md"
+,,,,,"My Aunt's Beautiful Collection","Old B/W photos.",,,,,
+,,,,,,"More description to demonstrate how multi-valued fields are filled.",,,,,
+,,,,,,"""id"" fields have been left blank to let the system auto-generate them.",,,,,
+"demo_collection/demo_postcard","jLYMjUtQpO9NuLPL","art0001","postcard","Example Postcard","This is an alternative label","Note that recto and verso representations have been named front and back, to emphasize that the ordering is not alphabetical.",,2025-06-10,,,
+,,,,,,,,,,,
+"demo_collection/demo_postcard/front","wqUANcxdRIC3KQuU",,"brick","Recto",,"A windy spring day in Capo Falcone, Sardinia","Capo Falcone (SS) Italy",2004-04-12,,,
+,,,,,,,"https://www.openstreetmap.org/#map=18/40.9696884/8.2020324",,,,
+"demo_collection/demo_postcard/front/54321.jpg","EH7WumaveaXZAsei","file0001","still_image_file",,,,,,,,
+"demo_collection/demo_postcard/back","muhZIUbBLh4TBXWd",,"brick","Verso",,"Wandering around somewhere in Tirana, 2006.","Tirana, Albania",2006-05-05,,,
+,,,,,,,"https://www.openstreetmap.org/relation/1250106",,,,
+"demo_collection/demo_postcard/back/567890.jpg","i5LlJGPkGhZh07Xw","file0002","still_image_file",,,,,,,,
+"demo_collection/single_image","7K45tyYHxDIptKR2","art0002","still_image","Preparing kebab at Aqil's during curfew",,"Nothing much to do under curfew but cooking, eating, singing, dancing, playing cards, smoking water pipe, and occasionally playing soccer in the street when the Merkava didn't get in the way.","Nablus, Palestine",2002-08-16,,,
+,,,,,,,"https://www.openstreetmap.org/#map=19/32.221597/35.260929",,,,
+"demo_collection/single_image/0685_04.jpg","2JzddOOKg6bSAo7z","file0003","still_image_file",,,,,,,,
+"coll2","DFf0nX3xENdEb6GA","coll0002","collection","Second collection",,"Collection made by reusing files from another collection.",,,"demo_collection/single_image/0685_04.jpg","demo_collection/single_image/0685_04.jpg",
+,,,,,,,,,"demo_collection/demo_postcard/front/54321.jpg",,
+"demo_collection/description.md","YdXxJ0xrzyDtZLLT",,"file","Collection description",,,,,,,