diff --git a/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/specs/v1/utils/ProcessSpecUtilsV1.java b/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/specs/v1/utils/ProcessSpecUtilsV1.java index 761baa5d..e339d957 100644 --- a/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/specs/v1/utils/ProcessSpecUtilsV1.java +++ b/qqq-middleware-javalin/src/main/java/com/kingsrook/qqq/middleware/javalin/specs/v1/utils/ProcessSpecUtilsV1.java @@ -28,6 +28,7 @@ import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import com.fasterxml.jackson.annotation.JsonInclude; import com.kingsrook.qqq.backend.core.actions.tables.InsertAction; import com.kingsrook.qqq.backend.core.actions.values.QValueFormatter; @@ -141,12 +142,14 @@ public class ProcessSpecUtilsV1 errorResponse.setError("Illegal Argument Exception: NaN"); errorResponse.setUserFacingError("The process could not be completed due to invalid input."); + Function responseToExample = response -> new Example().withValue(convertResponseToJSONObject(response).toMap()); + return MapBuilder.of(() -> new LinkedHashMap()) - .with("COMPLETE", new Example().withValue(completeResponse)) - .with("COMPLETE with metaDataAdjustment", new Example().withValue(completeResponseWithMetaDataAdjustment)) - .with("JOB_STARTED", new Example().withValue(jobStartedResponse)) - .with("RUNNING", new Example().withValue(runningResponse)) - .with("ERROR", new Example().withValue(errorResponse)) + .with("COMPLETE", responseToExample.apply(completeResponse)) + .with("COMPLETE with metaDataAdjustment", responseToExample.apply(completeResponseWithMetaDataAdjustment)) + .with("JOB_STARTED", responseToExample.apply(jobStartedResponse)) + .with("RUNNING", responseToExample.apply(runningResponse)) + .with("ERROR", responseToExample.apply(errorResponse)) .build(); } @@ -155,7 +158,21 @@ public class ProcessSpecUtilsV1 /*************************************************************************** ** ***************************************************************************/ - public static void handleOutput(Context context, ProcessInitOrStepOrStatusResponseV1 output) + public static void handleOutput(Context context, ProcessInitOrStepOrStatusResponseV1 response) + { + JSONObject outputJsonObject = convertResponseToJSONObject(response); + + String json = outputJsonObject.toString(3); + System.out.println(json); + context.result(json); + } + + + + /*************************************************************************** + ** + ***************************************************************************/ + private static JSONObject convertResponseToJSONObject(ProcessInitOrStepOrStatusResponseV1 response) { //////////////////////////////////////////////////////////////////////////////// // normally, we like the JsonUtils behavior of excluding null/empty elements. // @@ -163,7 +180,7 @@ public class ProcessSpecUtilsV1 // so, go through a loop of object → JSON String → JSONObject → String... // // also - work with the TypedResponse sub-object within this response class // //////////////////////////////////////////////////////////////////////////////// - ProcessInitOrStepOrStatusResponseV1.TypedResponse typedOutput = output.getTypedResponse(); + ProcessInitOrStepOrStatusResponseV1.TypedResponse typedOutput = response.getTypedResponse(); String outputJson = JsonUtils.toJson(typedOutput); JSONObject outputJsonObject = new JSONObject(outputJson); @@ -280,10 +297,7 @@ public class ProcessSpecUtilsV1 outputJsonObject.put("values", valuesAsJsonObject); } } - - String json = outputJsonObject.toString(3); - System.out.println(json); - context.result(json); + return outputJsonObject; } diff --git a/qqq-middleware-javalin/src/main/resources/openapi/v1/openapi.yaml b/qqq-middleware-javalin/src/main/resources/openapi/v1/openapi.yaml index f89ba784..e6772436 100644 --- a/qqq-middleware-javalin/src/main/resources/openapi/v1/openapi.yaml +++ b/qqq-middleware-javalin/src/main/resources/openapi/v1/openapi.yaml @@ -1652,66 +1652,61 @@ paths: examples: COMPLETE: value: - typedResponse: - nextStep: "reviewScreen" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "COMPLETE" - values: - totalAge: 32768 - firstLastName: "Aabramson" + values: + firstLastName: "Aabramson" + totalAge: 32768 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + nextStep: "reviewScreen" + type: "COMPLETE" COMPLETE with metaDataAdjustment: value: - typedResponse: - nextStep: "inputScreen" - processMetaDataAdjustment: - updatedFields: - someField: - displayFormat: "%s" - isEditable: true - isHeavy: false - isHidden: false - isRequired: true - name: "someField" - type: "STRING" - updatedFrontendStepList: - - components: - - type: "EDIT_FORM" - formFields: - - displayFormat: "%s" - isEditable: true - isHeavy: false - isHidden: false - isRequired: false - name: "someField" - type: "STRING" - name: "inputScreen" - - components: - - type: "PROCESS_SUMMARY_RESULTS" - name: "resultScreen" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "COMPLETE" - values: - totalAge: 32768 - firstLastName: "Aabramson" + values: + firstLastName: "Aabramson" + totalAge: 32768 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + nextStep: "inputScreen" + processMetaDataAdjustment: + updatedFields: + someField: + isRequired: true + isEditable: true + name: "someField" + displayFormat: "%s" + type: "STRING" + isHeavy: false + isHidden: false + updatedFrontendStepList: + - components: + - type: "EDIT_FORM" + name: "inputScreen" + formFields: + - isRequired: false + isEditable: true + name: "someField" + displayFormat: "%s" + type: "STRING" + isHeavy: false + isHidden: false + - components: + - type: "PROCESS_SUMMARY_RESULTS" + name: "resultScreen" + type: "COMPLETE" JOB_STARTED: value: - typedResponse: - jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "JOB_STARTED" + jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA" + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "JOB_STARTED" RUNNING: value: - typedResponse: - current: 47 - message: "Processing person records" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - total: 1701 - type: "RUNNING" + current: 47 + total: 1701 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "RUNNING" + message: "Processing person records" ERROR: value: - typedResponse: - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "RUNNING" + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "RUNNING" schema: $ref: "#/components/schemas/ProcessStepResponseV1" description: "State of the initialization of the job, with different fields\ @@ -1788,66 +1783,61 @@ paths: examples: COMPLETE: value: - typedResponse: - nextStep: "reviewScreen" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "COMPLETE" - values: - totalAge: 32768 - firstLastName: "Aabramson" + values: + firstLastName: "Aabramson" + totalAge: 32768 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + nextStep: "reviewScreen" + type: "COMPLETE" COMPLETE with metaDataAdjustment: value: - typedResponse: - nextStep: "inputScreen" - processMetaDataAdjustment: - updatedFields: - someField: - displayFormat: "%s" - isEditable: true - isHeavy: false - isHidden: false - isRequired: true - name: "someField" - type: "STRING" - updatedFrontendStepList: - - components: - - type: "EDIT_FORM" - formFields: - - displayFormat: "%s" - isEditable: true - isHeavy: false - isHidden: false - isRequired: false - name: "someField" - type: "STRING" - name: "inputScreen" - - components: - - type: "PROCESS_SUMMARY_RESULTS" - name: "resultScreen" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "COMPLETE" - values: - totalAge: 32768 - firstLastName: "Aabramson" + values: + firstLastName: "Aabramson" + totalAge: 32768 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + nextStep: "inputScreen" + processMetaDataAdjustment: + updatedFields: + someField: + isRequired: true + isEditable: true + name: "someField" + displayFormat: "%s" + type: "STRING" + isHeavy: false + isHidden: false + updatedFrontendStepList: + - components: + - type: "EDIT_FORM" + name: "inputScreen" + formFields: + - isRequired: false + isEditable: true + name: "someField" + displayFormat: "%s" + type: "STRING" + isHeavy: false + isHidden: false + - components: + - type: "PROCESS_SUMMARY_RESULTS" + name: "resultScreen" + type: "COMPLETE" JOB_STARTED: value: - typedResponse: - jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "JOB_STARTED" + jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA" + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "JOB_STARTED" RUNNING: value: - typedResponse: - current: 47 - message: "Processing person records" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - total: 1701 - type: "RUNNING" + current: 47 + total: 1701 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "RUNNING" + message: "Processing person records" ERROR: value: - typedResponse: - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "RUNNING" + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "RUNNING" schema: $ref: "#/components/schemas/ProcessStepResponseV1" description: "State of the backend's running of the next step(s) of the\ @@ -1895,66 +1885,61 @@ paths: examples: COMPLETE: value: - typedResponse: - nextStep: "reviewScreen" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "COMPLETE" - values: - totalAge: 32768 - firstLastName: "Aabramson" + values: + firstLastName: "Aabramson" + totalAge: 32768 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + nextStep: "reviewScreen" + type: "COMPLETE" COMPLETE with metaDataAdjustment: value: - typedResponse: - nextStep: "inputScreen" - processMetaDataAdjustment: - updatedFields: - someField: - displayFormat: "%s" - isEditable: true - isHeavy: false - isHidden: false - isRequired: true - name: "someField" - type: "STRING" - updatedFrontendStepList: - - components: - - type: "EDIT_FORM" - formFields: - - displayFormat: "%s" - isEditable: true - isHeavy: false - isHidden: false - isRequired: false - name: "someField" - type: "STRING" - name: "inputScreen" - - components: - - type: "PROCESS_SUMMARY_RESULTS" - name: "resultScreen" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "COMPLETE" - values: - totalAge: 32768 - firstLastName: "Aabramson" + values: + firstLastName: "Aabramson" + totalAge: 32768 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + nextStep: "inputScreen" + processMetaDataAdjustment: + updatedFields: + someField: + isRequired: true + isEditable: true + name: "someField" + displayFormat: "%s" + type: "STRING" + isHeavy: false + isHidden: false + updatedFrontendStepList: + - components: + - type: "EDIT_FORM" + name: "inputScreen" + formFields: + - isRequired: false + isEditable: true + name: "someField" + displayFormat: "%s" + type: "STRING" + isHeavy: false + isHidden: false + - components: + - type: "PROCESS_SUMMARY_RESULTS" + name: "resultScreen" + type: "COMPLETE" JOB_STARTED: value: - typedResponse: - jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "JOB_STARTED" + jobUUID: "98765432-10FE-DCBA-9876-543210FEDCBA" + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "JOB_STARTED" RUNNING: value: - typedResponse: - current: 47 - message: "Processing person records" - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - total: 1701 - type: "RUNNING" + current: 47 + total: 1701 + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "RUNNING" + message: "Processing person records" ERROR: value: - typedResponse: - processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" - type: "RUNNING" + processUUID: "01234567-89AB-CDEF-0123-456789ABCDEF" + type: "RUNNING" schema: $ref: "#/components/schemas/ProcessStepResponseV1" description: "State of the backend's running of the specified job, with\