Search in sources :

Example 11 with ConfigValue

use of com.typesafe.config.ConfigValue in project config by typesafehub.

the class SimpleConfig method hasPathPeek.

private ConfigValue hasPathPeek(String pathExpression) {
    Path path = Path.newPath(pathExpression);
    ConfigValue peeked;
    try {
        peeked = object.peekPath(path);
    } catch (ConfigException.NotResolved e) {
        throw ConfigImpl.improveNotResolved(path, e);
    }
    return peeked;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ConfigException(com.typesafe.config.ConfigException)

Example 12 with ConfigValue

use of com.typesafe.config.ConfigValue in project config by typesafehub.

the class SimpleConfig method findPaths.

private static void findPaths(Set<Map.Entry<String, ConfigValue>> entries, Path parent, AbstractConfigObject obj) {
    for (Map.Entry<String, ConfigValue> entry : obj.entrySet()) {
        String elem = entry.getKey();
        ConfigValue v = entry.getValue();
        Path path = Path.newKey(elem);
        if (parent != null)
            path = path.prepend(parent);
        if (v instanceof AbstractConfigObject) {
            findPaths(entries, path, (AbstractConfigObject) v);
        } else if (v instanceof ConfigNull) {
        // nothing; nulls are conceptually not in a Config
        } else {
            entries.add(new AbstractMap.SimpleImmutableEntry<String, ConfigValue>(path.render(), v));
        }
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 13 with ConfigValue

use of com.typesafe.config.ConfigValue in project config by typesafehub.

the class SimpleConfig method getBytesList.

@Override
public List<Long> getBytesList(String path) {
    List<Long> l = new ArrayList<Long>();
    List<? extends ConfigValue> list = getList(path);
    for (ConfigValue v : list) {
        if (v.valueType() == ConfigValueType.NUMBER) {
            l.add(((Number) v.unwrapped()).longValue());
        } else if (v.valueType() == ConfigValueType.STRING) {
            String s = (String) v.unwrapped();
            Long n = parseBytes(s, v.origin(), path);
            l.add(n);
        } else {
            throw new ConfigException.WrongType(v.origin(), path, "memory size string or number of bytes", v.valueType().name());
        }
    }
    return l;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ArrayList(java.util.ArrayList) ConfigException(com.typesafe.config.ConfigException)

Example 14 with ConfigValue

use of com.typesafe.config.ConfigValue in project config by typesafehub.

the class SimpleConfig method getDuration.

@Override
public long getDuration(String path, TimeUnit unit) {
    ConfigValue v = find(path, ConfigValueType.STRING);
    long result = unit.convert(parseDuration((String) v.unwrapped(), v.origin(), path), TimeUnit.NANOSECONDS);
    return result;
}
Also used : ConfigValue(com.typesafe.config.ConfigValue)

Example 15 with ConfigValue

use of com.typesafe.config.ConfigValue in project scoold by Erudika.

the class AdminController method get.

@GetMapping
public String get(HttpServletRequest req, Model model) {
    if (!utils.isAuthenticated(req) || !utils.isAdmin(utils.getAuthUser(req))) {
        return "redirect:" + HOMEPAGE;
    }
    Map<String, Object> configMap = new HashMap<String, Object>();
    for (Map.Entry<String, ConfigValue> entry : Config.getConfig().entrySet()) {
        ConfigValue value = entry.getValue();
        configMap.put(Config.PARA + "_" + entry.getKey(), value != null ? value.unwrapped() : "-");
    }
    configMap.putAll(System.getenv());
    model.addAttribute("path", "admin.vm");
    model.addAttribute("title", utils.getLang(req).get("admin.title"));
    model.addAttribute("configMap", configMap);
    model.addAttribute("version", pc.getServerVersion());
    return "base";
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) HashMap(java.util.HashMap) ParaObject(com.erudika.para.core.ParaObject) HashMap(java.util.HashMap) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ConfigValue (com.typesafe.config.ConfigValue)16 ConfigException (com.typesafe.config.ConfigException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ConfigObject (com.typesafe.config.ConfigObject)3 Config (com.typesafe.config.Config)2 ConfigList (com.typesafe.config.ConfigList)2 ParaObject (com.erudika.para.core.ParaObject)1 ConfigValueType (com.typesafe.config.ConfigValueType)1 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 AbstractMap (java.util.AbstractMap)1 EnumMap (java.util.EnumMap)1 List (java.util.List)1