Subversion Repositories SmartDukaan

Rev

Rev 3125 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3125 Rev 3214
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.user.User;
3
import in.shop2020.model.v1.user.User;
4
import in.shop2020.model.v1.user.UserCommunication;
4
import in.shop2020.model.v1.user.UserCommunication;
-
 
5
import in.shop2020.model.v1.user.UserCommunicationException;
5
import in.shop2020.model.v1.user.UserContextException;
6
import in.shop2020.model.v1.user.UserContextException;
6
import in.shop2020.model.v1.user.UserContextService.Client;
7
import in.shop2020.model.v1.user.UserContextService.Client;
7
import in.shop2020.thrift.clients.UserClient;
8
import in.shop2020.thrift.clients.UserClient;
8
 
9
 
9
import java.io.ByteArrayOutputStream;
10
import java.io.ByteArrayOutputStream;
Line 23... Line 24...
23
import org.apache.poi.ss.usermodel.Sheet;
24
import org.apache.poi.ss.usermodel.Sheet;
24
import org.apache.poi.ss.usermodel.Workbook;
25
import org.apache.poi.ss.usermodel.Workbook;
25
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.struts2.interceptor.ServletResponseAware;
27
import org.apache.struts2.interceptor.ServletResponseAware;
27
import org.apache.thrift.TException;
28
import org.apache.thrift.TException;
-
 
29
import org.slf4j.Logger;
-
 
30
import org.slf4j.LoggerFactory;
28
 
31
 
29
public class UserCommunicationsController implements ServletResponseAware{
32
public class UserCommunicationsController implements ServletResponseAware{
-
 
33
    
-
 
34
    private static Logger logger = LoggerFactory.getLogger(UserCommunicationsController.class);
30
 
35
 
31
	private HttpServletResponse response;
36
	private HttpServletResponse response;
32
	
37
	
33
	private String errorMsg = "";
38
	private String errorMsg = "";
34
	
39
	
Line 55... Line 60...
55
                ByteArrayOutputStream baos = getSpreadSheetData(allCommunications, userClient);
60
                ByteArrayOutputStream baos = getSpreadSheetData(allCommunications, userClient);
56
                sos = response.getOutputStream();
61
                sos = response.getOutputStream();
57
                baos.writeTo(sos);
62
                baos.writeTo(sos);
58
                sos.flush();
63
                sos.flush();
59
            } catch (IOException e) {
64
            } catch (IOException e) {
-
 
65
                logger.error("Unable to stream the user communications report");
60
                errorMsg = "Failed to write to response.";
66
                errorMsg = "Failed to write to response.";
61
                e.printStackTrace();
-
 
62
            }
67
            }
63
 
68
 
-
 
69
        } catch (UserCommunicationException e) {
-
 
70
            logger.error("Error while getting user communications", e);
-
 
71
            errorMsg = e.getMessage();
-
 
72
        } catch (TException e) {
-
 
73
            logger.error("Unable to get user communications", e);
-
 
74
            errorMsg = e.getMessage();
64
        } catch (Exception e)   {
75
        } catch (Exception e) {
-
 
76
            logger.error("Unexpected exception", e);
65
            errorMsg = e.getMessage();
77
            errorMsg = e.getMessage();
66
            e.printStackTrace();
-
 
67
        }
78
        }
68
        return null;
79
        return null;
69
	}
80
	}
70
	
81
	
71
	// Prepares the XLS worksheet object and fills in the data with proper formatting
82
	// Prepares the XLS worksheet object and fills in the data with proper formatting
Line 90... Line 101...
90
		// Write the workbook to the output stream
101
		// Write the workbook to the output stream
91
		try {
102
		try {
92
			wb.write(baosXLS);
103
			wb.write(baosXLS);
93
			baosXLS.close();
104
			baosXLS.close();
94
		} catch (IOException e) {
105
		} catch (IOException e) {
95
			e.printStackTrace();
106
			logger.error("Error while converting the user communications report to a byte array", e);
96
		}		
107
		}		
97
		return baosXLS;
108
		return baosXLS;
98
	}
109
	}
99
	
110
	
100
	private void createAllUserCommunicationSheet(
111
	private void createAllUserCommunicationSheet(
Line 152... Line 163...
152
					if (user.getSex() != null) {
163
					if (user.getSex() != null) {
153
						commContentRow.createCell(6).setCellValue(user.getSex().name());
164
						commContentRow.createCell(6).setCellValue(user.getSex().name());
154
					}
165
					}
155
				}
166
				}
156
			} catch (UserContextException e) {
167
			} catch (UserContextException e) {
157
				e.printStackTrace();
168
				logger.error("Error while getting user data", e);
158
			} catch (TException e) {
169
			} catch (TException e) {
159
				e.printStackTrace();
170
				logger.error("Unable to get user data", e);
160
			}
171
			}
161
			commContentRow.createCell(7).setCellValue(userComm.getOrderId());
172
			commContentRow.createCell(7).setCellValue(userComm.getOrderId());
162
			if (userComm.getCommunicationType() != null) {
173
			if (userComm.getCommunicationType() != null) {
163
				commContentRow.createCell(8).setCellValue(
174
				commContentRow.createCell(8).setCellValue(
164
						userComm.getCommunicationType().name());
175
						userComm.getCommunicationType().name());