use of fi.otavanopisto.pyramus.domainmodel.grading.CreditLink 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.CreditLink 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.domainmodel.grading.CreditLink in project pyramus by otavanopisto.
the class CreditLinkDAO method countByStudent.
public Long countByStudent(Student student) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<CreditLink> root = criteria.from(CreditLink.class);
criteria.select(criteriaBuilder.count(root));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CreditLink_.student), student), criteriaBuilder.equal(root.get(CreditLink_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getSingleResult();
}
use of fi.otavanopisto.pyramus.domainmodel.grading.CreditLink in project pyramus by otavanopisto.
the class CreditLinkDAO method create.
public CreditLink create(Credit credit, Student student, User creator) {
CreditLink creditLink = new CreditLink();
creditLink.setCredit(credit);
creditLink.setStudent(student);
creditLink.setCreator(creator);
creditLink.setCreated(new Date());
creditLink.setArchived(Boolean.FALSE);
return persist(creditLink);
}
use of fi.otavanopisto.pyramus.domainmodel.grading.CreditLink in project pyramus by otavanopisto.
the class CreditLinkDAO method listByStudent.
public List<CreditLink> listByStudent(Student student) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CreditLink> criteria = criteriaBuilder.createQuery(CreditLink.class);
Root<CreditLink> root = criteria.from(CreditLink.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CreditLink_.student), student), criteriaBuilder.equal(root.get(CreditLink_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations