-
Notifications
You must be signed in to change notification settings - Fork 17
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
PP-2696 Reinstate get transactions with refunds #462
PP-2696 Reinstate get transactions with refunds #462
Conversation
f1cf830
to
7dacbb4
Compare
- Add _@Transactional_ annotation to TransactionDao since this is causing issues, so PP-2515 can be added back: google/guice#730 - Reinstante PP-2515 Implementation of `TransactionDao` The implementation of `TransactionDao` is meant to be used a as drop-in replacement for `ChargeDao` when we want to take refunds into consideration while searching. - A transaction can be of two types `charge` or `refund`. Depending on whether we want to search for only charges or refunds, an optional payment type can be specified in the filtering criteria. The absence of a payment type in the search criteria implies all types are considered during the search. - The filtering criteria has been augmented to allow searching by refund status or charge status or any combination of both. - Technical note: Performance being an overriding concern when searching for transactions, the underlying query required to be hand-optimized in order to get a decent execution plan out of a SQL UNION with pagination. Since JPA tend to get in the way because of its lack of support for UNION query, we were forced to resort to using a native query constructed dynamically with the support of jOOQ's query DSL API. https://www.jooq.org/doc/3.9/manual/getting-started/use-cases/jooq-as-a-standalone-sql-builder/
- Reinstante PP-2515 Mechanism to switch between fetching strategies Introduce strategies for fetching transactions: - `TransactionSearchStrategy` fetches both charges and refunds - `ChargeSearchStrategy` fetches charges only, using the original implementation - Infer transaction_type from states (payments or refunds) The strategy is selected according to the `REFUNDS_IN_TX_LIST` feature flag. Testing: - `TransactionDaoITest` exercises the query operations of the TransactionDao - `ChargesApiResourceITest` exercises all layers from resource down, with `REFUNDS_IN_TX_LIST` disabled - `TransactionsApiResourceITest` exercises all layers from resource down, with `REFUNDS_IN_TX_LIST` enabled The strategy and switching via feature flag are temporary. We intend to replace the `TransactionSearchStrategy` implementation after refactoring the data model to store charges and refunds in the same database table.
Reinstante Clarify escaping of like clause: - Having a function called `escape` immediately sets off alarm bells when building SQL code. Why are we needing to explicitly escape a string? In fact we are quoting the special symbols `%` and `_` which can appear in a like clause.
7dacbb4
to
c7eb98c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor comments. But I don't really want to hold back approval if you want to look at them later
@@ -176,6 +176,11 @@ | |||
<artifactId>commons-collections</artifactId> | |||
<version>3.2.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.jooq</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see the benefits of using this. SQL is perfectly readable/manageble to me. 😐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
This code is temporary. Connector refactoring to use concept of transactions is in spike at the moment. See https://payments-platform.atlassian.net/browse/PP-2544
-
This will remove this complexity and jooq can be removed.
@@ -94,20 +90,58 @@ public ChargeResponse buildChargeResponse(UriInfo uriInfo, ChargeEntity chargeEn | |||
.orElseGet(Optional::empty); | |||
} | |||
|
|||
public <T extends AbstractChargeResponseBuilder<T, R>, R> AbstractChargeResponseBuilder<T, R> populateResponseBuilderWith(AbstractChargeResponseBuilder<T, R> responseBuilder, UriInfo uriInfo, ChargeEntity chargeEntity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬 <T extends AbstractChargeResponseBuilder<T, R>, R> AbstractChargeResponseBuilder<T, R>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
|
||
import static uk.gov.pay.connector.model.ChargeResponse.aChargeResponseBuilder; | ||
|
||
public class ChargeSearchStrategy extends AbstractSearchStrategy<ChargeEntity> implements SearchStrategy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to implements SearchStrategy
? AbstractSearchStrategy
already does that
import static uk.gov.pay.connector.resources.ApiPaths.CHARGE_API_PATH; | ||
import static uk.gov.pay.connector.resources.ApiPaths.REFUNDS_API_PATH; | ||
|
||
public class TransactionSearchStrategy extends AbstractSearchStrategy<Transaction> implements SearchStrategy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.AbstractSearchStrategy
already implement it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
WHAT
Reinstate get transactions with refunds adding the fix to prevent Automatically started UnitOfWork is never ended google/guice#730 by annotating
TransactionDao
with @transactional annotation.Reinstate story: https://payments-platform.atlassian.net/browse/PP-2515
Original PR: PP-2515 Get payments including refunds #439
Introduced mechanism to switch between fetching transactions:
TransactionSearchStrategy
fetches both charges and refundsChargeSearchStrategy
fetches charges only, using the original implementationThe strategy is selected according to the
REFUNDS_IN_TX_LIST
feature flag.The strategy and switching via feature flag are temporary. We intend to replace the
TransactionSearchStrategy
implementation after refactoring the data model to store charges and refunds in the same database table.The implementation of
TransactionDao
is meant to be used a as drop-in replacement forChargeDao
when we want to take refunds into consideration while searching.A transaction can be of two types
charge
orrefund
. Depending on whether we want to search for only charges or refunds, an optional payment type can be specified in the filtering criteria. The absence of a payment type in the search criteria implies all types are considered during the search.The filtering criteria has been augmented to allow searching by refund status or charge status or any combination of both.