diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/ExhibitionConfigurationController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/ExhibitionConfigurationController.java index 22fc120d6..52b2518e4 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/ExhibitionConfigurationController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/ExhibitionConfigurationController.java @@ -5,11 +5,14 @@ import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; import org.javers.common.collections.Arrays; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -25,6 +28,7 @@ import edu.asu.diging.vspace.core.model.impl.Exhibition; import edu.asu.diging.vspace.core.services.IExhibitionManager; import edu.asu.diging.vspace.core.services.ISpaceManager; +import edu.asu.diging.vspace.web.staff.forms.ExhibitionConfigurationForm; @Controller public class ExhibitionConfigurationController { @@ -77,19 +81,26 @@ public String showExhibitions(Model model) { * @param spaceParam * @param attributes * @return - */ + */ @RequestMapping(value = "/staff/exhibit/config", method = RequestMethod.POST) public RedirectView createOrUpdateExhibition(HttpServletRequest request, @RequestParam(required = false, name = "exhibitionParam") String exhibitID, - @RequestParam("spaceParam") String spaceID, @RequestParam("title") String title, - @RequestParam("exhibitMode") ExhibitionModes exhibitMode, - @RequestParam(value = "customMessage", required = false, defaultValue = "") String customMessage, - @RequestParam("exhibitLanguage") List languages, - @RequestParam("defaultExhibitLanguage") String defaultLanguage, + @RequestParam("spaceParam") String spaceID, + @Valid @ModelAttribute("exhibitionConfigurationForm") ExhibitionConfigurationForm exhibitionConfigForm, + BindingResult result, RedirectAttributes attributes) throws IOException { - - ISpace startSpace = spaceManager.getSpace(spaceID); - + if(result.hasErrors()) { + attributes.addAttribute("showAlert", true); + attributes.addAttribute("alertType", "danger"); + attributes.addAttribute("message", result.getFieldError().getDefaultMessage()); + return new RedirectView(request.getContextPath() + "/staff/exhibit/config"); + } + String title = exhibitionConfigForm.getTitle(); + ExhibitionModes exhibitMode = exhibitionConfigForm.getExhibitionMode(); + List languages = exhibitionConfigForm.getExhibitLanguage(); + String defaultLanguage = exhibitionConfigForm.getDefaultExhibitLanguage(); + String customMessage = exhibitionConfigForm.getCustomMessage(); + ISpace startSpace = spaceManager.getSpace(spaceID); Exhibition exhibition; if (exhibitID == null || exhibitID.isEmpty()) { exhibition = (Exhibition) exhibitFactory.createExhibition(); diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/forms/ExhibitionConfigurationForm.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/forms/ExhibitionConfigurationForm.java new file mode 100644 index 000000000..f17a171d7 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/forms/ExhibitionConfigurationForm.java @@ -0,0 +1,64 @@ +package edu.asu.diging.vspace.web.staff.forms; + +import java.util.List; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import edu.asu.diging.vspace.core.model.ExhibitionModes; + +public class ExhibitionConfigurationForm { + + private String customMessage; + + private String defaultExhibitLanguage; + + @NotEmpty(message = "Please select exhibition languages") + private List exhibitLanguage; + + @NotNull(message = "Please select exhibition mode") + private ExhibitionModes exhibitionMode; + + @NotEmpty(message = "Please enter title") + private String title; + + public String getCustomMessage() { + return customMessage; + } + + public void setCustomMessage(String customMessage) { + this.customMessage = customMessage; + } + + public String getDefaultExhibitLanguage() { + return defaultExhibitLanguage; + } + + public void setDefaultExhibitLanguage(String defaultExhibitLanguage) { + this.defaultExhibitLanguage = defaultExhibitLanguage; + } + + public List getExhibitLanguage() { + return exhibitLanguage; + } + + public void setExhibitLanguage(List exhibitLanguage) { + this.exhibitLanguage = exhibitLanguage; + } + + public ExhibitionModes getExhibitionMode() { + return exhibitionMode; + } + + public void setExhibitionMode(ExhibitionModes exhibitionMode) { + this.exhibitionMode = exhibitionMode; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/exhibit/config.html b/vspace/src/main/webapp/WEB-INF/views/staff/exhibit/config.html index 9570eec5f..919368a81 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/exhibit/config.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/exhibit/config.html @@ -1,15 +1,22 @@ + +