use of java.util.HashMap in project camel by apache.
the class BindyKeyValuePairDataFormat method unmarshal.
public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
BindyKeyValuePairFactory factory = (BindyKeyValuePairFactory) getFactory();
// List of Pojos
List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
// Pojos of the model
Map<String, Object> model;
// Map to hold the model @OneToMany classes while binding
Map<String, List<Object>> lists = new HashMap<String, List<Object>>();
InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));
// Scanner is used to read big file
Scanner scanner = new Scanner(in);
// Retrieve the pair separator defined to split the record
ObjectHelper.notNull(factory.getPairSeparator(), "The pair separator property of the annotation @Message");
String separator = factory.getPairSeparator();
int count = 0;
try {
while (scanner.hasNextLine()) {
// Read the line
String line = scanner.nextLine().trim();
if (ObjectHelper.isEmpty(line)) {
// skip if line is empty
continue;
}
// Increment counter
count++;
// Create POJO
model = factory.factory();
// Split the message according to the pair separator defined in
// annotated class @Message
List<String> result = Arrays.asList(line.split(separator));
if (result.size() == 0 || result.isEmpty()) {
throw new java.lang.IllegalArgumentException("No records have been defined in the KVP");
}
if (result.size() > 0) {
// Bind data from message with model classes
// Counter is used to detect line where error occurs
factory.bind(result, model, count, lists);
// Link objects together
factory.link(model);
// Add objects graph to the list
models.add(model);
LOG.debug("Graph of objects created: {}", model);
}
}
// If this is the case (correspond to an empty stream, ...)
if (models.size() == 0) {
throw new java.lang.IllegalArgumentException("No records have been defined in the CSV");
} else {
return extractUnmarshalResult(models);
}
} finally {
scanner.close();
IOHelper.close(in, "in", LOG);
}
}
use of java.util.HashMap in project camel by apache.
the class BindySimpleKeyValuePairWithoutSectionMarshallDslTest method generateModel.
public List<Map<String, Object>> generateModel() {
Map<String, Object> modelObjects = new HashMap<String, Object>();
Order order = new Order();
order.setAccount("BE.CHM.001");
order.setClOrdId("CHM0001-01");
order.setIDSource("4");
order.setSecurityId("BE0001245678");
order.setSide("1");
order.setText("this is a camel - bindy test");
modelObjects.put(order.getClass().getName(), order);
models.add(modelObjects);
return models;
}
use of java.util.HashMap in project camel by apache.
the class BindySimpleFixedLengthHeaderFooterTest method testMarshallMessageWithIndirectHeaderAndFooterInput.
/**
* Verifies that header & footer provided via message headers are marshalled successfully
*/
@Test
public void testMarshallMessageWithIndirectHeaderAndFooterInput() throws Exception {
Order order = new Order();
order.setOrderNr(10);
order.setOrderType("BUY");
order.setClientNr("A9");
order.setFirstName("Pauline");
order.setLastName("M");
order.setAmount(new BigDecimal("2500.45"));
order.setInstrumentCode("ISIN");
order.setInstrumentNumber("XD12345678");
order.setInstrumentType("Share");
order.setCurrency("USD");
Calendar calendar = new GregorianCalendar();
calendar.set(2009, 7, 1, 0, 0, 0);
order.setOrderDate(calendar.getTime());
List<Map<String, Object>> input = new ArrayList<Map<String, Object>>();
Map<String, Object> bodyRow = new HashMap<String, Object>();
bodyRow.put(Order.class.getName(), order);
input.add(bodyRow);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_HEADER, createHeaderRow());
headers.put(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_FOOTER, createFooterRow());
marshallResult.reset();
marshallResult.expectedMessageCount(1);
StringBuffer buff = new StringBuffer();
buff.append(TEST_HEADER).append(TEST_RECORD).append(TEST_FOOTER);
marshallResult.expectedBodiesReceived(Arrays.asList(new String[] { buff.toString() }));
template.sendBodyAndHeaders(URI_DIRECT_MARSHALL, input, headers);
marshallResult.assertIsSatisfied();
}
use of java.util.HashMap in project camel by apache.
the class BindySimpleCsvBooleanFalseMarshallTest method generateModel.
public List<Map<String, Object>> generateModel() {
Map<String, Object> modelObjects = new HashMap<String, Object>();
BooleanExample example = new BooleanExample();
example.setName("andrew");
example.setExist(Boolean.FALSE);
modelObjects.put(example.getClass().getName(), example);
models.add(modelObjects);
return models;
}
use of java.util.HashMap in project camel by apache.
the class BindySimpleCsvBooleanTrueMarshallTest method generateModel.
public List<Map<String, Object>> generateModel() {
Map<String, Object> modelObjects = new HashMap<String, Object>();
BooleanExample example = new BooleanExample();
example.setName("andrew");
example.setExist(Boolean.TRUE);
modelObjects.put(example.getClass().getName(), example);
models.add(modelObjects);
return models;
}
Aggregations