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

PP-2696 Reinstate get transactions with refunds #462

Merged
merged 3 commits into from
Oct 2, 2017

Conversation

rauligs
Copy link
Contributor

@rauligs rauligs commented Oct 2, 2017

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 refunds

      • ChargeSearchStrategy fetches charges only, using the original implementation

      • The 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 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.

@rauligs rauligs force-pushed the PP-2696-Reinstate-Get-Transactions-With-Refunds branch from f1cf830 to 7dacbb4 Compare October 2, 2017 10:27
     - 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.
@rauligs rauligs force-pushed the PP-2696-Reinstate-Get-Transactions-With-Refunds branch from 7dacbb4 to c7eb98c Compare October 2, 2017 10:28
@kakumara kakumara self-assigned this Oct 2, 2017
Copy link
Contributor

@kakumara kakumara left a 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>
Copy link
Contributor

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. 😐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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) {
Copy link
Contributor

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>

Copy link
Contributor Author

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@rauligs rauligs merged commit 3854b48 into master Oct 2, 2017
@rauligs rauligs deleted the PP-2696-Reinstate-Get-Transactions-With-Refunds branch October 2, 2017 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants