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));
}
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();
}
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;
}
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();
}
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();
}
Aggregations