diff --git a/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java b/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java index c82c1152db8..49037e901fb 100644 --- a/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java +++ b/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java @@ -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 @@ -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); @@ -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. * diff --git a/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java b/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java new file mode 100644 index 00000000000..0306fa70352 --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java @@ -0,0 +1,46 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * 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 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)); + } + } +}