Ejemplo n.º 1
0
  @Override
  protected QueryParameters prepareForm(final ActionContext context) {
    final SearchScheduledPaymentsForm form = context.getForm();
    final HttpServletRequest request = context.getRequest();

    final ScheduledPaymentQuery query = getDataBinder().readFromString(form.getQuery());
    query.fetch(
        ScheduledPayment.Relationships.TRANSFERS,
        RelationshipHelper.nested(
            ScheduledPayment.Relationships.FROM, MemberAccount.Relationships.MEMBER),
        RelationshipHelper.nested(
            ScheduledPayment.Relationships.TO, MemberAccount.Relationships.MEMBER));

    // Account owner
    AccountOwner owner = null;
    if (form.getMemberId() > 0) {
      owner = (Member) elementService.load(form.getMemberId());
      request.setAttribute("memberId", form.getMemberId());
    } else {
      // An admin or member or an operator searching his own scheduled payments
      owner = context.getAccountOwner();
    }
    query.setOwner(owner);

    List<? extends AccountType> accountTypes;
    if (context.isAdmin() && owner instanceof SystemAccountOwner) {
      final SystemAccountTypeQuery satq = new SystemAccountTypeQuery();
      accountTypes = accountTypeService.search(satq);
    } else {
      final MemberAccountTypeQuery matq = new MemberAccountTypeQuery();
      matq.setOwner((Member) owner);
      accountTypes = accountTypeService.search(matq);
    }
    request.setAttribute("accountTypes", accountTypes);

    if (query.getMember() != null) {
      final Member member = getFetchService().fetch(query.getMember(), Element.Relationships.USER);
      query.setMember(member);
    }
    if (query.getStatusList() == null) {
      query.setStatusGroup(ScheduledPaymentQuery.StatusGroup.OPEN);
      form.setQuery("statusGroup", ScheduledPaymentQuery.StatusGroup.OPEN);
    }

    RequestHelper.storeEnum(request, ScheduledPaymentQuery.SearchType.class, "searchTypes");
    RequestHelper.storeEnum(request, ScheduledPaymentQuery.StatusGroup.class, "statusGroups");
    request.setAttribute("accountOwner", owner);
    return query;
  }
Ejemplo n.º 2
0
 /** 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();
 }