- public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
- o = req.getParameter("O");
- c = req.getParameter("C");
- st = req.getParameter("ST");
- l = req.getParameter("L");
- email = req.getParameter("contact");
- if (result != null) {
- result.update(o, c, st, l);
- return true;
+ public SubmissionResult submit(HttpServletRequest req) throws GigiApiException {
+ String action = req.getParameter("action");
+ if (action == null) {
+ throw new GigiApiException("No action given.");
+ }
+
+ if (action.equals("new")) {
+ checkCertData(req);
+ checkOrganisationData(req);
+ Organisation ne = new Organisation(o, cs.getCountry(), st, l, email, optionalName, postalAddress, LoginPage.getUser(req));
+ result = ne;
+ } else if (action.equals("updateOrganisationData")) {
+ checkOrganisationData(req);
+ result.updateOrgData(email, optionalName, postalAddress);
+ } else if (action.equals("updateCertificateData")) {
+ checkCertData(req);
+ result.updateCertData(o, cs.getCountry(), st, l);
+ } else {
+ throw new GigiApiException("No valid action given.");
+ }
+ return new RedirectResult(ViewOrgPage.DEFAULT_PATH + "/" + result.getId());
+ }
+
+ private void checkOrganisationData(HttpServletRequest req) throws GigiApiException {
+ email = extractParam(req, "contact");
+ optionalName = extractParam(req, "optionalName");
+ postalAddress = extractParam(req, "postalAddress");
+ if ( !EmailProvider.isValidMailAddress(email)) {
+ throw new GigiApiException("Contact email is not a valid email address");