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

[#15] Return _expand field like Open Zaak #20

Merged
merged 2 commits into from
May 14, 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
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___expand__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
14 changes: 9 additions & 5 deletions backend/src/openarchiefbeheer/zaken/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,23 @@ def test_expanded_correctly(self, m):

zaak_with_resultaat = Zaak.objects.get(identificatie="ZAAK-01")

self.assertEqual(zaak_with_resultaat.resultaat["toelichting"], "Test result")
self.assertEqual(
zaak_with_resultaat.resultaat["resultaattype"],
zaak_with_resultaat._expand["resultaat"]["toelichting"], "Test result"
)
self.assertEqual(
zaak_with_resultaat._expand["resultaat"]["_expand"]["resultaattype"],
{
"url": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/bd84c463-fa65-46ef-8a9e-dd887e005aea",
},
)
self.assertEqual(
zaak_with_resultaat.zaaktype["url"],
zaak_with_resultaat._expand["zaaktype"]["url"],
"http://catalogue-api.nl/zaaktypen/111-111-111",
)
self.assertEqual(
zaak_with_resultaat.zaaktype["selectielijst_procestype"]["nummer"],
zaak_with_resultaat._expand["zaaktype"]["selectielijst_procestype"][
"nummer"
],
1,
)

Expand Down Expand Up @@ -244,6 +248,6 @@ def test_expand_no_selectielijst_service(self, m):
zaak = Zaak.objects.get(identificatie="ZAAK-01")

self.assertEqual(
zaak.zaaktype["selectielijst_procestype"],
zaak._expand["zaaktype"]["selectielijst_procestype"],
"https://selectielijst.openzaak.nl/api/v1/procestypen/e1b73b12-b2f6-4c4e-8929-94f84dd2a57d",
)
41 changes: 30 additions & 11 deletions backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ def test_using_query_params_to_filter(self):

def test_filter_resultaattype(self):
zaak_1 = ZaakFactory.create(
resultaat={
"resultaattype": {
"url": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/111-111-111"
_expand={
"resultaat": {
"resultaattype": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/111-111-111",
"_expand": {
"resultaattype": {
"url": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/111-111-111"
}
},
}
}
)
Expand All @@ -105,17 +110,22 @@ def test_filter_resultaattype(self):
) # Not expanded
ZaakFactory.create_batch(
2,
resultaat={
"resultaattype": {
"url": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/222-222-222"
_expand={
"resultaat": {
"resultaattype": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/222-222-222",
"_expand": {
"resultaattype": {
"url": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/222-222-222"
}
},
}
},
)

user = UserFactory(username="record_manager", role__can_start_destruction=True)

endpoint = furl(reverse("api:zaken-list"))
endpoint.args["resultaat__resultaattype__url"] = (
endpoint.args["_expand__resultaat__resultaattype"] = (
"http://catalogue-api.nl/catalogi/api/v1/resultaattypen/111-111-111"
)

Expand All @@ -129,13 +139,22 @@ def test_filter_resultaattype(self):

def test_filter_bewaartermijn(self):
zaak_1 = ZaakFactory.create(
resultaat={"resultaattype": {"archiefactietermijn": "P1D"}}
_expand={
"resultaat": {
"_expand": {"resultaattype": {"archiefactietermijn": "P1D"}}
}
}
)
ZaakFactory.create(
resultaat="http://zaken-api.nl/zaken/api/v1/resultaten/111-111-111"
) # Not expanded
ZaakFactory.create_batch(
2, resultaat={"resultaattype": {"archiefactietermijn": "P2D"}}
2,
_expand={
"resultaat": {
"_expand": {"resultaattype": {"archiefactietermijn": "P2D"}}
}
},
)

user = UserFactory(username="record_manager", role__can_start_destruction=True)
Expand All @@ -152,13 +171,13 @@ def test_filter_bewaartermijn(self):

def test_filter_vcs(self):
zaak_1 = ZaakFactory.create(
zaaktype={"selectielijst_procestype": {"nummer": 1}}
_expand={"zaaktype": {"selectielijst_procestype": {"nummer": 1}}}
)
ZaakFactory.create(
zaaktype="http://catalogue-api.nl/zaaktypen/111-111-111",
) # Not expanded
ZaakFactory.create_batch(
2, zaaktype={"selectielijst_procestype": {"nummer": 2}}
2, _expand={"zaaktype": {"selectielijst_procestype": {"nummer": 2}}}
)

user = UserFactory(username="record_manager", role__can_start_destruction=True)
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
Loading