#132 WIP: EMA
* WIP: adds first implementation for EMA migration * fixes bug where not found files would case migration to fail
This commit is contained in:
parent
f8627930d8
commit
ac704bc930
@ -84,6 +84,7 @@ class BaseMigrater:
|
||||
doc_path = doc_result[0]
|
||||
doc_comment = doc_result[1]
|
||||
doc_date = doc_result[2]
|
||||
try:
|
||||
with open(doc_path, encoding="latin1") as file:
|
||||
file = UploadedFile(file)
|
||||
doc_title = "Migrierte Datei"
|
||||
@ -103,6 +104,7 @@ class BaseMigrater:
|
||||
date_of_creation=doc_date,
|
||||
instance=instance,
|
||||
)
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"------ !!! File not found: {doc_path}")
|
||||
tmp_cursor.close()
|
||||
return instance
|
@ -5,6 +5,7 @@ from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
|
||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID, CODELIST_COMPENSATION_ACTION_ID
|
||||
from compensation.models import Compensation, CompensationState, CompensationAction, UnitChoices, CompensationDocument
|
||||
from ema.models import Ema, EmaDocument
|
||||
from intervention.models import Responsibility, Handler, Intervention
|
||||
from konova.management.commands.kspMigrater.base_migrater import BaseMigrater
|
||||
from konova.models import Deadline, DeadlineType
|
||||
@ -409,3 +410,60 @@ class CompensationMigrater(BaseMigrater):
|
||||
|
||||
tmp_cursor.close()
|
||||
return compensation
|
||||
|
||||
|
||||
class EmaMigrater(CompensationMigrater):
|
||||
|
||||
def migrate(self):
|
||||
cursor = self.db_connection.cursor()
|
||||
cursor.execute(
|
||||
'select '
|
||||
'om."KENNUNG", '
|
||||
'linf."OBJBEZ", '
|
||||
'ST_AsEWKT(ST_Multi(ST_CollectionExtract(ST_MakeValid(ST_Transform(geomf.the_geom,4326)), 3))) as geomf, '
|
||||
'ST_AsEWKT(ST_Multi(ST_CollectionExtract(ST_MakeValid(ST_Transform(geoml.the_geom,4326)), 2))) as geoml, '
|
||||
'ST_AsEWKT(ST_Multi(ST_CollectionExtract(ST_MakeValid(ST_Transform(geomp.the_geom,4326)), 1))) as geomp, '
|
||||
'linf."Bemerkung" '
|
||||
'from "OBJ_MASTER" om '
|
||||
'left join "LINFOS" linf on om."GISPADID"=linf."GISPADID" '
|
||||
'left join kom on om."GISPADID"=kom.gispadid '
|
||||
'left join geometry_f geomf on om."GISPADID"=geomf.gispadid '
|
||||
'left join geometry_l geoml on om."GISPADID"=geoml.gispadid '
|
||||
'left join geometry_p geomp on om."GISPADID"=geomp.gispadid '
|
||||
'left join "Aufwertung" auf on om."GISPADID"=auf."GISPADID" '
|
||||
'where '
|
||||
'om."OKL"=7730090 and '
|
||||
'om.archiv=false and '
|
||||
'om.nicht_vollstaendig=0'
|
||||
)
|
||||
|
||||
all_emas = cursor.fetchall()
|
||||
len_all_emas = len(all_emas)
|
||||
num_processed = 0
|
||||
print(f"Migrate EMAs to emas...")
|
||||
print(f"--Found {len_all_emas} entries. Process now...")
|
||||
for ema in all_emas:
|
||||
if num_processed % 500 == 0:
|
||||
print(f"----{num_processed}/{len_all_emas} processed")
|
||||
|
||||
with transaction.atomic():
|
||||
ema_identifier = ema[0]
|
||||
ema_title = ema[1]
|
||||
ema_comment = ema[5]
|
||||
ema_obj = Ema.objects.get_or_create(
|
||||
identifier=ema_identifier
|
||||
)[0]
|
||||
|
||||
ema_obj.title = ema_title
|
||||
ema_obj.comment = ema_comment
|
||||
ema_obj = self._migrate_geometry(ema_obj, ema)
|
||||
ema_obj = self._migrate_responsibility(ema_obj, ema)
|
||||
ema_obj = self._migrate_compensation_type(ema_obj, ema)
|
||||
ema_obj = self._migrate_states(ema_obj, ema)
|
||||
ema_obj = self._migrate_deadlines(ema_obj, ema)
|
||||
ema_obj = self._migrate_actions(ema_obj, ema)
|
||||
ema_obj = self._migrate_documents(ema_obj, EmaDocument, ema)
|
||||
ema_obj.save()
|
||||
|
||||
num_processed += 1
|
||||
cursor.close()
|
||||
|
@ -1,4 +1,4 @@
|
||||
from konova.management.commands.kspMigrater.compensation_migrater import CompensationMigrater
|
||||
from konova.management.commands.kspMigrater.compensation_migrater import CompensationMigrater, EmaMigrater
|
||||
from konova.management.commands.kspMigrater.intervention_migrater import InterventionMigrater
|
||||
from konova.management.commands.setup import BaseKonovaCommand
|
||||
|
||||
@ -16,7 +16,8 @@ class Command(BaseKonovaCommand):
|
||||
try:
|
||||
migraters = [
|
||||
#InterventionMigrater(options),
|
||||
CompensationMigrater(options),
|
||||
#CompensationMigrater(options),
|
||||
EmaMigrater(options),
|
||||
]
|
||||
for migrater in migraters:
|
||||
migrater.migrate()
|
||||
|
Loading…
Reference in New Issue
Block a user