Search in sources :

Example 1 with Course

use of fi.otavanopisto.pyramus.domainmodel.courses.Course in project pyramus by otavanopisto.

the class EnvironmentPermissionResolver method hasPermission.

@Override
public boolean hasPermission(Permission permission, ContextReference contextReference, User user) {
    fi.otavanopisto.pyramus.domainmodel.users.User userEntity = getUser(user);
    if (userEntity == null) {
        return hasEveryonePermission(permission, contextReference);
    }
    boolean allowed = false;
    if (PermissionScope.COURSE.equals(permission.getScope()) && (contextReference != null)) {
        Course course = resolveCourse(contextReference);
        if (course != null) {
            allowed = hasCourseAccess(course, userEntity, permission);
        }
    }
    Role environmentRole = userEntity.getRole();
    allowed = allowed || environmentUserRolePermissionDAO.hasEnvironmentPermissionAccess(environmentRole, permission) || hasEveryonePermission(permission, contextReference);
    PyramusPermissionCollection collection = findCollection(permission.getName());
    try {
        PermissionFeature[] features = collection.listPermissionFeatures(permission.getName());
        if (features != null) {
            for (PermissionFeature feature : features) {
                Instance<PermissionFeatureHandler> instance = featureHandlers.select(new PermissionFeatureLiteral(feature.value()));
                if (!instance.isUnsatisfied()) {
                    PermissionFeatureHandler permissionFeatureHandler = instance.get();
                    allowed = permissionFeatureHandler.hasPermission(permission.getName(), userEntity, contextReference, allowed);
                } else
                    logger.log(Level.SEVERE, String.format("Unsatisfied permission feature %s", feature.value()));
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, String.format("Could not list permission features for permission %s", permission), e);
    }
    return allowed;
}
Also used : PermissionFeatureLiteral(fi.otavanopisto.security.PermissionFeatureLiteral) PermissionFeatureHandler(fi.otavanopisto.security.PermissionFeatureHandler) Role(fi.otavanopisto.pyramus.domainmodel.users.Role) PermissionFeature(fi.otavanopisto.security.PermissionFeature) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 2 with Course

use of fi.otavanopisto.pyramus.domainmodel.courses.Course in project pyramus by otavanopisto.

the class EditStudentProjectJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Defaults defaults = defaultsDAO.getDefaults();
    // Project
    Long studentProjectId = jsonRequestContext.getLong("studentProject");
    StudentProject studentProject = studentProjectDAO.findById(studentProjectId);
    // Version check
    Long version = jsonRequestContext.getLong("version");
    if (!studentProject.getVersion().equals(version))
        throw new StaleObjectStateException(StudentProject.class.getName(), studentProject.getId());
    String name = jsonRequestContext.getString("name");
    String description = jsonRequestContext.getString("description");
    StaffMember staffMember = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
    Long optionalStudiesLengthTimeUnitId = jsonRequestContext.getLong("optionalStudiesLengthTimeUnit");
    EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
    Double optionalStudiesLength = jsonRequestContext.getDouble("optionalStudiesLength");
    String tagsText = jsonRequestContext.getString("tags");
    Long studentId = jsonRequestContext.getLong("student");
    CourseOptionality projectOptionality = (CourseOptionality) jsonRequestContext.getEnum("projectOptionality", CourseOptionality.class);
    Set<Tag> tagEntities = new HashSet<>();
    if (!StringUtils.isBlank(tagsText)) {
        List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
        for (String tag : tags) {
            if (!StringUtils.isBlank(tag)) {
                Tag tagEntity = tagDAO.findByText(tag.trim());
                if (tagEntity == null)
                    tagEntity = tagDAO.create(tag);
                tagEntities.add(tagEntity);
            }
        }
    }
    Student student = studentDAO.findById(studentId);
    if (!studentProject.getStudent().equals(student)) {
        studentProjectDAO.updateStudent(studentProject, student, staffMember);
    }
    studentProjectDAO.update(studentProject, name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, projectOptionality, staffMember);
    // Tags
    studentProjectDAO.updateTags(studentProject, tagEntities);
    // ProjectAssessments
    int rowCount = jsonRequestContext.getInteger("assessmentsTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "assessmentsTable." + i;
        Long assessmentModified = jsonRequestContext.getLong(colPrefix + ".modified");
        if ((assessmentModified != null) && (assessmentModified.intValue() == 1)) {
            Long assessmentId = jsonRequestContext.getLong(colPrefix + ".assessmentId");
            ProjectAssessment projectAssessment = ((assessmentId != null) && (assessmentId.intValue() != -1)) ? projectAssessmentDAO.findById(assessmentId) : null;
            Long assessmentArchived = jsonRequestContext.getLong(colPrefix + ".deleted");
            if ((assessmentArchived != null) && (assessmentArchived.intValue() == 1)) {
                if (projectAssessment != null)
                    projectAssessmentDAO.archive(projectAssessment);
                else
                    throw new SmvcRuntimeException(PyramusStatusCode.OK, "Assessment marked for delete does not exist.");
            } else {
                Date assessmentDate = jsonRequestContext.getDate(colPrefix + ".date");
                Long assessmentGradeId = jsonRequestContext.getLong(colPrefix + ".grade");
                Grade grade = assessmentGradeId != null ? gradeDAO.findById(assessmentGradeId) : null;
                String verbalAssessment = projectAssessment != null ? projectAssessment.getVerbalAssessment() : null;
                Long verbalAssessmentModified = jsonRequestContext.getLong(colPrefix + ".verbalModified");
                if ((verbalAssessmentModified != null) && (verbalAssessmentModified.intValue() == 1))
                    verbalAssessment = jsonRequestContext.getString(colPrefix + ".verbalAssessment");
                if (projectAssessment == null) {
                    projectAssessmentDAO.create(studentProject, staffMember, grade, assessmentDate, verbalAssessment);
                } else {
                    projectAssessmentDAO.update(projectAssessment, staffMember, grade, assessmentDate, verbalAssessment);
                }
            }
        }
    }
    // Student project modules
    Set<Long> existingModuleIds = new HashSet<>();
    rowCount = jsonRequestContext.getInteger("modulesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "modulesTable." + i;
        Long studentProjectModuleId = jsonRequestContext.getLong(colPrefix + ".studentProjectModuleId");
        CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
        Long studyTermId = jsonRequestContext.getLong(colPrefix + ".academicTerm");
        AcademicTerm academicTerm = studyTermId == null ? null : academicTermDAO.findById(studyTermId);
        if (studentProjectModuleId == -1) {
            Long moduleId = jsonRequestContext.getLong(colPrefix + ".moduleId");
            Module module = moduleDAO.findById(moduleId);
            studentProjectModuleId = studentProjectModuleDAO.create(studentProject, module, academicTerm, optionality).getId();
        } else {
            studentProjectModuleDAO.update(studentProjectModuleDAO.findById(studentProjectModuleId), academicTerm, optionality);
        }
        existingModuleIds.add(studentProjectModuleId);
    }
    // Removed Student project modules
    List<StudentProjectModule> studentProjectModules = studentProjectModuleDAO.listByStudentProject(studentProject);
    for (StudentProjectModule studentProjectModule : studentProjectModules) {
        if (!existingModuleIds.contains(studentProjectModule.getId())) {
            studentProjectModuleDAO.delete(studentProjectModule);
        }
    }
    // Student project courses
    rowCount = jsonRequestContext.getInteger("coursesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "coursesTable." + i;
        Long courseId = jsonRequestContext.getLong(colPrefix + ".courseId");
        CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
        Course course = courseId == -1 ? null : courseDAO.findById(courseId);
        CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, studentProject.getStudent());
        if (courseStudent == null) {
            CourseEnrolmentType courseEnrolmentType = defaults.getInitialCourseEnrolmentType();
            CourseParticipationType participationType = defaults.getInitialCourseParticipationType();
            Date enrolmentDate = new Date(System.currentTimeMillis());
            Boolean lodging = Boolean.FALSE;
            String organization = null;
            String additionalInfo = null;
            Room room = null;
            BigDecimal lodgingFee = null;
            Currency lodgingFeeCurrency = null;
            BigDecimal reservationFee = null;
            Currency reservationFeeCurrency = null;
            try {
                courseStudent = courseStudentDAO.create(course, studentProject.getStudent(), courseEnrolmentType, participationType, enrolmentDate, lodging, optionality, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
            } catch (DuplicateCourseStudentException dcse) {
                Locale locale = jsonRequestContext.getRequest().getLocale();
                throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
            }
        } else {
            courseStudentDAO.updateOptionality(courseStudent, optionality);
        }
    }
    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Also used : Locale(java.util.Locale) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Currency(java.util.Currency) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) HashSet(java.util.HashSet) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StaleObjectStateException(org.hibernate.StaleObjectStateException) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)

