From 89baaeec2be85e0c95f63837e87ae25eb7f2cf57 Mon Sep 17 00:00:00 2001 From: Vlas Khilkevich <93208596+vlaskhilkevich@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:30:04 +0100 Subject: [PATCH] Optimize performance by removing redundant code not leading to any outcome --- .../plugin/vertex/VertexInvoicePluginApi.java | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/src/main/java/org/killbill/billing/plugin/vertex/VertexInvoicePluginApi.java b/src/main/java/org/killbill/billing/plugin/vertex/VertexInvoicePluginApi.java index 80f85c0..73fb025 100644 --- a/src/main/java/org/killbill/billing/plugin/vertex/VertexInvoicePluginApi.java +++ b/src/main/java/org/killbill/billing/plugin/vertex/VertexInvoicePluginApi.java @@ -19,18 +19,13 @@ import java.sql.SQLException; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; import org.killbill.billing.ObjectType; import org.killbill.billing.account.api.Account; -import org.killbill.billing.catalog.api.CatalogApiException; -import org.killbill.billing.catalog.api.Plan; -import org.killbill.billing.catalog.api.StaticCatalog; import org.killbill.billing.invoice.api.Invoice; import org.killbill.billing.invoice.api.InvoiceItem; import org.killbill.billing.invoice.plugin.api.InvoiceContext; @@ -134,7 +129,6 @@ public OnSuccessInvoiceResult onSuccessCall(final InvoiceContext context, final private void checkForTaxCodes(final Invoice invoice, final Collection properties, final TenantContext context) { checkForTaxCodesInCustomFields(invoice, properties, context); - checkForTaxCodesOnProducts(invoice, properties, context); } private void checkForTaxCodesInCustomFields(final Invoice invoice, final Collection properties, final TenantContext context) { @@ -159,37 +153,6 @@ private void checkForTaxCodesInCustomFields(final Invoice invoice, final Collect } } - private void checkForTaxCodesOnProducts(final Invoice invoice, final Collection properties, final TenantContext context) { - final Map planToProductCache = new HashMap<>(); - final Map productToTaxCodeCache = new HashMap<>(); - - 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.findPlan(planName); - planToProductCache.put(planName, plan.getProduct().getName()); - } catch (final CatalogApiException e) { - continue; - } - } - final String productName = planToProductCache.get(planName); - if (productName == null) { - continue; - } - - final String taxCode = productToTaxCodeCache.get(productName); - if (taxCode != null) { - addTaxCodeToInvoiceItem(invoiceItem.getId(), productToTaxCodeCache.get(productName), properties); - } - } - } - private void addTaxCodeToInvoiceItem(final UUID invoiceItemId, final String taxCode, final Collection properties) { final String pluginPropertyName = String.format("%s_%s", VertexTaxCalculator.TAX_CODE, invoiceItemId); // Already in plugin properties?