Skip to content

Commit

Permalink
Add dossier to fragment, update & refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Dec 11, 2024
1 parent 8d636a4 commit c028dc0
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 162 deletions.
2 changes: 1 addition & 1 deletion ebl/dossiers/application/dossiers_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DossiersRepository(ABC):
@abstractmethod
def query_by_ids(self, ids: Sequence[str]) -> DossierRecord: ...
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.
2 changes: 1 addition & 1 deletion ebl/dossiers/infrastructure/mongo_dossiers_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)
from ebl.dossiers.application.dossiers_repository import DossiersRepository
from ebl.common.domain.provenance import Provenance
from ebl.fragmentarium.application.fragment_schema import ScriptSchema
from ebl.fragmentarium.application.fragment_fields_schemas import ScriptSchema
from ebl.schemas import NameEnumField
from ebl.bibliography.domain.reference import ReferenceType

Expand Down
4 changes: 3 additions & 1 deletion ebl/dossiers/web/dossier_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def __init__(self, _dossiersRepository: DossiersRepository):

def on_get(self, req: Request, resp: Response) -> None:
try:
dossiers = self._dossiersRepository.query_by_ids(req.params["ids"].split(","))
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."
Expand Down
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
164 changes: 164 additions & 0 deletions ebl/fragmentarium/application/fragment_fields_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import pydash
from marshmallow import Schema, fields, post_dump, post_load, EXCLUDE
from ebl.fragmentarium.domain.folios import Folio, Folios
from ebl.fragmentarium.domain.fragment import (
Introduction,
Notes,
Measure,
UncuratedReference,
Script,
DossierReference,
)
from ebl.fragmentarium.domain.record import Record, RecordEntry, RecordType
from ebl.schemas import ValueEnumField
from ebl.transliteration.application.note_line_part_schemas import (
OneOfNoteLinePartSchema,
)
from ebl.common.domain.period import Period, PeriodModifier
from ebl.fragmentarium.domain.fragment_external_numbers import ExternalNumbers


class MeasureSchema(Schema):
value = fields.Float(load_default=None)
note = fields.String(load_default=None)

@post_load
def make_measure(self, data, **kwargs):
return Measure(**data)

@post_dump
def filter_none(self, data, **kwargs):
return pydash.omit_by(data, pydash.is_none)


class RecordEntrySchema(Schema):
user = fields.String(required=True)
type = ValueEnumField(RecordType, required=True)
date = fields.String(required=True)

@post_load
def make_record_entry(self, data, **kwargs):
return RecordEntry(**data)


class RecordSchema(Schema):
entries = fields.Nested(RecordEntrySchema, many=True, required=True)

@post_load
def make_record(self, data, **kwargs):
return Record(tuple(data["entries"]))


class FolioSchema(Schema):
name = fields.String(required=True)
number = fields.String(required=True)

@post_load
def make_record_entry(self, data, **kwargs):
return Folio(**data)


class FoliosSchema(Schema):
entries = fields.Nested(FolioSchema, many=True, required=True)

@post_load
def make_folio(self, data, **kwargs):
return Folios(tuple(data["entries"]))


class UncuratedReferenceSchema(Schema):
document = fields.String(required=True)
pages = fields.List(fields.Integer(), required=True)

@post_load
def make_uncurated_reference(self, data, **kwargs):
data["pages"] = tuple(data["pages"])
return UncuratedReference(**data)


class MarkupTextSchema(Schema):
text = fields.String(required=True)
parts = fields.List(fields.Nested(OneOfNoteLinePartSchema), required=True)


class IntroductionSchema(MarkupTextSchema):
@post_load
def make_introduction(self, data, **kwargs) -> Introduction:
return Introduction(data["text"], tuple(data["parts"]))


class NotesSchema(MarkupTextSchema):
@post_load
def make_notes(self, data, **kwargs) -> Notes:
return Notes(data["text"], tuple(data["parts"]))


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

period = fields.Function(
lambda script: script.period.long_name,
lambda value: Period.from_name(value),
required=True,
)
period_modifier = ValueEnumField(
PeriodModifier, required=True, data_key="periodModifier"
)
uncertain = fields.Boolean(load_default=None)
sort_key = fields.Function(
lambda script: script.period.sort_key, data_key="sortKey", dump_only=True
)

@post_load
def make_script(self, data, **kwargs) -> Script:
return Script(**data)


class ExternalNumbersSchema(Schema):
cdli_number = fields.String(load_default="", data_key="cdliNumber")
bm_id_number = fields.String(load_default="", data_key="bmIdNumber")
archibab_number = fields.String(load_default="", data_key="archibabNumber")
bdtns_number = fields.String(load_default="", data_key="bdtnsNumber")
chicago_isac_number = fields.String(load_default="", data_key="chicagoIsacNumber")
ur_online_number = fields.String(load_default="", data_key="urOnlineNumber")
hilprecht_jena_number = fields.String(
load_default="", data_key="hilprechtJenaNumber"
)
hilprecht_heidelberg_number = fields.String(
load_default="", data_key="hilprechtHeidelbergNumber"
)
metropolitan_number = fields.String(load_default="", data_key="metropolitanNumber")
yale_peabody_number = fields.String(load_default="", data_key="yalePeabodyNumber")
louvre_number = fields.String(load_default="", data_key="louvreNumber")
dublin_tcd_number = fields.String(load_default="", data_key="dublinTcdNumber")
alalah_hpm_number = fields.String(load_default="", data_key="alalahHpmNumber")
philadelphia_number = fields.String(load_default="", data_key="philadelphiaNumber")
australianinstituteofarchaeology_number = fields.String(
load_default="", data_key="australianinstituteofarchaeologyNumber"
)
achemenet_number = fields.String(load_default="", data_key="achemenetNumber")
nabucco_number = fields.String(load_default="", data_key="nabuccoNumber")
oracc_numbers = fields.List(
fields.String(), load_default=(), data_key="oraccNumbers"
)
seal_numbers = fields.List(fields.String(), load_default=(), data_key="sealNumbers")

@post_load
def make_external_numbers(self, data, **kwargs) -> ExternalNumbers:
data["oracc_numbers"] = tuple(data["oracc_numbers"])
data["seal_numbers"] = tuple(data["seal_numbers"])
return ExternalNumbers(**data)

@post_dump
def omit_empty_numbers(self, data, **kwargs):
return pydash.omit_by(data, pydash.is_empty)


class DossierReferenceSchema(Schema):
dossierId = fields.String(required=True)
isUncertain = fields.Boolean(load_default=False)

@post_load
def make_dossier_reference(self, data, **kwargs) -> DossierReference:
return DossierReference(**data)
2 changes: 1 addition & 1 deletion ebl/fragmentarium/application/fragment_info_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ApiReferenceSchema,
)
from ebl.common.application.schemas import AccessionSchema
from ebl.fragmentarium.application.fragment_schema import ScriptSchema
from ebl.fragmentarium.application.fragment_fields_schemas import ScriptSchema
from ebl.fragmentarium.application.genre_schema import GenreSchema
from ebl.fragmentarium.domain.fragment_infos_pagination import FragmentInfosPagination
from ebl.transliteration.application.museum_number_schema import MuseumNumberSchema
Expand Down
Loading

0 comments on commit c028dc0

Please sign in to comment.