@Override
 protected void executeQuery(final ActionContext context, final QueryParameters queryParameters) {
   final ScheduledPaymentQuery query = (ScheduledPaymentQuery) queryParameters;
   List<ScheduledPayment> payments = null;
   if (LoggedUser.isAdministrator()) {
     query.setSearchType(SearchType.OUTGOING);
   }
   if (query.getOwner() instanceof SystemAccountOwner) {
     payments = scheduledPaymentService.searchSystem(query);
   } else {
     payments = scheduledPaymentService.search(query);
   }
   context.getRequest().setAttribute("payments", payments);
 }
  @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;
  }