Skip to content

Commit

Permalink
Merge pull request kitodo#6143 from BartChris/label_and_orderlabel_in…
Browse files Browse the repository at this point in the history
…_mass_import

Enrich process with LABEL and ORDERLABEL during mass import
  • Loading branch information
solth authored Aug 1, 2024
2 parents 1f5499d + 7a82c53 commit faf1085
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -1292,6 +1293,19 @@ private List<MetadataEntry> createMetadata(Map<String, List<String>> presetMetad
return metadata;
}

private void setLabelAndOrderLabelOfImportedProcess(TempProcess tempProcess, Map<String, List<String>> presetMetadata) {
List<String> labelList = presetMetadata.get(ProcessFieldedMetadata.METADATA_KEY_LABEL);
List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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<String, List<String>> 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> 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<Metadata> metadataSet, String metadataKey, String metadataValue) {
return metadataSet.stream()
.filter(metadata -> metadata.getKey().equals(metadataKey))
Expand Down

0 comments on commit faf1085

Please sign in to comment.