Example 3 with Course

use of fi.otavanopisto.pyramus.domainmodel.courses.Course in project pyramus by otavanopisto.

the class SearchStudentProjectCoursesJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
    if (resultsPerPage == null) {
        resultsPerPage = 10;
    }
    Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
    if (page == null) {
        page = 0;
    }
    String name = requestContext.getString("name");
    String tags = requestContext.getString("tags");
    SearchResult<Course> searchResult = courseDAO.searchCourses(resultsPerPage, page, name, tags, null, null, null, null, null, null, null, true, CourseTemplateFilter.LIST_COURSES);
    List<Map<String, Object>> results = new ArrayList<>();
    List<Course> courses = searchResult.getResults();
    for (Course course : courses) {
        Long studentCount = courseStudentDAO.countByCourse(course);
        Long maxStudentCount = course.getMaxParticipantCount();
        Map<String, Object> courseInfo = new HashMap<>();
        courseInfo.put("id", course.getId());
        courseInfo.put("name", course.getName());
        courseInfo.put("nameExtension", course.getNameExtension());
        courseInfo.put("moduleId", course.getModule().getId());
        if (course.getBeginDate() != null)
            courseInfo.put("beginDate", course.getBeginDate().getTime());
        if (course.getEndDate() != null)
            courseInfo.put("endDate", course.getEndDate().getTime());
        courseInfo.put("studentCount", studentCount);
        courseInfo.put("maxStudentCount", maxStudentCount);
        results.add(courseInfo);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (searchResult.getTotalHitCount() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "projects.searchStudentProjectCoursesDialog.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "projects.searchStudentProjectCoursesDialog.searchStatusNoMatches");
    }
    requestContext.addResponseParameter("results", results);
    requestContext.addResponseParameter("statusMessage", statusMessage);
    requestContext.addResponseParameter("pages", searchResult.getPages());
    requestContext.addResponseParameter("page", searchResult.getPage());
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) ArrayList(java.util.ArrayList) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Course

