REOPENED - issue BATCH-640: FieldSetMapper.mapLine() should contain the line number

This commit is contained in:
dsyer
2008-08-06 22:36:57 +00:00
parent b690c6e92b
commit b9291aff16
27 changed files with 125 additions and 97 deletions

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.explore;
import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
/**
* @author Dave Syer
*
*/
public interface BatchMetaDataExplorer {
int countJobExecutionsByStatus(EnumSet<BatchStatus> statuses);
/**
* @param statuses the status values to search
* @param start the start record (defaults to 0)
* @param count the maximum number of objects to return
* @return the {@link JobExecution} objects that have the provided status,
* sorted in reverse order by start time.
*/
Collection<JobExecution> findJobExecutionsByStatus(EnumSet<BatchStatus> statuses, int start, int count);
int countJobExecutionsByDate(Date from, Date to);
Collection<JobExecution> findJobExecutionsByDate(Date from, Date to, int start, int count);
Collection<JobInstance> findJobInstancesByJobName(String jobName);
Collection<JobExecution> getJobExecutionsForJobInstance(JobInstance jobInstance);
}

View File

@@ -245,7 +245,7 @@ public class FlatFileItemReader<T> extends AbstractBufferedItemReaderItemStream<
if (record != null) {
try {
FieldSet tokenizedLine = tokenizer.tokenize(record);
return fieldSetMapper.mapLine(tokenizedLine, lineCount);
return fieldSetMapper.mapLine(tokenizedLine);
}
catch (RuntimeException ex) {
// add current line count to message and re-throw

View File

@@ -102,7 +102,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
/**
* The bean name (id) for an object that can be populated from the field set
* that will be passed into {@link #mapLine(FieldSet, int)}. Typically a
* that will be passed into {@link #mapLine(FieldSet)}. Typically a
* prototype scoped bean so that a new instance is returned for each field
* set mapped.
*
@@ -118,7 +118,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
/**
* Public setter for the type of bean to create instead of using a prototype
* bean. An object of this type will be created from its default constructor
* for every call to {@link #mapLine(FieldSet, int)}.<br/>
* for every call to {@link #mapLine(FieldSet)}.<br/>
*
* Either this property or the prototype bean name must be specified, but
* not both.
@@ -153,10 +153,10 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
* the {@link DataBinder} from {@link #createBinder(Object)} has errors
* after binding).
*
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet, int)
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet)
*/
@SuppressWarnings("unchecked")
public T mapLine(FieldSet fs, int lineNum) {
public T mapLine(FieldSet fs) {
T copy = getBean();
DataBinder binder = createBinder(copy);
binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties())));

View File

@@ -30,7 +30,6 @@ public interface FieldSetMapper<T> {
* Method used to map data obtained from a {@link FieldSet} into an object.
*
* @param fs the {@link FieldSet} to map
* @param lineNum the current line number (if known), or negative if not
*/
public T mapLine(FieldSet fs, int lineNum);
public T mapLine(FieldSet fs);
}

View File

@@ -31,7 +31,7 @@ public class PassThroughFieldSetMapper implements FieldSetMapper<FieldSet> {
* org.springframework.batch.io.file.FieldSetMapper#mapLine(org.springframework
* .batch.io.file.FieldSet)
*/
public FieldSet mapLine(FieldSet fs, int lineNum) {
public FieldSet mapLine(FieldSet fs) {
return fs;
}

View File

@@ -78,14 +78,12 @@ public class AggregateItemFieldSetMapper<T> implements FieldSetMapper<AggregateI
* input {@link FieldSet} to check for begin and end delimiters. If the
* current record is neither a begin nor an end marker then it is mapped
* using the delegate.
*
* @param fieldSet a {@link FieldSet} to map
* @param lineNum the current line number if known
*
* @return an {@link AggregateItem} that wraps the return value from the
* delegate
*/
public AggregateItem<T> mapLine(FieldSet fieldSet, int lineNum) {
public AggregateItem<T> mapLine(FieldSet fieldSet) {
if (fieldSet.readString(0).equals(begin)) {
return AggregateItem.getHeader();
@@ -94,7 +92,7 @@ public class AggregateItemFieldSetMapper<T> implements FieldSetMapper<AggregateI
return AggregateItem.getFooter();
}
return new AggregateItem<T>(delegate.mapLine(fieldSet, lineNum));
return new AggregateItem<T>(delegate.mapLine(fieldSet));
}

View File

@@ -1,7 +1,5 @@
package org.springframework.batch.item.support;
import java.util.List;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
@@ -15,9 +13,9 @@ import org.springframework.batch.item.ItemWriter;
*/
public class CompositeItemWriter<T> implements ItemWriter<T> {
private List<ItemWriter<T>> delegates;
private ItemWriter<? super T>[] delegates;
public void setDelegates(List<ItemWriter<T>> delegates) {
public void setDelegates(ItemWriter<? super T>[] delegates) {
this.delegates = delegates;
}
@@ -25,19 +23,19 @@ public class CompositeItemWriter<T> implements ItemWriter<T> {
* Calls injected ItemProcessors in order.
*/
public void write(T item) throws Exception {
for (ItemWriter<T> writer : delegates) {
for (ItemWriter<? super T> writer : delegates) {
writer.write(item);
}
}
public void clear() throws ClearFailedException {
for (ItemWriter<T> writer : delegates) {
for (ItemWriter<? super T> writer : delegates) {
writer.clear();
}
}
public void flush() throws FlushFailedException {
for (ItemWriter<T> writer : delegates) {
for (ItemWriter<? super T> writer : delegates) {
writer.flush();
}
}

View File

@@ -18,8 +18,6 @@ package org.springframework.batch.item.file;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
@@ -104,23 +102,6 @@ public class FlatFileItemReaderBasicTests extends TestCase {
assertEquals(null, itemReader.read());
}
/**
* Regular usage of <code>read</code> method
*/
public void testReadWithLineNumber() throws Exception {
final List<Integer> list = new ArrayList<Integer>();
itemReader.setFieldSetMapper(new FieldSetMapper<FieldSet>() {
public FieldSet mapLine(FieldSet fs, int lineNum) {
list.add(lineNum);
return fs;
}
});
itemReader.open(executionContext);
assertEquals("[FlatFileInputTemplate-TestData]", itemReader.read().toString());
assertEquals(new Integer(1), list.get(0));
assertEquals(null, itemReader.read());
}
/**
* Regular usage of <code>read</code> method
*/
@@ -142,7 +123,7 @@ public class FlatFileItemReaderBasicTests extends TestCase {
public void testReadWithMapperError() throws Exception {
itemReader.setFieldSetMapper(new FieldSetMapper<FieldSet>() {
public FieldSet mapLine(FieldSet fs, int lineNum) {
public FieldSet mapLine(FieldSet fs) {
throw new RuntimeException("foo");
}
});

View File

@@ -21,7 +21,7 @@ public class FlatFileItemReaderCommonTests extends CommonItemStreamItemReaderTes
Resource resource = new ByteArrayResource(FOOS.getBytes());
tested.setResource(resource);
tested.setFieldSetMapper(new FieldSetMapper<Foo>() {
public Foo mapLine(FieldSet fs, int lineNum) {
public Foo mapLine(FieldSet fs) {
Foo foo = new Foo();
foo.setValue(fs.readInt(0));
return foo;

View File

@@ -23,7 +23,7 @@ public class MultiResourceItemReaderFlatFileTests extends
FlatFileItemReader<Foo> fileReader = new FlatFileItemReader<Foo>();
fileReader.setFieldSetMapper(new FieldSetMapper<Foo>() {
public Foo mapLine(FieldSet fs, int lineNum) {
public Foo mapLine(FieldSet fs) {
Foo foo = new Foo();
foo.setValue(fs.readInt(0));
return foo;

View File

@@ -63,7 +63,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -78,7 +78,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -93,7 +93,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "VarString", "VAR_BOOLEAN", "VAR_CHAR" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -107,7 +107,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -130,7 +130,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
new String[] { "This is some dummy string", "1", "Another dummy", "2" }, new String[] { "valueA",
"valueB", "testObjectB.valueA", "testObjectB.testObjectC.value" });
TestNestedA result = mapper.mapLine(fieldSet, -1);
TestNestedA result = mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getValueA());
assertEquals(1, result.getValueB());
@@ -150,7 +150,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "1" }, new String[] {
"VALUE_A", "VALUE_B" });
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet, -1);
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet);
assertEquals("This is some dummy string", result.getValueA());
assertEquals(1, result.getValueB());
@@ -167,7 +167,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1" }, new String[] { "foo" });
TestNestedC result = mapper.mapLine(fieldSet, -1);
TestNestedC result = mapper.mapLine(fieldSet);
// "foo" is similar enough to "value" that it matches - but only because
// nothing else does...
@@ -189,7 +189,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy", "2" }, new String[] {
"TestObjectB.ValueA", "TestObjectB.TestObjectC.Value" });
TestNestedA result = mapper.mapLine(fieldSet, -1);
TestNestedA result = mapper.mapLine(fieldSet);
assertEquals("Another dummy", result.getTestObjectB().getValueA());
assertEquals(2, result.getTestObjectB().getTestObjectC().getValue());
@@ -209,7 +209,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy" }, new String[] { "TestObjectB.foo" });
try {
mapper.mapLine(fieldSet, -1);
mapper.mapLine(fieldSet);
fail("Expected NotWritablePropertyException");
}
catch (NotWritablePropertyException e) {
@@ -231,7 +231,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "2" }, new String[] { "TestObjectA.garbage" });
try {
mapper.mapLine(fieldSet, -1);
mapper.mapLine(fieldSet);
fail("Expected NotWritablePropertyException");
}
catch (NotWritablePropertyException e) {
@@ -271,7 +271,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1", "2", "3" }, new String[] { "NestedC[0].Value",
"NestedC[1].Value", "NestedC[2].Value" });
mapper.mapLine(fieldSet, -1);
mapper.mapLine(fieldSet);
assertEquals(1, ((TestNestedC) nestedList.getNestedC().get(0)).getValue());
assertEquals(2, ((TestNestedC) nestedList.getNestedC().get(1)).getValue());
@@ -285,7 +285,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
mapper.setTargetType(TestObject.class);
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
TestObject bean = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject bean = (TestObject) mapper.mapLine(fieldSet);
// since Spring 2.5.5 this is OK (before that BATCH-261)
assertEquals(9, bean.getVarLong());
}
@@ -299,7 +299,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
.getNumberInstance(), true)));
TestObject bean = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject bean = (TestObject) mapper.mapLine(fieldSet);
assertEquals(9, bean.getVarLong());
}
@@ -313,7 +313,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
.getNumberInstance(), true)));
TestObject bean = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject bean = (TestObject) mapper.mapLine(fieldSet);
assertEquals(9, bean.getVarLong());
assertEquals(78, bean.getVarInt());

View File

@@ -27,11 +27,11 @@ public class PassThroughFieldSetMapperTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet, int)}.
* {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet)}.
*/
public void testMapLine() {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" });
assertEquals(fieldSet, mapper.mapLine(fieldSet, -1));
assertEquals(fieldSet, mapper.mapLine(fieldSet));
}

