public BillingState billingState(final InternalCallContext context) throws OverdueException { if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) { // calculate billing state from parent account final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context); return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext); } return billingStateCalcuator.calculateBillingState(overdueable, context); } }
if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(parentAccountInternalTenantContext.getAccountRecordId(), callContext); notificationKey = new OverdueAsyncBusNotificationKey(account.getParentAccountId(), action); asyncPoster.insertOverdueNotification(account.getParentAccountId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, parentAccountContext);
@Test(groups = "slow", description = "Test Account create Parent and Child") public void testCreateParentAndChildAccounts() throws Exception { final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext); final AccountModelDao childAccountModel = createTestAccount(); childAccountModel.setParentAccountId(parentAccount.getId()); childAccountModel.setIsPaymentDelegatedToParent(true); final AccountData childAccountData = new DefaultAccount(childAccountModel); final Account childAccount = accountUserApi.createAccount(childAccountData, callContext); final Account retrievedChildAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); Assert.assertNull(parentAccount.getParentAccountId()); Assert.assertNotNull(retrievedChildAccount.getParentAccountId()); Assert.assertEquals(retrievedChildAccount.getId(), childAccount.getId()); Assert.assertEquals(retrievedChildAccount.getParentAccountId(), parentAccount.getId()); Assert.assertEquals(retrievedChildAccount.isPaymentDelegatedToParent(), childAccount.isPaymentDelegatedToParent()); }
Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); Assert.assertNull(parentAccount.getParentAccountId()); Assert.assertFalse(parentAccount.isPaymentDelegatedToParent()); List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); Assert.assertEquals(childAccount1.getParentAccountId(), parentAccount.getId()); Assert.assertTrue(childAccount1.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); Assert.assertNull(childAccount2.getParentAccountId()); Assert.assertFalse(childAccount2.isPaymentDelegatedToParent()); Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); childAccount2 = accountUserApi.getAccountById(childAccount2.getId(), callContext); Assert.assertEquals(childAccount2.getParentAccountId(), parentAccount.getId()); Assert.assertTrue(childAccount2.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
Assert.assertEquals(retrievedAccount.getPhone(), account.getPhone()); Assert.assertEquals(retrievedAccount.isMigrated(), account.isMigrated()); Assert.assertEquals(retrievedAccount.getParentAccountId(), account.getParentAccountId()); Assert.assertEquals(retrievedAccount.isPaymentDelegatedToParent(), account.isPaymentDelegatedToParent());
accountData.setPhone(phone != null ? phone : currentAccount.getPhone()); accountData.setNotes(notes != null ? notes : currentAccount.getNotes()); accountData.setParentAccountId(parentAccountId != null ? parentAccountId : currentAccount.getParentAccountId()); accountData.setIsPaymentDelegatedToParent(isPaymentDelegatedToParent != null ? isPaymentDelegatedToParent : currentAccount.isPaymentDelegatedToParent()); final Boolean isMigrated = this.isMigrated != null ? this.isMigrated : currentAccount.isMigrated();
private boolean isChildrenAccountAndPaymentDelegated(final Account account) { return account.getParentAccountId() != null && account.isPaymentDelegatedToParent(); }
public void processParentInvoiceForInvoiceGeneration(final Account childAccount, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException { GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), childAccount.getParentAccountId().toString(), invoiceConfig.getMaxGlobalLockRetries()); processParentInvoiceForInvoiceGenerationWithLock(childAccount, childInvoiceId, context); } catch (final LockFailedException e) { log.warn("Failed to process parent invoice for parentAccountId='{}'", childAccount.getParentAccountId().toString(), e); } finally { if (lock != null) { lock.release(); } } }
public void processParentInvoiceForAdjustments(final Account childAccount, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException { GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), childAccount.getParentAccountId().toString(), invoiceConfig.getMaxGlobalLockRetries()); processParentInvoiceForAdjustmentsWithLock(childAccount, childInvoiceId, context); } catch (final LockFailedException e) { log.warn("Failed to process parent invoice for parentAccountId='{}'", childAccount.getParentAccountId().toString(), e); } finally { if (lock != null) { lock.release(); } } }
public BillingState billingState(final InternalCallContext context) throws OverdueException { if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) { // calculate billing state from parent account final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context); return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext); } return billingStateCalcuator.calculateBillingState(overdueable, context); } }
@Override public void transferChildCreditToParent(final UUID childAccountId, final CallContext context) throws InvoiceApiException { final Account childAccount; final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(childAccountId, ObjectType.ACCOUNT, context); try { childAccount = accountUserApi.getAccountById(childAccountId, internalCallContext); } catch (AccountApiException e) { throw new InvoiceApiException(e); } if (childAccount.getParentAccountId() == null) { throw new InvoiceApiException(ErrorCode.ACCOUNT_DOES_NOT_HAVE_PARENT_ACCOUNT, childAccountId); } final BigDecimal accountCBA = getAccountCBA(childAccountId, context); if (accountCBA.compareTo(BigDecimal.ZERO) <= 0) { throw new InvoiceApiException(ErrorCode.CHILD_ACCOUNT_MISSING_CREDIT, childAccountId); } dao.transferChildCreditToParent(childAccount, internalCallContext); }
if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(parentAccountInternalTenantContext.getAccountRecordId(), callContext); notificationKey = new OverdueAsyncBusNotificationKey(account.getParentAccountId(), action); asyncPoster.insertOverdueNotification(account.getParentAccountId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, parentAccountContext);
private void processParentInvoiceForInvoiceGenerationWithLock(final Account childAccount, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException { log.info("Processing parent invoice for parentAccountId='{}', childInvoiceId='{}'", childAccount.getParentAccountId(), childInvoiceId); final InvoiceModelDao childInvoiceModelDao = invoiceDao.getById(childInvoiceId, context); final Invoice childInvoice = new DefaultInvoice(childInvoiceModelDao); final Long parentAccountRecordId = internalCallContextFactory.getRecordIdFromObject(childAccount.getParentAccountId(), ObjectType.ACCOUNT, buildTenantContext(context)); final InternalCallContext parentContext = internalCallContextFactory.createInternalCallContext(parentAccountRecordId, context); InvoiceModelDao draftParentInvoice = invoiceDao.getParentDraftInvoice(childAccount.getParentAccountId(), parentContext); final ParentInvoiceItem newParentInvoiceItem = new ParentInvoiceItem(UUID.randomUUID(), context.getCreatedDate(), draftParentInvoice.getId(), childAccount.getParentAccountId(), childAccount.getId(), childInvoiceAmount, childAccount.getCurrency(), description); final InvoiceItemModelDao parentInvoiceItem = new InvoiceItemModelDao(newParentInvoiceItem); draftParentInvoice.addInvoiceItem(parentInvoiceItem); draftParentInvoice = new InvoiceModelDao(childAccount.getParentAccountId(), invoiceDate, childAccount.getCurrency(), InvoiceStatus.DRAFT, true); final InvoiceItem parentInvoiceItem = new ParentInvoiceItem(UUID.randomUUID(), context.getCreatedDate(), draftParentInvoice.getId(), childAccount.getParentAccountId(), childAccount.getId(), childInvoiceAmount, childAccount.getCurrency(), description); draftParentInvoice.addInvoiceItem(new InvoiceItemModelDao(parentInvoiceItem));
final Long parentAccountRecordId = internalCallContextFactory.getRecordIdFromObject(account.getParentAccountId(), ObjectType.ACCOUNT, buildTenantContext(context)); final InternalCallContext parentContext = internalCallContextFactory.createInternalCallContext(parentAccountRecordId, context); final String description = "Adjustment for account ".concat(account.getExternalKey());
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(childAccount.getParentAccountId(), childAccountContext); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), childAccountContext);
assertNull(childAccount.getParentAccountId()); assertFalse(childAccount.isPaymentDelegatedToParent()); List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childAccount.getParentAccountId(), parentAccount.getId()); assertFalse(childAccount.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childAccount.getParentAccountId(), parentAccount.getId()); assertTrue(childAccount.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
assertEquals(childAccount.getParentAccountId(), parentAccount.getId()); assertTrue(childAccount.isPaymentDelegatedToParent()); List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertNull(childAccount.getParentAccountId()); assertFalse(childAccount.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
public AccountJson(final Account account, final BigDecimal accountBalance, final BigDecimal accountCBA, @Nullable final AccountAuditLogs accountAuditLogs) { super(toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForAccount())); this.accountCBA = accountCBA; this.accountBalance = accountBalance; this.accountId = account.getId(); this.externalKey = account.getExternalKey(); this.name = account.getName(); this.firstNameLength = account.getFirstNameLength(); this.email = account.getEmail(); this.billCycleDayLocal = account.getBillCycleDayLocal(); this.currency = account.getCurrency(); this.parentAccountId = account.getParentAccountId(); this.isPaymentDelegatedToParent = account.isPaymentDelegatedToParent(); this.paymentMethodId = account.getPaymentMethodId(); this.referenceTime = account.getReferenceTime(); this.timeZone = account.getTimeZone() != null ? account.getTimeZone().toString() : null; this.address1 = account.getAddress1(); this.address2 = account.getAddress2(); this.postalCode = account.getPostalCode(); this.company = account.getCompanyName(); this.city = account.getCity(); this.state = account.getStateOrProvince(); this.country = account.getCountry(); this.locale = account.getLocale(); this.phone = account.getPhone(); this.notes = account.getNotes(); this.isMigrated = account.isMigrated(); }
final Invoice invoiceForCredit = new DefaultInvoice(childAccount.getParentAccountId(), parentInvoiceDate, childCreatedDate.toLocalDate(), childCreatedDate, invoiceForCredit.getId(), childAccount.getParentAccountId(), childCreatedDate.toLocalDate(), creditDescription,
accountData.setPhone(phone != null ? phone : currentAccount.getPhone()); accountData.setNotes(notes != null ? notes : currentAccount.getNotes()); accountData.setParentAccountId(parentAccountId != null ? parentAccountId : currentAccount.getParentAccountId()); accountData.setIsPaymentDelegatedToParent(isPaymentDelegatedToParent != null ? isPaymentDelegatedToParent : currentAccount.isPaymentDelegatedToParent()); final Boolean isMigrated = this.isMigrated != null ? this.isMigrated : currentAccount.isMigrated();