use of org.motechproject.mots.domain.Module 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.Module in project mots by motech-implementations.
the class ModuleDataBuilder method buildAsNew.
/**
* Builds instance of {@link Module} without id.
*/
public Module buildAsNew() {
Module module = new Module();
module.setName(name);
module.setIvrGroup(ivrGroup);
return module;
}
use of org.motechproject.mots.domain.Module in project mots by motech-implementations.
the class ModuleDataBuilder method build.
/**
* Builds instance of {@link Module}.
*/
public Module build() {
Module module = buildAsNew();
module.setId(id);
return module;
}
use of org.motechproject.mots.domain.Module in project mots by motech-implementations.
the class ModuleMapper method updateUnitFromDto.
private void updateUnitFromDto(UnitDto unitDto, Unit unit) {
List<CallFlowElementDto> callFlowElementDtos = unitDto.getChildren();
List<CallFlowElement> callFlowElements = unit.getCallFlowElements();
List<CallFlowElement> updatedCallFlowElements = new ArrayList<>();
if (callFlowElements == null) {
callFlowElements = new ArrayList<>();
}
if (callFlowElementDtos != null && !callFlowElementDtos.isEmpty()) {
for (int i = 0; i < callFlowElementDtos.size(); i++) {
CallFlowElementDto callFlowElementDto = callFlowElementDtos.get(i);
CallFlowElement callFlowElement;
if (callFlowElementDto.getId() == null) {
callFlowElement = fromDto(callFlowElementDto);
} else {
callFlowElement = callFlowElements.stream().filter(cf -> cf.getId().toString().equals(callFlowElementDto.getId())).findAny().orElseThrow(() -> new EntityNotFoundException("Cannot update module, because error occurred during unit list update"));
updateFromDto(callFlowElementDto, callFlowElement);
}
callFlowElement.setListOrder(i);
updatedCallFlowElements.add(callFlowElement);
}
}
updateFromDto(unitDto, unit);
unit.setCallFlowElements(updatedCallFlowElements);
}
use of org.motechproject.mots.domain.Module 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