@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 static NodeRecord convertToNodeRecord(final Node node, final Long id) { NodeRecord nodeRecord = new NodeRecord(); nodeRecord.setId(id); nodeRecord.setName(String.format("Message%d", id)); Prompt p = node.getPrompts().get(0); if (p instanceof TextToSpeechPrompt) { nodeRecord.setMessage(((TextToSpeechPrompt) p).getMessage()); } List<Action> actionBefore = node.getActionsBefore(); List<String> actionBeforeRecords = new ArrayList<>(actionBefore.size()); for (Action action : actionBefore) { actionBeforeRecords.add(action.getEventId()); } nodeRecord.setActionsBefore(actionBeforeRecords); List<Action> actionAfter = node.getActionsAfter(); List<String> actionAfterRecords = new ArrayList<>(actionAfter.size()); for (Action action : actionAfter) { actionAfterRecords.add(action.getEventId()); } nodeRecord.setActionsAfter(actionAfterRecords); return nodeRecord; }
node.afterPropertiesSet(); TextToSpeechPrompt prompt = new TextToSpeechPrompt().setMessage(node.getMessage());