b81506ead9451abd6f86697ea6585072dfd735e5
[so.git] /
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 import org.onap.so.bpmn.common.adapter.sdnc.SDNCAdapterCallbackRequest;
32 import org.onap.so.bpmn.common.adapter.sdnc.SDNCAdapterResponse;
33 import org.onap.so.bpmn.common.adapter.sdnc.SDNCCallbackAdapterPortType;
34 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
35 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
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",
43         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
50     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",
57             partName = "SDNCAdapterCallbackResponse")
58     public SDNCAdapterResponse sdncAdapterCallback(@WebParam(name = "SDNCAdapterCallbackRequest",
59             targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1",
60             partName = "SDNCAdapterCallbackRequest") SDNCAdapterCallbackRequest sdncAdapterCallbackRequest) {
61
62         String method = "sdncAdapterCallback";
63         Object message = sdncAdapterCallbackRequest;
64         String messageEventName = "sdncAdapterCallbackRequest";
65         String messageVariable = "sdncAdapterCallbackRequest";
66         String correlationVariable = "SDNCA_requestId";
67         String correlationValue = sdncAdapterCallbackRequest.getCallbackHeader().getRequestId();
68
69         CallbackResult result = callback.handleCallback(method, message, messageEventName, messageVariable,
70                 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 }