diff --git a/src/omotes_rest/apis/api_dataclasses.py b/src/omotes_rest/apis/api_dataclasses.py index e7dfccd..0c68fe2 100644 --- a/src/omotes_rest/apis/api_dataclasses.py +++ b/src/omotes_rest/apis/api_dataclasses.py @@ -47,7 +47,7 @@ class JobInput: Schema: ClassVar[Type[Schema]] = Schema job_name: str = "job name" - workflow_type: str = "Draft Design - Quickscan Validation" + workflow_type: str = "grow_optimizer_no_heat_losses" user_name: str = "user name" input_esdl: str = "input ESDL base64string" project_name: str = "project name" diff --git a/src/omotes_rest/apis/job.py b/src/omotes_rest/apis/job.py index f00d0eb..0bc5fad 100644 --- a/src/omotes_rest/apis/job.py +++ b/src/omotes_rest/apis/job.py @@ -1,3 +1,4 @@ +import base64 import logging import uuid @@ -38,6 +39,10 @@ class JobAPI(MethodView): @api.response(200, JobStatusResponse.Schema()) def post(self, job_input: JobInput) -> JobStatusResponse: """Start new job: 'input_params_dict' can have lists and (nested) dicts as values.""" + esdlstr_bytes = job_input.input_esdl.encode("utf-8") + esdlstr_base64_bytes = base64.b64decode(esdlstr_bytes) + esdl_str = esdlstr_base64_bytes.decode("utf-8") + job_input.input_esdl = esdl_str return current_app.rest_if.submit_job(job_input) @api.response(200, JobSummary.Schema(many=True)) @@ -53,7 +58,16 @@ class JobFromIdAPI(MethodView): @api.response(200, JobResponse.Schema()) def get(self, job_id: str) -> JobRest | None: """Return job details.""" - return current_app.rest_if.get_job(uuid.UUID(job_id)) + job = current_app.rest_if.get_job(uuid.UUID(job_id)) + if job: + input_esdl = job.input_esdl + if input_esdl: + job.input_esdl = base64.b64encode(bytes(input_esdl, "utf-8")).decode("utf-8") + + output_esdl = job.output_esdl + if output_esdl: + job.output_esdl = base64.b64encode(bytes(output_esdl, "utf-8")).decode("utf-8") + return job @api.response(200, JobDeleteResponse.Schema()) def delete(self, job_id: str) -> JobDeleteResponse: @@ -102,6 +116,8 @@ def get(self, job_id: str) -> JobResultResponse: """Return job result with output ESDL (can be None).""" job_uuid = uuid.UUID(job_id) output_esdl = current_app.rest_if.get_job_output_esdl(job_uuid) + if output_esdl: + output_esdl = base64.b64encode(bytes(output_esdl, "utf-8")).decode("utf-8") return JobResultResponse(job_id=job_uuid, output_esdl=output_esdl)