Search in sources :

Example 11 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class ModuleDAO method searchModules.

@SuppressWarnings("unchecked")
public SearchResult<Module> searchModules(int resultsPerPage, int page, String projectName, String name, String tags, String description, String componentName, String componentDescription, Long ownerId, Subject subject, EducationType educationType, EducationSubtype educationSubtype, Curriculum curriculum, boolean filterArchived) {
    int firstResult = page * resultsPerPage;
    StringBuilder queryBuilder = new StringBuilder();
    boolean hasName = !StringUtils.isBlank(name);
    boolean hasTags = !StringUtils.isBlank(tags);
    boolean hasDescription = !StringUtils.isBlank(description);
    boolean hasComponentName = !StringUtils.isBlank(componentName);
    boolean hasComponentDescription = !StringUtils.isBlank(componentDescription);
    boolean hasSubject = subject != null;
    boolean hasEduType = educationType != null;
    boolean hasEduSubtype = educationSubtype != null;
    boolean hasCurriculum = curriculum != null;
    if (hasName || hasTags || hasDescription || hasComponentName || hasComponentDescription || hasSubject || hasEduType || hasEduSubtype || hasCurriculum) {
        queryBuilder.append("+(");
        if (hasName)
            addTokenizedSearchCriteria(queryBuilder, "name", name, false);
        if (hasTags)
            addTokenizedSearchCriteria(queryBuilder, "tags.text", tags, false);
        if (hasDescription)
            addTokenizedSearchCriteria(queryBuilder, "description", description, false);
        if (hasComponentName)
            addTokenizedSearchCriteria(queryBuilder, "moduleComponents.name", componentName, false);
        if (hasComponentDescription)
            addTokenizedSearchCriteria(queryBuilder, "moduleComponents.description", componentDescription, false);
        if (hasSubject)
            addTokenizedSearchCriteria(queryBuilder, "subject.id", subject.getId().toString(), true);
        if (hasCurriculum)
            addTokenizedSearchCriteria(queryBuilder, "curriculums.id", curriculum.getId().toString(), true);
        if (hasEduType)
            addTokenizedSearchCriteria(queryBuilder, "courseEducationTypes.educationType.id", educationType.getId().toString(), true);
        if (hasEduSubtype)
            addTokenizedSearchCriteria(queryBuilder, "courseEducationTypes.courseEducationSubtypes.educationSubtype.id", educationSubtype.getId().toString(), true);
        queryBuilder.append(")");
    }
    // If project text is given, only include modules that are in project(s) having the given name
    // (only the first ten matching projects, though, to prevent the search from becoming too gigantic...)
    Set<Long> moduleIds = new HashSet<>();
    if (!StringUtils.isBlank(projectName)) {
        ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
        SearchResult<Project> searchResults = projectDAO.searchProjectsBasic(10, 0, projectName);
        List<Project> projects = searchResults.getResults();
        for (Project project : projects) {
            List<ProjectModule> projectModules = project.getProjectModules();
            for (ProjectModule projectModule : projectModules) {
                moduleIds.add(projectModule.getModule().getId());
            }
        }
        if (!moduleIds.isEmpty()) {
            queryBuilder.append(" +(");
            for (Long moduleId : moduleIds) {
                queryBuilder.append(" id: " + moduleId);
            }
            queryBuilder.append(")");
        } else {
            // Search condition by project name didn't yield any projects, so there cannot be any results
            return new SearchResult<>(0, 0, 0, 0, 0, new ArrayList<Module>());
        }
    }
    EntityManager entityManager = getEntityManager();
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    try {
        if (ownerId != null && ownerId > 0) {
            queryBuilder.append(" +creator.id: ").append(ownerId);
        }
        QueryParser parser = new QueryParser("", new StandardAnalyzer());
        String queryString = queryBuilder.toString();
        Query luceneQuery;
        if (StringUtils.isBlank(queryString)) {
            luceneQuery = new MatchAllDocsQuery();
        } else {
            luceneQuery = parser.parse(queryString);
        }
        FullTextQuery query = (FullTextQuery) fullTextEntityManager.createFullTextQuery(luceneQuery, Module.class).setSort(new Sort(new SortField[] { SortField.FIELD_SCORE, new SortField("nameSortable", SortField.Type.STRING) })).setFirstResult(firstResult).setMaxResults(resultsPerPage);
        if (filterArchived)
            query.enableFullTextFilter("ArchivedModule").setParameter("archived", Boolean.FALSE);
        int hits = query.getResultSize();
        int pages = hits / resultsPerPage;
        if (hits % resultsPerPage > 0) {
            pages++;
        }
        int lastResult = Math.min(firstResult + resultsPerPage, hits) - 1;
        return new SearchResult<>(page, pages, hits, firstResult, lastResult, query.getResultList());
    } catch (ParseException e) {
        throw new PersistenceException(e);
    }
}
Also used : Query(org.apache.lucene.search.Query) FullTextQuery(org.hibernate.search.jpa.FullTextQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) SortField(org.apache.lucene.search.SortField) Sort(org.apache.lucene.search.Sort) HashSet(java.util.HashSet) FullTextEntityManager(org.hibernate.search.jpa.FullTextEntityManager) SearchResult(fi.otavanopisto.pyramus.persistence.search.SearchResult) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) FullTextEntityManager(org.hibernate.search.jpa.FullTextEntityManager) EntityManager(javax.persistence.EntityManager) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) PersistenceException(javax.persistence.PersistenceException) ParseException(org.apache.lucene.queryparser.classic.ParseException) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) FullTextQuery(org.hibernate.search.jpa.FullTextQuery) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 12 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class ProjectModuleDAO method listProjectsByModule.

