Skip to content

Commit

Permalink
Merge pull request #310 from GispoCoding/239-paluusanoman-käsittely
Browse files Browse the repository at this point in the history
239 paluusanoman käsittely
  • Loading branch information
Rikuoja committed Aug 26, 2024
2 parents 417a3ca + f4fe945 commit 2dae72f
Show file tree
Hide file tree
Showing 25 changed files with 3,162 additions and 313 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pytest:
docker compose -f docker-compose.dev.yml build db_manager koodistot_loader ryhti_client
cd database; pytest

pytest-fail:
docker-compose -f docker-compose.dev.yml down -v
docker-compose -f docker-compose.dev.yml build db_manager koodistot_loader ryhti_client
cd database; pytest --maxfail=1

rebuild:
docker compose -f docker-compose.dev.yml down -v
docker compose -f docker-compose.dev.yml build db_manager koodistot_loader ryhti_client
Expand Down
85 changes: 85 additions & 0 deletions database/codes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from typing import Type

from models import CodeBase
from sqlalchemy.orm import Session


class LifeCycleStatus(CodeBase):
Expand Down Expand Up @@ -192,3 +195,85 @@ class TypeOfProcessingEvent(CodeBase):

__tablename__ = "type_of_processing_event"
code_list_uri = "http://uri.suomi.fi/codelist/rytj/kaavakastap"


class TypeOfDecisionMaker(CodeBase):
"""
Päätöksentekijän laji
"""

__tablename__ = "type_of_decision_maker"
code_list_uri = "http://uri.suomi.fi/codelist/rytj/PaatoksenTekija"


def get_code(session: Session, code_class: Type[CodeBase], value: str) -> CodeBase:
return session.query(code_class).filter_by(value=value).first()


decisions_by_status = {
# Some lifecycle statuses require decisions, some don't.
# Plan decision code depends on lifecycle status:
# https://ryhti.syke.fi/wp-content/uploads/sites/2/2023/11/Kaavatiedon-validointisaannot-ja-paluuarvot.pdf
"02": [
"01",
"02",
"03",
], # lifecycle/req-codelist-plandecision-name-codevalue-pending
"03": [
"04",
"05",
"06",
], # lifecycle/req-codelist-plandecision-name-codevalue-preparation
"04": ["07", "08"], # lifecycle/req-codelist-plandecision-name-codevalue-proposal
"05": ["07", "09"], # lifecycle/req-codelist-regionalplan-decisionname-lifecycle-05
"06": [
"11A"
], # lifecycle/req-codelist-plandecision-name-alternative-codevalues-approved-spatialplan # noqa
"07": None, # lifecycle/req-planmatterdecision-not-allowed-07-09-lifecycles
"08": [
"12",
"13",
"15",
], # lifecycle/req-planmatterdecision-name-subject-appeal-lifecycle
"09": None, # lifecycle/req-planmatterdecision-not-allowed-07-09-lifecycles
}

processing_events_by_status = {
# Some lifecycle statuses require processing events, some don't.
# Processing event code depends on lifecycle status:
# https://ryhti.syke.fi/wp-content/uploads/sites/2/2023/11/Kaavatiedon-validointisaannot-ja-paluuarvot.pdf
"02": ["04"], # lifecycle/req-codelist-handlingeventtype-codevalue-lifecycle
"03": ["05", "06"], # lifecycle/req-codelist-handlingeventtype-codevalue-lifecycle
"04": ["07", "08"], # lifecycle/req-codelist-plandecision-name-codevalue-proposal
"05": [
"08",
"09",
], # lifecycle/req-codelist-regionalplan-handlingeventtype-lifecycle-05
"06": [
"11"
], # lifecycle/req-codelist-regionalplan-handlingevent-approved-spatialplan
"11": ["13"], # not allowed in regional plan!
"13": ["16"], # lifecycle/req-codelist-handlingeventtype-codevalue-lifecycle
}


interaction_events_by_status = {
# Some lifecycle statuses require interaction events, some don't
# Interaction event code depends on lifecycle status:
# https://ryhti.syke.fi/wp-content/uploads/sites/2/2023/11/Kaavatiedon-validointisaannot-ja-paluuarvot.pdf
"03": ["01"], # lifecycle/req-codelist-interactionevent-codevalue-lifecycle
"04": [
"01"
], # lifecycle/req-codelist-regionalplan-interactionevent-display-proposal
"05": [
"01",
"02",
], # lifecycle/req-codelist-regionalplan-iteractioneventtype-lifecycle-05
}


