use of org.motechproject.mots.domain.Unit in project mots by motech-implementations.
the class ModuleMapper method updateModuleFromDto.
/**
* Update Module using data from DTO.
* @param moduleDto DTO with new data
* @param module Module to be updated
*/
private void updateModuleFromDto(ModuleDto moduleDto, Module module) {
List<UnitDto> unitDtos = moduleDto.getChildren();
List<Unit> units = module.getUnits();
List<Unit> updatedUnits = new ArrayList<>();
if (units == null) {
units = new ArrayList<>();
}
if (unitDtos != null && !unitDtos.isEmpty()) {
for (int i = 0; i < unitDtos.size(); i++) {
UnitDto unitDto = unitDtos.get(i);
Unit unit;
if (StringUtils.isBlank(unitDto.getId())) {
unit = new Unit();
} else {
unit = units.stream().filter(u -> u.getId().toString().equals(unitDto.getId())).findAny().orElseThrow(() -> new EntityNotFoundException("Cannot update module, because error occurred during unit list update"));
}
updateUnitFromDto(unitDto, unit);
unit.setAllowReplay(BooleanUtils.isTrue(unit.getAllowReplay()));
unit.setListOrder(i);
updatedUnits.add(unit);
}
}
updateFromDto(moduleDto, module);
module.setUnits(updatedUnits);
}
use of org.motechproject.mots.domain.Unit 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