Search in sources :

Example 1 with CreditLink

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);
}
Also used : PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Date(java.util.Date) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 2 with CreditLink

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);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)

Example 3 with CreditLink

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)

Example 4 with CreditLink

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);
}
Also used : CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) Date(java.util.Date)

Example 5 with 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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)

Aggregations

CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)20 TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)13 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)12 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)12 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)9 CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)8 CreditLinkDAO (fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO)8 TransferCreditDAO (fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO)8 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)7 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)6 Date (java.util.Date)6 EntityManager (javax.persistence.EntityManager)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)5 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)5 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 CourseAssessmentRequest (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)4 Grade (fi.otavanopisto.pyramus.domainmodel.grading.Grade)4