X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FExportAndImportDecisionBlackListEntries.java;h=1cfdbb736949e6e30a5d485441a5828442030915;hb=dfd9c0a09c35e4b5b4b61be08b8424e4a3d0d500;hp=8a37e9ddc608a2b50a55bb8124a6ae9dc422cfc8;hpb=95524c8ef8be0d41de8bb2b918f320e464ebb897;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java index 8a37e9ddc..1cfdbb736 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-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. @@ -21,6 +21,7 @@ package org.onap.policy.controller; import com.google.gson.Gson; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -38,8 +39,10 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; @@ -65,8 +68,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; - - /** * This class is used to import and export the black list entries which were used in the Decision Blacklist Guard YAML * Policy. @@ -102,8 +103,8 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr List blackLists = adapter.getYamlparams().getBlackList(); HSSFSheet sheet = workBook.createSheet("BlackList"); HSSFRow headingRow = sheet.createRow(0); - headingRow.createCell(0).setCellValue("Action"); - headingRow.createCell(1).setCellValue("BlackListEntry"); + headingRow.createCell(0).setCellValue(ACTION); + headingRow.createCell(1).setCellValue(BLACKLISTENTRY); short rowNo = 1; for (Object object : blackLists) { @@ -156,7 +157,7 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr out.write(jsonResposne.toString()); } catch (Exception e) { policyLogger.error( - XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting BlackList Entries" , e); + XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting BlackList Entries", e); } } @@ -166,25 +167,27 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr * * @param request the HTTP request contains file upload stream form GUI. * @param response the response is send to the GUI after reading the file input stream. - * @throws FileUploadException throws fileUpload Exception. - * @throws IOException throws IO Exceptions. */ @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) - public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) throws Exception { - List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); - List errorLogs = new ArrayList<>(); - Gson mapper = new Gson(); - errorLogs.add("error"); - Map model = new HashMap<>(); - if (items.isEmpty()) { - errorLogs.add("The File doesn't have any content and it is invalid."); - model.put(BLACKLISTENTRIESDATA, errorLogs); - } else { - readItems(items, errorLogs, model); + public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) { + try { + List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + List errorLogs = new ArrayList<>(); + Gson mapper = new Gson(); + errorLogs.add("error"); + Map model = new HashMap<>(); + if (items.isEmpty()) { + errorLogs.add("The File doesn't have any content and it is invalid."); + model.put(BLACKLISTENTRIESDATA, errorLogs); + } else { + readItems(items, errorLogs, model); + } + JsonMessage msg = new JsonMessage(mapper.toJson(model)); + JSONObject jsonResposne = new JSONObject(msg); + response.getWriter().write(jsonResposne.toString()); + } catch (FileUploadException | IOException e) { + policyLogger.error("Exception Occured while importing the BlackListEntry", e); } - JsonMessage msg = new JsonMessage(mapper.toJson(model)); - JSONObject jsonResposne = new JSONObject(msg); - response.getWriter().write(jsonResposne.toString()); } /** @@ -195,7 +198,7 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr * @param model Map which stores key value (blacklist and append list data) * @throws Exception throws exception if it is not .xls format */ - private void readItems(List items, List errorLogs, Map model) throws Exception { + private void readItems(List items, List errorLogs, Map model) throws IOException { Map files = new HashMap<>(); FileItem item = items.get(0); @@ -238,7 +241,7 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr String error = "Error Occured While Reading File. Please check the format of the file."; errorLogs.add(error); model.put(BLACKLISTENTRIESDATA, errorLogs); - policyLogger.error(error , e); + policyLogger.error(error, e); } } @@ -288,7 +291,6 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr ReturnBlackList returnList = readBlackListCell(cell, lineNo, errorLogs); blEntry = returnList.getEntryValue(); blackListCheck = returnList.isEntryCheck(); - actionEntry = returnList.getActionValue(); } lineNo++; } @@ -326,7 +328,6 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr } /** - * * This method is used to read the BlackList cell entry. * * @param cell reading the blacklist entry cell.