Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/eclipse/smarthome
Browse files Browse the repository at this point in the history
  • Loading branch information
S0urceror committed Aug 16, 2017
2 parents a0688bc + 98192b5 commit 10d2d8e
Show file tree
Hide file tree
Showing 538 changed files with 7,671 additions and 3,140 deletions.
Expand Up @@ -6,6 +6,7 @@ Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: Eclipse.org/SmartHome
Import-Package:
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.dto,
org.eclipse.smarthome.automation.events,
org.eclipse.smarthome.automation.handler,
org.eclipse.smarthome.automation.parser,
Expand Down
Expand Up @@ -7,8 +7,6 @@
*/
package org.eclipse.smarthome.automation;

import org.eclipse.smarthome.automation.Rule;
import org.eclipse.smarthome.automation.RuleProvider;
import org.eclipse.smarthome.core.common.registry.DefaultAbstractManagedProvider;

/**
Expand All @@ -20,11 +18,6 @@
*/
public class ManagedRuleProvider extends DefaultAbstractManagedProvider<Rule, String> implements RuleProvider {

@Override
protected String getKey(Rule element) {
return element.getUID();
}

@Override
protected String getStorageName() {
return "automation_rules";
Expand Down
@@ -1,10 +1,10 @@
/**
* Copyright (c) 1997, 2015 by ProSyst Software GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
* Copyright (c) 2015, 2017 by Bosch Software Innovations and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.automation.template;

import java.util.ArrayList;
Expand Down Expand Up @@ -241,4 +241,33 @@ public List<Action> getActions() {
return actions != null ? actions : Collections.<Action> emptyList();
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uid == null) ? 0 : uid.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof RuleTemplate)) {
return false;
}
RuleTemplate other = (RuleTemplate) obj;
if (uid == null) {
if (other.uid != null) {
return false;
}
} else if (!uid.equals(other.uid)) {
return false;
}
return true;
}
}
Expand Up @@ -6,6 +6,7 @@ Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: Eclipse.org/SmartHome
Import-Package:
com.google.gson,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.core.util,
org.eclipse.smarthome.automation.events,
Expand Down
Expand Up @@ -144,7 +144,7 @@ public static Set<Connection> getConnections(Map<String, String> inputs, Logger
connections.add(connection);

} else {
log.error("Wrong format of Output : " + inputName + ": " + output);
log.error("Wrong format of Output : {}: {}", inputName, output);
continue;
}
}
Expand Down
Expand Up @@ -213,8 +213,8 @@ private static String resolvePattern(String reference, Map<String, ?> context) {
end = reference.indexOf('}', start + 2);
if (end == -1) {
previous = start;
logger.warn("Couldn't parse referenced key: " + reference.substring(start)
+ ": expected reference syntax-> ${referencedKey}");
logger.warn("Couldn't parse referenced key: {}: expected reference syntax-> ${referencedKey}",
reference.substring(start));
break;
}
final String referencedKey = reference.substring(start + 2, end);
Expand Down
Expand Up @@ -23,7 +23,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.automation.Action;
import org.eclipse.smarthome.automation.Condition;
import org.eclipse.smarthome.automation.Module;
Expand Down Expand Up @@ -694,7 +694,7 @@ protected void setRuleEnabled(Rule rule, boolean isEnabled) {
if (status == RuleStatus.DISABLED) {
setRule(runtimeRule);
} else {
logger.debug("The rule rId = " + rUID + " is already enabled.");
logger.debug("The rule rId = {} is already enabled.", rUID);
}
} else {
unregister(runtimeRule);
Expand Down Expand Up @@ -1087,7 +1087,7 @@ protected synchronized RuleStatusInfo getRuleStatusInfo(String rUID) {
return statusMap.get(rUID);
}

protected synchronized String getUniqueId() {
protected synchronized @NonNull String getUniqueId() {
int result = 0;
if (rules != null) {
Set<String> col = rules.keySet();
Expand Down Expand Up @@ -1133,7 +1133,7 @@ protected void scheduleRulesConfigurationUpdated(Map<String, Object> config) {
if (value instanceof Number) {
scheduleReinitializationDelay = ((Number) value).longValue();
} else {
logger.error("Invalid configuration value: " + value + "It MUST be Number.");
logger.error("Invalid configuration value: {}. It MUST be Number.", value);
}
} else {
scheduleReinitializationDelay = DEFAULT_REINITIALIZATION_DELAY;
Expand Down
Expand Up @@ -15,9 +15,9 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.automation.Rule;
import org.eclipse.smarthome.automation.RuleProvider;
import org.eclipse.smarthome.automation.RuleRegistry;
Expand Down Expand Up @@ -231,17 +231,19 @@ protected void removeModuleHandlerFactory(ModuleHandlerFactory moduleHandlerFact
*/
@Override
public Rule add(Rule rule) {
if (rule == null) {
throw new IllegalArgumentException("The added rule must not be null!");
}
String rUID = rule.getUID();
if (rUID == null) {
rUID = ruleEngine.getUniqueId();
super.add(initRuleId(rUID, rule));
} else {
super.add(rule);
}
return get(rUID);
Rule ruleCopy = get(rUID);
if (ruleCopy != null) {
return ruleCopy;
} else {
throw new IllegalStateException();
}
}

/**
Expand All @@ -252,7 +254,7 @@ public Rule add(Rule rule) {
* @param rule candidate for unique ID
* @return a rule with UID
*/
protected Rule initRuleId(String rUID, Rule rule) {
protected @NonNull Rule initRuleId(String rUID, Rule rule) {
Rule ruleWithUID = new Rule(rUID, rule.getTriggers(), rule.getConditions(), rule.getActions(),
rule.getConfigurationDescriptions(), rule.getConfiguration(), rule.getTemplateUID(),
rule.getVisibility());
Expand Down Expand Up @@ -380,7 +382,7 @@ public Rule get(String key) {
@Override
public Stream<Rule> stream() {
// create copies for consumers
return super.stream().map( r -> RuleUtils.getRuleCopy(r) );
return super.stream().map(r -> RuleUtils.getRuleCopy(r));
}

@Override
Expand Down Expand Up @@ -587,9 +589,9 @@ public void runNow(String ruleUID) {
ruleEngine.runNow(ruleUID);
}

@Override
public void runNow(String ruleUID, boolean considerConditions, Map<String, Object> context) {
ruleEngine.runNow(ruleUID, considerConditions, context);
}
@Override
public void runNow(String ruleUID, boolean considerConditions, Map<String, Object> context) {
ruleEngine.runNow(ruleUID, considerConditions, context);
}

}
Expand Up @@ -18,7 +18,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -63,11 +62,13 @@ public RuleTemplate get(String templateUID) {

@Override
public RuleTemplate get(String templateUID, Locale locale) {
RuleTemplate resultTemplate = null;
for (Provider<RuleTemplate> provider : elementMap.keySet()) {
resultTemplate = ((RuleTemplateProvider) provider).getTemplate(templateUID, locale);
if (resultTemplate != null) {
return createCopy(resultTemplate);
for (RuleTemplate resultTemplate : elementMap.get(provider)) {
if (resultTemplate.getUID().equals(templateUID)) {
RuleTemplate t = locale == null ? resultTemplate
: ((RuleTemplateProvider) provider).getTemplate(templateUID, locale);
return createCopy(t);
}
}
}
return null;
Expand Down Expand Up @@ -135,20 +136,15 @@ public Collection<RuleTemplate> getByTag(String tag) {
@Override
public Collection<RuleTemplate> getByTag(String tag, Locale locale) {
Collection<RuleTemplate> result = new ArrayList<RuleTemplate>(20);
Collection<RuleTemplate> templates = null;
for (Provider<RuleTemplate> provider : elementMap.keySet()) {
templates = ((RuleTemplateProvider) provider).getTemplates(locale);
if (templates != null) {
for (Iterator< RuleTemplate>it = templates.iterator(); it.hasNext();) {
RuleTemplate t = it.next();
if (tag != null) {
Collection<String> tags = t.getTags();
if (tags != null && tags.contains(tag)) {
result.add(t);
}
} else {
result.add(t);
}
for (RuleTemplate resultTemplate : elementMap.get(provider)) {
Collection<String> tags = resultTemplate.getTags();
RuleTemplate t = locale == null ? resultTemplate
: ((RuleTemplateProvider) provider).getTemplate(resultTemplate.getUID(), locale);
if (tag == null) {
result.add(t);
} else if (tags != null && tags.contains(tag)) {
result.add(t);
}
}
}
Expand All @@ -164,22 +160,15 @@ public Collection<RuleTemplate> getByTags(String... tags) {
public Collection<RuleTemplate> getByTags(Locale locale, String... tags) {
Set<String> tagSet = tags != null ? new HashSet<String>(Arrays.asList(tags)) : null;
Collection<RuleTemplate> result = new ArrayList<RuleTemplate>(20);
Collection<RuleTemplate> templates = null;
for (Provider<RuleTemplate> provider : elementMap.keySet()) {
templates = ((RuleTemplateProvider) provider).getTemplates(locale);
if (templates != null) {
for (Iterator< RuleTemplate>it = templates.iterator(); it.hasNext();) {
RuleTemplate t = it.next();
if (tagSet != null) {
Collection<String> tTags = t.getTags();
if (tTags != null) {
if (tTags.containsAll(tagSet)) {
result.add(t);
}
}
} else {
result.add(t);
}
for (RuleTemplate resultTemplate : elementMap.get(provider)) {
Collection<String> tTags = resultTemplate.getTags();
RuleTemplate t = locale == null ? resultTemplate
: ((RuleTemplateProvider) provider).getTemplate(resultTemplate.getUID(), locale);
if (tagSet == null) {
result.add(t);
} else if (tTags != null && tTags.containsAll(tagSet)) {
result.add(t);
}
}
}
Expand All @@ -190,4 +179,5 @@ public Collection<RuleTemplate> getByTags(Locale locale, String... tags) {
public Collection<RuleTemplate> getAll(Locale locale) {
return getByTag(null, locale);
}

}
Expand Up @@ -12,7 +12,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -61,13 +60,13 @@ public ModuleType get(String typeUID) {
@Override
@SuppressWarnings("unchecked")
public <T extends ModuleType> T get(String moduleTypeUID, Locale locale) {
T mType = null;
for (Provider<ModuleType> provider : elementMap.keySet()) {
if (provider instanceof ModuleTypeProvider) {
mType = ((ModuleTypeProvider) provider).getModuleType(moduleTypeUID, locale);
}
if (mType != null) {
return (T) createCopy(mType);
for (ModuleType mType : elementMap.get(provider)) {
if (mType.getUID().equals(moduleTypeUID)) {
ModuleType mt = locale == null ? mType
: ((ModuleTypeProvider) provider).getModuleType(mType.getUID(), locale);
return (T) createCopy(mt);
}
}
}
return null;
Expand All @@ -82,20 +81,15 @@ public <T extends ModuleType> Collection<T> getByTag(String moduleTypeTag) {
@SuppressWarnings("unchecked")
public <T extends ModuleType> Collection<T> getByTag(String moduleTypeTag, Locale locale) {
Collection<T> result = new ArrayList<T>(20);
Collection<ModuleType> moduleTypes = null;
for (Provider<ModuleType> provider : elementMap.keySet()) {
moduleTypes = ((ModuleTypeProvider) provider).getModuleTypes(locale);
if (moduleTypes != null) {
for (Iterator<ModuleType> it = moduleTypes.iterator(); it.hasNext();) {
ModuleType mt = it.next();
if (moduleTypeTag != null) {
Collection<String> tags = mt.getTags();
if (tags != null && tags.contains(moduleTypeTag)) {
result.add((T) createCopy(mt));
}
} else {
result.add((T) createCopy(mt));
}
for (ModuleType mType : elementMap.get(provider)) {
ModuleType mt = locale == null ? mType
: ((ModuleTypeProvider) provider).getModuleType(mType.getUID(), locale);
Collection<String> tags = mt.getTags();
if (moduleTypeTag == null) {
result.add((T) createCopy(mt));
} else if (tags != null && tags.contains(moduleTypeTag)) {
result.add((T) createCopy(mt));
}
}
}
Expand All @@ -112,20 +106,14 @@ public <T extends ModuleType> Collection<T> getByTags(String... tags) {
public <T extends ModuleType> Collection<T> getByTags(Locale locale, String... tags) {
Set<String> tagSet = tags != null ? new HashSet<String>(Arrays.asList(tags)) : null;
Collection<T> result = new ArrayList<T>(20);
Collection<ModuleType> moduleTypes = null;
for (Provider<ModuleType> provider : elementMap.keySet()) {
moduleTypes = ((ModuleTypeProvider) provider).getModuleTypes(locale);
if (moduleTypes != null) {
for (Iterator<ModuleType> it = moduleTypes.iterator(); it.hasNext();) {
ModuleType mt = it.next();
if (tagSet != null) {
Collection<String> mtTags = mt.getTags();
if (mtTags.containsAll(tagSet)) {
result.add((T) createCopy(mt));
}
} else {
result.add((T) createCopy(mt));
}
for (ModuleType mType : elementMap.get(provider)) {
ModuleType mt = locale == null ? mType
: ((ModuleTypeProvider) provider).getModuleType(mType.getUID(), locale);
if (tagSet == null) {
result.add((T) createCopy(mt));
} else if (mt.getTags().containsAll(tagSet)) {
result.add((T) createCopy(mt));
}
}
}
Expand Down
Expand Up @@ -185,7 +185,7 @@ protected synchronized ModuleHandler internalCreate(final Module module, final S
}
}

logger.error("The ModuleHandler is not supported:" + moduleTypeUID);
logger.error("The ModuleHandler is not supported:{}", moduleTypeUID);
return null;
}
}

0 comments on commit 10d2d8e

Please sign in to comment.