Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dossier to fragment #587

Merged
merged 9 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env

- name: Install
id: install
run: |
pip install --upgrade pip
pip install poetry
poetry install --no-root

Expand Down Expand Up @@ -85,4 +91,4 @@ jobs:
push: true
tags: |
ebl.badw.de/ebl-api:master
${{format('ebl.badw.de/ebl-api:master.{0}', github.run_number)}}
${{format('ebl.badw.de/ebl-api:master.{0}', github.run_number)}}
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM pypy:3.9-7.3.10

RUN pip install --upgrade pip
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN pip install poetry

EXPOSE 8000
Expand All @@ -16,3 +19,4 @@ COPY ./docs ./docs
RUN chmod -R a-wx ./docs

CMD ["poetry", "run", "waitress-serve", "--port=8000", "--connection-limit=500", "--call", "ebl.app:get_app"]

6 changes: 6 additions & 0 deletions ebl/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@
from ebl.signs.infrastructure.mongo_sign_repository import MongoSignRepository
from ebl.signs.web.bootstrap import create_signs_routes
from ebl.afo_register.web.bootstrap import create_afo_register_routes
from ebl.dossiers.web.bootstrap import create_dossiers_routes
from ebl.transliteration.application.parallel_line_injector import ParallelLineInjector
from ebl.transliteration.infrastructure.mongo_parallel_repository import (
MongoParallelRepository,
)
from ebl.afo_register.infrastructure.mongo_afo_register_repository import (
MongoAfoRegisterRepository,
)
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
MongoDossiersRepository,
)
from ebl.users.domain.user import Guest
from ebl.users.infrastructure.auth0 import Auth0Backend
from ebl.fragmentarium.infrastructure.mongo_findspot_repository import (
Expand Down Expand Up @@ -99,6 +103,7 @@ def create_context():
annotations_repository=MongoAnnotationsRepository(database),
lemma_repository=MongoLemmaRepository(database),
afo_register_repository=MongoAfoRegisterRepository(database),
dossiers_repository=MongoDossiersRepository(database),
findspot_repository=MongoFindspotRepository(database),
custom_cache=custom_cache,
cache=cache,
Expand Down Expand Up @@ -128,6 +133,7 @@ def create_app(context: Context, issuer: str = "", audience: str = ""):
create_lemmatization_routes(api, context)
create_markup_routes(api, context)
create_afo_register_routes(api, context)
create_dossiers_routes(api, context)

return api

Expand Down
4 changes: 2 additions & 2 deletions ebl/chronology/chronology.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@attr.s(auto_attribs=True, frozen=True)
class King:
order_global: int
order_global: float
group_with: int
dynasty_number: str
dynasty_name: str
Expand All @@ -30,7 +30,7 @@ def find_king_by_name(self, king_name: str) -> Optional[King]:


class KingSchema(Schema):
order_global = fields.Integer(data_key="orderGlobal")
order_global = fields.Float(data_key="orderGlobal")
group_with = fields.Integer(
data_key="groupWith", allow_none=True, load_default=None
)
Expand Down
2 changes: 2 additions & 0 deletions ebl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ebl.fragmentarium.infrastructure.mongo_findspot_repository import (
MongoFindspotRepository,
)
from ebl.dossiers.application.dossiers_repository import DossiersRepository


@attr.s(auto_attribs=True, frozen=True)
Expand All @@ -53,6 +54,7 @@ class Context:
cache: Cache
parallel_line_injector: ParallelLineInjector
afo_register_repository: AfoRegisterRepository
dossiers_repository: DossiersRepository

def get_bibliography(self):
return Bibliography(self.bibliography_repository, self.changelog)
Expand Down
14 changes: 14 additions & 0 deletions ebl/dossiers/application/dossiers_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Sequence
from abc import ABC, abstractmethod

from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)


class DossiersRepository(ABC):
@abstractmethod
def query_by_ids(self, ids: Sequence[str]) -> Sequence[DossierRecord]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def create(self, dossier_record: DossierRecord) -> str: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
19 changes: 19 additions & 0 deletions ebl/dossiers/domain/dossier_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import attr
from typing import Sequence, Optional

from ebl.common.domain.provenance import Provenance
from ebl.fragmentarium.domain.fragment import Script
from ebl.bibliography.domain.reference import ReferenceType


