use of fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent in project muikku by otavanopisto.
the class QuerySelectFieldController method updateQuerySelectField.
public QuerySelectField updateQuerySelectField(Material material, MaterialField field, boolean removeAnswers) throws MaterialFieldMetaParsingExeption {
// Field JSON to metadata object
ObjectMapper objectMapper = new ObjectMapper();
SelectFieldMeta selectFieldMeta;
try {
selectFieldMeta = objectMapper.readValue(field.getContent(), SelectFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse select field meta", e);
}
QuerySelectField queryField = querySelectFieldDAO.findByMaterialAndName(material, selectFieldMeta.getName());
// -> fi.otavanopisto.muikku.plugins.workspace.QueryFieldChangeListener
queryFieldUpdateEvent.fire(new QueryFieldUpdateEvent(queryField, field, removeAnswers));
List<QuerySelectFieldOption> oldOptions = querySelectFieldOptionDAO.listByField(queryField);
List<SelectFieldOptionMeta> newOptions = selectFieldMeta.getOptions();
for (SelectFieldOptionMeta newOption : newOptions) {
QuerySelectFieldOption correspondingOption = findOptionByName(oldOptions, newOption.getName());
if (correspondingOption == null) {
// New options
createQuerySelectFieldOption(queryField, newOption.getName(), newOption.getText());
} else {
// Modified options
if (!StringUtils.equals(correspondingOption.getText(), newOption.getText())) {
updateQuerySelectFieldOptionText(correspondingOption, newOption.getText());
}
oldOptions.remove(correspondingOption);
}
}
// Removed options
for (QuerySelectFieldOption removedOption : oldOptions) {
deleteQuerySelectFieldOption(removedOption);
}
return queryField;
}
use of fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent in project muikku by otavanopisto.
the class QuerySorterFieldController method updateQuerySorterField.
public QuerySorterField updateQuerySorterField(Material material, MaterialField field, boolean removeAnswers) throws MaterialFieldMetaParsingExeption {
ObjectMapper objectMapper = new ObjectMapper();
SorterFieldMeta sorterFieldMeta;
try {
sorterFieldMeta = objectMapper.readValue(field.getContent(), SorterFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse sorter field meta", e);
}
QuerySorterField queryField = querySorterFieldDAO.findByMaterialAndName(material, sorterFieldMeta.getName());
// -> fi.otavanopisto.muikku.plugins.workspace.QueryFieldChangeListener
queryFieldUpdateEvent.fire(new QueryFieldUpdateEvent(queryField, field, removeAnswers));
return queryField;
}
use of fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent in project muikku by otavanopisto.
the class QueryMultiSelectFieldController method updateQueryMultiSelectField.
public QueryMultiSelectField updateQueryMultiSelectField(Material material, MaterialField field, boolean removeAnswers) throws MaterialFieldMetaParsingExeption {
// Field JSON to metadata object
ObjectMapper objectMapper = new ObjectMapper();
MultiSelectFieldMeta multiSelectFieldMeta;
try {
multiSelectFieldMeta = objectMapper.readValue(field.getContent(), MultiSelectFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse select field meta", e);
}
QueryMultiSelectField queryField = queryMultiSelectFieldDAO.findByMaterialAndName(material, multiSelectFieldMeta.getName());
// -> fi.otavanopisto.muikku.plugins.workspace.QueryFieldChangeListener
queryFieldUpdateEvent.fire(new QueryFieldUpdateEvent(queryField, field, removeAnswers));
List<QueryMultiSelectFieldOption> oldOptions = queryMultiSelectFieldOptionDAO.listByField(queryField);
List<MultiSelectFieldOptionMeta> newOptions = multiSelectFieldMeta.getOptions();
for (MultiSelectFieldOptionMeta newOption : newOptions) {
QueryMultiSelectFieldOption correspondingOption = findOptionByName(oldOptions, newOption.getName());
if (correspondingOption == null) {
// New options
createQueryMultiSelectFieldOption(queryField, newOption.getName(), newOption.getText());
} else {
// Modified options
if (!StringUtils.equals(correspondingOption.getText(), newOption.getText())) {
updateQueryMultiSelectFieldOptionText(correspondingOption, newOption.getText());
}
oldOptions.remove(correspondingOption);
}
}
// Removed options
for (QueryMultiSelectFieldOption removedOption : oldOptions) {
deleteQueryMultiSelectFieldOption(removedOption);
}
return queryField;
}
use of fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent in project muikku by otavanopisto.
the class QueryOrganizerFieldController method updateQueryOrganizerField.
public QueryOrganizerField updateQueryOrganizerField(Material material, MaterialField field, boolean removeAnswers) throws MaterialFieldMetaParsingExeption {
ObjectMapper objectMapper = new ObjectMapper();
OrganizerFieldMeta organizerFieldMeta;
try {
organizerFieldMeta = objectMapper.readValue(field.getContent(), OrganizerFieldMeta.class);
} catch (IOException e) {
throw new MaterialFieldMetaParsingExeption("Could not parse select field meta", e);
}
QueryOrganizerField queryField = queryOrganizerFieldDAO.findByMaterialAndName(material, organizerFieldMeta.getName());
// -> fi.otavanopisto.muikku.plugins.workspace.QueryFieldChangeListener
queryFieldUpdateEvent.fire(new QueryFieldUpdateEvent(queryField, field, removeAnswers));
return queryField;
}
Aggregations