Search in sources :

Example 1 with DataGridTemplateUnitException

use of com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException in project metalnx-web by irods-contrib.

the class TemplateController method addFieldToCurrentTemplate.

@RequestMapping(value = "/addFieldToCurrentTemplate")
public String addFieldToCurrentTemplate(final Model model, @ModelAttribute final TemplateFieldForm templateFieldForm) {
    updateAddTemplateFieldsList();
    boolean isAddFieldsEmpty = false;
    try {
        List<DataGridTemplateField> existingTemplateFields = templateService.listTemplateFields(templateFieldForm.getTemplateName());
        DataGridTemplateField newDataGridField = mapTempFieldFormToDataGridTemp(templateFieldForm);
        List<TemplateFieldForm> templateFields = new ArrayList<TemplateFieldForm>();
        TemplateFieldForm newField = this.mapDataGridTempToFieldForm(newDataGridField, addTemplateFields.size());
        templateFields.add(newField);
        if (addTemplateFields.isEmpty()) {
            isAddFieldsEmpty = true;
        }
        // prevent an AVU from being added twice to a template
        if (!addTemplateFields.contains(newField) || addTemplateFields.contains(newField) && newField.getValue().equals("")) {
            addTemplateFields.add(newField.getFormListPosition(), newField);
        }
        model.addAttribute("templateFields", templateFields);
        model.addAttribute("resultSize", templateFields.size());
        model.addAttribute("foundTemplateFields", templateFields.size() > 0);
        if (isAddFieldsEmpty && existingTemplateFields.isEmpty()) {
            return "template/templateFieldList";
        }
    } catch (DataGridTemplateAttrException e) {
        logger.error(e.getMessage());
    } catch (DataGridTemplateValueException e) {
        logger.error(e.getMessage());
    } catch (DataGridTemplateUnitException e) {
        logger.error(e.getMessage());
    }
    return "template/templateFieldList :: avuRow";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) ArrayList(java.util.ArrayList) DataGridTemplateUnitException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException) DataGridTemplateValueException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) DataGridTemplateAttrException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridTemplateField (com.emc.metalnx.core.domain.entity.DataGridTemplateField)1 DataGridTemplateAttrException (com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException)1 DataGridTemplateUnitException (com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException)1 DataGridTemplateValueException (com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException)1 TemplateFieldForm (com.emc.metalnx.modelattribute.template.field.TemplateFieldForm)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1