Search in sources :

Example 1 with WorkspaceMaterialFieldAnswer

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");
        }
    }
}
Also used : WorkspaceMaterialFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFieldAnswer) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)

Example 2 with WorkspaceMaterialFieldAnswer

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceMaterialFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFieldAnswer)

Aggregations

WorkspaceMaterialFieldAnswer (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFieldAnswer)2 WorkspaceMaterialField (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1