org.jetlinks.rule.engine.api.model.RuleModel Maven / Gradle / Ivy
package org.jetlinks.rule.engine.api.model;
import lombok.Getter;
import lombok.Setter;
import org.jetlinks.rule.engine.api.scheduler.SchedulingRule;
import java.util.*;
import java.util.stream.Collectors;
/**
* 规则模型
*
* @author zhouhao
* @since 1.0.0
*/
@Getter
@Setter
public class RuleModel {
private String id;
private String name;
private String description;
private SchedulingRule schedulingRule;
private Map configuration = new HashMap<>();
private List events = new ArrayList<>();
private List nodes = new ArrayList<>();
public List getEvents(String type) {
return events.stream()
.filter(link -> type.equals(link.getType()))
.collect(Collectors.toList());
}
public Optional getNode(String nodeId) {
return nodes.stream()
.filter(model -> model.getId().equals(nodeId))
.findFirst();
}
public RuleModel addConfiguration(String key, Object value) {
configuration.put(key, value);
return this;
}
public Optional getStartNode() {
return nodes.stream()
.filter(RuleNodeModel::isStart)
.findFirst();
}
public List getEndNodes() {
return nodes.stream()
.filter(RuleNodeModel::isEnd)
.collect(Collectors.toList());
}
}