Search in sources :

Example 6 with QueryConnectFieldCounterpart

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart 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 ");
    }
}
Also used : WorkspaceMaterialConnectFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer) QueryConnectFieldCounterpart(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryConnectField(fi.otavanopisto.muikku.plugins.material.model.QueryConnectField)

Aggregations

QueryConnectFieldCounterpart (fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart)6 QueryConnectFieldTerm (fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm)3 QueryConnectField (fi.otavanopisto.muikku.plugins.material.model.QueryConnectField)2 IOException (java.io.IOException)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 QueryFieldDeleteEvent (fi.otavanopisto.muikku.plugins.material.events.QueryFieldDeleteEvent)1 ConnectFieldConnectionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldConnectionMeta)1 ConnectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta)1 ConnectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldOptionMeta)1 QueryField (fi.otavanopisto.muikku.plugins.material.model.QueryField)1 WorkspaceMaterialConnectFieldAnswer (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer)1 HashMap (java.util.HashMap)1 TypeReference (org.codehaus.jackson.type.TypeReference)1