Search in sources :

Example 16 with StrSubstitutor

use of org.apache.commons.lang3.text.StrSubstitutor in project tomee by apache.

the class Configuration method loadFromProperties.

public void loadFromProperties(final Properties config) {
    // filtering properties with system properties or themself
    final StrSubstitutor strSubstitutor = new StrSubstitutor(new StrLookup<String>() {

        @Override
        public String lookup(final String key) {
            final String property = System.getProperty(key);
            return property == null ? config.getProperty(key) : null;
        }
    });
    for (final String key : config.stringPropertyNames()) {
        final String val = config.getProperty(key);
        if (val == null || val.trim().isEmpty()) {
            continue;
        }
        final String newVal = strSubstitutor.replace(config.getProperty(key));
        if (!val.equals(newVal)) {
            config.setProperty(key, newVal);
        }
    }
    final String http = config.getProperty("http");
    if (http != null) {
        setHttpPort(Integer.parseInt(http));
    }
    final String https = config.getProperty("https");
    if (https != null) {
        setHttpsPort(Integer.parseInt(https));
    }
    final String stop = config.getProperty("stop");
    if (stop != null) {
        setStopPort(Integer.parseInt(stop));
    }
    final String host = config.getProperty("host");
    if (host != null) {
        setHost(host);
    }
    final String dir = config.getProperty("dir");
    if (dir != null) {
        setDir(dir);
    }
    final String serverXml = config.getProperty("serverXml");
    if (serverXml != null) {
        setServerXml(serverXml);
    }
    final String keepServerXmlAsThis = config.getProperty("keepServerXmlAsThis");
    if (keepServerXmlAsThis != null) {
        setKeepServerXmlAsThis(Boolean.parseBoolean(keepServerXmlAsThis));
    }
    final String quickSession = config.getProperty("quickSession");
    if (quickSession != null) {
        setQuickSession(Boolean.parseBoolean(quickSession));
    }
    final String skipHttp = config.getProperty("skipHttp");
    if (skipHttp != null) {
        setSkipHttp(Boolean.parseBoolean(skipHttp));
    }
    final String ssl = config.getProperty("ssl");
    if (ssl != null) {
        setSsl(Boolean.parseBoolean(ssl));
    }
    final String http2 = config.getProperty("http2");
    if (http2 != null) {
        setHttp2(Boolean.parseBoolean(http2));
    }
    final String deleteBaseOnStartup = config.getProperty("deleteBaseOnStartup");
    if (deleteBaseOnStartup != null) {
        setDeleteBaseOnStartup(Boolean.parseBoolean(deleteBaseOnStartup));
    }
    final String webResourceCached = config.getProperty("webResourceCached");
    if (webResourceCached != null) {
        setWebResourceCached(Boolean.parseBoolean(webResourceCached));
    }
    final String withEjbRemote = config.getProperty("withEjbRemote");
    if (withEjbRemote != null) {
        setWithEjbRemote(Boolean.parseBoolean(withEjbRemote));
    }
    final String deployOpenEjbApp = config.getProperty("deployOpenEjbApp");
    if (deployOpenEjbApp != null) {
        setDeployOpenEjbApp(Boolean.parseBoolean(deployOpenEjbApp));
    }
    final String keystoreFile = config.getProperty("keystoreFile");
    if (keystoreFile != null) {
        setKeystoreFile(keystoreFile);
    }
    final String keystorePass = config.getProperty("keystorePass");
    if (keystorePass != null) {
        setKeystorePass(keystorePass);
    }
    final String keystoreType = config.getProperty("keystoreType");
    if (keystoreType != null) {
        setKeystoreType(keystoreType);
    }
    final String clientAuth = config.getProperty("clientAuth");
    if (clientAuth != null) {
        setClientAuth(clientAuth);
    }
    final String keyAlias = config.getProperty("keyAlias");
    if (keyAlias != null) {
        setKeyAlias(keyAlias);
    }
    final String sslProtocol = config.getProperty("sslProtocol");
    if (sslProtocol != null) {
        setSslProtocol(sslProtocol);
    }
    final String webXml = config.getProperty("webXml");
    if (webXml != null) {
        setWebXml(webXml);
    }
    final String tempDir = config.getProperty("tempDir");
    if (tempDir != null) {
        setTempDir(tempDir);
    }
    final String customWebResources = config.getProperty("customWebResources");
    if (customWebResources != null) {
        setCustomWebResources(customWebResources);
    }
    final String classesFilterType = config.getProperty("classesFilter");
    if (classesFilterType != null) {
        try {
            setClassesFilter(Filter.class.cast(Thread.currentThread().getContextClassLoader().loadClass(classesFilterType).newInstance()));
        } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new IllegalArgumentException(e);
        }
    }
    final String conf = config.getProperty("conf");
    if (conf != null) {
        setConf(conf);
    }
    for (final String prop : config.stringPropertyNames()) {
        if (prop.startsWith("properties.")) {
            property(prop.substring("properties.".length()), config.getProperty(prop));
        } else if (prop.startsWith("users.")) {
            user(prop.substring("users.".length()), config.getProperty(prop));
        } else if (prop.startsWith("roles.")) {
            role(prop.substring("roles.".length()), config.getProperty(prop));
        } else if (prop.startsWith("connector.")) {
            // created in container
            property(prop, config.getProperty(prop));
        } else if (prop.equals("realm")) {
            final ObjectRecipe recipe = new ObjectRecipe(config.getProperty(prop));
            for (final String realmConfig : config.stringPropertyNames()) {
                if (realmConfig.startsWith("realm.")) {
                    recipe.setProperty(realmConfig.substring("realm.".length()), config.getProperty(realmConfig));
                }
            }
            setRealm(Realm.class.cast(recipe.create()));
        } else if (prop.equals("login")) {
            final ObjectRecipe recipe = new ObjectRecipe(LoginConfigBuilder.class.getName());
            for (final String nestedConfig : config.stringPropertyNames()) {
                if (nestedConfig.startsWith("login.")) {
                    recipe.setProperty(nestedConfig.substring("login.".length()), config.getProperty(nestedConfig));
                }
            }
            loginConfig(LoginConfigBuilder.class.cast(recipe.create()));
        } else if (prop.equals("securityConstraint")) {
            final ObjectRecipe recipe = new ObjectRecipe(SecurityConstaintBuilder.class.getName());
            for (final String nestedConfig : config.stringPropertyNames()) {
                if (nestedConfig.startsWith("securityConstraint.")) {
                    recipe.setProperty(nestedConfig.substring("securityConstraint.".length()), config.getProperty(nestedConfig));
                }
            }
            securityConstaint(SecurityConstaintBuilder.class.cast(recipe.create()));
        } else if (prop.equals("configurationCustomizer.")) {
            final String next = prop.substring("configurationCustomizer.".length());
            if (next.contains(".")) {
                continue;
            }
            final ObjectRecipe recipe = new ObjectRecipe(properties.getProperty(prop + ".class"));
            for (final String nestedConfig : config.stringPropertyNames()) {
                if (nestedConfig.startsWith(prop) && !prop.endsWith(".class")) {
                    recipe.setProperty(nestedConfig.substring(prop.length() + 1), config.getProperty(nestedConfig));
                }
            }
            addCustomizer(ConfigurationCustomizer.class.cast(recipe.create()));
        }
    }
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) Filter(org.apache.xbean.finder.filter.Filter) Realm(org.apache.catalina.Realm)

