use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialSorterFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialSorterFieldAnswerDAO method create.
public WorkspaceMaterialSorterFieldAnswer create(WorkspaceMaterialField field, WorkspaceMaterialReply reply, String value) {
WorkspaceMaterialSorterFieldAnswer workspaceMaterialSorterFieldAnswer = new WorkspaceMaterialSorterFieldAnswer();
workspaceMaterialSorterFieldAnswer.setField(field);
workspaceMaterialSorterFieldAnswer.setReply(reply);
workspaceMaterialSorterFieldAnswer.setValue(value);
return persist(workspaceMaterialSorterFieldAnswer);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialSorterFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialSorterFieldAnswerDAO method findByFieldAndReply.
public WorkspaceMaterialSorterFieldAnswer findByFieldAndReply(WorkspaceMaterialField field, WorkspaceMaterialReply reply) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterialSorterFieldAnswer> criteria = criteriaBuilder.createQuery(WorkspaceMaterialSorterFieldAnswer.class);
Root<WorkspaceMaterialSorterFieldAnswer> root = criteria.from(WorkspaceMaterialSorterFieldAnswer.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceMaterialSorterFieldAnswer_.field), field), criteriaBuilder.equal(root.get(WorkspaceMaterialSorterFieldAnswer_.reply), reply)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialSorterFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialFieldChangeListener method onWorkspaceMaterialSorterFieldUpdate.
// Sorter field
public void onWorkspaceMaterialSorterFieldUpdate(@Observes WorkspaceMaterialFieldUpdateEvent event) throws MaterialFieldMetaParsingExeption, WorkspaceMaterialContainsAnswersExeption {
if (event.getMaterialField().getType().equals("application/vnd.muikku.field.sorter")) {
ObjectMapper objectMapper = new ObjectMapper();
SorterFieldMeta sorterFieldMeta;
try {
sorterFieldMeta = objectMapper.readValue(event.getMaterialField().getContent(), SorterFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse sorter field meta", e);
}
List<WorkspaceMaterialField> fields = workspaceMaterialFieldDAO.listByQueryField(event.getWorkspaceMaterialField().getQueryField());
for (WorkspaceMaterialField field : fields) {
List<WorkspaceMaterialSorterFieldAnswer> answers = workspaceMaterialSorterFieldAnswerDAO.listByWorkspaceMaterialField(field);
for (WorkspaceMaterialSorterFieldAnswer answer : answers) {
try {
boolean answerModified = false;
List<String> answerItems = objectMapper.readValue(answer.getValue(), new TypeReference<ArrayList<String>>() {
});
for (int i = answerItems.size() - 1; i >= 0; i--) {
String answerItem = answerItems.get(i);
if (!sorterFieldMeta.hasItemWithId(answerItem)) {
if (!event.getRemoveAnswers()) {
throw new WorkspaceMaterialContainsAnswersExeption("Could not update sorter field because it contains answers");
} else {
answerItems.remove(answerItem);
answerModified = true;
}
}
}
if (answerModified) {
workspaceMaterialSorterFieldAnswerDAO.updateValue(answer, objectMapper.writeValueAsString(answerItems));
}
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse sorter field answer meta", e);
}
}
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialSorterFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialSorterFieldAnswerDAO method listByWorkspaceMaterialField.
public List<WorkspaceMaterialSorterFieldAnswer> listByWorkspaceMaterialField(WorkspaceMaterialField field) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterialSorterFieldAnswer> criteria = criteriaBuilder.createQuery(WorkspaceMaterialSorterFieldAnswer.class);
Root<WorkspaceMaterialSorterFieldAnswer> root = criteria.from(WorkspaceMaterialSorterFieldAnswer.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WorkspaceMaterialOrganizerFieldAnswer_.field), field));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations