Skip to content

Commit

Permalink
feat(field-indicators): Use '\' instead of '#' for undefined indicato…
Browse files Browse the repository at this point in the history
…r codes

Implements: MODQM-443
  • Loading branch information
viacheslavkol committed Sep 6, 2024
1 parent 2530279 commit cb257b4
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions api/examples/response/indicatorCodeDtoCollection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ value:
updatedByUserId: 00000000-0000-0000-0000-000000000000
- id: ff0780f9-573d-46ba-8bf1-73181052f4c4
indicatorId: ff0780f9-573d-46ba-8bf1-73181052f4b5
code: '#'
label: 'Code #'
code: '\'
label: 'Code \'
scope: system
metadata:
createdDate: 2024-05-22 14:55:06
Expand Down
2 changes: 1 addition & 1 deletion api/schemas/indicatorCodeChangeDto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ properties:
code:
description: Indicator code
type: string
pattern: '[0-9a-z#]'
pattern: '[0-9a-z\\]'
label:
description: Code description
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@
"deprecated": false,
"defaultValue": true
},
"#": {
"\\": {
"id": "af66166f-f801-411e-932d-1b6d4885768e",
"code": "#",
"code": "\\",
"label": "Undefined",
"scope": "SYSTEM",
"deprecated": false,
Expand Down Expand Up @@ -800,9 +800,9 @@
"deprecated": false,
"defaultValue": true
},
"#": {
"\\": {
"id": "db30de81-f8e0-414a-9a8a-1d5afbb5f1d6",
"code": "#",
"code": "\\",
"label": "Undefined",
"scope": "SYSTEM",
"deprecated": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@
"deprecated": false,
"defaultValue": true
},
"#": {
"\\": {
"id": "a96146d9-4041-425b-a63c-94ee0d16071a",
"code": "#",
"code": "\\",
"label": "Undefined",
"scope": "SYSTEM",
"deprecated": false,
Expand Down Expand Up @@ -812,9 +812,9 @@
"deprecated": false,
"defaultValue": true
},
"#": {
"\\": {
"id": "a198da74-3e6d-490e-84d7-542a58fcc02e",
"code": "#",
"code": "\\",
"label": "Undefined",
"scope": "SYSTEM",
"deprecated": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void beforeAll() {
void getIndicatorCodes_shouldReturn200AndAllCodesForIndicator() throws Exception {
var fieldId = createLocalField("101");
var indId = createLocalIndicator(fieldId);
var code1 = localTestCode("#");
var code1 = localTestCode("\\");
var code2 = localTestCode("1");
code2.deprecated(false);
doPost(indicatorCodesPath(indId), code1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void getIndicatorCodes(@Random IndicatorCodeDto codeDto) throws Exception {
}

@ParameterizedTest
@ValueSource(strings = {"#", "5", "c"})
@ValueSource(strings = {"\\\\", "5", "c"})
void createIndicatorLocalCode_createNewLocalCode(String code, @Random IndicatorCodeDto codeDto) throws Exception {
var indicatorId = UUID.randomUUID();
codeDto.setCode(code);
Expand Down Expand Up @@ -145,7 +145,7 @@ void createIndicatorLocalCode_return400_invalidCode(String code) throws Exceptio
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errors.[*].message",
hasItem(is("A 'code' field must contain one character and can only accept "
+ "numbers 0-9, letters a-z or a '#'."))))
+ "numbers 0-9, letters a-z or a '\\'."))))
.andExpect(jsonPath("$.errors.[*].code", hasItem(is("103"))))
.andExpect(jsonPath("$.errors.[*].parameters.[*].key", hasItem(is("code"))))
.andExpect(jsonPath("$.errors.[*].parameters.[*].value", hasItem(is(code))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@ void build_givenLines_returnsArrayNode(List<String> lines, ArrayNode expected) {
private static Stream<Arguments> provideParametersForBuildTest() {
var lines1 = List.of(
"First - Simple Indicator1",
"# - Undefined",
"\\ - Undefined",
"Second - Simple Indicator2",
"# - Undefined"
"\\ - Undefined"
);
var expected1 =
newArrayNode(
newObjectNode(1, "Simple Indicator1", newArrayNode(newObjectNode("#", "Undefined"))),
newObjectNode(2, "Simple Indicator2", newArrayNode(newObjectNode("#", "Undefined")))
newObjectNode(1, "Simple Indicator1", newArrayNode(newObjectNode("\\", "Undefined"))),
newObjectNode(2, "Simple Indicator2", newArrayNode(newObjectNode("\\", "Undefined")))
);

var lines2 = List.of(
"First - Indicator With Codes",
"a - Code a",
"b - Code b",
"Second - Simple Indicator2",
"# - Undefined"
"\\ - Undefined"
);
var expected2 =
newArrayNode(
newObjectNode(1, "Indicator With Codes",
newArrayNode(newObjectNode("a", "Code a"), newObjectNode("b", "Code b"))),
newObjectNode(2, "Simple Indicator2", newArrayNode(newObjectNode("#", "Undefined")))
newObjectNode(2, "Simple Indicator2", newArrayNode(newObjectNode("\\", "Undefined")))
);

var lines3 = List.of(
"First - Simple Indicator1",
"# - Undefined",
"\\ - Undefined",
"Second - Indicator With Codes",
"a - Code a",
"b - Code b"
);
var expected3 =
newArrayNode(
newObjectNode(1, "Simple Indicator1", newArrayNode(newObjectNode("#", "Undefined"))),
newObjectNode(1, "Simple Indicator1", newArrayNode(newObjectNode("\\", "Undefined"))),
newObjectNode(2, "Indicator With Codes",
newArrayNode(newObjectNode("a", "Code a"), newObjectNode("b", "Code b")))
);
Expand All @@ -85,19 +85,19 @@ private static Stream<Arguments> provideParametersForBuildTest() {

var lines5 = List.of(
"First - Indicator [OBSOLETE]",
"# - Undefined",
"\\ - Undefined",
"First - Indicator With Codes1",
"a - Code a",
"b - Code b",
"First - Indicator [OBSOLETE]",
"# - Undefined",
"\\ - Undefined",
"Second - Indicator [OBSOLETE]",
"# - Undefined",
"\\ - Undefined",
"Second - Indicator With Codes2",
"c - Code c [OBSOLETE]",
"d - Code d",
"Second - Indicator [OBSOLETE]",
"# - Undefined"
"\\ - Undefined"
);
var expected5 =
newArrayNode(
Expand All @@ -109,13 +109,13 @@ private static Stream<Arguments> provideParametersForBuildTest() {

var lines6 = List.of(
"First - Simple Indicator1",
"# - Undefined",
"\\ - Undefined",
"Second - Indicator With Codes",
"0-9 - Code x"
);
var expected6 =
newArrayNode(
newObjectNode(1, "Simple Indicator1", newArrayNode(newObjectNode("#", "Undefined"))),
newObjectNode(1, "Simple Indicator1", newArrayNode(newObjectNode("\\", "Undefined"))),
newObjectNode(2, "Indicator With Codes", newArrayNode(IntStream.range(0, 10).boxed()
.map(num -> newObjectNode(String.valueOf(num), "Code x"))
.toArray(ObjectNode[]::new)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class Marc4jConverter implements Converter<Record, MarcRecord> {

private static final char EMPTY_SPACE_VALUE = 32;
private static final char MARC_INDICATOR_EMPTY_VALUE = '#';
private static final char MARC_INDICATOR_EMPTY_VALUE = '\\';

@Override
public MarcRecord convert(Record rec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public static boolean matches1xxTag(String tag) {
}

public static boolean matchesValidIndicator(char symbol) {
return symbol == '#' || symbol >= '0' && symbol <= '9' || symbol >= 'a' && symbol <= 'z';
return symbol == '\\' || symbol >= '0' && symbol <= '9' || symbol >= 'a' && symbol <= 'z';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ void testConvert_WhenCalled_ShouldReturnMarcRecord() {
.extracting(dataField -> dataField.reference().toString(), controlFieldExtractor(), dataFieldExtractor()
)
.containsExactlyInAnyOrder(
tuple("035[0]", "035[0]^1=#;035[0]^2=#", "035[0]$a[0]=(OCoLC)63611770"),
tuple("650[0]", "650[0]^1=#;650[0]^2=0", "650[0]$a[0]=Instrumental music"),
tuple("650[1]", "650[1]^1=#;650[1]^2=7",
tuple("035[0]", "035[0]^1=\\;035[0]^2=\\", "035[0]$a[0]=(OCoLC)63611770"),
tuple("650[0]", "650[0]^1=\\;650[0]^2=0", "650[0]$a[0]=Instrumental music"),
tuple("650[1]", "650[1]^1=\\;650[1]^2=7",
"650[1]$0[0]=(OCoLC)fst00974414 650[1]$a[0]=Instrumental music 650[1]$2[0]=fast"),
tuple("650[2]", "650[2]^1=#;650[2]^2=7",
tuple("650[2]", "650[2]^1=\\;650[2]^2=7",
"650[2]$0[0]=(OCoLC)fst01168379 650[2]$a[0]=Vocal music 650[2]$2[0]=fast"),
tuple("100[0]", "100[0]^1=0;100[0]^2=#",
tuple("100[0]", "100[0]^1=0;100[0]^2=\\",
"100[0]$0[0]=12345 100[0]$a[0]=Mozart, Wolfgang Amadeus, "
+ "100[0]$d[0]=1756-1791. 100[0]$9[0]=b9a5f035-de63-4e2c-92c2-07240c88b817"),
tuple("035[1]", "035[1]^1=#;035[1]^2=#", "035[1]$a[0]=393893"),
tuple("035[1]", "035[1]^1=\\;035[1]^2=\\", "035[1]$a[0]=393893"),
tuple("245[0]", "245[0]^1=1;245[0]^2=0",
"245[0]$a[0]=Neue Ausgabe samtlicher Werke, "
+ "245[0]$b[0]=in Verbindung mit den Mozartstadten, Augsburg, Salzburg und Wien. "
+ "245[0]$c[0]=Hrsg. von der Internationalen Stiftung Mozarteum, Salzburg."),
tuple("047[0]", "047[0]^1=#;047[0]^2=#",
tuple("047[0]", "047[0]^1=\\;047[0]^2=\\",
"047[0]$a[0]=cn 047[0]$a[1]=ct 047[0]$a[2]=co 047[0]$a[3]=df 047[0]$a[4]=dv "
+ "047[0]$a[5]=ft 047[0]$a[6]=fg 047[0]$a[7]=ms 047[0]$a[8]=mi 047[0]$a[9]=nc "
+ "047[0]$a[10]=op 047[0]$a[11]=ov 047[0]$a[12]=rq 047[0]$a[13]=sn 047[0]$a[14]=su "
+ "047[0]$a[15]=sy 047[0]$a[16]=vr 047[0]$a[17]=zz"),
tuple("010[0]", "010[0]^1=#;010[0]^2=#", "010[0]$a[0]= 2001000234 010[0]$z[0]=0001 010[0]$z[1]=0002")
tuple("010[0]", "010[0]^1=\\;010[0]^2=\\", "010[0]$a[0]= 2001000234 010[0]$z[0]=0001 010[0]$z[1]=0002")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void whenInvalid1xxValue_shouldNotValidateTag(String tag) {
}

@ParameterizedTest
@ValueSource(chars = {'#', '0', '5', '9', 'a', 'o', 'z'})
@ValueSource(chars = {'\\', '0', '5', '9', 'a', 'o', 'z'})
void whenValidIndicatorValue_shouldValidateIndicator(char indicator) {
assertTrue(MatcherUtils.matchesValidIndicator(indicator));
}

@ParameterizedTest
@ValueSource(chars = {'!', ' ', '/', '\\', 'X', 'O', 'I'})
@ValueSource(chars = {'!', ' ', '/', '#', 'X', 'O', 'I'})
void whenInvalidIndicatorValue_shouldNotValidateIndicator(char indicator) {
assertFalse(MatcherUtils.matchesValidIndicator(indicator));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void validate_whenValidIndicators_shouldReturnEmptyList() {
var fieldDefinition = getFieldDefinition();
var marcField = new MarcDataField(
Reference.forTag("tag", 0),
getIndicators('#', '#'),
getIndicators('\\', '\\'),
null);

List<ValidationError> errors = validator.validate(marcField.indicators(), fieldDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public static Stream<Arguments> undefinedIndicatorsTestSource() {
return Stream.of(
arguments('0', 's'),
arguments('s', '0'),
arguments('#', 'l'),
arguments('l', '#')
arguments('\\', 'l'),
arguments('l', '\\')
);
}

Expand All @@ -116,7 +116,7 @@ private static List<MarcIndicator> getIndicators(char ind1, char ind2) {

private static List<IndicatorCodeDto> getIndicatorCodes() {
return List.of(
new IndicatorCodeDto().code("#"),
new IndicatorCodeDto().code("\\"),
new IndicatorCodeDto().code("0"),
new IndicatorCodeDto().code("1"),
new IndicatorCodeDto().code("a"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,22 @@ private static SpecificationRuleDto enabledRule(MarcRuleCode ruleCode) {
private static List<FieldIndicatorDto> getFieldIndicatorDtoListByTag(String tag) {
return switch (tag) {
case "010", "035" -> List.of(
getFieldIndicatorDto(1, List.of("#")),
getFieldIndicatorDto(2, List.of("#")));
getFieldIndicatorDto(1, List.of("\\")),
getFieldIndicatorDto(2, List.of("\\")));
case "047" -> List.of(
getFieldIndicatorDto(1, List.of("#")),
getFieldIndicatorDto(2, List.of("#", "7")));
getFieldIndicatorDto(1, List.of("\\")),
getFieldIndicatorDto(2, List.of("\\", "7")));
case "100" -> List.of(
getFieldIndicatorDto(1, List.of("0", "1", "2", "3")),
getFieldIndicatorDto(2, List.of("#")));
getFieldIndicatorDto(2, List.of("\\")));
case "130" -> List.of(
getFieldIndicatorDto(1, List.of("#", "0", "1", "2", "3", "4", "5", "6", "7")),
getFieldIndicatorDto(2, List.of("#")));
getFieldIndicatorDto(1, List.of("\\", "0", "1", "2", "3", "4", "5", "6", "7")),
getFieldIndicatorDto(2, List.of("\\")));
case "245" -> List.of(
getFieldIndicatorDto(1, List.of("0", "1")),
getFieldIndicatorDto(2, List.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")));
case "650" -> List.of(
getFieldIndicatorDto(1, List.of("#", "0", "1", "2")),
getFieldIndicatorDto(1, List.of("\\", "0", "1", "2")),
getFieldIndicatorDto(2, List.of("0", "1", "2", "3", "4", "5", "6", "7")));
default -> null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"035": {
"ind1": "#",
"ind1": "\\",
"ind2": ".",
"subfields": [
{
Expand All @@ -25,7 +25,7 @@
{
"035": {
"ind1": "A",
"ind2": "#",
"ind2": "\\",
"subfields": [
{
"a": "symbol - 1st invalid, 2nd valid"
Expand All @@ -46,7 +46,7 @@
},
{
"047": {
"ind1": "#",
"ind1": "\\",
"ind2": "$",
"subfields": [
{
Expand Down Expand Up @@ -80,7 +80,7 @@
{
"100": {
"ind1": "0",
"ind2": "#####",
"ind2": "\\\\\\\\\\",
"subfields": [
{
"a": "Both valid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"035": {
"ind1": "0",
"ind2": "#",
"ind2": "\\",
"subfields": [
{
"a": "First and Second must be '#'"
Expand All @@ -24,7 +24,7 @@
},
{
"035": {
"ind1": "#",
"ind1": "\\",
"ind2": "1",
"subfields": [
{
Expand Down Expand Up @@ -57,7 +57,7 @@
},
{
"047": {
"ind1": "#",
"ind1": "\\",
"ind2": "a",
"subfields": [
{
Expand Down Expand Up @@ -121,8 +121,8 @@
},
{
"245": {
"ind1": "#",
"ind2": "#",
"ind1": "\\",
"ind2": "\\",
"subfields": [
{
"a": "First must be '0' or '1', Second must be from '0' to '9'"
Expand Down
Loading

0 comments on commit cb257b4

Please sign in to comment.