pl.altkom.sping.batch.sample.mapper.CustomerJpaFieldSetMapper.java Source code

Java tutorial

Introduction

Here is the source code for pl.altkom.sping.batch.sample.mapper.CustomerJpaFieldSetMapper.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.altkom.sping.batch.sample.mapper;

import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;
import pl.altkom.gemalto.spring.model.Address;
import pl.altkom.gemalto.spring.model.Customer;

/**
 *
 * @author admin
 */
public class CustomerJpaFieldSetMapper implements FieldSetMapper<Customer> {

    @Override
    public Customer mapFieldSet(FieldSet fs) throws BindException {

        Customer customer = new Customer();

        customer.setName(fs.readString("name"));
        customer.setNip(fs.readString("nip"));

        Address address = new Address();
        address.setPostalCode(fs.readString("postalCode"));
        address.setStreet(fs.readString("street"));
        address.setTown(fs.readString("town"));

        customer.setAddress(address);

        return customer;

    }

}