@BeforeMethod(groups = "fast") public void setUp() throws Exception { accountDao = new MockAccountDao(Mockito.mock(PersistentBus.class), clock); accountUserApi = new DefaultAccountUserApi(immutableAccountInternalApi, accountDao, nonEntityDao, controllerDispatcher, internalFactory); }
@Override public UUID getIdFromKey(final String externalKey, final InternalTenantContext context) { final AccountModelDao account = getAccountByKey(externalKey, context); return account == null ? null : account.getId(); }
@Override public Integer getAccountBCD(final UUID accountId, final InternalTenantContext context) { final AccountModelDao account = getById(accountId, context); return account != null ? account.getBillingCycleDayLocal() : 0; }
@Override public void updatePaymentMethod(final UUID accountId, final UUID paymentMethodId, final InternalCallContext context) throws AccountApiException { final AccountModelDao currentAccountModelDao = getById(accountId, context); if (currentAccountModelDao == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } final DefaultAccount currentAccount = new DefaultAccount(currentAccountModelDao); final DefaultMutableAccountData updatedAccount = new DefaultMutableAccountData(currentAccount); updatedAccount.setPaymentMethodId(paymentMethodId); update(new AccountModelDao(accountId, updatedAccount), context); }
@Override public void update(final AccountModelDao account, final boolean treatNullValueAsReset, final InternalCallContext context) { super.update(account, context); final AccountModelDao currentAccount = getById(account.getId(), context); final Long accountRecordId = getRecordId(account.getId(), context); final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId(); final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(account.getId(), currentAccount, account, accountRecordId, tenantRecordId, UUID.randomUUID(), clock.getUTCNow()); if (changeEvent.hasChanges()) { try { eventBus.post(changeEvent); } catch (final EventBusException ex) { Assert.fail(ex.toString()); } } }
@Override public Pagination<AccountModelDao> searchAccounts(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) { final Collection<AccountModelDao> results = new LinkedList<AccountModelDao>(); int maxNbRecords = 0; for (final AccountModelDao account : getAll(context)) { maxNbRecords++; if ((account.getName() != null && account.getName().contains(searchKey)) || (account.getEmail() != null && account.getEmail().contains(searchKey)) || (account.getExternalKey() != null && account.getExternalKey().contains(searchKey)) || (account.getCompanyName() != null && account.getCompanyName().contains(searchKey))) { results.add(account); } } return DefaultPagination.<AccountModelDao>build(offset, limit, maxNbRecords, results); }
@Override public void create(final AccountModelDao account, final InternalCallContext context) throws AccountApiException { super.create(account, context); try { final Long accountRecordId = getRecordId(account.getId(), context); final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId(); eventBus.post(new DefaultAccountCreationEvent(new DefaultAccountData(account), account.getId(), accountRecordId, tenantRecordId, UUID.randomUUID())); } catch (final EventBusException ex) { Assert.fail(ex.toString()); } }