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=856d825bd01135d78373222f07e70e323c183d64;hb=84b95a134c61217667b7eb7b7e774a485d2406ba;hp=bb6f38b8ea5ed0ab7f4cc02852abea2abfbff273;hpb=5458362a7dd96b54916ea3a9a7d0a63a0122e4c2;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 bb6f38b8e..856d825bd 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; @@ -116,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<>(); @@ -202,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; @@ -236,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(); @@ -342,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_")){