267e24fec4c21a7acbc06c8ae77634c4ba774cda
[so.git] / bpmn / mso-infrastructure-bpmn / src / main / java / org / onap / so / bpmn / common / workflow / service / SDNCAdapterCallbackServiceImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.common.workflow.service;
24
25 import javax.jws.WebMethod;
26 import javax.jws.WebParam;
27 import javax.jws.WebResult;
28 import javax.jws.WebService;
29 import javax.ws.rs.core.Context;
30 import javax.xml.ws.WebServiceContext;
31
32 import org.onap.so.bpmn.common.adapter.sdnc.SDNCAdapterCallbackRequest;
33 import org.onap.so.bpmn.common.adapter.sdnc.SDNCAdapterResponse;
34 import org.onap.so.bpmn.common.adapter.sdnc.SDNCCallbackAdapterPortType;
35 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
36 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
37 import org.onap.so.logger.MsoLogger;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Service;
40
41 /**
42  * Implementation of SDNCAdapterCallbackService.
43  */
44 @WebService(serviceName="SDNCAdapterCallbackService", targetNamespace="http://org.onap/workflow/sdnc/adapter/schema/v1")
45 @Service
46 public class SDNCAdapterCallbackServiceImpl extends ProcessEngineAwareService implements SDNCCallbackAdapterPortType {
47
48         private final static String logMarker = "[SDNC-CALLBACK]";
49
50         @Context WebServiceContext wsContext;
51         
52         @Autowired
53         CallbackHandlerService callback;
54
55         @WebMethod(operationName = "SDNCAdapterCallback")
56     @WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackResponse")
57     public SDNCAdapterResponse sdncAdapterCallback(
58             @WebParam(name = "SDNCAdapterCallbackRequest", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackRequest")
59             SDNCAdapterCallbackRequest sdncAdapterCallbackRequest) {
60
61                 String method = "sdncAdapterCallback";
62                 Object message = sdncAdapterCallbackRequest;
63                 String messageEventName = "sdncAdapterCallbackRequest";
64                 String messageVariable = "sdncAdapterCallbackRequest";
65                 String correlationVariable = "SDNCA_requestId";
66                 String correlationValue = sdncAdapterCallbackRequest.getCallbackHeader().getRequestId();
67
68                 MsoLogger.setLogContext(correlationValue, "N/A");
69
70                 CallbackResult result = callback.handleCallback(method, message, messageEventName,
71                         messageVariable, correlationVariable, correlationValue, logMarker);
72
73                 if (result instanceof CallbackError) {
74                         return new SDNCAdapterErrorResponse(((CallbackError)result).getErrorMessage());
75                 } else {
76                         return new SDNCAdapterResponse();
77                 }
78         }
79
80         // This subclass allows unit tests to extract the error
81         public class SDNCAdapterErrorResponse extends SDNCAdapterResponse {
82                 private String error;
83
84                 public SDNCAdapterErrorResponse(String error) {
85                         this.error = error;
86                 }
87
88                 public String getError() {
89                         return error;
90                 }
91         }
92 }