decisionmaker_by_status = {
# TODO: Decisionmaker may depend on lifecycle status.
str(i).zfill(2): "01"
for i in range(1, 16)
}
6 changes: 5 additions & 1 deletion database/koodistot_loader/koodistot_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def update_or_create_object(
"""
Find object based on its unique fields, or create new object. Update fields
that are present in the incoming dict.
However, do *not* try to update uuids. They may have references to them already,
so we cannot set uuids, even if they are the same as before.
"""
columns = code_class.__table__.columns
unique_keys = set(column.key for column in columns if column.unique)
Expand All @@ -187,7 +190,8 @@ def update_or_create_object(
# This is because dirtying sqlalchemy objects happens via the __setattr__
# method, so we will have to update instance fields one by one.
for key, value in values.items():
setattr(instance, key, value)
if key != "id":
setattr(instance, key, value)
else:
instance = code_class(**values)
session.add(instance)
Expand Down
9 changes: 9 additions & 0 deletions database/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
generate_add_plan_id_fkey_triggers,
generate_modified_at_triggers,
generate_new_lifecycle_date_triggers,
generate_new_lifecycle_status_triggers,
generate_update_lifecycle_status_triggers,
generate_validate_polygon_geometry_triggers,
trg_add_intersecting_other_area_geometries,
Expand All @@ -34,6 +35,12 @@
update_lifecycle_status_trgfuncs,
) = generate_update_lifecycle_status_triggers()

(
new_lifecycle_status_trgs,
new_lifecycle_status_trgfuncs,
) = generate_new_lifecycle_status_triggers()


add_plan_id_fkey_trgs, add_plan_id_fkey_trgfuncs = generate_add_plan_id_fkey_triggers()
(
validate_polygon_geometry_trgs,
Expand All @@ -47,6 +54,8 @@
+ new_lifecycle_date_trgfuncs
+ update_lifecycle_status_trgs
+ update_lifecycle_status_trgfuncs
+ new_lifecycle_status_trgs
+ new_lifecycle_status_trgfuncs
+ add_plan_id_fkey_trgs
+ add_plan_id_fkey_trgfuncs
+ validate_polygon_geometry_trgs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""add to_be_exported to plan
Revision ID: c84f695b3d22
Revises: 0da11d97b6cb
Create Date: 2024-05-21 18:23:40.322147
"""
from typing import Sequence, Union

import geoalchemy2
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "c84f695b3d22"
down_revision: Union[str, None] = "feb5395835bb"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"plan",
sa.Column("to_be_exported", sa.Boolean(), server_default="f", nullable=False),
schema="hame",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("plan", "to_be_exported", schema="hame")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""add decisionmaker type
Revision ID: 759353efdfdb
Revises: c84f695b3d22
Create Date: 2024-06-04 17:54:58.513232
"""
from typing import Sequence, Union

import geoalchemy2
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "759353efdfdb"
down_revision: Union[str, None] = "c84f695b3d22"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"type_of_decision_maker",
sa.Column("value", sa.String(), nullable=False),
sa.Column("short_name", sa.String(), server_default="", nullable=False),
sa.Column(
"name",
postgresql.JSONB(astext_type=sa.Text()),
server_default='{"fin": "", "swe": "", "eng": ""}',
nullable=False,
),
sa.Column(
"description",
postgresql.JSONB(astext_type=sa.Text()),
server_default='{"fin": "", "swe": "", "eng": ""}',
nullable=False,
),
sa.Column("status", sa.String(), nullable=False),
sa.Column("level", sa.Integer(), server_default="1", nullable=False),
sa.Column("parent_id", sa.UUID(as_uuid=False), nullable=True),
sa.Column(
"id",
sa.UUID(as_uuid=False),
server_default=sa.text("gen_random_uuid()"),
nullable=False,
),
sa.Column(
"created_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"modified_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["parent_id"],
["codes.type_of_decision_maker.id"],
name="type_of_decision_maker_parent_id_fkey",
),
sa.PrimaryKeyConstraint("id"),
schema="codes",
)
op.create_index(
op.f("ix_codes_type_of_decision_maker_level"),
"type_of_decision_maker",
["level"],
unique=False,
schema="codes",
)
op.create_index(
op.f("ix_codes_type_of_decision_maker_parent_id"),
"type_of_decision_maker",
["parent_id"],
unique=False,
schema="codes",
)
op.create_index(
op.f("ix_codes_type_of_decision_maker_short_name"),
"type_of_decision_maker",
["short_name"],
unique=False,
schema="codes",
)
op.create_index(
op.f("ix_codes_type_of_decision_maker_value"),
"type_of_decision_maker",
["value"],
unique=True,
schema="codes",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("ix_codes_type_of_decision_maker_value"),
table_name="type_of_decision_maker",
schema="codes",
)
op.drop_index(
op.f("ix_codes_type_of_decision_maker_short_name"),
table_name="type_of_decision_maker",
schema="codes",
)
op.drop_index(
op.f("ix_codes_type_of_decision_maker_parent_id"),
table_name="type_of_decision_maker",
schema="codes",
)
op.drop_index(
op.f("ix_codes_type_of_decision_maker_level"),
table_name="type_of_decision_maker",
schema="codes",
)
op.drop_table("type_of_decision_maker", schema="codes")
# ### end Alembic commands ###
Loading

0 comments on commit 2dae72f

Please sign in to comment.