Skip to content

Commit 5fee2f4

Browse files
committed
Entrytitle - Revised #325
1 parent 85ccd62 commit 5fee2f4

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

pyQuARC/code/schema_validator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44

55
from io import BytesIO
6-
from jsonschema import Draft7Validator, draft7_format_checker, RefResolver
6+
from jsonschema import Draft7Validator, RefResolver
77
from lxml import etree
88
from urllib.request import pathname2url
99

@@ -91,7 +91,8 @@ def run_json_validator(self, content_to_validate):
9191
resolver = RefResolver.from_schema(schema, store=schema_store)
9292

9393
validator = Draft7Validator(
94-
schema, format_checker=draft7_format_checker, resolver=resolver
94+
schema,
95+
format_checker=Draft7Validator.FORMAT_CHECKER, resolver=resolver
9596
)
9697

9798
for error in sorted(
@@ -136,13 +137,13 @@ def _build_errors(error_log, paths):
136137
# For DIF, because the namespace is specified in the metadata file, lxml library
137138
# provides field name concatenated with the namespace,
138139
# the following 3 lines of code removes the namespace
139-
namespaces = re.findall("(\{http[^}]*\})", line)
140+
namespaces = re.findall(r"(\{http[^}]*\})", line)
140141
for namespace in namespaces:
141142
line = line.replace(namespace, "")
142-
field_name = re.search("Element\s'(.*)':", line)[1]
143+
field_name = re.search(r"Element\s'(.*)':", line)[1]
143144
field_paths = [abs_path for abs_path in paths if field_name in abs_path]
144145
field_name = field_paths[0] if len(field_paths) == 1 else field_name
145-
message = re.search("Element\s'.+':\s(\[.*\])?(.*)", line)[2].strip()
146+
message = re.search(r"Element\s'.+':\s(\[.*\])?(.*)", line)[2].strip()
146147
errors.setdefault(field_name, {})["schema"] = {
147148
"message": [f"Error: {message}"],
148149
"valid": False,

pyQuARC/code/string_validator.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .base_validator import BaseValidator
22
from .gcmd_validator import GcmdValidator
33
from .utils import cmr_request, collection_in_cmr, if_arg, set_cmr_prms
4-
4+
import re
55

66
class StringValidator(BaseValidator):
77
"""
@@ -38,15 +38,21 @@ def length_check(string, extent, relation):
3838
def compare(first, second, relation):
3939
"""
4040
Compares two strings based on the relationship
41-
4241
Returns:
43-
(dict) An object with the validity of the check and the instance
42+
(dict) An object with the validity of the check and the instance
4443
"""
44+
45+
# Check if 'first' and 'second' contain any special characters
46+
first_clean = re.sub(r'[^a-zA-Z0-9]', '', first).upper()
47+
second_clean = re.sub(r'[^a-zA-Z0-9]', '', second).upper()
48+
49+
# If either string contains special characters, return a warning or handle as needed
4550
return {
46-
"valid": BaseValidator.compare(first.upper(), second.upper(), relation),
51+
"valid": BaseValidator.compare(first_clean, second_clean, relation),
4752
"value": (first, second),
4853
}
4954

55+
5056
@staticmethod
5157
@if_arg
5258
def controlled_keywords_check(value, keywords_list):
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
{}
1+
{
2+
"shortname_uniqueness": {
3+
"failure": "The EntryTitle/DataSetId `{}` is identical to the ShortName `{}`.",
4+
"help": {
5+
"message": "",
6+
"url": "https://wiki.earthdata.nasa.gov/display/CMR/Entry+Title"
7+
},
8+
"remediation": "Recommend providing a more descriptive title for the dataset. "
9+
}
10+
}
11+

tests/test_downloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class TestDownloader:
99
def setup_method(self):
1010
self.concept_ids = {
1111
"collection": {
12-
"real": "C1339230297-GES_DISC",
12+
"real": "C1000000042-CDDIS",
1313
"dummy": "C123456-LPDAAC_ECS",
1414
},
1515
"granule": {
16-
"real": "G1370895082-GES_DISC",
16+
"real": "G1018577631-CDDIS",
1717
"dummy": "G1000000002-CMR_PROV",
1818
},
1919
"invalid": "asdfasdf",

0 commit comments

Comments
 (0)