diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/MarcxmlEntityBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/MarcxmlEntityBuilder.java index c5db641a9..126cb29f2 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/MarcxmlEntityBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/MarcxmlEntityBuilder.java @@ -126,7 +126,7 @@ protected Entity buildChildFromRecord(Type type, Entity parent, } protected Entity buildChildFromControlField(Type type, Entity parent, - MarcxmlRecord record, int tag) throws EntityBuilderException { + MarcxmlRecord record, String tag) throws EntityBuilderException { MarcxmlControlField field = record.getControlField(tag); if (field == null) { @@ -143,7 +143,7 @@ protected Entity buildChildFromControlField(Type type, Entity parent, } protected Entity buildChildFromDataField(Type type, Entity parent, - MarcxmlRecord record, int tag) throws EntityBuilderException { + MarcxmlRecord record, String tag) throws EntityBuilderException { MarcxmlDataField field = record.getDataField(tag); if (field == null) { diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AdminMetadataBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AdminMetadataBuilder.java index c0f577e2f..2490e1ac7 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AdminMetadataBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AdminMetadataBuilder.java @@ -39,7 +39,7 @@ public Entity build(BuildParams params) throws EntityBuilderException { // Control field 001: local identifier buildChildFromControlField( - Ld4lIdentifierType.superClass(), adminMetadata, record, 1); + Ld4lIdentifierType.superClass(), adminMetadata, record, "001"); convert_040(); @@ -80,7 +80,7 @@ private void parseBuildParams(BuildParams params) private void convert_040() throws EntityBuilderException { - MarcxmlDataField field = record.getDataField(40); + MarcxmlDataField field = record.getDataField("040"); if (field == null) { return; @@ -176,7 +176,7 @@ private void addDescriptionConventions(MarcxmlDataField field) private void convert_005() throws EntityBuilderException { - MarcxmlControlField field_005 = record.getControlField(5); + MarcxmlControlField field_005 = record.getControlField("005"); if (field_005 == null) { return; diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AgentBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AgentBuilder.java index d5529d92b..662d69a25 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AgentBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/AgentBuilder.java @@ -7,7 +7,6 @@ import org.ld4l.bib2lod.entitybuilders.BuildParams; import org.ld4l.bib2lod.ontology.ObjectProp; import org.ld4l.bib2lod.ontology.Type; -import org.ld4l.bib2lod.ontology.ld4l.Ld4lActivityType; import org.ld4l.bib2lod.ontology.ld4l.Ld4lAgentType; import org.ld4l.bib2lod.ontology.ld4l.Ld4lDatatypeProp; import org.ld4l.bib2lod.ontology.ld4l.Ld4lObjectProp; diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilder.java index 1d7d1b218..2e8b7828f 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilder.java @@ -141,7 +141,7 @@ private Entity build(MarcxmlControlField field) { Entity identifier = null; - if (field.getTag() == 1) { + if (field.getTag().equals("001")) { identifier = buildFromTextField(Ld4lIdentifierType.LOCAL, Ld4lDatatypeProp.VALUE, field); } @@ -161,7 +161,7 @@ private Entity build(MarcxmlDataField field, BuildParams params) MarcxmlSubfield subfield = (MarcxmlSubfield) params.getSubfields().get(0); - if (field.getTag() == 35) { + if (field.getTag().equals("035")) { identifier = convert_035(subfield); } diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/InstanceBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/InstanceBuilder.java index 9340f7f2c..08a1cc518 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/InstanceBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/InstanceBuilder.java @@ -88,7 +88,7 @@ private void buildIdentifiers() throws EntityBuilderException { private void convert_035() throws EntityBuilderException { // 035 is a repeating field - List fields = record.getDataFields(35); + List fields = record.getDataFields("035"); if (fields.isEmpty()) { return; } @@ -127,7 +127,7 @@ private void buildPhysicalDescriptions() throws EntityBuilderException { private void buildExtent() throws EntityBuilderException { // 300 - List fields = record.getDataFields(300); + List fields = record.getDataFields("300"); if (fields.size() == 0) { return; @@ -187,12 +187,12 @@ private void buildPublisherActivities() throws EntityBuilderException { .setRecord(record); // First build current publisher activity from mandatory 008. - builder.build(params.setField(record.getControlField(8))); + builder.build(params.setField(record.getControlField("008"))); // 260 fields: build additional publisher activities and add data to // current publisher activity from 008. List publisherCodes = Arrays.asList('a', 'b', 'c'); - for (MarcxmlDataField field : record.getDataFields(260)) { + for (MarcxmlDataField field : record.getDataFields("260")) { params.setField(field); List> subfieldLists = ProviderActivityBuilder. getActivitySubfields(field, publisherCodes); @@ -208,15 +208,15 @@ private void buildProvisionActivityStatements() { // Each 260 and 264 yields one statement from all $a$b$c concatenated. buildProvisionActivityStatements( - Arrays.asList(260, 264), Arrays.asList('a', 'b', 'c')); + Arrays.asList("260", "264"), Arrays.asList('a', 'b', 'c')); // Each 260 yields one statement from all $e$f$g concatenated. buildProvisionActivityStatements( - Arrays.asList(260), Arrays.asList('e', 'f', 'g')); + Arrays.asList("260"), Arrays.asList('e', 'f', 'g')); } private void buildProvisionActivityStatements( - List tags, List codes) { + List tags, List codes) { for (MarcxmlDataField field : record.getDataFields(tags)) { @@ -246,7 +246,7 @@ private void buildManufacturerActivities() throws EntityBuilderException { // Build manufacturer activities from 260$e$f$g List manufacturerCodes = Arrays.asList('e', 'f', 'g'); - for (MarcxmlDataField field : record.getDataFields(260)) { + for (MarcxmlDataField field : record.getDataFields("260")) { params.setField(field); List> subfieldLists = ProviderActivityBuilder.getActivitySubfields( @@ -269,7 +269,7 @@ private void buildProviderActivities() throws EntityBuilderException { */ private void buildResponsiblityStatement() { - MarcxmlDataField field = record.getDataField(245); + MarcxmlDataField field = record.getDataField("245"); if (field == null) { return; } diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/PhysicalDescriptionBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/PhysicalDescriptionBuilder.java index 90d236125..b41dc1b4a 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/PhysicalDescriptionBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/PhysicalDescriptionBuilder.java @@ -52,7 +52,7 @@ private void parseBuildParams(BuildParams params) private Entity convertByField() { switch (field.getTag()) { - case 300: + case "300": return convert_300(); default: return null; diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/TitleBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/TitleBuilder.java index 1cf1ef53f..71c54046d 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/TitleBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/TitleBuilder.java @@ -98,9 +98,9 @@ private void buildTitleElements() throws EntityBuilderException { titleElements = new ArrayList<>(); // Note that every record must have a 245 - MarcxmlDataField field245 = record.getDataField(245); + MarcxmlDataField field_245 = record.getDataField("245"); - for (MarcxmlSubfield subfield : field245.getSubfields()) { + for (MarcxmlSubfield subfield : field_245.getSubfields()) { char code = subfield.getCode(); @@ -108,7 +108,7 @@ private void buildTitleElements() throws EntityBuilderException { // 245$a always stores the full title. If 130 and/or 240 are // present,the $a fields should be the same. case 'a': - addNonSortAndMainTitleElements(field245, subfield); + addNonSortAndMainTitleElements(field_245, subfield); break; case 'b': addSubtitleElements(subfield); diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/WorkBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/WorkBuilder.java index a559fe4dd..cfcd85542 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/WorkBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/WorkBuilder.java @@ -109,8 +109,8 @@ private void addLanguages() { /* TODO Codes not the same between lexvo and lc. Just use lc URIs for now. */ // Language from 008 - MarcxmlControlField field008 = record.getControlField(8); - String code = field008.getTextSubstring(35,38); + MarcxmlControlField field_008 = record.getControlField("008"); + String code = field_008.getTextSubstring(35,38); if (code != null && code.length() > 0) { // Lexvo iso639-3 codes are not completely identical with LC work.addExternalRelationship(Ld4lObjectProp.HAS_LANGUAGE, diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/ManufacturerActivityBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/ManufacturerActivityBuilder.java index 830709e23..241bce0c0 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/ManufacturerActivityBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/ManufacturerActivityBuilder.java @@ -20,7 +20,7 @@ public void build() throws EntityBuilderException { this.type = TYPE; // Not sure if any other tags apply - if (field.getTag() == 260) { + if (field.getTag().equals("260")) { convert_260(); } } diff --git a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/PublisherActivityBuilder.java b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/PublisherActivityBuilder.java index 8e5678a13..346d5b741 100644 --- a/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/PublisherActivityBuilder.java +++ b/src/main/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/activities/PublisherActivityBuilder.java @@ -28,9 +28,9 @@ public void build() throws EntityBuilderException { this.type = TYPE; - if (field.getTag() == 8) { + if (field.getTag().equals("008")) { convert_008(); - } else if (field.getTag() == 260) { + } else if (field.getTag().equals("260")) { convert_260(); } } @@ -74,7 +74,7 @@ private void convert_260() // First indicator == 3 if ( (ind1 != null && ind1 == 3) || // This is the only 260 - record.getDataFields(260).size() == 1) { + record.getDataFields("260").size() == 1) { activity.addExternalRelationship(Ld4lObjectProp.HAS_STATUS, Ld4lNamedIndividual.CURRENT); } diff --git a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlControlField.java b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlControlField.java index 75df6748b..62fe3b7a7 100644 --- a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlControlField.java +++ b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlControlField.java @@ -2,6 +2,7 @@ package org.ld4l.bib2lod.records.xml.marcxml; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ld4l.bib2lod.records.xml.XmlTextElement; @@ -17,7 +18,7 @@ public class MarcxmlControlField extends BaseMarcxmlField private static final Logger LOGGER = LogManager.getLogger(); private static final String CONTROL_NUMBER_ATTRIBUTE_NAME = "tag"; - private Integer tag; + private String tag; private String textValue; @@ -26,14 +27,9 @@ public class MarcxmlControlField extends BaseMarcxmlField */ public MarcxmlControlField(Element element) throws RecordFieldException { super(element); - try { - tag = Integer.parseInt( - element.getAttribute(CONTROL_NUMBER_ATTRIBUTE_NAME)); - textValue = retrieveTextValue(this.element); - isValid(); - } catch (NumberFormatException e) { - throw new RecordFieldException("Control number is not an integer."); - } + tag = element.getAttribute(CONTROL_NUMBER_ATTRIBUTE_NAME); + textValue = retrieveTextValue(this.element); + isValid(); } static String getControlNumberAttributeName() { @@ -43,12 +39,12 @@ static String getControlNumberAttributeName() { /** * Alias of getTag(). */ - public int getControlNumber() { + public String getControlNumber() { return tag; } @Override - public int getTag() { + public String getTag() { return tag; } @@ -59,22 +55,29 @@ public String getTextValue() { private void isValid() throws RecordFieldException { - if (tag == null) { - throw new RecordFieldException("Control number is null."); - } - if (! (tag > 0 && tag < 10)) { - throw new RecordFieldException( - "Control number is not between 1 and 9."); - } - if (textValue == null) { - throw new RecordFieldException("Text value is null."); + if (StringUtils.isBlank(tag)) { + throw new RecordFieldException("Control number must be non-empty."); } - if (textValue.isEmpty()) { - throw new RecordFieldException("Text value is empty."); - } - if (tag == 8 && textValue.length() != 40) { - throw new RecordFieldException( - "Control field 008 does not contain exactly 40 characters."); + + try { + int tagValue = Integer.parseInt(tag); + + if (! (tagValue > 0 && tagValue < 10)) { + throw new RecordFieldException( + "Control number is not between 1 and 9."); + } + if (textValue == null) { + throw new RecordFieldException("Text value is null."); + } + if (textValue.isEmpty()) { + throw new RecordFieldException("Text value is empty."); + } + if (tagValue == 8 && textValue.length() != 40) { + throw new RecordFieldException("Control field 008 does not " + + "contain exactly 40 characters."); + } + } catch (NumberFormatException e) { + throw new RecordFieldException("Control number must be numeric"); } } diff --git a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlDataField.java b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlDataField.java index 4ab142983..fbc1b2acd 100644 --- a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlDataField.java +++ b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlDataField.java @@ -29,7 +29,7 @@ public class MarcxmlDataField extends BaseMarcxmlField @SuppressWarnings("unused") private static final Logger LOGGER = LogManager.getLogger(); - private Integer tag; + private String tag; private Integer ind1; private Integer ind2; private List subfields; @@ -41,13 +41,8 @@ public class MarcxmlDataField extends BaseMarcxmlField public MarcxmlDataField(Element element) throws RecordFieldException { super(element); - - try { - tag = Integer.parseInt(element.getAttribute("tag")); - } catch (NumberFormatException e) { - throw new RecordFieldException("Tag value is not an integer."); - } + this.tag = element.getAttribute("tag"); this.ind1 = getIndicatorValue("ind1", element); this.ind2 = getIndicatorValue("ind2", element); @@ -127,7 +122,7 @@ private Integer getIndicatorValue(String ind, Element element) { } @Override - public int getTag() { + public String getTag() { return tag; } @@ -246,10 +241,10 @@ public boolean containsAnySubfield(Character[] codes) { * Returns the first if multiple are found. Returns null if none are found. */ public static MarcxmlDataField get( - List fields, int tag) { + List fields, String tag) { for (MarcxmlDataField field: fields) { - if (field.getTag() == tag) { + if (field.getTag().equals(tag)) { return field; } } @@ -258,12 +253,12 @@ public static MarcxmlDataField get( private void isValid() throws RecordFieldException { - if (tag == null) { - throw new RecordFieldException("Tag is null."); + if (StringUtils.isBlank(tag)) { + throw new RecordFieldException("Tag must be non-empty."); } - if (! (tag > 0 && tag < 1000) ) { + if (tag.length() != 3) { throw new RecordFieldException( - "Tag value is not between 1 and 999."); + "Tag must be exactly 3 characters long."); } /* * Bad test: when pretty-printed there is whitespace inside the element. @@ -274,7 +269,7 @@ private void isValid() throws RecordFieldException { if (subfields.isEmpty()) { throw new RecordFieldException("field has no subfields"); } - if (tag == 245) { + if (tag.equals("245")) { if (! ( hasSubfield('a') || hasSubfield('k') ) ) { throw new RecordFieldException( "Subfield $a or $k required for field 245."); diff --git a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlRecord.java b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlRecord.java index 9c36eaefb..38032e560 100644 --- a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlRecord.java +++ b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlRecord.java @@ -138,14 +138,14 @@ private void checkLeader() throws RecordException { private void checkRequiredControlFields() throws RecordException { - if (! hasControlField(8)) { + if (! hasControlField("008")) { throw new RecordException("Record has no 008 control field."); } } private void checkRequiredDataFields() throws RecordException { - if (! hasDataField(245)) { + if (! hasDataField("245")) { throw new RecordException("Record has no 245 data field."); } } @@ -171,10 +171,10 @@ public List getControlFields() { * tag is found. * @param String tag - the value of the tag attribute */ - public MarcxmlControlField getControlField(int controlNumber) { + public MarcxmlControlField getControlField(String string) { for (MarcxmlControlField controlField : controlFields) { - if (controlField.getControlNumber() == controlNumber) { + if (controlField.getControlNumber().equals(string)) { return controlField; } } @@ -184,8 +184,8 @@ public MarcxmlControlField getControlField(int controlNumber) { /** * Returns true iff the Record has the specified control field */ - public boolean hasControlField(int controlNumber) { - return getControlField(controlNumber) != null; + public boolean hasControlField(String string) { + return getControlField(string) != null; } /** @@ -200,23 +200,23 @@ public List getDataFields() { * Use with repeating datafields. Returns an empty List if none are found. * @param String tag - the value of the tag attribute */ - public List getDataFields(int tag) { + public List getDataFields(String tag) { List fields = new ArrayList(); for (MarcxmlDataField field : dataFields) { - if (field.getTag() == tag) { + if (field.getTag().equals(tag)) { fields.add(field); } } return fields; } - public List getDataFields(List tags) { + public List getDataFields(List tags) { List fields = new ArrayList(); - for (int tag : tags) { + for (String tag : tags) { fields.addAll(getDataFields(tag)); } @@ -229,10 +229,10 @@ public List getDataFields(List tags) { * Returns null if no data field is found. * @param String tag - the value of the tag attribute */ - public MarcxmlDataField getDataField(int tag) { + public MarcxmlDataField getDataField(String tag) { for (MarcxmlDataField field : dataFields) { - if (field.getTag() == tag) { + if (field.getTag().equals(tag)) { return field; } } @@ -242,7 +242,7 @@ public MarcxmlDataField getDataField(int tag) { /** * Returns true iff the Record has the specified data field. */ - public boolean hasDataField(int tag) { + public boolean hasDataField(String tag) { return getDataField(tag) != null; } @@ -251,10 +251,10 @@ public boolean hasDataField(int tag) { * Returns null if no field is found. * @throws RecordFieldException */ - public MarcxmlTaggedField getTaggedField(int tag) throws RecordFieldException { + public MarcxmlTaggedField getTaggedField(String tag) throws RecordFieldException { List fields = getTaggedFields(); for (MarcxmlTaggedField field : fields) { - if (field.getTag() == tag) { + if (field.getTag().equals(tag)) { return field; } } diff --git a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlTaggedField.java b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlTaggedField.java index 3e414976f..0186667cf 100644 --- a/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlTaggedField.java +++ b/src/main/java/org/ld4l/bib2lod/records/xml/marcxml/MarcxmlTaggedField.java @@ -8,7 +8,7 @@ */ public interface MarcxmlTaggedField extends RecordField { - public int getTag(); + public String getTag(); } diff --git a/src/test/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilderTest.java b/src/test/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilderTest.java index 2da174d8a..65742015e 100644 --- a/src/test/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilderTest.java +++ b/src/test/java/org/ld4l/bib2lod/entitybuilders/marcxml/ld4l/IdentifierBuilderTest.java @@ -115,32 +115,32 @@ public void nullField_ThrowsException() throws Exception { @Test public void invalidSubfieldCode_ThrowsException() throws Exception { buildAndExpectException( - _035_INVALID_SUBFIELD_CODE, 35, 'b', "Invalid subfield"); + _035_INVALID_SUBFIELD_CODE, "035", 'b', "Invalid subfield"); } @Test public void invalidValue_035_ThrowsException() throws Exception { buildAndExpectException( - _035_INVALID_VALUE, 35, 'a', "Invalid value for field"); + _035_INVALID_VALUE, "035", 'a', "Invalid value for field"); } @Test public void testStatusCancelled_035() throws Exception { - Entity identifier = buildIdentifier(_035_CANCELLED, 35, 'z'); + Entity identifier = buildIdentifier(_035_CANCELLED, "035", 'z'); Assert.assertEquals(Ld4lNamedIndividual.CANCELLED.uri(), identifier.getExternal(Ld4lObjectProp.HAS_STATUS)); } @Test public void test_001() throws Exception { - Entity identifier = buildIdentifier(_001, 1); + Entity identifier = buildIdentifier(_001, "001"); Assert.assertEquals("102063", identifier.getValue(Ld4lDatatypeProp.VALUE)); } @Test public void testOrgCode_035() throws Exception { - Entity identifier = buildIdentifier(_035_NIC, 35, 'a'); + Entity identifier = buildIdentifier(_035_NIC, "035", 'a'); Entity source = identifier.getChild(Ld4lObjectProp.HAS_SOURCE); Attribute attribute = source.getAttribute(Ld4lDatatypeProp.LABEL); Literal literal = ResourceFactory.createTypedLiteral( @@ -168,7 +168,7 @@ public void testDuplicateIdentifiers_001_035() throws Exception { @Test public void testNewOrgCode_035() throws Exception { - Entity identifier = buildIdentifier(_035_NEW_ORG_CODE, 35, 'a'); + Entity identifier = buildIdentifier(_035_NEW_ORG_CODE, "035", 'a'); Entity source = identifier.getChild(Ld4lObjectProp.HAS_SOURCE); Attribute attribute = source.getAttribute(Ld4lDatatypeProp.LABEL); Literal literal = ResourceFactory.createTypedLiteral( @@ -178,7 +178,7 @@ public void testNewOrgCode_035() throws Exception { @Test public void testNewKeyAddedToSources_035() throws Exception { - buildIdentifier(_035_NEW_ORG_CODE, 35, 'a'); + buildIdentifier(_035_NEW_ORG_CODE, "035", 'a'); Map sources = IdentifierBuilder.getSources(); Assert.assertTrue(sources.containsKey("ABC")); @@ -186,7 +186,7 @@ public void testNewKeyAddedToSources_035() throws Exception { @Test public void testNewSourceAddedToSources_035() throws Exception { - buildIdentifier(_035_NEW_ORG_CODE, 35, 'a'); + buildIdentifier(_035_NEW_ORG_CODE, "035", 'a'); Map sources = IdentifierBuilder.getSources(); Entity source = sources.get("ABC"); @@ -198,13 +198,13 @@ public void testNewSourceAddedToSources_035() throws Exception { @Test public void testNoSource_035() throws Exception { - Entity identifier = buildIdentifier(_035_NO_ORG_CODE, 35, 'a'); + Entity identifier = buildIdentifier(_035_NO_ORG_CODE, "035", 'a'); Assert.assertNull(identifier.getChild(Ld4lObjectProp.HAS_SOURCE)); } @Test public void testValueWithNoSource_035() throws Exception { - Entity identifier = buildIdentifier(_035_NO_ORG_CODE, 35, 'a'); + Entity identifier = buildIdentifier(_035_NO_ORG_CODE, "035", 'a'); Assert.assertEquals("1345399", identifier.getValue(Ld4lDatatypeProp.VALUE)); } @@ -214,7 +214,7 @@ public void testValueWithNoSource_035() throws Exception { // --------------------------------------------------------------------- private Entity buildIdentifier( - Entity entity, MockMarcxml input, int tag) throws Exception { + Entity entity, MockMarcxml input, String tag) throws Exception { MarcxmlRecord record = input.toRecord(); MarcxmlTaggedField field = record.getTaggedField(tag); @@ -225,13 +225,13 @@ private Entity buildIdentifier( return builder.build(params); } - private Entity buildIdentifier(MockMarcxml input, int tag) + private Entity buildIdentifier(MockMarcxml input, String tag) throws Exception { return buildIdentifier(new Entity(), input, tag); } private Entity buildIdentifier(Entity entity, MockMarcxml input, - int tag, char code) throws Exception { + String tag, char code) throws Exception { MarcxmlRecord record = input.toRecord(); MarcxmlDataField field = record.getDataField(tag); MarcxmlSubfield subfield = field.getSubfield(code); @@ -244,32 +244,32 @@ private Entity buildIdentifier(Entity entity, MockMarcxml input, } private Entity buildIdentifier(MockMarcxml input, - int tag, char code) throws Exception { + String tag, char code) throws Exception { return buildIdentifier(new Entity(), input, tag, code); } private void buildAndExpectException( - Entity entity, MockMarcxml input, int tag, String error) + Entity entity, MockMarcxml input, String tag, String error) throws Exception { expectException(EntityBuilderException.class, error); buildIdentifier(entity, input, tag); } @SuppressWarnings("unused") - private void buildAndExpectException(MockMarcxml input, int tag, String error) - throws Exception { + private void buildAndExpectException(MockMarcxml input, String tag, + String error) throws Exception { buildAndExpectException(new Entity(), input, tag, error); } - private void buildAndExpectException( - Entity entity, MockMarcxml input, int tag, char code, String error) + private void buildAndExpectException(Entity entity, MockMarcxml input, + String tag, char code, String error) throws Exception { expectException(EntityBuilderException.class, error); buildIdentifier(entity, input, tag, code); } - private void buildAndExpectException( - MockMarcxml input, int tag, char code, String error) throws Exception { + private void buildAndExpectException(MockMarcxml input, String tag, + char code, String error) throws Exception { buildAndExpectException(new Entity(), input, tag, code, error); } diff --git a/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlControlFieldTest.java b/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlControlFieldTest.java index a1620df8c..d25f71f4d 100644 --- a/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlControlFieldTest.java +++ b/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlControlFieldTest.java @@ -46,25 +46,26 @@ public class MarcxmlControlFieldTest extends AbstractTestClass { @Test public void noControlNumber_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "not an integer"); + expectException(RecordFieldException.class, "must be non-empty"); buildFromString(NO_CONTROL_NUMBER); } @Test public void emptyControlNumber_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "not an integer"); + expectException(RecordFieldException.class, "must be non-empty"); buildFromString(EMPTY_CONTROL_NUMBER); } @Test public void blankControlNumber_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "not an integer"); + expectException(RecordFieldException.class, "must be non-empty"); buildFromString(BLANK_CONTROL_NUMBER); } @Test public void invalidControlNumber_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "Control number is not between 1 and 9"); + expectException(RecordFieldException.class, + "Control number is not between 1 and 9"); buildFromString(INVALID_CONTROL_NUMBER); } diff --git a/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlDataFieldTest.java b/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlDataFieldTest.java index 6f10fb7de..2be1a5246 100644 --- a/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlDataFieldTest.java +++ b/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlDataFieldTest.java @@ -97,26 +97,26 @@ public class MarcxmlDataFieldTest extends AbstractTestClass { @Test public void noTag_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "not an integer"); + expectException(RecordFieldException.class, "must be non-empty"); buildFromString(NO_TAG); } @Test public void emptyTag_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "not an integer"); + expectException(RecordFieldException.class, "must be non-empty"); buildFromString(EMPTY_TAG); } @Test public void blankTag_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "not an integer"); + expectException(RecordFieldException.class, "must be non-empty"); buildFromString(BLANK_TAG); } @Test public void invalidTag_ThrowsException() throws Exception { expectException(RecordFieldException.class, - "value is not between 1 and 999"); + "must be exactly 3 characters long"); buildFromString(INVALID_TAG); } @@ -140,7 +140,8 @@ public void invalidSubfield_ThrowsException() throws Exception { @Test public void invalidField245_ThrowsException() throws Exception { - expectException(RecordFieldException.class, "required for field 245"); + expectException( + RecordFieldException.class, "required for field 245"); buildFromString(INVALID_FIELD_245); } diff --git a/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlRecordTest.java b/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlRecordTest.java index 086a28a4e..a9f9e853c 100644 --- a/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlRecordTest.java +++ b/src/test/java/org/ld4l/bib2lod/record/xml/marcxml/MarcxmlRecordTest.java @@ -117,7 +117,7 @@ public void duplicateNonRepeatingControlFields_Ignored() throws Exception { List fields = record.getControlFields(); int fieldCount = 0; for (MarcxmlControlField field : fields) { - if (field.getControlNumber() == 8) { + if (field.getControlNumber().equals("008")) { fieldCount++; } }