@Override public List<BusinessSubscriptionTransition> getTransitionsForBundle(final String externalKey, final TenantContext context) { final List<BusinessSubscriptionTransitionModelDao> transitionsByKey = analyticsDao.getTransitionsByKey(externalKey, internalCallContextFactory.createInternalTenantContext(context)); return ImmutableList.<BusinessSubscriptionTransition>copyOf(Collections2.transform(transitionsByKey, new Function<BusinessSubscriptionTransitionModelDao, BusinessSubscriptionTransition>() { @Override public BusinessSubscriptionTransition apply(@Nullable final BusinessSubscriptionTransitionModelDao input) { return new DefaultBusinessSubscriptionTransition(input); } })); }
@Override public List<String> getTenantValueForKey(final String key, final TenantContext context) throws TenantApiException { final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(context); return tenantDao.getTenantValueForKey(key, internalContext); }
@Override public Pagination<CustomFieldModelDao> build() { return customFieldDao.searchCustomFields(searchKey, offset, limit, internalCallContextFactory.createInternalTenantContext(context)); } },
@Override public Pagination<TagModelDao> build() { return tagDao.get(offset, limit, internalCallContextFactory.createInternalTenantContext(context)); } },
@Override public List<Invoice> getInvoicesByAccount(final UUID accountId, final LocalDate fromDate, final TenantContext context) { return ImmutableList.<Invoice>copyOf(Collections2.transform(dao.getInvoicesByAccount(fromDate, internalCallContextFactory.createInternalTenantContext(accountId, context)), new Function<InvoiceModelDao, Invoice>() { @Override public Invoice apply(final InvoiceModelDao input) { return new DefaultInvoice(input); } })); }
@Override public BigDecimal getAccountBalance(final UUID accountId, final TenantContext context) { final BigDecimal result = dao.getAccountBalance(accountId, internalCallContextFactory.createInternalTenantContext(accountId, context)); return result == null ? BigDecimal.ZERO : result; }
@Override public List<Refund> getAccountRefunds(final Account account, final TenantContext context) throws PaymentApiException { return refundProcessor.getAccountRefunds(account, internalCallContextFactory.createInternalTenantContext(context)); }
@Override public List<PaymentMethod> getPaymentMethods(final Account account, final boolean withPluginInfo, final TenantContext context) throws PaymentApiException { return methodProcessor.getPaymentMethods(account, withPluginInfo, internalCallContextFactory.createInternalTenantContext(context)); }
@Override public Collection<UUID> checkAnalyticsInSyncWithInvoice(final TenantContext context) { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(context); return dao.checkBiiMatchesInvoiceItems(internalTenantContext); }
@Override public Collection<UUID> checkAnalyticsInSyncWithTag(final TenantContext context) { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(context); return dao.checkBacTagsMatchesTags(internalTenantContext); }
@Override public List<BusinessOverdueStatus> getOverdueStatusesForBundle(final String externalKey, final TenantContext context) { final List<BusinessOverdueStatusModelDao> overdueStatusesForBundleByKey = analyticsDao.getOverdueStatusesForBundleByKey(externalKey, internalCallContextFactory.createInternalTenantContext(context)); return ImmutableList.<BusinessOverdueStatus>copyOf(Collections2.transform(overdueStatusesForBundleByKey, new Function<BusinessOverdueStatusModelDao, BusinessOverdueStatus>() { @Override public BusinessOverdueStatus apply(@Nullable final BusinessOverdueStatusModelDao input) { return new DefaultBusinessOverdueStatus(input); } })); }
@Override public List<BusinessTag> getTagsForAccount(final String accountKey, final TenantContext context) { final List<BusinessAccountTagModelDao> tagsForAccount = analyticsDao.getTagsForAccount(accountKey, internalCallContextFactory.createInternalTenantContext(context)); return ImmutableList.<BusinessTag>copyOf(Collections2.transform(tagsForAccount, new Function<BusinessAccountTagModelDao, BusinessTag>() { @Override public BusinessTag apply(@Nullable final BusinessAccountTagModelDao input) { return new DefaultBusinessTag(input); } })); }
@Override public List<Invoice> getAllInvoicesByAccount(final UUID accountId, final TenantContext context) { return ImmutableList.<Invoice>copyOf(Collections2.transform(dao.getAllInvoicesByAccount(internalCallContextFactory.createInternalTenantContext(accountId, context)), new Function<InvoiceModelDao, Invoice>() { @Override public Invoice apply(final InvoiceModelDao input) { return new DefaultInvoice(input); } })); }
@Override public List<SubscriptionBundle> getSubscriptionBundlesForExternalKey(final String externalKey, final TenantContext context) throws SubscriptionApiException { final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(context); final List<SubscriptionBaseBundle> baseBundles = subscriptionBaseInternalApi.getBundlesForKey(externalKey, internalContext); final List<SubscriptionBundle> result = new ArrayList<SubscriptionBundle>(baseBundles.size()); for (final SubscriptionBaseBundle cur : baseBundles) { final SubscriptionBundle bundle = getSubscriptionBundle(cur.getId(), context); result.add(bundle); } return result; }
@Override public BusinessAccount getAccountByKey(final String accountKey, final TenantContext context) { final BusinessAccountModelDao accountByKey = analyticsDao.getAccountByKey(accountKey, internalCallContextFactory.createInternalTenantContext(context)); if (accountByKey == null) { return null; } else { return new DefaultBusinessAccount(accountByKey); } }
@Override public BillingState getBillingStateFor(final Account overdueable, final TenantContext context) throws OverdueException { log.debug("Billing state of of {} requested", overdueable.getId()); final OverdueWrapper wrapper = factory.createOverdueWrapperFor(overdueable); return wrapper.billingState(internalCallContextFactory.createInternalTenantContext(context)); }
@Override public AccountAuditLogs getAccountAuditLogs(final UUID accountId, final AuditLevel auditLevel, final TenantContext tenantContext) { // Optimization - bail early if (AuditLevel.NONE.equals(auditLevel)) { return new DefaultAccountAuditLogs(accountId); } return auditDao.getAuditLogsForAccountRecordId(auditLevel, internalCallContextFactory.createInternalTenantContext(accountId, tenantContext)); }
@Override public TagDefinition getTagDefinitionForName(final String tagDefinitionName, final TenantContext context) throws TagDefinitionApiException { return new DefaultTagDefinition(tagDefinitionDao.getByName(tagDefinitionName, internalCallContextFactory.createInternalTenantContext(context)), TagModelDaoHelper.isControlTag(tagDefinitionName)); }
@SuppressWarnings("unchecked") @Override public OverdueState getOverdueStateFor(final Account overdueable, final TenantContext context) throws OverdueException { try { final String stateName = accessApi.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContextFactory.createInternalTenantContext(context)).getStateName(); final OverdueStateSet states = overdueConfig.getStateSet(); return states.findState(stateName); } catch (OverdueApiException e) { throw new OverdueException(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED, overdueable.getId(), overdueable.getClass().getSimpleName()); } }
@Override public InvoiceItem getExternalChargeById(final UUID externalChargeId, final TenantContext context) throws InvoiceApiException { final InvoiceItem externalChargeItem = InvoiceItemFactory.fromModelDao(dao.getExternalChargeById(externalChargeId, internalCallContextFactory.createInternalTenantContext(externalChargeId, ObjectType.INVOICE_ITEM, context))); if (externalChargeItem == null) { throw new InvoiceApiException(ErrorCode.INVOICE_NO_SUCH_EXTERNAL_CHARGE, externalChargeId); } return new ExternalChargeInvoiceItem(externalChargeItem.getId(), externalChargeItem.getInvoiceId(), externalChargeItem.getAccountId(), externalChargeItem.getPlanName(), externalChargeItem.getStartDate(), externalChargeItem.getAmount(), externalChargeItem.getCurrency()); }