X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FPolicyNotificationController.java;h=845b5f5a7e50367bce413fe8e50013a8972ed975;hb=428150834ee60899b9a8da019bae3c8bf009adf1;hp=f3291a79babd0a4c599f09bc8f7336db0ecd246f;hpb=073cc188efe9abb4c010cf674e34e2cf46ef1c52;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java index f3291a79b..845b5f5a7 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java @@ -25,17 +25,21 @@ package org.onap.policy.controller; * * */ import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.util.List; +import javax.script.SimpleBindings; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.WatchPolicyNotificationTable; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -49,23 +53,24 @@ import com.fasterxml.jackson.databind.node.ArrayNode; @Controller @RequestMapping({"/"}) public class PolicyNotificationController extends RestrictedBaseController { + private static Logger logger = FlexLogger.getLogger(PolicyNotificationController.class); @Autowired CommonClassDao commonClassDao; @RequestMapping(value={"/watchPolicy"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView watchPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + public ModelAndView watchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{ String path = ""; String responseValue = ""; try { String userId = UserUtils.getUserSession(request).getOrgUserId(); - System.out.println(userId); + logger.info("userid info: " + userId); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); String name = root.get("watchData").get("name").toString(); JsonNode pathList = root.get("watchData").get("path"); - String finalName = ""; + String finalName; if(pathList.isArray()){ ArrayNode arrayNode = (ArrayNode) pathList; for (int i = 0; i < arrayNode.size(); i++) { @@ -86,8 +91,11 @@ public class PolicyNotificationController extends RestrictedBaseController { if(finalName.contains("\\")){ finalName = finalName.replace("\\", "\\\\"); } - String query = "from WatchPolicyNotificationTable where POLICYNAME = '"+finalName+"' and LOGINIDS = '"+userId+"'"; - List watchList = commonClassDao.getDataByQuery(query); + String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId"; + SimpleBindings params = new SimpleBindings(); + params.put("finalName", finalName); + params.put("userId", userId); + List watchList = commonClassDao.getDataByQuery(query, params); if(watchList.isEmpty()){ if(finalName.contains("\\\\")){ finalName = finalName.replace("\\\\", File.separator); @@ -114,6 +122,7 @@ public class PolicyNotificationController extends RestrictedBaseController { }catch(Exception e){ response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); + logger.error("Error druing watchPolicy function " + e); PrintWriter out = response.getWriter(); out.write(e.getMessage()); }