Skip to content

Commit

Permalink
🚧 [#15] Keep structure of expanded data from OZ
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed May 14, 2024
1 parent afd7eaa commit 3ddcdfc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"djangorestframework_camel_case.parser.CamelCaseMultiPartParser",
],
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"JSON_UNDERSCOREIZE": {"ignore_keys": ("_expand",)},
}


Expand Down
14 changes: 9 additions & 5 deletions backend/src/openarchiefbeheer/zaken/api/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ZaakFilter(FilterSet):
"If True, only cases not already included in a destruction list are returned."
),
)
resultaat__resultaattype__url = CharFilter(
_expand__resultaat__resultaattype = CharFilter(
help_text=_("Filter on the exact URL of resultaattype."),
)
bewaartermijn = CharFilter(
Expand All @@ -36,7 +36,7 @@ class ZaakFilter(FilterSet):
method="filter_vcs",
help_text=_(
"Filter on VCS. This stands for 'Vernietigings-Categorie Selectielijst'. "
"It is obtained through 'zaak.zaaktype.procestype.nummer'."
"It is obtained through 'zaaktype.procestype.nummer'."
),
decimal_places=0,
)
Expand All @@ -45,7 +45,7 @@ class ZaakFilter(FilterSet):
method="filter_heeft_relaties",
help_text=_(
"Filter on whether this case has other related cases. "
"This is done by looking at the property 'zaak.relevanteAndereZaken'."
"This is done by looking at the property 'relevanteAndereZaken'."
),
)

Expand Down Expand Up @@ -112,12 +112,16 @@ def filter_bewaartermijn(
self, queryset: QuerySet[Zaak], name: str, value: str
) -> QuerySet[Zaak]:
# TODO it would be nice to do comparisons for periods such as gt/lt
return queryset.filter(resultaat__resultaattype__archiefactietermijn=value)
return queryset.filter(
_expand__resultaat__resultaattype__archiefactietermijn=value
)

def filter_vcs(
self, queryset: QuerySet[Zaak], name: str, value: Decimal
) -> QuerySet[Zaak]:
return queryset.filter(zaaktype__selectielijst_procestype__nummer=int(value))
return queryset.filter(
_expand__zaaktype__selectielijst_procestype__nummer=int(value)
)

def filter_heeft_relaties(
self, queryset: QuerySet[Zaak], name: str, value: bool
Expand Down
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/zaken/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ class Meta:
"vertrouwelijkheidaanduiding",
"uiterlijke_einddatum_afdoening",
"verantwoordelijke_organisatie",
"_expand",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.11 on 2024-05-14 12:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("zaken", "0002_alter_zaak_resultaat_and_zaak_zaaktype"),
]

operations = [
migrations.AddField(
model_name="zaak",
name="_expand",
field=models.JSONField(
blank=True, default=dict, null=True, verbose_name="expand"
),
),
migrations.AlterField(
model_name="zaak",
name="resultaat",
field=models.URLField(blank=True, null=True, verbose_name="resultaat"),
),
migrations.AlterField(
model_name="zaak",
name="zaaktype",
field=models.URLField(blank=True, null=True, verbose_name="zaaktype"),
),
]
5 changes: 3 additions & 2 deletions backend/src/openarchiefbeheer/zaken/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Zaak(models.Model):
models.URLField("rollen", max_length=1000, blank=True), null=True, blank=True
)
status = models.URLField("status", max_length=1000, blank=True, null=True)
zaaktype = models.JSONField("zaaktype", blank=True, null=True)
zaaktype = models.URLField("zaaktype", blank=True, null=True)
deelzaken = ArrayField(
models.URLField("deelzaken", max_length=1000, blank=True),
null=True,
Expand All @@ -19,7 +19,7 @@ class Zaak(models.Model):
einddatum = models.DateField("einddatum", blank=True, null=True)
hoofdzaak = models.URLField("hoofdzaak", max_length=1000, blank=True, null=True)
kenmerken = models.JSONField("kenmerken", blank=True, null=True)
resultaat = models.JSONField("resultaat", blank=True, null=True)
resultaat = models.URLField("resultaat", blank=True, null=True)
startdatum = models.DateField("startdatum")
verlenging = models.JSONField("verlenging", blank=True, null=True)
opschorting = models.JSONField("opschorting", blank=True, null=True)
Expand Down Expand Up @@ -93,6 +93,7 @@ class Zaak(models.Model):
verantwoordelijke_organisatie = models.CharField(
"verantwoordelijke organisatie", max_length=9
)
_expand = models.JSONField("expand", blank=True, null=True, default=dict)

class Meta:
verbose_name = "Zaak"
Expand Down
18 changes: 5 additions & 13 deletions backend/src/openarchiefbeheer/zaken/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,19 @@ def get_procestype(url: str) -> dict | None:


def process_expanded_data(zaken: list[dict]) -> list[dict]:
def _format_expanded_data(zaak: dict) -> dict:
def expand_procestype(zaak: dict) -> dict:
if "_expand" not in zaak:
return zaak

extra_data = zaak["_expand"]

zaak["zaaktype"] = extra_data["zaaktype"]
if procestype_url := zaak["zaaktype"].get("selectielijst_procestype"):
if procestype_url := extra_data["zaaktype"].get("selectielijst_procestype"):
expanded_procestype = get_procestype(procestype_url)
if expanded_procestype is not None:
zaak["zaaktype"]["selectielijst_procestype"] = expanded_procestype

if "resultaat" in extra_data:
resultaat = extra_data["resultaat"]
resultaat_extra_data = resultaat.pop("_expand")
resultaat["resultaattype"] = resultaat_extra_data["resultaattype"]
zaak["resultaat"] = resultaat
extra_data["zaaktype"]["selectielijst_procestype"] = expanded_procestype

return zaak

with parallel() as executor:
zaken_with_expanded_info = list(executor.map(_format_expanded_data, zaken))
processed_zaken = list(executor.map(expand_procestype, zaken))

return zaken_with_expanded_info
return processed_zaken

0 comments on commit 3ddcdfc

Please sign in to comment.