Fixing broken document migration
* adds changes to document migration to correctly migrate documents
This commit is contained in:
parent
44e21f4ed9
commit
ae89f3d43c
@ -11,7 +11,7 @@ import json
|
||||
import pika
|
||||
import xmltodict
|
||||
from django.db.models import Sum
|
||||
from django.utils import formats
|
||||
from django.utils import formats, timezone
|
||||
|
||||
from intervention.settings import EGON_RABBITMQ_HOST, EGON_RABBITMQ_USER, EGON_RABBITMQ_PW, EGON_RABBITMQ_PORT
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
||||
@ -43,7 +43,6 @@ class EgonExporter:
|
||||
"nachricht": self.gml_builder.gml,
|
||||
}
|
||||
msg = json.dumps(msg)
|
||||
print(msg)
|
||||
credentials = pika.PlainCredentials(EGON_RABBITMQ_USER, EGON_RABBITMQ_PW)
|
||||
params = pika.ConnectionParameters(
|
||||
EGON_RABBITMQ_HOST,
|
||||
@ -59,6 +58,7 @@ class EgonExporter:
|
||||
body=msg.encode("utf-8"),
|
||||
)
|
||||
conn.close()
|
||||
print(f"Successfully sent EGON data for {self.intervention.identifier}")
|
||||
|
||||
|
||||
class EgonGmlBuilder:
|
||||
@ -164,6 +164,8 @@ class EgonGmlBuilder:
|
||||
payment_date = None
|
||||
if payment is not None:
|
||||
payment_date = payment.due_on
|
||||
if payment_date is None:
|
||||
payment_date = timezone.datetime.fromisoformat("1970-01-01")
|
||||
payment_date = payment_date.strftime(DEFAULT_DATE_FORMAT)
|
||||
|
||||
cons_office = self.intervention.responsible.conservation_office
|
||||
|
@ -3,7 +3,7 @@ from abc import abstractmethod
|
||||
import psycopg2
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.gis.geos import GEOSException, MultiPolygon, Polygon, MultiPoint, MultiLineString
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
from django.core.files.uploadedfile import UploadedFile
|
||||
from django.utils.timezone import make_aware
|
||||
|
||||
@ -95,16 +95,18 @@ class BaseMigrater:
|
||||
doc_title = "Migrierte Datei"
|
||||
doc_date = doc_date or "1970-01-01"
|
||||
|
||||
# Ensure problematic characters not present in lookup file name
|
||||
clean_file_name = file.name.replace("§", "")
|
||||
doc_file = self.__find_migrated_file_recursive(
|
||||
document_cls,
|
||||
instance,
|
||||
file.name
|
||||
clean_file_name
|
||||
)
|
||||
|
||||
if doc_file is not None:
|
||||
doc_file.delete()
|
||||
else:
|
||||
print(f"------ Could not find file, that should have been migrated already. Adding new version anyway: {doc_path}")
|
||||
print(f"------ Could not find file, that should have been migrated already for {instance.identifier}. Adding new version anyway: {doc_path}")
|
||||
|
||||
doc = document_cls.objects.create(
|
||||
title=doc_title,
|
||||
@ -132,6 +134,14 @@ class BaseMigrater:
|
||||
return self.__find_migrated_file_recursive(document_cls, instance, file_name_tmp)
|
||||
else:
|
||||
return None
|
||||
except MultipleObjectsReturned:
|
||||
doc_files = document_cls.objects.filter(
|
||||
instance=instance,
|
||||
file__icontains=file_name_tmp
|
||||
)
|
||||
for doc in doc_files:
|
||||
doc.delete()
|
||||
return None
|
||||
|
||||
def _migrate_log(self, instance, db_result: tuple):
|
||||
identifier = f"'{db_result[0]}'"
|
||||
|
@ -10,6 +10,7 @@ from codelist.settings import CODELIST_LAW_ID, CODELIST_PROCESS_TYPE_ID, CODELIS
|
||||
CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID
|
||||
from compensation.models import Payment
|
||||
from intervention.models import Intervention, InterventionDocument, Legal, Handler, Responsibility, Revocation
|
||||
from intervention.utils.egon_export import EgonExporter
|
||||
from konova.management.commands.kspMigrater.base_migrater import BaseMigrater
|
||||
from konova.settings import ETS_GROUP
|
||||
|
||||
@ -167,7 +168,8 @@ class InterventionMigrater(BaseMigrater):
|
||||
'zt.erlass as Zulassungsdatum, '
|
||||
'zt.rechtskraft as Bestandskraftdatum, '
|
||||
'zt.baubeginn as ersatzzahlungstermin, '
|
||||
'eiv.ersatzzahlung '
|
||||
'eiv.ersatzzahlung, '
|
||||
'v.status '
|
||||
'from "OBJ_MASTER" om '
|
||||
'left join "LINFOS" linf on om."GISPADID"=linf."GISPADID" '
|
||||
'left join eiv on om."GISPADID"=eiv.gispadid '
|
||||
@ -178,6 +180,7 @@ class InterventionMigrater(BaseMigrater):
|
||||
'left join adressrolle adr on om."GISPADID"=adr."GISPADID" '
|
||||
'left join "Aufwertung" auf on om."GISPADID"=auf."GISPADID" '
|
||||
'left join zulassungstermin zt on eiv.zulassung=zt.id '
|
||||
'left join vorgang v on om."GISPADID"=v.gispadid '
|
||||
'where '
|
||||
'om."OKL"=7730085 and '
|
||||
'om.archiv=false and '
|
||||
@ -206,6 +209,17 @@ class InterventionMigrater(BaseMigrater):
|
||||
#intervention = self._migrate_revocation(intervention, eiv)
|
||||
intervention.save()
|
||||
|
||||
process_state = eiv[18] or 0
|
||||
requested_state = process_state == 100 or process_state == 300 # 100='privat', 300='bereitgestellt'
|
||||
payments_exist = intervention.payments.exists()
|
||||
if requested_state and payments_exist:
|
||||
egon_exporter = EgonExporter(intervention)
|
||||
try:
|
||||
egon_exporter.export_to_rabbitmq()
|
||||
except TypeError as e:
|
||||
print(e)
|
||||
continue
|
||||
|
||||
#intervention = self._migrate_geometry(intervention, eiv)
|
||||
#intervention = self._migrate_intervention_payment(intervention, eiv)
|
||||
#intervention.save()
|
||||
|
Loading…
Reference in New Issue
Block a user