2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.onap.so.client.exception.BadResponseException;
25 import org.onap.so.client.exception.ExceptionBuilder;
26 import org.onap.so.client.exception.MapperException;
27 import org.onap.so.client.sdnc.SDNCClient;
28 import org.onap.so.client.sdnc.beans.SDNCRequest;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
34 import com.jayway.jsonpath.JsonPath;
35 import com.jayway.jsonpath.PathNotFoundException;
38 public class SDNCRequestTasks {
40 private static final Logger logger = LoggerFactory.getLogger(SDNCRequestTasks.class);
42 private static final String SDNC_REQUEST = "SDNCRequest";
43 private static final String MESSAGE = "_MESSAGE";
44 private static final String CORRELATOR = "_CORRELATOR";
45 protected static final String IS_CALLBACK_COMPLETED = "isCallbackCompleted";
48 private ExceptionBuilder exceptionBuilder;
51 private SDNCClient sdncClient;
53 public void createCorrelationVariables (DelegateExecution execution) {
54 SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST);
55 execution.setVariable(request.getCorrelationName()+CORRELATOR, request.getCorrelationValue());
56 execution.setVariable("sdncTimeout", request.getTimeOut());
59 public void callSDNC (DelegateExecution execution) {
60 SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST);
62 String response = sdncClient.post(request.getSDNCPayload(),request.getTopology());
63 String finalMessageIndicator = JsonPath.read(response, "$.output.ack-final-indicator");
64 execution.setVariable("isSDNCCompleted", convertIndicatorToBoolean(finalMessageIndicator));
65 } catch(PathNotFoundException e) {
66 logger.error("Error Parsing SDNC Response", e);
67 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,"Error Parsing SDNC Response");
68 } catch (MapperException e) {
69 logger.error("Error Parsing SDNC Response", e);
70 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,"Error Parsing SDNC Response");
71 } catch (BadResponseException e) {
72 logger.error("Error Reading SDNC Response", e);
73 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error Reading SDNC Response");
77 public void processCallback (DelegateExecution execution) {
79 SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST);
80 String asyncRequest = (String) execution.getVariable(request.getCorrelationName()+MESSAGE);
81 String finalMessageIndicator = JsonPath.read(asyncRequest, "$.input.ack-final-indicator");
82 boolean isCallbackCompleted = convertIndicatorToBoolean(finalMessageIndicator);
83 execution.setVariable(IS_CALLBACK_COMPLETED, isCallbackCompleted);
84 } catch (Exception e) {
85 logger.error("Error procesing SDNC callback", e);
86 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error procesing SDNC callback");
90 public void handleTimeOutException (DelegateExecution execution) {
91 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error timed out waiting on SDNC Async-Response");
94 public void handleSyncError (DelegateExecution execution) {
95 String msg = (String) execution.getVariable("SDNCSyncError");
96 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
99 protected boolean convertIndicatorToBoolean(String finalMessageIndicator) {
100 return "Y".equals(finalMessageIndicator);