Search in sources :

Example 6 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class AbstractPropertyFileHandler method saveAll.

public void saveAll(Properties properties) throws ConfigurationError {
    lock.writeLock().lock();
    try {
        Properties p = load();
        properties.stringPropertyNames().forEach(key -> p.setProperty(key, properties.getProperty(key)));
        save(p);
    } catch (IOException e) {
        throw new ConfigurationError(ERROR_WRITING_MESSAGE, e);
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) IOException(java.io.IOException) Properties(java.util.Properties)

Example 7 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class AbstractPropertyFileHandler method delete.

public void delete(String m) throws ConfigurationError {
    lock.writeLock().lock();
    try {
        Properties p = load();
        p.remove(m);
        save(p);
    } catch (IOException e) {
        throw new ConfigurationError(ERROR_WRITING_MESSAGE, e);
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) IOException(java.io.IOException) Properties(java.util.Properties)

Example 8 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class SettingValueFactory method newBooleanSettingValue.

/**
 * Constructs a new {@code Boolean} setting value from the supplied key and string value.
 *
 * @param key         the setting key
 * @param stringValue the value as string
 *
 * @return the implementation specific {@code SettingValue}
 */
default SettingValue<Boolean> newBooleanSettingValue(String key, String stringValue) {
    Boolean value;
    if (nullOrEmpty(stringValue)) {
        return newBooleanSettingValue(key, Boolean.FALSE);
    }
    String lc = stringValue.trim().toLowerCase(Locale.ROOT);
    switch(lc) {
        case "true":
        case "yes":
        case "on":
        case "1":
            return newBooleanSettingValue(key, Boolean.TRUE);
        case "false":
        case "no":
        case "off":
        case "0":
            return newBooleanSettingValue(key, Boolean.FALSE);
        default:
            throw new ConfigurationError(String.format("'%s' is not a valid boolean value", stringValue));
    }
}
Also used : MultilingualString(org.n52.janmayen.i18n.MultilingualString)

Example 9 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class SettingsServiceImpl method configure.

private void configure(Object object, boolean persist) throws ConfigurationError {
    Class<?> clazz = object.getClass();
    if (clazz.getAnnotation(Configurable.class) == null) {
        return;
    }
    LOG.debug("Configuring object {}", object);
    for (Method method : clazz.getMethods()) {
        Setting s = method.getAnnotation(Setting.class);
        if (s != null) {
            String key = s.value();
            if (key == null || key.isEmpty()) {
                throw new ConfigurationError(String.format("Invalid value for @Setting: '%s'", key));
            } else if (getDefinitionByKey(key) == null && s.required()) {
                throw noSettingDefinitionFound(key);
            } else if (method.getParameterTypes().length != 1) {
                throw new ConfigurationError(String.format("Method %s annotated with @Setting in %s has a invalid method signature", method, clazz));
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new ConfigurationError(String.format("Non-public method %s annotated with @Setting in %s", method, clazz));
            } else {
                configure(new ConfigurableObject(method, object, key, s.required()), persist);
            }
        }
    }
}
Also used : Setting(org.n52.faroe.annotation.Setting) Configurable(org.n52.faroe.annotation.Configurable) Method(java.lang.reflect.Method)

Example 10 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class OwsServiceProviderFactory method create.

@Override
protected OwsServiceProvider create(Locale language) throws ConfigurationError {
    // TODO organisation name is missing
    String organisationName = null;
    OwsOnlineResource onlineResource = null;
    if (site != null) {
        onlineResource = new OwsOnlineResource(site);
    }
    OwsCode roleCode = null;
    if (role != null) {
        roleCode = new OwsCode(role, roleCodespace);
    }
    OwsOnlineResource providerSite = null;
    if (onlineResoureHref != null) {
        providerSite = new OwsOnlineResource(onlineResoureHref, onlineResoureTitle);
    }
    OwsAddress address = null;
    if (anyNonNull(deliveryPoint, city, administrativeArea, postalCode, country, electronicMailAddress)) {
        address = new OwsAddress(deliveryPoint, city, administrativeArea, postalCode, country, electronicMailAddress);
    }
    OwsPhone owsPhone = null;
    if (anyNonNull(phone, facsimile)) {
        owsPhone = new OwsPhone(phone, facsimile);
    }
    OwsContact contactInfo = null;
    if (anyNonNull(owsPhone, address, onlineResource, hoursOfService, contactInstructions)) {
        contactInfo = new OwsContact(owsPhone, address, onlineResource, hoursOfService, contactInstructions);
    }
    OwsResponsibleParty serviceContact = new OwsResponsibleParty(individualName, organisationName, positionName, contactInfo, roleCode);
    return new OwsServiceProvider(name, providerSite, serviceContact);
}
Also used : OwsOnlineResource(org.n52.shetland.ogc.ows.OwsOnlineResource) OwsResponsibleParty(org.n52.shetland.ogc.ows.OwsResponsibleParty) OwsContact(org.n52.shetland.ogc.ows.OwsContact) OwsServiceProvider(org.n52.shetland.ogc.ows.OwsServiceProvider) OwsCode(org.n52.shetland.ogc.ows.OwsCode) OwsAddress(org.n52.shetland.ogc.ows.OwsAddress) OwsPhone(org.n52.shetland.ogc.ows.OwsPhone)

Aggregations

ConfigurationError (org.n52.faroe.ConfigurationError)7 IOException (java.io.IOException)4 Properties (java.util.Properties)3 Setting (org.n52.faroe.annotation.Setting)3 MultilingualString (org.n52.janmayen.i18n.MultilingualString)3 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)2 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Joiner (com.google.common.base.Joiner)1 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1