Skip to content

Commit

Permalink
Merge pull request #380 from meaningfy-ws/feature/MWB-961
Browse files Browse the repository at this point in the history
added extra validations and logs on package import
  • Loading branch information
kaleanych authored Jan 23, 2025
2 parents e0d5e82 + 529c6b6 commit 40a8381
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ async def add_mapping_rules_from_mono(self, mono_package: ImportedMappingSuite):
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"))

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"))

# 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

0 comments on commit 40a8381

Please sign in to comment.