View File

@@ -16,26 +16,26 @@ public class AggregateItemFieldSetMapperTests {
@Test
public void testDefaultBeginRecord() throws Exception {
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" }), -1).isHeader());
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" }), -1).isFooter());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" })).isHeader());
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "BEGIN" })).isFooter());
}
@Test
public void testSetBeginRecord() throws Exception {
mapper.setBegin("FOO");
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" }), -1).isHeader());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" })).isHeader());
}
@Test
public void testDefaultEndRecord() throws Exception {
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "END" }), -1).isHeader());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "END" }), -1).isFooter());
assertFalse(mapper.mapLine(new DefaultFieldSet(new String[] { "END" })).isHeader());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "END" })).isFooter());
}
@Test
public void testSetEndRecord() throws Exception {
mapper.setEnd("FOO");
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" }), -1).isFooter());
assertTrue(mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" })).isFooter());
}
@Test
@@ -52,11 +52,11 @@ public class AggregateItemFieldSetMapperTests {
@Test
public void testDelegate() throws Exception {
mapper.setDelegate(new FieldSetMapper<String>() {
public String mapLine(FieldSet fs, int lineNum) {
public String mapLine(FieldSet fs) {
return "foo";
}
});
assertEquals("foo", mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" }), -1).getItem());
assertEquals("foo", mapper.mapLine(new DefaultFieldSet(new String[] { "FOO" })).getItem());
}

View File

@@ -1,11 +1,11 @@
package org.springframework.batch.item.support;
import java.util.ArrayList;
import java.util.List;
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import junit.framework.TestCase;
import static org.easymock.EasyMock.*;
import org.springframework.batch.item.ItemWriter;
/**
@@ -28,7 +28,8 @@ public class CompositeItemWriterTests extends TestCase {
final int NUMBER_OF_WRITERS = 10;
Object data = new Object();
List<ItemWriter<Object>> writers = new ArrayList<ItemWriter<Object>>(NUMBER_OF_WRITERS);
@SuppressWarnings("unchecked")
ItemWriter<Object>[] writers = new ItemWriter[NUMBER_OF_WRITERS];
for (int i = 0; i < NUMBER_OF_WRITERS; i++) {
@SuppressWarnings("unchecked")
@@ -38,7 +39,7 @@ public class CompositeItemWriterTests extends TestCase {
expectLastCall().once();
replay(writer);
writers.add(writer);
writers[i] = writer;
}
itemProcessor.setDelegates(writers);

View File

@@ -60,7 +60,7 @@ public abstract class AbstractTradeBatchTests extends TestCase {
}
protected static class TradeMapper implements FieldSetMapper<Trade> {
public Trade mapLine(FieldSet fs, int lineNum) {
public Trade mapLine(FieldSet fs) {
return new Trade(fs);
}
}

View File

@@ -6,7 +6,7 @@ import org.springframework.batch.sample.domain.football.Game;
public class GameFieldSetMapper implements FieldSetMapper<Game> {
public Game mapLine(FieldSet fs, int lineNum) {
public Game mapLine(FieldSet fs) {
if(fs == null){
return null;

View File

@@ -6,7 +6,7 @@ import org.springframework.batch.sample.domain.football.Player;
public class PlayerFieldSetMapper implements FieldSetMapper<Player> {
public Player mapLine(FieldSet fs, int lineNum) {
public Player mapLine(FieldSet fs) {
if(fs == null){
return null;

View File

@@ -33,7 +33,7 @@ public class AddressFieldSetMapper implements FieldSetMapper<Address> {
public static final String COUNTRY_COLUMN = "COUNTRY";
public Address mapLine(FieldSet fieldSet, int lineNum) {
public Address mapLine(FieldSet fieldSet) {
Address address = new Address();
address.setAddressee(fieldSet.readString(ADDRESSEE_COLUMN));

View File

@@ -27,7 +27,7 @@ public class BillingFieldSetMapper implements FieldSetMapper<BillingInfo> {
public static final String PAYMENT_TYPE_ID_COLUMN = "PAYMENT_TYPE_ID";
public static final String PAYMENT_DESC_COLUMN = "PAYMENT_DESC";
public BillingInfo mapLine(FieldSet fieldSet, int lineNum) {
public BillingInfo mapLine(FieldSet fieldSet) {
BillingInfo info = new BillingInfo();
info.setPaymentId(fieldSet.readString(PAYMENT_TYPE_ID_COLUMN));

View File

@@ -34,7 +34,7 @@ public class CustomerFieldSetMapper implements FieldSetMapper<Customer> {
public static final String REG_ID_COLUMN = "REG_ID";
public static final String VIP_COLUMN = "VIP";
public Customer mapLine(FieldSet fieldSet, int lineNum) {
public Customer mapLine(FieldSet fieldSet) {
Customer customer = new Customer();
if (Customer.LINE_ID_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {

View File

@@ -27,7 +27,7 @@ public class HeaderFieldSetMapper implements FieldSetMapper<Order> {
public static final String ORDER_ID_COLUMN = "ORDER_ID";
public static final String ORDER_DATE_COLUMN = "ORDER_DATE";
public Order mapLine(FieldSet fieldSet, int lineNum) {
public Order mapLine(FieldSet fieldSet) {
Order order = new Order();
order.setOrderId(fieldSet.readLong(ORDER_ID_COLUMN));
order.setOrderDate(fieldSet.readDate(ORDER_DATE_COLUMN));

View File

@@ -33,7 +33,7 @@ public class OrderItemFieldSetMapper implements FieldSetMapper<LineItem> {
public static final String ITEM_ID_COLUMN = "ITEM_ID";
public LineItem mapLine(FieldSet fieldSet, int lineNum) {
public LineItem mapLine(FieldSet fieldSet) {
LineItem item = new LineItem();
item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN));

View File

@@ -90,7 +90,7 @@ public class OrderItemReader extends AbstractItemReader<Order> {
// start a new Order
if (Order.LINE_ID_HEADER.equals(lineId)) {
log.debug("STARTING NEW RECORD");
order = headerMapper.mapLine(fieldSet, -1);
order = headerMapper.mapLine(fieldSet);
return;
}
@@ -115,7 +115,7 @@ public class OrderItemReader extends AbstractItemReader<Order> {
log.debug("MAPPING CUSTOMER");
if (order.getCustomer() == null) {
order.setCustomer(customerMapper.mapLine(fieldSet, -1));
order.setCustomer(customerMapper.mapLine(fieldSet));
order.getCustomer().setBusinessCustomer(true);
}
@@ -126,7 +126,7 @@ public class OrderItemReader extends AbstractItemReader<Order> {
log.debug("MAPPING CUSTOMER");
if (order.getCustomer() == null) {
order.setCustomer(customerMapper.mapLine(fieldSet, -1));
order.setCustomer(customerMapper.mapLine(fieldSet));
order.getCustomer().setBusinessCustomer(false);
}
@@ -135,25 +135,25 @@ public class OrderItemReader extends AbstractItemReader<Order> {
if (Address.LINE_ID_BILLING_ADDR.equals(lineId)) {
log.debug("MAPPING BILLING ADDRESS");
order.setBillingAddress(addressMapper.mapLine(fieldSet, -1));
order.setBillingAddress(addressMapper.mapLine(fieldSet));
return;
}
if (Address.LINE_ID_SHIPPING_ADDR.equals(lineId)) {
log.debug("MAPPING SHIPPING ADDRESS");
order.setShippingAddress(addressMapper.mapLine(fieldSet, -1));
order.setShippingAddress(addressMapper.mapLine(fieldSet));
return;
}
if (BillingInfo.LINE_ID_BILLING_INFO.equals(lineId)) {
log.debug("MAPPING BILLING INFO");
order.setBilling(billingMapper.mapLine(fieldSet, -1));
order.setBilling(billingMapper.mapLine(fieldSet));
return;
}
if (ShippingInfo.LINE_ID_SHIPPING_INFO.equals(lineId)) {
log.debug("MAPPING SHIPPING INFO");
order.setShipping(shippingMapper.mapLine(fieldSet, -1));
order.setShipping(shippingMapper.mapLine(fieldSet));
return;
}
@@ -163,7 +163,7 @@ public class OrderItemReader extends AbstractItemReader<Order> {
if (order.getLineItems() == null) {
order.setLineItems(new ArrayList<LineItem>());
}
order.getLineItems().add(itemMapper.mapLine(fieldSet, -1));
order.getLineItems().add(itemMapper.mapLine(fieldSet));
return;
}

View File

@@ -28,7 +28,7 @@ public class ShippingFieldSetMapper implements FieldSetMapper<ShippingInfo> {
public static final String SHIPPING_TYPE_ID_COLUMN = "SHIPPING_TYPE_ID";
public static final String SHIPPER_ID_COLUMN = "SHIPPER_ID";
public ShippingInfo mapLine(FieldSet fieldSet, int lineNum) {
public ShippingInfo mapLine(FieldSet fieldSet) {
ShippingInfo info = new ShippingInfo();
info.setShipperId(fieldSet.readString(SHIPPER_ID_COLUMN));

View File

@@ -29,7 +29,7 @@ public class TradeFieldSetMapper implements FieldSetMapper<Trade> {
public static final int PRICE_COLUMN = 2;
public static final int CUSTOMER_COLUMN = 3;
public Trade mapLine(FieldSet fieldSet, int lineNum) {
public Trade mapLine(FieldSet fieldSet) {
Trade trade = new Trade();
trade.setIsin(fieldSet.readString(ISIN_COLUMN));

View File

@@ -84,13 +84,13 @@ public class OrderItemReaderTests {
// create mock mapper
FieldSetMapper mapper = createMock(FieldSetMapper.class);
// set how mapper should respond - set return values for mapper
expect(mapper.mapLine(headerFS, -1)).andReturn(order);
expect(mapper.mapLine(customerFS, -1)).andReturn(customer);
expect(mapper.mapLine(billingFS, -1)).andReturn(billing);
expect(mapper.mapLine(shippingFS, -1)).andReturn(shipping);
expect(mapper.mapLine(billingInfoFS, -1)).andReturn(billingInfo);
expect(mapper.mapLine(shippingInfoFS, -1)).andReturn(shippingInfo);
expect(mapper.mapLine(itemFS, -1)).andReturn(item).times(3);
expect(mapper.mapLine(headerFS)).andReturn(order);
expect(mapper.mapLine(customerFS)).andReturn(customer);
expect(mapper.mapLine(billingFS)).andReturn(billing);
expect(mapper.mapLine(shippingFS)).andReturn(shipping);
expect(mapper.mapLine(billingInfoFS)).andReturn(billingInfo);
expect(mapper.mapLine(shippingInfoFS)).andReturn(shippingInfo);
expect(mapper.mapLine(itemFS)).andReturn(item).times(3);
replay(mapper);
// set-up provider: set mappers

View File

@@ -37,7 +37,7 @@ public abstract class AbstractFieldSetMapperTests {
*/
@Test
public void testRegularUse() {
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet(), -1));
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet()));
}
}