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);
}
}
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();
}
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);
}
}
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()));
}
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");
}
Aggregations