Subversion Repositories SmartDukaan

Rev

Rev 7930 | Rev 8368 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7930 manish.sha 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.config.ConfigException;
4
import in.shop2020.serving.model.ShipmentUpdate;
5
import in.shop2020.thrift.clients.config.ConfigClient;
6
 
7
import java.text.SimpleDateFormat;
8
import java.util.ArrayList;
9
import java.util.List;
8353 manish.sha 10
 
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
 
7930 manish.sha 14
import com.TrackWebServiceClient;
15
import com.fedex.track.stub.ClientDetail;
16
import com.fedex.track.stub.TrackDetail;
17
import com.fedex.track.stub.TrackEvent;
18
import com.fedex.track.stub.TrackReply;
19
import com.fedex.track.stub.WebAuthenticationCredential;
20
import com.fedex.track.stub.WebAuthenticationDetail;
21
 
22
public class FedExTrackingService {
8353 manish.sha 23
 
24
	private static final Log log = LogFactory.getLog(FedExTrackingService.class);
7930 manish.sha 25
	private TrackReply trackreply;
26
	/**
27
	 * @param args
28
	 */
29
 
30
	public List<ShipmentUpdate> getUpdates(String awbNumber){
31
		List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
32
		 ClientDetail clientDetail = new ClientDetail();
33
	        String accountNumber ="";
34
	        String meterNumber ="";
35
			try {
36
				accountNumber = ConfigClient.getClient().get("fedex_account_number");
37
				meterNumber = ConfigClient.getClient().get("fedex_meter_number");
38
			} catch (ConfigException e) {
39
				e.printStackTrace();
40
			}			
41
	        clientDetail.setAccountNumber(accountNumber);
42
	        clientDetail.setMeterNumber(meterNumber);
43
	        WebAuthenticationCredential wac = new WebAuthenticationCredential();
44
	        String key="";
45
	        String password="";
46
			try {
47
				key = ConfigClient.getClient().get("fedex_authenication_key");
48
				password = ConfigClient.getClient().get("fedex_authenication_password");
49
			} catch (ConfigException e) {
50
				e.printStackTrace();
51
			}
52
	        wac.setKey(key);
53
	        wac.setPassword(password);
54
         String endPoint="";
55
			try {
56
				endPoint = ConfigClient.getClient().get("fedex_endpoint_address_track");
57
			} catch (ConfigException e) {
8353 manish.sha 58
				log.error("Could not fetch End Point Address", e);
7930 manish.sha 59
			}
60
 
61
		trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetail, new WebAuthenticationDetail(wac), endPoint);
62
		if(trackreply!=null){
63
			TrackDetail[] trackDetails=trackreply.getTrackDetails();
64
			SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
65
			SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
66
			for (int i=0; i< trackDetails.length; i++) {
67
				TrackEvent trackEvents[]= trackDetails[i].getEvents();
68
				for(TrackEvent te : trackEvents){
69
					ShipmentUpdate shipUpdate = new ShipmentUpdate();
8353 manish.sha 70
					if(te.getAddress()!=null){
71
						if(te.getAddress().getCity()!=null){
72
							shipUpdate.city= te.getAddress().getCity();
73
						}
74
						else{
75
							shipUpdate.city="Unknown";
76
						}
77
					}
78
					else{
79
						shipUpdate.city="Unknown";
80
					}
7930 manish.sha 81
					shipUpdate.date= dateformat.format(te.getTimestamp().getTime());
82
					shipUpdate.time= timeformat.format(te.getTimestamp().getTime());
83
					shipUpdate.description= te.getEventDescription();
84
					updates.add(shipUpdate);
85
				}			
86
			}
87
			return updates;
88
		}
89
		else{
90
			return null;
91
		}
92
	}
93
 
94
	public static void main(String[] args) {
95
		FedExTrackingService trackClient = new FedExTrackingService();
8353 manish.sha 96
		List<ShipmentUpdate> updates = trackClient.getUpdates("796869799244");
7930 manish.sha 97
		for(ShipmentUpdate update: updates){
98
			System.out.println(update.toString());
99
		}
100
	}
101
 
102
}