use of org.motechproject.mots.domain.CallFlowElement in project mots by motech-implementations.
the class ModuleProgressService method parseVotoUnitBlocks.
/**
* Parse Voto Unit blocks.
* @return returns true if call was interrupted
*/
private boolean parseVotoUnitBlocks(UnitProgress unitProgress, Iterator<VotoBlockDto> blockIterator, boolean callInterrupted) {
unitProgress.startUnit();
List<CallFlowElement> callFlowElements = unitProgress.getNotProcessedCallFlowElements();
for (CallFlowElement callFlowElement : callFlowElements) {
if (blockIterator.hasNext()) {
VotoBlockDto blockDto = blockIterator.next();
if (!callFlowElement.getIvrId().equals(blockDto.getBlockId())) {
throw new CourseProgressException("IVR Block Id: {0} did not match CallFlowElement IVRId", blockDto.getBlockId());
}
LocalDateTime startDate = parseDate(blockDto.getEntryAt());
LocalDateTime endDate = parseDate(blockDto.getExitAt());
if (CallFlowElementType.QUESTION.equals(callFlowElement.getType())) {
Integer choiceId = getChoiceId(blockDto);
Integer numberOfAttempts = getNumberOfAttempts(blockDto);
unitProgress.addMultipleChoiceQuestionLog(startDate, endDate, callFlowElement, choiceId, numberOfAttempts);
} else {
unitProgress.addMessageLog(startDate, endDate, callFlowElement);
}
unitProgress.nextElement();
} else {
if (callInterrupted) {
unitProgress.previousElement();
return true;
}
throw new CourseProgressException("Unexpected end of IVR Call Log");
}
}
return false;
}
use of org.motechproject.mots.domain.CallFlowElement in project mots by motech-implementations.
the class ModuleMapper method updateUnitFromDto.
private void updateUnitFromDto(UnitDto unitDto, Unit unit) {
List<CallFlowElementDto> callFlowElementDtos = unitDto.getChildren();
List<CallFlowElement> callFlowElements = unit.getCallFlowElements();
List<CallFlowElement> updatedCallFlowElements = new ArrayList<>();
if (callFlowElements == null) {
callFlowElements = new ArrayList<>();
}
if (callFlowElementDtos != null && !callFlowElementDtos.isEmpty()) {
for (int i = 0; i < callFlowElementDtos.size(); i++) {
CallFlowElementDto callFlowElementDto = callFlowElementDtos.get(i);
CallFlowElement callFlowElement;
if (callFlowElementDto.getId() == null) {
callFlowElement = fromDto(callFlowElementDto);
} else {
callFlowElement = callFlowElements.stream().filter(cf -> cf.getId().toString().equals(callFlowElementDto.getId())).findAny().orElseThrow(() -> new EntityNotFoundException("Cannot update module, because error occurred during unit list update"));
updateFromDto(callFlowElementDto, callFlowElement);
}
callFlowElement.setListOrder(i);
updatedCallFlowElements.add(callFlowElement);
}
}
updateFromDto(unitDto, unit);
unit.setCallFlowElements(updatedCallFlowElements);
}
Aggregations