<commit_before>package org.broadleafcommerce.payment.service;

import java.util.Map;

import javax.annotation.Resource;

import org.broadleafcommerce.order.domain.Order;
import org.broadleafcommerce.order.domain.PaymentInfo;
import org.broadleafcommerce.payment.domain.Referenced;
import org.broadleafcommerce.payment.service.exception.PaymentException;
import org.broadleafcommerce.payment.service.module.PaymentResponse;
import org.broadleafcommerce.payment.service.module.PaymentResponseImpl;
import org.broadleafcommerce.payment.service.workflow.CompositePaymentResponse;
import org.broadleafcommerce.payment.service.workflow.PaymentSeed;
import org.broadleafcommerce.workflow.SequenceProcessor;
import org.broadleafcommerce.workflow.WorkflowException;
import org.springframework.stereotype.Service;

/**
 * Execute the payment workflow independently of the checkout workflow
 *
 * @author jfischer
 *
 */
@Service("compositePaymentService")
public class CompositePaymentServiceImpl implements CompositePaymentService {

    @Resource(name="paymentWorkflow")
    SequenceProcessor paymentWorkflow;

    @Override
    public CompositePaymentResponse executePayment(Order order, Map<PaymentInfo, Referenced> payments, PaymentResponse response) throws PaymentException {
        /*
         * TODO add validation that checks the order and payment information for validity.
         */
        try {
            PaymentSeed seed = new PaymentSeed(order, payments, response);
            paymentWorkflow.doActivities(seed);

            return seed;
        } catch (WorkflowException e) {
            Throwable cause = null;
            while(e.getCause() != null) {
                if (cause.equals(e.getCause())) {
                    break;
                }
                cause = e.getCause();<commit_msg>prevent null pointer when getting exception cause<commit_after>package org.broadleafcommerce.payment.service;

import java.util.Map;

import javax.annotation.Resource;

import org.broadleafcommerce.order.domain.Order;
import org.broadleafcommerce.order.domain.PaymentInfo;
import org.broadleafcommerce.payment.domain.Referenced;
import org.broadleafcommerce.payment.service.exception.PaymentException;
import org.broadleafcommerce.payment.service.module.PaymentResponse;
import org.broadleafcommerce.payment.service.module.PaymentResponseImpl;
import org.broadleafcommerce.payment.service.workflow.CompositePaymentResponse;
import org.broadleafcommerce.payment.service.workflow.PaymentSeed;
import org.broadleafcommerce.workflow.SequenceProcessor;
import org.broadleafcommerce.workflow.WorkflowException;
import org.springframework.stereotype.Service;

/**
 * Execute the payment workflow independently of the checkout workflow
 *
 * @author jfischer
 *
 */
@Service("compositePaymentService")
public class CompositePaymentServiceImpl implements CompositePaymentService {

    @Resource(name="paymentWorkflow")
    SequenceProcessor paymentWorkflow;

    @Override
    public CompositePaymentResponse executePayment(Order order, Map<PaymentInfo, Referenced> payments, PaymentResponse response) throws PaymentException {
        /*
         * TODO add validation that checks the order and payment information for validity.
         */
        try {
            PaymentSeed seed = new PaymentSeed(order, payments, response);
            paymentWorkflow.doActivities(seed);

            return seed;
        } catch (WorkflowException e) {
            Throwable cause = null;
            while(e.getCause() != null) {
                if (cause != null && cause.equals(e.getCause())) {
                    break;
                }
                cause = e.getCause();
{'fraction_non_alphanumeric': 0.08272108843537415, 'fraction_numerical': 0.0, 'mean_word_length': 3.8178243774574048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4159691', 'n_tokens_mistral': 923, 'n_tokens_neox': 894, 'n_words': 197}