use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.
the class CreateStudentProjectJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
User loggedUser = userDAO.findById(jsonRequestContext.getLoggedUserId());
Long studentId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("studentId"));
Long projectId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("projectId"));
String tagsText = jsonRequestContext.getString("tags");
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);
Project project = projectId == -1 ? null : projectDAO.findById(projectId);
String name;
String description;
EducationalTimeUnit unit;
Double units;
if (project == null) {
name = Messages.getInstance().getText(jsonRequestContext.getRequest().getLocale(), "projects.createStudentProject.newStudentProject");
description = null;
unit = defaultsDAO.getDefaults().getBaseTimeUnit();
units = 0.0;
} else {
name = project.getName();
description = project.getDescription();
unit = project.getOptionalStudiesLength().getUnit();
units = project.getOptionalStudiesLength().getUnits();
}
StudentProject studentProject = studentProjectDAO.create(student, name, description, units, unit, null, loggedUser, project);
studentProjectDAO.updateTags(studentProject, tagEntities);
if (project != null) {
List<ProjectModule> projectModules = project.getProjectModules();
for (ProjectModule projectModule : projectModules) {
studentProjectModuleDAO.create(studentProject, projectModule.getModule(), null, CourseOptionality.getOptionality(projectModule.getOptionality().getValue()));
}
}
String redirectURL = jsonRequestContext.getRequest().getContextPath() + "/projects/editstudentproject.page?studentproject=" + studentProject.getId();
String refererAnchor = jsonRequestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
jsonRequestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.
the class ListStudentProjectsJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
Long projectId = requestContext.getLong("project");
Project project = projectDAO.findById(projectId);
Integer page = requestContext.getInteger("page");
page = page != null ? page : 0;
Integer maxResults = requestContext.getInteger("maxResults");
maxResults = maxResults != null ? maxResults : 25;
int firstResult = page * maxResults;
long numStudentProjectsTotal = studentProjectDAO.countByProject(project);
int numPages = (int) Math.ceil((double) numStudentProjectsTotal / maxResults);
List<StudentProject> studentProjectsByProjectPage = studentProjectDAO.listByProject(project, firstResult, maxResults);
int resultsCount = studentProjectsByProjectPage.size();
JSONArray studentProjectsJSON = new JSONArray();
for (StudentProject sp : studentProjectsByProjectPage) {
StudentProjectBean bean = beanify(sp, courseDAO, courseStudentDAO, transferCreditDAO, courseAssessmentDAO, projectAssessmentDAO);
JSONObject spJSON = new JSONObject();
JSONArray spDates = new JSONArray();
StringBuilder gradeText = new StringBuilder();
for (ProjectAssessment assessment : bean.getAssessments()) {
spDates.add(assessment.getDate().getTime());
if (gradeText.length() > 0)
gradeText.append(", ");
if (assessment.getGrade() != null)
gradeText.append(assessment.getGrade().getName());
else
gradeText.append("-");
}
spJSON.put("personId", bean.getStudentProject().getStudent().getPerson().getId());
spJSON.put("studentProjectId", bean.getStudentProject().getId());
spJSON.put("studentName", bean.getStudentProject().getStudent().getLastName() + ", " + bean.getStudentProject().getStudent().getFirstName());
spJSON.put("studyProgrammeName", bean.getStudentProject().getStudent().getStudyProgramme().getName());
spJSON.put("optionality", bean.getStudentProject().getOptionality());
spJSON.put("dates", spDates);
spJSON.put("grade", gradeText.toString());
spJSON.put("passedMandatory", bean.getPassedMandatoryModuleCount() + "/" + bean.getMandatoryModuleCount());
spJSON.put("passedOptional", bean.getPassedOptionalModuleCount() + "/" + bean.getOptionalModuleCount());
studentProjectsJSON.add(spJSON);
}
String statusMessage;
Locale locale = requestContext.getRequest().getLocale();
if (studentProjectsByProjectPage.size() > 0) {
statusMessage = Messages.getInstance().getText(locale, "projects.viewProject.studentProjects.searchStatus", new Object[] { firstResult + 1, firstResult + resultsCount, numStudentProjectsTotal });
} else {
statusMessage = Messages.getInstance().getText(locale, "projects.viewProject.studentProjects.searchStatusNoMatches");
}
requestContext.addResponseParameter("studentProjects", studentProjectsJSON);
requestContext.addResponseParameter("page", page);
requestContext.addResponseParameter("pages", numPages);
requestContext.addResponseParameter("statusMessage", statusMessage);
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.
the class SearchProjectsJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
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;
}
// Gather the search terms
String text = requestContext.getRequest().getParameter("text");
// Search via the DAO object
SearchResult<Project> searchResult = projectDAO.searchProjectsBasic(resultsPerPage, page, text);
List<Map<String, Object>> results = new ArrayList<>();
List<Project> projects = searchResult.getResults();
for (Project project : projects) {
Map<String, Object> projectInfo = new HashMap<>();
projectInfo.put("id", project.getId());
projectInfo.put("name", project.getName());
results.add(projectInfo);
}
String statusMessage;
Locale locale = requestContext.getRequest().getLocale();
if (searchResult.getTotalHitCount() > 0) {
statusMessage = Messages.getInstance().getText(locale, "projects.searchProjects.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
} else {
statusMessage = Messages.getInstance().getText(locale, "projects.searchProjects.searchStatusNoMatches");
}
requestContext.addResponseParameter("results", results);
requestContext.addResponseParameter("statusMessage", statusMessage);
requestContext.addResponseParameter("pages", searchResult.getPages());
requestContext.addResponseParameter("page", searchResult.getPage());
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.
the class EditProjectViewController 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) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
Long projectId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("project"));
Project project = projectDAO.findById(projectId);
StringBuilder tagsBuilder = new StringBuilder();
Iterator<Tag> tagIterator = project.getTags().iterator();
while (tagIterator.hasNext()) {
Tag tag = tagIterator.next();
tagsBuilder.append(tag.getText());
if (tagIterator.hasNext())
tagsBuilder.append(' ');
}
List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
this.setJsDataVariable(pageRequestContext, "projectId", project.getId().toString());
pageRequestContext.getRequest().setAttribute("project", project);
pageRequestContext.getRequest().setAttribute("optionalStudiesLengthTimeUnits", educationalTimeUnits);
pageRequestContext.getRequest().setAttribute("users", userDAO.listAll());
pageRequestContext.setIncludeJSP("/templates/projects/editproject.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.
the class MatriculationExamSettingsViewController method doGet.
private void doGet(PageRequestContext pageRequestContext) {
MatriculationExamDAO dao = DAOFactory.getInstance().getMatriculationExamDAO();
MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
MatriculationExam exam;
if ("new".equals(pageRequestContext.getString("examId"))) {
pageRequestContext.getRequest().setAttribute("examId", pageRequestContext.getString("examId"));
exam = null;
} else {
Long examId = pageRequestContext.getLong("examId");
exam = dao.findById(examId);
pageRequestContext.getRequest().setAttribute("examId", examId);
}
pageRequestContext.getRequest().setAttribute("exam", exam);
JSONArray subjectsJSON = new JSONArray();
List<MatriculationExamSubject> matriculationExamSubjects = Arrays.asList(MatriculationExamSubject.values());
matriculationExamSubjects.sort(Comparator.comparing(MatriculationExamSubject::toString));
for (MatriculationExamSubject subject : matriculationExamSubjects) {
MatriculationExamSubjectSettings subset = exam != null ? matriculationExamSubjectSettingsDAO.findBy(exam, subject) : null;
JSONObject subjectJSON = new JSONObject();
subjectJSON.put("subjectCode", subject);
subjectJSON.put("projectId", (subset != null && subset.getProject() != null) ? subset.getProject().getId() : null);
subjectJSON.put("examDate", (subset != null && subset.getExamDate() != null) ? subset.getExamDate().getTime() : null);
subjectsJSON.add(subjectJSON);
}
setJsDataVariable(pageRequestContext, "subjectData", subjectsJSON.toString());
List<Project> projects = projectDAO.listUnarchived();
projects.sort(Comparator.comparing(Project::getName));
JSONArray projectsJSON = new JSONArray();
for (Project project : projects) {
JSONObject projectJSON = new JSONObject();
projectJSON.put("id", project.getId());
projectJSON.put("name", project.getName());
projectsJSON.add(projectJSON);
}
setJsDataVariable(pageRequestContext, "projectData", projectsJSON.toString());
pageRequestContext.setIncludeJSP("/templates/matriculation/management-enrollment-settings.jsp");
}
Aggregations