Example 17 with StrSubstitutor

use of org.apache.commons.lang3.text.StrSubstitutor in project dhis2-core by dhis2.

the class JdbcCompleteDataSetRegistrationExchangeStore method createQuery.

private static String createQuery(ExportParams params) {
    IdSchemes idSchemes = params.getOutputIdSchemes() != null ? params.getOutputIdSchemes() : new IdSchemes();
    ImmutableMap.Builder<String, String> namedParamsBuilder = ImmutableMap.<String, String>builder().put(DATA_SET_SCHEME, idSchemes.getDataSetIdScheme().getIdentifiableString().toLowerCase()).put(ORG_UNIT_SCHEME, idSchemes.getOrgUnitIdScheme().getIdentifiableString().toLowerCase()).put(ATTR_OPT_COMBO_SCHEME, idSchemes.getAttributeOptionComboIdScheme().getIdentifiableString().toLowerCase());
    String sql = "SELECT ds.${dsScheme} AS dsid, pe.startdate AS pe_start, pt.name AS ptname, ou.${ouScheme} AS ouid, " + "aoc.${aocScheme} AS aocid, cdsr.storedby AS storedby, cdsr.date AS created " + "FROM completedatasetregistration cdsr " + "INNER JOIN dataset ds ON (cdsr.datasetid=ds.datasetid) " + "INNER JOIN period pe ON (cdsr.periodid=pe.periodid) " + "INNER JOIN periodtype pt ON (pe.periodtypeid=pt.periodtypeid) " + "INNER JOIN organisationunit ou ON (cdsr.sourceid=ou.organisationunitid) " + "INNER JOIN categoryoptioncombo aoc ON (cdsr.attributeoptioncomboid = aoc.categoryoptioncomboid) ";
    sql += createOrgUnitGroupJoin(params);
    sql += createDataSetClause(params, namedParamsBuilder);
    sql += createOrgUnitClause(params, namedParamsBuilder);
    sql += createPeriodClause(params, namedParamsBuilder);
    sql += createCreatedClause(params, namedParamsBuilder);
    sql += createLimitClause(params, namedParamsBuilder);
    sql = new StrSubstitutor(namedParamsBuilder.build(), "${", "}").replace(sql);
    log.debug("CompleteDataSetRegistrations query: " + sql);
    return sql;
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) IdSchemes(org.hisp.dhis.common.IdSchemes) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

StrSubstitutor (org.apache.commons.lang3.text.StrSubstitutor)17 StrLookup (org.apache.commons.lang3.text.StrLookup)5 File (java.io.File)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)2 FileWriter (java.io.FileWriter)2 Map (java.util.Map)2 Properties (java.util.Properties)2 JSONObject (org.json.JSONObject)2 DomainVO (com.cloud.domain.DomainVO)1 AccountVO (com.cloud.user.AccountVO)1 UserVO (com.cloud.user.UserVO)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DimensionMap (com.linkedin.thirdeye.api.DimensionMap)1 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)1 FileConfigurationSourceProvider (io.dropwizard.configuration.FileConfigurationSourceProvider)1 SubstitutingSourceProvider (io.dropwizard.configuration.SubstitutingSourceProvider)1