/** * Emits an event before whenever a particular transition happens on the specified tree. Event subject is the eventId associated with the action. * * @param transition transition that is about to happen * @param params extra information to be passed */ public void sendTransitionActions(Transition transition, Map<String, Object> params) { Assert.notNull(transition, "Transition must not be null"); Assert.notNull(params, "Params must not be null"); params.put("transitionName", transition.getName()); sendActions(transition.getActions(), params); } }
@RequestMapping(value = "/tree/example", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void createExampleTree() { decisionTreeService.saveDecisionTree(new Tree() .setName("Illness Tree") .setRootTransition(new Transition().setDestinationNode(new Node() .setPrompts(new TextToSpeechPrompt().setMessage("if you feel sick select 1, if not select 2")) .setTransitions(new Object[][]{ {"1", new Transition().setName("pressed1") .setDestinationNode(new Node() .setPrompts(new TextToSpeechPrompt().setMessage("if you have a fever select 1, if not select 3")) .setTransitions(new Object[][]{ {"1", new Transition().setName("pressed1").setDestinationNode( new Node().setPrompts(new TextToSpeechPrompt().setMessage("come to the hospital now")) )}, {"3", new Transition().setName("pressed3").setDestinationNode( new Node().setPrompts(new TextToSpeechPrompt().setMessage("be patient, we will call you")) )} }) )}, {"2", new Transition().setName("pressed2") .setDestinationNode(new Node().setPrompts(new TextToSpeechPrompt().setMessage("Check with us again")))} }) ))); }
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)); } } }
transitions[i][1] = new Transition().setName(name).setDestinationNode(destinationNode); .setName(tree.getName()) .setDescription(tree.getDescription()) .setRootTransition(new Transition().setDestinationNode(convertedNodes.get(rootId)));
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)); } } }
/** * Emits an event before whenever a particular transition happens on the specified tree. Event subject is the eventId associated with the action. * * @param transition transition that is about to happen * @param params extra information to be passed */ public void sendTransitionActions(Transition transition, Map<String, Object> params) { Assert.notNull(transition, "Transition must not be null"); Assert.notNull(params, "Params must not be null"); params.put("transitionName", transition.getName()); sendActions(transition.getActions(), params); } }