Subversion Repositories SmartDukaan

Rev

Rev 7735 | 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;
90
		}
91
		 File fileToCreate = null;
92
	        try {
93
	            fileToCreate = new File("/tmp/", this.recordsFile.getName());
94
	            FileUtils.copyFile(this.recordsFile, fileToCreate);
95
	        } catch (Exception e) {
96
	           logger.error("Error while writing file used to the local file system", e);
97
	           addActionError("Unable to open the Uploaded File. Please check the file format.");
98
	           return "Error while writing file used to the local file system";
99
	        }
100
		if(fileToCreate.isFile()){
101
			HSSFWorkbook wb = null;
102
			try{
103
				wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
104
			}
105
			catch (FileNotFoundException e) {
106
	            logger.error("Unable to open the Uploaded File", e);
107
	            addActionError("Unable to open the Uploaded File. Please check the file format.");
108
	        } catch (IOException e) {
109
	            logger.error("Unable to open the Uploaded File", e);
110
	            addActionError("Unable to open the Uploaded File. Please check the file format.");
111
	        }
112
	        catch (Exception e){
113
	        	logger.error("Supplied Data is not in specified form. Please check the file format",e);
114
	        	addActionError("Supplied Data is not in specified form. Please check the file format");
115
	        }
116
	        if(checkForErrors())
117
	            return "Error in updation";
7784 manish.sha 118
 
7735 manish.sha 119
	        HSSFSheet sheet= wb.getSheetAt(0);
120
	        Iterator<Row> rowIterator = sheet.rowIterator();
121
	        int rowCount = 0;
7784 manish.sha 122
	        List<LogisticsLocationInfo> logisticsLocationInfoList;
123
	        logisticsLocationInfoList = new ArrayList<LogisticsLocationInfo>();
7735 manish.sha 124
	        while(rowIterator.hasNext()) {
125
	            Row row = rowIterator.next();
126
	            if(rowCount++==0)
127
	            	continue;
128
	            Iterator<Cell> cellIterator = row.cellIterator();
129
	            int cellCount= 0;
7784 manish.sha 130
	            LogisticsLocationInfo logisticsLocationInfo = new LogisticsLocationInfo();
7735 manish.sha 131
	            while(cellIterator.hasNext()) {
132
 
133
	                Cell cell = cellIterator.next();
134
	                String cellVal_Str ="";
135
	                Long cellVal_Num  = 0L;
136
	                boolean cellVal_bool = false;
137
 
138
	                switch(cell.getCellType()) {
139
	                    case Cell.CELL_TYPE_BOOLEAN:
140
	                    	cellVal_bool = cell.getBooleanCellValue();
141
	                        System.out.print(cell.getBooleanCellValue() + "\t\t");
142
	                        break;
143
	                    case Cell.CELL_TYPE_NUMERIC:
144
	                    	cellVal_Num= (long) cell.getNumericCellValue();
145
	                        System.out.print(cell.getNumericCellValue() + "\t\t");
146
	                        break;
147
	                    case Cell.CELL_TYPE_STRING:
148
	                    	cellVal_Str = cell.getStringCellValue();
149
	                        System.out.print(cell.getStringCellValue() + "\t\t");
150
	                        break;
151
	                }
152
	                switch(cellCount) {
153
	                	case 0:
7784 manish.sha 154
	                		logisticsLocationInfo.setProviderId((long) cellVal_Num);
7735 manish.sha 155
	                		break;
156
	                	case 1:
157
	                		pincode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
7784 manish.sha 158
	                		logisticsLocationInfo.setPinCode(pincode);
7735 manish.sha 159
	                		break;
160
	                	case 2:
161
	                		destCode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
7784 manish.sha 162
	                		logisticsLocationInfo.setDestinationCode(destCode);
7735 manish.sha 163
	                		break;
164
	                	case 3:
165
	                		if(cellVal_Num==0L)
166
	                			expService = false;
167
	                		else if(cellVal_Num==1L)
168
	                			expService = true;
169
	                		else 
170
	                			expService = false;
7784 manish.sha 171
	                		logisticsLocationInfo.setExpAvailable(expService);
7735 manish.sha 172
	                		break;
173
	                	case 4:
174
	                		if(cellVal_Num==0L)
175
	                			codService = false;
176
	                		else if(cellVal_Num==1L)
177
	                			codService = true;
178
	                		else 
179
	                			codService = false;
7784 manish.sha 180
	                		logisticsLocationInfo.setCodAvailable(codService);
7735 manish.sha 181
	                		break;
182
	                	case 5:
183
	                		if(cellVal_Num==0L)
184
	                			otgService = false;
185
	                		else if(cellVal_Num==1L)
186
	                			otgService = true;
187
	                		else 
188
	                			otgService = false;
7784 manish.sha 189
	                		logisticsLocationInfo.setOtgAvailable(otgService);
7735 manish.sha 190
	                		break;
7784 manish.sha 191
	                	case 6:
192
	                		logisticsLocationInfo.setCodLimit((long) cellVal_Num);
193
	                		break;
194
	                	case 7:
195
	                		logisticsLocationInfo.setPrepaidLimit((long) cellVal_Num);
196
	                		break;
197
	                	case 8:
198
	                		logisticsLocationInfo.setWarehouseId((long) cellVal_Num);
199
	                		break;
200
	                	case 9:
201
	                		logisticsLocationInfo.setDeliveryTime((long) cellVal_Num);
202
	                		break;
203
	                	case 10:
204
	                		logisticsLocationInfo.setDelivery_delay((long) cellVal_Num);
205
	                		break;
7735 manish.sha 206
	                }
207
	               cellCount++;
208
	            }
7784 manish.sha 209
	            logisticsLocationInfoList.add(logisticsLocationInfo);
7735 manish.sha 210
	        }
7784 manish.sha 211
	        try{
212
            	Client logisticsClient = new LogisticsClient().getClient();
213
	            logisticsClient.runLogisticsLocationInfoUpdate(logisticsLocationInfoList, runCompleteUpdateValue);
214
            }
215
            catch (TException e) {
216
                logger.error("Unable to update data", e);
217
                addActionError(e.getMessage());
218
            }
219
            if(checkForErrors())
220
	            return "Error in updation";
221
 
7735 manish.sha 222
		}
