Search in sources :

Example 1 with WorkflowCallbackResponse

use of org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse in project so by onap.

the class WorkflowContextHolderTest method testProcessCallback.

@Test
public void testProcessCallback() throws Exception {
    String requestId = UUID.randomUUID().toString();
    String message = "TEST MESSATGE";
    String responseMessage = "Successfully processed request";
    int testCode = 200;
    WorkflowContextHolder contextHolder = WorkflowContextHolder.getInstance();
    WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
    callbackResponse.setMessage(message);
    callbackResponse.setResponse(responseMessage);
    callbackResponse.setStatusCode(testCode);
    contextHolder.processCallback("testAsyncProcess", "process-instance-id", requestId, callbackResponse);
    // same object returned
    WorkflowContext contextFound = contextHolder.getWorkflowContext(requestId);
    if (contextFound == null)
        throw new Exception("Expected to find Context Object");
    WorkflowResponse testResponse = contextFound.getWorkflowResponse();
    Assert.assertEquals(200, testResponse.getMessageCode());
    Assert.assertEquals(message, testResponse.getMessage());
    Assert.assertEquals(responseMessage, testResponse.getResponse());
}
Also used : WorkflowContextHolder(org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder) WorkflowContext(org.onap.so.bpmn.common.workflow.context.WorkflowContext) WorkflowCallbackResponse(org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse) WorkflowResponse(org.onap.so.bpmn.common.workflow.context.WorkflowResponse) Test(org.junit.Test)

Example 2 with WorkflowCallbackResponse

use of org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse in project so by onap.

the class WorkflowActionBBTasks method sendErrorSyncAck.

public void sendErrorSyncAck(DelegateExecution execution) {
    final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
    try {
        ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
        String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
        if (errorMsg == null) {
            errorMsg = "WorkflowAction failed unexpectedly.";
        }
        String processKey = exceptionBuilder.getProcessKey(execution);
        String buildworkflowException = "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>" + errorMsg + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>";
        WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
        callbackResponse.setStatusCode(500);
        callbackResponse.setMessage("Fail");
        callbackResponse.setResponse(buildworkflowException);
        WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId, callbackResponse);
        execution.setVariable("sentSyncResponse", true);
    } catch (Exception ex) {
        logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
    }
}
Also used : WorkflowCallbackResponse(org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse) EntityNotFoundException(javax.persistence.EntityNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder)

Example 3 with WorkflowCallbackResponse

use of org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse in project so by onap.

the class WorkflowActionBBTasks method sendSyncAck.

public void sendSyncAck(DelegateExecution execution) {
    final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
    final String resourceId = (String) execution.getVariable("resourceId");
    ServiceInstancesResponse serviceInstancesResponse = new ServiceInstancesResponse();
    RequestReferences requestRef = new RequestReferences();
    requestRef.setInstanceId(resourceId);
    requestRef.setRequestId(requestId);
    serviceInstancesResponse.setRequestReferences(requestRef);
    ObjectMapper mapper = new ObjectMapper();
    String jsonRequest = "";
    try {
        jsonRequest = mapper.writeValueAsString(serviceInstancesResponse);
    } catch (JsonProcessingException e) {
        workflowAction.buildAndThrowException(execution, "Could not marshall ServiceInstancesRequest to Json string to respond to API Handler.", e);
    }
    WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
    callbackResponse.setStatusCode(200);
    callbackResponse.setMessage("Success");
    callbackResponse.setResponse(jsonRequest);
    String processKey = execution.getProcessEngineServices().getRepositoryService().getProcessDefinition(execution.getProcessDefinitionId()).getKey();
    WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId, callbackResponse);
    logger.info("Successfully sent sync ack.");
    updateInstanceId(execution);
}
Also used : WorkflowCallbackResponse(org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

WorkflowCallbackResponse (org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 Test (org.junit.Test)1 WorkflowContext (org.onap.so.bpmn.common.workflow.context.WorkflowContext)1 WorkflowContextHolder (org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder)1 WorkflowResponse (org.onap.so.bpmn.common.workflow.context.WorkflowResponse)1 ExceptionBuilder (org.onap.so.client.exception.ExceptionBuilder)1 RequestReferences (org.onap.so.serviceinstancebeans.RequestReferences)1 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)1