Skip to content

Commit d9aded3

Browse files
committed
Add conditional that tests if the incoming leader has length of 8 #527
If the incoming leader is 8 Metafacture is now able to create correct leaders for marc xml with static default values.
1 parent b39ac98 commit d9aded3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public String close(final Object[] args) {
9595

9696
private static final int LEADER_ENTITY_LENGTH = 5;
9797

98+
private static final int LEADER_CONCAT_ENTITIES_LENGTH = 8;
99+
private static final int LEADER_CONCAT_ENTITIES_POS_04 = 4;
100+
private static final int LEADER_CONCAT_ENTITIES_POS_05 = 5;
101+
private static final int LEADER_CONCAT_ENTITIES_POS_07 = 7;
102+
98103
private static final int IND1_BEGIN = 3;
99104
private static final int IND1_END = 4;
100105
private static final int IND2_BEGIN = 4;
@@ -445,7 +450,12 @@ private void writeLeader() {
445450
}
446451

447452
writeTagLeader(Tag.leader::open);
448-
writeRawLeader("0000" + leader.substring(0, 4) + "2200000" + leader.substring(5, 7) + "4500"); // creates a valid leader without counted elements
453+
if (leader.length() == LEADER_CONCAT_ENTITIES_LENGTH) {
454+
writeRawLeader("0000" + leader.substring(0, LEADER_CONCAT_ENTITIES_POS_04) + "2200000" + leader.substring(LEADER_CONCAT_ENTITIES_POS_05, LEADER_CONCAT_ENTITIES_POS_07) + "4500"); // creates a valid leader without counted elements
455+
}
456+
else {
457+
writeRawLeader(leader);
458+
}
449459
writeTagLeader(Tag.leader::close);
450460

451461
if (formatted) {

metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,21 +301,21 @@ public void issue548_failWhenLeaderIsNotFirst() {
301301
}
302302

303303
@Test
304-
public void issue527_shouldEmitLeaderAlwaysAsWholeString() {
304+
public void issue527_shouldEmitLeaderAlwaysAsWholeStringWithAddedDefaultLeaderValuesIfLeaderLengthIs8() {
305305
createRecordWithLeader("1", "a", "o", "a", " ", "a", "z", "u", " ");
306306
createRecordWithLeader("2", "d", "u", "m", " ", "m", "y", "#", " ");
307307
encoder.closeStream();
308308
String expected = XML_DECLARATION + XML_ROOT_OPEN
309-
+ "<marc:record><marc:leader>aoa azu </marc:leader></marc:record>"
310-
+ "<marc:record><marc:leader>dum my# </marc:leader></marc:record>" + XML_MARC_COLLECTION_END_TAG;
309+
+ "<marc:record><marc:leader>0000aoa 2200000zu4500</marc:leader></marc:record>"
310+
+ "<marc:record><marc:leader>0000dum 2200000y#4500</marc:leader></marc:record>" + XML_MARC_COLLECTION_END_TAG;
311311
String actual = resultCollector.toString();
312312
assertEquals(expected, actual);
313313
}
314314

315315
@Test(expected = MissingIdException.class)
316316
public void issue527_shouldEmitLeaderAlwaysAsWholeString_ensureCorrectMarc21Xml() {
317317
encoder.setEnsureCorrectMarc21Xml(true);
318-
issue527_shouldEmitLeaderAlwaysAsWholeString();
318+
issue527_shouldEmitLeaderAlwaysAsWholeStringWithAddedDefaultLeaderValuesIfLeaderLengthIs8();
319319
}
320320

321321
@Test

0 commit comments

Comments
 (0)