Search in sources :

Example 6 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class TransferCreditDAO method create.

public TransferCredit create(String courseName, Integer courseNumber, Double courseLength, EducationalTimeUnit courseLengthUnit, School school, Subject subject, CourseOptionality optionality, Student student, StaffMember assessingUser, Grade grade, Date date, String verbalAssessment, Curriculum curriculum, boolean offCurriculum, TransferCreditFunding funding) {
    TransferCredit transferCredit = new TransferCredit();
    EducationalLength length = new EducationalLength();
    length.setUnits(courseLength);
    length.setUnit(courseLengthUnit);
    transferCredit.setAssessor(assessingUser);
    transferCredit.setDate(date);
    transferCredit.setGrade(grade);
    transferCredit.setCourseLength(length);
    transferCredit.setCourseName(courseName);
    transferCredit.setCourseNumber(courseNumber);
    transferCredit.setSchool(school);
    transferCredit.setStudent(student);
    transferCredit.setSubject(subject);
    transferCredit.setOptionality(optionality);
    transferCredit.setVerbalAssessment(verbalAssessment);
    transferCredit.setCurriculum(curriculum);
    transferCredit.setOffCurriculum(offCurriculum);
    transferCredit.setFunding(funding);
    transferCredit.setArchived(Boolean.FALSE);
    EntityManager entityManager = getEntityManager();
    entityManager.persist(length);
    entityManager.persist(transferCredit);
    if (student != null)
        transferCreditCreatedEvent.fire(new TransferCreditEvent(student.getId(), transferCredit.getId()));
    return transferCredit;
}
Also used : EntityManager(javax.persistence.EntityManager) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) TransferCreditEvent(fi.otavanopisto.pyramus.events.TransferCreditEvent) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength)

Example 7 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class TransferCreditDAO method listByStudent.

/**
 * Lists all student's transfer credits excluding archived ones
 *
 * @return list of all students transfer credits
 */
public List<TransferCredit> listByStudent(Student student) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TransferCredit> criteria = criteriaBuilder.createQuery(TransferCredit.class);
    Root<TransferCredit> root = criteria.from(TransferCredit.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(TransferCredit_.student), student)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)

Example 8 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class TransferCreditDAO method listByStudentAndSubject.

/**
 * Lists all student's transfer credits excluding archived ones
 *
 * @return list of all students transfer credits
 */
public List<TransferCredit> listByStudentAndSubject(Student student, Subject subject) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TransferCredit> criteria = criteriaBuilder.createQuery(TransferCredit.class);
    Root<TransferCredit> root = criteria.from(TransferCredit.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(TransferCredit_.student), student), criteriaBuilder.equal(root.get(TransferCredit_.subject), subject)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)

Example 9 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class TransferCreditEntityFactory method buildFromDomainObject.

public TransferCreditEntity buildFromDomainObject(Object domainObject) {
    if (domainObject == null)
        return null;
    TransferCredit transferCredit = (TransferCredit) domainObject;
    GradeEntity grade = EntityFactoryVault.buildFromDomainObject(transferCredit.getGrade());
    UserEntity assessingUser = EntityFactoryVault.buildFromDomainObject(transferCredit.getAssessor());
    return new TransferCreditEntity(transferCredit.getId(), transferCredit.getStudent().getId(), transferCredit.getDate(), grade, transferCredit.getVerbalAssessment(), assessingUser, transferCredit.getArchived(), transferCredit.getCourseName(), transferCredit.getCourseNumber(), transferCredit.getCourseLength().getUnits(), transferCredit.getCourseLength().getUnit().getId(), transferCredit.getSchool().getId(), transferCredit.getSubject().getId(), transferCredit.getOptionality().toString());
}
Also used : TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) UserEntity(fi.pyramus.services.entities.users.UserEntity)

Example 10 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class MuikkuRESTService method getStudentStudyActivity.

@Path("/students/{ID:[0-9]*}/studyActivity")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response getStudentStudyActivity(@PathParam("ID") Long id) {
    // Access check
    Student student = studentController.findStudentById(id);
    if (student == null || student.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { MuikkuPermissions.GET_STUDENT_COURSE_ACTIVITY, UserPermissions.USER_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (!sessionController.hasEnvironmentPermission(OrganizationPermissions.ACCESS_ALL_ORGANIZATIONS)) {
        if (!UserUtils.isMemberOf(sessionController.getUser(), student.getOrganization())) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    Map<String, StudyActivityItemRestModel> items = new HashMap<>();
    // Transfer credits
    List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(student);
    transferCredits.sort(Comparator.comparing(TransferCredit::getDate).reversed());
    for (TransferCredit transferCredit : transferCredits) {
        String key = getActivityItemKey(transferCredit.getSubject(), transferCredit.getCourseNumber());
        StudyActivityItemRestModel item = getTransferCreditActivityItem(transferCredit);
        if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
            items.put(key, item);
        }
    }
    // Course assessments
    List<CourseAssessment> courseAssessments = courseAssessmentDAO.listByStudent(student);
    courseAssessments.sort(Comparator.comparing(CourseAssessment::getDate).reversed());
    for (CourseAssessment courseAssessment : courseAssessments) {
        Course course = courseAssessment.getCourseStudent().getCourse();
        String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
        StudyActivityItemRestModel item = getCourseAssessmentActivityItem(courseAssessment);
        if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
            items.put(key, item);
        }
    }
    // Linked credits
    List<CreditLink> creditLinks = creditLinkDAO.listByStudent(student);
    for (CreditLink creditLink : creditLinks) {
        Credit credit = creditLink.getCredit();
        if (credit.getCreditType() == CreditType.CourseAssessment) {
            CourseAssessment courseAssessment = (CourseAssessment) credit;
            Course course = courseAssessment.getCourseStudent().getCourse();
            String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
            StudyActivityItemRestModel item = getCourseAssessmentActivityItem(courseAssessment);
            if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
                items.put(key, item);
            }
        } else if (credit.getCreditType() == CreditType.TransferCredit) {
            TransferCredit transferCredit = (TransferCredit) credit;
            String key = getActivityItemKey(transferCredit.getSubject(), transferCredit.getCourseNumber());
            StudyActivityItemRestModel item = getTransferCreditActivityItem(transferCredit);
            if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
                items.put(key, item);
            }
        }
    }
    // Courses
    List<CourseStudent> courseStudents = courseStudentDAO.listByStudent(student);
    for (CourseStudent courseStudent : courseStudents) {
        Course course = courseStudent.getCourse();
        String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
        if (!items.containsKey(key)) {
            StudyActivityItemRestModel item = new StudyActivityItemRestModel();
            item.setCourseId(course.getId());
            item.setCourseName(course.getName());
            if (course.getCourseNumber() != null && course.getCourseNumber() > 0) {
                item.setCourseNumber(course.getCourseNumber());
            }
            item.setDate(courseStudent.getEnrolmentTime());
            item.setStatus(StudyActivityItemStatus.ONGOING);
            item.setSubject(course.getSubject().getCode());
            items.put(key, item);
        }
    }
    return Response.ok(items.values()).build();
}
Also used : StudyActivityItemRestModel(fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel) HashMap(java.util.HashMap) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Credit(fi.otavanopisto.pyramus.domainmodel.grading.Credit) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)28 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)17 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)15 TransferCreditDAO (fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO)12 CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)12 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)10 ArrayList (java.util.ArrayList)10 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)9 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)9 CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)8 CreditLinkDAO (fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO)8 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)8 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 CourseOptionality (fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality)7 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)7 List (java.util.List)7 EntityManager (javax.persistence.EntityManager)7 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)6