List of usage examples for org.apache.commons.configuration SubnodeConfiguration setProperty
public void setProperty(String key, Object value)
From source file:com.yfiton.notifiers.slack.SlackNotifier.java
@Override protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException { String teamId = accessTokenData.get("teamId"); configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId); SubnodeConfiguration section = configuration.getSection(teamId); section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken()); for (Map.Entry<String, String> entry : accessTokenData.getData()) { section.setProperty(entry.getKey(), entry.getValue()); }/*from www . j av a 2 s .c o m*/ try { configuration.save(); } catch (ConfigurationException e) { throw new NotificationException(e); } }
From source file:com.eyeq.pivot4j.ui.property.ConditionalProperty.java
/** * @see com.eyeq.pivot4j.ui.property.AbstractProperty#saveSettings(org.apache.commons.configuration.HierarchicalConfiguration) *//*from www. j a va2s. com*/ @Override public void saveSettings(HierarchicalConfiguration configuration) { super.saveSettings(configuration); if (defaultValue != null) { configuration.setProperty("default", defaultValue); } if (values != null) { int index = 0; configuration.setProperty("conditions", ""); SubnodeConfiguration configurations = configuration.configurationAt("conditions"); for (ConditionalValue value : values) { String prefix = String.format("condition-property(%s)", index++); configurations.setProperty(prefix + ".condition", ""); configurations.setProperty(prefix + ".value", value.getValue()); SubnodeConfiguration conditionConfig = configurations.configurationAt(prefix + ".condition"); value.getCondition().saveSettings(conditionConfig); } } }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private void writeWp43Configs(List<Contingency> contingencies, Path workingDir) throws IOException, ConfigurationException { Path baseWp43ConfigFile = PlatformConfig.CONFIG_DIR.resolve(WP43_CONFIGS_FILE_NAME); // generate one variant of the base config for all the contingency // this allow to add extra variables for some indexes HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(baseWp43ConfigFile.toFile()); SubnodeConfiguration node = configuration.getSection("smallsignal"); node.setProperty("f_instant", parameters.getFaultEventInstant()); for (int i = 0; i < contingencies.size(); i++) { Contingency contingency = contingencies.get(i); if (contingency.getElements().isEmpty()) { throw new AssertionError("Empty contingency " + contingency.getId()); }//www .ja v a 2 s . c o m Iterator<ContingencyElement> it = contingency.getElements().iterator(); // compute the maximum fault duration double maxDuration = getFaultDuration(contingency, it.next()); while (it.hasNext()) { maxDuration = Math.max(maxDuration, getFaultDuration(contingency, it.next())); } node.setProperty("f_duration", maxDuration); Path wp43Config = workingDir.resolve(WP43_CONFIGS_PER_FAULT_FILE_NAME .replace(Command.EXECUTION_NUMBER_PATTERN, Integer.toString(i))); try (Writer writer = Files.newBufferedWriter(wp43Config, StandardCharsets.UTF_8)) { configuration.save(writer); } } }
From source file:eu.itesla_project.dymola.DymolaImpactAnalysis.java
private List<String> writeDymolaInputs(Path workingDir, List<Contingency> contingencies) throws IOException { LOGGER.info(" Start writing dymola inputs"); List<String> retList = new ArrayList<>(); DdbConfig ddbConfig = DdbConfig.load(); String jbossHost = ddbConfig.getJbossHost(); String jbossPort = ddbConfig.getJbossPort(); String jbossUser = ddbConfig.getJbossUser(); String jbossPassword = ddbConfig.getJbossPassword(); Path dymolaExportPath = workingDir.resolve(MO_EXPORT_DIRECTORY); if (!Files.exists(dymolaExportPath)) { Files.createDirectory(dymolaExportPath); }/*from w ww. jav a 2 s. c o m*/ //retrieve modelica export parameters from configuration String modelicaVersion = config.getModelicaVersion(); String sourceEngine = config.getSourceEngine(); String sourceVersion = config.getSourceEngineVersion(); Path modelicaPowerSystemLibraryPath = Paths.get(config.getModelicaPowerSystemLibraryFile()); //write the modelica events file, to feed the modelica exporter Path eventsPath = workingDir.resolve(MODELICA_EVENTS_CSV_FILENAME); writeModelicaExporterContingenciesFile(eventsPath, contingencies); //these are only optional params needed if the source is eurostag Path modelicaLibPath = null; String slackId = config.getSlackId(); if ("".equals(slackId)) { slackId = null; // null when not specified () } LoadFlowFactory loadFlowFactory; try { loadFlowFactory = config.getLoadFlowFactoryClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } LOGGER.info("Exporting modelica data for network {}, working state-id {} ", network, network.getStateManager().getWorkingStateId()); ModelicaMainExporter exporter = new ModelicaMainExporter(network, slackId, jbossHost, jbossPort, jbossUser, jbossPassword, modelicaVersion, sourceEngine, sourceVersion, modelicaLibPath, loadFlowFactory); exporter.export(dymolaExportPath); ModEventsExport eventsExporter = new ModEventsExport( dymolaExportPath.resolve(network.getId() + ".mo").toFile(), eventsPath.toFile()); eventsExporter.export(dymolaExportPath); LOGGER.info(" modelica data exported."); // now assemble the input files to feed dymola // one .zip per contingency; in the zip, the .mo file and the powersystem library //TODO here it is assumed that contingencies ids in csv file start from 0 (i.e. 0 is the first contingency); id should be decoupled from the implementation try (final Stream<Path> pathStream = Files.walk(dymolaExportPath)) { pathStream.filter((p) -> !p.toFile().isDirectory() && p.toFile().getAbsolutePath().contains("events_") && p.toFile().getAbsolutePath().endsWith(".mo")).forEach(p -> { GenericArchive archive = ShrinkWrap.createDomain().getArchiveFactory() .create(GenericArchive.class); try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) { Path rootDir = fileSystem.getPath("/"); Files.copy(modelicaPowerSystemLibraryPath, rootDir.resolve(modelicaPowerSystemLibraryPath.getFileName())); Files.copy(Paths.get(p.toString()), rootDir.resolve(DymolaUtil.DYMOLA_SIM_MODEL_INPUT_PREFIX + ".mo")); String[] c = p.getFileName().toString().replace(".mo", "").split("_"); try (OutputStream os = Files.newOutputStream(dymolaExportPath.getParent().resolve( DymolaUtil.DYMOLAINPUTZIPFILENAMEPREFIX + "_" + c[c.length - 1] + ".zip"))) { archive.as(ZipExporter.class).exportTo(os); retList.add(new String(c[c.length - 1])); } catch (IOException e) { //e.printStackTrace(); throw new RuntimeException(e); } } catch (IOException e) { throw new RuntimeException(e); } }); } retList.sort(Comparator.<String>naturalOrder()); //prepare param inputs for indexes from indexes properties file LOGGER.info("writing input indexes parameters in .mat format - start "); try { Path baseWp43ConfigFile = PlatformConfig.CONFIG_DIR.resolve(WP43_CONFIG_FILE_NAME); HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration( baseWp43ConfigFile.toFile()); //fix params for smallsignal index (cfr EurostagImpactAnalysis sources) SubnodeConfiguration node = configuration.getSection("smallsignal"); node.setProperty("f_instant", Double.toString(parameters.getFaultEventInstant())); for (int i = 0; i < contingencies.size(); i++) { Contingency contingency = contingencies.get(i); if (contingency.getElements().isEmpty()) { throw new AssertionError("Empty contingency " + contingency.getId()); } Iterator<ContingencyElement> it = contingency.getElements().iterator(); // compute the maximum fault duration double maxDuration = getFaultDuration(it.next()); while (it.hasNext()) { maxDuration = Math.max(maxDuration, getFaultDuration(it.next())); } node.setProperty("f_duration", Double.toString(maxDuration)); } DymolaAdaptersMatParamsWriter writer = new DymolaAdaptersMatParamsWriter(configuration); for (String cId : retList) { String parFileNamePrefix = DymolaUtil.DYMOLA_SIM_MAT_OUTPUT_PREFIX + "_" + cId + "_wp43_"; String parFileNameSuffix = "_pars.mat"; String zippedParFileNameSuffix = "_pars.zip"; try (OutputStream os = Files.newOutputStream(dymolaExportPath.getParent() .resolve(DymolaUtil.DYMOLAINPUTZIPFILENAMEPREFIX + "_" + cId + zippedParFileNameSuffix))) { JavaArchive archive = ShrinkWrap.create(JavaArchive.class); Path sfile1 = ShrinkWrapFileSystems.newFileSystem(archive).getPath("/"); Arrays.asList(config.getIndexesNames()).forEach(indexName -> writer.write(indexName, sfile1.resolve(parFileNamePrefix + indexName + parFileNameSuffix))); archive.as(ZipExporter.class).exportTo(os); } catch (Exception e) { throw new RuntimeException(e); } } } catch (ConfigurationException exc) { throw new RuntimeException(exc); } LOGGER.info("writing input indexes parameters in .mat format - end - {}", retList); return retList; }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether a section that has been cleared can be manipulated and * saved later./*from ww w . ja v a2 s . co m*/ */ @Test public void testSaveClearedSection() throws ConfigurationException { final String data = "[section]\ntest = failed\n"; HierarchicalINIConfiguration config = setUpConfig(data); SubnodeConfiguration sub = config.getSection("section"); assertFalse("No content", sub.isEmpty()); sub.clear(); sub.setProperty("test", "success"); StringWriter writer = new StringWriter(); config.save(writer); HierarchicalConfiguration config2 = setUpConfig(writer.toString()); assertEquals("Wrong value", "success", config2.getString("section.test")); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests whether a subnode configuration created from another subnode * configuration of a XMLConfiguration can trigger the auto save mechanism. */// w w w .j av a 2 s . com @Test public void testAutoSaveWithSubSubnodeConfig() throws ConfigurationException { final String newValue = "I am autosaved"; conf.setFile(testSaveConf); conf.setAutoSave(true); SubnodeConfiguration sub1 = conf.configurationAt("element2"); SubnodeConfiguration sub2 = sub1.configurationAt("subelement"); sub2.setProperty("subsubelement", newValue); assertEquals("Change not visible to parent", newValue, conf.getString("element2.subelement.subsubelement")); XMLConfiguration conf2 = new XMLConfiguration(testSaveConf); assertEquals("Change was not saved", newValue, conf2.getString("element2.subelement.subsubelement")); }