- // Saving the Configurations file at server location for config policy.
- protected void saveConfigurations(String policyName, String prevPolicyName,
- String ruleBody) {
- final Path gitPath = Paths.get(policyAdapter.getUserGitPath()
- .toString());
- String policyDir = policyAdapter.getParentPath().toString();
- int startIndex = policyDir.indexOf(gitPath.toString())
- + gitPath.toString().length() + 1;
- policyDir = policyDir.substring(startIndex, policyDir.length());
- logger.info("print the main domain value" + policyDir);
- String path = policyDir.replace('\\', '.');
- if (path.contains("/")) {
- path = policyDir.replace('/', '.');
- logger.info("print the path:" + path);
- }
-
-
- String configFileName = getConfigFile(policyName);
- try{
- // Getting the previous policy Config Json file to be used for
- // updating the dictionary tables
- if (policyAdapter.isEditPolicy()) {
-
- String prevConfigFileName = getConfigFile(prevPolicyName);
-
- File oldFile;
- if (CONFIG_HOME.contains("\\")) {
- oldFile = new File(CONFIG_HOME + "\\" + path + "."
- + prevConfigFileName);
- } else {
- oldFile = new File(CONFIG_HOME + "/" + path + "."
- + prevConfigFileName);
- }
-
- String filepath = oldFile.toString();
-
- String prevJsonBody = readFile(filepath, StandardCharsets.UTF_8);
- policyAdapter.setPrevJsonBody(prevJsonBody);
- }
-
- File configHomeDir = new File(CONFIG_HOME);
- File[] listOfFiles = configHomeDir.listFiles();
- if (listOfFiles != null) {
- for (File eachFile : listOfFiles) {
- if (eachFile.isFile()) {
- String fileNameWithoutExtension = FilenameUtils
- .removeExtension(eachFile.getName());
- String configFileNameWithoutExtension = FilenameUtils
- .removeExtension(configFileName);
- if (fileNameWithoutExtension
- .equals(configFileNameWithoutExtension)) {
- // delete the file
- eachFile.delete();
- }
- }
- }
- }
- }
- catch(IOException e){
-
- }
- try {
-
- if (policyName.endsWith(".xml")) {
- policyName = policyName.substring(0,
- policyName.lastIndexOf(".xml"));
- }
- PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator
- + path + "." + policyName + ".txt");
- String expandedBody=expandConfigBody(ruleBody,policyAdapter.getBrmsParamBody());
- out.println(expandedBody);
- out.close();
-
- } catch (Exception e) {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
- }
- }