<commit_before>package com.commercetools.sunrise.shoppingcart.checkout.thankyou;

import com.commercetools.sunrise.common.contexts.RequestScoped;
import com.commercetools.sunrise.common.controllers.WithOverwriteableTemplateName;
import com.commercetools.sunrise.common.reverserouter.HomeReverseRouter;
import com.commercetools.sunrise.hooks.OrderByIdGetFilterHook;
import com.commercetools.sunrise.hooks.RequestHook;
import com.commercetools.sunrise.hooks.SingleOrderHook;
import com.commercetools.sunrise.hooks.SunrisePageDataHook;
import com.commercetools.sunrise.shoppingcart.OrderSessionUtils;
import com.commercetools.sunrise.shoppingcart.common.SunriseFrameworkCartController;
import com.google.inject.Injector;
import io.sphere.sdk.orders.Order;
import io.sphere.sdk.orders.queries.OrderByIdGet;
import play.mvc.Call;
import play.mvc.Result;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletionStage;

import static java.util.Arrays.asList;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static play.libs.concurrent.HttpExecution.defaultContext;

/**
 * Controller to show as last checkout step the confirmation of the order data.
 * By default the last order ID is taken from the cookie.
 *
 * <p id="hooks">supported hooks</p>
 * <ul>
 *     <li>{@link RequestHook}</li>
 *     <li>{@link SunrisePageDataHook}</li>
 *     <li>{@link OrderByIdGetFilterHook}</li>
 *     <li>{@link SingleOrderHook}</li>
 * </ul>
 * <p>tags</p>
 * <ul>
 *     <li>checkout-thankyou</li>
 *     <li>checkout</li>
 * </ul>
 */
@RequestScoped
public abstract class SunriseCheckoutThankYouPageController extends SunriseFrameworkCartController
        implements WithOverwriteableTemplateName {

    @Inject
    private Injector injector;
    @Inject
    private CheckoutThankYouPageContentFactory pageContentFactory;

    public CompletionStage<Result> show(final String languageTag) {
        return doRequest(() -> findLastOrder().
                thenComposeAsync(orderOpt -> orderOpt
                        .map(this::handleFoundOrder)
                        .orElseGet(this::handleNotFoundOrder), defaultContext()));
    }

    protected CompletionStage<Optional<Order>> findLastOrder() {
        final Optional<String> lastOrderId = OrderSessionUtils.getLastOrderId(session());
        return lastOrderId
                .map(orderId -> findOrderById(orderId))
                .orElseGet(() -> completedFuture(Optional.empty()));
    }

    protected CompletionStage<Optional<Order>> findOrderById(final String orderId) {
        final OrderByIdGet orderByIdGet = hooks().runFilterHook(OrderByIdGetFilterHook.class, (hook, getter) -> hook.filterOrderByIdGet(getter), OrderByIdGet.of(orderId));
        return sphere().execute(orderByIdGet)
                .thenApplyAsync(nullableOrder -> {
                    if (nullableOrder != null) {
                        hooks().runAsyncHook(SingleOrderHook.class, hook -> hook.onSingleOrderLoaded(nullableOrder));
                    }
                    return Optional.ofNullable(nullableOrder);
                }, defaultContext());
    }

    protected CompletionStage<Result> handleFoundOrder(final Order order) {
        final CheckoutThankYouPageContent pageContent = pageContentFactory.create(order);<commit_msg>show payment data in checkout thankyou<commit_after>package com.commercetools.sunrise.shoppingcart.checkout.thankyou;

import com.commercetools.sunrise.common.contexts.RequestScoped;
import com.commercetools.sunrise.common.controllers.WithOverwriteableTemplateName;
import com.commercetools.sunrise.common.reverserouter.HomeReverseRouter;
import com.commercetools.sunrise.hooks.OrderByIdGetFilterHook;
import com.commercetools.sunrise.hooks.RequestHook;
import com.commercetools.sunrise.hooks.SingleOrderHook;
import com.commercetools.sunrise.hooks.SunrisePageDataHook;
import com.commercetools.sunrise.shoppingcart.OrderSessionUtils;
import com.commercetools.sunrise.shoppingcart.common.SunriseFrameworkCartController;
import com.google.inject.Injector;
import io.sphere.sdk.orders.Order;
import io.sphere.sdk.orders.queries.OrderByIdGet;
import play.mvc.Call;
import play.mvc.Result;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletionStage;

import static java.util.Arrays.asList;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static play.libs.concurrent.HttpExecution.defaultContext;

/**
 * Controller to show as last checkout step the confirmation of the order data.
 * By default the last order ID is taken from the cookie.
 *
 * <p id="hooks">supported hooks</p>
 * <ul>
 *     <li>{@link RequestHook}</li>
 *     <li>{@link SunrisePageDataHook}</li>
 *     <li>{@link OrderByIdGetFilterHook}</li>
 *     <li>{@link SingleOrderHook}</li>
 * </ul>
 * <p>tags</p>
 * <ul>
 *     <li>checkout-thankyou</li>
 *     <li>checkout</li>
 * </ul>
 */
@RequestScoped
public abstract class SunriseCheckoutThankYouPageController extends SunriseFrameworkCartController
        implements WithOverwriteableTemplateName {

    @Inject
    private Injector injector;
    @Inject
    private CheckoutThankYouPageContentFactory pageContentFactory;

    public CompletionStage<Result> show(final String languageTag) {
        return doRequest(() -> findLastOrder().
                thenComposeAsync(orderOpt -> orderOpt
                        .map(this::handleFoundOrder)
                        .orElseGet(this::handleNotFoundOrder), defaultContext()));
    }

    protected CompletionStage<Optional<Order>> findLastOrder() {
        final Optional<String> lastOrderId = OrderSessionUtils.getLastOrderId(session());
        return lastOrderId
                .map(orderId -> findOrderById(orderId))
                .orElseGet(() -> completedFuture(Optional.empty()));
    }

    protected CompletionStage<Optional<Order>> findOrderById(final String orderId) {
        final OrderByIdGet baseRequest = OrderByIdGet.of(orderId).plusExpansionPaths(m -> m.paymentInfo().payments());
        final OrderByIdGet orderByIdGet = hooks().runFilterHook(OrderByIdGetFilterHook.class, (hook, getter) -> hook.filterOrderByIdGet(getter), baseRequest);
        return sphere().execute(orderByIdGet)
                .thenApplyAsync(nullableOrder -> {
                    if (nullableOrder != null) {
                        hooks().runAsyncHook(SingleOrderHook.class, hook -> hook.onSingleOrderLoaded(nullableOrder));
                    }
                    return Optional.ofNullable(nullableOrder);
                }, defaultContext());
    }

    protected CompletionStage<Result> handleFoundOrder(final Order order) {
        final CheckoutThankYouPageContent pageContent = pageContentFactory.create(order);
{'fraction_non_alphanumeric': 0.10378864857018436, 'fraction_numerical': 0.0, 'mean_word_length': 3.8969438521677326, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5457802', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1951, 'n_words': 345}