Skip to content

Commit

Permalink
GLD BulkUpload enable
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenHosper committed Dec 18, 2024
1 parent fe7c90f commit 27214f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
40 changes: 24 additions & 16 deletions api/bro_upload/gld_bulk_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def process(self) -> None:
self.bulk_upload_instance.save()

# Step 2: Prepare data for uploadtask per row
uploadtask_metadata = { # noqa: F841
uploadtask_metadata = {
"qualityRegime": self.bulk_upload_instance.metadata["qualityRegime"],
"requestReference": self.bulk_upload_instance.metadata["requestReference"],
}
Expand Down Expand Up @@ -136,32 +136,40 @@ def process(self) -> None:
measurement_tvps, self.bulk_upload_instance.sourcedocument_data
)

self.bulk_upload_instance.sourcedocument_data = uploadtask_sourcedocument_dict
upload_task = api_models.UploadTask.objects.create(
data_owner=self.bulk_upload_instance.data_owner,
bro_domain="GLD",
project_number=self.bulk_upload_instance.project_number,
registration_type="GLD_Addition",
request_type="registration",
metadata=uploadtask_metadata,
sourcedocument_data=uploadtask_sourcedocument_dict,
)

self.bulk_upload_instance.progress = 50.00
self.bulk_upload_instance.save()

# Wait while the GLD_Addition is being processed
time.sleep(10)
# upload_task.refresh_from_db()
upload_task.refresh_from_db()

# if upload_task.status in ["COMPLETED", "FAILED"]:
# self.bulk_upload_instance.progress = 100.00
if upload_task.status in ["COMPLETED", "FAILED"]:
self.bulk_upload_instance.progress = 100.00

# if upload_task.status == "COMPLETED":
# self.bulk_upload_instance.status = "FINISHED"
if upload_task.status == "COMPLETED":
self.bulk_upload_instance.status = "FINISHED"

# elif upload_task.status == "FAILED":
# self.bulk_upload_instance.status = "FAILED"
# self.bulk_upload_instance.log += f"Upload logging: {upload_task.log}."
elif upload_task.status == "FAILED":
self.bulk_upload_instance.status = "FAILED"
self.bulk_upload_instance.log += f"Upload logging: {upload_task.log}."

# else:
# self.bulk_upload_instance.status = "UNFINISHED"
# self.bulk_upload_instance.log += (
# "After 10 seconds the upload is not yet finished."
# )
else:
self.bulk_upload_instance.status = "UNFINISHED"
self.bulk_upload_instance.log += (
"After 10 seconds the upload is not yet finished."
)

# self.bulk_upload_instance.save()
self.bulk_upload_instance.save()


def csv_or_excel_to_df(file_instance: T) -> pl.DataFrame:
Expand Down
10 changes: 6 additions & 4 deletions api/bro_upload/upload_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ class GLDBulkUploadMetadata(BaseModel):
qualityRegime: str
deliveryAccountableParty: str | None = None
broId: str
# For Addition (Procedure data)


class GLDBulkUploadSourcedocumentData(BaseModel):
validationStatus: str | None = None
investigatorKvk: str
observationType: str
evaluationProcedure: str
measurementInstrumentType: str
processReference: str
airPressureCompensationType: str | None = None
beginPosition: str
endPosition: str
resultTime: str
beginPosition: str | None = None
endPosition: str | None = None
resultTime: str | None = None


# GMN sourcedocs_data
Expand Down
4 changes: 4 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from api.bro_upload.upload_datamodels import (
GARBulkUploadMetadata,
GLDBulkUploadMetadata,
GLDBulkUploadSourcedocumentData,
UploadTaskMetadata,
)
from api.choices import registration_type_datamodel_mapping
Expand Down Expand Up @@ -582,6 +583,9 @@ def create(self, request):
# Check data with pydantic models:
try:
GLDBulkUploadMetadata(**serializer.validated_data["metadata"])
GLDBulkUploadSourcedocumentData(
**serializer.validated_data["sourcedocument_data"]
)
except ValidationError as e:
errors = utils.simplify_validation_errors(e.errors())
return Response({"detail": errors}, status=status.HTTP_400_BAD_REQUEST)
Expand Down

0 comments on commit 27214f2

Please sign in to comment.