Search in sources :

Example 6 with Course

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

the class ModuleController method releaseCourse.

/**
 * Release Course.
 * @param id id of Course to release
 */
@RequestMapping(value = "/courses/{id}/release", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public CourseDto releaseCourse(@PathVariable("id") UUID id) {
    Course course = moduleService.findCourseById(id);
    validateCourseForRelease(course);
    return moduleMapper.toDto(moduleService.releaseCourse(course));
}
Also used : Course(org.motechproject.mots.domain.Course) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with Course

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

the class ModuleController method updateCourse.

/**
 * Update Course.
 * @param id id of Course to update
 * @param courseDto DTO of Course to update
 * @return updated Course
 */
@RequestMapping(value = "/courses/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public CourseDto updateCourse(@PathVariable("id") UUID id, @RequestBody @Valid CourseDto courseDto, BindingResult bindingResult) {
    checkBindingResult(bindingResult);
    Course course = moduleService.updateCourse(id, courseDto);
    return moduleMapper.toDto(course);
}
Also used : Course(org.motechproject.mots.domain.Course) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with Course

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

the class ModuleProgressService method createModuleProgress.

private void createModuleProgress(CommunityHealthWorker chw, Module module) {
    Course course = moduleService.getReleasedCourse();
    if (!moduleProgressRepository.findByCommunityHealthWorkerIdAndCourseModuleModuleIdAndCourseModuleCourseId(chw.getId(), module.getId(), course.getId()).isPresent()) {
        CourseModule courseModule = moduleService.findReleasedCourseModuleByModuleId(module.getId());
        ModuleProgress moduleProgress = new ModuleProgress(chw, courseModule);
        moduleProgressRepository.save(moduleProgress);
    }
}
Also used : ModuleProgress(org.motechproject.mots.domain.ModuleProgress) CourseModule(org.motechproject.mots.domain.CourseModule) Course(org.motechproject.mots.domain.Course)

Example 9 with Course

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

the class ModuleProgressService method removeModuleProgresses.

/**
 * Remove Module Progresses for given CHW and Modules.
 * @param chw CHW for which Module Progresses should be removed
 * @param modules List of Module for which Module Progresses should be removed
 */
public void removeModuleProgresses(CommunityHealthWorker chw, Set<Module> modules) {
    Course course = moduleService.getReleasedCourse();
    modules.forEach(module -> moduleProgressRepository.removeAllByCommunityHealthWorkerIdAndCourseModuleModuleIdAndCourseModuleCourseId(chw.getId(), module.getId(), course.getId()));
}
Also used : Course(org.motechproject.mots.domain.Course)

Example 10 with Course

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

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