- synchronized (target) {
- if (target.getAssurancePoints() == 0) {
- String newFname = req.getParameter("fname").trim();
- String newLname = req.getParameter("lname").trim();
- String newMname = req.getParameter("mname").trim();
- String newSuffix = req.getParameter("suffix").trim();
- if (newLname.isEmpty()) {
- throw new GigiApiException("Last name cannot be empty.");
- }
+ String rn = req.getParameter("removeName");
+ if (rn != null) {
+ Name n = Name.getById(Integer.parseInt(rn));
+ if (n.getOwner() != target) {
+ throw new GigiApiException("Cannot remove a name that does not belong to this account.");
+ }
+ if (n.equals(target.getPreferredName())) {
+ throw new GigiApiException("Cannot remove the account's preferred name.");
+ }
+ n.remove();
+ return true;
+ }
+ String dn = req.getParameter("deprecateName");
+ if (dn != null) {
+ Name n = Name.getById(Integer.parseInt(dn));
+ if (n.getOwner() != target) {
+ throw new GigiApiException("Cannot deprecate a name that does not belong to this account.");
+ }
+ if (n.equals(target.getPreferredName())) {
+ throw new GigiApiException("Cannot deprecate the account's preferred name.");
+ }
+ n.deprecate();
+ return true;
+ }
+ String pn = req.getParameter("preferred");
+ if (pn != null) {
+ Name n = Name.getById(Integer.parseInt(pn));
+ target.setPreferredName(n);
+ return true;
+ }
+
+ String action = req.getParameter("action");
+ if ("addName".equals(action)) {
+ ni.update(req);
+ ni.createName(target);
+ return true;
+ }
+ if ("updateDoB".equals(action)) {
+ ds.update(req);
+ target.setDoB(ds.getDate());
+ }
+ if ("updateResidenceCountry".equals(action)) {
+ cs.update(req);
+ target.setResidenceCountry(cs.getCountry());
+ }