Search in sources :

Example 1 with QuerySorterField

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

the class QuerySorterFieldController method updateQuerySorterField.

public QuerySorterField updateQuerySorterField(Material material, MaterialField field, boolean removeAnswers) throws MaterialFieldMetaParsingExeption {
    ObjectMapper objectMapper = new ObjectMapper();
    SorterFieldMeta sorterFieldMeta;
    try {
        sorterFieldMeta = objectMapper.readValue(field.getContent(), SorterFieldMeta.class);
    } catch (IOException e) {
        throw new MaterialFieldMetaParsingExeption("Could not parse sorter field meta", e);
    }
    QuerySorterField queryField = querySorterFieldDAO.findByMaterialAndName(material, sorterFieldMeta.getName());
    // -> fi.otavanopisto.muikku.plugins.workspace.QueryFieldChangeListener
    queryFieldUpdateEvent.fire(new QueryFieldUpdateEvent(queryField, field, removeAnswers));
    return queryField;
}
Also used : SorterFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SorterFieldMeta) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryFieldUpdateEvent(fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent) QuerySorterField(fi.otavanopisto.muikku.plugins.material.model.QuerySorterField)

Example 2 with QuerySorterField

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

the class QuerySorterFieldDAO method create.

public QuerySorterField create(Material material, String name) {
    QuerySorterField querySorterField = new QuerySorterField();
    querySorterField.setMaterial(material);
    querySorterField.setName(name);
    return persist(querySorterField);
}
Also used : QuerySorterField(fi.otavanopisto.muikku.plugins.material.model.QuerySorterField)

Example 3 with QuerySorterField

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

the class QuerySorterFieldDAO method findByMaterialAndName.

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

Aggregations

QuerySorterField (fi.otavanopisto.muikku.plugins.material.model.QuerySorterField)3 QueryFieldUpdateEvent (fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent)1 SorterFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SorterFieldMeta)1 IOException (java.io.IOException)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1