Search in sources :

Example 1 with Course

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

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

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

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

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

the class ModuleService method createModule.

/**
 * Create new Module.
 * @param moduleDto DTO of Module to be created
 * @return Created Module
 */
@Transactional
@PreAuthorize(RoleNames.HAS_MANAGE_MODULES_ROLE)
public ModuleDto createModule(ModuleDto moduleDto) {
    Course course = getDraftCourse();
    CourseModule courseModule = new CourseModule(course, Module.initialize(), course.getModules().size());
    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) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Course (org.motechproject.mots.domain.Course)10 CourseModule (org.motechproject.mots.domain.CourseModule)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 MotsException (org.motechproject.mots.exception.MotsException)4 Module (org.motechproject.mots.domain.Module)3 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 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