Skip to content

Commit ba2eb8c

Browse files
authored
Merge pull request #132 from E-ARK-Software/fix/CSIP1
Validating package name - CSIP1
2 parents 00d7357 + 361b382 commit ba2eb8c

5 files changed

Lines changed: 18 additions & 11 deletions

File tree

eark_validator/ipxml/resources/schematron/V2.0.4/CSIP/mets_metsRootElement_rules.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<assert test="mets:mets">CSIP1000;ERROR;The mets root element is mandatory.</assert>
88
</rule>
99
<rule context="/mets:mets">
10-
<assert test="@OBJID != ''">CSIP1;ERROR;The mets/@OBJID attribute is mandatory, its value is a string identifier for the METS document. For the package METS document, this should be the name/ID of the package, i.e. the name of the package root folder. For a representation level METS document this value records the name/ID of the representation, i.e. the name of the top-level representation folder.</assert>
10+
<assert test="@OBJID_test">CSIP1;ERROR;The mets/@OBJID attribute is mandatory, its value is a string identifier for the METS document. For the package METS document, this should be the name/ID of the package, i.e. the name of the package root folder. For a representation level METS document this value records the name/ID of the representation, i.e. the name of the top-level representation folder.</assert>
1111
<assert test="(@TYPE_vocabulary_test) and (@TYPE != 'Other' or (@TYPE = 'Other' and @csip:OTHERTYPE != ''))">CSIP2;ERROR;The mets/@TYPE attibute MUST be used to declare the category of the content held in the package, e.g. book, journal, stereograph, video, etc.. Legal values are defined in a fixed vocabulary.</assert>
1212
<assert test="(@TYPE = 'Other' and @csip:OTHERTYPE) or @TYPE != 'Other'">CSIP3;WARN;When the `mets/@TYPE` attribute has the value "Other" the `mets/@csip:OTHERTYPE` attribute MUST be used to declare the content category of the package/representation. The value can either be "Other" or any other string that are not present in the vocabulary used in the `mets/@TYPE` attribute.</assert>
1313
<assert test="(@csip:CONTENTINFORMATIONTYPE_vocabulary_test) and (@csip:CONTENTINFORMATIONTYPE != 'OTHER' or (@csip:CONTENTINFORMATIONTYPE = 'OTHER' and @csip:OTHERCONTENTINFORMATIONTYPE != ''))">CSIP4;ERROR;Used to declare the Content Information Type Specification used when creating the package. Legal values are defined in a fixed vocabulary. The attribute is mandatory for representation level METS documents.</assert>

eark_validator/ipxml/resources/schematron/V2.1.0/CSIP/mets_metsRootElement_rules.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<assert test="mets:mets">CSIP1000;ERROR;The mets root element is mandatory.</assert>
88
</rule>
99
<rule context="/mets:mets">
10-
<assert test="@OBJID != ''">CSIP1;ERROR;The mets/@OBJID attribute is mandatory, its value is a string identifier for the METS document. For the package METS document, this should be the name/ID of the package, i.e. the name of the package root folder. For a representation level METS document this value records the name/ID of the representation, i.e. the name of the top-level representation folder.</assert>
10+
<assert test="@OBJID_test">CSIP1;ERROR;The mets/@OBJID attribute is mandatory, its value is a string identifier for the METS document. For the package METS document, this should be the name/ID of the package, i.e. the name of the package root folder. For a representation level METS document this value records the name/ID of the representation, i.e. the name of the top-level representation folder.</assert>
1111
<assert test="(@TYPE_vocabulary_test) and (@TYPE != 'Other' or (@TYPE = 'Other' and @csip:OTHERTYPE != ''))">CSIP2;ERROR;The `mets/@TYPE` attribute MUST be used to declare the category of the content held in the package, e.g. "Datasets", "Websites", "Mixes" , "Other", etc.. Legal values are defined in a fixed vocabulary. When the content category used falls outside of the defined vocabulary the `mets/@TYPE` value must be set to "Other" and the specific value declared in `mets/@csip:OTHERTYPE`. The vocabulary will develop under the curation of the DILCIS Board as additional content information type specifications are produced.</assert>
1212
<assert test="(@TYPE = 'Other' and @csip:OTHERTYPE) or @TYPE != 'Other'">CSIP3;WARN;When the `mets/@TYPE` attribute has the value "Other" the `mets/@csip:OTHERTYPE` attribute MUST be used to declare the content category of the package/representation. The value can either be "Other" or any other string that are not present in the vocabulary used in the `mets/@TYPE` attribute.</assert>
1313
<assert test="(@csip:CONTENTINFORMATIONTYPE_vocabulary_test) and (@csip:CONTENTINFORMATIONTYPE != 'OTHER' or (@csip:CONTENTINFORMATIONTYPE = 'OTHER' and @csip:OTHERCONTENTINFORMATIONTYPE != ''))">CSIP4;ERROR;Used to declare the Content Information Type Specification used when creating the package. Legal values are defined in a fixed vocabulary. The attribute is mandatory for representation level METS documents.</assert>

