Search in sources :

Example 1 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialOrganizerFieldCreated.

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

Example 2 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialFileFieldCreated.

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

Example 3 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialMultiSelectFieldCreated.

// Multi-select field
public void onHtmlMaterialMultiSelectFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.multiselect")) {
        ObjectMapper objectMapper = new ObjectMapper();
        MultiSelectFieldMeta multiSelectFieldMeta;
        try {
            multiSelectFieldMeta = objectMapper.readValue(event.getField().getContent(), MultiSelectFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse select field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), multiSelectFieldMeta.getName());
        if (queryField != null) {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
        QueryMultiSelectField queryMultiSelectField = queryMultiSelectFieldController.createQueryMultiSelectField(event.getMaterial(), multiSelectFieldMeta.getName());
        for (MultiSelectFieldOptionMeta multiSelectFieldOptionMeta : multiSelectFieldMeta.getOptions()) {
            queryMultiSelectFieldController.createQueryMultiSelectFieldOption(queryMultiSelectField, multiSelectFieldOptionMeta.getName(), multiSelectFieldOptionMeta.getText());
        }
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) QueryMultiSelectField(fi.otavanopisto.muikku.plugins.material.model.QueryMultiSelectField) IOException(java.io.IOException) MultiSelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) MultiSelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta)

Example 4 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialSorterFieldCreated.

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

Example 5 with QueryField

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialFieldDeleted.

// Delete
public void onHtmlMaterialFieldDeleted(@Observes HtmlMaterialFieldDeleteEvent event) {
    HtmlMaterial material = event.getMaterial();
    QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(material, event.getField().getName());
    if (queryField != null) {
        queryFieldController.deleteQueryField(queryField, event.getRemoveAnswers());
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)

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