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.Customer;
22  
23  public class CustomerFieldSetMapper implements FieldSetMapper<Customer> {
24  
25  	public static final String LINE_ID_COLUMN = "LINE_ID";
26  	public static final String COMPANY_NAME_COLUMN = "COMPANY_NAME";
27  	public static final String LAST_NAME_COLUMN = "LAST_NAME";
28  	public static final String FIRST_NAME_COLUMN = "FIRST_NAME";
29  	public static final String MIDDLE_NAME_COLUMN = "MIDDLE_NAME";
30  	public static final String TRUE_SYMBOL = "T";
31  	public static final String REGISTERED_COLUMN = "REGISTERED";
32  	public static final String REG_ID_COLUMN = "REG_ID";
33  	public static final String VIP_COLUMN = "VIP";
34  
35  	public Customer mapFieldSet(FieldSet fieldSet) {
36  		Customer customer = new Customer();
37  
38  		if (Customer.LINE_ID_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {
39  			customer.setCompanyName(fieldSet.readString(COMPANY_NAME_COLUMN));
40  			// business customer must be always registered
41  			customer.setRegistered(true);
42  		}
43  
44  		if (Customer.LINE_ID_NON_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {
45  			customer.setLastName(fieldSet.readString(LAST_NAME_COLUMN));
46  			customer.setFirstName(fieldSet.readString(FIRST_NAME_COLUMN));
47  			customer.setMiddleName(fieldSet.readString(MIDDLE_NAME_COLUMN));
48  			customer.setRegistered(TRUE_SYMBOL.equals(fieldSet.readString(REGISTERED_COLUMN)));
49  		}
50  
51  		customer.setRegistrationId(fieldSet.readLong(REG_ID_COLUMN));
52  		customer.setVip(TRUE_SYMBOL.equals(fieldSet.readString(VIP_COLUMN)));
53  
54  		return customer;
55  	}
56  }