Skip to content

Commit

Permalink
Fix access to meta data on more deep structure elements
Browse files Browse the repository at this point in the history
  • Loading branch information
henning-gerhardt committed Nov 30, 2023
1 parent dbda5dc commit 2636e12
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,17 @@ private String determineReplacementForMetadata(Matcher variableFinder) {
switch (metadataLevel) {
case ALL:
List<LogicalDivision> allChildren = workpiece.getLogicalStructure().getChildren();
String allFirstchildValue = allChildren.isEmpty() ? null
: MetadataEditor.getMetadataValue(allChildren.get(0), variableFinder.group(5));
String allFirstchildValue = null;
if (!allChildren.isEmpty()) {
allFirstchildValue = MetadataEditor.getMetadataValue(allChildren.get(0), variableFinder.group(5));
if (Objects.isNull(allFirstchildValue)) {
List<LogicalDivision> firstChildChildren = allChildren.get(0).getChildren();
if (!firstChildChildren.isEmpty()) {
allFirstchildValue = MetadataEditor.getMetadataValue(firstChildChildren.get(0), variableFinder.group(5));
}
}
}

if (Objects.nonNull(allFirstchildValue)) {
return allFirstchildValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URI;

import org.junit.Test;
import org.kitodo.api.dataformat.Workpiece;
import org.kitodo.config.KitodoConfig;
import org.kitodo.data.database.beans.Folder;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.Project;
import org.kitodo.data.database.beans.Ruleset;
import org.kitodo.data.database.beans.Template;
import org.kitodo.production.services.ServiceManager;

public class VariableReplacerTest {

Expand Down Expand Up @@ -179,6 +182,39 @@ public void shouldReplaceOcrdWorkflowId() {
assertEquals("String was replaced incorrectly!", expected, replaced);
}

@Test
public void shouldReturnMetadataOfNewspaperIssue() throws IOException {
Process process = prepareProcess(2, "variableReplacer/newspaperIssue");
Workpiece workpiece = ServiceManager.getProcessService().readMetadataFile(process).getWorkpiece();
VariableReplacer variableReplacer = new VariableReplacer(workpiece, process, null);

String replaced = variableReplacer.replace("-language $(meta.DocLanguage) -scriptType $(meta.slub_script)");
String expected = "-language ger -scriptType Antiqua";
assertEquals("String should contain expected metadata!", expected, replaced);
}

@Test
public void shouldReturnMetadataOfPeriodialVolume() throws IOException {
Process process = prepareProcess(2, "variableReplacer/periodicalVolume");
Workpiece workpiece = ServiceManager.getProcessService().readMetadataFile(process).getWorkpiece();
VariableReplacer variableReplacer = new VariableReplacer(workpiece, process, null);

String replaced = variableReplacer.replace("-language $(meta.DocLanguage) -scriptType $(meta.slub_script)");
String expected = "-language ger -scriptType Fraktur";
assertEquals("String should contain expected metadata!", expected, replaced);
}

@Test
public void shouldReturnMetadataOfMonograph() throws IOException {
Process process = prepareProcess(2, "variableReplacer/monograph");
Workpiece workpiece = ServiceManager.getProcessService().readMetadataFile(process).getWorkpiece();
VariableReplacer variableReplacer = new VariableReplacer(workpiece, process, null);

String replaced = variableReplacer.replace("-language $(meta.DocLanguage) -scriptType $(meta.slub_script)");
// missing meta data element will be replaced by emtpy string and a warning message appear in the log
String expected = "-language -scriptType keine_OCR";
assertEquals("String should contain expected metadata!", expected, replaced);
}

private Process prepareProcess(int processId, String processFolder) {
Process process = new Process();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:kitodo="http://meta.kitodo.org/v1/" xmlns:mets="http://www.loc.gov/METS/">
<mets:metsHdr CREATEDATE="2023-09-18T09:02:55">
<mets:metsDocumentID>750440</mets:metsDocumentID>
</mets:metsHdr>
<mets:dmdSec ID="DMDLOG_0000">
<mets:mdWrap MDTYPE="OTHER" OTHERMDTYPE="KITODO">
<mets:xmlData>
<kitodo:kitodo>
<kitodo:metadata name="TitleDocMain">Andreas Hammerschmids Chor-Music</kitodo:metadata>
<kitodo:metadata name="TitleDocMainShort">Andreas Hammerschmids Chor-Music</kitodo:metadata>
<kitodo:metadata name="singleDigCollection">Drucke des 17. Jahrhunderts</kitodo:metadata>
<kitodo:metadata name="singleDigCollection">LDP: Sammlung Fürsten- und Landesschule Grimma</kitodo:metadata>
<kitodo:metadata name="singleDigCollection">Musik</kitodo:metadata>
<kitodo:metadata name="slub_script">keine_OCR</kitodo:metadata>
<kitodo:metadata name="docType">Monograph</kitodo:metadata>
<kitodo:metadata name="slub_ownerDigi">SLUB Dresden</kitodo:metadata>
<kitodo:metadata name="slub_ownerOrig">SLUB Dresden</kitodo:metadata>
</kitodo:kitodo>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:fileSec>
<mets:fileGrp USE="LOCAL"/>
</mets:fileSec>
<mets:structMap TYPE="LOGICAL">
<mets:div DMDID="DMDLOG_0000"
ID="LOG_0000"
LABEL="Andreas Hammerschmids Chor-Music"
ORDERLABEL="Andreas Hammerschmids Chor-Music"
TYPE="Monograph"/>
</mets:structMap>
<mets:structMap TYPE="PHYSICAL">
<mets:div ID="PHYS_0000"/>
</mets:structMap>
<mets:structLink>
<mets:smLink xmlns:xlink="http://www.w3.org/1999/xlink" xlink:to="" xlink:from=""/>
</mets:structLink>
</mets:mets>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:kitodo="http://meta.kitodo.org/v1/" xmlns:mets="http://www.loc.gov/METS/">
<mets:metsHdr CREATEDATE="2023-08-29T06:02:00.000+02:00" LASTMODDATE="2023-09-20T19:36:14.446+02:00">
<mets:metsDocumentID>740460</mets:metsDocumentID>
</mets:metsHdr>
<mets:dmdSec ID="uuid-b6cf1e58-29a9-3a16-9a91-f0998a104007">
<mets:mdWrap>
<mets:xmlData>
<kitodo:kitodo>
<kitodo:metadata name="PeriodicalIssue">01-Musiktheater</kitodo:metadata>
<kitodo:metadata name="docType">PeriodicalIssue</kitodo:metadata>
<kitodo:metadata name="singleDigCollection">Saxonica</kitodo:metadata>
<kitodo:metadata name="TitleDocMain">01-Musiktheater</kitodo:metadata>
<kitodo:metadata name="singleDigCollection">Performance Ephemera</kitodo:metadata>
<kitodo:metadata name="singleDigCollection">Musik</kitodo:metadata>
<kitodo:metadata name="slub_script">Antiqua</kitodo:metadata>
<kitodo:metadata name="DocLanguage">ger</kitodo:metadata>
<kitodo:metadata name="slub_ownerOrig">SLUB Dresden</kitodo:metadata>
<kitodo:metadata name="slub_ownerDigi">SLUB Dresden</kitodo:metadata>
</kitodo:kitodo>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:fileSec/>
<mets:structMap TYPE="PHYSICAL">
<mets:div ID="PHYS_0000"/>
</mets:structMap>
<mets:structMap TYPE="LOGICAL">
<mets:div ID="LOG_0009" ORDER="1" ORDERLABEL="1855-04">
<mets:div ID="LOG_0010" ORDER="1" ORDERLABEL="1855-04-30">
<mets:div ID="LOG_0011" DMDID="uuid-b6cf1e58-29a9-3a16-9a91-f0998a104007" TYPE="PeriodicalIssue" ORDER="1"/>
</mets:div>
</mets:div>
</mets:structMap>
<mets:structLink/>
</mets:mets>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:kitodo="http://meta.kitodo.org/v1/" xmlns:mets="http://www.loc.gov/METS/">
<mets:metsHdr CREATEDATE="2023-10-05T09:31:19.619+02:00" LASTMODDATE="2023-10-05T09:39:45.551+02:00">
<mets:metsDocumentID>761701</mets:metsDocumentID>
</mets:metsHdr>
<mets:dmdSec ID="uuid-0c7cc09b-db59-32d1-ae04-98d848ed2e54">
<mets:mdWrap>
<mets:xmlData>
<kitodo:kitodo>
<kitodo:metadata name="DocLanguage">ger</kitodo:metadata>
<kitodo:metadata name="CurrentNo">1829</kitodo:metadata>
<kitodo:metadata name="docType">Periodical</kitodo:metadata>
<kitodo:metadata name="slub_script">Fraktur</kitodo:metadata>
<kitodo:metadata name="PublicationYearSorting">1828</kitodo:metadata>
<kitodo:metadata name="slub_ownerDigi">SLUB Dresden</kitodo:metadata>
<kitodo:metadata name="CurrentNoSorting">18290000</kitodo:metadata>
<kitodo:metadata name="slub_ownerOrig">SLUB Dresden</kitodo:metadata>
<kitodo:metadata name="TitleDocMain">Königl. Sächs. gnädigst privileg. Pirnaischer Haus- und Landwirthschafts-Calender</kitodo:metadata>
</kitodo:kitodo>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:fileSec/>
<mets:structMap TYPE="PHYSICAL">
<mets:div ID="uuid-439342a2-66b7-4545-a3fa-dcf41653e51d"/>
</mets:structMap>
<mets:structMap TYPE="LOGICAL">
<mets:div ID="uuid-95c027f4-4e75-4506-bbfd-1e48550cdfde" DMDID="uuid-0c7cc09b-db59-32d1-ae04-98d848ed2e54" TYPE="PeriodicalVolume" ORDERLABEL="Königl. Sächs. gnädigst privileg. Pirnaischer Haus- und Landwirthschafts-Calender" LABEL="Königl. Sächs. gnädigst privileg. Pirnaischer Haus- und Landwirthschafts-Calender"/>
</mets:structMap>
<mets:structLink/>
</mets:mets>

0 comments on commit 2636e12

Please sign in to comment.