Search in sources :

Example 1 with CourseSignupStudyProgrammeDAO

use of fi.otavanopisto.pyramus.dao.courses.CourseSignupStudyProgrammeDAO in project pyramus by otavanopisto.

the class EditCourseJSONRequestController method processSignupStudyProgrammes.

private void processSignupStudyProgrammes(JSONRequestContext requestContext, Course course, StaffMember loggedUser) {
    CourseSignupStudyProgrammeDAO courseSignupStudyProgrammeDAO = DAOFactory.getInstance().getCourseSignupStudyProgrammeDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    List<CourseSignupStudyProgramme> signupStudyProgrammes = courseSignupStudyProgrammeDAO.listByCourse(course);
    Integer studyProgrammesRowCount = requestContext.getInteger("signupStudyProgrammesTable.rowCount");
    if (studyProgrammesRowCount != null) {
        Set<Long> studyProgrammeIdsPresent = new HashSet<>();
        for (int i = 0; i < studyProgrammesRowCount; i++) {
            Long studyProgrammeId = requestContext.getLong(String.format("signupStudyProgrammesTable.%d.studyProgrammeId", i));
            if (studyProgrammeId != null) {
                studyProgrammeIdsPresent.add(studyProgrammeId);
            }
        }
        // Create missing groups
        studyProgrammeIdsPresent.forEach(studentGroupId -> {
            if (signupStudyProgrammes.stream().noneMatch(signupStudentGroup -> Objects.equals(signupStudentGroup.getStudyProgramme().getId(), studentGroupId))) {
                StudyProgramme studyProgramme = studyProgrammeDAO.findById(studentGroupId);
                if ((studyProgramme != null) && UserUtils.canAccessOrganization(loggedUser, studyProgramme.getOrganization())) {
                    courseSignupStudyProgrammeDAO.create(course, studyProgramme);
                } else {
                    throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
                }
            }
        });
        // Remove groups that don't exist anymore
        signupStudyProgrammes.stream().filter(signupStudyProgramme -> !studyProgrammeIdsPresent.contains(signupStudyProgramme.getStudyProgramme().getId())).forEach(signupStudyProgramme -> {
            if (UserUtils.canAccessOrganization(loggedUser, signupStudyProgramme.getStudyProgramme().getOrganization())) {
                courseSignupStudyProgrammeDAO.delete(signupStudyProgramme);
            } else {
                throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
            }
        });
    }
}
Also used : CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) Enumeration(java.util.Enumeration) UserUtils(fi.otavanopisto.pyramus.framework.UserUtils) Date(java.util.Date) BasicCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.BasicCourseResource) OtherCost(fi.otavanopisto.pyramus.domainmodel.courses.OtherCost) JSONRequestContext(fi.internetix.smvc.controllers.JSONRequestContext) GradeCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.GradeCourseResource) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) OtherCostDAO(fi.otavanopisto.pyramus.dao.courses.OtherCostDAO) BigDecimal(java.math.BigDecimal) Vector(java.util.Vector) CourseComponentResourceDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentResourceDAO) CourseParticipationTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO) Locale(java.util.Locale) Map(java.util.Map) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) UserRole(fi.otavanopisto.pyramus.framework.UserRole) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) StaleObjectStateException(org.hibernate.StaleObjectStateException) CourseSignupStudentGroupDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudentGroupDAO) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) Set(java.util.Set) GradeCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.GradeCourseResourceDAO) PyramusStatusCode(fi.otavanopisto.pyramus.framework.PyramusStatusCode) Messages(fi.otavanopisto.pyramus.I18N.Messages) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) Objects(java.util.Objects) List(java.util.List) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) CourseEnrolmentTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StudentCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.StudentCourseResourceDAO) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Resource(fi.otavanopisto.pyramus.domainmodel.resources.Resource) CourseStaffMemberRole(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMemberRole) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) CourseDescription(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescription) ResourceType(fi.otavanopisto.pyramus.domainmodel.resources.ResourceType) HashMap(java.util.HashMap) Currency(java.util.Currency) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseSignupStudyProgrammeDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudyProgrammeDAO) CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) StudentCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.StudentCourseResource) MonetaryAmount(fi.otavanopisto.pyramus.persistence.usertypes.MonetaryAmount) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) HashSet(java.util.HashSet) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) BasicCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.BasicCourseResourceDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) JSONRequestController(fi.otavanopisto.pyramus.framework.JSONRequestController) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) Role(fi.otavanopisto.pyramus.domainmodel.users.Role) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) ResourceDAO(fi.otavanopisto.pyramus.dao.resources.ResourceDAO) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) CourseComponentResource(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponentResource) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) DAOFactory(fi.otavanopisto.pyramus.dao.DAOFactory) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) CourseSignupStudyProgrammeDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudyProgrammeDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) CourseSignupStudyProgrammeDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudyProgrammeDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) HashSet(java.util.HashSet)

Aggregations

SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)1 JSONRequestContext (fi.internetix.smvc.controllers.JSONRequestContext)1 Messages (fi.otavanopisto.pyramus.I18N.Messages)1 DAOFactory (fi.otavanopisto.pyramus.dao.DAOFactory)1 CourseEducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO)1 CourseEducationTypeDAO (fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO)1 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)1 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)1 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)1 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)1 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)1 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)1 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)1 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)1 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)1 BasicCourseResourceDAO (fi.otavanopisto.pyramus.dao.courses.BasicCourseResourceDAO)1 CourseComponentDAO (fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO)1 CourseComponentResourceDAO (fi.otavanopisto.pyramus.dao.courses.CourseComponentResourceDAO)1 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)1 CourseDescriptionCategoryDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO)1