Skip to content

Commit 04bd4ff

Browse files
committed
Solved bugs
1 parent 79f8723 commit 04bd4ff

File tree

6 files changed

+62
-30
lines changed

6 files changed

+62
-30
lines changed

bam_masterdata/checker/masterdata_validator.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def _validate_model(self, model: dict) -> dict:
120120
# Collect ordered sections for each entity
121121
entity_sections = []
122122
# Validate 'properties' (except for vocabulary_types, which uses 'terms')
123-
if entity_type != "vocabulary_types" and "properties" in entity_data:
123+
if (
124+
entity_type != "vocabulary_types"
125+
and entity_type != "vocabulary_type"
126+
) and "properties" in entity_data:
124127
for prop in entity_data["properties"]:
125128
row_location = prop.get("row_location", "Unknown")
126129

@@ -178,8 +181,8 @@ def _validate_model(self, model: dict) -> dict:
178181

179182
# Check if required properties exist in specific sections
180183
required_properties = {
181-
"Additional Information": "NOTES",
182-
"Comments": "$XMLCOMMENTS",
184+
"Additional Information": ["notes"],
185+
"Comments": ["comments", "xmlcomments", "$xmlcomments"],
183186
}
184187

185188
# Track found properties
@@ -190,11 +193,11 @@ def _validate_model(self, model: dict) -> dict:
190193
property_code = entry["code"]
191194
row_location = entry["row_location"]
192195

193-
if (
194-
section in required_properties
195-
and property_code == required_properties[section]
196-
):
197-
found_properties[section] = True
196+
# Check if this section is one we need to validate
197+
if section in required_properties:
198+
# Perform a case-insensitive check against the list of allowed property codes
199+
if property_code.lower() in required_properties[section]:
200+
found_properties[section] = True
198201

199202
# Log errors for missing required properties
200203
for section, prop in required_properties.items():
@@ -208,7 +211,10 @@ def _validate_model(self, model: dict) -> dict:
208211
)
209212

210213
# Validate 'terms' (only for vocabulary_types)
211-
if entity_type == "vocabulary_types" and "terms" in entity_data:
214+
if (
215+
entity_type == "vocabulary_types"
216+
or entity_type == "vocabulary_type"
217+
) and "terms" in entity_data:
212218
for term in entity_data["terms"]:
213219
row_location = term.get("row_location", "Unknown")
214220
self._validate_fields(
@@ -363,7 +369,7 @@ def _compare_with_current_model(self, mode) -> dict:
363369
)
364370

365371
# Special case for `property_types`
366-
if entity_type == "property_types":
372+
if entity_type in ("property_types", "property_type"):
367373
incoming_row_location = incoming_entity.get(
368374
"row_location", "Unknown"
369375
)

bam_masterdata/checker/source_loader.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def entities_to_json(self) -> dict:
6464
transformed_data[entity_type] = {}
6565

6666
for entity_name, entity_data in entities.items():
67-
if entity_type == "vocabulary_types":
67+
if entity_type in ("vocabulary_type", "vocabulary_types"):
6868
transformed_entity = {
6969
"terms": [], # Now placed before "defs"
7070
"defs": { # Metadata moved to the end
@@ -87,14 +87,17 @@ def entities_to_json(self) -> dict:
8787
entity_name
8888
), # PascalCase for entity ID
8989
"row_location": entity_data.get("row_location"),
90-
"validation_script": entity_data.get("validationPlugin")
91-
or None, # Convert "" to None
90+
"validation_script": entity_data.get(
91+
"validationPlugin"
92+
).strip()
93+
if isinstance(entity_data.get("validationPlugin"), str)
94+
else None,
9295
"iri": entity_data.get("iri") or None, # Convert "" to None
9396
},
9497
}
9598

9699
# Handle additional fields specific to dataset_types
97-
if entity_type == "dataset_types":
100+
if entity_type in ("dataset_types", "dataset_type"):
98101
transformed_entity["defs"]["main_dataset_pattern"] = (
99102
entity_data.get("main_dataset_pattern")
100103
)
@@ -103,7 +106,7 @@ def entities_to_json(self) -> dict:
103106
)
104107

105108
# Handle additional fields specific to object_types
106-
if entity_type == "object_types":
109+
if entity_type in ("object_types", "object_type"):
107110
transformed_entity["defs"]["generated_code_prefix"] = (
108111
entity_data.get("generatedCodePrefix")
109112
)
@@ -140,7 +143,10 @@ def entities_to_json(self) -> dict:
140143
transformed_entity["properties"].append(transformed_property)
141144

