private ITransition getPreConfiguredTransition(Node parentNode, String userInput) { return parentNode.getTransitions().get(userInput); }
private ITransition getPreConfiguredTransition(Node parentNode, String userInput) { return parentNode.getTransitions().get(userInput); }
private ITransition getTransitionForUserInput(String userInput, Node parentNode) { ITransition transition = getPreConfiguredTransition(parentNode, userInput); if (transition == null) { transition = parentNode.getTransitions().get(TreeNodeLocator.ANY_KEY); } if (transition == null) { throw new DecisionTreeException(Error.INVALID_TRANSITION_KEY, "Invalid Transition Key. There is no transition with key: " + userInput + " in the Node: " + parentNode); } return transition; }
private ITransition getTransitionForUserInput(String userInput, Node parentNode) { ITransition transition = getPreConfiguredTransition(parentNode, userInput); if (transition == null) { transition = parentNode.getTransitions().get(TreeNodeLocator.ANY_KEY); } if (transition == null) { throw new DecisionTreeException(Error.INVALID_TRANSITION_KEY, "Invalid Transition Key. There is no transition with key: " + userInput + " in the Node: " + parentNode); } return transition; }
private boolean hasNoActionableItems(Node node) { return node.getPrompts().isEmpty() && hasNoActions(node) && node.getTransitions().isEmpty(); }
private boolean hasNoActionableItems(Node node) { return node.getPrompts().isEmpty() && hasNoActions(node) && node.getTransitions().isEmpty(); }
private Integer maxDigits(Node node) { Map<String, ITransition> transitions = node.getTransitions(); int maxDigits = 1; for (String key : transitions.keySet()) { if (hasSpecialMeaning(key)) { return (node.getMaxTransitionInputDigit() == null) ? MAX_INPUT_DIGITS : node.getMaxTransitionInputDigit(); } if (maxDigits < key.length()) { maxDigits = key.length(); } } return maxDigits; }
private Integer maxDigits(Node node) { Map<String, ITransition> transitions = node.getTransitions(); int maxDigits = 1; for (String key : transitions.keySet()) { if (hasSpecialMeaning(key)) { return (node.getMaxTransitionInputDigit() == null) ? MAX_INPUT_DIGITS : node.getMaxTransitionInputDigit(); } if (maxDigits < key.length()) { maxDigits = key.length(); } } return maxDigits; }
private void validateNode(Node node) { for (Map.Entry<String, ITransition> transitionEntry : node.getTransitions().entrySet()) { final String key = transitionEntry.getKey(); if (noInput(key) || hasSpecialMeaning(key) || dtmfKey(key)) { return; } if (anyInput(key)) { return; } if (isStatusKey(key)) { return; } try { Integer.parseInt(key); } catch (NumberFormatException e) { throw new DecisionTreeException(Error.INVALID_TRANSITION_KEY, format("Invalid transition key [%s] for node [%s]", key, node), e); } ITransition transition = transitionEntry.getValue(); if (transition instanceof Transition && ((Transition) transition).getDestinationNode() == null) { throw new DecisionTreeException(Error.NULL_DESTINATION_NODE, format("Missing destination node in the transition for key [%s] on node [%s]: ", key, node)); } } }
private void validateNode(Node node) { for (Map.Entry<String, ITransition> transitionEntry : node.getTransitions().entrySet()) { final String key = transitionEntry.getKey(); if (noInput(key) || hasSpecialMeaning(key) || dtmfKey(key)) { return; } if (anyInput(key)) { return; } if (isStatusKey(key)) { return; } try { Integer.parseInt(key); } catch (NumberFormatException e) { throw new DecisionTreeException(Error.INVALID_TRANSITION_KEY, format("Invalid transition key [%s] for node [%s]", key, node), e); } ITransition transition = transitionEntry.getValue(); if (transition instanceof Transition && ((Transition) transition).getDestinationNode() == null) { throw new DecisionTreeException(Error.NULL_DESTINATION_NODE, format("Missing destination node in the transition for key [%s] on node [%s]: ", key, node)); } } }
public static TreeRecord convertToTreeRecord(final Tree tree) { TreeRecord treeRecord = new TreeRecord(); treeRecord.setName(tree.getName()); treeRecord.setDescription(tree.getDescription()); Map<Long, Node> nodes = new HashMap<>(); List<NodeRecord> nodeRecords = new ArrayList<>(); nodes.put(0L, tree.getRootTransition().getDestinationNode(null, null)); Long transitionId = 0L; Long nodeId = 0L; Long count = 1L; while (!nodes.isEmpty()) { Node next = nodes.get(nodeId); NodeRecord converted = convertToNodeRecord(next, nodeId); converted.setTransitions(new ArrayList<TransitionRecord>()); for (Map.Entry<String, ITransition> entry : next.getTransitions().entrySet()) { TransitionRecord transitionRecord = new TransitionRecord(); transitionRecord.setId(transitionId++); transitionRecord.setKey(entry.getKey()); transitionRecord.setNode(count); nodes.put(count, entry.getValue().getDestinationNode(null, null)); converted.getTransitions().add(transitionRecord); ++count; } nodeRecords.add(converted); nodes.remove(nodeId); ++nodeId; } treeRecord.setNodes(nodeRecords); return treeRecord; }