| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.services;
|
1 |
package in.shop2020.support.services;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.user.Address;
|
3 |
import in.shop2020.model.v1.user.Address;
|
| 4 |
import in.shop2020.model.v1.user.User;
|
4 |
import in.shop2020.model.v1.user.User;
|
| - |
|
5 |
import in.shop2020.model.v1.user.UserContextException;
|
| - |
|
6 |
import in.shop2020.model.v1.user.UserState;
|
| 5 |
import in.shop2020.model.v1.user.UserType;
|
7 |
import in.shop2020.model.v1.user.UserType;
|
| 6 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
8 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 7 |
|
9 |
|
| 8 |
import java.io.ByteArrayOutputStream;
|
10 |
import java.io.ByteArrayOutputStream;
|
| 9 |
import java.io.FileNotFoundException;
|
11 |
import java.io.FileNotFoundException;
|
| 10 |
import java.io.FileOutputStream;
|
12 |
import java.io.FileOutputStream;
|
| 11 |
import java.io.IOException;
|
13 |
import java.io.IOException;
|
| - |
|
14 |
import java.text.DateFormat;
|
| - |
|
15 |
import java.text.SimpleDateFormat;
|
| 12 |
import java.util.Calendar;
|
16 |
import java.util.Calendar;
|
| 13 |
import java.util.List;
|
17 |
import java.util.List;
|
| 14 |
|
18 |
|
| 15 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
19 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 16 |
import org.apache.poi.ss.usermodel.Cell;
|
20 |
import org.apache.poi.ss.usermodel.Cell;
|
| Line 82... |
Line 86... |
| 82 |
titleCell.setCellValue("Registered Users");
|
86 |
titleCell.setCellValue("Registered Users");
|
| 83 |
titleCell.setCellStyle(style);
|
87 |
titleCell.setCellStyle(style);
|
| 84 |
|
88 |
|
| 85 |
userSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
|
89 |
userSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
|
| 86 |
|
90 |
|
| 87 |
userSheet.createRow(userSerialNo++);
|
- |
|
| 88 |
|
- |
|
| 89 |
Row headerRow = userSheet.createRow(userSerialNo++);
|
91 |
Row headerRow = userSheet.createRow(userSerialNo++);
|
| 90 |
headerRow.createCell(0).setCellValue("User Id");
|
92 |
headerRow.createCell(0).setCellValue("User Id");
|
| 91 |
headerRow.createCell(1).setCellValue("Email");
|
93 |
headerRow.createCell(1).setCellValue("Email");
|
| 92 |
headerRow.createCell(2).setCellValue("Name");
|
94 |
headerRow.createCell(2).setCellValue("Name");
|
| 93 |
headerRow.createCell(3).setCellValue("Communication Email");
|
95 |
headerRow.createCell(3).setCellValue("Communication Email");
|
| 94 |
headerRow.createCell(4).setCellValue("Date of Birth");
|
96 |
headerRow.createCell(4).setCellValue("Date of Birth");
|
| 95 |
headerRow.createCell(5).setCellValue("Sex");
|
97 |
headerRow.createCell(5).setCellValue("Sex");
|
| 96 |
headerRow.createCell(6).setCellValue("Mobile");
|
98 |
headerRow.createCell(6).setCellValue("Mobile");
|
| 97 |
headerRow.createCell(7).setCellValue("Default Address");
|
99 |
headerRow.createCell(7).setCellValue("Registered On");
|
| - |
|
100 |
headerRow.createCell(8).setCellValue("Last Login");
|
| 98 |
|
101 |
|
| 99 |
int addrColWidth = 40;
|
- |
|
| 100 |
userSheet.setColumnWidth(7, 256 * addrColWidth); // set width of address column to 40 characters
|
- |
|
| 101 |
|
- |
|
| 102 |
Calendar calendar = Calendar.getInstance();
|
102 |
Calendar calendar = Calendar.getInstance();
|
| 103 |
Row contentRow;
|
103 |
Row contentRow;
|
| 104 |
float defaultRowHeight = userSheet.getDefaultRowHeightInPoints();
|
104 |
float defaultRowHeight = userSheet.getDefaultRowHeightInPoints();
|
| - |
|
105 |
UserState uState;
|
| - |
|
106 |
DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
| 105 |
for (User u : users) {
|
107 |
for (User u : users) {
|
| 106 |
userSerialNo++;
|
108 |
userSerialNo++;
|
| 107 |
contentRow = userSheet.createRow(userSerialNo);
|
109 |
contentRow = userSheet.createRow(userSerialNo);
|
| 108 |
contentRow.createCell(0).setCellValue(u.getUserId());
|
110 |
contentRow.createCell(0).setCellValue(u.getUserId());
|
| 109 |
contentRow.createCell(1).setCellValue(u.getEmail());
|
111 |
contentRow.createCell(1).setCellValue(u.getEmail());
|
| Line 112... |
Line 114... |
| 112 |
contentRow.createCell(4).setCellValue(u.getDateOfBirth());
|
114 |
contentRow.createCell(4).setCellValue(u.getDateOfBirth());
|
| 113 |
// calendar.setTimeInMillis
|
115 |
// calendar.setTimeInMillis
|
| 114 |
contentRow.createCell(5).setCellValue(u.getSex().name());
|
116 |
contentRow.createCell(5).setCellValue(u.getSex().name());
|
| 115 |
contentRow.createCell(6).setCellValue(u.getMobileNumber());
|
117 |
contentRow.createCell(6).setCellValue(u.getMobileNumber());
|
| 116 |
|
118 |
|
| - |
|
119 |
try {
|
| - |
|
120 |
uState = uClient.getUserState(u.getUserId());
|
| - |
|
121 |
calendar.setTimeInMillis(uState.getActiveSince());
|
| - |
|
122 |
contentRow.createCell(7).setCellValue(formatter.format(calendar.getTime()));
|
| - |
|
123 |
calendar.setTimeInMillis(uState.getLastLogin());
|
| - |
|
124 |
contentRow.createCell(8).setCellValue(formatter.format(calendar.getTime()));
|
| - |
|
125 |
} catch (UserContextException e) {
|
| - |
|
126 |
e.printStackTrace();
|
| - |
|
127 |
} catch (TException e) {
|
| - |
|
128 |
e.printStackTrace();
|
| - |
|
129 |
}
|
| - |
|
130 |
|
| 117 |
List<Address> addresses = u.getAddresses();
|
131 |
List<Address> addresses = u.getAddresses();
|
| 118 |
if(addresses == null || addresses.isEmpty()) {
|
132 |
if(addresses == null || addresses.isEmpty()) {
|
| 119 |
continue;
|
133 |
continue;
|
| 120 |
}
|
134 |
}
|
| 121 |
int i = 0, col, defaultAddrCol = 7, maxAddrLength = 0, len;
|
135 |
int i = 0, col, defaultAddrCol = 9, maxAddrLength = 0, len, addrColWidth = 40;
|
| 122 |
String addressString;
|
136 |
String addressString;
|
| 123 |
for(Address a : addresses) {
|
137 |
for(Address a : addresses) {
|
| 124 |
if(a.getId() == u.getDefaultAddressId()) {
|
138 |
if(a.getId() == u.getDefaultAddressId()) {
|
| 125 |
col = defaultAddrCol;
|
139 |
col = defaultAddrCol;
|
| - |
|
140 |
headerRow.createCell(col).setCellValue("Default Address");
|
| 126 |
} else {
|
141 |
} else {
|
| 127 |
i++;
|
142 |
i++;
|
| 128 |
col = defaultAddrCol + i;
|
143 |
col = defaultAddrCol + i;
|
| 129 |
headerRow.createCell(col).setCellValue("Address " + i);
|
144 |
headerRow.createCell(col).setCellValue("Address " + i);
|
| 130 |
}
|
145 |
}
|
| 131 |
userSheet.setColumnWidth(col, addrColWidth * 256);
|
146 |
userSheet.setColumnWidth(col, addrColWidth * 256); // set width of address column to 40 characters
|
| 132 |
addressString = generateAddressString(a);
|
147 |
addressString = generateAddressString(a);
|
| 133 |
contentRow.createCell(col).setCellValue(addressString);
|
148 |
contentRow.createCell(col).setCellValue(addressString);
|
| 134 |
contentRow.getCell(col).setCellStyle(styleWT);
|
149 |
contentRow.getCell(col).setCellStyle(styleWT);
|
| 135 |
len = addressString.length();
|
150 |
len = addressString.length();
|
| 136 |
if(len > maxAddrLength)
|
151 |
if(len > maxAddrLength)
|
| 137 |
maxAddrLength = len;
|
152 |
maxAddrLength = len;
|
| 138 |
}
|
153 |
}
|
| 139 |
contentRow.setHeightInPoints((maxAddrLength / addrColWidth + 1) * defaultRowHeight); // Setting Row Height
|
154 |
contentRow.setHeightInPoints((maxAddrLength / addrColWidth + 1) * defaultRowHeight); // Setting Row Height
|
| 140 |
}
|
155 |
}
|
| 141 |
for (int i = 0; i <= 6; i++) {
|
156 |
for (int i = 0; i <= 8; i++) {
|
| 142 |
userSheet.autoSizeColumn(i);
|
157 |
userSheet.autoSizeColumn(i);
|
| 143 |
}
|
158 |
}
|
| 144 |
|
159 |
|
| 145 |
// Write the workbook to the output stream
|
160 |
// Write the workbook to the output stream
|
| 146 |
try {
|
161 |
try {
|