-
Notifications
You must be signed in to change notification settings - Fork 0
Field structure
natlibfi-arlehiko edited this page Oct 31, 2018
·
4 revisions
Check whether the configured fields have valid structure.
The configured fields don't have to present in the record but if they are they must conform to the configured structures. Exception to this rule is when the dependencies match: The configured fields must be found and match the constraints.
For validating only the presence of fields see Fields present.
Configuration is passed in as an array which has field-specific objects as elements. The objects have the following properties:
-
leader
- Type: RegExp
- Exclusiveness: Mutually exclusive with tag, valuePattern, subfields-, ind1- and ind2-properties
- Description: Leader pattern
-
tag
- Type: RegExp
- Description: Field tag pattern
-
valuePattern:
- Type: RegExp
- Exclusiveness: Mutually exclusive with leader, subfields-, ind1- and ind2-properties
- Description: Pattern to which the field's value must match against
-
ind1, ind2:
- Type: RegExp
- Description: Pattern to which the indicator must match against
- Exclusiveness: Mutually exclusive with leader and value-properties
-
strict:
- Type: Boolean
- Exclusiveness: Mutually exclusive with leader and valuePattern-properties
- Description: Only the specified subfields are allowed if set to true. Defaults to false.
-
subfields:
- Type: Object<String, Subfield> (Keys are subfield codes)
- Exclusiveness: Mutually exclusive with leader and value-properties
- Description: Subfields configuration
-
dependencies:
- Type: Array<Dependency>
- Description: Dependencies configuration
-
pattern
- Type: RegExp
- Description: Pattern to which the subfield's value must match against
-
required
- Type: Boolean
- Description: Whether the subfield is mandatory or not. Defaults to false
-
maxOccurrence
- Type: Number
- Description: Maximum number of times this subfield can occur. Defaults to unlimited if omitted. The value 0 means that the subfield cannot exist.
An object with the following properties. Defines specification for matching fields that must be present.
-
tag:
- Type: RegExp
- Description: Field tag pattern
-
ind1, ind2
- Type: RegExp
- Exclusiveness: Mutually exclusive with the value-property
- Description: Pattern to which the indicator must match against
-
valuePattern:
- Type: RegExp
- Exclusiveness: Mutually exclusive with subfields-, ind1- and ind2-properties
- Description: Pattern to which the field's value must match against
-
subfields
- Type: Object<String, RegExp>
- Mandatory: false
- Description: An object with subfield codes as keys and RegExp patterns as values. The subfield value must this pattern.
[
{
tag: /^035$/,
ind1: /^0$/,
ind2: /^1$/
},
{
tag: /^100$/,
subfields: {
a: {maxOccurrence: 1}
}
}
]
{
"fields": [
{
"tag": "001",
"value": "123456"
},
{
"tag": "035",
"ind1": "0",
"ind2": "1",
"subfields": [
{
"code": "a",
"value": "foo"
}
]
},
{
"tag": "100",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "a",
"value": "bar"
},
{
"code": "b",
"value": "fubar"
}
]
}
]
}
{
"fields": [
{
"tag": "001",
"value": "123456"
},
{
"tag": "035",
"ind1": "1",
"ind2": "1",
"subfields": [
{
"code": "a",
"value": "foo"
}
]
},
{
"tag": "100",
"subfields": [
{
"code": "a",
"value": "bar"
},
{
"code": "b",
"value": "fubar"
},
{
"code": "a",
"value": "barfoo"
}
]
}
]
}
[
{
tag: /^001$/,
valuePattern: /\d+/
},
{
tag: /^245$/,
strict: true,
subfields: {
a: {required: true, maxOccurrence: 1, pattern: /\w+/},
b: {maxOccurrence: 1, pattern: /\w+/}
}
}
]
{
"fields": [
{
"tag": "001",
"value": "123456"
},
{
"tag": "100",
"subfields": [
{
"code": "a",
"value": "bar"
}
]
},
{
"tag": "245",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "a",
"value": "foo"
},
{
"code": "b",
"value": "bar"
}
]
}
]
}
{
"fields": [
{
"tag": "001",
"value": "123456a"
},
{
"tag": "100",
"subfields": [
{
"code": "a",
"value": "bar"
}
]
},
{
"tag": "245",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "a",
"value": "foo"
},
{
"code": "b",
"value": "bar"
},
{
"code": "c",
"value": "fubar"
}
]
}
]
}
[
{
leader: /^.{6}s/,
dependencies: [
{
tag: /^773$/,
subfields: {7: /^nnas$/}
}
]
}
]
{
"leader": "63ab75sfoo122myhgh",
"fields": [
{
"tag": "001",
"value": "123456"
},
{
"tag": "245",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "a",
"value": "foo"
}
]
},
{
"tag": "773",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "7",
"value": "nnas"
},
{
"code": "w",
"value": "789101112"
}
]
}
]
}
{
"leader": "63ab75sfoo122myhgh",
"fields": [
{
"tag": "001",
"value": "123456"
},
{
"tag": "245",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "a",
"value": "foo"
}
]
},
{
"tag": "773",
"ind1": " ",
"ind2": " ",
"subfields": [
{
"code": "w",
"value": "789101112"
}
]
}
]
}