Search in sources :

Example 1 with DataGridTooLongTemplateNameException

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

the class TemplateController method addNewTemplate.

@RequestMapping(value = "add/action/")
public String addNewTemplate(final Model model, @ModelAttribute final MetadataTemplateForm templateForm, final RedirectAttributes redirectAttributes) {
    DataGridTemplate newTemplate = null;
    try {
        newTemplate = new DataGridTemplate();
        newTemplate.setTemplateName(templateForm.getTemplateName());
        newTemplate.setDescription(templateForm.getDescription());
        newTemplate.setUsageInformation(templateForm.getUsageInformation());
        newTemplate.setOwner(loggedUserUtils.getLoggedDataGridUser().getUsername());
        newTemplate.setAccessType(templateForm.getAccessType().toString());
        long templateID = templateService.createTemplate(newTemplate);
        if (templateID > 0) {
            redirectAttributes.addFlashAttribute("templateAddedSuccessfully", newTemplate.getTemplateName());
            newTemplate.setId(templateID);
            // adding all fields to the template
            for (TemplateFieldForm tempFieldForm : addTemplateFields) {
                DataGridTemplateField dataGridTempField = mapTempFieldFormToDataGridTemp(tempFieldForm);
                dataGridTempField.setTemplate(newTemplate);
                templateFieldService.createTemplateField(dataGridTempField);
            }
            // reseting the temporary fields to be added and removed from a
            // template
            addTemplateFields = new ArrayList<TemplateFieldForm>();
            removeTemplateFields = new ArrayList<TemplateFieldForm>();
            return "redirect:/templates/";
        }
    } catch (DataGridTooLongTemplateNameException e) {
        redirectAttributes.addFlashAttribute("templateNotAddedSuccessfully", true);
        redirectAttributes.addFlashAttribute("tooLongTemplateName", true);
    } catch (Exception e) {
        redirectAttributes.addFlashAttribute("templateNotAddedSuccessfully", true);
    }
    return "redirect:/templates/add/";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) DataGridTooLongTemplateNameException(com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException) DataGridTemplateUnitException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JAXBException(javax.xml.bind.JAXBException) DataGridTemplateValueException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridTooLongTemplateNameException(com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException) IOException(java.io.IOException) DataGridTemplateAttrException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridTemplate (com.emc.metalnx.core.domain.entity.DataGridTemplate)1 DataGridTemplateField (com.emc.metalnx.core.domain.entity.DataGridTemplateField)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)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 DataGridTooLongTemplateNameException (com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException)1 TemplateFieldForm (com.emc.metalnx.modelattribute.template.field.TemplateFieldForm)1 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1