@Override public FieldSet tokenize(String line) { if(line.charAt(0) == 'F'){ //line starts with F, so the footer tokenizer should tokenize it. FieldSet fs = footerTokenizer.tokenize(line); long customerUpdateTotal = stepExecution.getReadCount(); long fileUpdateTotal = fs.readLong(1); if(customerUpdateTotal != fileUpdateTotal){ throw new IllegalStateException("The total number of customer updates in the file footer does not match the " + "number entered File footer total: [" + fileUpdateTotal + "] Total encountered during processing: [" + customerUpdateTotal + "]"); } else{ //return null, because the footer indicates an end of processing. return null; } } else if(line.charAt(0) == 'A' || line.charAt(0) == 'U' || line.charAt(0) == 'D'){ //line starts with A,U, or D, so it must be a customer operation. return customerTokenizer.tokenize(line); } else{ //If the line doesn't start with any of the characters above, it must obviously be invalid. throw new IllegalArgumentException("Invalid line encountered for tokenizing: " + line); } }
@Override public Order mapFieldSet(FieldSet fieldSet) { Order order = new Order(); order.setOrderId(fieldSet.readLong(ORDER_ID_COLUMN)); order.setOrderDate(fieldSet.readDate(ORDER_DATE_COLUMN)); return order; } }
Trade(FieldSet fieldSet) { this.isin = fieldSet.readString(0); this.quantity = fieldSet.readLong(1); this.price = fieldSet.readBigDecimal(2); }
@Test public void testPaddedLong() { FieldSet fs = new DefaultFieldSet(new String[] { "00000009" }); long value = fs.readLong(0); assertEquals(value, 9); }
@Override public Customer mapFieldSet(FieldSet fieldSet) { Customer customer = new Customer(); if (Customer.LINE_ID_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) { customer.setCompanyName(fieldSet.readString(COMPANY_NAME_COLUMN)); // business customer must be always registered customer.setRegistered(true); } if (Customer.LINE_ID_NON_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) { customer.setLastName(fieldSet.readString(LAST_NAME_COLUMN)); customer.setFirstName(fieldSet.readString(FIRST_NAME_COLUMN)); customer.setMiddleName(fieldSet.readString(MIDDLE_NAME_COLUMN)); customer.setRegistered(TRUE_SYMBOL.equals(fieldSet.readString(REGISTERED_COLUMN))); } customer.setRegistrationId(fieldSet.readLong(REG_ID_COLUMN)); customer.setVip(TRUE_SYMBOL.equals(fieldSet.readString(VIP_COLUMN))); return customer; } }
@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; } }
@Override public LineItem mapFieldSet(FieldSet fieldSet) { LineItem item = new LineItem(); item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN)); item.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN)); item.setDiscountPerc(fieldSet.readBigDecimal(DISCOUNT_PERC_COLUMN)); item.setDiscountAmount(fieldSet.readBigDecimal(DISCOUNT_AMOUNT_COLUMN)); item.setShippingPrice(fieldSet.readBigDecimal(SHIPPING_PRICE_COLUMN)); item.setHandlingPrice(fieldSet.readBigDecimal(HANDLING_PRICE_COLUMN)); item.setQuantity(fieldSet.readInt(QUANTITY_COLUMN)); item.setTotalPrice(fieldSet.readBigDecimal(TOTAL_PRICE_COLUMN)); return item; } }
@Override public Contact mapFieldSet(FieldSet fieldSet) throws BindException { return new Contact( fieldSet.readLong("id"), fieldSet.readString("firstname"), fieldSet.readString("lastname"), fieldSet.readDate("birth","yyyy-MM-dd") ); } }
@Override public Contact mapFieldSet(FieldSet fieldSet) throws BindException { return new Contact( fieldSet.readLong("id"), fieldSet.readString("firstname"), fieldSet.readString("lastname"), fieldSet.readDate("birth","yyyy-MM-dd") ); } }
@Override public Customer mapFieldSet(FieldSet fieldSet) throws BindException { return new Customer(fieldSet.readLong("id"), fieldSet.readString("firstName"), fieldSet.readString("lastName"), fieldSet.readDate("birthdate", "yyyy-MM-dd HH:mm:ss")); } }
@Override public Customer mapFieldSet(FieldSet fieldSet) throws BindException { return new Customer(fieldSet.readLong("id"), fieldSet.readString("firstName"), fieldSet.readString("lastName"), fieldSet.readDate("birthdate", "yyyy-MM-dd HH:mm:ss")); } }
@Override public Customer mapFieldSet(FieldSet fieldSet) throws BindException { return new Customer(fieldSet.readLong("id"), fieldSet.readString("firstName"), fieldSet.readString("lastName"), fieldSet.readDate("birthdate", "yyyy-MM-dd HH:mm:ss")); } }
@Override public Contact mapFieldSet(FieldSet fieldSet) throws BindException { return new Contact( fieldSet.readLong("id"), fieldSet.readString("firstname"), fieldSet.readString("lastname"), fieldSet.readDate("birth","yyyy-MM-dd") ); } }
@Override public Contact mapFieldSet(FieldSet fieldSet) throws BindException { return new Contact( fieldSet.readLong("id"), fieldSet.readString("firstname"), fieldSet.readString("lastname"), fieldSet.readDate("birth","yyyy-MM-dd") ); } }