e809ecd0ae7e54fbbbe232d21016675b00b3e512
[so.git] /
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 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse;
29 import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder;
30 import org.onap.so.bpmn.core.WorkflowException;
31 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
32 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
33 import org.onap.so.client.exception.ExceptionBuilder;
34 import org.onap.so.db.request.beans.InfraActiveRequests;
35 import org.onap.so.db.request.client.RequestsDbClient;
36 import org.onap.so.serviceinstancebeans.RequestReferences;
37 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
42 import com.fasterxml.jackson.core.JsonProcessingException;
43 import com.fasterxml.jackson.databind.ObjectMapper;
44
45 @Component
46 public class FlowCompletionTasks {
47
48     private static final Logger logger = LoggerFactory.getLogger(FlowCompletionTasks.class);
49
50     @Autowired
51     private RequestsDbClient requestDbclient;
52
53     public void updateRequestDbStatus(BuildingBlockExecution execution) {
54         try {
55             String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
56             InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
57
58             WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
59             if (workflowException == null) {
60                 request.setStatusMessage("RequestCompletedSuccessfully");
61                 request.setRequestStatus("COMPLETE");
62
63             } else {
64                 request.setStatusMessage(workflowException.getErrorMessage());
65                 request.setRequestStatus("FAILED");
66             }
67             request.setProgress(100L);
68             request.setLastModifiedBy("CamundaBPMN");
69
70             requestDbclient.updateInfraActiveRequests(request);
71         } catch (Exception e) {
72             logger.error("Unable to save the updated request status to the DB", e);
73         }
74     }
75
76
77 }