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.portalapp.portal.controller;
23 import java.util.UUID;
25 import javax.servlet.http.HttpServletRequest;
27 import org.json.simple.JSONObject;
28 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
29 import org.openecomp.portalapp.portal.scheduler.policy.PolicyProperties;
30 import org.openecomp.portalapp.portal.scheduler.policy.PolicyResponseWrapper;
31 import org.openecomp.portalapp.portal.scheduler.policy.PolicyRestInterfaceFactory;
32 import org.openecomp.portalapp.portal.scheduler.policy.PolicyRestInterfaceIfc;
33 import org.openecomp.portalapp.portal.scheduler.policy.PolicyUtil;
34 import org.openecomp.portalapp.portal.scheduler.policy.RestObject;
35 import org.openecomp.portalapp.portal.utils.PortalConstants;
36 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
37 import org.openecomp.portalsdk.core.util.SystemProperties;
38 import org.springframework.context.annotation.Configuration;
39 import org.springframework.context.annotation.EnableAspectJAutoProxy;
40 /*import org.openecomp.vid.policy.PolicyProperties;
41 import org.openecomp.vid.policy.PolicyResponseWrapper;
42 import org.openecomp.vid.policy.PolicyRestInterfaceFactory;
43 import org.openecomp.vid.policy.PolicyRestInterfaceIfc;
44 import org.openecomp.vid.policy.PolicyUtil;*/
45 import org.springframework.http.HttpStatus;
46 import org.springframework.http.ResponseEntity;
47 import org.springframework.web.bind.annotation.RequestBody;
48 import org.springframework.web.bind.annotation.RequestMapping;
49 import org.springframework.web.bind.annotation.RequestMethod;
50 import org.springframework.web.bind.annotation.RestController;
55 * Controller to handle Policy requests.
59 @RequestMapping(PortalConstants.REST_AUX_API)
61 @EnableAspectJAutoProxy
63 public class PolicyController implements BasicAuthenticationController{
66 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyController.class);
68 @RequestMapping(value="/get_policy",method = RequestMethod.POST)
69 public ResponseEntity<String> getPolicyInfo( HttpServletRequest request, @RequestBody JSONObject policy_request) throws Exception {
71 logger.debug(EELFLoggerDelegate.debugLogger, "#####################POLICY API CALL STARTED ###############"+ PolicyProperties.POLICY_GET_CONFIG_VAL);
72 logger.debug(EELFLoggerDelegate.debugLogger, "#####################Policy Request ###############"+policy_request.toString());
74 String path = SystemProperties.getProperty(PolicyProperties.POLICY_GET_CONFIG_VAL);
75 PolicyResponseWrapper policyResWrapper = getPolicyConfig(policy_request,path);
77 logger.debug(EELFLoggerDelegate.debugLogger, "$$$$$$$$$$$$$$$$$$$$$$ " + new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.OK).toString());
79 return ( new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.valueOf(policyResWrapper.getStatus())) );
82 protected static PolicyResponseWrapper getPolicyConfig(JSONObject request, String path) throws Exception {
83 String methodName = "getPolicyConfig";
84 String uuid = UUID.randomUUID().toString();
85 logger.debug(EELFLoggerDelegate.debugLogger, "starting getPolicyConfig ");
88 //STARTING REST API CALL AS AN FACTORY INSTACE
89 PolicyRestInterfaceIfc policyRestController = PolicyRestInterfaceFactory.getInstance();
91 RestObject<String> restObjStr = new RestObject<String>();
92 String str = new String();
94 policyRestController.<String>Post(str, request, uuid, path, restObjStr );
95 PolicyResponseWrapper policyRespWrapper = PolicyUtil.wrapResponse (restObjStr);
96 logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " w=" + policyRespWrapper.getResponse());
97 return policyRespWrapper;
98 } catch (Exception e) {
99 logger.debug(EELFLoggerDelegate.debugLogger, "EXCEPTION in getPolicyConfig <== " + "." + methodName + e.toString());