| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.util;
|
1 |
package com.spice.profitmandi.common.util;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.common.model.*;
|
4 |
import com.spice.profitmandi.common.model.*;
|
| - |
|
5 |
import com.spice.profitmandi.dao.model.PasswordOverrideRow;
|
| 5 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
6 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 6 |
import org.apache.logging.log4j.LogManager;
|
7 |
import org.apache.logging.log4j.LogManager;
|
| 7 |
import org.apache.logging.log4j.Logger;
|
8 |
import org.apache.logging.log4j.Logger;
|
| 8 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
9 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
| 9 |
import org.apache.poi.ss.usermodel.*;
|
10 |
import org.apache.poi.ss.usermodel.*;
|
| Line 59... |
Line 60... |
| 59 |
public static void main(String[] args) throws Throwable {
|
60 |
public static void main(String[] args) throws Throwable {
|
| 60 |
// List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
|
61 |
// List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
|
| 61 |
// writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
|
62 |
// writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
|
| 62 |
}
|
63 |
}
|
| 63 |
|
64 |
|
| - |
|
65 |
// Dev/staging password-override bulk sheet: Type | Id | Identifier | Password
|
| - |
|
66 |
public static void writePasswordOverrides(List<PasswordOverrideRow> rows, OutputStream outputStream)
|
| - |
|
67 |
throws IOException {
|
| - |
|
68 |
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
| - |
|
69 |
SXSSFSheet sheet = workbook.createSheet("PasswordOverrides");
|
| - |
|
70 |
String[] headers = {"Type", "Id", "Identifier", "Password"};
|
| - |
|
71 |
Row header = sheet.createRow(0);
|
| - |
|
72 |
for (int c = 0; c < headers.length; c++) {
|
| - |
|
73 |
header.createCell(c).setCellValue(headers[c]);
|
| - |
|
74 |
}
|
| - |
|
75 |
int rowIndex = 1;
|
| - |
|
76 |
for (PasswordOverrideRow r : rows) {
|
| - |
|
77 |
Row row = sheet.createRow(rowIndex++);
|
| - |
|
78 |
row.createCell(0).setCellValue(r.getType());
|
| - |
|
79 |
row.createCell(1).setCellValue("PARTNER".equalsIgnoreCase(r.getType()) ? r.getRetailerId() : r.getAuthUserId());
|
| - |
|
80 |
row.createCell(2).setCellValue(r.getIdentifier() == null ? "" : r.getIdentifier());
|
| - |
|
81 |
row.createCell(3).setCellValue(r.getCleartextPassword() == null ? "" : r.getCleartextPassword());
|
| - |
|
82 |
}
|
| - |
|
83 |
workbook.write(outputStream);
|
| - |
|
84 |
workbook.dispose();
|
| - |
|
85 |
}
|
| - |
|
86 |
|
| - |
|
87 |
public static List<PasswordOverrideRow> parsePasswordOverrides(InputStream inputStream) throws Exception {
|
| - |
|
88 |
List<PasswordOverrideRow> result = new ArrayList<>();
|
| - |
|
89 |
XSSFWorkbook workBook = new XSSFWorkbook(inputStream);
|
| - |
|
90 |
try {
|
| - |
|
91 |
workBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| - |
|
92 |
XSSFSheet sheet = workBook.getSheetAt(0);
|
| - |
|
93 |
for (int rowNumber = 1; rowNumber <= sheet.getLastRowNum(); rowNumber++) {
|
| - |
|
94 |
XSSFRow row = sheet.getRow(rowNumber);
|
| - |
|
95 |
if (row == null) {
|
| - |
|
96 |
continue;
|
| - |
|
97 |
}
|
| - |
|
98 |
String type = cellString(row.getCell(0));
|
| - |
|
99 |
String idStr = cellString(row.getCell(1));
|
| - |
|
100 |
String identifier = cellString(row.getCell(2));
|
| - |
|
101 |
String password = cellString(row.getCell(3));
|
| - |
|
102 |
if ((type == null || type.trim().isEmpty()) && (idStr == null || idStr.trim().isEmpty())
|
| - |
|
103 |
&& (identifier == null || identifier.trim().isEmpty())
|
| - |
|
104 |
&& (password == null || password.trim().isEmpty())) {
|
| - |
|
105 |
continue; // skip fully blank rows
|
| - |
|
106 |
}
|
| - |
|
107 |
PasswordOverrideRow r = new PasswordOverrideRow();
|
| - |
|
108 |
r.setType(type == null ? "" : type.trim());
|
| - |
|
109 |
int id = 0;
|
| - |
|
110 |
if (idStr != null && !idStr.trim().isEmpty()) {
|
| - |
|
111 |
id = (int) Double.parseDouble(idStr.trim());
|
| - |
|
112 |
}
|
| - |
|
113 |
if ("PARTNER".equalsIgnoreCase(r.getType())) {
|
| - |
|
114 |
r.setRetailerId(id);
|
| - |
|
115 |
} else {
|
| - |
|
116 |
r.setAuthUserId(id);
|
| - |
|
117 |
}
|
| - |
|
118 |
r.setIdentifier(identifier == null ? "" : identifier.trim());
|
| - |
|
119 |
r.setCleartextPassword(password == null ? "" : password.trim());
|
| - |
|
120 |
result.add(r);
|
| - |
|
121 |
}
|
| - |
|
122 |
} finally {
|
| - |
|
123 |
workBook.close();
|
| - |
|
124 |
}
|
| - |
|
125 |
return result;
|
| - |
|
126 |
}
|
| - |
|
127 |
|
| - |
|
128 |
private static String cellString(Cell cell) {
|
| - |
|
129 |
if (cell == null) {
|
| - |
|
130 |
return null;
|
| - |
|
131 |
}
|
| - |
|
132 |
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
|
| - |
|
133 |
double d = cell.getNumericCellValue();
|
| - |
|
134 |
if (d == Math.floor(d) && !Double.isInfinite(d)) {
|
| - |
|
135 |
return String.valueOf((long) d);
|
| - |
|
136 |
}
|
| - |
|
137 |
return String.valueOf(d);
|
| - |
|
138 |
}
|
| - |
|
139 |
return cell.toString();
|
| - |
|
140 |
}
|
| - |
|
141 |
|
| 64 |
public static List<TagListingModel> parse(InputStream inputStream) throws Exception {
|
142 |
public static List<TagListingModel> parse(InputStream inputStream) throws Exception {
|
| 65 |
|
143 |
|
| 66 |
List<TagListingModel> tagListings = new ArrayList<>();
|
144 |
List<TagListingModel> tagListings = new ArrayList<>();
|
| 67 |
XSSFWorkbook myWorkBook = null;
|
145 |
XSSFWorkbook myWorkBook = null;
|
| 68 |
try {
|
146 |
try {
|