From 924f0fd952d85a0ecf9f6aed645aa04f515e2694 Mon Sep 17 00:00:00 2001
From: David Maus <maus@hab.de>
Date: Mon, 19 Feb 2018 11:12:28 +0100
Subject: [PATCH] =?UTF-8?q?Erzeuge=20PREMIS:EVENT=20f=C3=BCr=20Dokumenters?=
 =?UTF-8?q?tellung?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/xproc/publish.xpl | 11 +++++++++++
 src/xslt/mets.xsl     | 27 +++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/xproc/publish.xpl b/src/xproc/publish.xpl
index 4ddf9fa..13d3a29 100644
--- a/src/xproc/publish.xpl
+++ b/src/xproc/publish.xpl
@@ -6,6 +6,14 @@
   <p:option name="objectId"  required="true"/>
   <p:option name="targetUri" required="true"/>
 
+  <p:uuid name="uuid-source" version="4" match="@create">
+    <p:input port="source">
+      <p:inline>
+        <uuid create=""/>
+      </p:inline>
+    </p:input>
+  </p:uuid>
+
   <p:choose>
     <p:when test="doc-available(resolve-uri($targetUri))">
       <p:error code="TargetFileExists">
@@ -31,6 +39,9 @@
 
       <p:xslt name="normalize">
         <p:with-param name="objectId" select="$objectId"/>
+        <p:with-param name="eventCreateUUID" select="/uuid/@create">
+          <p:pipe step="uuid-source" port="result"/>
+        </p:with-param>
         <p:input port="source">
           <p:pipe step="validate-kitodo" port="result"/>
         </p:input>
diff --git a/src/xslt/mets.xsl b/src/xslt/mets.xsl
index 77b129a..06f0380 100644
--- a/src/xslt/mets.xsl
+++ b/src/xslt/mets.xsl
@@ -11,6 +11,7 @@
 
   <!-- Normalisiert die von Kitodo.Production erzeugte METS-Datei -->
   <xsl:param name="objectId" as="xs:string" required="yes"/>
+  <xsl:param name="eventCreateUUID" as="xs:string" required="yes"/>
 
   <xsl:key name="files" match="file" use="@ID"/>
 
@@ -24,7 +25,29 @@
     </mets>
   </xsl:template>
 
-  <xsl:template match="amdSec"/>
+  <xsl:template match="amdSec">
+    <amdSec>
+      <digiprovMD ID="id.{$eventCreateUUID}" CREATED="{current-dateTime()}">
+        <mdWrap MDTYPE="PREMIS:EVENT">
+          <xmlData>
+            <premis:event xmlns:premis="http://www.loc.gov/premis/v3">
+              <premis:eventIdentifier>
+                <premis:eventIdentifierType>UUID</premis:eventIdentifierType>
+                <premis:eventIdentifierValue><xsl:value-of select="$eventCreateUUID"/></premis:eventIdentifierValue>
+              </premis:eventIdentifier>
+              <premis:eventType valueURI="http://id.loc.gov/vocabulary/preservation/eventType/creation">creation</premis:eventType>
+              <premis:eventDataTime><xsl:value-of select="/mets/metsHdr/@CREATEDATE"/></premis:eventDataTime>
+              <premis:linkingAgentIdentifier>
+                <premis:linkingAgentIdentifierType>Name</premis:linkingAgentIdentifierType>
+                <premis:linkingAgentIdentifierValue><xsl:value-of select="/mets/metsHdr/agent/name"/></premis:linkingAgentIdentifierValue>
+                <premis:linkingAgentRole valueURI="http://id.loc.gov/vocabulary/preservation/eventRelatedAgentRole/exe">executing program</premis:linkingAgentRole>
+              </premis:linkingAgentIdentifier>
+            </premis:event>
+          </xmlData>
+        </mdWrap>
+      </digiprovMD>
+    </amdSec>
+  </xsl:template>
 
   <xsl:template match="@ADMID"/>
 
@@ -35,7 +58,7 @@
   </xsl:template>
 
   <xsl:template match="metsHdr">
-    <metsHdr CREATEDATE="{@CREATEDATE}" LASTMODDATE="{current-dateTime()}">
+    <metsHdr CREATEDATE="{@CREATEDATE}" LASTMODDATE="{current-dateTime()}" ADMID="id.{$eventCreateUUID}">
       <agent ROLE="CUSTODIAN" TYPE="ORGANIZATION">
         <name>Herzog August Bibliothek Wolfenbüttel</name>
       </agent>
-- 
GitLab