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