Java Reference
In-Depth Information
import com.apress.springbatch.statement.domain.PricingTier;
public class FeesItemProcessor implements
ItemProcessor<AccountTransaction, AccountTransaction> {
public AccountTransaction process(AccountTransaction transaction)
throws Exception {
if (transaction.getTier() == PricingTier.I) {
priceTierOneTransaction(transaction);
} else if (transaction.getTier() == PricingTier.II) {
priceTierTwoTransaction(transaction);
} else if (transaction.getTier() == PricingTier.II) {
priceTierThreeTransaction(transaction);
} else {
priceTierFourTransaction(transaction);
}
return transaction;
}
private void priceTierFourTransaction(AccountTransaction transaction) {
transaction.setFee(new BigDecimal(1.00));
}
private void priceTierThreeTransaction(AccountTransaction transaction) {
transaction.setFee(new BigDecimal(2.00));
}
private void priceTierTwoTransaction(AccountTransaction transaction) {
transaction.setFee(new BigDecimal(3.00));
}
private void priceTierOneTransaction(AccountTransaction transaction) {
BigDecimal fee = transaction.getPrice()
.multiply(new BigDecimal(.001));
fee = fee.add(new BigDecimal(9.00));
transaction.setFee(fee);
}
}
FeesItemProcessor
determines what tier the account for each transaction has been calculated to be.
From there, it calls the appropriate method to calculate the price. To configure this ItemProcessor, you
use virtually the same configuration you did for
pricingTiersItemProcessor
. Listing 10-39 has the
configuration for
feesItemProcessor
.
Listing 10-39.
Configuration for the
calculateTransactionFees
Step
...
<beans:bean id="feesItemProcessor"