Search in sources :

Example 1 with YamlException

use of com.esotericsoftware.yamlbeans.YamlException in project audit4j-core by audit4j.

the class YAMLConfigProvider method readConfig.

/**
 * {@inheritDoc}
 *
 * @see org.audit4j.core.ConfigProvider#readConfig(java.io.InputStream)
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(InputStream fileAsStream) throws ConfigurationException {
    InputStreamReader streamReader = new InputStreamReader(fileAsStream);
    try {
        YamlReader reader = new YamlReader(streamReader);
        reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
        return (T) reader.read();
    } catch (YamlException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_002", e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.audit4j.core.exception.ConfigurationException) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 2 with YamlException

use of com.esotericsoftware.yamlbeans.YamlException in project StreetComplete by westnordost.

the class CreditsFragment method readContributors.

private List<String> readContributors() {
    try {
        InputStream is = getResources().openRawResource(R.raw.credits_contributors);
        YamlReader reader = new YamlReader(new InputStreamReader(is));
        List<String> result = new ArrayList<>((List) reader.read());
        result.add(getString(R.string.credits_and_more));
        return result;
    } catch (YamlException e) {
        throw new RuntimeException(e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 3 with YamlException

use of com.esotericsoftware.yamlbeans.YamlException in project StreetComplete by westnordost.

the class CreditsFragment method readTranslators.

private List<Map.Entry<String, String>> readTranslators() {
    try {
        InputStream is = getResources().openRawResource(R.raw.credits_translations);
        YamlReader reader = new YamlReader(new InputStreamReader(is));
        Map yml = (Map) reader.read();
        List<Map.Entry<String, String>> result = new ArrayList<>();
        for (Object e : yml.entrySet()) {
            result.add((Map.Entry<String, String>) e);
        }
        Collections.sort(result, (o1, o2) -> o1.getKey().compareTo(o2.getKey()));
        return result;
    } catch (YamlException e) {
        throw new RuntimeException(e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) Map(java.util.Map)

Example 4 with YamlException

use of com.esotericsoftware.yamlbeans.YamlException in project audit4j-core by audit4j.

the class YAMLConfigProvider method readConfig.

/**
 * {@inheritDoc}
 *
 * @see org.audit4j.core.ConfigProvider#readConfig(java.lang.String)
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(String filePath) throws ConfigurationException {
    try {
        YamlReader reader = new YamlReader(new FileReader(filePath));
        reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
        return (T) reader.read();
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_001", e);
    } catch (YamlException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_002", e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) ConfigurationException(org.audit4j.core.exception.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 5 with YamlException

use of com.esotericsoftware.yamlbeans.YamlException in project ecs-dashboard by carone1.

the class KibanaEmailer method loadConfig.

/*
	 * Utility method to load and parse emailer's configuration data
	 */
