Skip to content

Commit

Permalink
Added SDK fields preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolea PLESCO authored and Kolea PLESCO committed Dec 18, 2024
1 parent 191d170 commit 0fb4333
Show file tree
Hide file tree
Showing 20 changed files with 293 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mapping_workbench.backend.config import settings
from mapping_workbench.backend.fields_registry.models.field_registry import StructuralElementsVersionedView, \
StructuralElement
from mapping_workbench.backend.fields_registry.models.pool import PoolSDKField, PoolSDKFieldsVersionedView
from mapping_workbench.backend.mapping_package.models.entity import MappingPackage, MappingPackageStateGate
from mapping_workbench.backend.mapping_rule_registry.models.entity import MappingRuleRegistry, MappingGroup
from mapping_workbench.backend.ontology.models.namespace import Namespace, NamespaceCustom
Expand Down Expand Up @@ -72,5 +73,7 @@ async def init_project_models(mongodb_database: AsyncIOMotorDatabase):
StructuralElementsVersionedView,
XSDFileResource,
ConceptualMappingGroupBeanie,
PoolSDKField,
PoolSDKFieldsVersionedView
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NAME_FOR_MANY = "fields_registries"
NAME_FOR_ONE = "fields_registry"

TASK_IMPORT_EFORMS_FROM_GITHUB_NAME = f"{NAME_FOR_ONE}:tasks:import_eforms_from_github"
TASK_IMPORT_EFORMS_XSD_NAME = f"{NAME_FOR_ONE}:tasks:import_eforms_xsd"

router = APIRouter(
prefix=ROUTE_PREFIX,
Expand Down Expand Up @@ -188,20 +188,20 @@ async def route_search_structural_elements_versioned_view_by_eforms_version(


@router.post(
"/tasks/import_eforms_from_github",
description=f"Task Import eforms from github",
name=TASK_IMPORT_EFORMS_FROM_GITHUB_NAME,
"/tasks/import_eforms_xsd",
description=f"Task Import eForms XSD",
name=TASK_IMPORT_EFORMS_XSD_NAME,
status_code=status.HTTP_201_CREATED
)
async def route_task_import_eforms_from_github(
async def route_task_import_eforms_xsd(
github_repository_url: str = Form(...),
branch_or_tag_name: str = Form(...),
project_id: PydanticObjectId = Form(...),
user: User = Depends(current_active_user)
):
return add_task(
tasks.task_import_eforms_from_github,
f"Importing eForms from {github_repository_url}, branch: {branch_or_tag_name}",
tasks.task_import_eforms_xsd,
f"Importing eForms XSD versions: {branch_or_tag_name}",
None,
user.email,
False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,31 @@ class EFormsField(BaseModel):
legal_type: Optional[str] = Field(default=None, alias='legalType')
repeatable: EFormsFieldsRepeatableAttribute

def generate_hash_id(self, project_id: str = None) -> str:
fields_to_hash = [project_id, self.id, self.xpath_absolute, self.xpath_relative, self.repeatable.value,
def generate_hash_id(self, project_id: str = None, sdk_version: str = None) -> str:
fields_to_hash = [project_id, sdk_version, self.id, self.xpath_absolute, self.xpath_relative,
self.repeatable.value,
self.parent_node_id, self.name, self.bt_id, self.value_type,
self.legal_type]
str_content = "_".join(map(str, fields_to_hash))
return str(hashlib.sha1(str_content.encode("utf-8")).hexdigest())


def generate_project_eforms_field_hash_id(element_id: str, project_id: str) -> str:
fields_to_hash = [element_id, project_id, id]
str_content = "_".join(map(str, fields_to_hash))
return str(hashlib.sha1(str_content.encode("utf-8")).hexdigest())


def generate_eforms_node_hash_id(
id: str,
repeatable: bool,
parent_id: Optional[str] = None,
xpath_absolute: str = None,
xpath_relative: str = None,
project_id: str = None
project_id: str = None,
sdk_version: str = None
):
fields_to_hash = [project_id, id, xpath_absolute, xpath_relative, repeatable, parent_id]
fields_to_hash = [project_id, sdk_version, id, xpath_absolute, xpath_relative, repeatable, parent_id]
str_content = "_".join(map(str, fields_to_hash))
return str(hashlib.sha1(str_content.encode("utf-8")).hexdigest())

Expand All @@ -48,14 +56,15 @@ class EFormsNode(BaseModel):
xpath_relative: str = Field(..., alias='xpathRelative')
repeatable: bool

def generate_hash_id(self, project_id: str = None):
def generate_hash_id(self, project_id: str = None, sdk_version: str = None):
return generate_eforms_node_hash_id(
id=self.id,
repeatable=self.repeatable,
parent_id=self.parent_id,
xpath_absolute=self.xpath_absolute,
xpath_relative=self.xpath_relative,
project_id=project_id
project_id=project_id,
sdk_version=sdk_version
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional, List, Literal

import pymongo
from beanie import Link
from beanie import Link, PydanticObjectId
from pydantic import Field, BaseModel
from pymongo import IndexModel

Expand Down Expand Up @@ -120,7 +120,7 @@ def set_state(self, state: StructuralElementState):
raise Exception("Setting the state of a structural element is not supported.")

@classmethod
def from_pool_sdk_field(cls, sdk_field: PoolSDKField) -> 'StructuralElement':
def from_pool_sdk_field(cls, sdk_field: PoolSDKField, project_id: PydanticObjectId) -> 'StructuralElement':
# Create and return an instance of StructuralElement by mapping fields
return cls(
id=sdk_field.element_id,
Expand Down
20 changes: 17 additions & 3 deletions mapping_workbench/backend/fields_registry/models/pool.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Optional, List, Literal

from pydantic import BaseModel
from beanie import Link, Document


class PoolSDKField(BaseModel):
class PoolSDKField(Document):
"""
"""
Expand All @@ -23,4 +23,18 @@ class PoolSDKField(BaseModel):
order: Optional[int] = None

class Settings:
name = "pool_sdk_fields"
name = "pool_sdk_fields"


class PoolSDKFieldsVersionedView(Document):
"""
"""
view_id: str
eforms_sdk_version: str
eforms_subtype: str
ordered_elements: List[Link[PoolSDKField]] = None

class Settings:
name = "pool_sdk_fields_versioned_view"

Loading

0 comments on commit 0fb4333

Please sign in to comment.