Subversion Repositories SmartDukaan

Rev

Rev 6612 | Rev 7784 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6612 Rev 7735
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.logistics.LogisticsService.Client;
3
import in.shop2020.logistics.LogisticsService.Client;
-
 
4
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
5
import in.shop2020.support.utils.ReportsUtils;
-
 
6
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
4
import in.shop2020.thrift.clients.LogisticsClient;
7
import in.shop2020.thrift.clients.LogisticsClient;
5
 
8
 
6
import javax.servlet.http.HttpServletRequest;
9
import javax.servlet.http.HttpServletRequest;
-
 
10
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
11
import javax.servlet.http.HttpSession;
-
 
12
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
7
 
13
 
8
import org.apache.struts2.interceptor.ServletRequestAware;
14
import org.apache.struts2.interceptor.ServletRequestAware;
9
import org.apache.thrift.TException;
15
import org.apache.thrift.TException;
10
import org.slf4j.Logger;
16
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
17
import org.slf4j.LoggerFactory;
-
 
18
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
19
import org.apache.commons.io.FileUtils;
-
 
20
import org.apache.poi.hssf.usermodel.HSSFSheet;
-
 
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
 
22
import org.apache.poi.ss.usermodel.Cell;
-
 
23
import org.apache.poi.ss.usermodel.Row;
12
 
-
 
-
 
24
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
13
import com.opensymphony.xwork2.ActionSupport;
25
import com.opensymphony.xwork2.ActionSupport;
-
 
26
//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
27
import java.io.File;
-
 
28
import java.io.FileInputStream;
-
 
29
import java.io.FileNotFoundException;
-
 
30
import java.io.IOException;
-
 
31
import java.util.Collection;
-
 
32
import java.util.Iterator;
-
 
33
//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
14
 
34
 
-
 
