Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added extra validations and logs on package import #380

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
mwb_logger.log_all_warning(m)
self.warnings.append(TaskResultWarning(message=m, type="Field Name Mismatch"))

if not self.is_cm_rule_path_valid(mono_rule.class_path):
m = f"{mono_rule.class_path}"
mwb_logger.log_all_warning(m)
self.warnings.append(TaskResultWarning(message=m, type="Class Path Mismatch"))

Check warning on line 96 in mapping_workbench/backend/package_importer/adapters/eforms/importer.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/package_importer/adapters/eforms/importer.py#L94-L96

Added lines #L94 - L96 were not covered by tests

if not self.is_cm_rule_path_valid(mono_rule.property_path):
m = f"{mono_rule.property_path}"
mwb_logger.log_all_warning(m)
self.warnings.append(TaskResultWarning(message=m, type="Property Path Mismatch"))

Check warning on line 101 in mapping_workbench/backend/package_importer/adapters/eforms/importer.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/package_importer/adapters/eforms/importer.py#L99-L101

Added lines #L99 - L101 were not covered by tests

# A conceptual mapping rule may have same structural element but different Ontology Fragment
rule: ConceptualMappingRule = await ConceptualMappingRule.find_one(
ConceptualMappingRule.source_structural_element == StructuralElement.link_from_id(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from abc import ABC, abstractmethod
from itertools import takewhile
from pathlib import Path
Expand Down Expand Up @@ -43,7 +44,6 @@ def __init__(self, project: Project, user: User, task_response: TaskResponse = N
self.task_progress = TaskProgress(self.task_response)
self.package = None


@abstractmethod
async def import_from_mono_mapping_suite(self, mono_package: ImportedMappingSuite):
"""
Expand Down Expand Up @@ -366,6 +366,12 @@ async def add_mapping_package_from_mono(self, mono_package: ImportedMappingSuite

self.task_progress.finish_current_action_step()

@classmethod
def is_cm_rule_path_valid(cls, cm_rule_path: str) -> bool:
if not cm_rule_path:
return True
return len(cm_rule_path.split('/')) == len(cm_rule_path.split(" / "))

@classmethod
async def clear_project_data(cls, project: Project):
project_link = Project.link_from_id(project.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SPARQLValidator(TestDataValidator):
rdf_graph: Any = None
test_data: Any = None
test_data_suite: Any = None
errors: List[str] = None

@validate_call
def __init__(self, test_data: TestDataState, test_data_suite: TestDataSuiteState = None, **data: Any):
Expand All @@ -32,6 +33,7 @@ def __init__(self, test_data: TestDataState, test_data_suite: TestDataSuiteState
)
self.test_data = test_data
self.test_data_suite = test_data_suite
self.errors = []

def validate(self, sparql_queries: List[SPARQLTestState]) -> SPARQLTestDataValidationResult:
results = []
Expand All @@ -55,7 +57,7 @@ def validate(self, sparql_queries: List[SPARQLTestState]) -> SPARQLTestDataValid
except Exception as e:
sparql_query_result.error = str(e)[:100]
sparql_query_result.result = SPARQLQueryRefinedResultType.ERROR.value
mwb_logger.log_all_error(message="ERROR :: SPARQL Validation :: Stack trace:", stack_trace=str(e))
mwb_logger.log_all_error(message=f"ERROR :: SPARQL Validation :: Q:\n{sparql_query.content}\nStack trace:", stack_trace=str(e))

results.append(sparql_query_result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const ExtraForm = (props) => {
<Stack direction='row'
alignItems='center'
gap={2}>
{compare_items.length && <Button sx={{my: 1}}
{compare_items.length > 0 && <Button sx={{my: 1}}
onClick={() => setShowCompare(e => !e)}>{showCompare ? 'Hide Compare' : 'Show Compare'}</Button>}


Expand All @@ -128,6 +128,7 @@ const ExtraForm = (props) => {
onChange={handleCompareChange}
select
value={formik.values.compare_item}
sx={{minWidth: 200}}
>
{compare_items.map((compare_item) => (
<MenuItem
Expand Down Expand Up @@ -180,7 +181,7 @@ const Page = () => {
const {id, fid} = router.query;

const formState = useItem(sectionApi, fid);
const compare_items = useFileHistory(sectionApi, fid)
const compare_items = useFileHistory(sectionApi, fid).slice(1)
const item = formState.item;

usePageView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const FileResourceEditForm = (props) => {
md={12}>
<Stack direction='row'
gap={2}>
{extra_form_fields?.compare_items.length && <Button
{!!extra_form_fields?.compare_items.length && <Button
onClick={() => setShowCompare(e => !e)}>{showCompare ? 'Hide compare' : 'Show compare'}</Button>}

{showCompare && <TextField
Expand Down
Loading