diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java index db11aab30de..8eaa99a9e16 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java @@ -1216,6 +1216,7 @@ public Process importProcess(String ppn, int projectId, int templateId, ImportCo processTempProcess(tempProcess, ServiceManager.getRulesetService().openRuleset(template.getRuleset()), "create", Locale.LanguageRange.parse(metadataLanguage.isEmpty() ? "en" : metadataLanguage), parentTempProcess); + setLabelAndOrderLabelOfImportedProcess(tempProcess, presetMetadata); String title = tempProcess.getProcess().getTitle(); String validateRegEx = ConfigCore.getParameterOrDefaultValue(ParameterCore.VALIDATE_PROCESS_TITLE_REGEX); if (StringUtils.isBlank(title)) { @@ -1292,6 +1293,19 @@ private List createMetadata(Map> presetMetad return metadata; } + private void setLabelAndOrderLabelOfImportedProcess(TempProcess tempProcess, Map> presetMetadata) { + List labelList = presetMetadata.get(ProcessFieldedMetadata.METADATA_KEY_LABEL); + List orderLabelList = presetMetadata.get(ProcessFieldedMetadata.METADATA_KEY_ORDERLABEL); + + if (Objects.nonNull(labelList) && !labelList.isEmpty() && !labelList.get(0).isBlank()) { + tempProcess.getWorkpiece().getLogicalStructure().setLabel(labelList.get(0)); + } + + if (Objects.nonNull(orderLabelList) && !orderLabelList.isEmpty() && !orderLabelList.get(0).isBlank()) { + tempProcess.getWorkpiece().getLogicalStructure().setOrderlabel(orderLabelList.get(0)); + } + } + /** * Load doc type metadata keys from provided ruleset. * @param ruleset Ruleset from which doc type metadata keys are loaded and returned diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java index 862bf8fceab..bf28dfde4f0 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java @@ -44,7 +44,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; @@ -117,6 +116,8 @@ public class ImportServiceIT { private static final int RULESET_ID = 1; private static final String TITLE = "Title"; private static final String PLACE = "Place"; + private static final String LABEL = "LABEL"; + private static final String ORDERLABEL = "ORDERLABEL"; private static final int EXPECTED_NR_OF_CHILDREN = 23; private static final String PICA_XML = "picaxml"; private static final String PICA_PPN = "pica.ppn"; @@ -202,6 +203,40 @@ public void testImportProcessWithAdditionalMetadata() throws DAOException, Impor } } + /** + * Tests whether basic catalog metadata import with additional preset metadata including LABEL and ORDERLABEL + * succeeds. + * + * @throws DAOException when loading ImportConfiguration or removing test process from test database fails. + * @throws ImportException when importing metadata fails + * @throws IOException when importing metadata fails + */ + @Test + public void testImportProcessWithAdditionalMetadataWithLabelAndOrderlabel() throws DAOException, ImportException, IOException { + Map> presetMetadata = new HashMap<>(); + presetMetadata.put(TITLE, List.of("Band 1")); + presetMetadata.put(PLACE, List.of("Hamburg", "Berlin")); + presetMetadata.put(LABEL, List.of("TEST-LABEL")); + presetMetadata.put(ORDERLABEL, List.of("TEST-ORDERLABEL")); + Process processWithAdditionalMetadata = importProcessWithAdditionalMetadata(RECORD_ID, + MockDatabase.getK10PlusImportConfiguration(), presetMetadata); + Workpiece workpiece = ServiceManager.getMetsService() + .loadWorkpiece(processService.getMetadataFileUri(processWithAdditionalMetadata)); + HashSet metadata = workpiece.getLogicalStructure().getMetadata(); + String processLabel = workpiece.getLogicalStructure().getLabel(); + String processOrderlabel = workpiece.getLogicalStructure().getOrderlabel(); + try { + assertTrue(assertMetadataSetContainsMetadata(metadata, TITLE, "Band 1"), "Process does not contain correct metadata"); + assertTrue(assertMetadataSetContainsMetadata(metadata, PLACE, "Hamburg"), "Process does not contain correct metadata"); + assertTrue(assertMetadataSetContainsMetadata(metadata, PLACE, "Berlin"), "Process does not contain correct metadata"); + assertEquals("TEST-LABEL", processLabel,"Process does not have the correct LABEL"); + assertEquals("TEST-ORDERLABEL", processOrderlabel,"Process does not have the correct ORDERLABEL"); + } finally { + ProcessTestUtils.removeTestProcess(processWithAdditionalMetadata.getId()); + } + } + + private boolean assertMetadataSetContainsMetadata(HashSet metadataSet, String metadataKey, String metadataValue) { return metadataSet.stream() .filter(metadata -> metadata.getKey().equals(metadataKey))