Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify by removing objectMapper and making json value manually #43

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;

public class VertexTaxCalculator extends PluginTaxCalculator {
Expand Down Expand Up @@ -105,7 +102,6 @@ public class VertexTaxCalculator extends PluginTaxCalculator {
private final VertexApiConfigurationHandler vertexApiConfigurationHandler;
private final VertexDao dao;
private final Clock clock;
private final ObjectMapper objectMapper;

public VertexTaxCalculator(final VertexApiConfigurationHandler vertexApiConfigurationHandler,
final VertexDao dao,
Expand All @@ -115,7 +111,6 @@ public VertexTaxCalculator(final VertexApiConfigurationHandler vertexApiConfigur
this.vertexApiConfigurationHandler = vertexApiConfigurationHandler;
this.clock = clock;
this.dao = dao;
this.objectMapper = new ObjectMapper();
}

public List<InvoiceItem> compute(final Account account,
Expand Down Expand Up @@ -319,11 +314,6 @@ private InvoiceItem createTaxInvoiceItem(final InvoiceItem taxableItem, final UU
return taxItem;
}

final String taxItemDetails = createTaxItemDetails(taxRate);
if (taxItemDetails == null) {
return taxItem;
}

return new PluginInvoiceItem(new Builder<>()
.withId(taxItem.getId())
.withInvoiceItemType(taxItem.getInvoiceItemType())
Expand All @@ -349,18 +339,14 @@ private InvoiceItem createTaxInvoiceItem(final InvoiceItem taxableItem, final UU
.withUsageName(taxItem.getUsageName())
.withPrettyUsageName(taxItem.getPrettyUsageName())
.withQuantity(taxItem.getQuantity())
.withItemDetails(taxItemDetails)
.withItemDetails(createTaxItemDetails(taxRate))
.withCreatedDate(taxItem.getCreatedDate())
.withUpdatedDate(taxItem.getUpdatedDate())
.validate().build());
}

private String createTaxItemDetails(@Nonnull final Double effectiveRate) {
try {
return objectMapper.writeValueAsString(ImmutableMap.of("taxRate", String.valueOf(effectiveRate)));
} catch (JsonProcessingException ignored) {
return null;
}
return "{\"taxRate\":\"" + effectiveRate + "\"}";
}

private String getTaxDescription(final TaxesType transactionLineDetailModel) {
Expand Down
Loading