lower code smells
[appc.git] / appc-inbound / appc-interfaces-service / bundle / src / main / java / org / onap / appc / interfaces / service / InterfacesServiceProviderImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2019 Ericsson
10  * Modifications Copyright (C) 2019 IBM
11  * =============================================================================
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  * 
16  *      http://www.apache.org/licenses/LICENSE-2.0
17  * 
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  * 
24  * ============LICENSE_END=========================================================
25  */
26
27 package org.onap.appc.interfaces.service;
28
29 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceInput;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutput;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutputBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.InterfacesServiceService;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.response.info.ResponseInfoBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.status.StatusBuilder;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
37 import org.onap.appc.interfaces.service.executor.ServiceExecutor;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 import com.google.common.util.concurrent.Futures;
42 import com.google.common.util.concurrent.ListenableFuture;
43
44 public class InterfacesServiceProviderImpl implements InterfacesServiceService{
45
46     private static final Logger log = LoggerFactory.getLogger(InterfacesServiceProviderImpl.class);
47
48     @Override
49     public ListenableFuture<RpcResult<ExecuteServiceOutput>> executeService(ExecuteServiceInput input) {
50
51         log.info("Received Request: " + input.getRequest().getRequestId() + " Action : " + 
52                 input.getRequest().getAction() + " with RequestData  :" + input.getRequest().getRequestData() + " and data-Type : " + input.getRequest().getRequestDataType());
53         String requestId = input.getRequest().getRequestId();
54         String action = input.getRequest().getAction();
55         ResponseInfoBuilder responseInfoBuilder = new ResponseInfoBuilder();
56         ExecuteServiceOutputBuilder executeServicebuilder = new ExecuteServiceOutputBuilder();
57         ServiceExecutor serviceExecutor = getServiceExecutor();
58         StatusBuilder statusBuilder = new StatusBuilder();
59         try{
60             String response = serviceExecutor.execute(action, input.getRequest().getRequestData(), input.getRequest().getRequestDataType());
61             responseInfoBuilder.setBlock(response);
62             responseInfoBuilder.setRequestId(requestId);
63             statusBuilder.setCode("400");
64             statusBuilder.setMessage("success");
65         }
66         catch(Exception e){
67             log.error("Error" + e.getMessage());
68             statusBuilder.setCode("401");
69             statusBuilder.setMessage("failure");
70         }
71         executeServicebuilder.setResponseInfo(responseInfoBuilder.build());
72         executeServicebuilder.setStatus(statusBuilder.build());
73         RpcResult<ExecuteServiceOutput> result  = RpcResultBuilder.<ExecuteServiceOutput>status(true).withResult(executeServicebuilder.build()).build();
74         return Futures.immediateFuture(result);
75     }
76
77     protected ServiceExecutor getServiceExecutor() {
78         return new ServiceExecutor();
79     }
80 }