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.openecomp.vid.controller;
23 import java.util.UUID;
25 import javax.servlet.http.HttpServletRequest;
27 import org.json.simple.JSONObject;
28 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
29 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.openecomp.vid.policy.PolicyProperties;
31 import org.openecomp.vid.policy.PolicyResponseWrapper;
32 import org.openecomp.vid.policy.PolicyRestInterfaceFactory;
33 import org.openecomp.vid.policy.PolicyRestInterfaceIfc;
34 import org.openecomp.vid.policy.PolicyUtil;
35 import org.openecomp.vid.policy.RestObject;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RequestMethod;
41 import org.springframework.web.bind.annotation.RestController;
44 * Controller to handle Policy requests.
48 public class PolicyController extends RestrictedBaseController{
51 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyController.class);
53 @RequestMapping(value="/get_policy",method = RequestMethod.POST)
54 public ResponseEntity<String> getPolicyInfo( HttpServletRequest request, @RequestBody JSONObject policy_request) throws Exception {
56 logger.debug("#####################POLICY API CALL STARTED ###############"+ PolicyProperties.POLICY_GET_CONFIG_VAL);
57 logger.debug("#####################Policy Request ###############"+policy_request.toString());
59 String path = PolicyProperties.getProperty(PolicyProperties.POLICY_GET_CONFIG_VAL);
60 PolicyResponseWrapper policyResWrapper = getPolicyConfig(policy_request,path);
62 logger.debug("$$$$$$$$$$$$$$$$$$$$$$ " + new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.OK).toString());
64 return ( new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.valueOf(policyResWrapper.getStatus())) );
67 protected static PolicyResponseWrapper getPolicyConfig(JSONObject request, String path) throws Exception {
68 String methodName = "getPolicyConfig";
69 String uuid = UUID.randomUUID().toString();
70 logger.debug( "starting getPolicyConfig ");
73 //STARTING REST API CALL AS AN FACTORY INSTACE
74 PolicyRestInterfaceIfc restController = PolicyRestInterfaceFactory.getInstance();
76 RestObject<String> restObjStr = new RestObject<String>();
77 String str = new String();
79 restController.<String>Post(str, request, uuid, path, restObjStr );
80 PolicyResponseWrapper policyRespWrapper = PolicyUtil.wrapResponse (restObjStr);
82 logger.debug( "<== " + methodName + " w=" + policyRespWrapper.getResponse());
83 return policyRespWrapper;
84 } catch (Exception e) {
85 logger.debug( "EXCEPTION in getPolicyConfig <== " + "." + methodName + e.toString());