223
		else{
224
			addActionError("Uncompatible File Format !!!");
225
			if(checkForErrors())
226
	            return "Error in updation";
227
		}
228
		if(!checkForErrors()){
229
			successmsg="Pincode Updated Successfully";
230
		}
6322 amar.kumar 231
 
7735 manish.sha 232
		return "Pincode Updated Successfully";
233
 
6322 amar.kumar 234
	}
7735 manish.sha 235
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
236
 
6322 amar.kumar 237
	public String addPincode() throws TException{
238
		setBooleanServiceability();
239
		Client logisticsClient = new LogisticsClient().getClient();
6524 rajveer 240
		logisticsClient.addPincode(provider, pincode, destCode, expService, codService, stationType_int, otgService);
6322 amar.kumar 241
		return null;
242
	}
243
 
244
	public String updatePincode() throws TException{
245
		setBooleanServiceability();
6612 amar.kumar 246
		logger.info("provider = " + provider + " pincode " + pincode + " exp = " + expService + " cod = " + codService + " otg = " + otgService);
6322 amar.kumar 247
		Client logisticsClient = new LogisticsClient().getClient();
6524 rajveer 248
		logisticsClient.updatePincode(provider, pincode, expService, codService, otgService);
6322 amar.kumar 249
		return null;
250
	}
251
 
252
	public void setBooleanServiceability(){
253
 
254
		if(cod!=null && cod.equals("on")) {
255
			codService = true;
256
		}
257
		if(exp!= null && exp.equals("on")) {
258
			expService = true;
259
		}
6524 rajveer 260
		if(otg!= null && otg.equals("on")) {
261
			otgService = true;
262
		}
6322 amar.kumar 263
		if(stationType==null || !stationType.equals("on")) {
264
			stationType_int = 0;
265
		}
266
	}
267
 
268
	public Long getProvider() {
269
		return provider;
270
	}
271
 
272
	public void setProvider(Long provider) {
273
		this.provider = provider;
274
	}
275
 
276
	public String getPincode() {
277
		return pincode;
278
	}
279
 
280
	public void setPincode(String pincode) {
281
		this.pincode = pincode;
282
	}
283
 
284
	public String getDestCode() {
285
		return destCode;
286
	}
287
 
288
	public void setDestCode(String destCode) {
289
		this.destCode = destCode;
290
	}
291
 
292
	public String isExp() {
293
		return exp;
294
	}
295
 
296
	public void setExp(String exp) {
297
		this.exp = exp;
298
	}
299
 
300
	public String isCod() {
301
		return cod;
302
	}
303
 
304
	public void setCod(String cod) {
305
		this.cod = cod;
306
	}
307
 
308
	public String isStationType() {
309
		return stationType;
310
	}
311
 
312
	public void setStationType(String stationType) {
313
		this.stationType = stationType;
314
	}
6524 rajveer 315
 
316
	public void setOtg(String otg) {
317
		this.otg = otg;
318
	}
319
 
320
	public String getOtg() {
321
		return otg;
322
	}
6322 amar.kumar 323
 
7735 manish.sha 324
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
325
	public String getRunCompleteUpdate() {
326
		return runCompleteUpdate;
327
	}
328
 
329
	public void setRunCompleteUpdate(String runCompleteUpdate) {
330
		this.runCompleteUpdate = runCompleteUpdate;
331
	}
332
 
333
	public File getRecordsFile() {
334
		return recordsFile;
335
	}
336
 
337
	public void setRecordsFile(File recordsFile) {
338
		this.recordsFile = recordsFile;
339
	}
6322 amar.kumar 340
 
7735 manish.sha 341
	public String getErrorMsg(){
342
        return this.errorMsg;
343
    }
344
 
345
	public String getSuccessMessage(){
346
		return this.successmsg ;
347
	}
348
 
349
	private boolean checkForErrors(){
350
        Collection<String> actionErrors = getActionErrors();
351
        if(actionErrors != null && !actionErrors.isEmpty()){
352
            for (String str : actionErrors) {
353
                errorMsg += "<BR/>" + str;
354
            }
355
            return true;
356
        }
357
        return false;
358
    }
359
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
6322 amar.kumar 360
}