fix empty subfields, fixe #7

This commit is contained in:
Jörg Prante 2019-11-06 23:49:12 +01:00
parent 7317647023
commit f17e9c97b4
6 changed files with 41 additions and 4 deletions

View file

@ -43,11 +43,17 @@ tasks.withType(JavaCompile) {
} }
} }
clean {
delete 'out'
}
test { test {
useJUnitPlatform() useJUnitPlatform()
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties' systemProperty 'java.util.logging.config.file',
project.file('src/test/resources/logging.properties').toString()
failFast = false failFast = false
testLogging { testLogging {
showStandardStreams = true
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED' events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
} }
afterSuite { desc, result -> afterSuite { desc, result ->

View file

@ -523,7 +523,7 @@ public class MarcField implements Comparable<MarcField> {
public Builder value(RecordLabel recordLabel, String value) { public Builder value(RecordLabel recordLabel, String value) {
if (value.length() > 0) { if (value.length() > 0) {
int len = recordLabel.getSubfieldIdentifierLength() - 1; /* minus length of US separator char */ int len = recordLabel.getSubfieldIdentifierLength() - 1; /* minus length of US separator char */
if (!isControl() && len > 0 && value.length() > len) { if (!isControl() && len >= 0 && value.length() >= len) {
String id = value.substring(0, len); String id = value.substring(0, len);
String content = value.substring(len); String content = value.substring(len);
subfield(id, content); subfield(id, content);

View file

@ -347,4 +347,33 @@ public class MarcJsonWriterTest {
new FileInputStream(file)); new FileInputStream(file));
} }
/**
* Test a MARC file which defines an empty subfield for correct JSON output.
*
* @throws Exception if test fails
*/
@Test
public void testMarcRecordWithEmptySubfieldJson() throws Exception {
for (String s : new String[]{
"rism_190101037.mrc"
}) {
InputStream in = getClass().getResource("/org/xbib/marc/" + s).openStream();
File file = File.createTempFile(s + ".", ".json");
file.deleteOnExit();
FileOutputStream out = new FileOutputStream(file);
try (MarcJsonWriter writer = new MarcJsonWriter(out)
) {
Marc.builder()
.setFormat(MarcXchangeConstants.MARCXCHANGE_FORMAT)
.setType(MarcXchangeConstants.BIBLIOGRAPHIC_TYPE)
.setInputStream(in)
.setCharset(Charset.forName("ANSEL"))
.setMarcRecordListener(writer)
.build()
.writeRecordCollection();
}
assertStream(s, getClass().getResource("/org/xbib/marc/json/" + s + ".json").openStream(),
new FileInputStream(file));
}
}
} }

View file

@ -1,5 +1,5 @@
handlers = java.util.logging.ConsoleHandler handlers = java.util.logging.ConsoleHandler
.level = FINE .level = INFO
java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %1$tFT%1$tT.%1$tL%1$tz [%4$-11s] [%3$s] %5$s %6$s%n java.util.logging.SimpleFormatter.format = %1$tFT%1$tT.%1$tL%1$tz [%4$-11s] [%3$s] %5$s %6$s%n

View file

@ -0,0 +1 @@
[{"_FORMAT":"MarcXchange","_TYPE":"Bibliographic","_LEADER":"00937ndm a2200253 u 4500","001":["190101037"],"003":["DE-633"],"005":["20170526171907.0"],"031":[{"__":[{"a":"1"},{"b":"1"},{"c":"1"},{"d":"Largo"},{"g":"G-2"},{"m":"vl"},{"o":"3/2"},{"p":"2-4.8''E'EA''C/2'B4.8''E'EB''D/2C"},{"r":"a"},{"u":"30226769"},{"2":"pe"}]},{"__":[{"a":"1"},{"b":"2"},{"c":"1"},{"d":"Vivace"},{"o":"3/4"},{"u":"30226770"},{"2":"pe"}]},{"__":[{"a":"1"},{"b":"3"},{"c":"1"},{"d":"Adagio"},{"o":"3/2"},{"u":"30226771"},{"2":"pe"}]},{"__":[{"a":"1"},{"b":"4"},{"c":"1"},{"d":"Non presto"},{"o":"c/"},{"u":"30226772"},{"2":"pe"}]}],"040":[{"__":[{"a":"DE-633"}]}],"100":[{"1_":[{"a":"Roman, Johan Helmich"},{"d":"1694-1758"},{"j":"e"},{"0":"30002729"}]}],"240":[{"10":[{"a":"Sonatas"},{"m":"vl (2), bc"},{"n":"BenR T11.107"},{"r":"a"}]}],"245":[{"10":[{"a":"[without title]"}]}],"300":[{"__":[{"a":"score: 4f."},{"8":"1\\c"}]}],"500":[{"__":[{"a":"Thumb Ro 51 (32): http://muscat.rism.info/system/digital_objects/attachments/000/000/044/original/308.jpg"}]}],"504":[{"__":[{"a":"BenR"},{"b":"T11.107"},{"0":"265"}]}],"593":[{"__":[{"a":"autograph"},{"8":"1\\c"}]}],"594":[{"__":[{"a":"vl (2), bc"}]}],"650":[{"00":[{"a":"Trio sonatas"}]}],"852":[{"__":[{"a":"S-Skma"},{"c":"Ro 51"},{"x":"30002153"}]}],"856":[{"40":[{"u":"http://www.muslib.se/ebibliotek/roman/browsevol.php?lang=en&by=volymid&volymid=Ro+51"},{"z":""}]}]}]

View file

@ -0,0 +1 @@
00937ndm a2200253 u 4500001001000000003000700010005001700017031008500034031003900119031003900158031004200197040001100239100004900250240004100299245002000340300002000360500011000380504002300490593001900513594001500532650001700547852002800564856009100592190101037DE-63320170526171907.0 a1b1c1dLargogG-2mvlo3/2p2-4.8''E'EA''C/2'B4.8''E'EB''D/2Crau302267692pe a1b2c1dVivaceo3/4u302267702pe a1b3c1dAdagioo3/2u302267712pe a1b4c1dNon prestooc/u302267722pe aDE-6331 aRoman, Johan Helmichd1694-1758je03000272910aSonatasmvl (2), bcnBenR T11.107ra10a[without title] ascore: 4f.81\c aThumb Ro 51 (32): http://muscat.rism.info/system/digital_objects/attachments/000/000/044/original/308.jpg aBenRbT11.1070265 aautograph81\c avl (2), bc00aTrio sonatas aS-SkmacRo 51x3000215340uhttp://www.muslib.se/ebibliotek/roman/browsevol.php?lang=en&by=volymid&volymid=Ro+51z