Search in sources :

Example 6 with ParsingNestedException

use of org.eclipse.smarthome.automation.parser.ParsingNestedException in project smarthome by eclipse.

the class CommandlineTemplateProvider method importData.

@Override
protected Set<RuleTemplate> importData(URL url, Parser<RuleTemplate> parser, InputStreamReader inputStreamReader) throws ParsingException {
    Set<RuleTemplate> providedObjects = parser.parse(inputStreamReader);
    if (providedObjects != null && !providedObjects.isEmpty()) {
        List<String> portfolio = new ArrayList<String>();
        synchronized (providerPortfolio) {
            providerPortfolio.put(url, portfolio);
        }
        List<ParsingNestedException> importDataExceptions = new ArrayList<ParsingNestedException>();
        for (RuleTemplate ruleT : providedObjects) {
            List<ParsingNestedException> exceptions = new ArrayList<ParsingNestedException>();
            String uid = ruleT.getUID();
            checkExistence(uid, exceptions);
            if (exceptions.isEmpty()) {
                portfolio.add(uid);
                synchronized (providedObjectsHolder) {
                    notifyListeners(providedObjectsHolder.put(uid, ruleT), ruleT);
                }
            } else {
                importDataExceptions.addAll(exceptions);
            }
        }
        if (!importDataExceptions.isEmpty()) {
            throw new ParsingException(importDataExceptions);
        }
    }
    return providedObjects;
}
Also used : ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ArrayList(java.util.ArrayList) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) RuleTemplate(org.eclipse.smarthome.automation.template.RuleTemplate)

Aggregations

ParsingException (org.eclipse.smarthome.automation.parser.ParsingException)6 ParsingNestedException (org.eclipse.smarthome.automation.parser.ParsingNestedException)6 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 ModuleType (org.eclipse.smarthome.automation.type.ModuleType)3 JsonReader (com.google.gson.stream.JsonReader)2 JsonToken (com.google.gson.stream.JsonToken)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RuleTemplate (org.eclipse.smarthome.automation.template.RuleTemplate)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Rule (org.eclipse.smarthome.automation.Rule)1 Template (org.eclipse.smarthome.automation.template.Template)1