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%2FActionPolicyDictionaryController.java;h=02b0707b6713b3646cd8cd462892fd9806ec87ff;hb=a09137c40e602197cbf3b1430d8e33d085357730;hp=b5a3b45e818ef2785ffc506519dd3d53f3b6fcf8;hpb=1bfd18f999cda39a7b27bef8972864aafe59aecb;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java index b5a3b45e8..02b0707b6 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -38,6 +38,7 @@ import org.onap.policy.pap.xacml.rest.util.JsonMessage; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionPolicyDict; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -60,6 +61,10 @@ public class ActionPolicyDictionaryController { public ActionPolicyDictionaryController(CommonClassDao commonClassDao){ ActionPolicyDictionaryController.commonClassDao = commonClassDao; } + + public void setCommonClassDao(CommonClassDao commonClassDao){ + ActionPolicyDictionaryController.commonClassDao = commonClassDao; + } /* * This is an empty constructor */ @@ -123,8 +128,8 @@ public class ActionPolicyDictionaryController { String userId = null; if(fromAPI) { - actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class); - adapter = (ActionAdapter)mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class); + actionPolicyDict = mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class); + adapter = mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class); userId = "API"; //check if update operation or create, get id for data to be updated and update attributeData @@ -141,11 +146,11 @@ public class ActionPolicyDictionaryController { actionPolicyDict.setUserCreatedBy(this.getUserInfo(userId)); } } else { - actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class); + actionPolicyDict = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class); adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class); userId = root.get("userid").textValue(); } - String header = ""; + StringBuilder header = new StringBuilder(); int counter = 0; if(!adapter.getHeaders().isEmpty()){ for(Object attribute : adapter.getHeaders()){ @@ -153,15 +158,14 @@ public class ActionPolicyDictionaryController { String key = ((LinkedHashMap) attribute).get("option").toString(); String value = ((LinkedHashMap) attribute).get("number").toString(); if(counter>0){ - header = header + ":"; + header.append(":"); } - header = header + key + "="; - header = header + value; + header.append(key).append("=").append(value); counter ++; } } } - actionPolicyDict.setHeader(header); + actionPolicyDict.setHeader(header.toString()); if(actionPolicyDict.getId() == 0){ List duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class); if(!duplicateData.isEmpty()){ @@ -215,18 +219,18 @@ public class ActionPolicyDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + public void removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class); + ActionPolicyDict actionPolicyDict = mapper.readValue(root.get("data").toString(), ActionPolicyDict.class); commonClassDao.delete(actionPolicyDict); response.setCharacterEncoding(utf8); response.setContentType("application / json"); @@ -237,8 +241,6 @@ public class ActionPolicyDictionaryController { String responseString = mapper.writeValueAsString(ActionPolicyDictionaryController.commonClassDao.getData(ActionPolicyDict.class)); JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - - return null; } catch (Exception e){ LOGGER.error(e); @@ -247,7 +249,6 @@ public class ActionPolicyDictionaryController { PrintWriter out = response.getWriter(); out.write(e.getMessage()); } - return null; } }