@SuppressWarnings("unchecked")
private static void loadConfig() {
    try {
        FileReader fr;
        fr = new FileReader(kibanaConfigFile);
        logger.info("Loading configuration from config file: " + kibanaConfigFile);
        YamlReader reader = new YamlReader(fr);
        Object object = reader.read();
        if (object == null) {
            logger.info("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.out.println("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        Map<?, ?> map = (Map<?, ?>) object;
        if (map == null) {
            logger.info("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.out.println("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // chromedriver
        Object driverPathObj = map.get(CHROME_DRIVER_CONFIG);
        if (driverPathObj != null && driverPathObj instanceof String) {
            chromeDriverPath = (String) driverPathObj;
        } else {
            logger.info("Can't find: " + CHROME_DRIVER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + CHROME_DRIVER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // chromebrowser
        Object browserPathObj = map.get(CHROME_BROWSER_CONFIG);
        if (browserPathObj != null && browserPathObj instanceof String) {
            chromeBrowserPath = (String) browserPathObj;
        } else {
            logger.info("Can't find: " + CHROME_BROWSER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + CHROME_BROWSER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        Object captureDelayObj = map.get(SCREEN_CAPTURE_DELAY);
        if (captureDelayObj != null && captureDelayObj instanceof String) {
            screenCaptureDelay = Integer.valueOf((String) captureDelayObj);
        } else {
            logger.info("Can't find: " + SCREEN_CAPTURE_DELAY + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SCREEN_CAPTURE_DELAY + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // Kibana Urls
        Object urls = map.get(KIBANA_URLS_CONFIG);
        if (urls != null && urls instanceof ArrayList<?>) {
            kibanaUrls = (ArrayList<Map<String, String>>) urls;
        } else {
            logger.info("Can't find: " + KIBANA_URLS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + KIBANA_URLS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // destination path to save screen captures
        Object destinationObj = map.get(DESTINATION_PATH_CONFIG);
        if (destinationObj != null && destinationObj instanceof String) {
            destinationPath = (String) destinationObj;
        } else {
            logger.info("Can't find: " + DESTINATION_PATH_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + DESTINATION_PATH_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // == smtp config ==
        // smtp.host
        Object smtpHostObj = map.get(SMTP_HOST_CONFIG);
        if (smtpHostObj != null && smtpHostObj instanceof String) {
            smtpHost = (String) smtpHostObj;
        } else {
            logger.info("Can't find: " + SMTP_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.port
        Object smtpPortObj = map.get(SMTP_PORT_CONFIG);
        if (smtpPortObj != null && smtpPortObj instanceof String) {
            smtpPort = (String) smtpHostObj;
        } else {
            logger.info("Can't find: " + SMTP_PORT_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_PORT_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.username
        Object smtpUsernameObj = map.get(SMTP_USERNAME_CONFIG);
        if (smtpUsernameObj != null && smtpUsernameObj instanceof String) {
            smtpUsername = (String) smtpUsernameObj;
        } else {
            logger.info("Can't find: " + SMTP_USERNAME_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_USERNAME_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.password
        Object smtpPasswordObj = map.get(SMTP_PASSWORD_CONFIG);
        if (smtpPasswordObj != null && smtpPasswordObj instanceof String) {
            smtpPassword = (String) smtpPasswordObj;
        } else {
            logger.info("Can't find: " + SMTP_PASSWORD_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_PASSWORD_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.security "tls|ssl"
        Object smtpSecurityObj = map.get(SMTP_SECURITY_CONFIG);
        if (smtpSecurityObj != null && smtpSecurityObj instanceof String) {
            smtpSecurity = (String) smtpSecurityObj;
        } else {
            logger.info("Can't find: " + SMTP_SECURITY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_SECURITY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // source.host
        Object sourceHostObj = map.get(SOURCE_HOST_CONFIG);
        if (sourceHostObj != null && sourceHostObj instanceof String) {
            sourceHost = (String) sourceHostObj;
        } else {
            logger.info("Can't find: " + SOURCE_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SOURCE_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // e-mail addresses configuration
        // source.mail
        Object sourceAddressObj = map.get(SOURCE_ADDRESS_CONFIG);
        if (sourceAddressObj != null && sourceAddressObj instanceof String) {
            sourceAddress = (String) sourceAddressObj;
        } else {
            logger.info("Can't find: " + SOURCE_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SOURCE_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // destination.addresses
        Object destinations = map.get(DESTINATION_ADDRESS_CONFIG);
        if (destinations != null && destinations instanceof ArrayList<?>) {
            destinationAddressList = (ArrayList<String>) destinations;
        } else {
            logger.info("Can't find: " + DESTINATION_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + DESTINATION_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // e-mail content
        // mail.title
        Object mailTitleObj = map.get(MAIL_TITLE_CONFIG);
        if (mailTitleObj != null && mailTitleObj instanceof String) {
            mailTitle = (String) mailTitleObj;
        } else {
            logger.info("Can't find: " + MAIL_TITLE_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + MAIL_TITLE_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // mail.body
        Object mailBodyObj = map.get(MAIL_BODY_CONFIG);
        if (mailBodyObj != null && mailBodyObj instanceof String) {
            mailBody = (String) mailBodyObj;
        } else {
            logger.info("Can't find: " + MAIL_BODY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + MAIL_BODY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (YamlException e) {
        throw new RuntimeException(e);
    }
    logger.info("Loaded config details: " + SMTP_HOST_CONFIG + ": `" + smtpHost + "`, " + SMTP_PORT_CONFIG + ": `" + smtpPort.toString() + "`, " + SMTP_USERNAME_CONFIG + ": `" + smtpUsername + "`, " + SOURCE_HOST_CONFIG + ": `" + sourceHost + "`, " + SOURCE_ADDRESS_CONFIG + ": `" + sourceAddress + "`, " + DESTINATION_ADDRESS_CONFIG + ": `" + destinationAddressList.toString() + "`, " + MAIL_TITLE_CONFIG + ": `" + mailTitle + "`, " + MAIL_BODY_CONFIG + ": `" + mailBody);
    logger.info("Loaded config details: " + KIBANA_URLS_CONFIG + ": " + kibanaUrls.toString());
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

YamlException (com.esotericsoftware.yamlbeans.YamlException)5 YamlReader (com.esotericsoftware.yamlbeans.YamlReader)5 InputStreamReader (java.io.InputStreamReader)3 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConfigurationException (org.audit4j.core.exception.ConfigurationException)2 HashMap (java.util.HashMap)1