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