killbill-aplcache
Fix renaming issues with prevous commit (112c0b17227827d15af08b7a3504fa9dab13cfa4) …
6/11/2015 11:13:01 PM
Changes
payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlCompleted.java 90(+28 -62)
payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlInitiated.java 90(+62 -28)
Details
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlCompleted.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlCompleted.java
index 570cb68..e36fa20 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlCompleted.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlCompleted.java
@@ -1,7 +1,8 @@
/*
- * Copyright 2014 Groupon, Inc
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
*
- * Groupon licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
@@ -16,77 +17,42 @@
package org.killbill.billing.payment.core.sm.control;
-import org.joda.time.DateTime;
-import org.killbill.automaton.OperationException;
+import java.util.UUID;
+
+import org.killbill.automaton.Operation.OperationCallback;
+import org.killbill.automaton.OperationResult;
import org.killbill.automaton.State;
+import org.killbill.automaton.State.EnteringStateCallback;
import org.killbill.automaton.State.LeavingStateCallback;
-import org.killbill.billing.payment.api.TransactionType;
-import org.killbill.billing.payment.core.sm.PaymentStateContext;
+import org.killbill.billing.ObjectType;
import org.killbill.billing.payment.core.sm.PluginRoutingPaymentAutomatonRunner;
import org.killbill.billing.payment.dao.PaymentAttemptModelDao;
-import org.killbill.billing.payment.dao.PaymentDao;
-import org.killbill.billing.payment.dao.PaymentModelDao;
-import org.killbill.billing.payment.dao.PaymentTransactionModelDao;
-import org.killbill.billing.payment.dao.PluginPropertySerializer;
-import org.killbill.billing.payment.dao.PluginPropertySerializer.PluginPropertySerializerException;
-import org.killbill.billing.util.UUIDs;
-
-import com.google.common.base.Preconditions;
+import org.killbill.billing.payment.retry.BaseRetryService.RetryServiceScheduler;
-public class DefaultControlCompleted implements LeavingStateCallback {
+public class DefaultControlCompleted implements EnteringStateCallback {
- private final PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner;
- private final PaymentStateControlContext stateContext;
- private final State initialState;
- private final State retriedState;
- private final TransactionType transactionType;
- private final PaymentDao paymentDao;
+ private PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner;
+ private final PaymentStateControlContext paymentStateContext;
+ private final RetryServiceScheduler retryServiceScheduler;
- public DefaultControlCompleted(final PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner, final PaymentStateContext stateContext, final PaymentDao paymentDao,
- final State initialState, final State retriedState, final TransactionType transactionType) {
+ public DefaultControlCompleted(final PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner, final PaymentStateControlContext paymentStateContext,
+ final RetryServiceScheduler retryServiceScheduler) {
this.retryablePaymentAutomatonRunner = retryablePaymentAutomatonRunner;
- this.paymentDao = paymentDao;
- this.initialState = initialState;
- this.retriedState = retriedState;
- this.stateContext = (PaymentStateControlContext) stateContext;
- this.transactionType = transactionType;
+ this.paymentStateContext = paymentStateContext;
+ this.retryServiceScheduler = retryServiceScheduler;
}
@Override
- public void leavingState(final State state) throws OperationException {
- final DateTime utcNow = retryablePaymentAutomatonRunner.getClock().getUTCNow();
-
- if (stateContext.getPaymentId() != null && stateContext.getPaymentExternalKey() == null) {
- final PaymentModelDao payment = paymentDao.getPayment(stateContext.getPaymentId(), stateContext.getInternalCallContext());
- Preconditions.checkNotNull(payment, "payment cannot be null for id " + stateContext.getPaymentId());
- stateContext.setPaymentExternalKey(payment.getExternalKey());
- } else if (stateContext.getPaymentExternalKey() == null) {
- stateContext.setPaymentExternalKey(UUIDs.randomUUID().toString());
- }
- if (stateContext.getTransactionId() != null && stateContext.getPaymentTransactionExternalKey() == null) {
- final PaymentTransactionModelDao paymentTransactionModelDao = paymentDao.getPaymentTransaction(stateContext.getTransactionId(), stateContext.getInternalCallContext());
- Preconditions.checkNotNull(paymentTransactionModelDao, "paymentTransaction cannot be null for id " + stateContext.getTransactionId());
- stateContext.setPaymentTransactionExternalKey(paymentTransactionModelDao.getTransactionExternalKey());
- } else if (stateContext.getPaymentTransactionExternalKey() == null) {
- stateContext.setPaymentTransactionExternalKey(UUIDs.randomUUID().toString());
- }
-
- if (state.getName().equals(initialState.getName()) || state.getName().equals(retriedState.getName())) {
- try {
- final byte[] serializedProperties = PluginPropertySerializer.serialize(stateContext.getProperties());
-
- final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(stateContext.getAccount().getId(), stateContext.getPaymentMethodId(),
- utcNow, utcNow, stateContext.getPaymentExternalKey(), stateContext.getTransactionId(),
- stateContext.getPaymentTransactionExternalKey(), transactionType, initialState.getName(),
- stateContext.getAmount(), stateContext.getCurrency(),
- stateContext.getPaymentControlPluginNames(), serializedProperties);
-
- retryablePaymentAutomatonRunner.getPaymentDao().insertPaymentAttemptWithProperties(attempt, stateContext.getInternalCallContext());
-
- stateContext.setAttemptId(attempt.getId());
- } catch (final PluginPropertySerializerException e) {
- throw new OperationException(e);
- }
+ public void enteringState(final State state, final OperationCallback operationCallback, final OperationResult operationResult, final LeavingStateCallback leavingStateCallback) {
+ final PaymentAttemptModelDao attempt = retryablePaymentAutomatonRunner.getPaymentDao().getPaymentAttempt(paymentStateContext.getAttemptId(), paymentStateContext.getInternalCallContext());
+ final UUID transactionId = paymentStateContext.getCurrentTransaction() != null ?
+ paymentStateContext.getCurrentTransaction().getId() :
+ null;
+ retryablePaymentAutomatonRunner.getPaymentDao().updatePaymentAttempt(attempt.getId(), transactionId, state.getName(), paymentStateContext.getInternalCallContext());
+
+ if ("RETRIED".equals(state.getName())) {
+ retryServiceScheduler.scheduleRetry(ObjectType.PAYMENT_ATTEMPT, attempt.getId(), attempt.getId(), attempt.getTenantRecordId(),
+ paymentStateContext.getPaymentControlPluginNames(), paymentStateContext.getRetryDate());
}
}
}
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlInitiated.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlInitiated.java
index e574c50..e5c52b1 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlInitiated.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/DefaultControlInitiated.java
@@ -1,8 +1,7 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014 Groupon, Inc
*
- * The Billing Project licenses this file to you under the Apache License, version 2.0
+ * Groupon licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
@@ -17,42 +16,77 @@
package org.killbill.billing.payment.core.sm.control;
-import java.util.UUID;
-
-import org.killbill.automaton.Operation.OperationCallback;
-import org.killbill.automaton.OperationResult;
+import org.joda.time.DateTime;
+import org.killbill.automaton.OperationException;
import org.killbill.automaton.State;
-import org.killbill.automaton.State.EnteringStateCallback;
import org.killbill.automaton.State.LeavingStateCallback;
-import org.killbill.billing.ObjectType;
+import org.killbill.billing.payment.api.TransactionType;
+import org.killbill.billing.payment.core.sm.PaymentStateContext;
import org.killbill.billing.payment.core.sm.PluginRoutingPaymentAutomatonRunner;
import org.killbill.billing.payment.dao.PaymentAttemptModelDao;
-import org.killbill.billing.payment.retry.BaseRetryService.RetryServiceScheduler;
+import org.killbill.billing.payment.dao.PaymentDao;
+import org.killbill.billing.payment.dao.PaymentModelDao;
+import org.killbill.billing.payment.dao.PaymentTransactionModelDao;
+import org.killbill.billing.payment.dao.PluginPropertySerializer;
+import org.killbill.billing.payment.dao.PluginPropertySerializer.PluginPropertySerializerException;
+import org.killbill.billing.util.UUIDs;
+
+import com.google.common.base.Preconditions;
-public class DefaultControlInitiated implements EnteringStateCallback {
+public class DefaultControlInitiated implements LeavingStateCallback {
- private PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner;
- private final PaymentStateControlContext paymentStateContext;
- private final RetryServiceScheduler retryServiceScheduler;
+ private final PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner;
+ private final PaymentStateControlContext stateContext;
+ private final State initialState;
+ private final State retriedState;
+ private final TransactionType transactionType;
+ private final PaymentDao paymentDao;
- public DefaultControlInitiated(final PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner, final PaymentStateControlContext paymentStateContext,
- final RetryServiceScheduler retryServiceScheduler) {
+ public DefaultControlInitiated(final PluginRoutingPaymentAutomatonRunner retryablePaymentAutomatonRunner, final PaymentStateContext stateContext, final PaymentDao paymentDao,
+ final State initialState, final State retriedState, final TransactionType transactionType) {
this.retryablePaymentAutomatonRunner = retryablePaymentAutomatonRunner;
- this.paymentStateContext = paymentStateContext;
- this.retryServiceScheduler = retryServiceScheduler;
+ this.paymentDao = paymentDao;
+ this.initialState = initialState;
+ this.retriedState = retriedState;
+ this.stateContext = (PaymentStateControlContext) stateContext;
+ this.transactionType = transactionType;
}
@Override
- public void enteringState(final State state, final OperationCallback operationCallback, final OperationResult operationResult, final LeavingStateCallback leavingStateCallback) {
- final PaymentAttemptModelDao attempt = retryablePaymentAutomatonRunner.getPaymentDao().getPaymentAttempt(paymentStateContext.getAttemptId(), paymentStateContext.getInternalCallContext());
- final UUID transactionId = paymentStateContext.getCurrentTransaction() != null ?
- paymentStateContext.getCurrentTransaction().getId() :
- null;
- retryablePaymentAutomatonRunner.getPaymentDao().updatePaymentAttempt(attempt.getId(), transactionId, state.getName(), paymentStateContext.getInternalCallContext());
-
- if ("RETRIED".equals(state.getName())) {
- retryServiceScheduler.scheduleRetry(ObjectType.PAYMENT_ATTEMPT, attempt.getId(), attempt.getId(), attempt.getTenantRecordId(),
- paymentStateContext.getPaymentControlPluginNames(), paymentStateContext.getRetryDate());
+ public void leavingState(final State state) throws OperationException {
+ final DateTime utcNow = retryablePaymentAutomatonRunner.getClock().getUTCNow();
+
+ if (stateContext.getPaymentId() != null && stateContext.getPaymentExternalKey() == null) {
+ final PaymentModelDao payment = paymentDao.getPayment(stateContext.getPaymentId(), stateContext.getInternalCallContext());
+ Preconditions.checkNotNull(payment, "payment cannot be null for id " + stateContext.getPaymentId());
+ stateContext.setPaymentExternalKey(payment.getExternalKey());
+ } else if (stateContext.getPaymentExternalKey() == null) {
+ stateContext.setPaymentExternalKey(UUIDs.randomUUID().toString());
+ }
+ if (stateContext.getTransactionId() != null && stateContext.getPaymentTransactionExternalKey() == null) {
+ final PaymentTransactionModelDao paymentTransactionModelDao = paymentDao.getPaymentTransaction(stateContext.getTransactionId(), stateContext.getInternalCallContext());
+ Preconditions.checkNotNull(paymentTransactionModelDao, "paymentTransaction cannot be null for id " + stateContext.getTransactionId());
+ stateContext.setPaymentTransactionExternalKey(paymentTransactionModelDao.getTransactionExternalKey());
+ } else if (stateContext.getPaymentTransactionExternalKey() == null) {
+ stateContext.setPaymentTransactionExternalKey(UUIDs.randomUUID().toString());
+ }
+
+ if (state.getName().equals(initialState.getName()) || state.getName().equals(retriedState.getName())) {
+ try {
+ final byte[] serializedProperties = PluginPropertySerializer.serialize(stateContext.getProperties());
+
+ final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(stateContext.getAccount().getId(), stateContext.getPaymentMethodId(),
+ utcNow, utcNow, stateContext.getPaymentExternalKey(), stateContext.getTransactionId(),
+ stateContext.getPaymentTransactionExternalKey(), transactionType, initialState.getName(),
+ stateContext.getAmount(), stateContext.getCurrency(),
+ stateContext.getPaymentControlPluginNames(), serializedProperties);
+
+ retryablePaymentAutomatonRunner.getPaymentDao().insertPaymentAttemptWithProperties(attempt, stateContext.getInternalCallContext());
+
+ stateContext.setAttemptId(attempt.getId());
+ } catch (final PluginPropertySerializerException e) {
+ throw new OperationException(e);
+ }
}
}
}
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginRoutingPaymentAutomatonRunner.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginRoutingPaymentAutomatonRunner.java
index d80eee5..7836409 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginRoutingPaymentAutomatonRunner.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginRoutingPaymentAutomatonRunner.java
@@ -47,9 +47,9 @@ import org.killbill.billing.payment.core.sm.control.CaptureControlOperation;
import org.killbill.billing.payment.core.sm.control.ChargebackControlOperation;
import org.killbill.billing.payment.core.sm.control.CompletionControlOperation;
import org.killbill.billing.payment.core.sm.control.CreditControlOperation;
-import org.killbill.billing.payment.core.sm.control.DefaultControlInitiated;
import org.killbill.billing.payment.core.sm.control.DefaultControlCompleted;
-import org.killbill.billing.payment.core.sm.control.NoopControlCompleted;
+import org.killbill.billing.payment.core.sm.control.DefaultControlInitiated;
+import org.killbill.billing.payment.core.sm.control.NoopControlInitiated;
import org.killbill.billing.payment.core.sm.control.PurchaseControlOperation;
import org.killbill.billing.payment.core.sm.control.RefundControlOperation;
import org.killbill.billing.payment.core.sm.control.VoidControlOperation;
@@ -112,8 +112,8 @@ public class PluginRoutingPaymentAutomatonRunner extends PaymentAutomatonRunner
properties, paymentControlPluginNames, callContext, internalCallContext);
try {
final OperationCallback callback = createOperationCallback(transactionType, paymentStateContext);
- final LeavingStateCallback leavingStateCallback = new DefaultControlCompleted(this, paymentStateContext, paymentDao, paymentControlStateMachineHelper.getInitialState(), paymentControlStateMachineHelper.getRetriedState(), transactionType);
- final EnteringStateCallback enteringStateCallback = new DefaultControlInitiated(this, paymentStateContext, retryServiceScheduler);
+ final LeavingStateCallback leavingStateCallback = new DefaultControlInitiated(this, paymentStateContext, paymentDao, paymentControlStateMachineHelper.getInitialState(), paymentControlStateMachineHelper.getRetriedState(), transactionType);
+ final EnteringStateCallback enteringStateCallback = new DefaultControlCompleted(this, paymentStateContext, retryServiceScheduler);
state.runOperation(paymentControlStateMachineHelper.getOperation(), callback, enteringStateCallback, leavingStateCallback);
} catch (final MissingEntryException e) {
@@ -134,8 +134,8 @@ public class PluginRoutingPaymentAutomatonRunner extends PaymentAutomatonRunner
public Payment completeRun(final PaymentStateControlContext paymentStateContext) throws PaymentApiException {
try {
final OperationCallback callback = new CompletionControlOperation(locker, paymentPluginDispatcher, paymentStateContext, paymentProcessor, paymentControlPluginRegistry);
- final LeavingStateCallback leavingStateCallback = new NoopControlCompleted();
- final EnteringStateCallback enteringStateCallback = new DefaultControlInitiated(this, paymentStateContext, retryServiceScheduler);
+ final LeavingStateCallback leavingStateCallback = new NoopControlInitiated();
+ final EnteringStateCallback enteringStateCallback = new DefaultControlCompleted(this, paymentStateContext, retryServiceScheduler);
paymentControlStateMachineHelper.getInitialState().runOperation(paymentControlStateMachineHelper.getOperation(), callback, enteringStateCallback, leavingStateCallback);
} catch (final MissingEntryException e) {