@Test public void testExport() throws IOException { PolicyExportAndImportController controller = new PolicyExportAndImportController(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setBodyContent("{\n\"exportData\": {}\n}\n"); MockHttpServletResponse response = new MockHttpServletResponse(); controller.exportPolicy(request, response); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); }
@RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { try (HSSFWorkbook workBook2 = new HSSFWorkbook()) { ArrayList<String> selectedPolicy = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyExportAdapter adapter = mapper.readValue(root.get("exportData").toString(), PolicyExportAdapter.class); for (Object policyId : adapter.getPolicyDatas()) { LinkedHashMap<?, ?> selected = (LinkedHashMap<?, ?>) policyId; String policyWithScope = selected.get(policyName).toString() + "." + selected.get("activeVersion").toString() + ".xml"; String scope = policyWithScope.substring(0, policyWithScope.lastIndexOf(File.separator)) .replace(File.separator, "."); String policyNamel = policyWithScope.substring(policyWithScope.lastIndexOf(File.separator) + 1); selectedPolicy.add(policyNamel + ":" + scope); } HSSFSheet sheet = workBook2.createSheet("PolicyEntity"); HSSFRow headingRow = sheet.createRow(0); headingRow.createCell(0).setCellValue(policyName); headingRow.createCell(1).setCellValue("scope"); headingRow.createCell(2).setCellValue("version"); headingRow.createCell(3).setCellValue("policyData"); headingRow.createCell(4).setCellValue("description"); headingRow.createCell(5).setCellValue(configurationName); headingRow.createCell(6).setCellValue(BODYSIZE); headingRow.createCell(7).setCellValue(configurationbody); List<Object> entityData = commonClassDao.getMultipleDataOnAddingConjunction(PolicyEntity.class, "policyName:scope", selectedPolicy); processEntityData(entityData, sheet, headingRow); String tmp = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; String deleteCheckPath = tmp + File.separator + "PolicyExport.xls"; File deleteCheck = new File(deleteCheckPath); if (deleteCheck.exists() && deleteCheck.delete()) { logger.info("Deleted the file from system before exporting a new file."); } File temPath = new File(tmp); if (!temPath.exists()) { temPath.mkdir(); } String file = temPath + File.separator + "PolicyExport.xls"; File filepath = new File(file); FileOutputStream fos = new FileOutputStream(filepath); workBook2.write(fos); fos.flush(); response.setContentType(PolicyUtils.APPLICATION_JSON); request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); PrintWriter out = response.getWriter(); String successMap = file.substring(file.lastIndexOf("webapps") + 8); String responseString = mapper.writeValueAsString(successMap); JSONObject json = new JSONObject("{data: " + responseString + "}"); out.write(json.toString()); } catch (Exception e) { logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting Policies" + e); } }
PolicyExportAndImportController extends RestrictedBaseController { @RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { try (HSSFWorkbook workBook2 = new HSSFWorkbook()) { ArrayList<String> selectedPolicy = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyExportAdapter adapter = mapper.readValue(root.get("exportData").toString(), PolicyExportAdapter.class); for (Object policyId : adapter.getPolicyDatas()) { LinkedHashMap<?, ?> selected = (LinkedHashMap<?, ?>) policyId; String policyWithScope = selected.get(policyName).toString() + "." + selected.get("activeVersion").toString() + ".xml"; String scope = policyWithScope.substring(0, policyWithScope.lastIndexOf(File.separator)) .replace(File.separator, "."); String policyNamel = policyWithScope.substring(policyWithScope.lastIndexOf(File.separator) + 1); selectedPolicy.add(policyNamel + ":" + scope); } HSSFSheet sheet = workBook2.createSheet("PolicyEntity"); HSSFRow headingRow = sheet.createRow(0); headingRow.createCell(0).setCellValue(policyName); headingRow.createCell(1).setCellValue("scope"); headingRow.createCell(2).setCellValue("version"); headingRow.createCell(3).setCellValue("policyData"); headingRow.createCell(4).setCellValue("description"); headingRow.createCell(5).setCellValue(configurationName); headingRow.createCell(6).setCellValue(BODYSIZE); headingRow.createCell(7).setCellValue(configurationbody); List<Object> entityData = commonClassDao.getMultipleDataOnAddingConjunction(PolicyEntity.class, "policyName:scope", selectedPolicy); processEntityData(entityData, sheet, headingRow); String tmp = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; String deleteCheckPath = tmp + File.separator + "PolicyExport.xls"; File deleteCheck = new File(deleteCheckPath); if (deleteCheck.exists() && deleteCheck.delete()) { logger.info("Deleted the file from system before exporting a new file."); } File temPath = new File(tmp); if (!temPath.exists()) { temPath.mkdir(); } String file = temPath + File.separator + "PolicyExport.xls"; File filepath = new File(file); FileOutputStream fos = new FileOutputStream(filepath); workBook2.write(fos); fos.flush(); response.setContentType(PolicyUtils.APPLICATION_JSON); request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); PrintWriter out = response.getWriter(); String successMap = file.substring(file.lastIndexOf("webapps") + 8); String responseString = mapper.writeValueAsString(successMap); JSONObject json = new JSONObject("{data: " + responseString + "}"); out.write(json.toString()); } catch (Exception e) { logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting Policies" + e); } } }
PolicyExportAndImportController extends RestrictedBaseController { @RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { try (HSSFWorkbook workBook2 = new HSSFWorkbook()) { ArrayList<String> selectedPolicy = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyExportAdapter adapter = mapper.readValue(root.get("exportData").toString(), PolicyExportAdapter.class); for (Object policyId : adapter.getPolicyDatas()) { LinkedHashMap<?, ?> selected = (LinkedHashMap<?, ?>) policyId; String policyWithScope = selected.get(policyName).toString() + "." + selected.get("activeVersion").toString() + ".xml"; String scope = policyWithScope.substring(0, policyWithScope.lastIndexOf(File.separator)) .replace(File.separator, "."); String policyNamel = policyWithScope.substring(policyWithScope.lastIndexOf(File.separator) + 1); selectedPolicy.add(policyNamel + ":" + scope); } HSSFSheet sheet = workBook2.createSheet("PolicyEntity"); HSSFRow headingRow = sheet.createRow(0); headingRow.createCell(0).setCellValue(policyName); headingRow.createCell(1).setCellValue("scope"); headingRow.createCell(2).setCellValue("version"); headingRow.createCell(3).setCellValue("policyData"); headingRow.createCell(4).setCellValue("description"); headingRow.createCell(5).setCellValue(configurationName); headingRow.createCell(6).setCellValue(BODYSIZE); headingRow.createCell(7).setCellValue(configurationbody); List<Object> entityData = commonClassDao.getMultipleDataOnAddingConjunction(PolicyEntity.class, "policyName:scope", selectedPolicy); processEntityData(entityData, sheet, headingRow); String tmp = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; String deleteCheckPath = tmp + File.separator + "PolicyExport.xls"; File deleteCheck = new File(deleteCheckPath); if (deleteCheck.exists() && deleteCheck.delete()) { logger.info("Deleted the file from system before exporting a new file."); } File temPath = new File(tmp); if (!temPath.exists()) { temPath.mkdir(); } String file = temPath + File.separator + "PolicyExport.xls"; File filepath = new File(file); FileOutputStream fos = new FileOutputStream(filepath); workBook2.write(fos); fos.flush(); response.setContentType(PolicyUtils.APPLICATION_JSON); request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); PrintWriter out = response.getWriter(); String successMap = file.substring(file.lastIndexOf("webapps") + 8); String responseString = mapper.writeValueAsString(successMap); JSONObject json = new JSONObject("{data: " + responseString + "}"); out.write(json.toString()); } catch (Exception e) { logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting Policies" + e); } } PolicyExportAndImportController(); @Autowired private  PolicyExportAndImportController(CommonClassDao commonClassDao); }
PolicyExportAndImportController extends RestrictedBaseController { @RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { try (HSSFWorkbook workBook2 = new HSSFWorkbook()) { ArrayList<String> selectedPolicy = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyExportAdapter adapter = mapper.readValue(root.get("exportData").toString(), PolicyExportAdapter.class); for (Object policyId : adapter.getPolicyDatas()) { LinkedHashMap<?, ?> selected = (LinkedHashMap<?, ?>) policyId; String policyWithScope = selected.get(policyName).toString() + "." + selected.get("activeVersion").toString() + ".xml"; String scope = policyWithScope.substring(0, policyWithScope.lastIndexOf(File.separator)) .replace(File.separator, "."); String policyNamel = policyWithScope.substring(policyWithScope.lastIndexOf(File.separator) + 1); selectedPolicy.add(policyNamel + ":" + scope); } HSSFSheet sheet = workBook2.createSheet("PolicyEntity"); HSSFRow headingRow = sheet.createRow(0); headingRow.createCell(0).setCellValue(policyName); headingRow.createCell(1).setCellValue("scope"); headingRow.createCell(2).setCellValue("version"); headingRow.createCell(3).setCellValue("policyData"); headingRow.createCell(4).setCellValue("description"); headingRow.createCell(5).setCellValue(configurationName); headingRow.createCell(6).setCellValue(BODYSIZE); headingRow.createCell(7).setCellValue(configurationbody); List<Object> entityData = commonClassDao.getMultipleDataOnAddingConjunction(PolicyEntity.class, "policyName:scope", selectedPolicy); processEntityData(entityData, sheet, headingRow); String tmp = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; String deleteCheckPath = tmp + File.separator + "PolicyExport.xls"; File deleteCheck = new File(deleteCheckPath); if (deleteCheck.exists() && deleteCheck.delete()) { logger.info("Deleted the file from system before exporting a new file."); } File temPath = new File(tmp); if (!temPath.exists()) { temPath.mkdir(); } String file = temPath + File.separator + "PolicyExport.xls"; File filepath = new File(file); FileOutputStream fos = new FileOutputStream(filepath); workBook2.write(fos); fos.flush(); response.setContentType(PolicyUtils.APPLICATION_JSON); request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); PrintWriter out = response.getWriter(); String successMap = file.substring(file.lastIndexOf("webapps") + 8); String responseString = mapper.writeValueAsString(successMap); JSONObject json = new JSONObject("{data: " + responseString + "}"); out.write(json.toString()); } catch (Exception e) { logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting Policies" + e); } } PolicyExportAndImportController(); @Autowired private  PolicyExportAndImportController(CommonClassDao commonClassDao); PolicyController getPolicyController(); void setPolicyController(PolicyController policyController); static CommonClassDao getCommonClassDao(); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) void exportPolicy(HttpServletRequest request, HttpServletResponse response); String importRepositoryFile(String file, HttpServletRequest request); String validatMatchRequiredFields(String policyName, String jsonString); }
PolicyExportAndImportController extends RestrictedBaseController { @RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { try (HSSFWorkbook workBook2 = new HSSFWorkbook()) { ArrayList<String> selectedPolicy = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyExportAdapter adapter = mapper.readValue(root.get("exportData").toString(), PolicyExportAdapter.class); for (Object policyId : adapter.getPolicyDatas()) { LinkedHashMap<?, ?> selected = (LinkedHashMap<?, ?>) policyId; String policyWithScope = selected.get(policyName).toString() + "." + selected.get("activeVersion").toString() + ".xml"; String scope = policyWithScope.substring(0, policyWithScope.lastIndexOf(File.separator)) .replace(File.separator, "."); String policyNamel = policyWithScope.substring(policyWithScope.lastIndexOf(File.separator) + 1); selectedPolicy.add(policyNamel + ":" + scope); } HSSFSheet sheet = workBook2.createSheet("PolicyEntity"); HSSFRow headingRow = sheet.createRow(0); headingRow.createCell(0).setCellValue(policyName); headingRow.createCell(1).setCellValue("scope"); headingRow.createCell(2).setCellValue("version"); headingRow.createCell(3).setCellValue("policyData"); headingRow.createCell(4).setCellValue("description"); headingRow.createCell(5).setCellValue(configurationName); headingRow.createCell(6).setCellValue(BODYSIZE); headingRow.createCell(7).setCellValue(configurationbody); List<Object> entityData = commonClassDao.getMultipleDataOnAddingConjunction(PolicyEntity.class, "policyName:scope", selectedPolicy); processEntityData(entityData, sheet, headingRow); String tmp = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; String deleteCheckPath = tmp + File.separator + "PolicyExport.xls"; File deleteCheck = new File(deleteCheckPath); if (deleteCheck.exists() && deleteCheck.delete()) { logger.info("Deleted the file from system before exporting a new file."); } File temPath = new File(tmp); if (!temPath.exists()) { temPath.mkdir(); } String file = temPath + File.separator + "PolicyExport.xls"; File filepath = new File(file); FileOutputStream fos = new FileOutputStream(filepath); workBook2.write(fos); fos.flush(); response.setContentType(PolicyUtils.APPLICATION_JSON); request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); PrintWriter out = response.getWriter(); String successMap = file.substring(file.lastIndexOf("webapps") + 8); String responseString = mapper.writeValueAsString(successMap); JSONObject json = new JSONObject("{data: " + responseString + "}"); out.write(json.toString()); } catch (Exception e) { logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception Occured while Exporting Policies" + e); } } PolicyExportAndImportController(); @Autowired private  PolicyExportAndImportController(CommonClassDao commonClassDao); PolicyController getPolicyController(); void setPolicyController(PolicyController policyController); static CommonClassDao getCommonClassDao(); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/policy_download/exportPolicy.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) void exportPolicy(HttpServletRequest request, HttpServletResponse response); String importRepositoryFile(String file, HttpServletRequest request); String validatMatchRequiredFields(String policyName, String jsonString);  }