use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialFieldChangeListener method onWorkspaceMaterialFieldDelete.
// Delete
public void onWorkspaceMaterialFieldDelete(@Observes WorkspaceMaterialFieldDeleteEvent event) throws WorkspaceMaterialContainsAnswersExeption {
WorkspaceMaterialField materialField = event.getWorkspaceMaterialField();
List<WorkspaceMaterialFieldAnswer> answers = workspaceMaterialFieldAnswerController.listWorkspaceMaterialFieldAnswersByField(materialField);
if (event.getRemoveAnswers()) {
for (WorkspaceMaterialFieldAnswer answer : answers) {
deleteFieldAnswer(answer);
}
} else {
if (!answers.isEmpty()) {
throw new WorkspaceMaterialContainsAnswersExeption("Could not remove workspace material field because it contains answers");
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialFieldAnswerDAO method listByField.
public List<WorkspaceMaterialFieldAnswer> listByField(WorkspaceMaterialField field) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterialFieldAnswer> criteria = criteriaBuilder.createQuery(WorkspaceMaterialFieldAnswer.class);
Root<WorkspaceMaterialFieldAnswer> root = criteria.from(WorkspaceMaterialFieldAnswer.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WorkspaceMaterialFieldAnswer_.field), field));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations