From 826febd8a8df783e1f63de9d83809bcd8aabd87a Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <andreas.romeyke@slub-dresden.de>
Date: Thu, 1 Feb 2018 12:59:43 +0100
Subject: [PATCH] - fixed DateTime - added counters to improve
 EventOutComeDetail1

---
 .../metadata_DnxMoveFileOriginalPath.xml       |  2 +-
 .../DnxMoveFileOriginalPath.java               | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPath.xml b/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPath.xml
index bb5b3cc..07789d7 100644
--- a/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPath.xml
+++ b/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPath.xml
@@ -7,7 +7,7 @@
 	</fr:x_form>
   </pl:initParameters>
   <pl:description>repairs broken file original paths</pl:description>
-  <pl:version>1.05</pl:version>
+  <pl:version>1.08</pl:version>
   <pl:materialType>DIGITAL</pl:materialType>
   <pl:module>Repository</pl:module>
   <pl:generalType>TASK</pl:generalType>
diff --git a/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPath.java b/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPath.java
index 061674e..0ac50c6 100644
--- a/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPath.java
+++ b/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPath.java
@@ -6,7 +6,9 @@ import com.exlibris.digitool.common.dnx.DnxDocumentHelper;
 import com.exlibris.digitool.exceptions.DigitoolException;
 import com.exlibris.digitool.repository.api.IEEditor;
 import com.exlibris.digitool.repository.api.RepositoryTaskPlugin;
-import java.time.LocalDate;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.List;
 import java.util.Map;
 
@@ -31,6 +33,8 @@ public class DnxMoveFileOriginalPath implements RepositoryTaskPlugin {
             taskResults.addResult(ieEditor.getIEPid(), null, false, "no RepPids found!");
             return taskResults;
         }
+        int countFiles=0;
+        int countSuccess=0;
         // get all file pids
         for (String repPid: repPids) {
             List<String> filePids;
@@ -44,7 +48,8 @@ public class DnxMoveFileOriginalPath implements RepositoryTaskPlugin {
             }
             for (String filePid: filePids) {
                 try {
-                    replaceFileOriginalPath(ieEditor, repPid, filePid);
+                    countFiles++;
+                    if (replaceFileOriginalPath(ieEditor, repPid, filePid)) { countSuccess++; }
                     taskResults.addResult(ieEditor.getIEPid(), null, true, "filepid=" + filePid + " processed");
                 } catch (DigitoolException e) {
                     success = false;
@@ -62,14 +67,16 @@ public class DnxMoveFileOriginalPath implements RepositoryTaskPlugin {
             DnxDocumentHelper.Event event = ieDnxH.new Event();
             event.setEventIdentifierType("Rosetta-SupportCase");
             event.setEventIdentifierValue("00490927");
-            event.setEventDateTime(LocalDate.now().toString());
+            LocalDateTime date = LocalDateTime.now();
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            event.setEventDateTime(date.format(formatter));
             event.setEventType("external repair using DnxMoveFileOriginalPath plugin");
             if (success) {
                 event.setEventOutcome1("success");
             } else {
                 event.setEventOutcome1("fail");
             }
-            event.setEventOutcomeDetail1("IE-PID = '" + ieEditor.getIEPid() + "'");
+            event.setEventOutcomeDetail1("IE-PID = '" + ieEditor.getIEPid() + "', " + countSuccess + " of " + countFiles + " fileOriginalPath entries replaced");
             event.setEventDescription("fileOriginalPath needs to be updated to correct a mistake in the Submission Application where wrong fileOriginalPath metadata was read and inserted. The result of this mistake was that the fileOriginalPath now includes directories that are too high up in the directory hierarchy.");
             event.setLinkingAgentIdentifierType1("HUMAN");
             event.setLinkingAgentIdentifierValue1("plugin programmed by Andreas Romeyke (SLUB Dresden), code available at https://github.com/SLUB-digitalpreservation/fileoriginalpath_plugin4rosetta");
@@ -85,7 +92,7 @@ public class DnxMoveFileOriginalPath implements RepositoryTaskPlugin {
 
 
 	/* replace file original path if it starts with "file://data/" or "/data/" */
-    private void replaceFileOriginalPath(IEEditor ieEditor, String repPid, String filePid) throws DigitoolException {
+    private boolean replaceFileOriginalPath(IEEditor ieEditor, String repPid, String filePid) throws DigitoolException {
         DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid);
         DnxDocumentHelper.GeneralFileCharacteristics ieGfs = ieDnxH.getGeneralFileCharacteristics();
         String currentFileOriginalPath = ieGfs.getFileOriginalPath();
@@ -118,6 +125,7 @@ public class DnxMoveFileOriginalPath implements RepositoryTaskPlugin {
         ieGfs.setFileOriginalPath(updatedFileOriginalPath);
         ieDnxH.setGeneralFileCharacteristics(ieGfs);
         ieEditor.setDnx(ieDnxH, filePid);
+        return updated;
     }
 
 
-- 
GitLab