View Javadoc

1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.sample.domain.order.internal.mapper;
18  
19  import org.springframework.batch.item.file.mapping.FieldSetMapper;
20  import org.springframework.batch.item.file.transform.FieldSet;
21  import org.springframework.batch.sample.domain.order.LineItem;
22  
23  public class OrderItemFieldSetMapper implements FieldSetMapper<LineItem> {
24  
25  	public static final String TOTAL_PRICE_COLUMN = "TOTAL_PRICE";
26  	public static final String QUANTITY_COLUMN = "QUANTITY";
27  	public static final String HANDLING_PRICE_COLUMN = "HANDLING_PRICE";
28  	public static final String SHIPPING_PRICE_COLUMN = "SHIPPING_PRICE";
29  	public static final String DISCOUNT_AMOUNT_COLUMN = "DISCOUNT_AMOUNT";
30  	public static final String DISCOUNT_PERC_COLUMN = "DISCOUNT_PERC";
31  	public static final String PRICE_COLUMN = "PRICE";
32  	public static final String ITEM_ID_COLUMN = "ITEM_ID";
33  
34  	public LineItem mapFieldSet(FieldSet fieldSet) {
35  		LineItem item = new LineItem();
36  
37  		item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN));
38  		item.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN));
39  		item.setDiscountPerc(fieldSet.readBigDecimal(DISCOUNT_PERC_COLUMN));
40  		item.setDiscountAmount(fieldSet.readBigDecimal(DISCOUNT_AMOUNT_COLUMN));
41  		item.setShippingPrice(fieldSet.readBigDecimal(SHIPPING_PRICE_COLUMN));
42  		item.setHandlingPrice(fieldSet.readBigDecimal(HANDLING_PRICE_COLUMN));
43  		item.setQuantity(fieldSet.readInt(QUANTITY_COLUMN));
44  		item.setTotalPrice(fieldSet.readBigDecimal(TOTAL_PRICE_COLUMN));
45  
46  		return item;
47  	}
48  }