Search in sources :

Example 1 with PurchaseOrder

use of org.apache.camel.converter.PurchaseOrder in project camel by apache.

the class PurchaseOrderConverter method toPurchaseOrder.

@Converter
public PurchaseOrder toPurchaseOrder(byte[] data) {
    String s = converter.convertTo(String.class, data);
    if (s == null || s.length() < 30) {
        throw new IllegalArgumentException("data is invalid");
    }
    s = s.replaceAll("##START##", "");
    s = s.replaceAll("##END##", "");
    String name = s.substring(0, 9).trim();
    String s2 = s.substring(10, 19).trim();
    String s3 = s.substring(20).trim();
    BigDecimal price = new BigDecimal(s2);
    price = price.setScale(2);
    Integer amount = converter.convertTo(Integer.class, s3);
    PurchaseOrder order = new PurchaseOrder(name, price, amount);
    return order;
}
Also used : PurchaseOrder(org.apache.camel.converter.PurchaseOrder) BigDecimal(java.math.BigDecimal) TypeConverter(org.apache.camel.TypeConverter) Converter(org.apache.camel.Converter)

Aggregations

BigDecimal (java.math.BigDecimal)1 Converter (org.apache.camel.Converter)1 TypeConverter (org.apache.camel.TypeConverter)1 PurchaseOrder (org.apache.camel.converter.PurchaseOrder)1