Search in sources :

Example 1 with 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);
}
Also used : RuleDTO(org.eclipse.smarthome.automation.dto.RuleDTO)

Example 2 with 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);
}
Also used : RuleDTO(org.eclipse.smarthome.automation.dto.RuleDTO)

Example 3 with 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();
}
Also used : RuleDTO(org.eclipse.smarthome.automation.dto.RuleDTO) TypeToken(com.google.gson.reflect.TypeToken) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) JsonReader(com.google.gson.stream.JsonReader) JsonToken(com.google.gson.stream.JsonToken) Rule(org.eclipse.smarthome.automation.Rule) IOException(java.io.IOException) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 4 with 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);
}
Also used : RuleDTO(org.eclipse.smarthome.automation.dto.RuleDTO) RuleRemovedEvent(org.eclipse.smarthome.automation.events.RuleRemovedEvent)

Example 5 with 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);
}
Also used : RuleDTO(org.eclipse.smarthome.automation.dto.RuleDTO) RuleAddedEvent(org.eclipse.smarthome.automation.events.RuleAddedEvent)

Aggregations

RuleDTO (org.eclipse.smarthome.automation.dto.RuleDTO)8 LinkedList (java.util.LinkedList)2 TypeToken (com.google.gson.reflect.TypeToken)1 JsonReader (com.google.gson.stream.JsonReader)1 JsonToken (com.google.gson.stream.JsonToken)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Rule (org.eclipse.smarthome.automation.Rule)1 RuleAddedEvent (org.eclipse.smarthome.automation.events.RuleAddedEvent)1 RuleRemovedEvent (org.eclipse.smarthome.automation.events.RuleRemovedEvent)1 RuleUpdatedEvent (org.eclipse.smarthome.automation.events.RuleUpdatedEvent)1 ParsingException (org.eclipse.smarthome.automation.parser.ParsingException)1 ParsingNestedException (org.eclipse.smarthome.automation.parser.ParsingNestedException)1