Search in sources :

Example 6 with Module

use of org.motechproject.mots.domain.Module in project mots by motech-implementations.

the class ModuleService method copyModule.

/**
 * Copy Module as a new draft.
 * @param id id of module to be copied
 * @return copied module draft
 */
@PreAuthorize(RoleNames.HAS_MANAGE_MODULES_ROLE)
public ModuleDto copyModule(UUID id) {
    Course course = getDraftCourse();
    CourseModule courseModule = course.findCourseModuleByModuleId(id);
    if (!Status.RELEASED.equals(courseModule.getModule().getStatus())) {
        throw new MotsException("Only released Module can be copied");
    }
    Module moduleCopy = courseModule.getModule().copyAsNewDraft();
    courseModule.setModule(moduleCopy);
    courseModule = courseModuleRepository.save(courseModule);
    return moduleMapper.toDto(courseModule);
}
Also used : CourseModule(org.motechproject.mots.domain.CourseModule) Course(org.motechproject.mots.domain.Course) CourseModule(org.motechproject.mots.domain.CourseModule) Module(org.motechproject.mots.domain.Module) MotsException(org.motechproject.mots.exception.MotsException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with Module

use of org.motechproject.mots.domain.Module in project mots by motech-implementations.

the class ModuleDataBuilder method buildAsNew.

/**
 * Builds instance of {@link Module} without id.
 */
public Module buildAsNew() {
    Module module = new Module();
    module.setName(name);
    module.setIvrGroup(ivrGroup);
    return module;
}
Also used : Module(org.motechproject.mots.domain.Module)

Example 8 with Module

use of org.motechproject.mots.domain.Module in project mots by motech-implementations.

the class ModuleDataBuilder method build.

/**
 * Builds instance of {@link Module}.
 */
public Module build() {
    Module module = buildAsNew();
    module.setId(id);
    return module;
}
Also used : Module(org.motechproject.mots.domain.Module)

Example 9 with Module

use of org.motechproject.mots.domain.Module 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)

Example 10 with Module

use of org.motechproject.mots.domain.Module in project mots by motech-implementations.

the class ModuleMapper method updateCourseFromDto.

/**
 * Update Course using data from DTO.
 * @param courseDto DTO with new data
 * @param course Course to be updated
 */
public void updateCourseFromDto(CourseDto courseDto, Course course) {
    List<ModuleDto> moduleDtos = courseDto.getChildren();
    List<CourseModule> courseModules = course.getCourseModules();
    List<CourseModule> updatedCourseModules = new ArrayList<>();
    if (courseModules == null) {
        courseModules = new ArrayList<>();
    }
    if (moduleDtos != null && !moduleDtos.isEmpty()) {
        for (int i = 0; i < moduleDtos.size(); i++) {
            ModuleDto moduleDto = moduleDtos.get(i);
            CourseModule courseModule;
            if (StringUtils.isBlank(moduleDto.getId())) {
                courseModule = new CourseModule(course, Module.initialize());
            } else {
                courseModule = courseModules.stream().filter(cm -> cm.getModule().getId().toString().equals(moduleDto.getId())).findAny().orElseThrow(() -> new EntityNotFoundException("Cannot update course, because error occurred during module list update"));
            }
            updateCourseModuleFromDto(moduleDto, courseModule);
            courseModule.setListOrder(i);
            updatedCourseModules.add(courseModule);
        }
    }
    updateFromDto(courseDto, course);
    course.setCourseModules(updatedCourseModules);
}
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) CourseModule(org.motechproject.mots.domain.CourseModule) ArrayList(java.util.ArrayList) EntityNotFoundException(org.motechproject.mots.exception.EntityNotFoundException) ModuleDto(org.motechproject.mots.dto.ModuleDto)

Aggregations

Module (org.motechproject.mots.domain.Module)10 CourseModule (org.motechproject.mots.domain.CourseModule)7 Course (org.motechproject.mots.domain.Course)5 EntityNotFoundException (org.motechproject.mots.exception.EntityNotFoundException)5 List (java.util.List)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 BooleanUtils (org.apache.commons.lang.BooleanUtils)3 StringUtils (org.apache.commons.lang.StringUtils)3 Mapper (org.mapstruct.Mapper)3 Mapping (org.mapstruct.Mapping)3 MappingTarget (org.mapstruct.MappingTarget)3 Mappings (org.mapstruct.Mappings)3 ReportingPolicy (org.mapstruct.ReportingPolicy)3 Mappers (org.mapstruct.factory.Mappers)3 AssignedModules (org.motechproject.mots.domain.AssignedModules)3 CallFlowElement (org.motechproject.mots.domain.CallFlowElement)3 Choice (org.motechproject.mots.domain.Choice)3 CommunityHealthWorker (org.motechproject.mots.domain.CommunityHealthWorker)3