Search in sources :

Example 1 with GroupletLinkPolicy

use of org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy in project symmetric-ds by JumpMind.

the class GroupletService method isSourceEnabled.

public boolean isSourceEnabled(TriggerRouter triggerRouter) {
    boolean enabled = true;
    Node node = engine.getNodeService().findIdentity();
    if (node == null) {
        enabled = false;
    } else {
        List<Grouplet> grouplets = getGroupletsFor(triggerRouter, AppliesWhen.S, false);
        if (grouplets != null && grouplets.size() > 0) {
            enabled = false;
            for (Grouplet grouplet : grouplets) {
                GroupletLinkPolicy policy = grouplet.getGroupletLinkPolicy();
                List<GroupletLink> links = grouplet.getGroupletLinks();
                boolean foundMatch = false;
                for (GroupletLink groupletLink : links) {
                    if (groupletLink.getExternalId().equals(node.getExternalId())) {
                        foundMatch = true;
                    }
                }
                if ((foundMatch && policy == GroupletLinkPolicy.I) || (!foundMatch && policy == GroupletLinkPolicy.E)) {
                    enabled = true;
                }
            }
        }
    }
    return enabled;
}
Also used : TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) Grouplet(org.jumpmind.symmetric.model.Grouplet) GroupletLink(org.jumpmind.symmetric.model.GroupletLink) Node(org.jumpmind.symmetric.model.Node) GroupletLinkPolicy(org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy)

Example 2 with GroupletLinkPolicy

use of org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy in project symmetric-ds by JumpMind.

the class GroupletService method getTargetEnabled.

public Set<Node> getTargetEnabled(TriggerRouter triggerRouter, Set<Node> nodes) {
    List<Grouplet> grouplets = getGroupletsFor(triggerRouter, AppliesWhen.T, false);
    if (grouplets != null && grouplets.size() > 0) {
        Set<Node> matchedNodes = new HashSet<Node>();
        Set<Node> excludedNodes = new HashSet<Node>();
        for (Grouplet grouplet : grouplets) {
            GroupletLinkPolicy policy = grouplet.getGroupletLinkPolicy();
            List<GroupletLink> links = grouplet.getGroupletLinks();
            for (GroupletLink groupletLink : links) {
                for (Node node : nodes) {
                    if (groupletLink.getExternalId().equals(node.getExternalId())) {
                        if (policy == GroupletLinkPolicy.I) {
                            matchedNodes.add(node);
                        } else {
                            excludedNodes.add(node);
                        }
                    }
                }
            }
        }
        Set<Node> toReturn = new HashSet<Node>();
        excludedNodes.removeAll(matchedNodes);
        if (excludedNodes.size() > 0) {
            toReturn.addAll(nodes);
            toReturn.removeAll(excludedNodes);
        } else {
            toReturn.addAll(matchedNodes);
        }
        return toReturn;
    } else {
        return nodes;
    }
}
Also used : TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) Grouplet(org.jumpmind.symmetric.model.Grouplet) GroupletLink(org.jumpmind.symmetric.model.GroupletLink) Node(org.jumpmind.symmetric.model.Node) GroupletLinkPolicy(org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy) HashSet(java.util.HashSet)

Aggregations

Grouplet (org.jumpmind.symmetric.model.Grouplet)2 GroupletLinkPolicy (org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy)2 GroupletLink (org.jumpmind.symmetric.model.GroupletLink)2 Node (org.jumpmind.symmetric.model.Node)2 TriggerRouterGrouplet (org.jumpmind.symmetric.model.TriggerRouterGrouplet)2 HashSet (java.util.HashSet)1