public DataBinder<CreditLimitDTO> getDataBinder() {
    if (dataBinder == null) {

      final LocalSettings localSettings = settingsService.getLocalSettings();

      final PropertyBinder<AccountType> keyBinder =
          PropertyBinder.instance(AccountType.class, "accountTypeIds");
      final PropertyBinder<BigDecimal> limitValueBinder =
          PropertyBinder.instance(
              BigDecimal.class,
              "newCreditLimits",
              localSettings.getNumberConverter().negativeToAbsolute());
      final PropertyBinder<BigDecimal> upperLimitValueBinder =
          PropertyBinder.instance(
              BigDecimal.class, "newUpperCreditLimits", localSettings.getNumberConverter());

      final MapBinder<AccountType, BigDecimal> limitBinder =
          MapBinder.instance(keyBinder, limitValueBinder);
      final MapBinder<AccountType, BigDecimal> upperLimitBinder =
          MapBinder.instance(keyBinder, upperLimitValueBinder);

      final BeanBinder<CreditLimitDTO> binder = BeanBinder.instance(CreditLimitDTO.class);
      binder.registerBinder("limitPerType", limitBinder);
      binder.registerBinder("upperLimitPerType", upperLimitBinder);
      dataBinder = binder;
    }
    return dataBinder;
  }
Exemple #2
0
 @Override
 protected void appendVariableValues(
     final Map<String, Object> variables, final LocalSettings localSettings) {
   variables.put("grant_date", localSettings.getDateConverter().toString(transfer.getDate()));
   variables.put(
       "amount",
       localSettings
           .getUnitsConverter(transfer.getTo().getType().getCurrency().getPattern())
           .toString(transfer.getAmount()));
 }
  @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;
  }
  public DataBinder<Invoice> getDataBinder() {
    if (dataBinder == null) {
      final BeanBinder<? extends CustomFieldValue> customValueBinder =
          BeanBinder.instance(PaymentCustomFieldValue.class);
      customValueBinder.registerBinder(
          "field", PropertyBinder.instance(PaymentCustomField.class, "field"));
      customValueBinder.registerBinder(
          "value", PropertyBinder.instance(String.class, "value", HtmlConverter.instance()));

      final LocalSettings localSettings = settingsService.getLocalSettings();
      final BeanBinder<Invoice> binder = BeanBinder.instance(Invoice.class);
      binder.registerBinder(
          "from",
          PropertyBinder.instance(AccountOwner.class, "from", AccountOwnerConverter.instance()));
      binder.registerBinder(
          "to",
          PropertyBinder.instance(AccountOwner.class, "to", AccountOwnerConverter.instance()));
      binder.registerBinder(
          "transferType",
          PropertyBinder.instance(
              TransferType.class, "type", ReferenceConverter.instance(TransferType.class)));
      binder.registerBinder(
          "destinationAccountType",
          PropertyBinder.instance(
              AccountType.class, "destType", ReferenceConverter.instance(AccountType.class)));
      binder.registerBinder(
          "amount",
          PropertyBinder.instance(BigDecimal.class, "amount", localSettings.getNumberConverter()));
      binder.registerBinder("description", PropertyBinder.instance(String.class, "description"));
      binder.registerBinder(
          "customValues", BeanCollectionBinder.instance(customValueBinder, "customValues"));

      final BeanBinder<InvoicePayment> scheduledPayments =
          BeanBinder.instance(InvoicePayment.class);
      scheduledPayments.registerBinder(
          "date",
          PropertyBinder.instance(Calendar.class, "date", localSettings.getRawDateConverter()));
      scheduledPayments.registerBinder(
          "amount",
          PropertyBinder.instance(BigDecimal.class, "amount", localSettings.getNumberConverter()));
      binder.registerBinder(
          "payments", BeanCollectionBinder.instance(scheduledPayments, "payments"));

      dataBinder = binder;
    }
    return dataBinder;
  }
  public DataBinder<Collection<DefaultBrokerCommissionDTO>> getDataBinder() {
    if (dataBinder == null) {
      final LocalSettings localSettings = settingsService.getLocalSettings();

      final BeanBinder<DefaultBrokerCommissionDTO> beanBinder =
          BeanBinder.instance(DefaultBrokerCommissionDTO.class);
      beanBinder.registerBinder(
          "id", PropertyBinder.instance(Long.class, "id", IdConverter.instance()));
      beanBinder.registerBinder(
          "brokerCommission", PropertyBinder.instance(BrokerCommission.class, "brokerCommission"));
      beanBinder.registerBinder("type", PropertyBinder.instance(Type.class, "type"));
      beanBinder.registerBinder(
          "value",
          PropertyBinder.instance(BigDecimal.class, "value", localSettings.getNumberConverter()));
      beanBinder.registerBinder("count", PropertyBinder.instance(Integer.class, "count"));
      beanBinder.registerBinder(
          "when", PropertyBinder.instance(BrokerCommission.When.class, "when"));

      final BeanCollectionBinder<DefaultBrokerCommissionDTO> defaultBrokerCommissionsBinder =
          BeanCollectionBinder.instance(beanBinder, ArrayList.class);
      dataBinder = defaultBrokerCommissionsBinder;
    }
    return dataBinder;
  }