private void createNewPreferencesFileFromTemplate() throws IOException, URISyntaxException { jsonFile.createNewFile(); File templateFile = loadWorkspacePrefTemplateFile(); json = new JSONObject(FileUtil.readFileContentsToString(templateFile, "UTF-8")); FileUtil.writePrettyPrintedJSONObjectToFile(json, jsonFile); }
private File loadWorkspacePrefTemplateFile() throws IOException { ServletContextParameterMap contextParameters = ContextParametersRegistry.getInstance().getContextParameters(contextId); File file = new File(contextParameters.getParameterValue(ContextParameter.USER_CONFIG_DIRECTORY) + "/workspace-pref.template"); if(!file.exists()) { JSONObject json = new JSONObject(defaultWorkspaceTemplate); file.createNewFile(); FileUtil.writePrettyPrintedJSONObjectToFile(json, file); } return file; }
private File getModelsFile(String contextId) throws IOException { ServletContextParameterMap contextParameters = ContextParametersRegistry.getInstance().getContextParameters(contextId); File file = new File(contextParameters.getParameterValue(ContextParameter.USER_PREFERENCES_DIRECTORY) + "/" + modelFile); if(!file.exists()) { JSONObject json = new JSONObject("{\"models\":[]}"); file.createNewFile(); FileUtil.writePrettyPrintedJSONObjectToFile(json, file); } return file; }
public void saveModelUrl(String url, String contextId) throws JSONException, IOException { File file = getModelsFile(contextId); JSONObject json = new JSONObject(FileUtil.readFileContentsToString(file, "UTF-8")); JSONArray models = ((JSONArray)json.get("models")); JSONArray newModels = new JSONArray(); int modelIndex = modelExists(models, url); for(int i = Math.max(0, models.length() - maxNumUrls); i < models.length(); i ++) { if(modelIndex != i) { newModels.put(models.get(i)); } } newModels.put(url); json.put("models", newModels); FileUtil.writePrettyPrintedJSONObjectToFile(json, file); }
protected void savePreferences() throws JSONException, IOException { ServletContextParameterMap contextParameters = ContextParametersRegistry.getInstance().getContextParameters(contextId); ModelingConfiguration modelingConfiguration = ModelingConfigurationRegistry.getInstance().getModelingConfiguration(contextParameters.getKarmaHome()); if(modelingConfiguration.getOntologyAlignment() || modelingConfiguration.getKnownModelsAlignment()) { FileUtil.writePrettyPrintedJSONObjectToFile(json, jsonFile); } } }