Subversion Repositories SmartDukaan

Rev

Rev 19421 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
	                        System.out.print(cell.getBooleanCellValue() + "\t\t");
144
	                        break;
145
	                    case Cell.CELL_TYPE_NUMERIC:
146
	                    	cellVal_Num= (long) cell.getNumericCellValue();
147
	                        System.out.print(cell.getNumericCellValue() + "\t\t");
148
	                        break;
149
	                    case Cell.CELL_TYPE_STRING:
150
	                    	cellVal_Str = cell.getStringCellValue();
151
	                        System.out.print(cell.getStringCellValue() + "\t\t");
152
	                        break;
153
	                }
154
	                switch(cellCount) {
155
	                	case 0:
23122 amit.gupta 156
	                		long provider_id = (long) cellVal_Num;
157
	                		if (provider_id != provider) break;
7784 manish.sha 158
	                		logisticsLocationInfo.setProviderId((long) cellVal_Num);
7735 manish.sha 159
	                		break;
160
	                	case 1:
161
	                		pincode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
7784 manish.sha 162
	                		logisticsLocationInfo.setPinCode(pincode);
7735 manish.sha 163
	                		break;
164
	                	case 2:
165
	                		destCode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
7784 manish.sha 166
	                		logisticsLocationInfo.setDestinationCode(destCode);
7735 manish.sha 167
	                		break;
168
	                	case 3:
169
	                		if(cellVal_Num==0L)
170
	                			expService = false;
171
	                		else if(cellVal_Num==1L)
172
	                			expService = true;
173
	                		else 
174
	                			expService = false;
7784 manish.sha 175
	                		logisticsLocationInfo.setExpAvailable(expService);
7735 manish.sha 176
	                		break;
177
	                	case 4:
178
	                		if(cellVal_Num==0L)
179
	                			codService = false;
180
	                		else if(cellVal_Num==1L)
181
	                			codService = true;
182
	                		else 
183
	                			codService = false;
7784 manish.sha 184
	                		logisticsLocationInfo.setCodAvailable(codService);
7735 manish.sha 185
	                		break;
186
	                	case 5:
187
	                		if(cellVal_Num==0L)
188
	                			otgService = false;
189
	                		else if(cellVal_Num==1L)
190
	                			otgService = true;
191
	                		else 
192
	                			otgService = false;
7784 manish.sha 193
	                		logisticsLocationInfo.setOtgAvailable(otgService);
7735 manish.sha 194
	                		break;
7784 manish.sha 195
	                	case 6:
196
	                		logisticsLocationInfo.setCodLimit((long) cellVal_Num);
197
	                		break;
198
	                	case 7:
199
	                		logisticsLocationInfo.setPrepaidLimit((long) cellVal_Num);
200
	                		break;
201
	                	case 8:
202
	                		logisticsLocationInfo.setWarehouseId((long) cellVal_Num);
203
	                		break;
204
	                	case 9:
205
	                		logisticsLocationInfo.setDeliveryTime((long) cellVal_Num);
206
	                		break;
207
	                	case 10:
208
	                		logisticsLocationInfo.setDelivery_delay((long) cellVal_Num);
209
	                		break;
19421 manish.sha 210
	                	case 11:
211
	                		logisticsLocationInfo.setZoneCode(cellVal_Str);
212
	                		break;
7735 manish.sha 213
	                }
214
	               cellCount++;
215
	            }
7784 manish.sha 216
	            logisticsLocationInfoList.add(logisticsLocationInfo);
7735 manish.sha 217
	        }
7784 manish.sha 218
	        try{
219
            	Client logisticsClient = new LogisticsClient().getClient();
23122 amit.gupta 220
	            logisticsClient.runLogisticsLocationInfoUpdate(logisticsLocationInfoList, runCompleteUpdateValue, provider);
7784 manish.sha 221
            }
222
            catch (TException e) {
223
                logger.error("Unable to update data", e);
224
                addActionError(e.getMessage());
225
            }
226
            if(checkForErrors())
227
	            return "Error in updation";
228
 
7735 manish.sha 229
		}
230
		else{
231
			addActionError("Uncompatible File Format !!!");
232
			if(checkForErrors())
233
	            return "Error in updation";
234
		}
