| 7930 |
manish.sha |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
| 8368 |
manish.sha |
4 |
import in.shop2020.model.v1.order.Order;
|
| 7930 |
manish.sha |
5 |
import in.shop2020.serving.model.ShipmentUpdate;
|
|
|
6 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
7 |
|
|
|
8 |
import java.text.SimpleDateFormat;
|
|
|
9 |
import java.util.ArrayList;
|
| 8368 |
manish.sha |
10 |
import java.util.HashMap;
|
| 7930 |
manish.sha |
11 |
import java.util.List;
|
| 8368 |
manish.sha |
12 |
import java.util.Map;
|
| 8353 |
manish.sha |
13 |
|
|
|
14 |
import org.apache.commons.logging.Log;
|
|
|
15 |
import org.apache.commons.logging.LogFactory;
|
|
|
16 |
|
| 7930 |
manish.sha |
17 |
import com.TrackWebServiceClient;
|
|
|
18 |
import com.fedex.track.stub.ClientDetail;
|
|
|
19 |
import com.fedex.track.stub.TrackDetail;
|
|
|
20 |
import com.fedex.track.stub.TrackEvent;
|
|
|
21 |
import com.fedex.track.stub.TrackReply;
|
|
|
22 |
import com.fedex.track.stub.WebAuthenticationCredential;
|
|
|
23 |
import com.fedex.track.stub.WebAuthenticationDetail;
|
|
|
24 |
|
|
|
25 |
public class FedExTrackingService {
|
| 8353 |
manish.sha |
26 |
|
|
|
27 |
private static final Log log = LogFactory.getLog(FedExTrackingService.class);
|
| 7930 |
manish.sha |
28 |
private TrackReply trackreply;
|
| 8368 |
manish.sha |
29 |
private ClientDetail clientDetails;
|
|
|
30 |
private WebAuthenticationDetail waDetails;
|
|
|
31 |
private String endPointAddress;
|
| 7930 |
manish.sha |
32 |
/**
|
|
|
33 |
* @param args
|
|
|
34 |
*/
|
|
|
35 |
|
| 8368 |
manish.sha |
36 |
public FedExTrackingService(){
|
|
|
37 |
trackreply= null;
|
|
|
38 |
clientDetails = getFedExClientDetails();
|
|
|
39 |
waDetails = getFedExWebAuthenticationDetails();
|
|
|
40 |
endPointAddress = getFedExEndpointAddress();
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public ClientDetail getFedExClientDetails(){
|
|
|
44 |
ClientDetail clientDetail = new ClientDetail();
|
|
|
45 |
String accountNumber ="";
|
|
|
46 |
String meterNumber ="";
|
|
|
47 |
try {
|
|
|
48 |
accountNumber = ConfigClient.getClient().get("fedex_account_number");
|
|
|
49 |
meterNumber = ConfigClient.getClient().get("fedex_meter_number");
|
|
|
50 |
} catch (ConfigException e) {
|
|
|
51 |
log.error("Could not fetch Client Detail", e);
|
|
|
52 |
}
|
|
|
53 |
clientDetail.setAccountNumber(accountNumber);
|
|
|
54 |
clientDetail.setMeterNumber(meterNumber);
|
|
|
55 |
return clientDetail;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public WebAuthenticationDetail getFedExWebAuthenticationDetails(){
|
|
|
59 |
WebAuthenticationCredential wac = new WebAuthenticationCredential();
|
|
|
60 |
String key="";
|
|
|
61 |
String password="";
|
|
|
62 |
try {
|
|
|
63 |
key = ConfigClient.getClient().get("fedex_authenication_key");
|
|
|
64 |
password = ConfigClient.getClient().get("fedex_authenication_password");
|
|
|
65 |
} catch (ConfigException e) {
|
|
|
66 |
log.error("Could not fetch Web Authenication Detail", e);
|
|
|
67 |
}
|
|
|
68 |
wac.setKey(key);
|
|
|
69 |
wac.setPassword(password);
|
|
|
70 |
return new WebAuthenticationDetail(wac);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public String getFedExEndpointAddress(){
|
|
|
74 |
String endPoint="";
|
|
|
75 |
try {
|
|
|
76 |
endPoint = ConfigClient.getClient().get("fedex_endpoint_address_track");
|
|
|
77 |
} catch (ConfigException e) {
|
|
|
78 |
log.error("Could not fetch enpoint Address", e);
|
|
|
79 |
}
|
|
|
80 |
return endPoint;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public Map<String,String> readFedExPickupOrdersMap(List<Order> ordersList){
|
|
|
84 |
Map<String,String> fedexPickupOrdersMap= new HashMap<String,String>();
|
|
|
85 |
for(Order ord: ordersList){
|
|
|
86 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
87 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
88 |
if(trackreply!=null){
|
|
|
89 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
90 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
91 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
92 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
93 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
94 |
for(TrackEvent te : trackEvents){
|
|
|
95 |
if("PU".equalsIgnoreCase(te.getEventType())){
|
|
|
96 |
fedexPickupOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
97 |
}
|
|
|
98 |
}
|
| 8368 |
manish.sha |
99 |
}
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
return fedexPickupOrdersMap;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public Map<String,String> readFedExReachedDestinationOrdersMap(List<Order> ordersList){
|
|
|
106 |
Map<String,String> fedexReachedDestinationOrdersMap= new HashMap<String,String>();
|
|
|
107 |
for(Order ord: ordersList){
|
|
|
108 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
109 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
110 |
if(trackreply!=null){
|
|
|
111 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
112 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
113 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
114 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
115 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
116 |
for(TrackEvent te : trackEvents){
|
|
|
117 |
if("AR".equalsIgnoreCase(te.getEventType())){
|
| 8368 |
manish.sha |
118 |
fedexReachedDestinationOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| 8377 |
manish.sha |
119 |
}
|
|
|
120 |
}
|
| 8368 |
manish.sha |
121 |
}
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
return fedexReachedDestinationOrdersMap;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public Map<String,String> readFedExDeliveredOrdersMap(List<Order> ordersList){
|
|
|
128 |
Map<String,String> fedexDeliveredOrdersMap= new HashMap<String,String>();
|
|
|
129 |
for(Order ord: ordersList){
|
|
|
130 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
131 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
132 |
if(trackreply!=null){
|
|
|
133 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
134 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
135 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
136 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
137 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
138 |
for(TrackEvent te : trackEvents){
|
|
|
139 |
if("DL".equalsIgnoreCase(te.getEventType())){
|
|
|
140 |
fedexDeliveredOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
141 |
}
|
|
|
142 |
}
|
| 8368 |
manish.sha |
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
return fedexDeliveredOrdersMap;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public Map<String,String> readFedExReturnedOrdersMap(List<Order> ordersList){
|
|
|
150 |
Map<String,String> fedexReturnedOrdersMap= new HashMap<String,String>();
|
|
|
151 |
for(Order ord: ordersList){
|
|
|
152 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
153 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
154 |
if(trackreply!=null){
|
|
|
155 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
156 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
157 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
158 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
159 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
160 |
for(TrackEvent te : trackEvents){
|
|
|
161 |
if("RS".equalsIgnoreCase(te.getEventType())){
|
|
|
162 |
fedexReturnedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
163 |
}
|
|
|
164 |
}
|
| 8368 |
manish.sha |
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
return fedexReturnedOrdersMap;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
public Map<String,String> readFedExUnDeliveredOrdersMap(List<Order> ordersList){
|
|
|
172 |
Map<String,String> fedexUnDeliveredOrdersMap= new HashMap<String,String>();
|
|
|
173 |
for(Order ord: ordersList){
|
|
|
174 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
175 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
176 |
if(trackreply!=null){
|
|
|
177 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
178 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
179 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
180 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
181 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
182 |
for(TrackEvent te : trackEvents){
|
|
|
183 |
if("DE".equalsIgnoreCase(te.getEventType())){
|
|
|
184 |
fedexUnDeliveredOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
185 |
}
|
|
|
186 |
}
|
| 8368 |
manish.sha |
187 |
}
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
return fedexUnDeliveredOrdersMap;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public Map<String,String> readFedExFirstDeliveryAttemptedOrdersMap(List<Order> ordersList){
|
|
|
194 |
Map<String,String> fedexFirstDeliveryAttemptedOrdersMap= new HashMap<String,String>();
|
|
|
195 |
for(Order ord: ordersList){
|
|
|
196 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
197 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
198 |
if(trackreply!=null){
|
|
|
199 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
200 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
201 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
202 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
203 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
204 |
for(TrackEvent te : trackEvents){
|
|
|
205 |
if("OD".equalsIgnoreCase(te.getEventType())){
|
|
|
206 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
207 |
}
|
|
|
208 |
}
|
| 8368 |
manish.sha |
209 |
}
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
return fedexFirstDeliveryAttemptedOrdersMap;
|
|
|
213 |
}
|
|
|
214 |
|
| 7930 |
manish.sha |
215 |
public List<ShipmentUpdate> getUpdates(String awbNumber){
|
|
|
216 |
List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
|
| 8368 |
manish.sha |
217 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 7930 |
manish.sha |
218 |
if(trackreply!=null){
|
|
|
219 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
220 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
221 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
222 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
223 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
|
|
224 |
for(TrackEvent te : trackEvents){
|
|
|
225 |
ShipmentUpdate shipUpdate = new ShipmentUpdate();
|
| 8353 |
manish.sha |
226 |
if(te.getAddress()!=null){
|
|
|
227 |
if(te.getAddress().getCity()!=null){
|
|
|
228 |
shipUpdate.city= te.getAddress().getCity();
|
|
|
229 |
}
|
|
|
230 |
else{
|
|
|
231 |
shipUpdate.city="Unknown";
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
else{
|
|
|
235 |
shipUpdate.city="Unknown";
|
|
|
236 |
}
|
| 7930 |
manish.sha |
237 |
shipUpdate.date= dateformat.format(te.getTimestamp().getTime());
|
|
|
238 |
shipUpdate.time= timeformat.format(te.getTimestamp().getTime());
|
|
|
239 |
shipUpdate.description= te.getEventDescription();
|
|
|
240 |
updates.add(shipUpdate);
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
return updates;
|
|
|
244 |
}
|
|
|
245 |
else{
|
|
|
246 |
return null;
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
public static void main(String[] args) {
|
|
|
251 |
FedExTrackingService trackClient = new FedExTrackingService();
|
| 8368 |
manish.sha |
252 |
List<ShipmentUpdate> updates = trackClient.getUpdates("796869788166");
|
| 7930 |
manish.sha |
253 |
for(ShipmentUpdate update: updates){
|
|
|
254 |
System.out.println(update.toString());
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
}
|