From 00d32d869b6024e16a6da390db22bd87b9b92fea Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <andreas.romeyke@slub-dresden.de> Date: Thu, 13 Dec 2018 14:10:41 +0100 Subject: [PATCH] - file creation/modification date extracted by GeneralObjectCharacteristics as suggested in Supportcase https://exlibrisgroup--c.na62.visual.force.com/apex/VF_Case_WithoutJira?id=5000e00001LYpukAAD - bugfix, parse date using SimpleDateFormat uses parse string now - fixed default values in plugin config --- ..._DnxMoveFileOriginalPathDublettesClean.xml | 8 +-- ...DnxMoveFileOriginalPathDublettesClean.java | 53 +++++++++++++------ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPathDublettesClean.xml b/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPathDublettesClean.xml index 8cf7a19..cef8f5e 100644 --- a/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPathDublettesClean.xml +++ b/src/PLUGIN-INF/metadata_DnxMoveFileOriginalPathDublettesClean.xml @@ -40,7 +40,7 @@ <mandatory>true</mandatory> <x_logic_type>String</x_logic_type> <x_ui_type>TextField</x_ui_type> - <default_value>localhost</default_value> + <default_value>Goobi_SMA</default_value> <css_class>width40</css_class> <x_options></x_options> </x_field> @@ -52,7 +52,7 @@ <mandatory>true</mandatory> <x_logic_type>String</x_logic_type> <x_ui_type>TextField</x_ui_type> - <default_value>localhost</default_value> + <default_value>SLUB</default_value> <css_class>width40</css_class> <x_options></x_options> </x_field> @@ -64,7 +64,7 @@ <mandatory>true</mandatory> <x_logic_type>String</x_logic_type> <x_ui_type>TextField</x_ui_type> - <default_value>localhost</default_value> + <default_value>a12345678A</default_value> <css_class>width40</css_class> <x_options></x_options> </x_field> @@ -74,7 +74,7 @@ </fr:x_form> </pl:initParameters> <pl:description>repairs broken file original paths with dublettes, see <a href="https://intranet.slub-dresden.de/display/LZA/Umgang+mit+Updates+auf+alte+Kitodo-AIPs">https://intranet.slub-dresden.de/display/LZA/Umgang+mit+Updates+auf+alte+Kitodo-AIPs</a></pl:description> - <pl:version>1.3</pl:version> + <pl:version>1.6</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/DnxMoveFileOriginalPathDublettesClean.java b/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPathDublettesClean.java index bd15147..312da5c 100644 --- a/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPathDublettesClean.java +++ b/src/org/slub/rosetta/plugins/repositoryTask/DnxMoveFileOriginalPathDublettesClean.java @@ -122,6 +122,26 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug } } + private String get_file_object_creation_date (IEEditor ieEditor, String filePid) throws DigitoolException { + DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid); + DnxDocumentHelper.ObjectCharacteristics ieOs = ieDnxH.getObjectCharacteristics(); + String file_cre_date = ieOs.getInternalCreationDate(); + return file_cre_date; + } + private String get_file_object_modification_date (IEEditor ieEditor, String filePid) throws DigitoolException { + DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid); + DnxDocumentHelper.ObjectCharacteristics ieOs = ieDnxH.getObjectCharacteristics(); + String file_mod_date = ieOs.getInternalModificationDate(); + return file_mod_date; + } + + private String get_file_object_originalpath (IEEditor ieEditor, String filePid) throws DigitoolException { + DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid); + DnxDocumentHelper.GeneralFileCharacteristics ieGfs = ieDnxH.getGeneralFileCharacteristics(); + String currentFileOriginalPath = ieGfs.getFileOriginalPath(); + return currentFileOriginalPath; + } + public TaskResults execute(IEEditor ieEditor, Map<String, String> initParams, TaskResults taskResults) { log.info("Executing DnxMoveFileOriginalPathDublettesClean for " + ieEditor.getIEPid()); @@ -140,15 +160,13 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug Map<String, Pair<String,Date>> filePathsWithModificationDate = new HashMap<>(); for (String filePid : filePids) { try { - DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid); - DnxDocumentHelper.GeneralFileCharacteristics ieGfs = ieDnxH.getGeneralFileCharacteristics(); - DateFormat date = new SimpleDateFormat(); - String file_mod_date = ieGfs.getInternalFileModificationDate(); - String file_cre_date = ieGfs.getInternalFileCreationDate(); - log.info( "found1 filecreationdate='" + file_cre_date + "' filemoddate='" + file_mod_date + "' for filepid=" + filePid ); + String file_mod_date = get_file_object_modification_date(ieEditor, filePid); + String file_cre_date = get_file_object_creation_date(ieEditor, filePid); + log.info( "found1 fileobject creationdate='" + file_cre_date + "' file object modification date='" + file_mod_date + "' for filepid=" + filePid ); + DateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date currentUpdateDate = date.parse( file_mod_date ); - String currentFileOriginalPath = ieGfs.getFileOriginalPath(); + String currentFileOriginalPath = get_file_object_originalpath(ieEditor, filePid); // workaround to check if fileOriginalPath has no "file://" because the replacement // always(!) starts with "file://" @@ -242,6 +260,7 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug TimeUnit.SECONDS.sleep(2); doRep(); } catch (Exception e) { + log.error("unexpected time storage", e); } return taskResults; @@ -252,15 +271,12 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug /* replace file original path if it starts with "file://data/" or "/data/" */ private boolean replaceFileOriginalPath(IEEditor ieEditor, String repPid, String filePid, Map<String, Pair<String,Date>> filePathsWithModificationDate) throws DigitoolException, FileOriginalPathCollisionException, java.text.ParseException { - DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid); - DnxDocumentHelper.GeneralFileCharacteristics ieGfs = ieDnxH.getGeneralFileCharacteristics(); - String currentFileOriginalPath = ieGfs.getFileOriginalPath(); + String currentFileOriginalPath = get_file_object_originalpath(ieEditor, filePid); String iePid = ieEditor.getIEPid(); - DateFormat date = new SimpleDateFormat(); - String file_mod_date = ieGfs.getInternalFileModificationDate(); - String file_cre_date = ieGfs.getInternalFileCreationDate(); - log.info( "found2 filecreationdate='" + file_cre_date + "' filemoddate='" + file_mod_date + "' for filepid=" + filePid ); - + String file_cre_date = get_file_object_creation_date(ieEditor, filePid); + String file_mod_date = get_file_object_modification_date(ieEditor, filePid); + log.info( "found2 file object creation date='" + file_cre_date + "' file object modification date='" + file_mod_date + "' for filepid=" + filePid ); + DateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date currentModificationDate = date.parse( file_mod_date ); String updatedFileOriginalPath = currentFileOriginalPath; /* default to current to avoid empty string */ boolean updated = false; @@ -273,9 +289,9 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug if (filePathsWithModificationDate.containsKey( updatedFileOriginalPath )) { //collision found as expected // find file and check date Date updatedFileModificationDate = new Date(); - String updatedFilePid = new String(); // file pid which is outdated now + String updatedFilePid = ""; // file pid which is outdated now for(Map.Entry<String, Pair<String, Date>> entry : filePathsWithModificationDate.entrySet()) { - if (entry.getKey() == updatedFileOriginalPath) { + if (entry.getKey().equals(updatedFileOriginalPath)) { updatedFilePid = entry.getValue().getKey(); updatedFileModificationDate = entry.getValue().getValue(); break; @@ -298,6 +314,7 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug } else { // no collision but candidate to rename found // Do nothing, because we set fileoriginalpath to updated version + log.info("nothing todo, because no collision but candidate to rename found"); } updated = true; log.info("update needed for IE " + ieEditor.getIEPid() + " RepPid " + repPid + " FilePid " + filePid + @@ -309,6 +326,8 @@ public class DnxMoveFileOriginalPathDublettesClean implements RepositoryTaskPlug log.info("No update needed for IE " + ieEditor.getIEPid() + " RepPid " + repPid + " FilePid " + filePid + " (file_original_path='" + currentFileOriginalPath + "')"); } + DnxDocumentHelper ieDnxH = ieEditor.getDnxHelper(filePid); + DnxDocumentHelper.GeneralFileCharacteristics ieGfs = ieDnxH.getGeneralFileCharacteristics(); ieGfs.setFileOriginalPath(updatedFileOriginalPath); // new set of fileoriginalpath ieDnxH.setGeneralFileCharacteristics(ieGfs); ieEditor.setDnx(ieDnxH, filePid); /* necessary to commit changes on filePID */ -- GitLab