Bladeren bron

Fix explicit ID setting; add submission ID.

scossu 2 weken geleden
bovenliggende
commit
2f83fdec31
4 gewijzigde bestanden met toevoegingen van 21 en 8 verwijderingen
  1. 5 0
      config/model/typedef/anything.lua
  2. 1 1
      ext/monocypher/lua_monocypher.c
  3. 2 2
      src/generator.lua
  4. 13 5
      src/submission.lua

+ 5 - 0
config/model/typedef/anything.lua

@@ -30,6 +30,11 @@ return {
             max_cardinality = 1,
         },
         --]]
+        sub_id = {
+            description = "Unique ID for the submission that the resource \z
+                was created or updated in.",
+            type = "string",
+        },
         ext_id = {
             uri = "dc:identifier",
             label = "External system ID",

+ 1 - 1
ext/monocypher/lua_monocypher.c

@@ -50,7 +50,7 @@ static int l_blake2b_final (lua_State *L) {
     // digest: BLAKE2 hash.
     crypto_blake2b_ctx *ctx = luaL_checkudata (L, 1, "monocypher.B2Context");
     bool convert_hex = lua_toboolean (L, 2);
-    printf ("Convert to hex: %d\n", convert_hex);
+    //printf ("Convert to hex: %d\n", convert_hex);
 
     unsigned char digest[64];
     size_t hash_size = ctx->hash_size;

+ 2 - 2
src/generator.lua

@@ -208,8 +208,8 @@ local function generate_coll(s, mconf)
     out_html = templates.coll.data({
         --webroot = M.webroot,
         site_title = pkar.config.site.title,
-        title = title.data,
-        description = description.data,
+        title = (title or NT).data or "[No title]",
+        description = (description or NT).data,
         body = body,
         head_tpl = templates.head.data,
         header_tpl = templates.header.data,

+ 13 - 5
src/submission.lua

@@ -79,6 +79,11 @@ end
 
 
 local function generate_sip(ll_path)
+    if not path.isfile(ll_path) then error(ll_path .. " is not a file.", 2) end
+
+    -- Submission ID sticks to all the resources.
+    local sub_id = idgen()
+
     local sip = {root_path = path.dirname(ll_path)}
     path_to_uri = {}
 
@@ -107,16 +112,18 @@ local function generate_sip(ll_path)
                     :format(i, row_n))
             prev_path = row.source_path
             -- New row.
-            sip[i] = {}
+            sip[i] = {
+                -- Normalize provided ID or generate random ID if not provided.
+                id = "par:" .. (row.id or idgen()),
+                sub_id = sub_id,
+            }
             for k, v in pairs(row) do
-                if not v then goto cont1 end  -- skip empty strings.
+                if not v or k == "id" then goto cont1 end  -- skip empty strings.
                 if pkar.config.md.single_values[k] then sip[i][k] = v
                 -- Multi-values are ordered in the SIP for further processing.
                 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
@@ -148,7 +155,7 @@ local function generate_sip(ll_path)
     -- Infer structure from paths and row ordering.
     for i, v in ipairs(sip) do
         local rmod = model.types[v.content_type]
-        dbg.assert(v.source_path)
+        --dbg.assert(v.source_path)
         local fpath = path.join(sip.root_path, v.source_path)
         --dbg.assert(rmod)
         v.has_member = v.has_member or {}
@@ -159,6 +166,7 @@ local function generate_sip(ll_path)
             table.insert(sip, {
                 content_type = rmod.default_fmodel or "file",
                 id = file_id,
+                sub_id = sub_id,
                 label = path.basename(v.source_path),
                 source_path = v.source_path,
             })