private Transfer resolveTransfer(final ActionContext context) { final ScheduledPaymentForm form = context.getForm(); final Long transferId = form.getTransferId(); if (transferId <= 0L) { throw new ValidationException(); } return paymentService.load( transferId, RelationshipHelper.nested(Payment.Relationships.FROM, MemberAccount.Relationships.MEMBER), RelationshipHelper.nested(Payment.Relationships.TO, MemberAccount.Relationships.MEMBER), RelationshipHelper.nested( Transfer.Relationships.SCHEDULED_PAYMENT, ScheduledPayment.Relationships.TRANSFERS)); }
@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; }
@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; }
@Override protected void prepareForm(final ActionContext context) throws Exception { final Transfer transfer = resolveTransfer(context); // Check for transaction password final HttpServletRequest request = context.getRequest(); final boolean requestTransactionPassword = shouldValidateTransactionPassword(context, transfer); if (requestTransactionPassword) { context.validateTransactionPassword(); } request.setAttribute("requestTransactionPassword", requestTransactionPassword); request.setAttribute( "wouldRequireAuthorization", paymentService.wouldRequireAuthorization(transfer)); // Transfer number and number of transfers final int transferNumber = getTransferNumber(transfer); final int numberOfTransfers = getNumberOfTransfer(transfer); request.setAttribute("transferNumber", transferNumber); request.setAttribute("numberOfTransfers", numberOfTransfers); // Fetch related data final AccountOwner from = transfer.getFromOwner(); final AccountOwner to = transfer.getToOwner(); final TransferType transferType = transferTypeService.load( transfer.getType().getId(), RelationshipHelper.nested( TransferType.Relationships.FROM, AccountType.Relationships.CURRENCY), TransferType.Relationships.TO); final BigDecimal amount = transfer.getAmount(); if (from instanceof Member) { request.setAttribute("fromMember", from); } if (to instanceof Member) { request.setAttribute("toMember", to); } transfer.setType(transferType); request.setAttribute("unitsPattern", transferType.getFrom().getCurrency().getPattern()); // Store the transaction fees final TransactionFeePreviewDTO preview = transactionFeeService.preview(from, to, transferType, amount); request.setAttribute("finalAmount", preview.getFinalAmount()); request.setAttribute("fees", preview.getFees()); request.setAttribute("transfer", transfer); }