@attr.s(frozen=True, auto_attribs=True)
class DossierRecord:
id: str
description: Optional[str] = None
is_approximate_date: bool = False
year_range_from: Optional[int] = None
year_range_to: Optional[int] = None
related_kings: Sequence[float] = []
provenance: Optional[Provenance] = None
script: Optional[Script] = None
references: Sequence[ReferenceType] = []
59 changes: 59 additions & 0 deletions ebl/dossiers/infrastructure/mongo_dossiers_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from typing import Sequence
from marshmallow import Schema, fields, post_load, EXCLUDE
from pymongo.database import Database
from ebl.mongo_collection import MongoCollection
from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)
from ebl.dossiers.application.dossiers_repository import DossiersRepository
from ebl.common.domain.provenance import Provenance
from ebl.fragmentarium.application.fragment_fields_schemas import ScriptSchema
from ebl.schemas import NameEnumField
from ebl.bibliography.domain.reference import ReferenceType

COLLECTION = "dossier"

provenance_field = fields.Function(
lambda object_: getattr(object_.provenance, "long_name", None),
lambda value: Provenance.from_name(value) if value else None,
allow_none=True,
)


class DossierRecordSchema(Schema):
class Meta:
unknown = EXCLUDE

id = fields.String(required=True, unique=True, data_key="_id")
description = fields.String(load_default=None)
is_approximate_date = fields.Boolean(
data_key="isApproximateDate", load_default=False
)
year_range_from = fields.Integer(
data_key="yearRangeFrom", allow_none=True, load_default=None
)
year_range_to = fields.Integer(
data_key="yearRangeTo", allow_none=True, load_default=None
)
related_kings = fields.List(
fields.Float(), data_key="relatedKings", load_default=list
)
provenance = provenance_field
script = fields.Nested(ScriptSchema, allow_none=True, load_default=None)
references = fields.List(NameEnumField(ReferenceType), load_default=list)

@post_load
def make_record(self, data, **kwargs):
return DossierRecord(**data)


class MongoDossiersRepository(DossiersRepository):
def __init__(self, database: Database):
self._collection = MongoCollection(database, COLLECTION)

def query_by_ids(self, ids: Sequence[str]) -> Sequence[DossierRecord]:
cursor = self._collection.find_many({"_id": {"$in": ids}})
return DossierRecordSchema(many=True).load(cursor)

def create(self, dossier_record: DossierRecord) -> str:
return self._collection.insert_one(DossierRecordSchema().dump(dossier_record))
11 changes: 11 additions & 0 deletions ebl/dossiers/web/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import falcon
from ebl.context import Context

from ebl.dossiers.web.dossier_records import (
DossiersResource,
)


def create_dossiers_routes(api: falcon.App, context: Context):
dossier_resourse = DossiersResource(context.dossiers_repository)
api.add_route("/dossiers", dossier_resourse)
24 changes: 24 additions & 0 deletions ebl/dossiers/web/dossier_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from falcon import Request, Response
from ebl.errors import NotFoundError
from marshmallow import EXCLUDE

from ebl.dossiers.application.dossiers_repository import DossiersRepository
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
DossierRecordSchema,
)


class DossiersResource:
def __init__(self, _dossiersRepository: DossiersRepository):
self._dossiersRepository = _dossiersRepository

def on_get(self, req: Request, resp: Response) -> None:
try:
dossiers = self._dossiersRepository.query_by_ids(
req.params["ids"].split(",")
)
except ValueError as error:
raise NotFoundError(
f"No dossier records matching {str(req.params)} found."
) from error
resp.media = DossierRecordSchema(unknown=EXCLUDE, many=True).dump(dossiers)
2 changes: 1 addition & 1 deletion ebl/fragmentarium/application/annotations_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from marshmallow import Schema, fields, post_load, post_dump
import pydash
from ebl.fragmentarium.application.cropped_sign_image import CroppedSignSchema
from ebl.fragmentarium.application.fragment_schema import ScriptSchema
from ebl.fragmentarium.application.fragment_fields_schemas import ScriptSchema
from ebl.fragmentarium.domain.annotation import (
Geometry,
AnnotationData,
Expand Down
Loading
Loading