use of org.eclipse.smarthome.automation.dto.RuleDTO in project smarthome by eclipse.
the class RuleEventFactory method createRuleAddedEvent.
/**
* Creates a rule added event
*
* @param rule the rule for which this event is created
* @param source the source of the event
* @return {@link RuleAddedEvent} instance
*/
public static RuleAddedEvent createRuleAddedEvent(Rule rule, String source) {
String topic = buildTopic(RULE_ADDED_EVENT_TOPIC, rule);
final RuleDTO ruleDto = RuleDTOMapper.map(rule);
String payload = serializePayload(ruleDto);
return new RuleAddedEvent(topic, payload, source, ruleDto);
}
use of org.eclipse.smarthome.automation.dto.RuleDTO in project smarthome by eclipse.
the class RuleEventFactory method createRuleRemovedEvent.
/**
* Creates a rule removed event
*
* @param rule the rule for which this event is created
* @param source the source of the event
* @return {@link RuleRemovedEvent} instance
*/
public static RuleRemovedEvent createRuleRemovedEvent(Rule rule, String source) {
String topic = buildTopic(RULE_REMOVED_EVENT_TOPIC, rule);
final RuleDTO ruleDto = RuleDTOMapper.map(rule);
String payload = serializePayload(ruleDto);
return new RuleRemovedEvent(topic, payload, source, ruleDto);
}
use of org.eclipse.smarthome.automation.dto.RuleDTO in project smarthome by eclipse.
the class RuleGSONParser method parse.
@Override
public Set<Rule> parse(InputStreamReader reader) throws ParsingException {
JsonReader jr = new JsonReader(reader);
try {
Set<Rule> rules = new HashSet<>();
if (jr.hasNext()) {
JsonToken token = jr.peek();
if (JsonToken.BEGIN_ARRAY.equals(token)) {
List<RuleDTO> ruleDtos = gson.fromJson(jr, new TypeToken<List<RuleDTO>>() {
}.getType());
for (RuleDTO ruleDto : ruleDtos) {
rules.add(RuleDTOMapper.map(ruleDto));
}
} else {
RuleDTO ruleDto = gson.fromJson(jr, RuleDTO.class);
rules.add(RuleDTOMapper.map(ruleDto));
}
return rules;
}
} catch (Exception e) {
throw new ParsingException(new ParsingNestedException(ParsingNestedException.RULE, null, e));
} finally {
try {
jr.close();
} catch (IOException e) {
}
}
return Collections.emptySet();
}
use of org.eclipse.smarthome.automation.dto.RuleDTO in project smarthome by eclipse.
the class RuleEventFactory method createRuleRemovedEvent.
/**
* Creates a rule removed event.
*
* @param rule the rule for which this event is created.
* @param source the source of the event.
* @return {@link RuleRemovedEvent} instance.
*/
public static RuleRemovedEvent createRuleRemovedEvent(Rule rule, String source) {
String topic = buildTopic(RULE_REMOVED_EVENT_TOPIC, rule);
final RuleDTO ruleDto = RuleDTOMapper.map(rule);
String payload = serializePayload(ruleDto);
return new RuleRemovedEvent(topic, payload, source, ruleDto);
}
use of org.eclipse.smarthome.automation.dto.RuleDTO in project smarthome by eclipse.
the class RuleEventFactory method createRuleAddedEvent.
/**
* Creates a rule added event.
*
* @param rule the rule for which this event is created.
* @param source the source of the event.
* @return {@link RuleAddedEvent} instance.
*/
public static RuleAddedEvent createRuleAddedEvent(Rule rule, String source) {
String topic = buildTopic(RULE_ADDED_EVENT_TOPIC, rule);
final RuleDTO ruleDto = RuleDTOMapper.map(rule);
String payload = serializePayload(ruleDto);
return new RuleAddedEvent(topic, payload, source, ruleDto);
}
Aggregations