142145
if "terms" in entity_data:
143-
for term_name, term_data in entity_data["terms"].items():
146+
transformed_entity.setdefault("terms", [])
147+
for term_name, term_data in (
148+
entity_data.get("terms") or {}
149+
).items():
144150
transformed_term = {
145151
"code": term_data.get("code"),
146152
"description": term_data.get("description", ""),

bam_masterdata/checker/validation_rules/excel_validation_rules.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Description": {"key": "description", "pattern": ".*", "is_description": true},
55
"Validation script": {
66
"key": "validationPlugin",
7-
"pattern": "^[A-Za-z0-9_]+\\.py$",
7+
"pattern": "^[A-Za-z0-9_\\.]+\\.py$",
88
"allow_empty": true
99
},
1010
"Generated code prefix": {
@@ -19,7 +19,7 @@
1919
"Description": {"key": "description", "pattern": ".*", "is_description": true},
2020
"Validation script": {
2121
"key": "validationPlugin",
22-
"pattern": "^[A-Za-z0-9_]+\\.py$",
22+
"pattern": "^[A-Za-z0-9_\\.]+\\.py$",
2323
"allow_empty": true
2424
},
2525
"Generated code prefix": {
@@ -34,7 +34,7 @@
3434
"Description": {"key": "description", "pattern": ".*", "is_description": true},
3535
"Validation script": {
3636
"key": "validationPlugin",
37-
"pattern": "^[A-Za-z0-9_\\.]+$",
37+
"pattern": "^[A-Za-z0-9_\\.]+\\.py$",
3838
"allow_empty": true
3939
}
4040
},
@@ -43,7 +43,7 @@
4343
"Description": {"key": "description", "pattern": ".*", "is_description": true},
4444
"Validation script": {
4545
"key": "validationPlugin",
46-
"pattern": "^[A-Za-z0-9_]+\\.py$",
46+
"pattern": "^[A-Za-z0-9_\\.]+\\.py$",
4747
"allow_empty": true
4848
},
4949
"Main dataset pattern": {"key": "main_dataset_pattern", "pattern": ".*", "allow_empty": true},
@@ -58,7 +58,7 @@
5858
"Metadata": {"key": "metadata", "pattern": ".*"},
5959
"Dynamic script": {
6060
"key": "plugin",
61-
"pattern": "^[A-Za-z0-9_]+\\.py$",
61+
"pattern": "^[A-Za-z0-9_\\.]+\\.py$",
6262
"allow_empty": true
6363
}
6464
},

bam_masterdata/checker/validation_rules/validation_rules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"is_bool": true
7272
},
7373
"section": {
74-
"pattern": "^([A-Z][a-z]*|[A-Z]+)( ([A-Z][a-z]*|[A-Z]+))*$",
74+
"pattern": "^([A-Z][a-z]*|[A-Z]+)( (([A-Z][a-z]*|[A-Z]+)|\\(([A-Z][a-z]*|[A-Z]+)( ([A-Z][a-z]*|[A-Z]+))*\\)))*$",
7575
"is_section": true,
7676
"allow_empty": true
7777
},

bam_masterdata/excel/excel_to_entities.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import sys
34
from typing import TYPE_CHECKING, Any
45

56
from bam_masterdata.utils import is_reduced_version, load_validation_rules
@@ -577,21 +578,30 @@ def process_term_cell(term, cell_value, coordinate, sheet_title):
577578
process_term_cell(term, cell.value, cell.coordinate, sheet.title)
578579
)
579580

580-
# Combine extracted values into a dictionary
581+
if not extracted_columns.get("Code"):
582+
self.logger.error(
583+
f"The required 'Code' column for terms was not found in sheet {sheet.title}."
584+
)
585+
return {}
586+
587+
# Combine extracted values into a dictionary safely
581588
for i in range(len(extracted_columns["Code"])):
582-
terms_dict[extracted_columns["Code"][i]] = {
583-
"permId": extracted_columns["Code"][i],
584-
"code": extracted_columns["Code"][i],
589+
code = extracted_columns["Code"][i]
590+
terms_dict[code] = {
591+
"permId": code,
592+
"code": code,
585593
}
594+
# Also correct a typo here: "descriptions" -> "description"
586595
for key, pybis_val in {
587-
"Description": "descriptions",
596+
"Description": "description",
588597
"Url template": "url_template",
589598
"Label": "label",
590599
"Official": "official",
591600
}.items():
592-
if extracted_columns.get(key):
601+
# THE CRITICAL FIX: Only try to access a value if the column exists and has an entry for this row.
602+
if extracted_columns.get(key) and i < len(extracted_columns[key]):
593603
value = extracted_columns[key][i]
594-
terms_dict[extracted_columns["Code"][i]][pybis_val] = value
604+
terms_dict[code][pybis_val] = value
595605

596606
return terms_dict
597607

@@ -609,6 +619,14 @@ def block_to_entity_dict(
609619

610620
# Get the entity type
611621
entity_type = sheet[f"A{start_index_row}"].value
622+
623+
self.logger.critical("--- DIAGNOSTIC: Inside block_to_entity_dict ---")
624+
self.logger.critical(
625+
f"Raw entity_type from Excel cell A{start_index_row} is: {repr(entity_type)}"
626+
)
627+
print(
628+
f"--- DIAGNOSTIC PRINT: Raw entity_type is: {repr(entity_type)}", flush=True
629+
)
612630
if entity_type not in self.VALIDATION_RULES:
613631
raise ValueError(f"Invalid entity type: {entity_type}")
614632

bam_masterdata/openbis/login.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ def ologin(url: str = "") -> Openbis:
1414
Openbis: Openbis object for the specific openBIS instance defined in `URL`.
1515
"""
1616
o = Openbis(url)
17-
o.login(environ("OPENBIS_USERNAME"), environ("OPENBIS_PASSWORD"), save_token=True)
17+
o.login(
18+
environ("OPENBIS_USERNAME"), environ("OPENBIS_NEW_PASSWORD"), save_token=True
19+
)
1820
return o

0 commit comments

Comments
 (0)