use of org.motechproject.mots.dto.CallFlowElementDto 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