| 6322 |
amar.kumar |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 7784 |
manish.sha |
3 |
import in.shop2020.logistics.LogisticsLocationInfo;
|
| 6322 |
amar.kumar |
4 |
import in.shop2020.logistics.LogisticsService.Client;
|
| 7735 |
manish.sha |
5 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
6 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
7 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 6322 |
amar.kumar |
8 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
| 7735 |
manish.sha |
11 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
12 |
import javax.servlet.http.HttpSession;
|
|
|
13 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 6322 |
amar.kumar |
14 |
|
|
|
15 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
16 |
import org.apache.thrift.TException;
|
| 6612 |
amar.kumar |
17 |
import org.slf4j.Logger;
|
|
|
18 |
import org.slf4j.LoggerFactory;
|
| 7735 |
manish.sha |
19 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
20 |
import org.apache.commons.io.FileUtils;
|
|
|
21 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
22 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
23 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
24 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
25 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 6322 |
amar.kumar |
26 |
import com.opensymphony.xwork2.ActionSupport;
|
| 7735 |
manish.sha |
27 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
28 |
import java.io.File;
|
|
|
29 |
import java.io.FileInputStream;
|
|
|
30 |
import java.io.FileNotFoundException;
|
|
|
31 |
import java.io.IOException;
|
| 7784 |
manish.sha |
32 |
import java.util.ArrayList;
|
| 7735 |
manish.sha |
33 |
import java.util.Collection;
|
|
|
34 |
import java.util.Iterator;
|
|
|
35 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 7784 |
manish.sha |
36 |
import java.util.List;
|
| 6322 |
amar.kumar |
37 |
|
| 7735 |
manish.sha |
38 |
@SuppressWarnings("serial")
|
| 6322 |
amar.kumar |
39 |
public class PincodeController extends ActionSupport implements ServletRequestAware {
|
|
|
40 |
|
|
|
41 |
private Long provider;
|
|
|
42 |
private String pincode;
|
|
|
43 |
private String destCode;
|
|
|
44 |
private String exp;
|
|
|
45 |
private String cod;
|
| 6524 |
rajveer |
46 |
private String otg;
|
| 6322 |
amar.kumar |
47 |
private String stationType;
|
| 7735 |
manish.sha |
48 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
49 |
private String runCompleteUpdate;
|
| 6322 |
amar.kumar |
50 |
|
| 7735 |
manish.sha |
51 |
private HttpServletRequest request;
|
|
|
52 |
private HttpSession session;
|
|
|
53 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
54 |
|
| 6322 |
amar.kumar |
55 |
private boolean codService = false;
|
|
|
56 |
private boolean expService = false;
|
| 6524 |
rajveer |
57 |
private boolean otgService = false;
|
| 6322 |
amar.kumar |
58 |
private int stationType_int = 1;
|
| 7735 |
manish.sha |
59 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
60 |
private boolean runCompleteUpdateValue = false;
|
| 6322 |
amar.kumar |
61 |
|
| 7735 |
manish.sha |
62 |
private File recordsFile;
|
|
|
63 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 6612 |
amar.kumar |
64 |
private static Logger logger = LoggerFactory.getLogger(PincodeController.class);
|
| 7735 |
manish.sha |
65 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
66 |
private String errorMsg = "";
|
|
|
67 |
private String successmsg = "";
|
|
|
68 |
|
|
|
69 |
public String index() {
|
|
|
70 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
|
|
|
71 |
return "authfail";
|
|
|
72 |
checkForErrors();
|
|
|
73 |
return "authsuccess";
|
|
|
74 |
}
|
|
|
75 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
76 |
|
| 6322 |
amar.kumar |
77 |
@Override
|
| 7735 |
manish.sha |
78 |
public void setServletRequest(HttpServletRequest request) {
|
| 6322 |
amar.kumar |
79 |
// TODO Auto-generated method stub
|
| 7735 |
manish.sha |
80 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
81 |
this.request = request;
|
|
|
82 |
this.session = request.getSession();
|
|
|
83 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
87 |
public String create(){
|
|
|
88 |
if(runCompleteUpdate!=null && runCompleteUpdate.equals("on")) {
|
|
|
89 |
runCompleteUpdateValue = true;
|
| 23122 |
amit.gupta |
90 |
} else {
|
|
|
91 |
provider = -1L;
|
| 7735 |
manish.sha |
92 |
}
|
| 19421 |
manish.sha |
93 |
File fileToCreate = null;
|
| 7735 |
manish.sha |
94 |
try {
|
|
|
95 |
fileToCreate = new File("/tmp/", this.recordsFile.getName());
|
|
|
96 |
FileUtils.copyFile(this.recordsFile, fileToCreate);
|
|
|
97 |
} catch (Exception e) {
|
|
|
98 |
logger.error("Error while writing file used to the local file system", e);
|
|
|
99 |
addActionError("Unable to open the Uploaded File. Please check the file format.");
|
|
|
100 |
return "Error while writing file used to the local file system";
|
|
|
101 |
}
|
|
|
102 |
if(fileToCreate.isFile()){
|
|
|
103 |
HSSFWorkbook wb = null;
|
|
|
104 |
try{
|
|
|
105 |
wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
|
|
|
106 |
}
|
|
|
107 |
catch (FileNotFoundException e) {
|
|
|
108 |
logger.error("Unable to open the Uploaded File", e);
|
|
|
109 |
addActionError("Unable to open the Uploaded File. Please check the file format.");
|
|
|
110 |
} catch (IOException e) {
|
|
|
111 |
logger.error("Unable to open the Uploaded File", e);
|
|
|
112 |
addActionError("Unable to open the Uploaded File. Please check the file format.");
|
|
|
113 |
}
|
|
|
114 |
catch (Exception e){
|
|
|
115 |
logger.error("Supplied Data is not in specified form. Please check the file format",e);
|
|
|
116 |
addActionError("Supplied Data is not in specified form. Please check the file format");
|
|
|
117 |
}
|
|
|
118 |
if(checkForErrors())
|
|
|
119 |
return "Error in updation";
|
| 7784 |
manish.sha |
120 |
|
| 7735 |
manish.sha |
121 |
HSSFSheet sheet= wb.getSheetAt(0);
|
|
|
122 |
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
|
123 |
int rowCount = 0;
|
| 7784 |
manish.sha |
124 |
List<LogisticsLocationInfo> logisticsLocationInfoList;
|
|
|
125 |
logisticsLocationInfoList = new ArrayList<LogisticsLocationInfo>();
|
| 7735 |
manish.sha |
126 |
while(rowIterator.hasNext()) {
|
|
|
127 |
Row row = rowIterator.next();
|
|
|
128 |
if(rowCount++==0)
|
|
|
129 |
continue;
|
|
|
130 |
Iterator<Cell> cellIterator = row.cellIterator();
|
|
|
131 |
int cellCount= 0;
|
| 7784 |
manish.sha |
132 |
LogisticsLocationInfo logisticsLocationInfo = new LogisticsLocationInfo();
|
| 7735 |
manish.sha |
133 |
while(cellIterator.hasNext()) {
|
|
|
134 |
|
|
|
135 |
Cell cell = cellIterator.next();
|
|
|
136 |
String cellVal_Str ="";
|
|
|
137 |
Long cellVal_Num = 0L;
|
|
|
138 |
boolean cellVal_bool = false;
|
|
|
139 |
|
|
|
140 |
switch(cell.getCellType()) {
|
|
|
141 |
case Cell.CELL_TYPE_BOOLEAN:
|
|
|
142 |
cellVal_bool = cell.getBooleanCellValue();
|
|
|
143 |
break;
|
|
|
144 |
case Cell.CELL_TYPE_NUMERIC:
|
|
|
145 |
cellVal_Num= (long) cell.getNumericCellValue();
|
|
|
146 |
break;
|
|
|
147 |
case Cell.CELL_TYPE_STRING:
|
|
|
148 |
cellVal_Str = cell.getStringCellValue();
|
|
|
149 |
break;
|
|
|
150 |
}
|
|
|
151 |
switch(cellCount) {
|
|
|
152 |
case 0:
|
| 23122 |
amit.gupta |
153 |
long provider_id = (long) cellVal_Num;
|
|
|
154 |
if (provider_id != provider) break;
|
| 7784 |
manish.sha |
155 |
logisticsLocationInfo.setProviderId((long) cellVal_Num);
|
| 7735 |
manish.sha |
156 |
break;
|
|
|
157 |
case 1:
|
|
|
158 |
pincode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
|
| 7784 |
manish.sha |
159 |
logisticsLocationInfo.setPinCode(pincode);
|
| 7735 |
manish.sha |
160 |
break;
|
|
|
161 |
case 2:
|
|
|
162 |
destCode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
|
| 7784 |
manish.sha |
163 |
logisticsLocationInfo.setDestinationCode(destCode);
|
| 7735 |
manish.sha |
164 |
break;
|
|
|
165 |
case 3:
|
|
|
166 |
if(cellVal_Num==0L)
|
|
|
167 |
expService = false;
|
|
|
168 |
else if(cellVal_Num==1L)
|
|
|
169 |
expService = true;
|
|
|
170 |
else
|
|
|
171 |
expService = false;
|
| 7784 |
manish.sha |
172 |
logisticsLocationInfo.setExpAvailable(expService);
|
| 7735 |
manish.sha |
173 |
break;
|
|
|
174 |
case 4:
|
|
|
175 |
if(cellVal_Num==0L)
|
|
|
176 |
codService = false;
|
|
|
177 |
else if(cellVal_Num==1L)
|
|
|
178 |
codService = true;
|
|
|
179 |
else
|
|
|
180 |
codService = false;
|
| 7784 |
manish.sha |
181 |
logisticsLocationInfo.setCodAvailable(codService);
|
| 7735 |
manish.sha |
182 |
break;
|
|
|
183 |
case 5:
|
|
|
184 |
if(cellVal_Num==0L)
|
|
|
185 |
otgService = false;
|
|
|
186 |
else if(cellVal_Num==1L)
|
|
|
187 |
otgService = true;
|
|
|
188 |
else
|
|
|
189 |
otgService = false;
|
| 7784 |
manish.sha |
190 |
logisticsLocationInfo.setOtgAvailable(otgService);
|
| 7735 |
manish.sha |
191 |
break;
|
| 7784 |
manish.sha |
192 |
case 6:
|
|
|
193 |
logisticsLocationInfo.setCodLimit((long) cellVal_Num);
|
|
|
194 |
break;
|
|
|
195 |
case 7:
|
|
|
196 |
logisticsLocationInfo.setPrepaidLimit((long) cellVal_Num);
|
|
|
197 |
break;
|
|
|
198 |
case 8:
|
|
|
199 |
logisticsLocationInfo.setWarehouseId((long) cellVal_Num);
|
|
|
200 |
break;
|
|
|
201 |
case 9:
|
|
|
202 |
logisticsLocationInfo.setDeliveryTime((long) cellVal_Num);
|
|
|
203 |
break;
|
|
|
204 |
case 10:
|
|
|
205 |
logisticsLocationInfo.setDelivery_delay((long) cellVal_Num);
|
|
|
206 |
break;
|
| 19421 |
manish.sha |
207 |
case 11:
|
|
|
208 |
logisticsLocationInfo.setZoneCode(cellVal_Str);
|
|
|
209 |
break;
|
| 7735 |
manish.sha |
210 |
}
|
| 23129 |
amit.gupta |
211 |
if(logisticsLocationInfo.getProviderId()==0l) break;
|
| 7735 |
manish.sha |
212 |
cellCount++;
|
|
|
213 |
}
|
| 7784 |
manish.sha |
214 |
logisticsLocationInfoList.add(logisticsLocationInfo);
|
| 7735 |
manish.sha |
215 |
}
|
| 7784 |
manish.sha |
216 |
try{
|
|
|
217 |
Client logisticsClient = new LogisticsClient().getClient();
|
| 23122 |
amit.gupta |
218 |
logisticsClient.runLogisticsLocationInfoUpdate(logisticsLocationInfoList, runCompleteUpdateValue, provider);
|
| 7784 |
manish.sha |
219 |
}
|
|
|
220 |
catch (TException e) {
|
|
|
221 |
logger.error("Unable to update data", e);
|
|
|
222 |
addActionError(e.getMessage());
|
|
|
223 |
}
|
|
|
224 |
if(checkForErrors())
|
|
|
225 |
return "Error in updation";
|
|
|
226 |
|
| 7735 |
manish.sha |
227 |
}
|
|
|
228 |
else{
|
|
|
229 |
addActionError("Uncompatible File Format !!!");
|
|
|
230 |
if(checkForErrors())
|
|
|
231 |
return "Error in updation";
|
|
|
232 |
}
|
|
|
233 |
if(!checkForErrors()){
|
|
|
234 |
successmsg="Pincode Updated Successfully";
|
|
|
235 |
}
|
| 6322 |
amar.kumar |
236 |
|
| 7735 |
manish.sha |
237 |
return "Pincode Updated Successfully";
|
|
|
238 |
|
| 6322 |
amar.kumar |
239 |
}
|
| 7735 |
manish.sha |
240 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
241 |
|
| 6322 |
amar.kumar |
242 |
public String addPincode() throws TException{
|
|
|
243 |
setBooleanServiceability();
|
|
|
244 |
Client logisticsClient = new LogisticsClient().getClient();
|
| 6524 |
rajveer |
245 |
logisticsClient.addPincode(provider, pincode, destCode, expService, codService, stationType_int, otgService);
|
| 6322 |
amar.kumar |
246 |
return null;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
public String updatePincode() throws TException{
|
|
|
250 |
setBooleanServiceability();
|
| 6612 |
amar.kumar |
251 |
logger.info("provider = " + provider + " pincode " + pincode + " exp = " + expService + " cod = " + codService + " otg = " + otgService);
|
| 6322 |
amar.kumar |
252 |
Client logisticsClient = new LogisticsClient().getClient();
|
| 6524 |
rajveer |
253 |
logisticsClient.updatePincode(provider, pincode, expService, codService, otgService);
|
| 6322 |
amar.kumar |
254 |
return null;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
public void setBooleanServiceability(){
|
|
|
258 |
|
|
|
259 |
if(cod!=null && cod.equals("on")) {
|
|
|
260 |
codService = true;
|
|
|
261 |
}
|
|
|
262 |
if(exp!= null && exp.equals("on")) {
|
|
|
263 |
expService = true;
|
|
|
264 |
}
|
| 6524 |
rajveer |
265 |
if(otg!= null && otg.equals("on")) {
|
|
|
266 |
otgService = true;
|
|
|
267 |
}
|
| 6322 |
amar.kumar |
268 |
if(stationType==null || !stationType.equals("on")) {
|
|
|
269 |
stationType_int = 0;
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
public Long getProvider() {
|
|
|
274 |
return provider;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public void setProvider(Long provider) {
|
|
|
278 |
this.provider = provider;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
public String getPincode() {
|
|
|
282 |
return pincode;
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
public void setPincode(String pincode) {
|
|
|
286 |
this.pincode = pincode;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
public String getDestCode() {
|
|
|
290 |
return destCode;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
public void setDestCode(String destCode) {
|
|
|
294 |
this.destCode = destCode;
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
public String isExp() {
|
|
|
298 |
return exp;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
public void setExp(String exp) {
|
|
|
302 |
this.exp = exp;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
public String isCod() {
|
|
|
306 |
return cod;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
public void setCod(String cod) {
|
|
|
310 |
this.cod = cod;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
public String isStationType() {
|
|
|
314 |
return stationType;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
public void setStationType(String stationType) {
|
|
|
318 |
this.stationType = stationType;
|
|
|
319 |
}
|
| 6524 |
rajveer |
320 |
|
|
|
321 |
public void setOtg(String otg) {
|
|
|
322 |
this.otg = otg;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
public String getOtg() {
|
|
|
326 |
return otg;
|
|
|
327 |
}
|
| 6322 |
amar.kumar |
328 |
|
| 7735 |
manish.sha |
329 |
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
|
|
330 |
public String getRunCompleteUpdate() {
|
|
|
331 |
return runCompleteUpdate;
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
public void setRunCompleteUpdate(String runCompleteUpdate) {
|
|
|
335 |
this.runCompleteUpdate = runCompleteUpdate;
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
public File getRecordsFile() {
|
|
|
339 |
return recordsFile;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
public void setRecordsFile(File recordsFile) {
|
|
|
343 |
this.recordsFile = recordsFile;
|
|
|
344 |
}
|
| 6322 |
amar.kumar |
345 |
|
| 7735 |
manish.sha |
346 |
public String getErrorMsg(){
|
|
|
347 |
return this.errorMsg;
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
public String getSuccessMessage(){
|
|
|
351 |
return this.successmsg ;
|
|
|
352 |
}
|
| 19421 |
manish.sha |
353 |
|
| 7735 |
manish.sha |
354 |
private boolean checkForErrors(){
|
|
|
355 |
Collection<String> actionErrors = getActionErrors();
|
|
|
356 |
if(actionErrors != null && !actionErrors.isEmpty()){
|
|
|
357 |
for (String str : actionErrors) {
|
|
|
358 |
errorMsg += "<BR/>" + str;
|
|
|
359 |
}
|
|
|
360 |
return true;
|
|
|
361 |
}
|
|
|
362 |
return false;
|
|
|
363 |
}
|
|
|
364 |
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
|
| 6322 |
amar.kumar |
365 |
}
|