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");
}
}
}
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());
}
}
}
Aggregations