public List<Project> listProjectsByModule(Module module) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Project> criteria = criteriaBuilder.createQuery(Project.class);
    Root<ProjectModule> root = criteria.from(ProjectModule.class);
    criteria.select(root.get(ProjectModule_.project));
    criteria.where(criteriaBuilder.equal(root.get(ProjectModule_.module), module));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) EntityManager(javax.persistence.EntityManager) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule)

Example 13 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class EditEnrollmentViewController method createOrUpdateStudentProject.

private void createOrUpdateStudentProject(MatriculationExamAttendance examAttendance, Student student, MatriculationExamSubject subject, boolean mandatory, StaffMember loggedUser) {
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    MatriculationExamAttendanceDAO matriculationExamAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    MatriculationExamSubjectSettings subjectSettings = matriculationExamSubjectSettingsDAO.findBy(examAttendance.getEnrollment().getExam(), subject);
    if (subjectSettings == null || subjectSettings.getProject() == null) {
        // We cannot really do anything if the settings aren't in place
        return;
    }
    CourseOptionality projectOptionality = mandatory ? CourseOptionality.MANDATORY : CourseOptionality.OPTIONAL;
    Project project = subjectSettings.getProject();
    StudentProject studentProject;
    if (examAttendance != null && examAttendance.getProjectAssessment() != null && BooleanUtils.isFalse(examAttendance.getProjectAssessment().getArchived()) && examAttendance.getProjectAssessment().getStudentProject() != null && BooleanUtils.isFalse(examAttendance.getProjectAssessment().getStudentProject().getArchived())) {
        // Use the studentproject from the projectassessment if it exists
        studentProject = examAttendance.getProjectAssessment().getStudentProject();
    } else {
        // Resolve studentProject from the project in the settings
        List<StudentProject> studentProjects = studentProjectDAO.listBy(student, project, TSB.IGNORE);
        // Find first non-archived project
        studentProject = studentProjects.stream().filter(studentProject1 -> BooleanUtils.isFalse(studentProject1.getArchived())).findFirst().orElse(null);
        if (studentProject == null) {
            // No unarchived student project was found so try to use any other
            studentProject = studentProjects.isEmpty() ? null : studentProjects.get(0);
            if (studentProject != null && BooleanUtils.isTrue(studentProject.getArchived())) {
                studentProjectDAO.unarchive(studentProject);
            }
        }
    }
    if (studentProject == null) {
        // No matching student project was found so create a new one
        studentProject = studentProjectDAO.create(student, project.getName(), project.getDescription(), project.getOptionalStudiesLength().getUnits(), project.getOptionalStudiesLength().getUnit(), projectOptionality, loggedUser, project);
        Set<Tag> tags = new HashSet<>();
        for (Tag tag : project.getTags()) {
            tags.add(tag);
        }
        studentProjectDAO.updateTags(studentProject, tags);
        List<ProjectModule> projectModules = project.getProjectModules();
        for (ProjectModule projectModule : projectModules) {
            studentProjectModuleDAO.create(studentProject, projectModule.getModule(), null, CourseOptionality.getOptionality(projectModule.getOptionality().getValue()));
        }
    } else {
        studentProject = studentProjectDAO.updateOptionality(studentProject, projectOptionality);
    }
    MatriculationExam matriculationExam = examAttendance.getEnrollment().getExam();
    if (matriculationExam != null && matriculationExam.getSignupGrade() != null && subjectSettings.getExamDate() != null && examAttendance.getProjectAssessment() == null) {
        // Add the exam date
        ProjectAssessment projectAssessment = projectAssessmentDAO.create(studentProject, loggedUser, matriculationExam.getSignupGrade(), subjectSettings.getExamDate(), "");
        // Link the project assessment to this exam atten dance
        matriculationExamAttendanceDAO.updateProjectAssessment(examAttendance, projectAssessment);
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Arrays(java.util.Arrays) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) MatriculationExamAttendanceFunding(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding) SchoolType(fi.otavanopisto.pyramus.domainmodel.matriculation.SchoolType) DegreeType(fi.otavanopisto.pyramus.domainmodel.matriculation.DegreeType) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) StringUtils(org.apache.commons.lang3.StringUtils) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamGrade(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamGrade) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BooleanUtils(org.apache.commons.lang.BooleanUtils) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) MatriculationExamAttendanceStatus(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceStatus) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) MatriculationExamEnrollmentState(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState) Severity(fi.internetix.smvc.Severity) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) UserRole(fi.otavanopisto.pyramus.framework.UserRole) MatriculationExamEnrollmentDegreeStructure(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentDegreeStructure) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TSB(fi.otavanopisto.pyramus.domainmodel.TSB) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) PageRequestContext(fi.internetix.smvc.controllers.PageRequestContext) PyramusViewController(fi.otavanopisto.pyramus.framework.PyramusViewController) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance) List(java.util.List) DAOFactory(fi.otavanopisto.pyramus.dao.DAOFactory) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) HashSet(java.util.HashSet)

