Search in sources :

Example 1 with OPERATOR_MANUAL_RECOVERY

use of org.mifos.connector.mpesa.zeebe.ZeebeMessages.OPERATOR_MANUAL_RECOVERY in project ph-ee-connector-mpesa by openMF.

the class OperationsRouteBuilder method configure.

@Override
public void configure() {
    from("rest:POST:/channel/transaction/{" + TRANSACTION_ID + "}/resolve").id("transaction-resolve").log(LoggingLevel.INFO, "## operator transaction resolve").process(e -> {
        Map<String, Object> variables = new HashMap<>();
        JSONObject request = new JSONObject(e.getIn().getBody(String.class));
        request.keys().forEachRemaining(k -> {
            variables.put(k, request.get(k));
        });
        zeebeClient.newPublishMessageCommand().messageName(OPERATOR_MANUAL_RECOVERY).correlationKey(e.getIn().getHeader(TRANSACTION_ID, String.class)).timeToLive(Duration.ofMillis(30000)).variables(variables).send().join();
    }).setBody(constant((Object) null));
    from("rest:POST:/channel/job/resolve").id("job-resolve").log(LoggingLevel.INFO, "## operator job resolve").process(e -> {
        JSONObject request = new JSONObject(e.getIn().getBody(String.class));
        JSONObject incident = request.getJSONObject("incident");
        Map<String, Object> newVariables = new HashMap<>();
        JSONObject requestedVariables = request.getJSONObject("variables");
        requestedVariables.keys().forEachRemaining(k -> {
            newVariables.put(k, requestedVariables.get(k));
        });
        zeebeClient.newSetVariablesCommand(incident.getLong("elementInstanceKey")).variables(newVariables).send().join();
        zeebeClient.newUpdateRetriesCommand(incident.getLong("jobKey")).retries(incident.getInt("newRetries")).send().join();
        zeebeClient.newResolveIncidentCommand(incident.getLong("key")).send().join();
    }).setBody(constant((Object) null));
    from("rest:POST:/channel/workflow/resolve").id("workflow-resolve").log(LoggingLevel.INFO, "## operator workflow resolve").process(e -> {
        JSONObject request = new JSONObject(e.getIn().getBody(String.class));
        JSONObject incident = request.getJSONObject("incident");
        Map<String, Object> newVariables = new HashMap<>();
        JSONObject requestedVariables = request.getJSONObject("variables");
        requestedVariables.keys().forEachRemaining(k -> {
            newVariables.put(k, requestedVariables.get(k));
        });
        zeebeClient.newSetVariablesCommand(incident.getLong("elementInstanceKey")).variables(newVariables).send().join();
        zeebeClient.newResolveIncidentCommand(incident.getLong("key")).send().join();
    }).setBody(constant((Object) null));
    from("rest:POST:/channel/workflow/{workflowInstanceKey}/cancel").id("workflow-cancel").log(LoggingLevel.INFO, "## operator workflow cancel ${header.workflowInstanceKey}").process(e -> zeebeClient.newCancelInstanceCommand(Long.parseLong(e.getIn().getHeader("workflowInstanceKey", String.class))).send().join()).setBody(constant((Object) null));
}
Also used : LoggingLevel(org.apache.camel.LoggingLevel) Component(org.springframework.stereotype.Component) JSONObject(org.json.JSONObject) TRANSACTION_ID(org.mifos.connector.mpesa.zeebe.ZeebeVariables.TRANSACTION_ID) Duration(java.time.Duration) Map(java.util.Map) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorHandlerRouteBuilder(org.mifos.connector.common.camel.ErrorHandlerRouteBuilder) HashMap(java.util.HashMap) OPERATOR_MANUAL_RECOVERY(org.mifos.connector.mpesa.zeebe.ZeebeMessages.OPERATOR_MANUAL_RECOVERY) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ZeebeClient (io.camunda.zeebe.client.ZeebeClient)1 Duration (java.time.Duration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LoggingLevel (org.apache.camel.LoggingLevel)1 JSONObject (org.json.JSONObject)1 ErrorHandlerRouteBuilder (org.mifos.connector.common.camel.ErrorHandlerRouteBuilder)1 OPERATOR_MANUAL_RECOVERY (org.mifos.connector.mpesa.zeebe.ZeebeMessages.OPERATOR_MANUAL_RECOVERY)1 TRANSACTION_ID (org.mifos.connector.mpesa.zeebe.ZeebeVariables.TRANSACTION_ID)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1