2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.controllers;
23 import org.json.simple.JSONObject;
24 import org.onap.vid.policy.*;
25 import org.onap.portalsdk.core.controller.RestrictedBaseController;
26 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.springframework.http.HttpStatus;
28 import org.springframework.http.ResponseEntity;
29 import org.springframework.web.bind.annotation.RequestBody;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RequestMethod;
32 import org.springframework.web.bind.annotation.RestController;
34 import javax.servlet.http.HttpServletRequest;
35 import java.util.UUID;
38 * Controller to handle Policy requests.
42 public class PolicyController extends RestrictedBaseController{
45 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PolicyController.class);
47 @RequestMapping(value="/get_policy",method = RequestMethod.POST)
48 public ResponseEntity<String> getPolicyInfo( HttpServletRequest request, @RequestBody JSONObject policy_request) {
50 LOGGER.debug("#####################POLICY API CALL STARTED ###############"+ PolicyProperties.POLICY_GET_CONFIG_VAL);
51 LOGGER.debug("#####################Policy Request ###############"+policy_request.toString());
53 String path = PolicyProperties.getProperty(PolicyProperties.POLICY_GET_CONFIG_VAL);
54 PolicyResponseWrapper policyResWrapper = getPolicyConfig(policy_request,path);
56 LOGGER.debug("$$$$$$$$$$$$$$$$$$$$$$ " + new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.OK).toString());
58 return ( new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.valueOf(policyResWrapper.getStatus())) );
61 protected static PolicyResponseWrapper getPolicyConfig(JSONObject request, String path) {
62 String methodName = "getPolicyConfig";
63 String uuid = UUID.randomUUID().toString();
64 LOGGER.debug( "starting getPolicyConfig ");
67 //STARTING REST API CALL AS AN FACTORY INSTACE
68 PolicyRestInterfaceIfc restController = PolicyRestInterfaceFactory.getInstance();
70 RestObject<String> restObjStr = new RestObject<String>();
71 String str = new String();
73 restController.<String>Post(str, request, uuid, path, restObjStr );
74 PolicyResponseWrapper policyRespWrapper = PolicyUtil.wrapResponse (restObjStr);
76 LOGGER.debug( "<== " + methodName + " w=" + policyRespWrapper.getResponse());
77 return policyRespWrapper;
78 } catch (Exception e) {
79 LOGGER.debug( "EXCEPTION in getPolicyConfig <== " + "." + methodName + e.toString());