| 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);
|
| 8387 |
manish.sha |
52 |
}
|
|
|
53 |
log.info("fedex_account_number in Tracking Service"+accountNumber);
|
|
|
54 |
log.info("fedex_meter_number in Tracking Service"+meterNumber);
|
| 8368 |
manish.sha |
55 |
clientDetail.setAccountNumber(accountNumber);
|
|
|
56 |
clientDetail.setMeterNumber(meterNumber);
|
|
|
57 |
return clientDetail;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public WebAuthenticationDetail getFedExWebAuthenticationDetails(){
|
|
|
61 |
WebAuthenticationCredential wac = new WebAuthenticationCredential();
|
|
|
62 |
String key="";
|
|
|
63 |
String password="";
|
|
|
64 |
try {
|
|
|
65 |
key = ConfigClient.getClient().get("fedex_authenication_key");
|
|
|
66 |
password = ConfigClient.getClient().get("fedex_authenication_password");
|
|
|
67 |
} catch (ConfigException e) {
|
|
|
68 |
log.error("Could not fetch Web Authenication Detail", e);
|
|
|
69 |
}
|
| 8387 |
manish.sha |
70 |
log.info("fedex_authenication_key in Tracking Service"+key);
|
|
|
71 |
log.info("fedex_authenication_password in Tracking Service"+password);
|
| 8368 |
manish.sha |
72 |
wac.setKey(key);
|
|
|
73 |
wac.setPassword(password);
|
|
|
74 |
return new WebAuthenticationDetail(wac);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public String getFedExEndpointAddress(){
|
|
|
78 |
String endPoint="";
|
|
|
79 |
try {
|
|
|
80 |
endPoint = ConfigClient.getClient().get("fedex_endpoint_address_track");
|
|
|
81 |
} catch (ConfigException e) {
|
|
|
82 |
log.error("Could not fetch enpoint Address", e);
|
|
|
83 |
}
|
| 8387 |
manish.sha |
84 |
log.info("fedex_endpoint_address_track in Tracking Service"+endPoint);
|
| 8368 |
manish.sha |
85 |
return endPoint;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public Map<String,String> readFedExPickupOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
89 |
log.info("Into Method to Read Fedex Pickup Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
90 |
Map<String,String> fedexPickupOrdersMap= new HashMap<String,String>();
|
|
|
91 |
for(Order ord: ordersList){
|
|
|
92 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
93 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 8390 |
manish.sha |
94 |
log.info("Track Reply..."+trackreply);
|
| 8368 |
manish.sha |
95 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
96 |
log.info("Successfully get Fedex Pickup Orders Reply");
|
| 8368 |
manish.sha |
97 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
98 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
99 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
100 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
101 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
102 |
for(TrackEvent te : trackEvents){
|
|
|
103 |
if("PU".equalsIgnoreCase(te.getEventType())){
|
|
|
104 |
fedexPickupOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
|
|
105 |
}
|
|
|
106 |
}
|
| 8368 |
manish.sha |
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
| 8385 |
manish.sha |
110 |
log.info("Read Fedex Pickup Orders");
|
| 8368 |
manish.sha |
111 |
return fedexPickupOrdersMap;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public Map<String,String> readFedExReachedDestinationOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
115 |
log.info("Into Method to Read Fedex Reached Destination Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
116 |
Map<String,String> fedexReachedDestinationOrdersMap= new HashMap<String,String>();
|
|
|
117 |
for(Order ord: ordersList){
|
|
|
118 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
119 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
120 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
121 |
log.info("Successfully get Fedex Reached Destination Orders");
|
| 8368 |
manish.sha |
122 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
123 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
124 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
125 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
126 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
127 |
for(TrackEvent te : trackEvents){
|
|
|
128 |
if("AR".equalsIgnoreCase(te.getEventType())){
|
| 8368 |
manish.sha |
129 |
fedexReachedDestinationOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| 8377 |
manish.sha |
130 |
}
|
|
|
131 |
}
|
| 8368 |
manish.sha |
132 |
}
|
|
|
133 |
}
|
|
|
134 |
}
|
| 8385 |
manish.sha |
135 |
log.info("Read Fedex Reached Destination Orders");
|
| 8368 |
manish.sha |
136 |
return fedexReachedDestinationOrdersMap;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public Map<String,String> readFedExDeliveredOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
140 |
log.info("Into Method to Read Fedex Delivered Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
141 |
Map<String,String> fedexDeliveredOrdersMap= new HashMap<String,String>();
|
|
|
142 |
for(Order ord: ordersList){
|
|
|
143 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
144 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
145 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
146 |
log.info("Successfully get Fedex Delivered Orders");
|
| 8368 |
manish.sha |
147 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 8380 |
manish.sha |
148 |
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
|
| 8368 |
manish.sha |
149 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
150 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
151 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
152 |
for(TrackEvent te : trackEvents){
|
|
|
153 |
if("DL".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
154 |
fedexDeliveredOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+trackDetails[i].getDeliverySignatureName());
|
| 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();
|
|
|
169 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
170 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
171 |
log.info("Successfully get Fedex Returned Orders");
|
| 8368 |
manish.sha |
172 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
173 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
174 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
175 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
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());
|
| 8377 |
manish.sha |
180 |
}
|
|
|
181 |
}
|
| 8368 |
manish.sha |
182 |
}
|
|
|
183 |
}
|
|
|
184 |
}
|
| 8385 |
manish.sha |
185 |
log.info("Read Fedex Returned Orders");
|
| 8368 |
manish.sha |
186 |
return fedexReturnedOrdersMap;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
public Map<String,String> readFedExUnDeliveredOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
190 |
log.info("Into Method to Read Fedex Undelivered Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
191 |
Map<String,String> fedexUnDeliveredOrdersMap= new HashMap<String,String>();
|
|
|
192 |
for(Order ord: ordersList){
|
|
|
193 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
194 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
195 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
196 |
log.info("Successfully Get Fedex Undelivered Orders");
|
| 8368 |
manish.sha |
197 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
198 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
199 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
200 |
for(TrackEvent te : trackEvents){
|
|
|
201 |
if("DE".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
202 |
fedexUnDeliveredOrdersMap.put(awbNumber, te.getEventDescription());
|
| 8377 |
manish.sha |
203 |
}
|
|
|
204 |
}
|
| 8368 |
manish.sha |
205 |
}
|
|
|
206 |
}
|
|
|
207 |
}
|
| 8385 |
manish.sha |
208 |
log.info("Read Fedex Undelivered Orders");
|
| 8368 |
manish.sha |
209 |
return fedexUnDeliveredOrdersMap;
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
public Map<String,String> readFedExFirstDeliveryAttemptedOrdersMap(List<Order> ordersList){
|
| 8388 |
manish.sha |
213 |
log.info("Into Method to Read Fedex First Delivery Attempted Orders.... "+ ordersList.size());
|
| 8368 |
manish.sha |
214 |
Map<String,String> fedexFirstDeliveryAttemptedOrdersMap= new HashMap<String,String>();
|
|
|
215 |
for(Order ord: ordersList){
|
|
|
216 |
String awbNumber= ord.getAirwaybill_no();
|
|
|
217 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
|
|
218 |
if(trackreply!=null){
|
| 8385 |
manish.sha |
219 |
log.info("Successfully get Fedex First Delivery Attempted Orders");
|
| 8368 |
manish.sha |
220 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
221 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
222 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
223 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
224 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| 8377 |
manish.sha |
225 |
for(TrackEvent te : trackEvents){
|
|
|
226 |
if("OD".equalsIgnoreCase(te.getEventType())){
|
| 8380 |
manish.sha |
227 |
if(te.getStatusExceptionCode()!=null){
|
|
|
228 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+te.getStatusExceptionDescription());
|
|
|
229 |
}
|
|
|
230 |
else{
|
|
|
231 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime())+"|"+te.getEventDescription());
|
|
|
232 |
}
|
| 8377 |
manish.sha |
233 |
}
|
|
|
234 |
}
|
| 8368 |
manish.sha |
235 |
}
|
|
|
236 |
}
|
|
|
237 |
}
|
| 8385 |
manish.sha |
238 |
log.info("Read Fedex First Delivery Attempted Orders");
|
| 8368 |
manish.sha |
239 |
return fedexFirstDeliveryAttemptedOrdersMap;
|
|
|
240 |
}
|
|
|
241 |
|
| 7930 |
manish.sha |
242 |
public List<ShipmentUpdate> getUpdates(String awbNumber){
|
|
|
243 |
List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
|
| 8368 |
manish.sha |
244 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 7930 |
manish.sha |
245 |
if(trackreply!=null){
|
|
|
246 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
|
|
247 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
248 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
|
|
249 |
for (int i=0; i< trackDetails.length; i++) {
|
|
|
250 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
|
|
251 |
for(TrackEvent te : trackEvents){
|
|
|
252 |
ShipmentUpdate shipUpdate = new ShipmentUpdate();
|
| 8353 |
manish.sha |
253 |
if(te.getAddress()!=null){
|
|
|
254 |
if(te.getAddress().getCity()!=null){
|
|
|
255 |
shipUpdate.city= te.getAddress().getCity();
|
|
|
256 |
}
|
|
|
257 |
else{
|
|
|
258 |
shipUpdate.city="Unknown";
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
else{
|
|
|
262 |
shipUpdate.city="Unknown";
|
|
|
263 |
}
|
| 7930 |
manish.sha |
264 |
shipUpdate.date= dateformat.format(te.getTimestamp().getTime());
|
|
|
265 |
shipUpdate.time= timeformat.format(te.getTimestamp().getTime());
|
|
|
266 |
shipUpdate.description= te.getEventDescription();
|
|
|
267 |
updates.add(shipUpdate);
|
|
|
268 |
}
|
|
|
269 |
}
|
|
|
270 |
return updates;
|
|
|
271 |
}
|
|
|
272 |
else{
|
|
|
273 |
return null;
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public static void main(String[] args) {
|
|
|
278 |
FedExTrackingService trackClient = new FedExTrackingService();
|
| 8368 |
manish.sha |
279 |
List<ShipmentUpdate> updates = trackClient.getUpdates("796869788166");
|
| 7930 |
manish.sha |
280 |
for(ShipmentUpdate update: updates){
|
|
|
281 |
System.out.println(update.toString());
|
|
|
282 |
}
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
}
|