Example usage for org.springframework.batch.item.file.transform FieldSet readBigDecimal

List of usage examples for org.springframework.batch.item.file.transform FieldSet readBigDecimal

Introduction

In this page you can find the example usage for org.springframework.batch.item.file.transform FieldSet readBigDecimal.

Prototype

BigDecimal readBigDecimal(String name);

Source Link

Document

Read the java.math.BigDecimal value from column with given 'name.

Usage

From source file:org.jboss.examples.spring.batch.multiline.TradeFieldSetMapper.java

@Override
public Trade mapFieldSet(FieldSet fieldSet) {

    Trade trade = new Trade();
    trade.setIsin(fieldSet.readString(ISIN_COLUMN));
    trade.setQuantity(fieldSet.readLong(QUANTITY_COLUMN));
    trade.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN));
    trade.setCustomer(fieldSet.readString(CUSTOMER_COLUMN));

    return trade;
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.CustomerCreditFieldSetMapper.java

@Override
public CustomerCredit mapFieldSet(FieldSet fieldSet) {
    CustomerCredit trade = new CustomerCredit();
    trade.setId(fieldSet.readInt(ID_COLUMN));
    trade.setName(fieldSet.readString(NAME_COLUMN));
    trade.setCredit(fieldSet.readBigDecimal(CREDIT_COLUMN));

    return trade;
}

From source file:lcn.module.batch.web.guide.service.TradeFieldSetMapper.java

public Trade mapFieldSet(FieldSet fieldSet) {

    Trade trade = new Trade();
    trade.setIsin(fieldSet.readString(ISIN_COLUMN));
    trade.setQuantity(fieldSet.readLong(QUANTITY_COLUMN));
    trade.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN));
    trade.setCustomer(fieldSet.readString(CUSTOMER_COLUMN));

    return trade;
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.CustomerUpdateFieldSetMapper.java

@Override
public CustomerUpdate mapFieldSet(FieldSet fs) {

    if (fs == null) {
        return null;
    }//from w  w  w.  j  a  v a2s .c o m

    CustomerOperation operation = CustomerOperation.fromCode(fs.readChar(0));
    String name = fs.readString(1);
    BigDecimal credit = fs.readBigDecimal(2);

    return new CustomerUpdate(operation, name, credit);

}

From source file:com.manning.siia.batch.PaymentFieldSetMapper.java

@Override
public Payment mapFieldSet(FieldSet fieldSet) throws BindException {
    Payment payment = new Payment();

    payment.setSourceAccountNo(fieldSet.readString("source"));
    payment.setDestinationAccountNo(fieldSet.readString("destination"));
    payment.setAmount(fieldSet.readBigDecimal("amount"));
    payment.setDate(fieldSet.readDate("date"));

    return payment;
}

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;/*  www  .  ja  v 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);
    }
}