diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperPageImporterWorkflowPlugin.java b/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperPageImporterWorkflowPlugin.java index 833d432..9fde260 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperPageImporterWorkflowPlugin.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperPageImporterWorkflowPlugin.java @@ -124,12 +124,6 @@ public class NewspaperPageImporterWorkflowPlugin implements IWorkflowPlugin, IPu private Prefs prefs; private Fileformat fileformat; - private static final Comparator byIssueDate = (NewspaperPage page1, NewspaperPage page2) -> { - String date1 = page1.getDate(); - String date2 = page2.getDate(); - return date1.compareTo(date2); - }; - @Override public PluginType getType() { return PluginType.Workflow; @@ -270,7 +264,7 @@ public void startImport(String set) { if (!run) { break; } - String issueDate = issueEntry.getKey(); + String issueDate = issueEntry.getKey().substring(0, issueEntry.getKey().indexOf("_")); List issuePages = issueEntry.getValue(); boolean success = tryUpdateOldProcessForIssue(process, issuePages); if (!success) { @@ -304,14 +298,35 @@ public void startImport(String set) { new Thread(runnable).start(); } + /** + * get all Newspapers ordered by date and type + * + * @param folder + * @return + */ private List getSortedNewspaperPages(String folder) { return storageProvider.listFiles(folder) .stream() - .map(NewspaperPage::new) - .sorted(byIssueDate) + .map(fileName -> new NewspaperPage(fileName, morningIssueIdentifier, eveningIssueIdentifier)) + .sorted(byMultipleFields) .collect(Collectors.toList()); } + /** + * Comparator for NewspaperPages to get them sorted by date and then by morning, regular and evening + */ + Comparator byMultipleFields = Comparator + .comparing(NewspaperPage::getDate) + .thenComparing(page -> { + if (page.isMorningIssue()) { + return 1; // morning issues + } + if (page.isEveningIssue()) { + return 3; // evening issues + } + return 2; // general issues + }); + private boolean validateNewspaperPages(List pages) { boolean result = true; for (NewspaperPage p : pages) { @@ -347,7 +362,7 @@ private int getNumberOfPages(Map> pagesGrouped) { private Map> getSortedNewspaperPagesGroupedByDates(List pages) { return pages .stream() - .collect(Collectors.groupingBy(NewspaperPage::getDate, LinkedHashMap::new, Collectors.toList())); + .collect(Collectors.groupingBy(NewspaperPage::getDateAndType, LinkedHashMap::new, Collectors.toList())); } /** @@ -704,6 +719,13 @@ private DocStruct createNewIssue(Prefs prefs, DigitalDocument dd, NewspaperPage // TitleDocMain MetadataType titleType = prefs.getMetadataTypeByName(TITLE_DOC_MAIN_TYPE); String titleValue = page.getUserFriendlyTitle(languageForDateFormat, issueTitlePrefix); + if (page.isMorningIssue()) { + titleValue = page.getUserFriendlyTitle(languageForDateFormat, issueTitlePrefixMorning); + } + if (page.isEveningIssue()) { + titleValue = page.getUserFriendlyTitle(languageForDateFormat, issueTitlePrefixEvening); + } + Metadata titleMetadata = createMetadata(titleType, titleValue, false); issue.addMetadata(titleMetadata); diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/model/NewspaperPage.java b/module-base/src/main/java/de/intranda/goobi/plugins/model/NewspaperPage.java index f50f31b..91d747e 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/model/NewspaperPage.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/model/NewspaperPage.java @@ -54,22 +54,26 @@ public class NewspaperPage { private String fileName; private LocalDate localdate; private String date; + private String dateAndType; private String year; private String month; private String day; private String pageNumber; + private boolean morningIssue = false; + private boolean eveningIssue = false; /** * Constructs a NewspaperPage object with the given file path. * * @param filePath The path to the newspaper page file. */ - public NewspaperPage(Path filePath) { + public NewspaperPage(Path filePath, String morningIdentifier, String eveningIdentifier) { this.filePath = filePath; fileName = filePath.getFileName().toString(); pageNumber = fileName.substring(fileName.lastIndexOf("_") + 1, fileName.lastIndexOf(".")); date = getDateFromFileName(fileName); + dateAndType = date + "_1"; localdate = LocalDate.parse(date); String[] dateParts = date.split("[\\W_]+"); @@ -78,6 +82,16 @@ public NewspaperPage(Path filePath) { month = dateParts[1]; day = dateParts[2]; } + + // check if it is a morning or evening issue + if (StringUtils.isNotBlank(morningIdentifier) && fileName.contains(morningIdentifier)) { + morningIssue = true; + dateAndType = date + "_0"; + } + if (StringUtils.isNotBlank(eveningIdentifier) && fileName.contains(eveningIdentifier)) { + eveningIssue = true; + dateAndType = date + "_2"; + } } /**