eark_validator/ipxml/schematron.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ class SchematronTests():
5151

5252
tests = {}
5353

54-
def __init__(self):
54+
def __init__(self, to_validate: Optional[Path]):
5555
for attribute, vocabulary_uri in self.__vocabulary_definitions.items():
56-
self.tests[attribute + '_vocabulary_test'] = self.__create_vocabulary_test(attribute, vocabulary_uri)
56+
self.tests[attribute + '_vocabulary_test'] = self._create_vocabulary_test(attribute, vocabulary_uri)
5757

58-
def __create_vocabulary_test(self, attribute: str, vocabulary_uri: str) -> str:
58+
self.tests['@OBJID_test'] = self._create_OBJID_test(to_validate)
59+
60+
def _create_vocabulary_test(self, attribute: str, vocabulary_uri: str) -> str:
5961
vocabulary_tests = []
6062
for line_bytes in urlopen(vocabulary_uri):
6163
line = line_bytes.decode('utf-8')
@@ -70,17 +72,21 @@ def __create_vocabulary_test(self, attribute: str, vocabulary_uri: str) -> str:
7072

7173
return ' or '.join(vocabulary_tests)
7274

73-
schematron_tests = SchematronTests()
75+
def _create_OBJID_test(self, to_validate: Optional[Path]):
76+
if to_validate:
77+
return f"(@OBJID = '{to_validate.stem}')"
78+
return "(@OBJID != '')"
7479

7580
class SchematronRuleset():
7681
"""Encapsulates a set of Schematron rules loaded from a file."""
77-
def __init__(self, sch_path: str=None):
82+
def __init__(self, sch_path: str=None, to_validate: Path=None):
7883
if not os.path.exists(sch_path):
7984
raise FileNotFoundError(NO_PATH.format(sch_path))
8085
if not os.path.isfile(sch_path):
8186
raise ValueError(NOT_FILE.format(sch_path))
8287
self._path = sch_path
8388

89+
schematron_tests = SchematronTests(to_validate)
8490
try:
8591
with open(sch_path) as schematron_file:
8692
schematron_data = schematron_file.read()

eark_validator/packages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def validate(cls, version: SpecificationVersion, to_validate: Path) -> Validatio
102102
'metadata': metadata
103103
})
104104

105-
csip_profile = SC.ValidationProfile(SpecificationType.CSIP, version)
105+
csip_profile = SC.ValidationProfile(SpecificationType.CSIP, version, to_validate)
106106
csip_profile.validate(to_validate.joinpath(METS))
107107
results = csip_profile.get_all_results()
108108

109109
package: InformationPackage = InformationPackages.from_path(to_validate)
110110
if package.details.oaispackagetype in ['SIP', 'DIP']:
111-
profile = SC.ValidationProfile(SpecificationType.from_string(package.details.oaispackagetype), version)
111+
profile = SC.ValidationProfile(SpecificationType.from_string(package.details.oaispackagetype), version, to_validate)
112112
profile.validate(to_validate.joinpath(METS))
113113
results.extend(profile.get_all_results())
114114

eark_validator/rules.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
from eark_validator.specifications.specification import EarkSpecification, Specification, SpecificationType, SpecificationVersion
3434
from eark_validator.const import NO_PATH, NOT_FILE
3535
from eark_validator.model import Severity
36+
from pathlib import Path
3637

3738
class ValidationProfile():
3839
""" A complete set of Schematron rule sets that comprise a complete validation profile."""
39-
def __init__(self, type: SpecificationType, version: SpecificationVersion):
40+
def __init__(self, type: SpecificationType, version: SpecificationVersion, to_validate: Path = None):
4041
specification: Specification = EarkSpecification(type, version).specification
4142

4243
self._rulesets: Dict[str, SchematronRuleset] = {}
@@ -46,7 +47,7 @@ def __init__(self, type: SpecificationType, version: SpecificationVersion):
4647
self.results: Dict[str, List[Result]] = {}
4748
self.messages: List[str] = []
4849
for section in specification.sections:
49-
self.rulesets[section] = SchematronRuleset(get_schematron_path(version, specification.id, section))
50+
self.rulesets[section] = SchematronRuleset(get_schematron_path(version, specification.id, section), to_validate)
5051

5152
@property
5253
def specification(self) -> Specification:

0 commit comments

Comments
 (0)