X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FPolicyExportAndImportController.java;h=78a8c5ad15a69950b6cf89046c6327e5e3638bf7;hb=428150834ee60899b9a8da019bae3c8bf009adf1;hp=92794dda93fecdf4afc08885a53629d263ad9e88;hpb=073cc188efe9abb4c010cf674e34e2cf46ef1c52;p=policy%2Fengine.git 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 92794dda9..78a8c5ad1 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 @@ -21,9 +21,12 @@ package org.onap.policy.controller; +import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; @@ -32,6 +35,7 @@ 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; @@ -55,8 +59,8 @@ import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -115,7 +119,7 @@ public class PolicyExportAndImportController extends RestrictedBaseController { public PolicyExportAndImportController(){} @RequestMapping(value={"/policy_download/exportPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + public void exportPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ String file = null; selectedPolicy = new ArrayList<>(); @@ -201,7 +205,7 @@ public class PolicyExportAndImportController extends RestrictedBaseController { } //Policy Import - public JSONObject importRepositoryFile(String file, HttpServletRequest request) throws Exception{ + public JSONObject importRepositoryFile(String file, HttpServletRequest request) throws IOException{ boolean configExists = false; boolean actionExists = false; String configName = null; @@ -235,6 +239,7 @@ public class PolicyExportAndImportController extends RestrictedBaseController { Iterator rowIterator = datatypeSheet.iterator(); while (rowIterator.hasNext()) { + finalColumn = false; policyEntity = new PolicyEntity(); configurationDataEntity = new ConfigurationDataEntity(); actionBodyEntity = new ActionBodyEntity(); @@ -279,8 +284,11 @@ public class PolicyExportAndImportController extends RestrictedBaseController { if(finalColumn){ scope = policyEntity.getScope().replace(".", File.separator); - String query = "FROM PolicyEntity where policyName = '"+policyEntity.getPolicyName()+"' and scope ='"+policyEntity.getScope()+"'"; - List queryData = controller.getDataByQuery(query); + String query = "FROM PolicyEntity where policyName = :policyName and scope = :policyScope"; + SimpleBindings params = new SimpleBindings(); + params.put("policyName", policyEntity.getPolicyName()); + params.put("policyScope", policyEntity.getScope()); + List queryData = controller.getDataByQuery(query, params); if(!queryData.isEmpty()){ continue; } @@ -338,12 +346,26 @@ public class PolicyExportAndImportController extends RestrictedBaseController { configurationDataEntity.setCreatedBy(userId); configurationDataEntity.setModifiedBy(userId); commonClassDao.save(configurationDataEntity); + try(FileWriter fw = new FileWriter(PolicyController.getConfigHome() + File.separator + configName)){ + BufferedWriter bw = new BufferedWriter(fw); + bw.write(configurationDataEntity.getConfigBody()); + bw.close(); + } catch (IOException e) { + logger.error("Exception Occured While cloning the configuration file",e); + } } if(actionExists){ actionBodyEntity.setDeleted(false); actionBodyEntity.setCreatedBy(userId); actionBodyEntity.setModifiedBy(userId); commonClassDao.save(actionBodyEntity); + try(FileWriter fw = new FileWriter(PolicyController.getActionHome() + File.separator + actionBodyEntity.getActionBodyName())) { + BufferedWriter bw = new BufferedWriter(fw); + bw.write(actionBodyEntity.getActionBody()); + bw.close(); + } catch (IOException e) { + logger.error("Exception Occured While cloning the configuration file",e); + } } if(configName != null){ if(configName.contains("Config_")){