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