Java Reference
In-Depth Information
Note The step after a split isn't executed until all the flows within a split are completed.
In order to do the credit verification and inventory checking required in this job, you can develop a
couple of high-tech services to perform the checking for you. You use each of these services as
ItemProcessors in your steps. First let's look at CreditServiceImpl , which is responsible for verifying that
the customer's credit card will go through. Listing 11-14 shows the code related to this process.
Listing 11-14. CreditServiceImpl
package com.apress.springbatch.chapter11.service.impl;
import com.apress.springbatch.chapter11.domain.Order;
import com.apress.springbatch.chapter11.service.CreditService;
public class CreditServiceImpl implements CreditService {
@Override
public Order validateCharge(Order order) {
if(order.getId() % 3 == 0) {
order.setCreditValidated(true);
} else {
order.setCreditValidated(false);
}
return order;
}
}
Because you don't actually process orders here, it doesn't make much sense to validate that credit
cards go through. Instead, the service approves a third of the orders. Because CreditServiceImpl has a
simplistic approach to verifying funds, you can imagine that InventoryServiceImpl has a similar
approach to making sure you have the product on hand to fulfill the order. Listing 11-15 shows the code
to verify that you have the inventory for each OrderItem .
Listing 11-15. InventoryServiceImpl
package com.apress.springbatch.chapter11.service.impl;
import com.apress.springbatch.chapter11.domain.OrderItem;
import com.apress.springbatch.chapter11.service.InventoryService;
public class InventoryServiceImpl implements InventoryService {
@Override
public OrderItem validateInventory(OrderItem item) {
if(item.getId() % 2 == 0) {
item.setInventoryValidated(true);
} else {
Search WWH ::




Custom Search