diff options
Diffstat (limited to 'POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin')
3 files changed, 132 insertions, 128 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java index 639e29e3d..1821e1031 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java @@ -95,13 +95,13 @@ public class PolicyManagerServlet extends HttpServlet { LIST, RENAME, COPY, DELETE, EDITFILE, ADDFOLDER, DESCRIBEPOLICYFILE, VIEWPOLICY, ADDSUBSCOPE, SWITCHVERSION, EXPORT, SEARCHLIST } - private PolicyController policyController; - public PolicyController getPolicyController() { + private static PolicyController policyController; + public synchronized PolicyController getPolicyController() { return policyController; } - public void setPolicyController(PolicyController policyController) { - this.policyController = policyController; + public synchronized static void setPolicyController(PolicyController policyController) { + PolicyManagerServlet.policyController = policyController; } private static String CONTENTTYPE = "application/json"; @@ -115,7 +115,7 @@ public class PolicyManagerServlet extends HttpServlet { private static Path closedLoopJsonLocation; private static JsonArray policyNames; - private String testUserId = null; + private static String testUserId = null; public static JsonArray getPolicyNames() { return policyNames; @@ -126,7 +126,6 @@ public class PolicyManagerServlet extends HttpServlet { } private static List<String> serviceTypeNamesList = new ArrayList<>(); - private List<Object> policyData; public static List<String> getServiceTypeNamesList() { return serviceTypeNamesList; @@ -192,7 +191,11 @@ public class PolicyManagerServlet extends HttpServlet { fileOperation(request, response); } } catch (Exception e) { - setError(e, response); + try { + setError(e, response); + }catch(Exception e1){ + LOGGER.error("Exception Occured"+e1); + } } } @@ -270,6 +273,7 @@ public class PolicyManagerServlet extends HttpServlet { Mode mode = Mode.valueOf(params.getString("mode")); switch (mode) { case ADDFOLDER: + case ADDSUBSCOPE: responseJsonObject = addFolder(params, request); break; case COPY: @@ -278,12 +282,10 @@ public class PolicyManagerServlet extends HttpServlet { case DELETE: responseJsonObject = delete(params, request); break; - case EDITFILE: + case EDITFILE: + case VIEWPOLICY: responseJsonObject = editFile(params); break; - case VIEWPOLICY: - responseJsonObject = editFile(params); - break; case LIST: responseJsonObject = list(params, request); break; @@ -293,9 +295,6 @@ public class PolicyManagerServlet extends HttpServlet { case DESCRIBEPOLICYFILE: responseJsonObject = describePolicy(params); break; - case ADDSUBSCOPE: - responseJsonObject = addFolder(params, request); - break; case SWITCHVERSION: responseJsonObject = switchVersion(params, request); break; @@ -321,7 +320,7 @@ public class PolicyManagerServlet extends HttpServlet { private JSONObject searchPolicyList(JSONObject params, HttpServletRequest request) { Set<String> scopes = null; List<String> roles = null; - policyData = new ArrayList<>(); + List<Object> policyData = new ArrayList<>(); JSONArray policyList = null; if(params.has("policyList")){ policyList = (JSONArray) params.get("policyList"); @@ -1230,7 +1229,7 @@ public class PolicyManagerServlet extends HttpServlet { policyEntity = (PolicyEntity) object; String policyEntityName = policyEntity.getPolicyName().replace(".xml", ""); int policyEntityVersion = Integer.parseInt(policyEntityName.substring(policyEntityName.lastIndexOf(".")+1)); - if(policyEntityVersion > highestVersion){ + if(policyEntityVersion > highestVersion && policyEntityVersion != version){ highestVersion = policyEntityVersion; } } @@ -1472,7 +1471,7 @@ public class PolicyManagerServlet extends HttpServlet { return testUserId; } - public void setTestUserId(String testUserId) { - this.testUserId = testUserId; + public static void setTestUserId(String testUserId) { + PolicyManagerServlet.testUserId = testUserId; } }
\ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java index 9bd6e4f43..1a535dc76 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java @@ -106,7 +106,7 @@ public class PolicyNotificationMail{ + '\n' + '\n' + "Moved By : " +entityItem.getModifiedBy() + '\n' + "Moved Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; } String policyFileName = entityItem.getPolicyName(); - String checkPolicyName = policyFileName; + String checkPolicyName = policyName; if(policyFileName.contains("/")){ policyFileName = policyFileName.substring(0, policyFileName.indexOf("/")); policyFileName = policyFileName.replace("/", File.separator); @@ -119,40 +119,41 @@ public class PolicyNotificationMail{ String query = "from WatchPolicyNotificationTable where policyName like'" +policyFileName+"%'"; boolean sendFlag = false; List<Object> watchList = policyNotificationDao.getDataByQuery(query); - if(watchList != null){ - if(watchList.isEmpty()){ - for(Object watch : watchList){ - WatchPolicyNotificationTable list = (WatchPolicyNotificationTable) watch; - String watchPolicyName = list.getPolicyName(); - if(watchPolicyName.contains("Config_") || watchPolicyName.contains("Action_") || watchPolicyName.contains("Decision_")){ - if(watchPolicyName.equals(checkPolicyName)){ - sendFlag = true; - }else{ - sendFlag = false; - } + if(watchList != null && !watchList.isEmpty()){ + for(Object watch : watchList){ + WatchPolicyNotificationTable list = (WatchPolicyNotificationTable) watch; + String watchPolicyName = list.getPolicyName(); + if(watchPolicyName.contains("Config_") || watchPolicyName.contains("Action_") || watchPolicyName.contains("Decision_")){ + if(watchPolicyName.equals(checkPolicyName)){ + sendFlag = true; + }else{ + sendFlag = false; } - if(sendFlag){ - AnnotationConfigApplicationContext ctx = null; - try { - to = list.getLoginIds()+"@"+PolicyController.getSmtpApplicationName(); - to = to.trim(); - ctx = new AnnotationConfigApplicationContext(); - ctx.register(PolicyNotificationMail.class); - ctx.refresh(); - JavaMailSenderImpl mailSender = ctx.getBean(JavaMailSenderImpl.class); - MimeMessage mimeMessage = mailSender.createMimeMessage(); - MimeMessageHelper mailMsg = new MimeMessageHelper(mimeMessage); - mailMsg.setFrom(new InternetAddress(from, "Policy Notification System")); - mailMsg.setTo(to); - mailMsg.setSubject(subject); - mailMsg.setText(message); - mailSender.send(mimeMessage); - } catch (Exception e) { - policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception Occured in Policy Notification" +e); - }finally{ - if(ctx != null){ - ctx.close(); - } + } + if(sendFlag){ + AnnotationConfigApplicationContext ctx = null; + try { + to = list.getLoginIds()+"@"+PolicyController.getSmtpEmailExtension(); + to = to.trim(); + ctx = new AnnotationConfigApplicationContext(); + ctx.register(PolicyNotificationMail.class); + ctx.refresh(); + JavaMailSenderImpl mailSender = ctx.getBean(JavaMailSenderImpl.class); + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper mailMsg = new MimeMessageHelper(mimeMessage); + mailMsg.setFrom(new InternetAddress(from, "Policy Notification System")); + mailMsg.setTo(to); + mailMsg.setSubject(subject); + mailMsg.setText(message); + mailSender.send(mimeMessage); + if(mode.equalsIgnoreCase("Rename") || mode.contains("Delete") || mode.contains("Move")){ + policyNotificationDao.delete(watch); + } + } catch (Exception e) { + policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception Occured in Policy Notification" +e); + }finally{ + if(ctx != null){ + ctx.close(); } } } diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyRestController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyRestController.java index 2c04bc66d..08ef99f94 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyRestController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/PolicyRestController.java @@ -86,90 +86,90 @@ public class PolicyRestController extends RestrictedBaseController{ CommonClassDao commonClassDao; @RequestMapping(value={"/policycreation/save_policy"}, method={RequestMethod.POST}) - public ModelAndView policyCreationController(HttpServletRequest request, HttpServletResponse response) throws Exception{ - + public void policyCreationController(HttpServletRequest request, HttpServletResponse response) { String userId = UserUtils.getUserSession(request).getOrgUserId(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JsonNode root = mapper.readTree(request.getReader()); - - PolicyRestAdapter policyData = mapper.readValue(root.get(PolicyController.getPolicydata()).get("policy").toString(), PolicyRestAdapter.class); - - if("file".equals(root.get(PolicyController.getPolicydata()).get(modal).get("type").toString().replace("\"", ""))){ - policyData.setEditPolicy(true); - } - if(root.get(PolicyController.getPolicydata()).get(modal).get("path").size() != 0){ - String dirName = ""; - for(int i = 0; i < root.get(PolicyController.getPolicydata()).get(modal).get("path").size(); i++){ - dirName = dirName.replace("\"", "") + root.get(PolicyController.getPolicydata()).get(modal).get("path").get(i).toString().replace("\"", "") + File.separator; + try{ + JsonNode root = mapper.readTree(request.getReader()); + + PolicyRestAdapter policyData = mapper.readValue(root.get(PolicyController.getPolicydata()).get("policy").toString(), PolicyRestAdapter.class); + + if("file".equals(root.get(PolicyController.getPolicydata()).get(modal).get("type").toString().replace("\"", ""))){ + policyData.setEditPolicy(true); } - if(policyData.isEditPolicy()){ - policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + if(root.get(PolicyController.getPolicydata()).get(modal).get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get(PolicyController.getPolicydata()).get(modal).get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get(PolicyController.getPolicydata()).get(modal).get("path").get(i).toString().replace("\"", "") + File.separator; + } + if(policyData.isEditPolicy()){ + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(dirName + root.get(PolicyController.getPolicydata()).get(modal).get("name").toString().replace("\"", "")); + } }else{ - policyData.setDomainDir(dirName + root.get(PolicyController.getPolicydata()).get(modal).get("name").toString().replace("\"", "")); - } - }else{ - String domain = root.get(PolicyController.getPolicydata()).get("model").get("name").toString(); - if(domain.contains("/")){ - domain = domain.substring(0, domain.lastIndexOf('/')).replace("/", File.separator); + String domain = root.get(PolicyController.getPolicydata()).get("model").get("name").toString(); + if(domain.contains("/")){ + domain = domain.substring(0, domain.lastIndexOf('/')).replace("/", File.separator); + } + domain = domain.replace("\"", ""); + policyData.setDomainDir(domain); } - domain = domain.replace("\"", ""); - policyData.setDomainDir(domain); - } - - if(policyData.getConfigPolicyType() != null){ - if("ClosedLoop_Fault".equalsIgnoreCase(policyData.getConfigPolicyType())){ - CreateClosedLoopFaultController faultController = new CreateClosedLoopFaultController(); - policyData = faultController.setDataToPolicyRestAdapter(policyData, root); - }else if("Firewall Config".equalsIgnoreCase(policyData.getConfigPolicyType())){ - CreateFirewallController fwController = new CreateFirewallController(); - policyData = fwController.setDataToPolicyRestAdapter(policyData); - }else if("Micro Service".equalsIgnoreCase(policyData.getConfigPolicyType())){ - CreateDcaeMicroServiceController msController = new CreateDcaeMicroServiceController(); - policyData = msController.setDataToPolicyRestAdapter(policyData, root); + + if(policyData.getConfigPolicyType() != null){ + if("ClosedLoop_Fault".equalsIgnoreCase(policyData.getConfigPolicyType())){ + CreateClosedLoopFaultController faultController = new CreateClosedLoopFaultController(); + policyData = faultController.setDataToPolicyRestAdapter(policyData, root); + }else if("Firewall Config".equalsIgnoreCase(policyData.getConfigPolicyType())){ + CreateFirewallController fwController = new CreateFirewallController(); + policyData = fwController.setDataToPolicyRestAdapter(policyData); + }else if("Micro Service".equalsIgnoreCase(policyData.getConfigPolicyType())){ + CreateDcaeMicroServiceController msController = new CreateDcaeMicroServiceController(); + policyData = msController.setDataToPolicyRestAdapter(policyData, root); + } } - } - - policyData.setUserId(userId); - - String result; - String body = PolicyUtils.objectToJsonString(policyData); - String uri = request.getRequestURI(); - ResponseEntity<?> responseEntity = sendToPAP(body, uri, HttpMethod.POST); - if(responseEntity != null && responseEntity.getBody().equals(HttpServletResponse.SC_CONFLICT)){ - result = "PolicyExists"; - }else if(responseEntity != null){ - result = responseEntity.getBody().toString(); - String policyName = responseEntity.getHeaders().get("policyName").get(0); - if(policyData.isEditPolicy() && "success".equalsIgnoreCase(result)){ - PolicyNotificationMail email = new PolicyNotificationMail(); - String mode = "EditPolicy"; - String watchPolicyName = policyName.replace(".xml", ""); - String version = watchPolicyName.substring(watchPolicyName.lastIndexOf('.')+1); - watchPolicyName = watchPolicyName.substring(0, watchPolicyName.lastIndexOf('.')).replace(".", File.separator); - String policyVersionName = watchPolicyName.replace(".", File.separator); - watchPolicyName = watchPolicyName + "." + version + ".xml"; - PolicyVersion entityItem = new PolicyVersion(); - entityItem.setPolicyName(policyVersionName); - entityItem.setActiveVersion(Integer.parseInt(version)); - entityItem.setModifiedBy(userId); - email.sendMail(entityItem, watchPolicyName, mode, commonClassDao); + + policyData.setUserId(userId); + + String result; + String body = PolicyUtils.objectToJsonString(policyData); + String uri = request.getRequestURI(); + ResponseEntity<?> responseEntity = sendToPAP(body, uri, HttpMethod.POST); + if(responseEntity != null && responseEntity.getBody().equals(HttpServletResponse.SC_CONFLICT)){ + result = "PolicyExists"; + }else if(responseEntity != null){ + result = responseEntity.getBody().toString(); + String policyName = responseEntity.getHeaders().get("policyName").get(0); + if(policyData.isEditPolicy() && "success".equalsIgnoreCase(result)){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String watchPolicyName = policyName.replace(".xml", ""); + String version = watchPolicyName.substring(watchPolicyName.lastIndexOf('.')+1); + watchPolicyName = watchPolicyName.substring(0, watchPolicyName.lastIndexOf('.')).replace(".", File.separator); + String policyVersionName = watchPolicyName.replace(".", File.separator); + watchPolicyName = watchPolicyName + "." + version + ".xml"; + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setPolicyName(policyVersionName); + entityItem.setActiveVersion(Integer.parseInt(version)); + entityItem.setModifiedBy(userId); + email.sendMail(entityItem, watchPolicyName, mode, commonClassDao); + } + }else{ + result = "Response is null from PAP"; } - }else{ - result = "Response is null from PAP"; - } - - - response.setCharacterEncoding(PolicyController.getCharacterencoding()); - response.setContentType(PolicyController.getContenttype()); - request.setCharacterEncoding(PolicyController.getCharacterencoding()); - PrintWriter out = response.getWriter(); - String responseString = mapper.writeValueAsString(result); - JSONObject j = new JSONObject("{policyData: " + responseString + "}"); - out.write(j.toString()); - return null; + response.setCharacterEncoding(PolicyController.getCharacterencoding()); + response.setContentType(PolicyController.getContenttype()); + request.setCharacterEncoding(PolicyController.getCharacterencoding()); + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(result); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + }catch(Exception e){ + policyLogger.error("Exception Occured while saving policy" , e); + } } @@ -344,7 +344,7 @@ public class PolicyRestController extends RestrictedBaseController{ } @RequestMapping(value={"/getDictionary/*"}, method={RequestMethod.GET}) - public void getDictionaryController(HttpServletRequest request, HttpServletResponse response) throws Exception{ + public void getDictionaryController(HttpServletRequest request, HttpServletResponse response){ String uri = request.getRequestURI().replace("/getDictionary", ""); String body = null; ResponseEntity<?> responseEntity = sendToPAP(null, uri, HttpMethod.GET); @@ -353,7 +353,11 @@ public class PolicyRestController extends RestrictedBaseController{ }else{ body = ""; } - response.getWriter().write(body); + try { + response.getWriter().write(body); + } catch (IOException e) { + policyLogger.error("Exception occured while getting Dictionary entries", e); + } } @RequestMapping(value={"/saveDictionary/*/*"}, method={RequestMethod.POST}) |