aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-03-15 12:47:14 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-15 12:47:14 +0000
commit3ee6e148e8763f95f0161bc666b3e8a7bdf9ee6e (patch)
tree07269dab4af73f61d5203b73cb4a31386ee05e43 /bpmn/so-bpmn-tasks/src
parent1e22f36f9d682875754c927506d1d299389260eb (diff)
parent1b758b88037fcb87db293dc3194c3a43deca90b6 (diff)
Merge "Implement ManualHandlingTasks"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java202
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java155
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java98
3 files changed, 455 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java
new file mode 100644
index 0000000000..2fba3b3b25
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java
@@ -0,0 +1,202 @@
+package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.camunda.bpm.engine.TaskService;
+import org.camunda.bpm.engine.delegate.BpmnError;
+import org.camunda.bpm.engine.delegate.DelegateTask;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.client.ticket.ExternalTicket;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.logger.MessageEnum;
+import org.onap.so.logger.MsoLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ManualHandlingTasks {
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ManualHandlingTasks.class);
+
+ private static final String TASK_TYPE_PAUSE = "pause";
+ private static final String TASK_TYPE_FALLOUT = "fallout";
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ @Autowired
+ private RequestsDbClient requestDbclient;
+
+ public void setFalloutTaskVariables (DelegateTask task) {
+
+ DelegateExecution execution = task.getExecution();
+ try {
+ String taskId = task.getId();
+ msoLogger.debug("taskId is: " + taskId);
+ String type = TASK_TYPE_FALLOUT;
+ String nfRole = (String) execution.getVariable("vnfType");
+ String subscriptionServiceType = (String) execution.getVariable("serviceType");
+ String originalRequestId = (String) execution.getVariable("msoRequestId");
+ String originalRequestorId = (String) execution.getVariable("requestorId");
+ String description = "";
+ String timeout = "";
+ String errorSource = (String) execution.getVariable("failedActivity");
+ String errorCode = (String) execution.getVariable("errorCode");
+ String errorMessage = (String) execution.getVariable("errorText");
+ String buildingBlockName = (String) execution.getVariable("currentActivity");
+ String buildingBlockStep = (String) execution.getVariable("workStep");
+ String validResponses = (String) execution.getVariable("validResponses");
+
+ Map<String, String> taskVariables = new HashMap<String, String>();
+ taskVariables.put("type", type);
+ taskVariables.put("nfRole", nfRole);
+ taskVariables.put("subscriptionServiceType", subscriptionServiceType);
+ taskVariables.put("originalRequestId", originalRequestId);
+ taskVariables.put("originalRequestorId", originalRequestorId);
+ taskVariables.put("errorSource", errorSource);
+ taskVariables.put("errorCode", errorCode);
+ taskVariables.put("errorMessage", errorMessage);
+ taskVariables.put("buildingBlockName", buildingBlockName);
+ taskVariables.put("buildingBlockStep", buildingBlockStep);
+ taskVariables.put("validResponses", validResponses);
+ taskVariables.put("tmeout", timeout);
+ taskVariables.put("description", description);
+ TaskService taskService = execution.getProcessEngineServices().getTaskService();
+
+ taskService.setVariables(taskId, taskVariables);
+ msoLogger.debug("successfully created fallout task: "+ taskId);
+ } catch (BpmnError e) {
+ msoLogger.debug("BPMN exception: " + e.getMessage());
+ throw e;
+ } catch (Exception ex){
+ String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
+ msoLogger.debug(msg);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+ }
+
+ public void setPauseTaskVariables (DelegateTask task) {
+
+ DelegateExecution execution = task.getExecution();
+
+ try {
+ String taskId = task.getId();
+ msoLogger.debug("taskId is: " + taskId);
+ String type = TASK_TYPE_PAUSE;
+ String nfRole = (String) execution.getVariable("vnfType");
+ String subscriptionServiceType = (String) execution.getVariable("serviceType");
+ String originalRequestId = (String) execution.getVariable("msoRequestId");
+ String originalRequestorId = (String) execution.getVariable("requestorId");
+ String description = (String) execution.getVariable("description");
+ String timeout = (String) execution.getVariable("taskTimeout");
+ String errorSource = "";
+ String errorCode = "";
+ String errorMessage = "";
+ String buildingBlockName = "";
+ String buildingBlockStep = "";
+ String validResponses = (String) execution.getVariable("validResponses");
+
+ Map<String, String> taskVariables = new HashMap<String, String>();
+ taskVariables.put("type", type);
+ taskVariables.put("nfRole", nfRole);
+ taskVariables.put("description", description);
+ taskVariables.put("timeout", timeout);
+ taskVariables.put("subscriptionServiceType", subscriptionServiceType);
+ taskVariables.put("originalRequestId", originalRequestId);
+ taskVariables.put("originalRequestorId", originalRequestorId);
+ taskVariables.put("errorSource", errorSource);
+ taskVariables.put("errorCode", errorCode);
+ taskVariables.put("errorMessage", errorMessage);
+ taskVariables.put("buildingBlockName", buildingBlockName);
+ taskVariables.put("buildingBlockStep", buildingBlockStep);
+ taskVariables.put("validResponses", validResponses);
+ TaskService taskService = execution.getProcessEngineServices().getTaskService();
+
+ taskService.setVariables(taskId, taskVariables);
+ msoLogger.debug("successfully created pause task: "+ taskId);
+ } catch (BpmnError e) {
+ msoLogger.debug("BPMN exception: " + e.getMessage());
+ throw e;
+ } catch (Exception ex){
+ String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
+ msoLogger.debug(msg);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+
+ }
+
+ public void completeTask (DelegateTask task) {
+
+ DelegateExecution execution = task.getExecution();
+
+ try {
+
+ String taskId = task.getId();
+ msoLogger.debug("taskId is: " + taskId);
+ TaskService taskService = execution.getProcessEngineServices().getTaskService();
+
+ Map<String, Object> taskVariables = taskService.getVariables(taskId);
+ String responseValue = (String) taskVariables.get("responseValue");
+
+ msoLogger.debug("Received responseValue on completion: "+ responseValue);
+ // Have to set the first letter of the response to upper case
+ String responseValueUppercaseStart = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1);
+ msoLogger.debug("ResponseValue to taskListener: "+ responseValueUppercaseStart);
+ execution.setVariable("responseValueTask", responseValueUppercaseStart);
+
+ } catch (BpmnError e) {
+ msoLogger.debug("BPMN exception: " + e.getMessage());
+ throw e;
+ } catch (Exception ex){
+ String msg = "Exception in completeManualTask " + ex.getMessage();
+ msoLogger.debug(msg);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+
+ }
+
+ public void createExternalTicket (DelegateExecution execution) {
+
+ try {
+ ExternalTicket ticket = new ExternalTicket();
+
+ ticket.setRequestId((String) execution.getVariable("msoRequestId"));
+ ticket.setCurrentActivity((String) execution.getVariable("currentActivity"));
+ ticket.setNfRole((String) execution.getVariable("vnfType"));
+ ticket.setDescription((String) execution.getVariable("description"));
+ ticket.setSubscriptionServiceType((String) execution.getVariable("serviceType"));
+ ticket.setRequestorId((String) execution.getVariable("requestorId"));
+ ticket.setTimeout((String) execution.getVariable("taskTimeout"));
+ ticket.setErrorSource((String) execution.getVariable("failedActivity"));
+ ticket.setErrorCode((String) execution.getVariable("errorCode"));
+ ticket.setErrorMessage((String) execution.getVariable("errorText"));
+ ticket.setWorkStep((String) execution.getVariable("workStep"));
+
+ ticket.createTicket();
+ } catch (BpmnError e) {
+ String msg = "BPMN error in createAOTSTicket " + e.getMessage();
+ msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.ErrorCode.UnknownError, "");
+ } catch (Exception ex){
+ String msg = "Exception in createExternalTicket " + ex.getMessage();
+ msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.ErrorCode.UnknownError, "");
+ }
+
+ }
+
+ public void updateRequestDbStatus(DelegateExecution execution, String status) {
+ try {
+ String requestId = (String) execution.getVariable("msoRequestId");
+ InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
+
+ request.setRequestStatus(status);
+ request.setLastModifiedBy("ManualHandling");
+
+ requestDbclient.updateInfraActiveRequests(request);
+ } catch (Exception e) {
+ msoLogger.error("Unable to save the updated request status to the DB",e);
+ }
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java
new file mode 100644
index 0000000000..519afe6f2d
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java
@@ -0,0 +1,155 @@
+package org.onap.so.client.ticket;
+
+public class ExternalTicket {
+ private String requestId;
+ private String nfRole;
+ private String currentActivity;
+ private String description;
+ private String subscriptionServiceType;
+ private String requestorId;
+ private String timeout;
+ private String errorSource;
+ private String errorCode;
+ private String errorMessage;
+ private String workStep;
+
+ public String getRequestId() {
+ return requestId;
+ }
+
+
+
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
+
+
+
+ public String getNfRole() {
+ return nfRole;
+ }
+
+
+
+ public void setNfRole(String nfRole) {
+ this.nfRole = nfRole;
+ }
+
+
+
+ public String getCurrentActivity() {
+ return currentActivity;
+ }
+
+
+
+ public void setCurrentActivity(String currentActivity) {
+ this.currentActivity = currentActivity;
+ }
+
+
+
+ public String getDescription() {
+ return description;
+ }
+
+
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+
+
+ public String getSubscriptionServiceType() {
+ return subscriptionServiceType;
+ }
+
+
+
+ public void setSubscriptionServiceType(String subscriptionServiceType) {
+ this.subscriptionServiceType = subscriptionServiceType;
+ }
+
+
+
+ public String getRequestorId() {
+ return requestorId;
+ }
+
+
+
+ public void setRequestorId(String requestorId) {
+ this.requestorId = requestorId;
+ }
+
+
+
+ public String getTimeout() {
+ return timeout;
+ }
+
+
+
+ public void setTimeout(String timeout) {
+ this.timeout = timeout;
+ }
+
+
+
+ public String getErrorSource() {
+ return errorSource;
+ }
+
+
+
+ public void setErrorSource(String errorSource) {
+ this.errorSource = errorSource;
+ }
+
+
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+
+
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
+
+
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+
+
+ public String getWorkStep() {
+ return workStep;
+ }
+
+
+
+ public void setWorkStep(String workStep) {
+ this.workStep = workStep;
+ }
+
+
+
+ public void createTicket() throws Exception {
+ //Replace with your ticket creation mechanism if any
+ }
+
+
+
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java
new file mode 100644
index 0000000000..5e9565446f
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java
@@ -0,0 +1,98 @@
+package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.camunda.bpm.engine.ProcessEngineServices;
+import org.camunda.bpm.engine.TaskService;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.DelegateTask;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+
+public class ManualHandlingTasksTest extends BaseTaskTest {
+ @InjectMocks
+ protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
+
+ @Mock
+ TaskService taskService;
+
+ @Mock
+ private DelegateExecution mockExecution;
+
+ @Mock
+ ProcessEngineServices processEngineServices;
+
+ @Mock
+ private DelegateTask task;
+
+ private DelegateExecution delegateExecution;
+
+ @Before
+ public void before() throws Exception {
+ delegateExecution = new DelegateExecutionFake();
+ }
+
+ @Test
+ public void setFalloutTaskVariables_Test () {
+ when(task.getId()).thenReturn("taskId");
+ when(task.getExecution()).thenReturn(mockExecution);
+ when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
+ when(processEngineServices.getTaskService()).thenReturn(taskService);
+ manualHandlingTasks.setFalloutTaskVariables(task);
+ verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
+ }
+
+ @Test
+ public void setPauseTaskVariables_Test () {
+ when(task.getId()).thenReturn("taskId");
+ when(task.getExecution()).thenReturn(mockExecution);
+ when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
+ when(processEngineServices.getTaskService()).thenReturn(taskService);
+ manualHandlingTasks.setPauseTaskVariables(task);
+ verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
+ }
+
+ @Test
+ public void completeTask_Test() throws Exception{
+ when(task.getId()).thenReturn("taskId");
+ when(task.getExecution()).thenReturn(mockExecution);
+ Map<String, Object> taskVariables = new HashMap<String, Object>();
+ taskVariables.put("responseValue", "resume");
+ when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
+ when(processEngineServices.getTaskService()).thenReturn(taskService);
+ when(taskService.getVariables(any(String.class))).thenReturn(taskVariables);
+ manualHandlingTasks.completeTask(task);
+ verify(mockExecution, times(1)).setVariable("responseValueTask", "Resume");
+ }
+
+ @Test
+ public void updateRequestDbStatus_Test() throws Exception{
+ InfraActiveRequests mockedRequest = new InfraActiveRequests();
+ delegateExecution.setVariable("msoRequestId", "testMsoRequestId");
+ when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
+ doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
+ manualHandlingTasks.updateRequestDbStatus(delegateExecution, "IN_PROGRESS");
+ verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
+ assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS");
+ }
+
+ @Test
+ public void createExternalTicket_Test() throws Exception{
+ delegateExecution.setVariable("msoRequestId", ("testMsoRequestId"));
+ delegateExecution.setVariable("vnfType", "testVnfType");
+ manualHandlingTasks.createExternalTicket(delegateExecution);
+ }
+}