Search in sources :

Example 1 with MotsException

use of org.motechproject.mots.exception.MotsException in project mots by motech-implementations.

the class ModuleService method createCourse.

/**
 * Create new Course.
 * @return Created Course
 */
@Transactional
@PreAuthorize(RoleNames.HAS_MANAGE_MODULES_ROLE)
public Course createCourse() {
    List<Course> courses = courseRepository.findByStatus(Status.DRAFT);
    if (courses != null && !courses.isEmpty()) {
        throw new MotsException("Only one draft course allowed at a time");
    }
    Course releasedCourse = getReleasedCourseIfExists();
    Course course;
    if (releasedCourse == null) {
        course = Course.initialize();
    } else {
        course = releasedCourse.copyAsNewDraft();
    }
    return courseRepository.save(course);
}
Also used : Course(org.motechproject.mots.domain.Course) MotsException(org.motechproject.mots.exception.MotsException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MotsException

use of org.motechproject.mots.exception.MotsException in project mots by motech-implementations.

the class ModuleService method updateCourse.

/**
 * Update existing Course.
 * @param id id of Course to be updated
 * @param courseDto Course DTO
 * @return updated Course
 */
@PreAuthorize(RoleNames.HAS_MANAGE_MODULES_ROLE)
public Course updateCourse(UUID id, CourseDto courseDto) {
    Course course = findCourseById(id);
    if (!Status.DRAFT.equals(course.getStatus())) {
        throw new MotsException("Only Course draft can be updated");
    }
    moduleMapper.updateCourseFromDto(courseDto, course);
    return courseRepository.save(course);
}
Also used : Course(org.motechproject.mots.domain.Course) MotsException(org.motechproject.mots.exception.MotsException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with MotsException

use of org.motechproject.mots.exception.MotsException in project mots by motech-implementations.

the class ModuleService method updateModule.

/**
 * Update existing Module.
 * @param id id of Module to be updated
 * @param moduleDto Module DTO
 * @return updated Module
 */
@PreAuthorize(RoleNames.HAS_MANAGE_MODULES_ROLE)
public ModuleDto updateModule(UUID id, ModuleDto moduleDto) {
    Course course = getDraftCourse();
    CourseModule courseModule = course.findCourseModuleByModuleId(id);
    Module module = courseModule.getModule();
    if (!Status.DRAFT.equals(module.getStatus())) {
        throw new MotsException("Only Module draft can be updated");
    }
    moduleMapper.updateCourseModuleFromDto(moduleDto, courseModule);
    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 4 with MotsException

use of org.motechproject.mots.exception.MotsException 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 5 with MotsException

use of org.motechproject.mots.exception.MotsException in project mots by motech-implementations.

the class ModuleProgressService method updateModuleProgress.

/**
 * Update Module Progress after call ends.
 * @param votoCallLogDto log containing all Voto tree interactions in specific call
 * @param callInterrupted true if last call was interrupted
 */
public void updateModuleProgress(VotoCallLogDto votoCallLogDto, boolean callInterrupted) {
    String chwIvrId = votoCallLogDto.getChwIvrId();
    Optional<ModuleProgress> interruptedModuleProgress = moduleProgressRepository.findByCommunityHealthWorkerIvrIdAndInterrupted(chwIvrId, true);
    Iterator<VotoBlockDto> blockIterator = votoCallLogDto.getInteractions().iterator();
    try {
        if (interruptedModuleProgress.isPresent()) {
            ModuleProgress moduleProgress = interruptedModuleProgress.get();
            if (parseVotoModuleBlocks(votoCallLogDto, blockIterator, moduleProgress.getCourseModule().getIvrId(), callInterrupted)) {
                return;
            }
        }
        parseVotoMainMenuBlocks(votoCallLogDto, blockIterator, callInterrupted);
    } catch (MotsException ex) {
        LOGGER.error("Could not parse CallLog with id: " + votoCallLogDto.getLogId(), ex);
    }
}
Also used : VotoBlockDto(org.motechproject.mots.dto.VotoBlockDto) ModuleProgress(org.motechproject.mots.domain.ModuleProgress) MotsException(org.motechproject.mots.exception.MotsException)

Aggregations

MotsException (org.motechproject.mots.exception.MotsException)5 Course (org.motechproject.mots.domain.Course)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 CourseModule (org.motechproject.mots.domain.CourseModule)2 Module (org.motechproject.mots.domain.Module)2 ModuleProgress (org.motechproject.mots.domain.ModuleProgress)1 VotoBlockDto (org.motechproject.mots.dto.VotoBlockDto)1 Transactional (org.springframework.transaction.annotation.Transactional)1