/** Validate the typed username */ private Member validateTo(final MobileActionContext context) { final MobileDoPaymentForm form = context.getForm(); final String username = form.getUsername(); if (StringUtils.isEmpty(username)) { throw new MobileException("errors.required", context.message("mobile.payment.username")); } User user; try { user = elementService.loadUser(username, User.Relationships.ELEMENT); if (!(user instanceof MemberUser) || context.getUser().equals(user)) { throw new Exception(); } } catch (final Exception e) { throw new MobileException("errors.invalid", context.message("mobile.payment.username")); } return (Member) user.getElement(); }
/** Validate the typed amount */ private BigDecimal validateAmount(final MobileActionContext context) { final MobileDoPaymentForm form = context.getForm(); final UnitsConverter converter = getUnitsConverter(context); BigDecimal amount = null; try { amount = converter.valueOf(form.getAmount()); } catch (final Exception e) { throw new MobileException("errors.invalid", context.message("mobile.payment.amount")); } if (amount == null) { throw new MobileException("errors.required", context.message("mobile.payment.amount")); } if (amount.compareTo(paymentService.getMinimumPayment()) == -1) { throw new MobileException("errors.invalid", context.message("mobile.payment.amount")); } return amount; }
/** Validate the typed description */ private String validateDescription(final MobileActionContext context) { final MobileDoPaymentForm form = context.getForm(); return StringUtils.trimToNull(form.getDescription()); }