Example usage for org.springframework.batch.sample.domain.order Customer setBusinessCustomer

List of usage examples for org.springframework.batch.sample.domain.order Customer setBusinessCustomer

Introduction

In this page you can find the example usage for org.springframework.batch.sample.domain.order Customer setBusinessCustomer.

Prototype

public void setBusinessCustomer(boolean bussinessCustomer) 

Source Link

Usage

From source file:org.springframework.batch.sample.domain.order.internal.OrderItemReader.java

private void process(FieldSet fieldSet) throws Exception {
    // finish processing if we hit the end of file
    if (fieldSet == null) {
        log.debug("FINISHED");
        recordFinished = true;/*from  www  .j av  a  2  s. c  o m*/
        order = null;
        return;
    }

    String lineId = fieldSet.readString(0);

    if (Order.LINE_ID_HEADER.equals(lineId)) {
        log.debug("STARTING NEW RECORD");
        order = headerMapper.mapFieldSet(fieldSet);
    } else if (Order.LINE_ID_FOOTER.equals(lineId)) {
        log.debug("END OF RECORD");

        // Do mapping for footer here, because mapper does not allow to pass
        // an Order object as input.
        // Mapper always creates new object
        order.setTotalPrice(fieldSet.readBigDecimal("TOTAL_PRICE"));
        order.setTotalLines(fieldSet.readInt("TOTAL_LINE_ITEMS"));
        order.setTotalItems(fieldSet.readInt("TOTAL_ITEMS"));

        // mark we are finished with current Order
        recordFinished = true;
    } else if (Customer.LINE_ID_BUSINESS_CUST.equals(lineId)) {
        log.debug("MAPPING CUSTOMER");
        if (order.getCustomer() == null) {
            Customer customer = customerMapper.mapFieldSet(fieldSet);
            customer.setBusinessCustomer(true);
            order.setCustomer(customer);
        }
    } else if (Customer.LINE_ID_NON_BUSINESS_CUST.equals(lineId)) {
        log.debug("MAPPING CUSTOMER");
        if (order.getCustomer() == null) {
            Customer customer = customerMapper.mapFieldSet(fieldSet);
            customer.setBusinessCustomer(false);
            order.setCustomer(customer);
        }
    } else if (Address.LINE_ID_BILLING_ADDR.equals(lineId)) {
        log.debug("MAPPING BILLING ADDRESS");
        order.setBillingAddress(addressMapper.mapFieldSet(fieldSet));
    } else if (Address.LINE_ID_SHIPPING_ADDR.equals(lineId)) {
        log.debug("MAPPING SHIPPING ADDRESS");
        order.setShippingAddress(addressMapper.mapFieldSet(fieldSet));
    } else if (BillingInfo.LINE_ID_BILLING_INFO.equals(lineId)) {
        log.debug("MAPPING BILLING INFO");
        order.setBilling(billingMapper.mapFieldSet(fieldSet));
    } else if (ShippingInfo.LINE_ID_SHIPPING_INFO.equals(lineId)) {
        log.debug("MAPPING SHIPPING INFO");
        order.setShipping(shippingMapper.mapFieldSet(fieldSet));
    } else if (LineItem.LINE_ID_ITEM.equals(lineId)) {
        log.debug("MAPPING LINE ITEM");
        if (order.getLineItems() == null) {
            order.setLineItems(new ArrayList<LineItem>());
        }
        order.getLineItems().add(itemMapper.mapFieldSet(fieldSet));
    } else {
        log.debug("Could not map LINE_ID=" + lineId);
    }
}