Search in sources :

Example 1 with FileFieldMeta

use of fi.otavanopisto.muikku.plugins.material.fieldmeta.FileFieldMeta 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 2 with FileFieldMeta

use of fi.otavanopisto.muikku.plugins.material.fieldmeta.FileFieldMeta in project muikku by otavanopisto.

the class FieldElementsHandler method handleFileField.

@Override
public Node handleFileField(Document ownerDocument, String paramName, String help, String hint) throws DeusNexException {
    FileFieldMeta fileFieldData = fieldTranslator.translateFileField(paramName, help, hint);
    Element inputElement = ownerDocument.createElement("input");
    inputElement.setAttribute("type", "file");
    inputElement.setAttribute("name", paramName);
    // TODO Auto-generated method stub
    return wrapWithObjectElement(ownerDocument, inputElement, fileFieldData);
}
Also used : Element(org.w3c.dom.Element) FileFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.FileFieldMeta)

Aggregations

FileFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.FileFieldMeta)2 QueryField (fi.otavanopisto.muikku.plugins.material.model.QueryField)1 IOException (java.io.IOException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 Element (org.w3c.dom.Element)1