Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package org.belio.service.producer; import com.googlecode.jcsv.reader.CSVEntryParser; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.sql.Timestamp; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import org.belio.domain.tix.Alert; import org.belio.domain.tix.Outbox; import org.belio.model.QueueType; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; /** * * @author jacktone */ class OutboxEntryParser implements CSVEntryParser<Outbox> { private final Alert alert; public OutboxEntryParser(Alert alert) { this.alert = alert; } @Override public Outbox parseEntry(String... strings) { Outbox outbox = new Outbox(); try { // String[] strings = string[0].split(","); // System.out.println(strings[6]); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS"); outbox.setAlertsId(Long.valueOf(strings[0])); outbox.setShortCode(strings[1]); outbox.setMsisdn(Long.valueOf(strings[2])); outbox.setText(URLDecoder.decode(strings[3], "UTF-8")); outbox.setPriority(Integer.valueOf(strings[4])); outbox.setNetwork(strings[5]); outbox.setSdpId(strings[6]); outbox.setRefNo(Integer.valueOf(strings[7])); // switch (strings[2]) { // case "CONTENT": // outbox.setQueueType(QueueType.CONTENT); // break; // case "TEXT": // outbox.setQueueType(QueueType.TEXT); // break; // case "BULK": // outbox.setQueueType(QueueType.BULK); // break; // case "DATING": // outbox.setQueueType(QueueType.DATING); // break; // case "SERVICE": // outbox.setQueueType(QueueType.SERVICE); // break; // } outbox.setCreated(new Timestamp(formatter.parseDateTime(strings[8]).getMillis())); outbox.setDateCreated(new Timestamp(formatter.parseDateTime(strings[9]).getMillis())); outbox.setModified(new Timestamp(formatter.parseDateTime(strings[10]).getMillis())); // outbox.setServiceID(String.valueOf(alert.getServiceId())); } catch (UnsupportedEncodingException ex) { Logger.getLogger(OutboxEntryParser.class.getName()).log(Level.SEVERE, null, ex); } return outbox; } }