Example 14 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class MatriculationExamSettingsViewController method doPost.

private void doPost(PageRequestContext pageRequestContext) {
    MatriculationExamDAO dao = DAOFactory.getInstance().getMatriculationExamDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    Date starts = DateUtils.startOfDay(pageRequestContext.getDate("starts"));
    Date ends = DateUtils.endOfDay(pageRequestContext.getDate("ends"));
    boolean enrollmentActive = Boolean.TRUE.equals(pageRequestContext.getBoolean("enrollmentActive"));
    Long signupGradeId = pageRequestContext.getLong("signupGradeId");
    Grade signupGrade = signupGradeId != null ? gradeDAO.findById(signupGradeId) : null;
    Integer examYear = pageRequestContext.getInteger("examYear");
    MatriculationExamTerm examTerm = StringUtils.isNotBlank(pageRequestContext.getString("examTerm")) ? MatriculationExamTerm.valueOf(pageRequestContext.getString("examTerm")) : null;
    MatriculationExam exam;
    if ("new".equals(pageRequestContext.getString("examId"))) {
        // Create new
        exam = dao.create(starts, ends, signupGrade, examYear, examTerm, enrollmentActive);
    } else {
        Long examId = pageRequestContext.getLong("examId");
        exam = dao.findById(examId);
        exam = dao.update(exam, starts, ends, signupGrade, examYear, examTerm, enrollmentActive);
    }
    Long subjectTableRowCount = pageRequestContext.getLong("subjectSettingsTable.rowCount");
    for (int i = 0; i < subjectTableRowCount; i++) {
        String colPrefix = "subjectSettingsTable." + i;
        MatriculationExamSubject subject = MatriculationExamSubject.valueOf(pageRequestContext.getString(colPrefix + ".subjectCode"));
        Long projectId = pageRequestContext.getLong(colPrefix + ".projectId");
        Project project = projectId != null ? projectDAO.findById(projectId) : null;
        Date examDate = pageRequestContext.getDate(colPrefix + ".examDate");
        MatriculationExamSubjectSettings subjectSettings = matriculationExamSubjectSettingsDAO.findBy(exam, subject);
        if (subjectSettings == null) {
            matriculationExamSubjectSettingsDAO.create(exam, subject, project, examDate);
        } else {
            matriculationExamSubjectSettingsDAO.update(subjectSettings, project, examDate);
        }
    }
    pageRequestContext.setRedirectURL(String.format("%s/matriculation/settings.page?examId=%d", pageRequestContext.getRequest().getContextPath(), exam.getId()));
}
Also used : MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) Date(java.util.Date) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 15 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class SelectProjectDialogViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    List<Project> projects = projectDAO.listUnarchived();
    Collections.sort(projects, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("projects", projects);
    pageRequestContext.setIncludeJSP("/templates/projects/selectprojectdialog.jsp");
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Aggregations

Project (fi.otavanopisto.pyramus.domainmodel.projects.Project)25 ProjectDAO (fi.otavanopisto.pyramus.dao.projects.ProjectDAO)14 ProjectModule (fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule)12 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)8 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)8 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)7 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)7 HashSet (java.util.HashSet)7 Path (javax.ws.rs.Path)7 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)6 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)4 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)4 StudentProject (fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)4 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)4 ArrayList (java.util.ArrayList)4 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)3 MatriculationExamSubjectSettingsDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO)3 StudentProjectModuleDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO)3 User (fi.otavanopisto.pyramus.domainmodel.users.User)3 ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)2