diff --git a/server/factories/__init__.py b/server/factories/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/models/file_metadata.py b/server/models/file_metadata.py index 4b8b1e6..f7e2195 100644 --- a/server/models/file_metadata.py +++ b/server/models/file_metadata.py @@ -19,3 +19,18 @@ class FileMetadata: stem: str suffix: str hash: str + + def to_table(self): + """ + Convert to table representation + + Returns: + dict: Table representation + """ + return { + "uuid": self.uuid, + "name": self.name, + "stem": self.stem, + "suffix": self.suffix, + "hash": self.hash, + } diff --git a/server/models/workspace.py b/server/models/workspace.py index dfb23ec..7561778 100644 --- a/server/models/workspace.py +++ b/server/models/workspace.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from server.models.workspace_metadata import ( - WorkspaceMetadataModel, + WorkspaceMetadata, ) @@ -19,7 +19,7 @@ class WorkspaceModel: used_uri_patterns (list[str]): list of used URI patterns """ - metadata: WorkspaceMetadataModel + metadata: WorkspaceMetadata sources: list[str] mappings: list[str] prefixes: dict[str, str] diff --git a/server/models/workspace_metadata.py b/server/models/workspace_metadata.py index affa28c..ce76f4c 100644 --- a/server/models/workspace_metadata.py +++ b/server/models/workspace_metadata.py @@ -1,13 +1,13 @@ from dataclasses import dataclass from server.services.core.sqlite_db_service.tables.workspace_metadata import ( - WorkspaceMetadata, + WorkspaceMetadataTable, WorkspaceType, ) @dataclass -class WorkspaceMetadataModel: +class WorkspaceMetadata: """ Model for workspace metadata @@ -28,8 +28,10 @@ class WorkspaceMetadataModel: enabled_features: list[str] @staticmethod - def from_table(workspace_metadata: WorkspaceMetadata): - return WorkspaceMetadataModel( + def from_table( + workspace_metadata: WorkspaceMetadataTable, + ): + return WorkspaceMetadata( uuid=workspace_metadata.uuid, name=workspace_metadata.name, description=workspace_metadata.description, @@ -41,7 +43,7 @@ def from_table(workspace_metadata: WorkspaceMetadata): ) def to_table(self): - return WorkspaceMetadata( + return WorkspaceMetadataTable( uuid=self.uuid, name=self.name, description=self.description, diff --git a/server/server.py b/server/server.py index a400c3e..49ff947 100644 --- a/server/server.py +++ b/server/server.py @@ -157,6 +157,6 @@ async def get_data(): app.include_router( workspaces_router, - prefix="/api/workspaces", - tags=["workspaces"], + prefix="/api/workspaces_metadata", + tags=["workspaces_metadata"], ) diff --git a/server/service_protocols/fs_service_protocol/__init__.py b/server/service_protocols/fs_service_protocol/__init__.py index 76cd122..869cab4 100644 --- a/server/service_protocols/fs_service_protocol/__init__.py +++ b/server/service_protocols/fs_service_protocol/__init__.py @@ -6,15 +6,6 @@ class FSServiceProtocol(Protocol): - def service_type(self) -> str: - """ - Get service type - - Returns: - str: service type - """ - ... - def upload_file( self, name: str, diff --git a/server/service_protocols/workspace_metadata_service_protocol/__init__.py b/server/service_protocols/workspace_metadata_service_protocol/__init__.py index a003eff..660f6fa 100644 --- a/server/service_protocols/workspace_metadata_service_protocol/__init__.py +++ b/server/service_protocols/workspace_metadata_service_protocol/__init__.py @@ -1,7 +1,7 @@ from typing import Protocol from server.models.workspace_metadata import ( - WorkspaceMetadataModel, + WorkspaceMetadata, ) from server.services.core.sqlite_db_service.tables.workspace_metadata import ( WorkspaceType, @@ -15,7 +15,7 @@ class WorkspaceMetadataService(Protocol): def get_workspaces( self, - ) -> list[WorkspaceMetadataModel]: + ) -> list[WorkspaceMetadata]: """ Get all workspaces diff --git a/server/service_protocols/workspace_service_protocol/__init__.py b/server/service_protocols/workspace_service_protocol/__init__.py index 78f320c..e8888d7 100644 --- a/server/service_protocols/workspace_service_protocol/__init__.py +++ b/server/service_protocols/workspace_service_protocol/__init__.py @@ -10,15 +10,6 @@ class WorkspaceServiceProtocol(Protocol): Service for workspace operations """ - def service_type(self) -> str: - """ - Get service type - - Returns: - str: service type - """ - ... - def get_workspace(self, uuid: str) -> WorkspaceModel: """ Get a workspace by UUID diff --git a/server/services/core/config_service.py b/server/services/core/config_service.py index a184069..06907ca 100644 --- a/server/services/core/config_service.py +++ b/server/services/core/config_service.py @@ -3,7 +3,7 @@ from server.services.core.sqlite_db_service import DBService from server.services.core.sqlite_db_service.tables.config import ( - Config, + ConfigTable, ) @@ -14,21 +14,25 @@ def __init__(self, db_service: DBService): def get(self, key: str) -> str | None: with self._db_service.get_session() as session: - result: Config | None = session.get(Config, key) + result: ConfigTable | None = session.get( + ConfigTable, key + ) return result.value if result else None def set(self, key: str, value: str): with self._db_service.get_session() as session: - session.merge(Config(key=key, value=value)) + session.merge(ConfigTable(key=key, value=value)) session.commit() def delete(self, key: str): with self._db_service.get_session() as session: - item = session.get(Config, key) + item = session.get(ConfigTable, key) if not item: return session.execute( - delete(Config).where(Config.key == key) + delete(ConfigTable).where( + ConfigTable.key == key + ) ) session.commit() diff --git a/server/services/core/sqlite_db_service/tables/__init__.py b/server/services/core/sqlite_db_service/tables/__init__.py index 2e86b01..243b1fb 100644 --- a/server/services/core/sqlite_db_service/tables/__init__.py +++ b/server/services/core/sqlite_db_service/tables/__init__.py @@ -1,11 +1,11 @@ from server.services.core.sqlite_db_service.tables.config import ( - Config, + ConfigTable, ) from server.services.core.sqlite_db_service.tables.workspace_metadata import ( - WorkspaceMetadata, + WorkspaceMetadataTable, ) __all__ = [ - "Config", - "WorkspaceMetadata", + "ConfigTable", + "WorkspaceMetadataTable", ] diff --git a/server/services/core/sqlite_db_service/tables/config.py b/server/services/core/sqlite_db_service/tables/config.py index 8ffdfb4..ea3307a 100644 --- a/server/services/core/sqlite_db_service/tables/config.py +++ b/server/services/core/sqlite_db_service/tables/config.py @@ -6,7 +6,7 @@ ) -class Config(Base): +class ConfigTable(Base): __tablename__ = "config" key: Mapped[str] = mapped_column( diff --git a/server/services/core/sqlite_db_service/tables/file_metadata.py b/server/services/core/sqlite_db_service/tables/file_metadata.py new file mode 100644 index 0000000..c40ea4b --- /dev/null +++ b/server/services/core/sqlite_db_service/tables/file_metadata.py @@ -0,0 +1,24 @@ +from sqlalchemy import String +from sqlalchemy.orm import Mapped, mapped_column + +from server.services.core.sqlite_db_service.base import ( + Base, +) + + +class FileMetadataTable(Base): + __tablename__ = "file_metadata" + + uuid: Mapped[str] = mapped_column( + String, primary_key=True + ) + name: Mapped[str] = mapped_column(String) + stem: Mapped[str] = mapped_column(String) + suffix: Mapped[str] = mapped_column(String) + hash: Mapped[str] = mapped_column(String) + + def __repr__(self): + return f"" + + def __str__(self): + return self.__repr__() diff --git a/server/services/core/sqlite_db_service/tables/plugin.py b/server/services/core/sqlite_db_service/tables/plugin.py index e7973e2..71a7ee4 100644 --- a/server/services/core/sqlite_db_service/tables/plugin.py +++ b/server/services/core/sqlite_db_service/tables/plugin.py @@ -6,7 +6,7 @@ ) -class Plugin(Base): +class PluginTable(Base): """ Table for plugin metadata. diff --git a/server/services/core/sqlite_db_service/tables/plugin_ui_element.py b/server/services/core/sqlite_db_service/tables/plugin_ui_element.py index c95c1a9..e609a7b 100644 --- a/server/services/core/sqlite_db_service/tables/plugin_ui_element.py +++ b/server/services/core/sqlite_db_service/tables/plugin_ui_element.py @@ -6,7 +6,7 @@ ) -class PluginUIElement(Base): +class PluginUIElementTable(Base): """ Table for plugin UI elements. diff --git a/server/services/core/sqlite_db_service/tables/workspace_metadata.py b/server/services/core/sqlite_db_service/tables/workspace_metadata.py index 57b6f54..4ecdef8 100644 --- a/server/services/core/sqlite_db_service/tables/workspace_metadata.py +++ b/server/services/core/sqlite_db_service/tables/workspace_metadata.py @@ -13,7 +13,7 @@ class WorkspaceType(str, Enum): REMOTE = "remote" -class WorkspaceMetadata(Base): +class WorkspaceMetadataTable(Base): """ Table for workspace metadata. diff --git a/server/services/core/workspace_metadata_service.py b/server/services/core/workspace_metadata_service.py index 1839386..500b6a2 100644 --- a/server/services/core/workspace_metadata_service.py +++ b/server/services/core/workspace_metadata_service.py @@ -8,11 +8,11 @@ from server.const.err_enums import ErrCodes from server.exceptions import ServerException from server.models.workspace_metadata import ( - WorkspaceMetadataModel, + WorkspaceMetadata, ) from server.services.core.sqlite_db_service import DBService from server.services.core.sqlite_db_service.tables.workspace_metadata import ( - WorkspaceMetadata, + WorkspaceMetadataTable, WorkspaceType, ) @@ -27,15 +27,17 @@ def __init__(self, db_service: DBService): def get_workspaces( self, - ) -> list[WorkspaceMetadataModel]: + ) -> list[WorkspaceMetadata]: self.logger.info("Getting workspaces") with self._db_service.get_session() as session: - res = session.query(WorkspaceMetadata).all() + res = session.query( + WorkspaceMetadataTable + ).all() self.logger.info( f"Fetched {len(res)} workspaces" ) return list( - map(WorkspaceMetadataModel.from_table, res) + map(WorkspaceMetadata.from_table, res) ) def create_workspace_metadata( @@ -49,7 +51,7 @@ def create_workspace_metadata( f"Creating workspace metadata for {name}" ) - workspace_metadata = WorkspaceMetadataModel( + workspace_metadata = WorkspaceMetadata( uuid=uuid4().hex, name=name, description=description, @@ -74,18 +76,18 @@ def update_workspace_metadata( self.logger.info( f"Updating workspace metadata: {uuid}" ) - query: Select[Tuple[WorkspaceMetadata]] = ( - select(WorkspaceMetadata) - .where(WorkspaceMetadata.uuid == uuid) + query: Select[Tuple[WorkspaceMetadataTable]] = ( + select(WorkspaceMetadataTable) + .where(WorkspaceMetadataTable.uuid == uuid) .limit(1) ) with self._db_service.get_session() as session: - res: Result[Tuple[WorkspaceMetadata]] = ( + res: Result[Tuple[WorkspaceMetadataTable]] = ( session.execute(query) ) - item: Row[Tuple[WorkspaceMetadata]] | None = ( - res.one_or_none() - ) + item: ( + Row[Tuple[WorkspaceMetadataTable]] | None + ) = res.one_or_none() if item is None: err_msg = f"Workspace metadata with uuid {uuid} not found" self.logger.error(err_msg) @@ -107,19 +109,19 @@ def delete_workspace_metadata(self, uuid: str) -> None: f"Deleting workspace metadata: {uuid}" ) - query: Select[Tuple[WorkspaceMetadata]] = ( - select(WorkspaceMetadata) - .where(WorkspaceMetadata.uuid == uuid) + query: Select[Tuple[WorkspaceMetadataTable]] = ( + select(WorkspaceMetadataTable) + .where(WorkspaceMetadataTable.uuid == uuid) .limit(1) ) with self._db_service.get_session() as session: - res: Result[Tuple[WorkspaceMetadata]] = ( + res: Result[Tuple[WorkspaceMetadataTable]] = ( session.execute(query) ) - item: Row[Tuple[WorkspaceMetadata]] | None = ( - res.one_or_none() - ) + item: ( + Row[Tuple[WorkspaceMetadataTable]] | None + ) = res.one_or_none() if item is None: err_msg = f"Workspace metadata with uuid {uuid} not found" self.logger.error(err_msg) @@ -128,8 +130,8 @@ def delete_workspace_metadata(self, uuid: str) -> None: ErrCodes.WORKSPACE_METADATA_NOT_FOUND, ) session.execute( - delete(WorkspaceMetadata).where( - WorkspaceMetadata.uuid == uuid + delete(WorkspaceMetadataTable).where( + WorkspaceMetadataTable.uuid == uuid ) ) session.commit() diff --git a/server/services/core/workspace_service.py b/server/services/core/workspace_service.py new file mode 100644 index 0000000..e69de29 diff --git a/server/services/local/local_ontology_service.py b/server/services/local/local_ontology_service.py new file mode 100644 index 0000000..bf0c162 --- /dev/null +++ b/server/services/local/local_ontology_service.py @@ -0,0 +1,15 @@ +from kink import inject + +from server.service_protocols.fs_service_protocol import ( + FSServiceProtocol, +) +from server.services.local.local_fs_service import ( + LocalFSService, +) + + +@inject +class LocalOntologyService: + def __init__(self, fs_service: LocalFSService): + self.fs_service: FSServiceProtocol = fs_service + diff --git a/test/services/core/workspace_metadata_service_test.py b/test/services/core/workspace_metadata_service_test.py index 5bf0aab..bd46498 100644 --- a/test/services/core/workspace_metadata_service_test.py +++ b/test/services/core/workspace_metadata_service_test.py @@ -5,7 +5,7 @@ from server.exceptions import ServerException from server.services.core.sqlite_db_service import DBService from server.services.core.sqlite_db_service.tables.workspace_metadata import ( - WorkspaceMetadata, + WorkspaceMetadataTable, WorkspaceType, ) from server.services.core.workspace_metadata_service import ( @@ -47,13 +47,13 @@ def test_get_workspaces(self): self.assertEqual(result, []) session_mock.query.assert_called_once_with( - WorkspaceMetadata + WorkspaceMetadataTable ) def test_update_workspace_metadata(self): session_mock = MagicMock() self.db_service.get_session.return_value.__enter__.return_value = session_mock - session_mock.execute.return_value.one_or_none.return_value = WorkspaceMetadata( + session_mock.execute.return_value.one_or_none.return_value = WorkspaceMetadataTable( uuid="test-uuid" ) @@ -85,7 +85,7 @@ def test_update_workspace_metadata_not_found(self): def test_delete_workspace_metadata(self): session_mock = MagicMock() self.db_service.get_session.return_value.__enter__.return_value = session_mock - session_mock.execute.return_value.one_or_none.return_value = WorkspaceMetadata( + session_mock.execute.return_value.one_or_none.return_value = WorkspaceMetadataTable( uuid="test-uuid" )