Search in sources :

Example 16 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialTextFieldCreated.

// Create
// Text field
public void onHtmlMaterialTextFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.text")) {
        ObjectMapper objectMapper = new ObjectMapper();
        TextFieldMeta textFieldMeta;
        try {
            textFieldMeta = objectMapper.readValue(event.getField().getContent(), TextFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse text field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), textFieldMeta.getName());
        if (queryField == null) {
            queryTextFieldController.createQueryTextField(event.getMaterial(), textFieldMeta.getName());
        } else {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) TextFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 17 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialSelectFieldCreated.

// Select field
public void onHtmlMaterialSelectFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.select")) {
        ObjectMapper objectMapper = new ObjectMapper();
        SelectFieldMeta selectFieldMeta;
        try {
            selectFieldMeta = objectMapper.readValue(event.getField().getContent(), SelectFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse select field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), selectFieldMeta.getName());
        if (queryField != null) {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
        QuerySelectField querySelectField = querySelectFieldController.createQuerySelectField(event.getMaterial(), selectFieldMeta.getName());
        for (SelectFieldOptionMeta selectFieldOptionMeta : selectFieldMeta.getOptions()) {
            querySelectFieldController.createQuerySelectFieldOption(querySelectField, selectFieldOptionMeta.getName(), selectFieldOptionMeta.getText());
        }
    }
}
Also used : SelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta) MultiSelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta) QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) IOException(java.io.IOException) QuerySelectField(fi.otavanopisto.muikku.plugins.material.model.QuerySelectField) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta) MultiSelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)

Aggregations

QueryField (fi.otavanopisto.muikku.plugins.material.model.QueryField)17 IOException (java.io.IOException)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 WorkspaceMaterialField (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)6 MultiSelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta)2 MultiSelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 AudioFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.AudioFieldMeta)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 FileFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.FileFieldMeta)1 OrganizerFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.OrganizerFieldMeta)1 SelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta)1 SelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta)1 SorterFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SorterFieldMeta)1 TextFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1