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