-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f4602a
Update `Dockerfile`
khoidt 17dee98
Update `main.yml`
khoidt 235aa15
Implement dossier classes & tests (WiP)
khoidt 1e89adb
Update & add tests (WiP)
khoidt 5415cd8
Update & fix test
khoidt 2cf6830
Update & add tests
khoidt fa677bc
Update & add test
khoidt 8d636a4
Implement batch queries & update
khoidt c028dc0
Add dossier to fragment, update & refactor
khoidt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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]: ... | ||
|
||
@abstractmethod | ||
def create(self, dossier_record: DossierRecord) -> str: ... | ||
Check notice Code scanning / CodeQL Statement has no effect Note
This statement has no effect.
|
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,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] = [] |
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,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)) |
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,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) |
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,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) |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Statement has no effect Note