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%2FDescriptiveDictionaryController.java;h=b383518061b31c6899c08a144e33e86c079a84b3;hb=a09137c40e602197cbf3b1430d8e33d085357730;hp=b5973d7322d9cddbeb02ed59351829da56e6aa4c;hpb=cbc5914ca2c1770797f6ad2a05ea9d7c30a55b63;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java index b5973d732..b38351806 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.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. @@ -40,6 +40,7 @@ import org.onap.policy.pap.xacml.rest.util.JsonMessage; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.DescriptiveScope; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -63,15 +64,20 @@ public class DescriptiveDictionaryController { DescriptiveDictionaryController.commonClassDao = commonClassDao; } - public DescriptiveDictionaryController(){} + public void setCommonClassDao(CommonClassDao commonClassDao){ + DescriptiveDictionaryController.commonClassDao = commonClassDao; + } + + public DescriptiveDictionaryController(){ + //Empty Constructor + } public UserInfo getUserInfo(String loginId){ - UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); - return name; + return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); } @RequestMapping(value={"/get_DescriptiveScopeByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDescriptiveDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -86,7 +92,7 @@ public class DescriptiveDictionaryController { } @RequestMapping(value={"/get_DescriptiveScope"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDescriptiveDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getDescriptiveDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -120,8 +126,8 @@ public class DescriptiveDictionaryController { GridData data; String userId = null; if (fromAPI) { - descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class); - data = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class); + data = mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); userId = "API"; //check if update operation or create, get id for data to be updated and update attributeData @@ -139,27 +145,26 @@ public class DescriptiveDictionaryController { descriptiveScope.setUserCreatedBy(this.getUserInfo(userId)); } } else { - descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); - data = (GridData)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); + descriptiveScope = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); + data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); userId = root.get("userid").textValue(); } - String header = ""; + StringBuilder header = new StringBuilder(); int counter = 0; - if(data.getAttributes().size() > 0){ + if(!data.getAttributes().isEmpty()){ for(Object attribute : data.getAttributes()){ if(attribute instanceof LinkedHashMap){ String key = ((LinkedHashMap) attribute).get("option").toString(); String value = ((LinkedHashMap) attribute).get("number").toString(); if(counter>0){ - header = header + "AND"; + header.append("AND"); } - header = header + key + ":"; - header = header + value; + header.append(key).append(":").append(value); counter ++; } } } - descriptiveScope.setSearch(header); + descriptiveScope.setSearch(header.toString()); if(descriptiveScope.getId() == 0){ List duplicateData = commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), "descriptiveScopeName", DescriptiveScope.class); if(!duplicateData.isEmpty()){ @@ -210,18 +215,18 @@ public class DescriptiveDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public void removeDescriptiveDictionary(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()); - DescriptiveScope descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("data").toString(), DescriptiveScope.class); + DescriptiveScope descriptiveScope = mapper.readValue(root.get("data").toString(), DescriptiveScope.class); commonClassDao.delete(descriptiveScope); response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); @@ -232,17 +237,14 @@ public class DescriptiveDictionaryController { String responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class)); JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - - return null; } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } - return null; } }