@Override public JsonSensitivityFactorsProvider create() { ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("json-sensitivity-factors"); Path jsonFile = config.getPathProperty("json-file"); return new JsonSensitivityFactorsProvider(jsonFile); }
private static Path getConfiguredScript(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); Path defaultScript = platformConfig.getConfigDir().resolve(DEFAULT_SCRIPT_NAME); return platformConfig.getOptionalModuleConfig("groovy-post-processor") .map(config -> config.getPathProperty("script", defaultScript)) .orElse(defaultScript); }
private synchronized ModuleConfig getModuleConfig() { if (!init) { if (platformConfig == null) { platformConfig = PlatformConfig.defaultConfig(); } configCache = platformConfig.moduleExists(MODULE_NAME) ? platformConfig.getModuleConfig(MODULE_NAME) : null; init = true; } return configCache; }
public Map<String, BoundaryPoint> parseDefault() throws IOException { Path defaultBoundaryPoint = PlatformConfig.defaultConfig().getConfigDir().resolve("BoundaryPoint.xls"); if (!Files.exists(defaultBoundaryPoint)) { throw new PowsyblException("Boundary point sheet " + defaultBoundaryPoint + " not found"); } try (InputStream is = Files.newInputStream(defaultBoundaryPoint)) { return parse(is); } }
public XMLImporter() { this(PlatformConfig.defaultConfig()); }
public static ImportConfig load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); List<String> postProcessors; if (platformConfig.moduleExists("import")) { ModuleConfig config = platformConfig.getModuleConfig("import"); postProcessors = config.getStringListProperty("postProcessors", DEFAULT_POST_PROCESSORS); } else { postProcessors = DEFAULT_POST_PROCESSORS; } return new ImportConfig(postProcessors); }
public static void setProxy() { try { URLConnection connection = new URL("http://www.google.com").openConnection(); connection.setConnectTimeout(1000); connection.connect(); } catch (IOException e) { // get proxy config PlatformConfig.defaultConfig().getOptionalModuleConfig("proxy") .ifPresent(proxyConfig -> { String host = proxyConfig.getStringProperty("host"); int port = proxyConfig.getIntProperty("port"); String user = proxyConfig.getStringProperty("user"); String password = proxyConfig.getStringProperty("password"); LOGGER.info("Set proxy host={}, port={}, user={}", host, port, user); System.getProperties().put("http.proxyHost", host); System.getProperties().put("http.proxyPort", Integer.toString(port)); Authenticator.setDefault( new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user, password.toCharArray()); } } ); }); } } }
public static LoadFlowBasedPhaseShifterOptimizerConfig load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); ModuleConfig config = platformConfig.getModuleConfig("load-flow-based-phase-shifter-optimizer"); Class<? extends LoadFlowFactory> loadFlowFactoryClass = config.getClassProperty("load-flow-factory", LoadFlowFactory.class); return new LoadFlowBasedPhaseShifterOptimizerConfig(loadFlowFactoryClass); }
@Override public EurostagNamingStrategy create() { ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfigIfExists(CONFIG_SECTION_NAME); if (config != null) { Path dicoFile = config.getPathProperty(CONFIG_PROPERTY_DICO_FILE_NAME, null); LOGGER.info("Instantiating DicoEurostagNamingStrategy: property {}={} declared in config section '{}'", CONFIG_PROPERTY_DICO_FILE_NAME, dicoFile, CONFIG_SECTION_NAME); dicoFile = config.getPathProperty(CONFIG_PROPERTY_DICO_FILE_NAME); return new DicoEurostagNamingStrategy(dicoFile); } else { LOGGER.warn("Cannot instantiate DicoEurostagNamingStrategy: config section '{}' not found . Using CutEurostagNamingStrategy, instead.", CONFIG_SECTION_NAME); return new CutEurostagNamingStrategy(); } } }
public static EurostagEchExportConfig load(PlatformConfig platformConfig) { // specificCompatibility parameter = true forces svcAsFixedInjectionInLF to true ModuleConfig loadFlowModuleConfig = platformConfig.getModuleConfigIfExists("load-flow-default-parameters"); boolean specificCompatibility = (loadFlowModuleConfig != null) ? loadFlowModuleConfig.getBooleanProperty("specificCompatibility", DEFAULT_SPECIFIC_COMPATIBILITY) : DEFAULT_SPECIFIC_COMPATIBILITY; if (platformConfig.moduleExists(EUROSTAG_ECH_EXPORT_CONFIG)) { ModuleConfig config = platformConfig.getModuleConfig(EUROSTAG_ECH_EXPORT_CONFIG); boolean noGeneratorMinMaxQ = config.getBooleanProperty("noGeneratorMinMaxQ", DEFAULT_NOGENERATORMINMAXQ); boolean noSwitch = config.getBooleanProperty("noSwitch", DEFAULT_NOSWITCH); boolean svcAsFixedInjectionInLF = config.getBooleanProperty("svcAsFixedInjectionInLF", DEFAULT_SVC_AS_FIXED_INJECTION_IN_LF); String forbiddenCharacters = config.getStringProperty("forbiddenCharacters", DEFAULT_FORBIDDEN_CHARACTERS); String replacementCharString = config.getStringProperty("forbiddenCharactersReplacement", DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT.toString()); if (replacementCharString.length() != 1) { throw new IllegalArgumentException("forbiddenCharactersReplacement must be a single character: " + replacementCharString); } Character forbiddenCharactersReplacement = replacementCharString.charAt(0); boolean exportMainCCOnly = config.getBooleanProperty("exportMainCCOnly", DEFAULT_EXPORT_MAIN_CC_ONLY); return new EurostagEchExportConfig(noGeneratorMinMaxQ, noSwitch, forbiddenCharacters, forbiddenCharactersReplacement, svcAsFixedInjectionInLF, specificCompatibility, exportMainCCOnly); } else { LOGGER.warn("no eurostag-ech-export config found: Using defaults."); return new EurostagEchExportConfig(DEFAULT_NOGENERATORMINMAXQ, DEFAULT_NOSWITCH, DEFAULT_FORBIDDEN_CHARACTERS, DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT, DEFAULT_SVC_AS_FIXED_INJECTION_IN_LF, specificCompatibility, DEFAULT_EXPORT_MAIN_CC_ONLY); } }
PlatformConfig config = new PlatformConfig(new YamlModuleConfigRepository(cfgDir.resolve("config.yml")), cfgDir); assertFalse(config.getOptionalModuleConfig("module2").isPresent()); assertFalse(config.getOptionalModuleConfig("module2").isPresent()); ModuleConfig module1 = config.getModuleConfig("module1"); assertEquals("a", module1.getStringProperty("s")); assertEquals(Collections.singletonList("a"), module1.getStringListProperty("s"));
prop1.store(w, null); PlatformConfig propsConfig = new PlatformConfig(new PropertiesModuleConfigRepository(cfgDir), cfgDir); ModuleConfig modConfig = propsConfig.getModuleConfig("mod"); assertModConfig(modConfig);
public static LoadFlowResultsCompletionParameters load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); return platformConfig.getOptionalModuleConfig("loadflow-results-completion-parameters") .map(config -> { float epsilonX = config.getFloatProperty("epsilon-x", LoadFlowResultsCompletionParameters.EPSILON_X_DEFAULT); boolean applyReactanceCorrection = config.getBooleanProperty("apply-reactance-correction", LoadFlowResultsCompletionParameters.APPLY_REACTANCE_CORRECTION_DEFAULT); return new LoadFlowResultsCompletionParameters(epsilonX, applyReactanceCorrection); }) .orElseGet(() -> new LoadFlowResultsCompletionParameters(LoadFlowResultsCompletionParameters.EPSILON_X_DEFAULT, LoadFlowResultsCompletionParameters.APPLY_REACTANCE_CORRECTION_DEFAULT)); }
public LoadFlowResultsCompletionPostProcessor() { this(PlatformConfig.defaultConfig()); }
public static SimulationDetailedParameters load(String fileName) { SimulationDetailedParameters parameters = null; Path file = PlatformConfig.defaultConfig().getConfigDir().resolve(fileName); if (Files.exists(file)) { parameters = new SimulationDetailedParameters(fileName); try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { parse(reader, parameters); } catch (IOException e) { throw new UncheckedIOException(e); } } return parameters; }
public CaseProjectorLoadFlowParameters(PlatformConfig config) { Objects.requireNonNull(config); if (config.moduleExists("caseProjector")) { ModuleConfig amplConfig = config.getModuleConfig("caseProjector"); this.amplHomeDir = amplConfig.getPathProperty("amplHomeDir"); this.generatorsDomainsFile = amplConfig.getPathProperty("generatorsDomainsFile"); this.debug = amplConfig.getBooleanProperty("debug"); } }
static EntsoeCaseRepositoryConfig load(String moduleConfigName, PlatformConfig platformConfig, Collection<String> supportedFormats) { ModuleConfig config = platformConfig.getModuleConfig(moduleConfigName); Path rootDir = config.getPathProperty("rootDir"); Multimap<EntsoeGeographicalCode, String> forbiddenFormatsByCountry = HashMultimap.create(); for (EntsoeGeographicalCode geographicalCode : EntsoeGeographicalCode.values()) { List<String> forbiddenFormats = config.getStringListProperty("forbiddenFormats_" + geographicalCode, Collections.emptyList()); if (forbiddenFormats.size() > 0) { forbiddenFormatsByCountry.putAll(geographicalCode, forbiddenFormats); } } return new EntsoeCaseRepositoryConfig(rootDir, checkedFormats(forbiddenFormatsByCountry, supportedFormats)); }
@Test public void properties2XmlConvertionTest() throws IOException, XMLStreamException { try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { Path cfgDir = Files.createDirectory(fileSystem.getPath("config")); Properties prop1 = new Properties(); prop1.setProperty("a", "hello"); prop1.setProperty("b", "bye"); try (Writer w = Files.newBufferedWriter(cfgDir.resolve("mod1.properties"), StandardCharsets.UTF_8)) { prop1.store(w, null); } Properties prop2 = new Properties(); prop2.setProperty("c", "thanks"); try (Writer w = Files.newBufferedWriter(cfgDir.resolve("mod2.properties"), StandardCharsets.UTF_8)) { prop2.store(w, null); } PlatformConfig propsConfig = new PlatformConfig(new PropertiesModuleConfigRepository(cfgDir), cfgDir); assertEquals("hello", propsConfig.getModuleConfig("mod1").getStringProperty("a")); assertEquals("bye", propsConfig.getModuleConfig("mod1").getStringProperty("b")); assertEquals("thanks", propsConfig.getModuleConfig("mod2").getStringProperty("c")); Path xmlConfigFile = cfgDir.resolve("config.xml"); PropertiesModuleConfigRepository.writeXml(cfgDir, xmlConfigFile); PlatformConfig xmlConfig = new PlatformConfig(new XmlModuleConfigRepository(xmlConfigFile), cfgDir); assertEquals("hello", xmlConfig.getModuleConfig("mod1").getStringProperty("a")); assertEquals("bye", xmlConfig.getModuleConfig("mod1").getStringProperty("b")); assertEquals("thanks", xmlConfig.getModuleConfig("mod2").getStringProperty("c")); } }
public static List<LocalAppFileSystemConfig> load(PlatformConfig platformConfig) { return platformConfig.getOptionalModuleConfig("local-app-file-system") .map(moduleConfig -> { List<LocalAppFileSystemConfig> configs = new ArrayList<>(); load(moduleConfig, OptionalInt.empty(), configs); int maxAdditionalDriveCount = moduleConfig.getIntProperty("max-additional-drive-count", 0); for (int i = 0; i < maxAdditionalDriveCount; i++) { load(moduleConfig, OptionalInt.of(i), configs); } return configs; }) .orElseGet(() -> { List<LocalAppFileSystemConfig> configs = new ArrayList<>(); for (Path rootDir : FileSystems.getDefault().getRootDirectories()) { if (Files.isDirectory(rootDir)) { configs.add(new LocalAppFileSystemConfig(rootDir.toString(), false, rootDir)); } } return configs; }); }
@Override public GroovyDslContingenciesProvider create() { ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("groovy-dsl-contingencies"); Path dslFile = config.getPathProperty("dsl-file"); return new GroovyDslContingenciesProvider(dslFile); }