| 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);
|
| 8368 |
manish.sha |
28 |
private ClientDetail clientDetails;
|
|
|
29 |
private WebAuthenticationDetail waDetails;
|
|
|
30 |
private String endPointAddress;
|
| 7930 |
manish.sha |
31 |
/**
|
|
|
32 |
* @param args
|
|
|
33 |
*/
|
|
|
34 |
|
| 8368 |
manish.sha |
35 |
public FedExTrackingService(){
|
|
|
36 |
clientDetails = getFedExClientDetails();
|
|
|
37 |
waDetails = getFedExWebAuthenticationDetails();
|
|
|
38 |
endPointAddress = getFedExEndpointAddress();
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public ClientDetail getFedExClientDetails(){
|
|
|
42 |
ClientDetail clientDetail = new ClientDetail();
|
|
|
43 |
String accountNumber ="";
|
|
|
44 |
String meterNumber ="";
|
|
|
45 |
try {
|
|
|
46 |
accountNumber = ConfigClient.getClient().get("fedex_account_number");
|
|
|
47 |
meterNumber = ConfigClient.getClient().get("fedex_meter_number");
|
|
|
48 |
} catch (ConfigException e) {
|
|
|
49 |
log.error("Could not fetch Client Detail", e);
|
| 8387 |
manish.sha |
50 |
}
|
|
|
51 |
log.info("fedex_account_number in Tracking Service"+accountNumber);
|
|
|
52 |
log.info("fedex_meter_number in Tracking Service"+meterNumber);
|
| 8368 |
manish.sha |
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 |
}
|
| 8387 |
manish.sha |
68 |
log.info("fedex_authenication_key in Tracking Service"+key);
|
|
|
69 |
log.info("fedex_authenication_password in Tracking Service"+password);
|
| 8368 |
manish.sha |
70 |
wac.setKey(key);
|
|
|
71 |
wac.setPassword(password);
|
|
|
72 |
return new WebAuthenticationDetail(wac);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public String getFedExEndpointAddress(){
|
|
|
76 |
String endPoint="";
|
|
|
77 |
try {
|
|
|
78 |
endPoint = ConfigClient.getClient().get("fedex_endpoint_address_track");
|
|
|
79 |
} catch (ConfigException e) {
|
|
|
80 |
log.error("Could not fetch enpoint Address", e);
|
|
|
81 |
}
|
| 8387 |
manish.sha |
82 |
log.info("fedex_endpoint_address_track in Tracking Service"+endPoint);
|
| 8368 |
manish.sha |
83 |
return endPoint;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
public Map<String,String> readFedExPickupOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
87 |
log.info("Into Method to Read Fedex Pickup Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
88 |
Map<String,String> fedexPickupOrdersMap= new HashMap<String,String>();
|
|
|
89 |
for(Order ord: ordersList){
|
|
|
90 |
String awbNumber= ord.getAirwaybill_no();
|
| 8391 |
manish.sha |
91 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8368 |
manish.sha |
92 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
93 |
log.info("Successfully get Fedex Pickup Orders Reply");
|
| 8368 |
manish.sha |
94 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8402 |
manish.sha |
95 |
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
|
| 8368 |
manish.sha |
96 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| 8568 |
manish.sha |
97 |
trackDetailsLoop:for (int i=0; i< trackDetails.length; i++) {
|
| 8368 |
manish.sha |
98 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
99 |
for(TrackEvent te : trackEvents){
|
|
|
100 |
if("PU".equalsIgnoreCase(te.getEventType())){
|
|
|
101 |
fedexPickupOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| 8568 |
manish.sha |
102 |
break trackDetailsLoop;
|
| 8377 |
manish.sha |
103 |
}
|
|
|
104 |
}
|
| 8368 |
manish.sha |
105 |
}
|
|
|
106 |
}
|
|
|
107 |
}
|
| 8385 |
manish.sha |
108 |
log.info("Read Fedex Pickup Orders");
|
| 8368 |
manish.sha |
109 |
return fedexPickupOrdersMap;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public Map<String,String> readFedExReachedDestinationOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
113 |
log.info("Into Method to Read Fedex Reached Destination Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
114 |
Map<String,String> fedexReachedDestinationOrdersMap= new HashMap<String,String>();
|
|
|
115 |
for(Order ord: ordersList){
|
|
|
116 |
String awbNumber= ord.getAirwaybill_no();
|
| 8391 |
manish.sha |
117 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8368 |
manish.sha |
118 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
119 |
log.info("Successfully get Fedex Reached Destination Orders");
|
| 8368 |
manish.sha |
120 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8402 |
manish.sha |
121 |
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
|
| 8368 |
manish.sha |
122 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| 8568 |
manish.sha |
123 |
trackDetailsLoop:for (int i=0; i< trackDetails.length; i++) {
|
| 8368 |
manish.sha |
124 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
125 |
for(TrackEvent te : trackEvents){
|
|
|
126 |
if("AR".equalsIgnoreCase(te.getEventType())){
|
| 8568 |
manish.sha |
127 |
fedexReachedDestinationOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
128 |
break trackDetailsLoop;
|
| 8377 |
manish.sha |
129 |
}
|
|
|
130 |
}
|
| 8368 |
manish.sha |
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|
| 8385 |
manish.sha |
134 |
log.info("Read Fedex Reached Destination Orders");
|
| 8368 |
manish.sha |
135 |
return fedexReachedDestinationOrdersMap;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public Map<String,String> readFedExDeliveredOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
139 |
log.info("Into Method to Read Fedex Delivered Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
140 |
Map<String,String> fedexDeliveredOrdersMap= new HashMap<String,String>();
|
|
|
141 |
for(Order ord: ordersList){
|
|
|
142 |
String awbNumber= ord.getAirwaybill_no();
|
| 8391 |
manish.sha |
143 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8368 |
manish.sha |
144 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
145 |
log.info("Successfully get Fedex Delivered Orders");
|
| 8368 |
manish.sha |
146 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8380 |
manish.sha |
147 |
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
|
| 8368 |
manish.sha |
148 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| 8568 |
manish.sha |
149 |
trackDetailsLoop:for (int i=0; i< trackDetails.length; i++) {
|
| 8368 |
manish.sha |
150 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
151 |
for(TrackEvent te : trackEvents){
|
|
|
152 |
if("DL".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
153 |
fedexDeliveredOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+trackDetails[i].getDeliverySignatureName());
|
| 8568 |
manish.sha |
154 |
break trackDetailsLoop;
|
| 8377 |
manish.sha |
155 |
}
|
|
|
156 |
}
|
| 8368 |
manish.sha |
157 |
}
|
|
|
158 |
}
|
|
|
159 |
}
|
| 8385 |
manish.sha |
160 |
log.info("Read Fedex Delivered Orders");
|
| 8368 |
manish.sha |
161 |
return fedexDeliveredOrdersMap;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
public Map<String,String> readFedExReturnedOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
165 |
log.info("Into Method to Read Fedex Returned Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
166 |
Map<String,String> fedexReturnedOrdersMap= new HashMap<String,String>();
|
|
|
167 |
for(Order ord: ordersList){
|
|
|
168 |
String awbNumber= ord.getAirwaybill_no();
|
| 8391 |
manish.sha |
169 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8368 |
manish.sha |
170 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
171 |
log.info("Successfully get Fedex Returned Orders");
|
| 8368 |
manish.sha |
172 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8402 |
manish.sha |
173 |
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
|
| 8368 |
manish.sha |
174 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| 8568 |
manish.sha |
175 |
trackDetailsLoop:for (int i=0; i< trackDetails.length; i++) {
|
| 8368 |
manish.sha |
176 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
177 |
for(TrackEvent te : trackEvents){
|
|
|
178 |
if("RS".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
179 |
fedexReturnedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+te.getEventDescription());
|
| 8568 |
manish.sha |
180 |
break trackDetailsLoop;
|
| 8377 |
manish.sha |
181 |
}
|
|
|
182 |
}
|
| 8368 |
manish.sha |
183 |
}
|
|
|
184 |
}
|
|
|
185 |
}
|
| 8385 |
manish.sha |
186 |
log.info("Read Fedex Returned Orders");
|
| 8368 |
manish.sha |
187 |
return fedexReturnedOrdersMap;
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
public Map<String,String> readFedExUnDeliveredOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
191 |
log.info("Into Method to Read Fedex Undelivered Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
192 |
Map<String,String> fedexUnDeliveredOrdersMap= new HashMap<String,String>();
|
| 8504 |
manish.sha |
193 |
orderLoop:for(Order ord: ordersList){
|
| 8368 |
manish.sha |
194 |
String awbNumber= ord.getAirwaybill_no();
|
| 8391 |
manish.sha |
195 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8368 |
manish.sha |
196 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
197 |
log.info("Successfully Get Fedex Undelivered Orders");
|
| 8368 |
manish.sha |
198 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8568 |
manish.sha |
199 |
trackDetailsLoop:for (int i=0; i< trackDetails.length; i++) {
|
| 8368 |
manish.sha |
200 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8504 |
manish.sha |
201 |
for(TrackEvent tevent : trackEvents){
|
|
|
202 |
if("DL".equalsIgnoreCase(tevent.getEventType())){
|
|
|
203 |
continue orderLoop;
|
|
|
204 |
}
|
|
|
205 |
}
|
| 8377 |
manish.sha |
206 |
for(TrackEvent te : trackEvents){
|
|
|
207 |
if("DE".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
208 |
fedexUnDeliveredOrdersMap.put(awbNumber, te.getEventDescription());
|
| 8568 |
manish.sha |
209 |
break trackDetailsLoop;
|
| 8377 |
manish.sha |
210 |
}
|
|
|
211 |
}
|
| 8368 |
manish.sha |
212 |
}
|
|
|
213 |
}
|
|
|
214 |
}
|
| 8385 |
manish.sha |
215 |
log.info("Read Fedex Undelivered Orders");
|
| 8368 |
manish.sha |
216 |
return fedexUnDeliveredOrdersMap;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public Map<String,String> readFedExFirstDeliveryAttemptedOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
220 |
log.info("Into Method to Read Fedex First Delivery Attempted Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
221 |
Map<String,String> fedexFirstDeliveryAttemptedOrdersMap= new HashMap<String,String>();
|
|
|
222 |
for(Order ord: ordersList){
|
|
|
223 |
String awbNumber= ord.getAirwaybill_no();
|
| 8391 |
manish.sha |
224 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8368 |
manish.sha |
225 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
226 |
log.info("Successfully get Fedex First Delivery Attempted Orders");
|
| 8368 |
manish.sha |
227 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8402 |
manish.sha |
228 |
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
|
| 8368 |
manish.sha |
229 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| 8568 |
manish.sha |
230 |
trackDeatilsLoop:for (int i=0; i< trackDetails.length; i++) {
|
| 8368 |
manish.sha |
231 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
232 |
for(TrackEvent te : trackEvents){
|
|
|
233 |
if("OD".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
234 |
if(te.getStatusExceptionCode()!=null){
|
|
|
235 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+te.getStatusExceptionDescription());
|
|
|
236 |
}
|
|
|
237 |
else{
|
|
|
238 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+te.getEventDescription());
|
|
|
239 |
}
|
| 8568 |
manish.sha |
240 |
break trackDeatilsLoop;
|
| 8377 |
manish.sha |
241 |
}
|
| 8568 |
manish.sha |
242 |
else if("DE".equalsIgnoreCase(te.getEventType())){
|
|
|
243 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+te.getEventDescription());
|
|
|
244 |
break trackDeatilsLoop;
|
|
|
245 |
}
|
| 8377 |
manish.sha |
246 |
}
|
| 8368 |
manish.sha |
247 |
}
|
|
|
248 |
}
|
|
|
249 |
}
|
| 8385 |
manish.sha |
250 |
log.info("Read Fedex First Delivery Attempted Orders");
|
| 8368 |
manish.sha |
251 |
return fedexFirstDeliveryAttemptedOrdersMap;
|
|
|
252 |
}
|
|
|
253 |
|
| 7930 |
manish.sha |
254 |
public List<ShipmentUpdate> getUpdates(String awbNumber){
|
|
|
255 |
List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
|
| 8391 |
manish.sha |
256 |
TrackReply trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 7930 |
manish.sha |
257 |
if(trackreply!=null){
|
|
|
258 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
259 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
260 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
261 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
262 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
|
|
263 |
for(TrackEvent te : trackEvents){
|
|
|
264 |
ShipmentUpdate shipUpdate = new ShipmentUpdate();
|
| 8353 |
manish.sha |
265 |
if(te.getAddress()!=null){
|
|
|
266 |
if(te.getAddress().getCity()!=null){
|
|
|
267 |
shipUpdate.city= te.getAddress().getCity();
|
|
|
268 |
}
|
|
|
269 |
else{
|
|
|
270 |
shipUpdate.city="Unknown";
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
else{
|
|
|
274 |
shipUpdate.city="Unknown";
|
|
|
275 |
}
|
| 7930 |
manish.sha |
276 |
shipUpdate.date= dateformat.format(te.getTimestamp().getTime());
|
|
|
277 |
shipUpdate.time= timeformat.format(te.getTimestamp().getTime());
|
|
|
278 |
shipUpdate.description= te.getEventDescription();
|
|
|
279 |
updates.add(shipUpdate);
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
return updates;
|
|
|
283 |
}
|
|
|
284 |
else{
|
|
|
285 |
return null;
|
|
|
286 |
}
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
public static void main(String[] args) {
|
|
|
290 |
FedExTrackingService trackClient = new FedExTrackingService();
|
| 8368 |
manish.sha |
291 |
List<ShipmentUpdate> updates = trackClient.getUpdates("796869788166");
|
| 7930 |
manish.sha |
292 |
for(ShipmentUpdate update: updates){
|
|
|
293 |
System.out.println(update.toString());
|
|
|
294 |
}
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
}
|