@Override
    public Object transform(final Object at) {
      final AccountType accountType = (AccountType) at;
      final Map<String, Object> map = new HashMap<String, Object>();

      final TransferTypeQuery ttQuery = new TransferTypeQuery();
      ttQuery.setPageForCount();
      ttQuery.setContext(TransactionContext.PAYMENT);
      ttQuery.setFromOwner(from);
      ttQuery.setToOwner(to);
      ttQuery.setToAccountType(accountType);
      ttQuery.setSchedulable(true);
      if (from instanceof Member) {
        final Member member =
            elementService.load(((Member) from).getId(), Element.Relationships.GROUP);
        ttQuery.setGroup(member.getGroup());
      }
      final int count = PageHelper.getTotalCount(transferTypeService.search(ttQuery));

      map.put("id", accountType.getId());
      map.put("name", accountType.getName());
      map.put("currency", accountType.getCurrency());
      map.put("allowsScheduledPayments", count > 0);

      return map;
    }
Exemplo n.º 2
0
  @Override
  protected ActionForward handleValidation(final ActionContext context) {
    try {
      final Invoice invoice = resolveInvoice(context);
      invoiceService.validate(invoice);

      // Retrive and fetch the destination account type
      AccountType accountType = invoice.getDestinationAccountType();
      if (accountType == null) {
        final TransferType tt =
            transferTypeService.load(
                invoice.getTransferType().getId(),
                RelationshipHelper.nested(
                    TransferType.Relationships.TO, AccountType.Relationships.CURRENCY));
        accountType = tt.getTo();
      } else {
        accountType = accountTypeService.load(accountType.getId());
      }

      // If the validation passed, resolve the confirmation message
      final LocalSettings localSettings = settingsService.getLocalSettings();
      final UnitsConverter unitsConverter =
          localSettings.getUnitsConverter(accountType.getCurrency().getPattern());

      final AccountOwner toOwner = invoice.getTo();
      final boolean toSystem = toOwner instanceof SystemAccountOwner;

      // Retrieve the message arguments
      String to;
      if (toSystem) {
        to = localSettings.getApplicationUsername();
      } else {
        final Member member = elementService.load(((Member) toOwner).getId());
        to = member.getName();
      }
      final String amount = unitsConverter.toString(invoice.getAmount());

      final String confirmationKey = "invoice.sendConfirmationMessage";

      final Map<String, Object> fields = new HashMap<String, Object>();
      fields.put("confirmationMessage", context.message(confirmationKey, to, amount));

      responseHelper.writeStatus(context.getResponse(), ResponseHelper.Status.SUCCESS, fields);

    } catch (final ValidationException e) {
      responseHelper.writeValidationErrors(context.getResponse(), e);
    }
    return null;
  }