Skip to content

Commit

Permalink
issue #75: add tag local codelist for 852
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Dec 7, 2020
1 parent d73bb0a commit db643e7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SubfieldDefinition implements Serializable {
private SubfieldContentParser contentParser;
protected CodeList codeList;
private List<Code> codes;
private Map<MarcVersion, List<Code>> localCodes;
private List<String> allowedCodes;
private String codeForIndex = null;
private List<ControlSubfieldDefinition> positions;
Expand Down Expand Up @@ -98,8 +99,22 @@ public SubfieldDefinition setCodes(String... input) {
return this;
}

public SubfieldDefinition setLocalCodes(MarcVersion version, String... input) {
if (localCodes == null)
localCodes = new HashMap<>();
localCodes.put(version, new ArrayList<>());
for (int i = 0; i < input.length; i += 2) {
localCodes.get(version).add(new Code(input[i], input[i+1]));
}
return this;
}

public Code getCode(String _code) {
for (Code code : codes) {
return getCode(codes, _code);
}

public Code getCode(List<Code> _codes, String _code) {
for (Code code : _codes) {
if (code.getCode().equals(_code)) {
return code;
} else if (code.isRange() && code.getRange().isValid(_code)) {
Expand All @@ -113,6 +128,21 @@ public List<Code> getCodes() {
return codes;
}

public Map<MarcVersion, List<Code>> getLocalCodes() {
return localCodes;
}

public List<Code> getLocalCodes(MarcVersion version) {
return localCodes.getOrDefault(version, null);
}

public Code getLocalCode(MarcVersion version, String _code) {
List<Code> _codes = getLocalCodes(version);
if (_codes == null)
return null;
return getCode(_codes, _code);
}

public String getCardinalityCode() {
return cardinalityCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.gwdg.metadataqa.marc.definition.Cardinality;
import de.gwdg.metadataqa.marc.definition.DataFieldDefinition;
import de.gwdg.metadataqa.marc.definition.Indicator;
import de.gwdg.metadataqa.marc.definition.MarcVersion;
import de.gwdg.metadataqa.marc.definition.general.codelist.ClassificationSchemeSourceCodes;
import de.gwdg.metadataqa.marc.definition.general.codelist.CountryCodes;
import de.gwdg.metadataqa.marc.definition.general.codelist.OrganizationCodes;
Expand Down Expand Up @@ -112,7 +113,42 @@ private void initialize() {
getSubfield("a")
.setMqTag("location")
.setFrbrFunctions(DiscoveryIdentify, DiscoveryObtain, UseManage)
.setCompilanceLevels("M");
.setCompilanceLevels("M")
.setLocalCodes(MarcVersion.BL,
"ABP", "Aberdeen City Libraries",
"BODBL", "Bodleian Library",
"BRG", "Brighton Central Library",
"stpancras", "British Library",
"CUL", "Cambridge University Library",
"CUM", "Cumbernauld News & Kilsyth Chronicle",
"DBA", "Dumbarton District Libraries",
"bryson", "Durham University",
"HAD", "East Lothian District Libraries, Haddington",
"HAM", "Hamilton District Libraries (Hamilton Town House Library)",
"INV", "Highland Regional Library Service, Inverness",
"HUDu", "Huddersfield University Library",
"GRE", "Inverclyde District Libraries, Greenock",
"LAR", "Largs and District Historical Society",
"LOUp", "Loughton Central Library (National Jazz Archive)",
"Gp", "Mitchell Library, Glasgow",
"LV", "National Art Library (Victoria and Albert Museum)",
"NLS", "National Library of Scotland",
"NLW", "National Library of Wales",
"KIK", "Orkney Islands Library, Kirkwall",
"PER", "Perth and Kinross District Libraries (AK Bell Library, Perth)",
"Bfr", "Public Record Office for Northern Ireland",
"main", "Register of Preservation Surrogates",
"RSL", "Royal Society, London",
"Lrvc", "Royal Veterinary College, London",
"Shp", "Sheffield City Library",
"LERW", "Shetland Library, Lerwick",
"STIcrs", "Stirling Central Region School Library Service (Stirling Library Headquarters)",
"tcl", "Trinity College Dublin",
"BT", "Tweedale Press Group, Berwick-upon-Tweed",
"Bffm", "Ulster Folk and Transport Museum",
"YMI", "York Minister Library"
)
;

getSubfield("b")
.setMqTag("sublocation")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.gwdg.metadataqa.marc.definition.tags.bltags;

import de.gwdg.metadataqa.marc.DataField;
import de.gwdg.metadataqa.marc.definition.MarcVersion;
import de.gwdg.metadataqa.marc.definition.SubfieldDefinition;
import de.gwdg.metadataqa.marc.definition.tags.tags84x.Tag852;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class Tag852Test extends BLTagTest {

public Tag852Test() {
super(Tag852.getInstance());
}

@Test
public void testValidFields() {
SubfieldDefinition subfield = tag.getSubfield("a");
assertEquals(1, subfield.getLocalCodes().size());
assertEquals(32, subfield.getLocalCodes(MarcVersion.BL).size());
assertEquals("Bodleian Library", subfield.getLocalCode(MarcVersion.BL, "BODBL").getLabel());
}
}

0 comments on commit db643e7

Please sign in to comment.