X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FPolicyExportAndImportController.java;h=fb566f37d6b85de30ef2730f56d8e4e584a04fdc;hp=6c7a0aff3b9b2cf506ffc6c40024a1898b7217b9;hb=dfd9c0a09c35e4b5b4b61be08b8424e4a3d0d500;hpb=ffd7241c7bfa8d8b68b504406fc6ed4cc299ffe6 diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java index 6c7a0aff3..fb566f37d 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-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. @@ -23,6 +23,7 @@ package org.onap.policy.controller; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; @@ -35,9 +36,11 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Set; + import javax.script.SimpleBindings; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -90,7 +93,6 @@ public class PolicyExportAndImportController extends RestrictedBaseController { private static final String ACTION = "Action_"; private static CommonClassDao commonClassDao; - private PolicyController policyController; public PolicyController getPolicyController() { @@ -120,7 +122,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { * @param response HttpServletResponse * @throws IOException error out */ - @RequestMapping(value = {"/policy_download/exportPolicy.htm"}, + @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()) { @@ -134,9 +137,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { 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 scope = policyWithScope.substring(0, policyWithScope.lastIndexOf(File.separator)) + .replace(File.separator, "."); String policyNamel = policyWithScope.substring(policyWithScope.lastIndexOf(File.separator) + 1); selectedPolicy.add(policyNamel + ":" + scope); } @@ -152,9 +154,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { headingRow.createCell(6).setCellValue(BODYSIZE); headingRow.createCell(7).setCellValue(configurationbody); - List entityData = - commonClassDao.getMultipleDataOnAddingConjunction(PolicyEntity.class, "policyName:scope", - selectedPolicy); + List 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"; @@ -233,8 +234,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { row.createCell(7).setCellValue(body.substring(index, Math.min(index + 30000, body.length()))); } else { headingRow.createCell(7 + arraySize).setCellValue(configurationbody + arraySize); - row.createCell(7 + arraySize).setCellValue( - body.substring(index, Math.min(index + 30000, body.length()))); + row.createCell(7 + arraySize) + .setCellValue(body.substring(index, Math.min(index + 30000, body.length()))); } index += 30000; arraySize += 1; @@ -247,8 +248,6 @@ public class PolicyExportAndImportController extends RestrictedBaseController { return row; } - - /** * This is to upload a policy and save it to database. * @@ -331,9 +330,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { } private void writeConfigurationFile(ConfigurationDataEntity configurationDataEntity) { - try (FileWriter fw = - new FileWriter(PolicyController.getConfigHome() + File.separator - + configurationDataEntity.getConfigurationName())) { + try (FileWriter fw = new FileWriter( + PolicyController.getConfigHome() + File.separator + configurationDataEntity.getConfigurationName())) { BufferedWriter bw = new BufferedWriter(fw); bw.write(configurationDataEntity.getConfigBody()); bw.close(); @@ -343,8 +341,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { } private void writeActionBodyFile(ActionBodyEntity actionBodyEntity) { - try (FileWriter fw = - new FileWriter(PolicyController.getActionHome() + File.separator + actionBodyEntity.getActionBodyName())) { + try (FileWriter fw = new FileWriter( + PolicyController.getActionHome() + File.separator + actionBodyEntity.getActionBodyName())) { BufferedWriter bw = new BufferedWriter(fw); bw.write(actionBodyEntity.getActionBody()); bw.close(); @@ -605,14 +603,12 @@ public class PolicyExportAndImportController extends RestrictedBaseController { private void savePolicyEntity(PolicyEntity policyEntity, String configName, String userId) { if (configName != null) { if (configName.contains(config) || configName.contains(DECISION_MS)) { - ConfigurationDataEntity configuration = - (ConfigurationDataEntity) commonClassDao.getEntityItem(ConfigurationDataEntity.class, - configurationName, configName); + ConfigurationDataEntity configuration = (ConfigurationDataEntity) commonClassDao + .getEntityItem(ConfigurationDataEntity.class, configurationName, configName); policyEntity.setConfigurationData(configuration); } else { - ActionBodyEntity actionBody = - (ActionBodyEntity) commonClassDao.getEntityItem(ActionBodyEntity.class, "actionBodyName", - configName); + ActionBodyEntity actionBody = (ActionBodyEntity) commonClassDao.getEntityItem(ActionBodyEntity.class, + "actionBodyName", configName); policyEntity.setActionBodyEntity(actionBody); } } @@ -639,8 +635,9 @@ public class PolicyExportAndImportController extends RestrictedBaseController { private int getSetBodySize(PolicyEntity policyEntity, Cell cell, int setBodySize) { int setBodySizel = setBodySize; if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) - && ((policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName() - .contains(DECISION_MS)) && (policyEntity.getPolicyName().contains("Config_BRMS_Param_")))) { + && ((policyEntity.getPolicyName().contains(config) + || policyEntity.getPolicyName().contains(DECISION_MS)) + && (policyEntity.getPolicyName().contains("Config_BRMS_Param_")))) { setBodySizel += 1; } return setBodySizel; @@ -664,29 +661,28 @@ public class PolicyExportAndImportController extends RestrictedBaseController { boolean configurationBodySet) { boolean configurationBodySetl = configurationBodySet; if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) - && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS)) - && (setBodySize == bodySize)) { + && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS)) + && (setBodySize == bodySize)) { configurationBodySetl = true; } if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) - && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS)) - && (setBodySize == 0)) { + && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS)) + && (setBodySize == 0)) { configurationBodySetl = true; } return configurationBodySetl; } - private boolean isConfigExists(PolicyEntity policyEntity, Cell cell, boolean configExists) { boolean configExistsl = configExists; if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) - && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS))) { + && (policyEntity.getPolicyName().contains(config) + || policyEntity.getPolicyName().contains(DECISION_MS))) { configExistsl = true; } return configExistsl; } - private boolean isActionExists(PolicyEntity policyEntity, Cell cell, boolean actionExists) { boolean actionExistsl = actionExists; if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) @@ -706,17 +702,18 @@ public class PolicyExportAndImportController extends RestrictedBaseController { private StringBuilder addCellValue(PolicyEntity policyEntity, Cell cell, StringBuilder body) { if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) - && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS))) { + && (policyEntity.getPolicyName().contains(config) + || policyEntity.getPolicyName().contains(DECISION_MS))) { body.append(cell.getStringCellValue()); } return body; } - private ActionBodyEntity setActionBodyObject(PolicyEntity policyEntity, ActionBodyEntity actionBodyEntity, + private ActionBodyEntity setActionBodyObject(PolicyEntity policyEntity, ActionBodyEntity actionBodyEntity, Cell cell) { if (configurationbody.equalsIgnoreCase(getCellHeaderName(cell)) - && (policyEntity.getPolicyName().contains(ACTION))) { + && (policyEntity.getPolicyName().contains(ACTION))) { actionBodyEntity.setActionBody(cell.getStringCellValue()); } return actionBodyEntity; @@ -734,7 +731,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController { private ConfigurationDataEntity populateConfigurationDataEntity(PolicyEntity policyEntity, ConfigurationDataEntity configurationDataEntity, Cell cell) { if (configurationName.equalsIgnoreCase(getCellHeaderName(cell)) - && (policyEntity.getPolicyName().contains(config) || policyEntity.getPolicyName().contains(DECISION_MS))) { + && (policyEntity.getPolicyName().contains(config) + || policyEntity.getPolicyName().contains(DECISION_MS))) { configurationDataEntity.setConfigurationName(cell.getStringCellValue()); } return configurationDataEntity;