Search in sources :

Example 6 with CourseBaseVariable

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

the class CourseBaseVariableDAO method setCourseVariable.

public void setCourseVariable(Course course, String key, String value) {
    CourseBaseVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
    CourseBaseVariableKey courseBaseVariableKey = variableKeyDAO.findByVariableKey(key);
    if (courseBaseVariableKey != null) {
        CourseBaseVariable courseBaseVariable = findByCourseAndVariableKey(course, courseBaseVariableKey);
        if (StringUtils.isBlank(value)) {
            delete(courseBaseVariable);
        } else {
            if (courseBaseVariable == null) {
                courseBaseVariable = create(course, courseBaseVariableKey, value);
            } else {
                update(courseBaseVariable, value);
            }
        }
    } else {
        throw new PersistenceException("Unknown VariableKey");
    }
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) CourseBaseVariable(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable) PersistenceException(javax.persistence.PersistenceException)

Example 7 with CourseBaseVariable

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

the class CourseBaseVariableDAO method findByCourseAndVariableKey.

public CourseBaseVariable findByCourseAndVariableKey(Course course, CourseBaseVariableKey key) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseBaseVariable> criteria = criteriaBuilder.createQuery(CourseBaseVariable.class);
    Root<CourseBaseVariable> root = criteria.from(CourseBaseVariable.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseBaseVariable_.courseBase), course), criteriaBuilder.equal(root.get(CourseBaseVariable_.key), key)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CourseBaseVariable(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable) EntityManager(javax.persistence.EntityManager)

Example 8 with CourseBaseVariable

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

the class CourseDAO method listByCourseVariable.

public List<Course> listByCourseVariable(String key, String value) {
    CourseBaseVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
    CourseBaseVariableKey courseBaseVariableKey = variableKeyDAO.findByVariableKey(key);
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Course> criteria = criteriaBuilder.createQuery(Course.class);
    Root<CourseBaseVariable> variable = criteria.from(CourseBaseVariable.class);
    Root<Course> course = criteria.from(Course.class);
    criteria.select(course);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(course, variable.get(CourseBaseVariable_.courseBase)), criteriaBuilder.equal(course.get(Course_.archived), Boolean.FALSE), criteriaBuilder.equal(variable.get(CourseBaseVariable_.key), courseBaseVariableKey), criteriaBuilder.equal(variable.get(CourseBaseVariable_.value), value)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) CourseBaseVariable(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable) FullTextEntityManager(org.hibernate.search.jpa.FullTextEntityManager) EntityManager(javax.persistence.EntityManager) CourseBaseVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Aggregations

CourseBaseVariable (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable)8 CourseBaseVariableKey (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey)5 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)2 HashSet (java.util.HashSet)2 CourseBaseVariableKeyDAO (fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO)1 Address (fi.otavanopisto.pyramus.domainmodel.base.Address)1 BillingDetails (fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)1 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)1 ContactURL (fi.otavanopisto.pyramus.domainmodel.base.ContactURL)1 ContactURLType (fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)1 CourseEducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype)1 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)1 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)1 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)1 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)1 Email (fi.otavanopisto.pyramus.domainmodel.base.Email)1 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)1 Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)1