Skip to content

Commit

Permalink
allow a distinction between morning and evening issues based on file
Browse files Browse the repository at this point in the history
names
  • Loading branch information
SteffenHankiewicz committed Dec 10, 2024
1 parent a4f724e commit b20d099
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ public class NewspaperPageImporterWorkflowPlugin implements IWorkflowPlugin, IPu
private Prefs prefs;
private Fileformat fileformat;

private static final Comparator<NewspaperPage> byIssueDate = (NewspaperPage page1, NewspaperPage page2) -> {
String date1 = page1.getDate();
String date2 = page2.getDate();
return date1.compareTo(date2);
};

@Override
public PluginType getType() {
return PluginType.Workflow;
Expand Down Expand Up @@ -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<NewspaperPage> issuePages = issueEntry.getValue();
boolean success = tryUpdateOldProcessForIssue(process, issuePages);
if (!success) {
Expand Down Expand Up @@ -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<NewspaperPage> 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<NewspaperPage> 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<NewspaperPage> pages) {
boolean result = true;
for (NewspaperPage p : pages) {
Expand Down Expand Up @@ -347,7 +362,7 @@ private int getNumberOfPages(Map<String, List<NewspaperPage>> pagesGrouped) {
private Map<String, List<NewspaperPage>> getSortedNewspaperPagesGroupedByDates(List<NewspaperPage> pages) {
return pages
.stream()
.collect(Collectors.groupingBy(NewspaperPage::getDate, LinkedHashMap::new, Collectors.toList()));
.collect(Collectors.groupingBy(NewspaperPage::getDateAndType, LinkedHashMap::new, Collectors.toList()));
}

/**
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_]+");
Expand All @@ -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";
}
}

/**
Expand Down

0 comments on commit b20d099

Please sign in to comment.