35
@SuppressWarnings("serial")
15
public class PincodeController extends ActionSupport implements ServletRequestAware {
36
public class PincodeController extends ActionSupport implements ServletRequestAware {
16
	
37
	
17
	private Long provider;
38
	private Long provider;
18
	private String pincode;
39
	private String pincode;
19
	private String destCode;
40
	private String destCode;
20
	private String exp;
41
	private String exp;
21
	private String cod;
42
	private String cod;
22
	private String otg;
43
	private String otg;
23
	private String stationType;
44
	private String stationType;
-
 
45
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
46
	private String runCompleteUpdate;
-
 
47
	
-
 
48
	private HttpServletRequest request;
-
 
49
    private HttpSession session;
-
 
50
    //End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
24
	
51
	
25
	private boolean codService = false;
52
	private boolean codService = false;
26
	private boolean expService = false;
53
	private boolean expService = false;
27
	private boolean otgService = false;
54
	private boolean otgService = false;
28
	private int stationType_int = 1;
55
	private int stationType_int = 1;
-
 
56
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
57
	private boolean runCompleteUpdateValue = false;
29
	
58
	
-
 
59
	private File recordsFile;
-
 
60
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
30
	private static Logger logger = LoggerFactory.getLogger(PincodeController.class);
61
	private static Logger logger = LoggerFactory.getLogger(PincodeController.class);
-
 
62
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
63
    private String errorMsg = "";
-
 
64
	private String successmsg = "";
31
	
65
 
-
 
66
    public String index() {
-
 
67
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
-
 
68
            return "authfail";
-
 
69
        checkForErrors();
-
 
70
        return "authsuccess";
-
 
71
    }
-
 
72
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
73
    
32
	@Override
74
	@Override
33
	public void setServletRequest(HttpServletRequest arg0) {
75
	public void setServletRequest(HttpServletRequest request) {
34
		// TODO Auto-generated method stub
76
		// TODO Auto-generated method stub
-
 
77
		//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
35
		
78
		this.request = request;
-
 
79
        this.session = request.getSession();		
-
 
80
        //End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
36
	}
81
	}
37
 
82
 
-
 
83
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
84
	public String create(){
-
 
85
		if(runCompleteUpdate!=null && runCompleteUpdate.equals("on")) {
-
 
86
			runCompleteUpdateValue = true;
-
 
87
		}
-
 
88
		 File fileToCreate = null;
-
 
89
	        try {
-
 
90
	            fileToCreate = new File("/tmp/", this.recordsFile.getName());
-
 
91
	            FileUtils.copyFile(this.recordsFile, fileToCreate);
-
 
92
	        } catch (Exception e) {
-
 
93
	           logger.error("Error while writing file used to the local file system", e);
-
 
94
	           addActionError("Unable to open the Uploaded File. Please check the file format.");
-
 
95
	           return "Error while writing file used to the local file system";
-
 
96
	        }
-
 
97
		if(fileToCreate.isFile()){
-
 
98
			HSSFWorkbook wb = null;
-
 
99
			try{
-
 
100
				wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
-
 
101
			}
-
 
102
			catch (FileNotFoundException e) {
-
 
103
	            logger.error("Unable to open the Uploaded File", e);
-
 
104
	            addActionError("Unable to open the Uploaded File. Please check the file format.");
-
 
105
	        } catch (IOException 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
	        }
-
 
109
	        catch (Exception e){
-
 
110
	        	logger.error("Supplied Data is not in specified form. Please check the file format",e);
-
 
111
	        	addActionError("Supplied Data is not in specified form. Please check the file format");
-
 
112
	        }
-
 
113
	        if(checkForErrors())
-
 
114
	            return "Error in updation";
-
 
115
	        try{
-
 
116
		        Client logisticsClient = new LogisticsClient().getClient();
-
 
117
		        if(runCompleteUpdateValue){
-
 
118
		        	logisticsClient.runCompleteUpdateForPincode();
-
 
119
		        }
-
 
120
	        }
-
 
121
	        catch (TException e) {
-
 
122
                logger.error("Unable to complete the operation", e);
-
 
123
                addActionError(e.getMessage());
-
 
124
            }
-
 
125
	        if(checkForErrors())
-
 
126
	            return "Error in updation";
-
 
127
	        HSSFSheet sheet= wb.getSheetAt(0);
-
 
128
	        Iterator<Row> rowIterator = sheet.rowIterator();
-
 
129
	        int rowCount = 0;
-
 
130
	        while(rowIterator.hasNext()) {
-
 
131
	            Row row = rowIterator.next();
-
 
132
	            if(rowCount++==0)
-
 
133
	            	continue;
-
 
134
	            Iterator<Cell> cellIterator = row.cellIterator();
-
 
135
	            int cellCount= 0;
-
 
136
	            while(cellIterator.hasNext()) {
-
 
137
	                 
-
 
138
	                Cell cell = cellIterator.next();
-
 
139
	                String cellVal_Str ="";
-
 
140
	                Long cellVal_Num  = 0L;
-
 
141
	                boolean cellVal_bool = false;
-
 
142
	                
-
 
143
	                switch(cell.getCellType()) {
-
 
144
	                    case Cell.CELL_TYPE_BOOLEAN:
-
 
145
	                    	cellVal_bool = cell.getBooleanCellValue();
-
 
146
	                        System.out.print(cell.getBooleanCellValue() + "\t\t");
-
 
147
	                        break;
-
 
148
	                    case Cell.CELL_TYPE_NUMERIC:
-
 
149
	                    	cellVal_Num= (long) cell.getNumericCellValue();
-
 
150
	                        System.out.print(cell.getNumericCellValue() + "\t\t");
-
 
151
	                        break;
-
 
152
	                    case Cell.CELL_TYPE_STRING:
-
 
153
	                    	cellVal_Str = cell.getStringCellValue();
-
 
154
	                        System.out.print(cell.getStringCellValue() + "\t\t");
-
 
155
	                        break;
-
 
156
	                }
-
 
157
	                switch(cellCount) {
-
 
158
	                	case 0:
-
 
159
	                		provider = (long) cellVal_Num;
-
 
160
	                		break;
-
 
161
	                	case 1:
-
 
162
	                		pincode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
-
 
163
	                		break;
-
 
164
	                	case 2:
-
 
165
	                		destCode = cellVal_Str.length() > 0 ? cellVal_Str : cellVal_Num +"";
-
 
166
	                		break;
-
 
167
	                	case 3:
-
 
168
	                		if(cellVal_Num==0L)
-
 
169
	                			expService = false;
-
 
170
	                		else if(cellVal_Num==1L)
-
 
171
	                			expService = true;
-
 
172
	                		else 
-
 
173
	                			expService = false;
-
 
174
	                		break;
-
 
175
	                	case 4:
-
 
176
	                		if(cellVal_Num==0L)
-
 
177
	                			codService = false;
-
 
178
	                		else if(cellVal_Num==1L)
-
 
179
	                			codService = true;
-
 
180
	                		else 
-
 
181
	                			codService = false;
-
 
182
	                		break;
-
 
183
	                	case 5:
-
 
184
	                		stationType_int = Integer.parseInt(cellVal_Num.toString());
-
 
185
	                		break;
-
 
186
	                	case 6:
-
 
187
	                		if(cellVal_Num==0L)
-
 
188
	                			otgService = false;
-
 
189
	                		else if(cellVal_Num==1L)
-
 
190
	                			otgService = true;
-
 
191
	                		else 
-
 
192
	                			otgService = false;
-
 
193
	                		break;
-
 
194
	                }
-
 
195
	               cellCount++;
-
 
196
	            }
-
 
197
	            try{
-
 
198
	            	Client logisticsClient = new LogisticsClient().getClient();
-
 
199
		            boolean isRecordAvaliable = logisticsClient.getServiceableLocationAsPerProviderIdAndPincode(provider, pincode);
-
 
200
	                if(isRecordAvaliable){
-
 
201
	                	logisticsClient.updatePincode(provider, pincode, expService, codService, otgService);
-
 
202
	                }
-
 
203
	                else{
-
 
204
	                	logisticsClient.addPincode(provider, pincode, destCode, expService, codService, stationType_int, otgService);
-
 
205
	                }
-
 
206
	            }
-
 
207
	            catch (TException e) {
-
 
208
	                logger.error("Unable to update data", e);
-
 
209
	                addActionError(e.getMessage());
-
 
210
	            }
-
 
211
	            if(checkForErrors())
-
 
212
		            return "Error in updation";
-
 
213
	        }
-
 
214
		}
-
 
215
		else{
-
 
216
			addActionError("Uncompatible File Format !!!");
-
 
217
			if(checkForErrors())
-
 
218
	            return "Error in updation";
-
 
219
		}
-
 
220
		if(!checkForErrors()){
-
 
221
			successmsg="Pincode Updated Successfully";
-
 
222
		}
-
 
223
		
-
 
224
		return "Pincode Updated Successfully";
-
 
225
	
-
 
226
	}
-
 
227
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
228
	
38
	public String addPincode() throws TException{
229
	public String addPincode() throws TException{
39
		setBooleanServiceability();
230
		setBooleanServiceability();
40
		Client logisticsClient = new LogisticsClient().getClient();
231
		Client logisticsClient = new LogisticsClient().getClient();
41
		logisticsClient.addPincode(provider, pincode, destCode, expService, codService, stationType_int, otgService);
232
		logisticsClient.addPincode(provider, pincode, destCode, expService, codService, stationType_int, otgService);
42
		return null;
233
		return null;
Line 120... Line 311...
120
 
311
 
121
	public String getOtg() {
312
	public String getOtg() {
122
		return otg;
313
		return otg;
123
	}
314
	}
124
	
315
	
-
 
316
	//Start:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
-
 
317
	public String getRunCompleteUpdate() {
-
 
318
		return runCompleteUpdate;
-
 
319
	}
-
 
320
 
-
 
321
	public void setRunCompleteUpdate(String runCompleteUpdate) {
-
 
322
		this.runCompleteUpdate = runCompleteUpdate;
-
 
323
	}
-
 
324
 
-
 
325
	public File getRecordsFile() {
-
 
326
		return recordsFile;
-
 
327
	}
-
 
328
 
-
 
329
	public void setRecordsFile(File recordsFile) {
-
 
330
		this.recordsFile = recordsFile;
-
 
331
	}
-
 
332
	
-
 
333
	public String getErrorMsg(){
-
 
334
        return this.errorMsg;
-
 
335
    }
-
 
336
	
-
 
337
	public String getSuccessMessage(){
-
 
338
		return this.successmsg ;
-
 
339
	}
125
	
340
	
-
 
341
	private boolean checkForErrors(){
-
 
342
        Collection<String> actionErrors = getActionErrors();
-
 
343
        if(actionErrors != null && !actionErrors.isEmpty()){
-
 
344
            for (String str : actionErrors) {
-
 
345
                errorMsg += "<BR/>" + str;
-
 
346
            }
-
 
347
            return true;
-
 
348
        }
-
 
349
        return false;
-
 
350
    }
-
 
351
	//End:- Added/Modified by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013
126
}
352
}