Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleanych committed Oct 7, 2023
1 parent 9af8115 commit e13fcb3
Show file tree
Hide file tree
Showing 18 changed files with 424 additions and 22 deletions.
21 changes: 21 additions & 0 deletions mapping_workbench/backend/conceptual_mapping_rule/models/entity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import datetime
from enum import Enum

Check warning on line 2 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L1-L2

Added lines #L1 - L2 were not covered by tests
from typing import Optional, List

import pymongo
from beanie import Link, Indexed
from pydantic import BaseModel
from pymongo import IndexModel

Check warning on line 8 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L5-L8

Added lines #L5 - L8 were not covered by tests

from mapping_workbench.backend.core.models.base_project_resource_entity import BaseProjectResourceEntity, \
Expand All @@ -11,13 +13,28 @@
from mapping_workbench.backend.ontology.models.term import TermValidityResponse

Check warning on line 13 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L13

Added line #L13 was not covered by tests
from mapping_workbench.backend.sparql_test_suite.models.entity import SPARQLTestFileResource
from mapping_workbench.backend.triple_map_fragment.models.entity import GenericTripleMapFragment
from mapping_workbench.backend.user.models.user import User

Check warning on line 16 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L16

Added line #L16 was not covered by tests


class ConceptualMappingRuleTermsValidity(Enum):
VALID = "valid"
INVALID = "invalid"

Check warning on line 21 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L19-L21

Added lines #L19 - L21 were not covered by tests


class ConceptualMappingRuleCommentPriority(Enum):
HIGH = "high"
NORMAL = "normal"
LOW = "low"

Check warning on line 27 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L24-L27

Added lines #L24 - L27 were not covered by tests


class ConceptualMappingRuleComment(BaseModel):
title: Optional[str] = None
comment: Optional[str] = None
priority: Optional[ConceptualMappingRuleCommentPriority] = ConceptualMappingRuleCommentPriority.NORMAL
created_at: Optional[datetime] = None
created_by: Optional[Link[User]] = None

Check warning on line 35 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L30-L35

Added lines #L30 - L35 were not covered by tests


class ConceptualMappingRuleIn(BaseProjectResourceEntityInSchema):
field_id: Optional[str] = None
field_title: Optional[str] = None
Expand Down Expand Up @@ -51,6 +68,8 @@ class ConceptualMappingRuleOut(BaseProjectResourceEntityOutSchema):
mapping_packages: Optional[List[Link[MappingPackage]]] = None
triple_map_fragment: Optional[Link[GenericTripleMapFragment]] = None
sparql_assertions: Optional[List[Link[SPARQLTestFileResource]]] = None
notes: Optional[List[ConceptualMappingRuleComment]] = None
comments: Optional[List[ConceptualMappingRuleComment]] = None

Check warning on line 72 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L59-L72

Added lines #L59 - L72 were not covered by tests


class ConceptualMappingRule(BaseProjectResourceEntity):
Expand All @@ -66,6 +85,8 @@ class ConceptualMappingRule(BaseProjectResourceEntity):
mapping_packages: Optional[List[Optional[Link[MappingPackage]]]] = None
triple_map_fragment: Optional[Link[GenericTripleMapFragment]] = None
sparql_assertions: Optional[List[Link[SPARQLTestFileResource]]] = None
notes: Optional[List[ConceptualMappingRuleComment]] = None
comments: Optional[List[ConceptualMappingRuleComment]] = None

Check warning on line 89 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L76-L89

Added lines #L76 - L89 were not covered by tests

class Settings(BaseProjectResourceEntity.Settings):
name = "conceptual_mapping_rules"
Expand Down
48 changes: 33 additions & 15 deletions mapping_workbench/backend/conceptual_mapping_rule/services/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Dict

Check warning on line 1 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L1

Added line #L1 was not covered by tests