use of fi.otavanopisto.pyramus.domainmodel.courses.Course in project pyramus by otavanopisto.

the class EditCourseJSONRequestController method processSignupStudentGroups.

private void processSignupStudentGroups(JSONRequestContext requestContext, Course course, StaffMember loggedUser) {
    CourseSignupStudentGroupDAO courseSignupStudentGroupDAO = DAOFactory.getInstance().getCourseSignupStudentGroupDAO();
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    List<CourseSignupStudentGroup> signupStudentGroups = courseSignupStudentGroupDAO.listByCourse(course);
    Integer studentGroupsRowCount = requestContext.getInteger("signupStudentGroupsTable.rowCount");
    if (studentGroupsRowCount != null) {
        Set<Long> studentGroupIdsPresent = new HashSet<>();
        for (int i = 0; i < studentGroupsRowCount; i++) {
            Long studentGroupId = requestContext.getLong(String.format("signupStudentGroupsTable.%d.studentGroupId", i));
            if (studentGroupId != null) {
                studentGroupIdsPresent.add(studentGroupId);
            }
        }
        // Create missing groups
        studentGroupIdsPresent.forEach(studentGroupId -> {
            if (signupStudentGroups.stream().noneMatch(signupStudentGroup -> Objects.equals(signupStudentGroup.getStudentGroup().getId(), studentGroupId))) {
                StudentGroup studentGroup = studentGroupDAO.findById(studentGroupId);
                if ((studentGroup != null) && UserUtils.canAccessOrganization(loggedUser, studentGroup.getOrganization())) {
                    courseSignupStudentGroupDAO.create(course, studentGroup);
                } else {
                    throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
                }
            }
        });
        // Remove groups that don't exist anymore
        signupStudentGroups.stream().filter(signupStudentGroup -> !studentGroupIdsPresent.contains(signupStudentGroup.getStudentGroup().getId())).forEach(signupStudentGroup -> {
            if (UserUtils.canAccessOrganization(loggedUser, signupStudentGroup.getStudentGroup().getOrganization())) {
                courseSignupStudentGroupDAO.delete(signupStudentGroup);
            } 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) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) CourseSignupStudentGroupDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudentGroupDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) CourseSignupStudentGroupDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudentGroupDAO) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) HashSet(java.util.HashSet)

Example 5 with Course

use of fi.otavanopisto.pyramus.domainmodel.courses.Course in project pyramus by otavanopisto.

the class SearchCoursesJSONRequestController method process.

