use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit 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.TransferCredit in project pyramus by otavanopisto.
the class ArchiveTransferCreditJSONRequestController method process.
/**
* Processes the request to archive a transfer credit.
* The request should contain the either following parameters:
* <dl>
* <dt><code>transferCreditId</code></dt>
* <dd>The ID of the transfer credit to archive.</dd>
* </dl>
*
* @param jsonRequestContext The JSON request context
*/
public void process(JSONRequestContext jsonRequestContext) {
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
Long transferCreditId = jsonRequestContext.getLong("transferCreditId");
TransferCredit transferCredit = transferCreditDAO.findById(transferCreditId);
transferCreditDAO.archive(transferCredit);
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class StudentRESTService method listStudentsTransferCredits.
@Path("/students/{STUDENTID:[0-9]*}/transferCredits")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStudentsTransferCredits(@PathParam("STUDENTID") Long studentId) {
Student student = studentController.findStudentById(studentId);
Status studentStatus = checkStudent(student);
if (studentStatus != Status.OK)
return Response.status(studentStatus).build();
if (!restSecurity.hasPermission(new String[] { StudentPermissions.LIST_STUDENT_TRANSFER_CREDITS, PersonPermissions.PERSON_OWNER }, student.getPerson(), Style.OR)) {
return Response.status(Status.FORBIDDEN).build();
}
List<TransferCredit> transferCredits = studentController.listStudentTransferCredits(student);
return Response.status(Status.OK).entity(objectFactory.createModel(transferCredits)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit 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.domainmodel.grading.TransferCredit 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);
}
Aggregations