generated from ensaremirerol/nextjs-fastapi-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a9be0f
commit 0718c11
Showing
11 changed files
with
457 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
server/facades/workspace/mapping/mapping_to_yarrrml_facade.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from kink import inject | ||
|
||
from server.exceptions import ErrCodes | ||
from server.facades import ( | ||
BaseFacade, | ||
FacadeResponse, | ||
ServerException, | ||
) | ||
from server.service_protocols.mapping_service_protocol import ( | ||
MappingServiceProtocol, | ||
) | ||
from server.service_protocols.mapping_to_yarrrml_service_protocol import ( | ||
FSServiceProtocol, | ||
MappingToYARRRMLServiceProtocol, | ||
) | ||
from server.services.core.workspace_metadata_service import ( | ||
WorkspaceMetadataServiceProtocol, | ||
) | ||
from server.services.local.local_source_service import ( | ||
SourceServiceProtocol, | ||
) | ||
from server.services.local.local_workspace_service import ( | ||
WorkspaceServiceProtocol, | ||
) | ||
|
||
|
||
@inject | ||
class MappingToYARRRMLFacade(BaseFacade): | ||
def __init__( | ||
self, | ||
workspace_metadata_service: WorkspaceMetadataServiceProtocol, | ||
workspace_service: WorkspaceServiceProtocol, | ||
mapping_service: MappingServiceProtocol, | ||
source_service: SourceServiceProtocol, | ||
yarrrml_service: MappingToYARRRMLServiceProtocol, | ||
fs_service: FSServiceProtocol, | ||
): | ||
super().__init__() | ||
self.workspace_metadata_service: WorkspaceMetadataServiceProtocol = workspace_metadata_service | ||
self.workspace_service: WorkspaceServiceProtocol = ( | ||
workspace_service | ||
) | ||
self.mapping_service: MappingServiceProtocol = ( | ||
mapping_service | ||
) | ||
self.source_service: SourceServiceProtocol = ( | ||
source_service | ||
) | ||
self.yarrrml_service: MappingToYARRRMLServiceProtocol = yarrrml_service | ||
self.fs_service: FSServiceProtocol = fs_service | ||
|
||
@BaseFacade.error_wrapper | ||
def execute( | ||
self, | ||
workspace_id: str, | ||
mapping_id: str | None = None, | ||
) -> FacadeResponse: | ||
self.logger.info( | ||
f"Creating YARRRML mapping for mapping {mapping_id} in workspace {workspace_id}" | ||
) | ||
|
||
self.logger.info("Retrieving workspace metadata") | ||
|
||
workspace_metadata = self.workspace_metadata_service.get_workspace_metadata( | ||
workspace_id, | ||
) | ||
|
||
self.logger.info("Retrieving workspace") | ||
|
||
workspace = self.workspace_service.get_workspace( | ||
workspace_metadata.location, | ||
) | ||
|
||
self.logger.info("Retrieving mapping") | ||
|
||
if mapping_id not in workspace.mappings: | ||
self.logger.error( | ||
f"Mapping {mapping_id} not found in workspace {workspace_id}" | ||
) | ||
raise ServerException( | ||
f"Mapping {mapping_id} not found in workspace {workspace_id}", | ||
ErrCodes.MAPPING_NOT_FOUND, | ||
) | ||
|
||
mapping = self.mapping_service.get_mapping( | ||
mapping_id | ||
) | ||
|
||
self.logger.info("Retrieving source") | ||
|
||
source = self.source_service.get_source( | ||
mapping.source_id, | ||
) | ||
|
||
self.logger.info("Converting mapping to YARRRML") | ||
|
||
yarrrml = ( | ||
self.yarrrml_service.convert_mapping_to_yarrrml( | ||
workspace.prefixes, | ||
source, | ||
mapping, | ||
self.fs_service, | ||
) | ||
) | ||
|
||
return self._success_response( | ||
data=yarrrml, | ||
message="YARRRML mapping created", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
server/service_protocols/mapping_to_yarrrml_service_protocol/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from server.models.mapping import MappingGraph | ||
from server.models.source import Source | ||
from server.service_protocols.fs_service_protocol import ( | ||
FSServiceProtocol, | ||
) | ||
|
||
|
||
class MappingToYARRRMLServiceProtocol(ABC): | ||
@abstractmethod | ||
def convert_mapping_to_yarrrml( | ||
self, | ||
prefixes: dict[str, str], | ||
source: Source, | ||
mapping: MappingGraph, | ||
fs_service: FSServiceProtocol, | ||
) -> str: | ||
""" | ||
Convert a mapping to YARRRML | ||
Args: | ||
prefixes (dict): A dictionary of prefixes | ||
source (Source): Source data of the mapping | ||
mapping (MappingGraph): Mapping data | ||
Returns: | ||
str: Valid Yaml string representing the YARRRML mapping | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.