use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialConnectFieldAnswerDAO method create.
public WorkspaceMaterialConnectFieldAnswer create(WorkspaceMaterialField field, WorkspaceMaterialReply reply, QueryConnectFieldTerm term, QueryConnectFieldCounterpart counterpart) {
WorkspaceMaterialConnectFieldAnswer workspaceMaterialConectFieldAnswer = new WorkspaceMaterialConnectFieldAnswer();
workspaceMaterialConectFieldAnswer.setField(field);
workspaceMaterialConectFieldAnswer.setReply(reply);
workspaceMaterialConectFieldAnswer.setTerm(term);
workspaceMaterialConectFieldAnswer.setCounterpart(counterpart);
return persist(workspaceMaterialConectFieldAnswer);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer in project muikku by otavanopisto.
the class WorkspaceConnectFieldIOHandler method retrieve.
@Override
public String retrieve(WorkspaceMaterialField field, WorkspaceMaterialReply reply) throws WorkspaceFieldIOException {
Map<String, String> answers = new HashMap<>();
QueryConnectField queryConnectField = (QueryConnectField) field.getQueryField();
List<QueryConnectFieldTerm> terms = queryConnectFieldController.listConnectFieldTermsByField(queryConnectField);
for (QueryConnectFieldTerm term : terms) {
WorkspaceMaterialConnectFieldAnswer connectFieldAnswer = workspaceMaterialFieldAnswerController.findWorkspaceMaterialConnectFieldAnswerByFieldAndReplyAndTerm(field, reply, term);
if ((connectFieldAnswer != null) && (connectFieldAnswer.getCounterpart() != null)) {
answers.put(term.getName(), connectFieldAnswer.getCounterpart().getName());
}
}
try {
return new ObjectMapper().writeValueAsString(answers);
} catch (IOException e) {
throw new WorkspaceFieldIOException("Could not marshal field response", e);
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer in project muikku by otavanopisto.
the class WorkspaceMaterialConnectFieldAnswerDAO method findByQueryFieldAndReplyAndTerm.
public WorkspaceMaterialConnectFieldAnswer findByQueryFieldAndReplyAndTerm(WorkspaceMaterialField field, WorkspaceMaterialReply reply, QueryConnectFieldTerm term) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterialConnectFieldAnswer> criteria = criteriaBuilder.createQuery(WorkspaceMaterialConnectFieldAnswer.class);
Root<WorkspaceMaterialConnectFieldAnswer> root = criteria.from(WorkspaceMaterialConnectFieldAnswer.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceMaterialConnectFieldAnswer_.field), field), criteriaBuilder.equal(root.get(WorkspaceMaterialConnectFieldAnswer_.reply), reply), criteriaBuilder.equal(root.get(WorkspaceMaterialConnectFieldAnswer_.term), term)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer in project muikku by otavanopisto.
the class WorkspaceConnectFieldIOHandler method store.
@Override
public void store(WorkspaceMaterialField field, WorkspaceMaterialReply reply, String value) throws WorkspaceFieldIOException {
Map<String, String> valueMap = null;
try {
valueMap = new ObjectMapper().readValue(value, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) {
throw new WorkspaceFieldIOException("Could not unmarshal field response", e);
}
QueryConnectField queryConnectField = (QueryConnectField) field.getQueryField();
if (queryConnectField != null) {
List<QueryConnectFieldTerm> terms = queryConnectFieldController.listConnectFieldTermsByField(queryConnectField);
for (QueryConnectFieldTerm term : terms) {
String parameterValue = valueMap.get(term.getName());
QueryConnectFieldCounterpart counterpart = StringUtils.isNotEmpty(parameterValue) ? queryConnectFieldController.findQueryConnectFieldCounterpartByFieldAndName(queryConnectField, parameterValue) : null;
WorkspaceMaterialConnectFieldAnswer connectFieldAnswer = workspaceMaterialFieldAnswerController.findWorkspaceMaterialConnectFieldAnswerByFieldAndReplyAndTerm(field, reply, term);
if (connectFieldAnswer != null) {
workspaceMaterialFieldAnswerController.updateWorkspaceMaterialConnectFieldAnswerCounterpart(connectFieldAnswer, counterpart);
} else {
if (counterpart != null) {
workspaceMaterialFieldAnswerController.createWorkspaceMaterialConnectFieldAnswer(field, reply, term, counterpart);
}
}
}
} else {
throw new WorkspaceFieldIOException("Workspace material connect field #" + field.getId() + " points to non-existing field ");
}
}
Aggregations