Search in sources :

Example 1 with QueryFieldUpdateEvent

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;
}
Also used : SelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta) IOException(java.io.IOException) QuerySelectField(fi.otavanopisto.muikku.plugins.material.model.QuerySelectField) QuerySelectFieldOption(fi.otavanopisto.muikku.plugins.material.model.QuerySelectFieldOption) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryFieldUpdateEvent(fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent) SelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta)

Example 2 with QueryFieldUpdateEvent

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;
}
Also used : SorterFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SorterFieldMeta) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryFieldUpdateEvent(fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent) QuerySorterField(fi.otavanopisto.muikku.plugins.material.model.QuerySorterField)

Example 3 with QueryFieldUpdateEvent

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;
}
Also used : 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) QueryFieldUpdateEvent(fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent) MultiSelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta) QueryMultiSelectFieldOption(fi.otavanopisto.muikku.plugins.material.model.QueryMultiSelectFieldOption)

Example 4 with QueryFieldUpdateEvent

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;
}
Also used : OrganizerFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.OrganizerFieldMeta) IOException(java.io.IOException) QueryOrganizerField(fi.otavanopisto.muikku.plugins.material.model.QueryOrganizerField) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) QueryFieldUpdateEvent(fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent)

Aggregations

QueryFieldUpdateEvent (fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent)4 IOException (java.io.IOException)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 MultiSelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta)1 MultiSelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)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 QueryMultiSelectField (fi.otavanopisto.muikku.plugins.material.model.QueryMultiSelectField)1 QueryMultiSelectFieldOption (fi.otavanopisto.muikku.plugins.material.model.QueryMultiSelectFieldOption)1 QueryOrganizerField (fi.otavanopisto.muikku.plugins.material.model.QueryOrganizerField)1 QuerySelectField (fi.otavanopisto.muikku.plugins.material.model.QuerySelectField)1 QuerySelectFieldOption (fi.otavanopisto.muikku.plugins.material.model.QuerySelectFieldOption)1 QuerySorterField (fi.otavanopisto.muikku.plugins.material.model.QuerySorterField)1