Merge "Added @Override annotation to method signature"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / java / org / openecomp / mso / bpmn / infrastructure / workflow / serviceTask / SdncServiceTopologyOperationTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.mso.bpmn.infrastructure.workflow.serviceTask;
22
23
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.openecomp.mso.bpmn.core.WorkflowException;
26 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
27 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.ServiceRpcInputEntityBuilder;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcServiceTopologyOperationInputEntity;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcServiceTopologyOperationOutputEntity;
30 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ServiceTopologyOperationOutputEntity;
31 import org.openecomp.mso.requestsdb.RequestsDbConstant;
32
33 import java.util.Map;
34
35 /**
36  * Created by 10112215 on 2017/9/26.
37  */
38 public class SdncServiceTopologyOperationTask extends AbstractSdncOperationTask {
39     @Override
40     public void sendRestrequestAndHandleResponse(DelegateExecution execution,
41                                                  Map<String, String> inputs,
42                                                  GenericResourceApi genericResourceApiClient) throws Exception {
43         ServiceRpcInputEntityBuilder builder = new ServiceRpcInputEntityBuilder();
44         RpcServiceTopologyOperationInputEntity inputEntity = builder.build(execution, inputs);
45         RpcServiceTopologyOperationOutputEntity outputEntity = genericResourceApiClient.postServiceTopologyOperation(inputEntity).execute().body();
46         saveOutput(execution, outputEntity);
47     }
48
49     private void saveOutput(DelegateExecution execution, RpcServiceTopologyOperationOutputEntity output) throws Exception {
50         String responseCode = output.getOutput().getResponseCode();
51         if (!"200".equals(responseCode)) {
52             String processKey = getProcessKey(execution);
53             int errorCode = Integer.valueOf(responseCode);
54             String errorMessage = output.getOutput().getResponseMessage();
55             WorkflowException workflowException = new WorkflowException(processKey, errorCode, errorMessage);
56             execution.setVariable("SDNCA_SuccessIndicator", workflowException);
57             updateProgress(execution, RequestsDbConstant.Status.ERROR, String.valueOf(errorCode), null, errorMessage);
58             throw new Exception("");
59         }
60     }
61 }