use of fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment 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));
}
use of fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment in project pyramus by otavanopisto.
the class ListStudentProjectsJSONRequestController method beanify.
private StudentProjectBean beanify(StudentProject studentProject, CourseDAO courseDAO, CourseStudentDAO courseStudentDAO, TransferCreditDAO transferCreditDAO, CourseAssessmentDAO courseAssessmentDAO, ProjectAssessmentDAO projectAssessmentDAO) {
int mandatoryModuleCount = 0;
int optionalModuleCount = 0;
int passedMandatoryModuleCount = 0;
int passedOptionalModuleCount = 0;
/**
* Go through project modules to
* a) count mandatory/optional modules
* b) count mandatory/optional modules that have passing grade on them
* c) create beans to be passed to jsp
*/
List<TransferCredit> transferCreditsByStudent = transferCreditDAO.listByStudent(studentProject.getStudent());
for (StudentProjectModule studentProjectModule : studentProject.getStudentProjectModules()) {
boolean hasPassingGrade = false;
List<CourseStudent> courseStudentList = courseStudentDAO.listByModuleAndStudent(studentProjectModule.getModule(), studentProject.getStudent());
// Find out if there is a course that has passing grade for the module
if (courseStudentList != null) {
for (CourseStudent cs : courseStudentList) {
CourseAssessment ca = courseAssessmentDAO.findLatestByCourseStudentAndArchived(cs, Boolean.FALSE);
if (ca != null && ca.getGrade() != null && ca.getGrade().getPassingGrade()) {
hasPassingGrade = true;
break;
}
}
}
if (!hasPassingGrade) {
if ((studentProjectModule.getModule().getCourseNumber() != null) && (studentProjectModule.getModule().getCourseNumber() != -1) && (studentProjectModule.getModule().getSubject() != null)) {
for (TransferCredit tc : transferCreditsByStudent) {
if ((tc.getCourseNumber() != null) && (tc.getCourseNumber() != -1) && (tc.getSubject() != null)) {
if (tc.getCourseNumber().equals(studentProjectModule.getModule().getCourseNumber()) && tc.getSubject().equals(studentProjectModule.getModule().getSubject())) {
if (tc.getGrade() != null && tc.getGrade().getPassingGrade()) {
hasPassingGrade = true;
break;
}
}
}
}
}
}
if (studentProjectModule.getOptionality() == CourseOptionality.MANDATORY) {
mandatoryModuleCount++;
if (hasPassingGrade)
passedMandatoryModuleCount++;
} else if (studentProjectModule.getOptionality() == CourseOptionality.OPTIONAL) {
optionalModuleCount++;
if (hasPassingGrade)
passedOptionalModuleCount++;
}
}
List<ProjectAssessment> projectAssessments = projectAssessmentDAO.listByProjectAndArchived(studentProject, Boolean.FALSE);
Collections.sort(projectAssessments, new Comparator<ProjectAssessment>() {
@Override
public int compare(ProjectAssessment o1, ProjectAssessment o2) {
return o2.getDate().compareTo(o1.getDate());
}
});
return new StudentProjectBean(studentProject, mandatoryModuleCount, optionalModuleCount, passedMandatoryModuleCount, passedOptionalModuleCount, projectAssessments);
}
use of fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment in project pyramus by otavanopisto.
the class ProjectAssessmentDAO method create.
public ProjectAssessment create(StudentProject studentProject, StaffMember assessingUser, Grade grade, Date date, String verbalAssessment) {
ProjectAssessment projectAssessment = new ProjectAssessment();
projectAssessment.setAssessor(assessingUser);
projectAssessment.setStudentProject(studentProject);
projectAssessment.setDate(date);
projectAssessment.setGrade(grade);
projectAssessment.setVerbalAssessment(verbalAssessment);
projectAssessment.setArchived(Boolean.FALSE);
return persist(projectAssessment);
}
use of fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment 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.grading.ProjectAssessment 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);
}
Aggregations