Containerization feature of SO
[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  * 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.common.workflow.service;
22
23 import javax.jws.WebMethod;
24 import javax.jws.WebParam;
25 import javax.jws.WebResult;
26 import javax.jws.WebService;
27 import javax.ws.rs.core.Context;
28 import javax.xml.ws.WebServiceContext;
29
30 import org.onap.so.bpmn.common.adapter.sdnc.SDNCAdapterCallbackRequest;
31 import org.onap.so.bpmn.common.adapter.sdnc.SDNCAdapterResponse;
32 import org.onap.so.bpmn.common.adapter.sdnc.SDNCCallbackAdapterPortType;
33 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
34 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
35 import org.onap.so.logger.MsoLogger;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
38
39 /**
40  * Implementation of SDNCAdapterCallbackService.
41  */
42 @WebService(serviceName="SDNCAdapterCallbackService", targetNamespace="http://org.onap/workflow/sdnc/adapter/schema/v1")
43 @Service
44 public class SDNCAdapterCallbackServiceImpl extends ProcessEngineAwareService implements SDNCCallbackAdapterPortType {
45
46         private final static String logMarker = "[SDNC-CALLBACK]";
47
48         @Context WebServiceContext wsContext;
49         
50         @Autowired
51         CallbackHandlerService callback;
52
53         @WebMethod(operationName = "SDNCAdapterCallback")
54     @WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackResponse")
55     public SDNCAdapterResponse sdncAdapterCallback(
56             @WebParam(name = "SDNCAdapterCallbackRequest", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackRequest")
57             SDNCAdapterCallbackRequest sdncAdapterCallbackRequest) {
58
59                 String method = "sdncAdapterCallback";
60                 Object message = sdncAdapterCallbackRequest;
61                 String messageEventName = "sdncAdapterCallbackRequest";
62                 String messageVariable = "sdncAdapterCallbackRequest";
63                 String correlationVariable = "SDNCA_requestId";
64                 String correlationValue = sdncAdapterCallbackRequest.getCallbackHeader().getRequestId();
65
66                 MsoLogger.setServiceName("MSO." + method);
67                 MsoLogger.setLogContext(correlationValue, "N/A");
68
69                 CallbackResult result = callback.handleCallback(method, message, messageEventName,
70                         messageVariable, correlationVariable, correlationValue, logMarker);
71
72                 if (result instanceof CallbackError) {
73                         return new SDNCAdapterErrorResponse(((CallbackError)result).getErrorMessage());
74                 } else {
75                         return new SDNCAdapterResponse();
76                 }
77         }
78
79         // This subclass allows unit tests to extract the error
80         public class SDNCAdapterErrorResponse extends SDNCAdapterResponse {
81                 private String error;
82
83                 public SDNCAdapterErrorResponse(String error) {
84                         this.error = error;
85                 }
86
87                 public String getError() {
88                         return error;
89                 }
90         }
91 }