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