Search in sources :

Example 1 with QueryConnectFieldCounterpart

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

the class QueryConnectFieldCounterpartDAO method findByFieldAndName.

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

Example 2 with QueryConnectFieldCounterpart

use of fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart 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 3 with QueryConnectFieldCounterpart

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

the class QueryConnectFieldCounterpartDAO method listByField.

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

Example 4 with QueryConnectFieldCounterpart

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

the class QueryConnectFieldCounterpartDAO method create.

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

Example 5 with QueryConnectFieldCounterpart

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

the class QueryConnectFieldController method deleteQueryConnectField.

public void deleteQueryConnectField(QueryConnectField queryField, boolean removeAnswers) {
    queryFieldDeleteEvent.fire(new QueryFieldDeleteEvent(queryField, removeAnswers));
    for (QueryConnectFieldTerm term : listConnectFieldTermsByField(queryField)) {
        queryConnectFieldTermDAO.delete(term);
    }
    for (QueryConnectFieldCounterpart counterpart : listQueryConnectFieldCounterpartByField(queryField)) {
        queryConnectFieldCounterpartDAO.delete(counterpart);
    }
    queryConnectFieldDAO.delete(queryField);
}
Also used : QueryConnectFieldCounterpart(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldCounterpart) QueryFieldDeleteEvent(fi.otavanopisto.muikku.plugins.material.events.QueryFieldDeleteEvent) QueryConnectFieldTerm(fi.otavanopisto.muikku.plugins.material.model.QueryConnectFieldTerm)

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