diff options
author | Rob Daugherty <rd472p@att.com> | 2018-09-20 18:18:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-20 18:18:10 +0000 |
commit | 5423e0e1b725b572357b4d79b034e1e0703aa1b8 (patch) | |
tree | 02bc4ac620fd1b4a52a1f2ab65d1e401f2865af5 /bpmn/so-bpmn-tasks | |
parent | c4347b25ddf03c4f8e25b9443e0e25be102d0ba6 (diff) | |
parent | 82e8b0b7045ea96eb1788317fb4101a53ecc77be (diff) |
Merge "Activity for Flow Completion Status"
Diffstat (limited to 'bpmn/so-bpmn-tasks')
2 files changed, 148 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java new file mode 100644 index 0000000000..ec2ccdf202 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse; +import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.serviceinstancebeans.RequestReferences; +import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class FlowCompletionTasks { + + private static final Logger logger = LoggerFactory.getLogger(FlowCompletionTasks.class); + + @Autowired + private RequestsDbClient requestDbclient; + + public void updateRequestDbStatus(BuildingBlockExecution execution) { + try { + String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId(); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + + WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException"); + if (workflowException == null) { + request.setStatusMessage("RequestCompletedSuccessfully"); + request.setRequestStatus("COMPLETE"); + + } + else { + request.setStatusMessage(workflowException.getErrorMessage()); + request.setRequestStatus("FAILED"); + } + request.setProgress(100L); + request.setLastModifiedBy("CamundaBPMN"); + + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + logger.error("Unable to save the updated request status to the DB",e); + } + } + + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java new file mode 100644 index 0000000000..03ed2cb4d4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.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 org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.springframework.beans.factory.annotation.Autowired; + +public class FlowCompletionTasksTest extends BaseTaskTest { + + @Autowired + protected FlowCompletionTasks flowCompletionTasks; + + @Before + public void before() { + setRequestContext(); + } + + @Test + public void updateRequestDbStatusComplete_Test() throws Exception{ + InfraActiveRequests mockedRequest = new InfraActiveRequests(); + when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest); + doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class)); + flowCompletionTasks.updateRequestDbStatus(execution); + verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class)); + assertEquals(mockedRequest.getRequestStatus(), "COMPLETE"); + } + + @Test + public void updateRequestDbStatusFailed_Test() throws Exception{ + WorkflowException workflowException = new WorkflowException("testProcessKey", 7000, "Error"); + execution.setVariable("WorkflowException", workflowException); + InfraActiveRequests mockedRequest = new InfraActiveRequests(); + when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest); + doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class)); + flowCompletionTasks.updateRequestDbStatus(execution); + verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class)); + assertEquals(mockedRequest.getRequestStatus(), "FAILED"); + } +} |