Skip to content

Commit

Permalink
Add conditional that tests if the incoming leader has length of 8 #527
Browse files Browse the repository at this point in the history
If the incoming leader is 8 Metafacture is now able to create correct leaders for marc xml with static default values.
  • Loading branch information
TobiasNx committed Nov 19, 2024
1 parent b39ac98 commit d9aded3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public String close(final Object[] args) {

private static final int LEADER_ENTITY_LENGTH = 5;

private static final int LEADER_CONCAT_ENTITIES_LENGTH = 8;
private static final int LEADER_CONCAT_ENTITIES_POS_04 = 4;
private static final int LEADER_CONCAT_ENTITIES_POS_05 = 5;
private static final int LEADER_CONCAT_ENTITIES_POS_07 = 7;

private static final int IND1_BEGIN = 3;
private static final int IND1_END = 4;
private static final int IND2_BEGIN = 4;
Expand Down Expand Up @@ -445,7 +450,12 @@ private void writeLeader() {
}

writeTagLeader(Tag.leader::open);
writeRawLeader("0000" + leader.substring(0, 4) + "2200000" + leader.substring(5, 7) + "4500"); // creates a valid leader without counted elements
if (leader.length() == LEADER_CONCAT_ENTITIES_LENGTH) {
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
}
else {
writeRawLeader(leader);
}
writeTagLeader(Tag.leader::close);

if (formatted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,21 @@ public void issue548_failWhenLeaderIsNotFirst() {
}

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

@Test(expected = MissingIdException.class)
public void issue527_shouldEmitLeaderAlwaysAsWholeString_ensureCorrectMarc21Xml() {
encoder.setEnsureCorrectMarc21Xml(true);
issue527_shouldEmitLeaderAlwaysAsWholeString();
issue527_shouldEmitLeaderAlwaysAsWholeStringWithAddedDefaultLeaderValuesIfLeaderLengthIs8();
}

@Test
Expand Down

0 comments on commit d9aded3

Please sign in to comment.