Search in sources :

Example 1 with QueryConnectFieldTerm

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.

the class QueryConnectFieldTermDAO method findByFieldAndName.

public QueryConnectFieldTerm findByFieldAndName(QueryConnectField field, String name) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<QueryConnectFieldTerm> criteria = criteriaBuilder.createQuery(QueryConnectFieldTerm.class);
    Root<QueryConnectFieldTerm> root = criteria.from(QueryConnectFieldTerm.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(QueryConnectFieldTerm_.field), field), criteriaBuilder.equal(root.get(QueryConnectFieldTerm_.name), name)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm)

Example 2 with QueryConnectFieldTerm

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm 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);
    }
}
Also used : WorkspaceMaterialConnectFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer) HashMap(java.util.HashMap) 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)

Example 3 with QueryConnectFieldTerm

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.

the class HtmlMaterialFieldChangeListener method onHtmlMaterialConnectFieldCreated.

// Connect field
public void onHtmlMaterialConnectFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.connect")) {
        ObjectMapper objectMapper = new ObjectMapper();
        ConnectFieldMeta connectFieldMeta;
        try {
            connectFieldMeta = objectMapper.readValue(event.getField().getContent(), ConnectFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse connect field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), connectFieldMeta.getName());
        if (queryField != null) {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
        QueryConnectField field = queryConnectFieldController.createQueryConnectField(event.getMaterial(), connectFieldMeta.getName());
        Map<String, QueryConnectFieldTerm> terms = new HashMap<String, QueryConnectFieldTerm>();
        Map<String, QueryConnectFieldCounterpart> counterparts = new HashMap<String, QueryConnectFieldCounterpart>();
        for (ConnectFieldOptionMeta option : connectFieldMeta.getFields()) {
            terms.put(option.getName(), queryConnectFieldController.createConnectFieldTerm(field, option.getName(), option.getText(), null));
        }
        for (ConnectFieldOptionMeta option : connectFieldMeta.getCounterparts()) {
            counterparts.put(option.getName(), queryConnectFieldController.createConnectFieldCounterpart(field, option.getName(), option.getText()));
        }
        for (ConnectFieldConnectionMeta connection : connectFieldMeta.getConnections()) {
            terms.get(connection.getField()).setCounterpart(counterparts.get(connection.getCounterpart()));
        }
    }
}
Also used : ConnectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldMeta) HashMap(java.util.HashMap) QueryConnectFieldCounterpart(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart) ConnectFieldConnectionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldConnectionMeta) IOException(java.io.IOException) QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm) ConnectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.ConnectFieldOptionMeta) QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryConnectField(fi.otavanopisto.muikku.plugins.material.model.QueryConnectField)

Example 4 with QueryConnectFieldTerm

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.

the class QueryConnectFieldTermDAO method create.

public QueryConnectFieldTerm create(QueryConnectField field, String name, String text, QueryConnectFieldCounterpart counterpart) {
    QueryConnectFieldTerm queryConnectFieldTerm = new QueryConnectFieldTerm();
    queryConnectFieldTerm.setName(name);
    queryConnectFieldTerm.setText(text);
    queryConnectFieldTerm.setField(field);
    queryConnectFieldTerm.setCounterpart(counterpart);
    return persist(queryConnectFieldTerm);
}
Also used : QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm)

Example 5 with QueryConnectFieldTerm

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm in project muikku by otavanopisto.

the class QueryConnectFieldTermDAO method listByField.

public List<QueryConnectFieldTerm> listByField(QueryConnectField field) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<QueryConnectFieldTerm> criteria = criteriaBuilder.createQuery(QueryConnectFieldTerm.class);
    Root<QueryConnectFieldTerm> root = criteria.from(QueryConnectFieldTerm.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(QueryConnectFieldTerm_.field), field));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm)

Aggregations

QueryConnectFieldTerm (fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm)7 QueryConnectField (fi.otavanopisto.muikku.plugins.material.model.QueryConnectField)3 QueryConnectFieldCounterpart (fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart)3 IOException (java.io.IOException)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 WorkspaceMaterialConnectFieldAnswer (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialConnectFieldAnswer)2 HashMap (java.util.HashMap)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)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 TypeReference (org.codehaus.jackson.type.TypeReference)1