Search in sources :

Example 1 with QueryOrganizerField

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

the class QueryOrganizerFieldController method updateQueryOrganizerField.

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

Example 2 with QueryOrganizerField

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

the class QueryOrganizerFieldDAO method findByMaterialAndName.

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

Example 3 with QueryOrganizerField

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

the class QueryOrganizerFieldDAO method create.

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

Aggregations

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