/**
 * Processes the request to search courses.
 * The request should contain the either following parameters (for simple search):
 * <dl>
 *   <dt><code>text</code></dt>
 *   <dd>The text to search for</dd>
 * </dl>
 * or the following parameters (for advanced search):
 * <dl>
 *   <dt><code>name</code></dt>
 *   <dd>Course name to find.</dd>
 *   <dt><code>tags</code></dt>
 *   <dd>Tags to find.</dd>
 *   <dt><code>nameExtension</code></dt>
 *   <dd>The name extension to find.</dd>
 *   <dt><code>description</code></dt>
 *   <dd>The description to find.</dd>
 *   <dt><code>state</code></dt>
 *   <dd>The ID of the course state to find.</dd>
 *   <dt><code>subject</code></dt>
 *   <dd>The ID of the subject to find.</dd>
 *   <dt><code>timeframeStart</code></dt>
 *   <dd>The start of the timeframe to find.</dd>
 *   <dt><code>timeframeEnd</code></dt>
 *   <dd>The end of the timeframe to find.</dd>
 *   <dt><code>educationType</code></dt>
 *   <dd>The education type to find.</dd>
 *   <dt><code>educationSubtype</code></dt>
 *   <dd>The education subtype to find.</dd>
 *   <dt><code>timeframeMode</code></dt>
 *   <dd>The mode of the timeframe. Can be <code>INCLUSIVE</code>
 *   or <code>EXCLUSIVE</code>.</dd>
 * </dl>
 *
 * @param jsonRequestContext The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    // Determine the number of results shown per page. If not defined, default to ten results per page
    Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
    if (resultsPerPage == null)
        resultsPerPage = 10;
    // Determine the result page to be shown. If not defined, default to the first page
    Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
    if (page == null) {
        page = 0;
    }
    SearchResult<Course> searchResult;
    if ("advanced".equals(requestContext.getRequest().getParameter("activeTab"))) {
        String name = requestContext.getString("name");
        String tags = requestContext.getString("tags");
        if (!StringUtils.isBlank(tags))
            tags = tags.replace(',', ' ');
        String nameExtension = requestContext.getString("nameExtension");
        String description = requestContext.getString("description");
        CourseState courseState = null;
        Long courseStateId = requestContext.getLong("state");
        if (courseStateId != null) {
            courseState = courseStateDAO.findById(courseStateId);
        }
        Subject subject = null;
        Long subjectId = requestContext.getLong("subject");
        if (subjectId != null) {
            subject = subjectDAO.findById(subjectId);
        }
        Date timeframeStart = null;
        String value = requestContext.getString("timeframeStart");
        if (NumberUtils.isNumber(value)) {
            timeframeStart = new Date(NumberUtils.createLong(value));
        }
        Date timeframeEnd = null;
        value = requestContext.getString("timeframeEnd");
        if (NumberUtils.isNumber(value)) {
            timeframeEnd = new Date(NumberUtils.createLong(value));
        }
        EducationType educationType = null;
        Long educationTypeId = requestContext.getLong("educationType");
        if (educationTypeId != null) {
            educationType = educationTypeDAO.findById(educationTypeId);
        }
        EducationSubtype educationSubtype = null;
        Long educationSubtypeId = requestContext.getLong("educationSubtype");
        if (educationSubtypeId != null) {
            educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
        }
        CourseTemplateFilter courseTemplateFilter = (CourseTemplateFilter) requestContext.getEnum("courseTemplateFilter", CourseTemplateFilter.class);
        SearchTimeFilterMode timeFilterMode = (SearchTimeFilterMode) requestContext.getEnum("timeframeMode", SearchTimeFilterMode.class);
        searchResult = courseDAO.searchCourses(resultsPerPage, page, name, tags, nameExtension, description, courseState, subject, timeFilterMode, timeframeStart, timeframeEnd, educationType, educationSubtype, true, courseTemplateFilter);
    } else {
        String text = requestContext.getRequest().getParameter("text");
        searchResult = courseDAO.searchCoursesBasic(resultsPerPage, page, text, true);
    }
    List<Map<String, Object>> results = new ArrayList<>();
    List<Course> courses = searchResult.getResults();
    for (Course course : courses) {
        Map<String, Object> courseInfo = new HashMap<>();
        courseInfo.put("id", course.getId());
        courseInfo.put("name", course.getName());
        courseInfo.put("nameExtension", course.getNameExtension());
        if (course.getBeginDate() != null) {
            courseInfo.put("beginDate", course.getBeginDate().getTime());
        }
        if (course.getEndDate() != null) {
            courseInfo.put("endDate", course.getEndDate().getTime());
        }
        results.add(courseInfo);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (searchResult.getTotalHitCount() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "courses.searchCourses.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "courses.searchCourses.searchStatusNoMatches");
    }
    requestContext.addResponseParameter("results", results);
    requestContext.addResponseParameter("statusMessage", statusMessage);
    requestContext.addResponseParameter("pages", searchResult.getPages());
    requestContext.addResponseParameter("page", searchResult.getPage());
}
Also used : Locale(java.util.Locale) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) ArrayList(java.util.ArrayList) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) SearchTimeFilterMode(fi.otavanopisto.pyramus.persistence.search.SearchTimeFilterMode) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) Date(java.util.Date) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseTemplateFilter(fi.otavanopisto.pyramus.dao.courses.CourseDAO.CourseTemplateFilter) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)111 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)50 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)44 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)44 Path (javax.ws.rs.Path)44 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)34 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)25 GET (javax.ws.rs.GET)23 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)20 Date (java.util.Date)20 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)18 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)18 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)16 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)14 EntityManager (javax.persistence.EntityManager)14 CourseParticipationType (fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)13 CourseAssessmentRequest (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)13 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)13