Search in sources :

Example 1 with CallFlowElementDto

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);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Mappings(org.mapstruct.Mappings) Mapping(org.mapstruct.Mapping) ChoiceDto(org.motechproject.mots.dto.ChoiceDto) CourseModule(org.motechproject.mots.domain.CourseModule) CallFlowElementType(org.motechproject.mots.domain.enums.CallFlowElementType) ArrayList(java.util.ArrayList) UnitDto(org.motechproject.mots.dto.UnitDto) BooleanUtils(org.apache.commons.lang.BooleanUtils) MessageDto(org.motechproject.mots.dto.MessageDto) MappingTarget(org.mapstruct.MappingTarget) Mapper(org.mapstruct.Mapper) MultipleChoiceQuestion(org.motechproject.mots.domain.MultipleChoiceQuestion) Module(org.motechproject.mots.domain.Module) EntityNotFoundException(org.motechproject.mots.exception.EntityNotFoundException) Mappers(org.mapstruct.factory.Mappers) MultipleChoiceQuestionDto(org.motechproject.mots.dto.MultipleChoiceQuestionDto) Choice(org.motechproject.mots.domain.Choice) Course(org.motechproject.mots.domain.Course) CallFlowElement(org.motechproject.mots.domain.CallFlowElement) ReportingPolicy(org.mapstruct.ReportingPolicy) ModuleDto(org.motechproject.mots.dto.ModuleDto) List(java.util.List) Message(org.motechproject.mots.domain.Message) Unit(org.motechproject.mots.domain.Unit) ModuleSimpleDto(org.motechproject.mots.dto.ModuleSimpleDto) Status(org.motechproject.mots.domain.enums.Status) CourseDto(org.motechproject.mots.dto.CourseDto) CallFlowElementDto(org.motechproject.mots.dto.CallFlowElementDto) CallFlowElementDto(org.motechproject.mots.dto.CallFlowElementDto) CallFlowElement(org.motechproject.mots.domain.CallFlowElement) ArrayList(java.util.ArrayList) EntityNotFoundException(org.motechproject.mots.exception.EntityNotFoundException)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 BooleanUtils (org.apache.commons.lang.BooleanUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 Mapper (org.mapstruct.Mapper)1 Mapping (org.mapstruct.Mapping)1 MappingTarget (org.mapstruct.MappingTarget)1 Mappings (org.mapstruct.Mappings)1 ReportingPolicy (org.mapstruct.ReportingPolicy)1 Mappers (org.mapstruct.factory.Mappers)1 CallFlowElement (org.motechproject.mots.domain.CallFlowElement)1 Choice (org.motechproject.mots.domain.Choice)1 Course (org.motechproject.mots.domain.Course)1 CourseModule (org.motechproject.mots.domain.CourseModule)1 Message (org.motechproject.mots.domain.Message)1 Module (org.motechproject.mots.domain.Module)1 MultipleChoiceQuestion (org.motechproject.mots.domain.MultipleChoiceQuestion)1 Unit (org.motechproject.mots.domain.Unit)1 CallFlowElementType (org.motechproject.mots.domain.enums.CallFlowElementType)1 Status (org.motechproject.mots.domain.enums.Status)1