235
		if(!checkForErrors()){
236
			successmsg="Pincode Updated Successfully";
237
		}
6322 amar.kumar 238
 
7735 manish.sha 239
		return "Pincode Updated Successfully";
240
 
6322 amar.kumar 241
	}
7735 manish.sha 242
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
243
 
6322 amar.kumar 244
	public String addPincode() throws TException{
245
		setBooleanServiceability();
246
		Client logisticsClient = new LogisticsClient().getClient();
6524 rajveer 247
		logisticsClient.addPincode(provider, pincode, destCode, expService, codService, stationType_int, otgService);
6322 amar.kumar 248
		return null;
249
	}
250
 
251
	public String updatePincode() throws TException{
252
		setBooleanServiceability();
6612 amar.kumar 253
		logger.info("provider = " + provider + " pincode " + pincode + " exp = " + expService + " cod = " + codService + " otg = " + otgService);
6322 amar.kumar 254
		Client logisticsClient = new LogisticsClient().getClient();
6524 rajveer 255
		logisticsClient.updatePincode(provider, pincode, expService, codService, otgService);
6322 amar.kumar 256
		return null;
257
	}
258
 
259
	public void setBooleanServiceability(){
260
 
261
		if(cod!=null && cod.equals("on")) {
262
			codService = true;
263
		}
264
		if(exp!= null && exp.equals("on")) {
265
			expService = true;
266
		}
6524 rajveer 267
		if(otg!= null && otg.equals("on")) {
268
			otgService = true;
269
		}
6322 amar.kumar 270
		if(stationType==null || !stationType.equals("on")) {
271
			stationType_int = 0;
272
		}
273
	}
274
 
275
	public Long getProvider() {
276
		return provider;
277
	}
278
 
279
	public void setProvider(Long provider) {
280
		this.provider = provider;
281
	}
282
 
283
	public String getPincode() {
284
		return pincode;
285
	}
286
 
287
	public void setPincode(String pincode) {
288
		this.pincode = pincode;
289
	}
290
 
291
	public String getDestCode() {
292
		return destCode;
293
	}
294
 
295
	public void setDestCode(String destCode) {
296
		this.destCode = destCode;
297
	}
298
 
299
	public String isExp() {
300
		return exp;
301
	}
302
 
303
	public void setExp(String exp) {
304
		this.exp = exp;
305
	}
306
 
307
	public String isCod() {
308
		return cod;
309
	}
310
 
311
	public void setCod(String cod) {
312
		this.cod = cod;
313
	}
314
 
315
	public String isStationType() {
316
		return stationType;
317
	}
318
 
319
	public void setStationType(String stationType) {
320
		this.stationType = stationType;
321
	}
6524 rajveer 322
 
323
	public void setOtg(String otg) {
324
		this.otg = otg;
325
	}
326
 
327
	public String getOtg() {
328
		return otg;
329
	}
6322 amar.kumar 330
 
7735 manish.sha 331
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
332
	public String getRunCompleteUpdate() {
333
		return runCompleteUpdate;
334
	}
335
 
336
	public void setRunCompleteUpdate(String runCompleteUpdate) {
337
		this.runCompleteUpdate = runCompleteUpdate;
338
	}
339
 
340
	public File getRecordsFile() {
341
		return recordsFile;
342
	}
343
 
344
	public void setRecordsFile(File recordsFile) {
345
		this.recordsFile = recordsFile;
346
	}
6322 amar.kumar 347
 
7735 manish.sha 348
	public String getErrorMsg(){
349
        return this.errorMsg;
350
    }
351
 
352
	public String getSuccessMessage(){
353
		return this.successmsg ;
354
	}
19421 manish.sha 355
 
7735 manish.sha 356
	private boolean checkForErrors(){
357
        Collection<String> actionErrors = getActionErrors();
358
        if(actionErrors != null && !actionErrors.isEmpty()){
359
            for (String str : actionErrors) {
360
                errorMsg += "<BR/>" + str;
361
            }
362
            return true;
363
        }
364
        return false;
365
    }
366
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
6322 amar.kumar 367
}