from beanie import PydanticObjectId
from pymongo.errors import DuplicateKeyError
Expand All @@ -21,16 +21,6 @@ async def list_conceptual_mapping_rules(filters: dict = None, page: int = None,
prepare_search_param(query_filters)
skip, limit = pagination_params(page, limit)

Check warning on line 22 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L21-L22

Added lines #L21 - L22 were not covered by tests

# update terms_validity info for queried rules
for item in await ConceptualMappingRule.find(query_filters).to_list():
item.target_class_path_terms_validity = await check_content_terms_validity(item.target_class_path)
item.target_property_path_terms_validity = await check_content_terms_validity(item.target_property_path)
item.terms_validity = ConceptualMappingRuleTermsValidity.INVALID \
if any(not x.is_valid for x in item.target_class_path_terms_validity) \
or any(not x.is_valid for x in item.target_property_path_terms_validity) \
else ConceptualMappingRuleTermsValidity.VALID
await item.save()

items: List[ConceptualMappingRuleOut] = await ConceptualMappingRule.find(

Check warning on line 24 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L24

Added line #L24 was not covered by tests
query_filters,
projection_model=ConceptualMappingRuleOut,
Expand Down Expand Up @@ -59,13 +49,17 @@ async def create_conceptual_mapping_rule(data: ConceptualMappingRuleCreateIn,
async def update_conceptual_mapping_rule(conceptual_mapping_rule: ConceptualMappingRule,

Check warning on line 49 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L49

Added line #L49 was not covered by tests
data: ConceptualMappingRuleUpdateIn,
user: User) -> ConceptualMappingRuleOut:
return ConceptualMappingRuleOut(**(
await conceptual_mapping_rule.set(request_update_data(data, user=user))
).model_dump())
update_data = request_update_data(data, user=user)
terms_validated_rule = await rule_terms_validator(ConceptualMappingRule(**update_data))
update_data['target_class_path_terms_validity'] = terms_validated_rule.target_class_path_terms_validity
update_data['target_property_path_terms_validity'] = terms_validated_rule.target_property_path_terms_validity
update_data['terms_validity'] = terms_validated_rule.terms_validity
rule: ConceptualMappingRule = await conceptual_mapping_rule.set(update_data)
return ConceptualMappingRuleOut(**rule.model_dump())

Check warning on line 58 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L52-L58

Added lines #L52 - L58 were not covered by tests


async def clone_conceptual_mapping_rule(conceptual_mapping_rule: ConceptualMappingRule,

Check warning on line 61 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L61

Added line #L61 was not covered by tests
user: User) -> ConceptualMappingRuleOut:
user: User) -> ConceptualMappingRuleOut:
cloned_conceptual_mapping_rule: ConceptualMappingRule = \

Check warning on line 63 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L63

Added line #L63 was not covered by tests
await conceptual_mapping_rule.model_copy(
update={"id": None, "updated_at": None, "updated_by": None}
Expand All @@ -89,3 +83,27 @@ async def get_conceptual_mapping_rule_out(id: PydanticObjectId) -> ConceptualMap

async def delete_conceptual_mapping_rule(conceptual_mapping_rule: ConceptualMappingRule):
return await conceptual_mapping_rule.delete()


async def rule_terms_validator(rule: ConceptualMappingRule) -> ConceptualMappingRule:
rule.target_class_path_terms_validity = await check_content_terms_validity(rule.target_class_path)
rule.target_property_path_terms_validity = await check_content_terms_validity(rule.target_property_path)
rule.terms_validity = ConceptualMappingRuleTermsValidity.INVALID \

Check warning on line 91 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L88-L91

Added lines #L88 - L91 were not covered by tests
if any(not x.is_valid for x in rule.target_class_path_terms_validity) \
or any(not x.is_valid for x in rule.target_property_path_terms_validity) \
else ConceptualMappingRuleTermsValidity.VALID

return rule

Check warning on line 96 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L96

Added line #L96 was not covered by tests


async def validate_and_save_rules_terms(query_filters: Dict = None):

Check warning on line 99 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L99

Added line #L99 was not covered by tests
"""
update terms_validity info for queried rules
:param query_filters:
:return:
"""

for item in await ConceptualMappingRule.find(query_filters or {}).to_list():
item = await rule_terms_validator(item)
await item.save()

Check warning on line 109 in mapping_workbench/backend/conceptual_mapping_rule/services/api.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/services/api.py#L107-L109

Added lines #L107 - L109 were not covered by tests
6 changes: 5 additions & 1 deletion mapping_workbench/backend/core/entrypoints/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
from mapping_workbench.backend.user.entrypoints.api import routes as user_routes
from mapping_workbench.backend.user.models.user import User

from mapping_workbench.backend.tasks.entrypoints.api import routes as tasks_routes

Check warning on line 47 in mapping_workbench/backend/core/entrypoints/api/main.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/core/entrypoints/api/main.py#L47

Added line #L47 was not covered by tests


ROOT_API_PATH = "/api/v1"

google_oauth_client = GoogleOAuth2("CLIENT_ID", "CLIENT_SECRET")
Expand Down Expand Up @@ -118,7 +121,8 @@ async def on_startup():
specific_triple_map_fragment_routes.router,
generic_triple_map_fragment_routes.router,
config_routes.router,
ontology_routes.router
ontology_routes.router,
tasks_routes.router
]

for secured_router in secured_routers:
Expand Down
4 changes: 4 additions & 0 deletions mapping_workbench/backend/core/models/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ class APIRequestWithId(BaseModel):
class APIRequestForUpdateMany(BaseModel):
for_query: Optional[Dict]
set_values: Optional[Dict]


class APIRequestWithProject(BaseModel):
project: Optional[PydanticObjectId] = None

Check warning on line 17 in mapping_workbench/backend/core/models/api_request.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/core/models/api_request.py#L16-L17

Added lines #L16 - L17 were not covered by tests
2 changes: 1 addition & 1 deletion mapping_workbench/backend/ontology/models/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NamespaceOut(BaseEntityOutSchema):


class Namespace(BaseEntity):
prefix: Indexed(str, unique=True)
prefix: Indexed(str, unique=False)
uri: Optional[str] = None
is_syncable: Optional[bool] = True

Expand Down
Empty file.
28 changes: 28 additions & 0 deletions mapping_workbench/backend/tasks/entrypoints/api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Dict

from beanie import PydanticObjectId
from fastapi import APIRouter

from mapping_workbench.backend.core.models.api_request import APIRequestWithProject
from mapping_workbench.backend.tasks.services.terms_validator import task_terms_validator

ROUTE_PREFIX = "/tasks"
TAG = "task"
NAME_FOR_MANY = "tasks"
NAME_FOR_ONE = "task"

router = APIRouter(
prefix=ROUTE_PREFIX,
tags=[TAG]
)


@router.post(
"/terms_validator",
description=f"{NAME_FOR_ONE} Terms Validator",
name=f"{NAME_FOR_MANY}:{NAME_FOR_ONE}_terms_validator"
)
async def route_task_terms_validator(
filters: APIRequestWithProject = None
):
return await task_terms_validator(filters)
14 changes: 14 additions & 0 deletions mapping_workbench/backend/tasks/services/terms_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Dict

from mapping_workbench.backend.conceptual_mapping_rule.services.api import validate_and_save_rules_terms
from mapping_workbench.backend.core.models.api_request import APIRequestWithProject
from mapping_workbench.backend.project.models.entity import Project


async def task_terms_validator(filters: APIRequestWithProject = None):
query_filters: Dict = {}

if filters.project:
query_filters['project'] = Project.link_from_id(filters.project)

await validate_and_save_rules_terms(query_filters)
32 changes: 32 additions & 0 deletions mapping_workbench/frontend/src/api/tasks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {SectionApi} from "../section";
import {appApi} from "../app";
import {apiPaths} from "../../paths";

class TasksApi {
get TASKS_TITLE() {
return "Tasks";
}

get TASK_TITLE() {
return "Task";
}

constructor() {
this.section = "tasks";
this.paths = apiPaths[this.section];
}

async runTermsValidator(request = {}) {
try {
let endpoint = this.paths['terms_validator'];
let filters = {}
if (request['filters']) {
filters = request['filters'];
}
return appApi.post(endpoint, filters);
} catch (err) {
}
}
}

export const tasksApi = new TasksApi();
16 changes: 16 additions & 0 deletions mapping_workbench/frontend/src/layouts/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import FolderOpenIcon from '@mui/icons-material/FolderOpen';
import HiveIcon from '@mui/icons-material/Hive';
import MapIcon from '@mui/icons-material/Map';
import SchemaIcon from '@mui/icons-material/Schema';
import TaskIcon from '@mui/icons-material/TaskAlt';

import HomeSmileIcon from 'src/icons/ui/duocolor/home-smile';
import LayoutAlt02 from 'src/icons/ui/duocolor/layout-alt-02';
Expand Down Expand Up @@ -252,6 +253,21 @@ export const useSections = () => {
}
]
},
{
title: t(tokens.nav.tasks),
path: paths.app.tasks.index,
icon: (
<SvgIcon fontSize="small">
<TaskIcon/>
</SvgIcon>
),
items: [
{
title: t(tokens.nav.terms_validator),
path: paths.app.tasks.terms_validator
}
]
},
{
title: t(tokens.nav.users),
path: paths.app.users.index,
Expand Down
2 changes: 2 additions & 0 deletions mapping_workbench/frontend/src/locales/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@ export const tokens = {

admin: 'nav.admin',
users: 'nav.users',
terms_validator: 'nav.terms_validator',
tasks: 'nav.tasks'
}
};
2 changes: 2 additions & 0 deletions mapping_workbench/frontend/src/locales/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ export const en = {
[tokens.nav.triple_map_fragments]: 'Triple Maps',
[tokens.nav.specific_triple_map_fragments]: 'Specific Triple Maps',
[tokens.nav.generic_triple_map_fragments]: 'Generic Triple Maps',
[tokens.nav.terms_validator]: 'Terms Validator',
[tokens.nav.tasks]: 'Tasks',
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import ArrowLeftIcon from '@untitled-ui/icons-react/build/esm/ArrowLeft';
import Box from '@mui/material/Box';
import Container from '@mui/material/Container';
import Link from '@mui/material/Link';
import Stack from '@mui/material/Stack';
import SvgIcon from '@mui/material/SvgIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Box from '@mui/material/Box';
import Container from '@mui/material/Container';
import Link from '@mui/material/Link';
import Stack from '@mui/material/Stack';
import SvgIcon from '@mui/material/SvgIcon';
Expand Down
Loading

0 comments on commit e13fcb3

Please sign in to comment.