protected Plan getPlanFromInvoiceItem(final InvoiceItem invoiceItem, final TenantContext context) throws AnalyticsRefreshException { try { final Catalog catalog = getCatalog(context); return catalog.findPlan( invoiceItem.getPlanName(), invoiceItem.getStartDate().toDateTimeAtStartOfDay()); } catch (CatalogApiException e) { logService.log( LogService.LOG_INFO, "Unable to retrieve plan for invoice item " + invoiceItem.getId(), e); return null; } }
private void checkForTaxCodesOnProducts( final Invoice invoice, final Collection<PluginProperty> properties, final TenantContext context) { final Map<String, String> planToProductCache = new HashMap<String, String>(); final Map<String, String> productToTaxCodeCache = new HashMap<String, String>(); for (final InvoiceItem invoiceItem : invoice.getInvoiceItems()) { final String planName = invoiceItem.getPlanName(); if (planName == null) { continue; } if (planToProductCache.get(planName) == null) { try { final StaticCatalog catalog = killbillAPI.getCatalogUserApi().getCurrentCatalog(null, context); final Plan plan = catalog.findCurrentPlan(planName); planToProductCache.put(planName, plan.getProduct().getName()); } catch (final CatalogApiException e) { continue; } } final String productName = planToProductCache.get(planName); if (productName == null) { continue; } if (productToTaxCodeCache.get(productName) == null) { try { final String taxCode = dao.getTaxCode(productName, context.getTenantId()); productToTaxCodeCache.put(productName, taxCode); } catch (final SQLException e) { continue; } } final String taxCode = productToTaxCodeCache.get(productName); if (taxCode != null) { addTaxCodeToInvoiceItem( invoiceItem.getId(), productToTaxCodeCache.get(productName), properties); } } }