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));
}
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);
}
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);
}
}
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()));
}
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);
}
Aggregations