Search in sources :

Example 1 with CourseBaseVariableKeyDAO

use of fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO in project pyramus by otavanopisto.

the class CourseVariableKeyAPI method create.

public Long create(String key, String name, String type, Boolean userEditable) throws InvalidScriptException {
    VariableType variableType = VariableType.valueOf(type);
    if (variableType == null) {
        throw new InvalidScriptException(String.format("Invalid variable type %s", type));
    }
    CourseBaseVariableKeyDAO courseBaseVariableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
    CourseBaseVariableKey variableKey = courseBaseVariableKeyDAO.findByVariableKey(key);
    if (variableKey == null) {
        return courseBaseVariableKeyDAO.create(key, name, variableType, userEditable).getId();
    } else {
        throw new InvalidScriptException("Course variable key already exists");
    }
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) VariableType(fi.otavanopisto.pyramus.domainmodel.base.VariableType) CourseBaseVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException)

Example 2 with CourseBaseVariableKeyDAO

use of fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO in project pyramus by otavanopisto.

the class CourseVariableKeyAPI method findIdByKey.

public Long findIdByKey(String key) {
    CourseBaseVariableKeyDAO courseBaseVariableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
    CourseBaseVariableKey variableKey = courseBaseVariableKeyDAO.findByVariableKey(key);
    return variableKey != null ? variableKey.getId() : null;
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) CourseBaseVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO)

Example 3 with CourseBaseVariableKeyDAO

use of fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO 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

CourseBaseVariableKeyDAO (fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO)3 CourseBaseVariableKey (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey)3 CourseBaseVariable (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable)1 VariableType (fi.otavanopisto.pyramus.domainmodel.base.VariableType)1 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)1 InvalidScriptException (fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 FullTextEntityManager (org.hibernate.search.jpa.FullTextEntityManager)1