OPEN - issue BATCH-773: Refactor and extend ExportedJobLauncher to JobOperator

Add new interfaces and exceptions.  Re-align JobInstanceDao.
This commit is contained in:
dsyer
2008-08-08 14:04:55 +00:00
parent fca856dc7b
commit 61ccafa25c
17 changed files with 377 additions and 134 deletions

View File

@@ -38,7 +38,7 @@ public class OrderTransformer implements ItemTransformer<Order, List<String>> {
/**
* Aggregators for all types of lines in the output file
*/
private Map<String, LineAggregator<String[]>> aggregators;
private Map<String, LineAggregator<Object[]>> aggregators;
/**
* Converts information from an Order object to a collection of Strings for
@@ -64,11 +64,11 @@ public class OrderTransformer implements ItemTransformer<Order, List<String>> {
return result;
}
public void setAggregators(Map<String, LineAggregator<String[]>> aggregators) {
public void setAggregators(Map<String, LineAggregator<Object[]>> aggregators) {
this.aggregators = aggregators;
}
private LineAggregator<String[]> getAggregator(String name) {
private LineAggregator<Object[]> getAggregator(String name) {
return aggregators.get(name);
}
@@ -80,36 +80,36 @@ public class OrderTransformer implements ItemTransformer<Order, List<String>> {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
static String[] headerArgs(Order order) {
return new String[] { "BEGIN_ORDER:", String.valueOf(order.getOrderId()),
static Object[] headerArgs(Order order) {
return new Object[] { "BEGIN_ORDER:", String.valueOf(order.getOrderId()),
dateFormat.format(order.getOrderDate()) };
}
static String[] footerArgs(Order order) {
return new String[] { "END_ORDER:", order.getTotalPrice().toString() };
static Object[] footerArgs(Order order) {
return new Object[] { "END_ORDER:", order.getTotalPrice().toString() };
}
static String[] customerArgs(Order order) {
static Object[] customerArgs(Order order) {
Customer customer = order.getCustomer();
return new String[] { "CUSTOMER:", String.valueOf(customer.getRegistrationId()), customer.getFirstName(),
return new Object[] { "CUSTOMER:", String.valueOf(customer.getRegistrationId()), customer.getFirstName(),
customer.getMiddleName(), customer.getLastName() };
}
static String[] lineItemArgs(LineItem item) {
return new String[] { "ITEM:", String.valueOf(item.getItemId()), item.getPrice().toString() };
static Object[] lineItemArgs(LineItem item) {
return new Object[] { "ITEM:", String.valueOf(item.getItemId()), item.getPrice().toString() };
}
static String[] billingAddressArgs(Order order) {
static Object[] billingAddressArgs(Order order) {
Address address = order.getBillingAddress();
return new String[] { "ADDRESS:", address.getAddrLine1(), address.getCity(), address.getZipCode() };
return new Object[] { "ADDRESS:", address.getAddrLine1(), address.getCity(), address.getZipCode() };
}
static String[] billingInfoArgs(Order order) {
static Object[] billingInfoArgs(Order order) {
BillingInfo billingInfo = order.getBilling();
return new String[] { "BILLING:", billingInfo.getPaymentId(), billingInfo.getPaymentDesc() };
return new Object[] { "BILLING:", billingInfo.getPaymentId(), billingInfo.getPaymentDesc() };
}
}

View File

@@ -50,10 +50,10 @@ public class FlatFileOrderAggregatorTests {
order.setTotalPrice(BigDecimal.valueOf(0));
// create aggregator stub
LineAggregator<String[]> aggregator = new DelimitedLineAggregator<String>();
LineAggregator<Object[]> aggregator = new DelimitedLineAggregator<Object>();
// create map of aggregators and set it to writer
Map<String, LineAggregator<String[]>> aggregators = new HashMap<String, LineAggregator<String[]>>();
Map<String, LineAggregator<Object[]>> aggregators = new HashMap<String, LineAggregator<Object[]>>();
OrderTransformer converter = new OrderTransformer();
aggregators.put("header", aggregator);

View File

@@ -1,62 +0,0 @@
/*
* Copyright 2006-2008 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.sample.domain.order;
import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import org.junit.Test;
import org.springframework.batch.item.file.transform.LineAggregator;
import org.springframework.batch.item.file.transform.PassThroughLineAggregator;
import org.springframework.batch.sample.domain.order.internal.OrderTransformer;
/**
* @author Dave Syer
*
*/
public class OrderTransformerTests {
private OrderTransformer converter = new OrderTransformer();
@Test
public void testConvert() throws Exception {
converter.setAggregators(new HashMap<String, LineAggregator<String[]>>() {
{
put("header", new PassThroughLineAggregator<String[]>());
put("customer", new PassThroughLineAggregator<String[]>());
put("address", new PassThroughLineAggregator<String[]>());
put("billing", new PassThroughLineAggregator<String[]>());
put("item", new PassThroughLineAggregator<String[]>());
put("footer", new PassThroughLineAggregator<String[]>());
}
});
Order order = new Order();
order.setOrderDate(new Date());
order.setCustomer(new Customer());
order.setBillingAddress(new Address());
order.setBilling(new BillingInfo());
order.setLineItems(new ArrayList<LineItem>());
order.setTotalPrice(new BigDecimal(10));
Object result = converter.transform(order);
assertTrue(result instanceof Collection);
}
}