| Line 1... |
Line 1... |
| 1 |
package in.shop2020.serving.services;
|
1 |
package in.shop2020.serving.services;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.config.ConfigException;
|
3 |
import in.shop2020.config.ConfigException;
|
| - |
|
4 |
import in.shop2020.model.v1.order.Order;
|
| 4 |
import in.shop2020.serving.model.ShipmentUpdate;
|
5 |
import in.shop2020.serving.model.ShipmentUpdate;
|
| 5 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
6 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 6 |
|
7 |
|
| 7 |
import java.text.SimpleDateFormat;
|
8 |
import java.text.SimpleDateFormat;
|
| 8 |
import java.util.ArrayList;
|
9 |
import java.util.ArrayList;
|
| - |
|
10 |
import java.util.HashMap;
|
| 9 |
import java.util.List;
|
11 |
import java.util.List;
|
| - |
|
12 |
import java.util.Map;
|
| 10 |
|
13 |
|
| 11 |
import org.apache.commons.logging.Log;
|
14 |
import org.apache.commons.logging.Log;
|
| 12 |
import org.apache.commons.logging.LogFactory;
|
15 |
import org.apache.commons.logging.LogFactory;
|
| 13 |
|
16 |
|
| 14 |
import com.TrackWebServiceClient;
|
17 |
import com.TrackWebServiceClient;
|
| Line 21... |
Line 24... |
| 21 |
|
24 |
|
| 22 |
public class FedExTrackingService {
|
25 |
public class FedExTrackingService {
|
| 23 |
|
26 |
|
| 24 |
private static final Log log = LogFactory.getLog(FedExTrackingService.class);
|
27 |
private static final Log log = LogFactory.getLog(FedExTrackingService.class);
|
| 25 |
private TrackReply trackreply;
|
28 |
private TrackReply trackreply;
|
| - |
|
29 |
private ClientDetail clientDetails;
|
| - |
|
30 |
private WebAuthenticationDetail waDetails;
|
| - |
|
31 |
private String endPointAddress;
|
| 26 |
/**
|
32 |
/**
|
| 27 |
* @param args
|
33 |
* @param args
|
| 28 |
*/
|
34 |
*/
|
| 29 |
|
35 |
|
| - |
|
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();
|
| - |
|
94 |
TrackEvent te= trackEvents[0];
|
| - |
|
95 |
if("PU".equalsIgnoreCase(te.getEventType())){
|
| - |
|
96 |
fedexPickupOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| - |
|
97 |
}
|
| - |
|
98 |
}
|
| - |
|
99 |
}
|
| - |
|
100 |
}
|
| - |
|
101 |
return fedexPickupOrdersMap;
|
| - |
|
102 |
}
|
| - |
|
103 |
|
| - |
|
104 |
public Map<String,String> readFedExReachedDestinationOrdersMap(List<Order> ordersList){
|
| - |
|
105 |
Map<String,String> fedexReachedDestinationOrdersMap= new HashMap<String,String>();
|
| - |
|
106 |
for(Order ord: ordersList){
|
| - |
|
107 |
String awbNumber= ord.getAirwaybill_no();
|
| - |
|
108 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| - |
|
109 |
if(trackreply!=null){
|
| - |
|
110 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| - |
|
111 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
| - |
|
112 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| - |
|
113 |
for (int i=0; i< trackDetails.length; i++) {
|
| - |
|
114 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| - |
|
115 |
TrackEvent te= trackEvents[0];
|
| - |
|
116 |
if("AR".equalsIgnoreCase(te.getEventType())){
|
| - |
|
117 |
fedexReachedDestinationOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| - |
|
118 |
}
|
| - |
|
119 |
}
|
| - |
|
120 |
}
|
| - |
|
121 |
}
|
| - |
|
122 |
return fedexReachedDestinationOrdersMap;
|
| - |
|
123 |
}
|
| - |
|
124 |
|
| - |
|
125 |
public Map<String,String> readFedExDeliveredOrdersMap(List<Order> ordersList){
|
| - |
|
126 |
Map<String,String> fedexDeliveredOrdersMap= new HashMap<String,String>();
|
| - |
|
127 |
for(Order ord: ordersList){
|
| - |
|
128 |
String awbNumber= ord.getAirwaybill_no();
|
| - |
|
129 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| - |
|
130 |
if(trackreply!=null){
|
| - |
|
131 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| - |
|
132 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
| - |
|
133 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| - |
|
134 |
for (int i=0; i< trackDetails.length; i++) {
|
| - |
|
135 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| - |
|
136 |
TrackEvent te= trackEvents[0];
|
| - |
|
137 |
if("DL".equalsIgnoreCase(te.getEventType())){
|
| - |
|
138 |
fedexDeliveredOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| - |
|
139 |
}
|
| - |
|
140 |
}
|
| - |
|
141 |
}
|
| - |
|
142 |
}
|
| - |
|
143 |
return fedexDeliveredOrdersMap;
|
| - |
|
144 |
}
|
| - |
|
145 |
|
| - |
|
146 |
public Map<String,String> readFedExReturnedOrdersMap(List<Order> ordersList){
|
| - |
|
147 |
Map<String,String> fedexReturnedOrdersMap= new HashMap<String,String>();
|
| - |
|
148 |
for(Order ord: ordersList){
|
| - |
|
149 |
String awbNumber= ord.getAirwaybill_no();
|
| - |
|
150 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| - |
|
151 |
if(trackreply!=null){
|
| - |
|
152 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| - |
|
153 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
| - |
|
154 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| - |
|
155 |
for (int i=0; i< trackDetails.length; i++) {
|
| - |
|
156 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| - |
|
157 |
TrackEvent te= trackEvents[0];
|
| - |
|
158 |
if("RS".equalsIgnoreCase(te.getEventType())){
|
| - |
|
159 |
fedexReturnedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| - |
|
160 |
}
|
| - |
|
161 |
}
|
| - |
|
162 |
}
|
| - |
|
163 |
}
|
| - |
|
164 |
return fedexReturnedOrdersMap;
|
| - |
|
165 |
}
|
| - |
|
166 |
|
| - |
|
167 |
public Map<String,String> readFedExUnDeliveredOrdersMap(List<Order> ordersList){
|
| - |
|
168 |
Map<String,String> fedexUnDeliveredOrdersMap= new HashMap<String,String>();
|
| - |
|
169 |
for(Order ord: ordersList){
|
| - |
|
170 |
String awbNumber= ord.getAirwaybill_no();
|
| - |
|
171 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| - |
|
172 |
if(trackreply!=null){
|
| - |
|
173 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| - |
|
174 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
| - |
|
175 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| - |
|
176 |
for (int i=0; i< trackDetails.length; i++) {
|
| - |
|
177 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| - |
|
178 |
TrackEvent te= trackEvents[0];
|
| - |
|
179 |
if("DE".equalsIgnoreCase(te.getEventType())){
|
| - |
|
180 |
fedexUnDeliveredOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| - |
|
181 |
}
|
| - |
|
182 |
}
|
| - |
|
183 |
}
|
| - |
|
184 |
}
|
| - |
|
185 |
return fedexUnDeliveredOrdersMap;
|
| - |
|
186 |
}
|
| - |
|
187 |
|
| - |
|
188 |
public Map<String,String> readFedExFirstDeliveryAttemptedOrdersMap(List<Order> ordersList){
|
| - |
|
189 |
Map<String,String> fedexFirstDeliveryAttemptedOrdersMap= new HashMap<String,String>();
|
| - |
|
190 |
for(Order ord: ordersList){
|
| - |
|
191 |
String awbNumber= ord.getAirwaybill_no();
|
| - |
|
192 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| - |
|
193 |
if(trackreply!=null){
|
| - |
|
194 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| - |
|
195 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
| - |
|
196 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| - |
|
197 |
for (int i=0; i< trackDetails.length; i++) {
|
| - |
|
198 |
TrackEvent trackEvents[]= trackDetails[i].getEvents();
|
| - |
|
199 |
TrackEvent te= trackEvents[trackEvents.length-1];
|
| - |
|
200 |
if("OD".equalsIgnoreCase(te.getEventType())){
|
| - |
|
201 |
fedexFirstDeliveryAttemptedOrdersMap.put(awbNumber, dateformat.format(te.getTimestamp().getTime())+" "+timeformat.format(te.getTimestamp().getTime()));
|
| - |
|
202 |
}
|
| - |
|
203 |
}
|
| - |
|
204 |
}
|
| - |
|
205 |
}
|
| - |
|
206 |
return fedexFirstDeliveryAttemptedOrdersMap;
|
| - |
|
207 |
}
|
| - |
|
208 |
|
| 30 |
public List<ShipmentUpdate> getUpdates(String awbNumber){
|
209 |
public List<ShipmentUpdate> getUpdates(String awbNumber){
|
| 31 |
List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
|
210 |
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) {
|
- |
|
| 58 |
log.error("Could not fetch End Point Address", e);
|
- |
|
| 59 |
}
|
- |
|
| 60 |
|
- |
|
| 61 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetail, new WebAuthenticationDetail(wac), endPoint);
|
211 |
trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetails, waDetails, endPointAddress);
|
| 62 |
if(trackreply!=null){
|
212 |
if(trackreply!=null){
|
| 63 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
213 |
TrackDetail[] trackDetails=trackreply.getTrackDetails();
|
| 64 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
214 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
|
| 65 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
215 |
SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
|
| 66 |
for (int i=0; i< trackDetails.length; i++) {
|
216 |
for (int i=0; i< trackDetails.length; i++) {
|
| Line 91... |
Line 241... |
| 91 |
}
|
241 |
}
|
| 92 |
}
|
242 |
}
|
| 93 |
|
243 |
|
| 94 |
public static void main(String[] args) {
|
244 |
public static void main(String[] args) {
|
| 95 |
FedExTrackingService trackClient = new FedExTrackingService();
|
245 |
FedExTrackingService trackClient = new FedExTrackingService();
|
| 96 |
List<ShipmentUpdate> updates = trackClient.getUpdates("796869799244");
|
246 |
List<ShipmentUpdate> updates = trackClient.getUpdates("796869788166");
|
| 97 |
for(ShipmentUpdate update: updates){
|
247 |
for(ShipmentUpdate update: updates){
|
| 98 |
System.out.println(update.toString());
|
248 |
System.out.println(update.toString());
|
| 99 |
}
|
249 |
}
|
| 100 |
}
|
250 |
}
|
| 101 |
|
251 |
|