Skip to content

Commit

Permalink
Merge pull request kitodo#4585 from henning-gerhardt/fix_newspaper_ti…
Browse files Browse the repository at this point in the history
…tle_generation

Change regular expression to needed separator before date.
  • Loading branch information
Kathrin-Huber authored Aug 17, 2021
2 parents 83fad32 + 64d5ad4 commit 916032b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class NewspaperProcessesMigrator {
* Regular expression to find (and remove) the individual part of the
* process title, to get the base process title.
*/
private static final String INDIVIDUAL_PART = "(?<=.)\\p{Punct}*(?:1[6-9]|20)\\d{2}\\p{Punct}?(?:0[1-9]|1[012]).*$";
private static final String INDIVIDUAL_PART = "(?<=.)\\p{Punct}+(?:1[6-9]|20)\\d{2}\\p{Punct}?(?:0[1-9]|1[012]).*$";

/**
* A regular expression describing a four-digit year number or a double year
Expand Down Expand Up @@ -261,7 +261,7 @@ public static void initializeMigration(Integer batchId) throws DAOException {
private void initializeMigrator(Process process, String newspaperIncludedStructalElementDivision)
throws IOException, ConfigurationException {

title = process.getTitle().replaceFirst(INDIVIDUAL_PART, "");
title = generateNewspaperShortTitle(process.getTitle());
logger.trace("Newspaper is: {}", title);
projectId = process.getProject().getId();
logger.trace("Project is: {} (ID {})", process.getProject().getTitle(), projectId);
Expand All @@ -286,6 +286,16 @@ private void initializeMigrator(Process process, String newspaperIncludedStructa
() -> new ConfigurationException(dayDivisionView.getId() + " has no dates metadata configuration!"));
}

/**
* Convert a newspaper like full title into its shorted version.
*
* @param newspaperFullTitle Newspaper like full title
* @return Shorted newspaper like title
*/
public String generateNewspaperShortTitle(String newspaperFullTitle) {
return newspaperFullTitle.replaceFirst(INDIVIDUAL_PART, "");
}

/**
* Converts one newspaper process.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.migration;

import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.kitodo.data.database.beans.Batch;


public class NewspaperProcessesMigratorTest {

@Test
public void checkNewspaperShortedTitleGeneration() {
Batch testBatch = new Batch();
testBatch.setTitle("Test Batch for Newspaper Shorted Title Generation");
testBatch.setId(1234);

List<String> listOfNewspaperTitles = Arrays.asList(
"Aben_399196951",
"DresNa_516710338",
"LeipMofT_1679165712",
"StaaHofM_1031939121",
"Zeit_425552225"
);

NewspaperProcessesMigrator migrator = new NewspaperProcessesMigrator(testBatch);
for (String newspaperTitle : listOfNewspaperTitles) {
String dailyTitle = newspaperTitle + "-20210804";
String multipleDailyTitle = dailyTitle + "01p_01-p";
Assert.assertEquals(newspaperTitle, migrator.generateNewspaperShortTitle(dailyTitle));
Assert.assertEquals(newspaperTitle, migrator.generateNewspaperShortTitle(multipleDailyTitle));
}
}
}

0 comments on commit 916032b

Please sign in to comment.