aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java4
-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
4 files changed, 459 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java
index f4b528c4be..deb985c62b 100644
--- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java
+++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java
@@ -63,6 +63,7 @@ import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf;
import org.onap.so.bpmn.infrastructure.namingservice.tasks.NamingServiceCreateTasks;
import org.onap.so.bpmn.infrastructure.namingservice.tasks.NamingServiceDeleteTasks;
+import org.onap.so.bpmn.infrastructure.manualhandling.tasks.ManualHandlingTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCAssignTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCChangeAssignTasks;
@@ -242,6 +243,9 @@ public abstract class BaseBPMNTest {
@MockBean
protected AuditTasks auditTasks;
+
+ @MockBean
+ protected ManualHandlingTasks manualHandlingTasks;
@LocalServerPort
protected int port;
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);
+ }
+}