use of fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO in project pyramus by otavanopisto.
the class GradingService method getCourseAssessmentByCourseStudentId.
public CourseAssessmentEntity getCourseAssessmentByCourseStudentId(@WebParam(name = "courseStudentId") Long courseStudentId) {
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
CourseStudent courseStudent = courseStudentDAO.findById(courseStudentId);
CourseAssessment courseAssessment = courseAssessmentDAO.findLatestByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
return EntityFactoryVault.buildFromDomainObject(courseAssessment);
}
use of fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO in project pyramus by otavanopisto.
the class EditStudentViewController method process.
public void process(PageRequestContext pageRequestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StudentActivityTypeDAO studentActivityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
StudentEducationalLevelDAO studentEducationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
StudentExaminationTypeDAO studentExaminationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
UserVariableKeyDAO userVariableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
PersonVariableKeyDAO personVariableKeyDAO = DAOFactory.getInstance().getPersonVariableKeyDAO();
PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
Locale locale = pageRequestContext.getRequest().getLocale();
User loggedUser = userDAO.findById(pageRequestContext.getLoggedUserId());
Long personId = pageRequestContext.getLong("person");
Person person = personDAO.findById(personId);
List<Student> students = UserUtils.canAccessAllOrganizations(loggedUser) ? studentDAO.listByPerson(person) : studentDAO.listByPersonAndOrganization(person, loggedUser.getOrganization());
Collections.sort(students, new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
/**
* Ordering study programmes as follows
* 1. studies that have start date but no end date (ongoing)
* 2. studies that have no start nor end date
* 3. studies that have ended
* 4. studies that are archived
* 5. other
*/
int o1class = (o1.getArchived()) ? 4 : (o1.getStudyStartDate() != null && o1.getStudyEndDate() == null) ? 1 : (o1.getStudyStartDate() == null && o1.getStudyEndDate() == null) ? 2 : (o1.getStudyEndDate() != null) ? 3 : 5;
int o2class = (o2.getArchived()) ? 4 : (o2.getStudyStartDate() != null && o2.getStudyEndDate() == null) ? 1 : (o2.getStudyStartDate() == null && o2.getStudyEndDate() == null) ? 2 : (o2.getStudyEndDate() != null) ? 3 : 5;
if (o1class == o2class) {
// classes are the same, we try to do last comparison from the start dates
return ((o1.getStudyStartDate() != null) && (o2.getStudyStartDate() != null)) ? o2.getStudyStartDate().compareTo(o1.getStudyStartDate()) : 0;
} else
return o1class < o2class ? -1 : o1class == o2class ? 0 : 1;
}
});
Map<Long, String> studentTags = new HashMap<>();
Map<Long, Boolean> studentHasCredits = new HashMap<>();
List<UserVariableKey> userVariableKeys = userVariableKeyDAO.listByUserEditable(Boolean.TRUE);
Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
JSONObject studentLodgingPeriods = new JSONObject();
JSONObject studentStudyPeriodsJSON = new JSONObject();
for (Student student : students) {
StringBuilder tagsBuilder = new StringBuilder();
Iterator<Tag> tagIterator = student.getTags().iterator();
while (tagIterator.hasNext()) {
Tag tag = tagIterator.next();
tagsBuilder.append(tag.getText());
if (tagIterator.hasNext())
tagsBuilder.append(' ');
}
studentTags.put(student.getId(), tagsBuilder.toString());
studentHasCredits.put(student.getId(), creditLinkDAO.countByStudent(student) + courseAssessmentDAO.countByStudent(student) + transferCreditDAO.countByStudent(student) > 0);
JSONArray variables = new JSONArray();
for (UserVariableKey userVariableKey : userVariableKeys) {
UserVariable userVariable = userVariableDAO.findByUserAndVariableKey(student, userVariableKey);
JSONObject variable = new JSONObject();
variable.put("type", userVariableKey.getVariableType());
variable.put("name", userVariableKey.getVariableName());
variable.put("key", userVariableKey.getVariableKey());
variable.put("value", userVariable != null ? userVariable.getValue() : "");
variables.add(variable);
}
setJsDataVariable(pageRequestContext, "variables." + student.getId(), variables.toString());
List<StudentLodgingPeriod> studentLodgingPeriodEntities = studentLodgingPeriodDAO.listByStudent(student);
studentLodgingPeriodEntities.sort(Comparator.comparing(StudentLodgingPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
JSONArray lodgingPeriods = new JSONArray();
for (StudentLodgingPeriod period : studentLodgingPeriodEntities) {
JSONObject periodJSON = new JSONObject();
periodJSON.put("id", period.getId());
periodJSON.put("begin", period.getBegin() != null ? period.getBegin().getTime() : null);
periodJSON.put("end", period.getEnd() != null ? period.getEnd().getTime() : null);
lodgingPeriods.add(periodJSON);
}
if (!lodgingPeriods.isEmpty()) {
studentLodgingPeriods.put(student.getId(), lodgingPeriods);
}
List<StudentStudyPeriod> studyPeriods = studentStudyPeriodDAO.listByStudent(student);
studyPeriods.sort(Comparator.comparing(StudentStudyPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
JSONArray studyPeriodsJSON = new JSONArray();
for (StudentStudyPeriod studyPeriod : studyPeriods) {
JSONObject periodJSON = new JSONObject();
periodJSON.put("id", studyPeriod.getId());
periodJSON.put("begin", studyPeriod.getBegin() != null ? studyPeriod.getBegin().getTime() : null);
periodJSON.put("end", studyPeriod.getEnd() != null ? studyPeriod.getEnd().getTime() : null);
periodJSON.put("type", studyPeriod.getPeriodType());
studyPeriodsJSON.add(periodJSON);
}
if (!studyPeriodsJSON.isEmpty()) {
studentStudyPeriodsJSON.put(student.getId(), studyPeriodsJSON);
}
}
setJsDataVariable(pageRequestContext, "studentLodgingPeriods", studentLodgingPeriods.toString());
setJsDataVariable(pageRequestContext, "studentStudyPeriods", studentStudyPeriodsJSON.toString());
List<PersonVariableKey> personVariableKeys = personVariableKeyDAO.listUserEditablePersonVariableKeys();
Collections.sort(personVariableKeys, new StringAttributeComparator("getVariableName"));
JSONArray personVariablesJSON = new JSONArray();
for (PersonVariableKey personVariableKey : personVariableKeys) {
PersonVariable personVariable = personVariableDAO.findByPersonAndVariableKey(person, personVariableKey);
JSONObject personVariableJSON = new JSONObject();
personVariableJSON.put("type", personVariableKey.getVariableType());
personVariableJSON.put("name", personVariableKey.getVariableName());
personVariableJSON.put("key", personVariableKey.getVariableKey());
personVariableJSON.put("value", personVariable != null ? personVariable.getValue() : "");
personVariablesJSON.add(personVariableJSON);
}
setJsDataVariable(pageRequestContext, "personVariables", personVariablesJSON.toString());
List<Nationality> nationalities = nationalityDAO.listUnarchived();
Collections.sort(nationalities, new StringAttributeComparator("getName"));
List<Municipality> municipalities = municipalityDAO.listUnarchived();
Collections.sort(municipalities, new StringAttributeComparator("getName"));
List<Language> languages = languageDAO.listUnarchived();
Collections.sort(languages, new StringAttributeComparator("getName"));
List<School> schools = schoolDAO.listUnarchived();
Collections.sort(schools, new StringAttributeComparator("getName"));
List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
Collections.sort(contactTypes, new StringAttributeComparator("getName"));
String username = "";
boolean hasInternalAuthenticationStrategies = AuthenticationProviderVault.getInstance().hasInternalStrategies();
if (UserUtils.allowEditCredentials(loggedUser, person)) {
if (hasInternalAuthenticationStrategies) {
// TODO: Support for multiple internal authentication providers
List<InternalAuthenticationProvider> internalAuthenticationProviders = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
if (internalAuthenticationProviders.size() == 1) {
InternalAuthenticationProvider internalAuthenticationProvider = internalAuthenticationProviders.get(0);
if (internalAuthenticationProvider != null) {
UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), person);
if (internalAuthenticationProvider.canUpdateCredentials()) {
if (userIdentification != null) {
username = internalAuthenticationProvider.getUsername(userIdentification.getExternalId());
}
}
}
}
}
}
JSONArray studentStudyPeriodTypesJSON = new JSONArray();
for (StudentStudyPeriodType studentStudyPeriodType : StudentStudyPeriodType.values()) {
JSONObject studyPeriodType = new JSONObject();
studyPeriodType.put("id", studentStudyPeriodType.toString());
studyPeriodType.put("displayName", Messages.getInstance().getText(locale, String.format("generic.studentStudyPeriods.%s", studentStudyPeriodType)));
studyPeriodType.put("beginOnly", StudentStudyPeriodType.BEGINDATE_ONLY.contains(studentStudyPeriodType));
studentStudyPeriodTypesJSON.add(studyPeriodType);
}
setJsDataVariable(pageRequestContext, "studentStudyPeriodTypes", studentStudyPeriodTypesJSON.toString());
List<Curriculum> curriculums = curriculumDAO.listUnarchived();
Collections.sort(curriculums, new StringAttributeComparator("getName"));
List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
List<StaffMember> studyApprovers = staffMemberDAO.listByProperty(StaffMemberProperties.STUDY_APPROVER.getKey(), "1");
// Add study approvers to the list that have been used before so the selections can be persisted
List<StaffMember> selectedStudyApprovers = students.stream().map(student -> student.getStudyApprover()).filter(Objects::nonNull).collect(Collectors.toList());
for (StaffMember selectedStudyApprover : selectedStudyApprovers) {
Long selectedStudyApproverId = selectedStudyApprover.getId();
boolean isSelectedInList = studyApprovers.stream().map(StaffMember::getId).anyMatch(selectedStudyApproverId::equals);
if (!isSelectedInList) {
studyApprovers.add(selectedStudyApprover);
}
}
studyApprovers.sort(Comparator.comparing(StaffMember::getLastName).thenComparing(StaffMember::getFirstName));
readUserVariablePresets(pageRequestContext);
pageRequestContext.getRequest().setAttribute("tags", studentTags);
pageRequestContext.getRequest().setAttribute("person", person);
pageRequestContext.getRequest().setAttribute("students", students);
pageRequestContext.getRequest().setAttribute("activityTypes", studentActivityTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
pageRequestContext.getRequest().setAttribute("contactTypes", contactTypes);
pageRequestContext.getRequest().setAttribute("examinationTypes", studentExaminationTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("educationalLevels", studentEducationalLevelDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("nationalities", nationalities);
pageRequestContext.getRequest().setAttribute("municipalities", municipalities);
pageRequestContext.getRequest().setAttribute("languages", languages);
pageRequestContext.getRequest().setAttribute("schools", schools);
pageRequestContext.getRequest().setAttribute("studyProgrammes", studyProgrammes);
pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
pageRequestContext.getRequest().setAttribute("studyEndReasons", studyEndReasonDAO.listByParentReason(null));
pageRequestContext.getRequest().setAttribute("variableKeys", userVariableKeys);
pageRequestContext.getRequest().setAttribute("personVariableKeys", personVariableKeys);
pageRequestContext.getRequest().setAttribute("studentHasCredits", studentHasCredits);
pageRequestContext.getRequest().setAttribute("hasInternalAuthenticationStrategies", hasInternalAuthenticationStrategies);
pageRequestContext.getRequest().setAttribute("username", username);
pageRequestContext.getRequest().setAttribute("allowEditCredentials", UserUtils.allowEditCredentials(loggedUser, person));
pageRequestContext.getRequest().setAttribute("studyApprovers", studyApprovers);
pageRequestContext.setIncludeJSP("/templates/students/editstudent.jsp");
}
use of fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO in project pyramus by otavanopisto.
the class CopyStudentStudyProgrammeJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
Long studentId = requestContext.getLong("studentId");
Student oldStudent = studentDAO.findById(studentId);
StaffMember loggedUser = userDAO.findById(requestContext.getLoggedUserId());
if (!UserUtils.canAccessOrganization(loggedUser, oldStudent.getOrganization())) {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access specified student");
}
Long newStudyProgrammeId = requestContext.getLong("newStudyProgrammeId");
StudyProgramme newStudyProgramme = studyProgrammeDAO.findById(newStudyProgrammeId);
if (newStudyProgramme == null) {
throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "New Study Programme not defined");
}
if (!UserUtils.canAccessOrganization(loggedUser, newStudyProgramme.getOrganization())) {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access specified study programme");
}
Boolean linkCredits = requestContext.getBoolean("linkCredits");
Boolean setAsDefaultUser = requestContext.getBoolean("setAsDefaultUser");
Person person = oldStudent.getPerson();
String firstName = oldStudent.getFirstName();
String lastName = oldStudent.getLastName();
String nickname = oldStudent.getNickname();
String additionalInfo = oldStudent.getAdditionalInfo();
// student.getPreviousStudies();
Double previousStudies = null;
// student.getStudyTimeEnd();
Date studyTimeEnd = null;
// student.getStudyStartDate();
Date studyStartTime = null;
// student.getStudyEndDate();
Date studyEndTime = null;
// student.getStudyEndText();
String studyEndText = null;
Language language = oldStudent.getLanguage();
Municipality municipality = oldStudent.getMunicipality();
StudentActivityType activityType = oldStudent.getActivityType();
StudentExaminationType examinationType = oldStudent.getExaminationType();
StudentEducationalLevel educationalLevel = oldStudent.getEducationalLevel();
String education = oldStudent.getEducation();
Nationality nationality = oldStudent.getNationality();
School school = oldStudent.getSchool();
// oldStudent.getStudyProgramme();
StudyProgramme studyProgramme = newStudyProgramme;
// student.getStudyEndReason();
StudentStudyEndReason studyEndReason = null;
Curriculum curriculum = oldStudent.getCurriculum();
Student newStudent = studentDAO.create(person, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, studyProgramme, curriculum, previousStudies, studyStartTime, studyEndTime, studyEndReason, studyEndText, false);
// Variables are not copied, but the default values are applied
userVariableDAO.createDefaultValueVariables(newStudent);
// Contact info
contactInfoDAO.update(newStudent.getContactInfo(), oldStudent.getContactInfo().getAdditionalInfo());
if (person.getDefaultUser() == null || Boolean.TRUE.equals(setAsDefaultUser)) {
personDAO.updateDefaultUser(person, newStudent);
}
// Addresses
List<Address> addresses = oldStudent.getContactInfo().getAddresses();
for (int i = 0; i < addresses.size(); i++) {
Address add = addresses.get(i);
addressDAO.create(newStudent.getContactInfo(), add.getContactType(), add.getName(), add.getStreetAddress(), add.getPostalCode(), add.getCity(), add.getCountry(), add.getDefaultAddress());
}
// Email addresses
List<Email> emails = oldStudent.getContactInfo().getEmails();
for (int i = 0; i < emails.size(); i++) {
Email email = emails.get(i);
emailDAO.create(newStudent.getContactInfo(), email.getContactType(), email.getDefaultAddress(), email.getAddress());
}
// Phone numbers
List<PhoneNumber> phoneNumbers = oldStudent.getContactInfo().getPhoneNumbers();
for (int i = 0; i < phoneNumbers.size(); i++) {
PhoneNumber phoneNumber = phoneNumbers.get(i);
phoneNumberDAO.create(newStudent.getContactInfo(), phoneNumber.getContactType(), phoneNumber.getDefaultNumber(), phoneNumber.getNumber());
}
if (linkCredits) {
List<CourseAssessment> assessments = courseAssessmentDAO.listByStudent(oldStudent);
for (CourseAssessment assessment : assessments) {
creditLinkDAO.create(assessment, newStudent, loggedUser);
}
List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(oldStudent);
for (TransferCredit transferCredit : transferCredits) {
creditLinkDAO.create(transferCredit, newStudent, loggedUser);
}
List<CreditLink> creditLinks = creditLinkDAO.listByStudent(oldStudent);
for (CreditLink creditLink : creditLinks) {
creditLinkDAO.create(creditLink.getCredit(), newStudent, loggedUser);
}
}
String redirectURL = requestContext.getRequest().getContextPath() + "/students/editstudent.page?student=" + newStudent.getPerson().getId();
String refererAnchor = requestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
requestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO in project pyramus by otavanopisto.
the class ImportStudentCreditsJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
Long studentId = requestContext.getLong("studentId");
Student baseStudent = studentDAO.findById(studentId);
List<Student> students = studentDAO.listByPerson(baseStudent.getPerson());
students.remove(baseStudent);
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
// LinkedCourseAssessments for baseStudent
int rowCount = requestContext.getLong("linkedCourseAssessmentsTable." + baseStudent.getId() + ".rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String paramName = "linkedCourseAssessmentsTable." + baseStudent.getId() + "." + i + ".selected";
boolean selected = new Long(1).equals(requestContext.getLong(paramName));
if (selected) {
Long creditLinkId = requestContext.getLong("linkedCourseAssessmentsTable." + baseStudent.getId() + "." + i + ".creditLinkId");
CreditLink creditLink = creditLinkDAO.findById(creditLinkId);
creditLinkDAO.archive(creditLink, loggedUser);
}
}
// LinkedTransferCredits for baseStudent
rowCount = requestContext.getLong("linkedTransferCreditsTable." + baseStudent.getId() + ".rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String paramName = "linkedTransferCreditsTable." + baseStudent.getId() + "." + i + ".selected";
boolean selected = new Long(1).equals(requestContext.getLong(paramName));
if (selected) {
Long creditLinkId = requestContext.getLong("linkedTransferCreditsTable." + baseStudent.getId() + "." + i + ".creditLinkId");
CreditLink creditLink = creditLinkDAO.findById(creditLinkId);
creditLinkDAO.archive(creditLink, loggedUser);
}
}
for (Student student : students) {
// CourseAssessments
rowCount = requestContext.getLong("courseAssessmentsTable." + student.getId() + ".rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String paramName = "courseAssessmentsTable." + student.getId() + "." + i + ".selected";
boolean selected = new Long(1).equals(requestContext.getLong(paramName));
if (selected) {
Long courseAssessmentId = requestContext.getLong("courseAssessmentsTable." + student.getId() + "." + i + ".courseAssessmentId");
CourseAssessment courseAssessment = courseAssessmentDAO.findById(courseAssessmentId);
CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, courseAssessment);
if (creditLink == null)
creditLinkDAO.create(courseAssessment, baseStudent, loggedUser);
}
}
// TransferCredits
rowCount = requestContext.getLong("transferCreditsTable." + student.getId() + ".rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String paramName = "transferCreditsTable." + student.getId() + "." + i + ".selected";
boolean selected = new Long(1).equals(requestContext.getLong(paramName));
if (selected) {
Long transferCreditId = requestContext.getLong("transferCreditsTable." + student.getId() + "." + i + ".transferCreditId");
TransferCredit transferCredit = transferCreditDAO.findById(transferCreditId);
CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, transferCredit);
if (creditLink == null)
creditLinkDAO.create(transferCredit, baseStudent, loggedUser);
}
}
// LinkedCourseAssessments
rowCount = requestContext.getLong("linkedCourseAssessmentsTable." + student.getId() + ".rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String paramName = "linkedCourseAssessmentsTable." + student.getId() + "." + i + ".selected";
boolean selected = new Long(1).equals(requestContext.getLong(paramName));
if (selected) {
Long courseAssessmentId = requestContext.getLong("linkedCourseAssessmentsTable." + student.getId() + "." + i + ".courseAssessmentId");
CourseAssessment courseAssessment = courseAssessmentDAO.findById(courseAssessmentId);
CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, courseAssessment);
if (creditLink == null)
creditLinkDAO.create(courseAssessment, baseStudent, loggedUser);
}
}
// LinkedTransferCredits
rowCount = requestContext.getLong("linkedTransferCreditsTable." + student.getId() + ".rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String paramName = "linkedTransferCreditsTable." + student.getId() + "." + i + ".selected";
boolean selected = new Long(1).equals(requestContext.getLong(paramName));
if (selected) {
Long transferCreditId = requestContext.getLong("linkedTransferCreditsTable." + student.getId() + "." + i + ".transferCreditId");
TransferCredit transferCredit = transferCreditDAO.findById(transferCreditId);
CreditLink creditLink = creditLinkDAO.findByStudentAndCredit(baseStudent, transferCredit);
if (creditLink == null)
creditLinkDAO.create(transferCredit, baseStudent, loggedUser);
}
}
}
String redirectURL = requestContext.getRequest().getContextPath() + "/students/importstudentcredits.page?studentId=" + baseStudent.getId();
// String refererAnchor = requestContext.getRefererAnchor();
// if (!StringUtils.isBlank(refererAnchor))
// redirectURL += "#" + refererAnchor;
requestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO in project pyramus by otavanopisto.
the class ManageCourseAssessmentsViewController 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) {
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
Course course = courseDAO.findById(NumberUtils.createLong(pageRequestContext.getRequest().getParameter("course")));
List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
List<CourseStudent> courseStudents = courseStudentDAO.listByCourse(course);
Collections.sort(courseStudents, new Comparator<CourseStudent>() {
@Override
public int compare(CourseStudent o1, CourseStudent o2) {
int cmp = o1.getStudent().getLastName().compareToIgnoreCase(o2.getStudent().getLastName());
if (cmp == 0)
cmp = o1.getStudent().getFirstName().compareToIgnoreCase(o2.getStudent().getFirstName());
return cmp;
}
});
Map<Long, CourseAssessment> courseAssessments = new HashMap<>();
Map<Long, String> verbalAssessments = new HashMap<>();
Iterator<CourseStudent> students = courseStudents.iterator();
while (students.hasNext()) {
CourseStudent courseStudent = students.next();
CourseAssessment courseAssessment = courseAssessmentDAO.findLatestByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
if (courseAssessment != null) {
courseAssessments.put(courseStudent.getId(), courseAssessment);
// Shortened descriptions
String description = courseAssessment.getVerbalAssessment();
if (description != null) {
description = StringEscapeUtils.unescapeHtml(description.replaceAll("\\<.*?>", ""));
description = description.replaceAll("\\n", "");
verbalAssessments.put(courseAssessment.getId(), description);
}
}
}
List<CourseParticipationType> courseParticipationTypes = participationTypeDAO.listUnarchived();
Collections.sort(courseParticipationTypes, new Comparator<CourseParticipationType>() {
public int compare(CourseParticipationType o1, CourseParticipationType o2) {
return o1.getIndexColumn() == null ? -1 : o2.getIndexColumn() == null ? 1 : o1.getIndexColumn().compareTo(o2.getIndexColumn());
}
});
pageRequestContext.getRequest().setAttribute("course", course);
pageRequestContext.getRequest().setAttribute("courseStudents", courseStudents);
pageRequestContext.getRequest().setAttribute("courseParticipationTypes", courseParticipationTypes);
pageRequestContext.getRequest().setAttribute("assessments", courseAssessments);
pageRequestContext.getRequest().setAttribute("verbalAssessments", verbalAssessments);
pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
pageRequestContext.setIncludeJSP("/templates/courses/managecourseassessments.jsp");
}
Aggregations