ec2ccdf2027892b41929886d7e12f26da0903223
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / FlowCompletionTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.camunda.bpm.engine.delegate.BpmnError;
27 import org.camunda.bpm.engine.delegate.DelegateExecution;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse;
30 import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder;
31 import org.onap.so.bpmn.core.WorkflowException;
32 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
33 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.db.request.beans.InfraActiveRequests;
36 import org.onap.so.db.request.client.RequestsDbClient;
37 import org.onap.so.serviceinstancebeans.RequestReferences;
38 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
43
44 import com.fasterxml.jackson.core.JsonProcessingException;
45 import com.fasterxml.jackson.databind.ObjectMapper;
46
47 @Component
48 public class FlowCompletionTasks {
49
50         private static final Logger logger = LoggerFactory.getLogger(FlowCompletionTasks.class);
51
52         @Autowired
53         private RequestsDbClient requestDbclient;
54                 
55         public void updateRequestDbStatus(BuildingBlockExecution execution) {
56                 try {
57                         String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
58                         InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
59                         
60                         WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
61                         if (workflowException == null) {
62                                 request.setStatusMessage("RequestCompletedSuccessfully");
63                                 request.setRequestStatus("COMPLETE");
64                                                         
65                         }
66                         else {
67                                 request.setStatusMessage(workflowException.getErrorMessage());          
68                                 request.setRequestStatus("FAILED");
69                         }
70                         request.setProgress(100L);
71                         request.setLastModifiedBy("CamundaBPMN");
72                                 
73                         requestDbclient.updateInfraActiveRequests(request);
74                 } catch (Exception e) {
75                         logger.error("Unable to save the updated request status to the DB",e);
76                 }
77         }
78         
79         
80 }