X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FPushPolicyController.java;h=b7b63a9e086c1f62b8f1e2070f69c7feed0742f2;hb=e4ac1ef3c51fc9afe44849ada5bea8c3d6057897;hp=eec34b6425460a929dd737fcec52499b720a0234;hpb=84df4a428ded309f750f52ac1c104ac84e426fc0;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java index eec34b642..b7b63a9e0 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; +import com.att.research.xacml.api.pap.PAPException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -28,8 +34,7 @@ import java.net.URI; import java.util.List; import java.util.UUID; -import javax.persistence.EntityManager; -import javax.persistence.Query; +import javax.script.SimpleBindings; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -48,11 +53,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import com.att.research.xacml.api.pap.PAPException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class PushPolicyController { private static final Logger LOGGER = FlexLogger.getLogger(PushPolicyController.class); @@ -96,8 +96,8 @@ public class PushPolicyController { LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); - String policyVersionName = policyScope.replace(".", File.separator) + File.separator - + filePrefix + policyName; + String policyVersionName = + policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if (policyVersionObject != null) { @@ -123,10 +123,10 @@ public class PushPolicyController { } private void addPolicyToGroup(String policyScope, String policyID, String policyName, String pdpGroup, - HttpServletResponse response) { + HttpServletResponse response) { StdPDPGroup selectedPDPGroup = null; StdPDPPolicy selectedPolicy = null; - //Get the selected PDP Group to push the policy + // Get the selected PDP Group to push the policy try { selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup); } catch (PAPException e1) { @@ -144,20 +144,21 @@ public class PushPolicyController { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } - //Get PolicyEntity from DB; - EntityManager em = XACMLPapServlet.getEmf().createEntityManager(); - Query createPolicyQuery = - em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName"); - createPolicyQuery.setParameter("scope", policyScope); - createPolicyQuery.setParameter(policyNames, policyName.substring(policyScope.length() + 1)); - List createPolicyQueryList = createPolicyQuery.getResultList(); + // Get PolicyEntity from DB; + String createPolicyQuery = "SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName"; + SimpleBindings params = new SimpleBindings(); + params.put("scope", policyScope); + params.put(policyNames, policyName.substring(policyScope.length() + 1)); + List createPolicyQueryList = commonClassDao.getDataByQuery(createPolicyQuery, params); + LOGGER.info("addPolicyToGroup:Total execution time to retrieve " + policyNames + " from PolicyEntity"); + PolicyEntity policyEntity = null; if (!createPolicyQueryList.isEmpty()) { policyEntity = (PolicyEntity) createPolicyQueryList.get(0); } else { PolicyLogger - .error("Somehow, more than one policy with the same scope, name, and deleted status were found in" + - " the database"); + .error("Somehow, more than one policy with the same scope, name, and deleted status were found in" + + " the database"); String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownPolicy");