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

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

Introduction

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

Prototype

int readInt(String name);

Source Link

Document

Read the 'int' value from column with given 'name'.

Usage

From source file:io.spring.batch.SimilaritiesFieldSetMapper.java

@Override
public Object mapFieldSet(FieldSet fieldSet) throws BindException {
    int tagId = fieldSet.readInt(0);

    String[] values = fieldSet.getValues();
    Map<Integer, Double> similarites = new HashMap<Integer, Double>();

    for (int i = 1; i < values.length; i++) {
        String[] curValues = values[i].split(":");

        similarites.put(Integer.valueOf(curValues[0]), Double.valueOf(curValues[1]));
    }/*from w  w w  . java 2  s.  c o m*/

    return new Similarities(tagId, similarites);
}

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:com.sofrecom.batch.mapper.RegistrationFieldSetMapper.java

@Override
public RegistrationConfirmation mapFieldSet(FieldSet fieldSet) throws BindException {
    Integer contactId = fieldSet.readString(0) != null && !fieldSet.readString(0).isEmpty()
            ? fieldSet.readInt(0)
            : null;/*from  w  w w . ja va  2 s . co m*/
    Contact contact = new Contact(contactId, fieldSet.readString(1), fieldSet.readString(2),
            fieldSet.readString(4), fieldSet.readDate(3, "yyyy-MM-dd"));
    RegistrationConfirmation confirmation = new RegistrationConfirmation(contact, fieldSet.readBoolean(5),
            fieldSet.readDate(6));
    return confirmation;
}

From source file:io.spring.batch.reader.CustomerFieldSetMapper.java

@Override
public Customer mapFieldSet(FieldSet fieldSet) throws BindException {
    Customer cust = new Customer();

    cust.setCustomerName(fieldSet.readString(0));
    cust.setQty(fieldSet.readInt(1));

    return cust;/*from  w  ww  .  j  a  va2  s  . c o  m*/
}

From source file:io.spring.batch.jsr.reader.CustomerFieldSetMapper.java

@Override
public Customer mapFieldSet(FieldSet fieldSet) throws BindException {
    Customer cust = new Customer();

    cust.setCustomerName(fieldSet.readString(0));
    cust.setQty(fieldSet.readInt(1));

    System.out.println("Read " + cust.getCustomerName());
    return cust;/*from w  ww .j  a  v  a2 s  . c  o  m*/
}

From source file:com.griddynamics.spring.batch.football.internal.GameFieldSetMapper.java

public Game mapFieldSet(FieldSet fs) {

    if (fs == null) {
        return null;
    }//w w  w . ja  v  a2s . c om

    Game game = new Game();
    game.setId(fs.readString("id"));
    game.setYear(fs.readInt("year"));
    game.setTeam(fs.readString("team"));
    game.setWeek(fs.readInt("week"));
    game.setOpponent(fs.readString("opponent"));
    game.setCompletes(fs.readInt("completes"));
    game.setAttempts(fs.readInt("attempts"));
    game.setPassingYards(fs.readInt("passingYards"));
    game.setPassingTd(fs.readInt("passingTd"));
    game.setInterceptions(fs.readInt("interceptions"));
    game.setRushes(fs.readInt("rushes"));
    game.setRushYards(fs.readInt("rushYards"));
    game.setReceptions(fs.readInt("receptions", 0));
    game.setReceptionYards(fs.readInt("receptionYards"));
    game.setTotalTd(fs.readInt("totalTd"));

    return game;
}

From source file:io.spring.batch.configuration.BatchConfiguration.java

@Bean
@StepScope//from www . j av a 2  s .  co m
protected FlatFileItemReader<Customer> reader(@Value("#{jobParameters['fileName']}") Resource fileName)
        throws Exception {
    DefaultLineMapper<Customer> defaultLineMapper = new DefaultLineMapper<>();
    defaultLineMapper.setLineTokenizer(new DelimitedLineTokenizer());
    defaultLineMapper.setFieldSetMapper(new FieldSetMapper<Customer>() {
        @Override
        public Customer mapFieldSet(FieldSet fieldSet) throws BindException {
            Customer cust = new Customer();

            cust.setCustomerName(fieldSet.readString(0));
            cust.setQty(fieldSet.readInt(1));

            return cust;
        }
    });

    defaultLineMapper.afterPropertiesSet();

    FlatFileItemReader<Customer> reader = new FlatFileItemReader<>();
    reader.setLineMapper(defaultLineMapper);
    reader.setResource(fileName);
    reader.afterPropertiesSet();

    return reader;
}

From source file:com.griddynamics.spring.batch.football.internal.PlayerFieldSetMapper.java

public Player mapFieldSet(FieldSet fs) {

    if (fs == null) {
        return null;
    }//from www  .  ja va  2 s . co m

    Player player = new Player();
    player.setId(fs.readString("ID"));
    player.setLastName(fs.readString("lastName"));
    player.setFirstName(fs.readString("firstName"));
    player.setPosition(fs.readString("position"));
    player.setDebutYear(fs.readInt("debutYear"));
    player.setBirthYear(fs.readInt("birthYear"));

    return player;
}

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  w  w  w. j  a va  2s . 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);
    }
}