Search in sources :

Example 26 with StudyProgramme

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.

the class StudyProgrammeDAO method findByCode.

public StudyProgramme findByCode(String code) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StudyProgramme> criteria = criteriaBuilder.createQuery(StudyProgramme.class);
    Root<StudyProgramme> root = criteria.from(StudyProgramme.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(StudyProgramme_.code), code));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)

Example 27 with StudyProgramme

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.

the class StudyProgrammeDAO method listByOrganization.

public List<StudyProgramme> listByOrganization(Organization organization, Archived archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StudyProgramme> criteria = criteriaBuilder.createQuery(StudyProgramme.class);
    Root<StudyProgramme> root = criteria.from(StudyProgramme.class);
    criteria.select(root);
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(criteriaBuilder.equal(root.get(StudyProgramme_.organization), organization));
    if (archived.isBoolean()) {
        predicates.add(criteriaBuilder.equal(root.get(StudyProgramme_.archived), archived.booleanValue()));
    }
    criteria.where(predicates.toArray(new Predicate[0]));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 28 with StudyProgramme

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.

the class StudyProgrammeDAO method create.

public StudyProgramme create(Organization organization, String name, StudyProgrammeCategory category, String code, boolean hasEvaluationFees) {
    EntityManager entityManager = getEntityManager();
    StudyProgramme studyProgramme = new StudyProgramme();
    studyProgramme.setOrganization(organization);
    studyProgramme.setName(name);
    studyProgramme.setCategory(category);
    studyProgramme.setCode(code);
    studyProgramme.setHasEvaluationFees(hasEvaluationFees);
    entityManager.persist(studyProgramme);
    studyProgrammeCreatedEvent.fire(new StudyProgrammeCreatedEvent(studyProgramme.getId()));
    return studyProgramme;
}
Also used : EntityManager(javax.persistence.EntityManager) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) StudyProgrammeCreatedEvent(fi.otavanopisto.pyramus.events.StudyProgrammeCreatedEvent)

Example 29 with StudyProgramme

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.

the class StudentDAO method listByPersonAndOrganization.

public List<Student> listByPersonAndOrganization(Person person, Organization organization) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Student> criteria = criteriaBuilder.createQuery(Student.class);
    Root<Student> root = criteria.from(Student.class);
    Join<Student, StudyProgramme> studyProgramme = root.join(Student_.studyProgramme);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(Student_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(Student_.person), person), criteriaBuilder.equal(studyProgramme.get(StudyProgramme_.organization), organization)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student)

Example 30 with StudyProgramme

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.

the class StudentDAO method listBy.

public List<Student> listBy(Collection<Organization> organizations, String email, List<StudentGroup> groups, Boolean archived, Integer firstResult, Integer maxResults) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Student> criteria = criteriaBuilder.createQuery(Student.class);
    Root<Student> root = criteria.from(Student.class);
    Join<Student, ContactInfo> contactInfoJoin = root.join(Student_.contactInfo);
    List<Predicate> predicates = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(organizations)) {
        Join<Student, StudyProgramme> jStudyProgramme = root.join(Student_.studyProgramme);
        Join<StudyProgramme, Organization> jOrganization = jStudyProgramme.join(StudyProgramme_.organization);
        predicates.add(jOrganization.in(organizations));
    }
    if (StringUtils.isNotBlank(email)) {
        ListJoin<ContactInfo, Email> emailJoin = contactInfoJoin.join(ContactInfo_.emails);
        predicates.add(criteriaBuilder.equal(emailJoin.get(Email_.address), email));
    }
    if (archived != null) {
        predicates.add(criteriaBuilder.equal(root.get(Student_.archived), archived));
    }
    if (groups != null) {
        Subquery<Student> subquery = criteria.subquery(Student.class);
        Root<StudentGroupStudent> studentGroup = subquery.from(StudentGroupStudent.class);
        subquery.select(studentGroup.get(StudentGroupStudent_.student));
        subquery.where(studentGroup.get(StudentGroupStudent_.studentGroup).in(groups));
        predicates.add(root.in(subquery));
    }
    criteria.select(root);
    if (!predicates.isEmpty()) {
        criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
    }
    TypedQuery<Student> query = entityManager.createQuery(criteria);
    if (firstResult != null) {
        query.setFirstResult(firstResult);
    }
    if (maxResults != null) {
        query.setMaxResults(maxResults);
    }
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) ArrayList(java.util.ArrayList) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Predicate(javax.persistence.criteria.Predicate) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) EntityManager(javax.persistence.EntityManager) ContactInfo(fi.otavanopisto.pyramus.domainmodel.base.ContactInfo)

Aggregations

StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)43 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)26 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)21 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)15 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)14 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)14 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)13 Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)13 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)13 School (fi.otavanopisto.pyramus.domainmodel.base.School)12 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)12 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)10 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)9 StudentActivityType (fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType)9 StudentEducationalLevel (fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel)9 StudentExaminationType (fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType)9 StudentStudyEndReason (fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason)9 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)8 Path (javax.ws.rs.Path)8 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)7