| Line 17... |
Line 17... |
| 17 |
import in.shop2020.ui.util.SpecialPageJSONConvertor;
|
17 |
import in.shop2020.ui.util.SpecialPageJSONConvertor;
|
| 18 |
import in.shop2020.utils.GmailUtils;
|
18 |
import in.shop2020.utils.GmailUtils;
|
| 19 |
|
19 |
|
| 20 |
import java.io.File;
|
20 |
import java.io.File;
|
| 21 |
import java.io.IOException;
|
21 |
import java.io.IOException;
|
| - |
|
22 |
import java.text.SimpleDateFormat;
|
| 22 |
import java.util.ArrayList;
|
23 |
import java.util.ArrayList;
|
| 23 |
import java.util.Calendar;
|
24 |
import java.util.Calendar;
|
| 24 |
import java.util.Date;
|
25 |
import java.util.Date;
|
| 25 |
import java.util.HashMap;
|
26 |
import java.util.HashMap;
|
| 26 |
import java.util.LinkedHashMap;
|
27 |
import java.util.LinkedHashMap;
|
| Line 41... |
Line 42... |
| 41 |
public class ContentGenerationUtility {
|
42 |
public class ContentGenerationUtility {
|
| 42 |
private static final String UPDATE_TYPE_CATALOG = "CATALOG";
|
43 |
private static final String UPDATE_TYPE_CATALOG = "CATALOG";
|
| 43 |
|
44 |
|
| 44 |
private static final String UPDATE_TYPE_CONTENT = "CONTENT";
|
45 |
private static final String UPDATE_TYPE_CONTENT = "CONTENT";
|
| 45 |
|
46 |
|
| 46 |
private static final String COMMAND_LINE = "java ContentGenerationUtility.class -t { ALL | INCREMENTAL | ONE } -u { CONTENT | CATALOG } -e {EntityId} ";
|
47 |
private static final String COMMAND_LINE = "java ContentGenerationUtility.class -t { ALL | INCREMENTAL | ONE } -s { yyyy-MM-dd-HH-mm-ss } -u { CONTENT | CATALOG } -e {EntityId} ";
|
| 47 |
|
48 |
|
| 48 |
private static Log log = LogFactory
|
49 |
private static Log log = LogFactory
|
| 49 |
.getLog(ContentGenerationUtility.class);
|
50 |
.getLog(ContentGenerationUtility.class);
|
| 50 |
|
51 |
|
| 51 |
// Commandline options
|
52 |
// Commandline options
|
| Line 54... |
Line 55... |
| 54 |
private static final String GENERATION_TYPE_ALL = "ALL";
|
55 |
private static final String GENERATION_TYPE_ALL = "ALL";
|
| 55 |
private static final String GENERATION_TYPE_ONE = "ONE";
|
56 |
private static final String GENERATION_TYPE_ONE = "ONE";
|
| 56 |
private static final String UPDATE_TYPE_OPTION = "u";
|
57 |
private static final String UPDATE_TYPE_OPTION = "u";
|
| 57 |
private static final String GENERATION_TYPE_OPTION = "t";
|
58 |
private static final String GENERATION_TYPE_OPTION = "t";
|
| 58 |
private static final String ENTITY_ID_OPTION = "e";
|
59 |
private static final String ENTITY_ID_OPTION = "e";
|
| - |
|
60 |
private static final String TIMESTAMP_OPTION = "s";
|
| 59 |
|
61 |
|
| 60 |
// Default values of cmdline options
|
62 |
// Default values of cmdline options
|
| 61 |
private static String UPDATE_TYPE = UPDATE_TYPE_CONTENT;
|
63 |
private static String UPDATE_TYPE = UPDATE_TYPE_CONTENT;
|
| 62 |
private static String GENERATION_TYPE = GENERATION_TYPE_INCREMENTAL;
|
64 |
private static String GENERATION_TYPE = GENERATION_TYPE_INCREMENTAL;
|
| 63 |
private static String ENTITY_ID = "ALL";
|
65 |
private static String ENTITY_ID = "ALL";
|
| 64 |
|
66 |
|
| - |
|
67 |
private Date timeStamp = null;
|
| 65 |
private CommandLine cmd = null;
|
68 |
private CommandLine cmd = null;
|
| 66 |
private Map<Long, List<Item>> entityIdItemMap = new LinkedHashMap<Long, List<Item>>();
|
69 |
private Map<Long, List<Item>> entityIdItemMap = new LinkedHashMap<Long, List<Item>>();
|
| 67 |
private Long lastGenerationTime = 0l;
|
70 |
private Long lastGenerationTime = 0l;
|
| 68 |
private Map<Long, Entity> entities;
|
71 |
private Map<Long, Entity> entities;
|
| - |
|
72 |
private Map<Long, Entity> dbg_entities;
|
| 69 |
private List<Item> items;
|
73 |
private List<Item> items;
|
| 70 |
private List<Source> sources;
|
74 |
private List<Source> sources;
|
| 71 |
private CatalogClient csc;
|
75 |
private CatalogClient csc;
|
| 72 |
private Client client;
|
76 |
private Client client;
|
| 73 |
|
77 |
|
| Line 78... |
Line 82... |
| 78 |
options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
|
82 |
options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
|
| 79 |
options.addOption(UPDATE_TYPE_OPTION, true, "Default is : "
|
83 |
options.addOption(UPDATE_TYPE_OPTION, true, "Default is : "
|
| 80 |
+ UPDATE_TYPE);
|
84 |
+ UPDATE_TYPE);
|
| 81 |
options.addOption(ENTITY_ID_OPTION, true, "all entities " + ENTITY_ID
|
85 |
options.addOption(ENTITY_ID_OPTION, true, "all entities " + ENTITY_ID
|
| 82 |
+ " by default");
|
86 |
+ " by default");
|
| - |
|
87 |
options.addOption(TIMESTAMP_OPTION, true, "Manual timestamp");
|
| - |
|
88 |
|
| 83 |
}
|
89 |
}
|
| 84 |
|
90 |
|
| 85 |
public ContentGenerationUtility() throws Exception {
|
91 |
public ContentGenerationUtility() throws Exception {
|
| 86 |
csc = new CatalogClient();
|
92 |
csc = new CatalogClient();
|
| 87 |
client = csc.getClient();
|
93 |
client = csc.getClient();
|
| Line 124... |
Line 130... |
| 124 |
.hasOption(UPDATE_TYPE_OPTION))) {
|
130 |
.hasOption(UPDATE_TYPE_OPTION))) {
|
| 125 |
HelpFormatter formatter = new HelpFormatter();
|
131 |
HelpFormatter formatter = new HelpFormatter();
|
| 126 |
formatter.printHelp(COMMAND_LINE, options);
|
132 |
formatter.printHelp(COMMAND_LINE, options);
|
| 127 |
System.exit(1);
|
133 |
System.exit(1);
|
| 128 |
}
|
134 |
}
|
| - |
|
135 |
|
| 129 |
|
136 |
|
| 130 |
GENERATION_TYPE = cmd.getOptionValue(GENERATION_TYPE_OPTION);
|
137 |
GENERATION_TYPE = cmd.getOptionValue(GENERATION_TYPE_OPTION);
|
| - |
|
138 |
|
| 131 |
UPDATE_TYPE = cmd.getOptionValue(UPDATE_TYPE_OPTION);
|
139 |
UPDATE_TYPE = cmd.getOptionValue(UPDATE_TYPE_OPTION);
|
| 132 |
|
140 |
|
| 133 |
// Look for optional args.
|
141 |
// Look for optional args.
|
| 134 |
if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
|
142 |
if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
|
| 135 |
if (cmd.hasOption(ENTITY_ID_OPTION)) {
|
143 |
if (cmd.hasOption(ENTITY_ID_OPTION)) {
|
| Line 138... |
Line 146... |
| 138 |
HelpFormatter formatter = new HelpFormatter();
|
146 |
HelpFormatter formatter = new HelpFormatter();
|
| 139 |
formatter.printHelp(COMMAND_LINE, options);
|
147 |
formatter.printHelp(COMMAND_LINE, options);
|
| 140 |
System.exit(1);
|
148 |
System.exit(1);
|
| 141 |
}
|
149 |
}
|
| 142 |
}
|
150 |
}
|
| - |
|
151 |
|
| - |
|
152 |
if (GENERATION_TYPE_INCREMENTAL.equals(GENERATION_TYPE))
|
| - |
|
153 |
if (cmd.hasOption(TIMESTAMP_OPTION)) {
|
| - |
|
154 |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
| - |
|
155 |
try {
|
| - |
|
156 |
timeStamp = df.parse(cmd.getOptionValue(TIMESTAMP_OPTION));
|
| - |
|
157 |
} catch(Exception e) {
|
| - |
|
158 |
HelpFormatter formatter = new HelpFormatter();
|
| - |
|
159 |
formatter.printHelp(COMMAND_LINE, options);
|
| - |
|
160 |
System.exit(1);
|
| - |
|
161 |
}
|
| - |
|
162 |
}
|
| 143 |
}
|
163 |
}
|
| 144 |
|
164 |
|
| 145 |
/**
|
165 |
/**
|
| 146 |
* Call method based on arguments
|
166 |
* Call method based on arguments
|
| 147 |
*
|
167 |
*
|
| Line 168... |
Line 188... |
| 168 |
} catch (Exception e) {
|
188 |
} catch (Exception e) {
|
| 169 |
log.error("Error updating prices", e);
|
189 |
log.error("Error updating prices", e);
|
| 170 |
}
|
190 |
}
|
| 171 |
}
|
191 |
}
|
| 172 |
|
192 |
|
| 173 |
GmailUtils gm = new GmailUtils();
|
193 |
// GmailUtils gm = new GmailUtils();
|
| 174 |
String[] sendTo = { "chandranshu.s@shop2020.in",
|
194 |
// String[] sendTo = { "chandranshu.s@shop2020.in",
|
| 175 |
"rajveer.singh@shop2020.in", "mandeep.dhir@shop2020.in" };
|
195 |
// "rajveer.singh@shop2020.in", "mandeep.dhir@shop2020.in" };
|
| 176 |
|
196 |
//
|
| 177 |
try {
|
197 |
// try {
|
| 178 |
gm.sendSSLMessage(sendTo, "Content Generation Successful ? : "
|
198 |
// gm.sendSSLMessage(sendTo, "Content Generation Successful ? : "
|
| 179 |
+ isSuccess, "Content generation completed at time : "
|
199 |
// + isSuccess, "Content generation completed at time : "
|
| 180 |
+ Calendar.getInstance().getTime().toString(),
|
200 |
// + Calendar.getInstance().getTime().toString(),
|
| 181 |
"build@shop2020.in", "shop2020", logfile);
|
201 |
// "build@shop2020.in", "shop2020", logfile);
|
| 182 |
} catch (MessagingException e) {
|
202 |
// } catch (MessagingException e) {
|
| 183 |
log.error("Could not send status mail", e);
|
203 |
// log.error("Could not send status mail", e);
|
| 184 |
}
|
204 |
// }
|
| 185 |
}
|
205 |
}
|
| 186 |
|
206 |
|
| 187 |
public boolean cleanDir(File dir, boolean deleteSelf) {
|
207 |
public boolean cleanDir(File dir, boolean deleteSelf) {
|
| 188 |
if (dir.isDirectory()) {
|
208 |
if (dir.isDirectory()) {
|
| 189 |
String[] children = dir.list();
|
209 |
String[] children = dir.list();
|
| Line 315... |
Line 335... |
| 315 |
if (GENERATION_TYPE.equals(GENERATION_TYPE_ALL)) {
|
335 |
if (GENERATION_TYPE.equals(GENERATION_TYPE_ALL)) {
|
| 316 |
entities = CreationUtils.getEntities();
|
336 |
entities = CreationUtils.getEntities();
|
| 317 |
lastGenerationTime = new Long(0);
|
337 |
lastGenerationTime = new Long(0);
|
| 318 |
} else if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
|
338 |
} else if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
|
| 319 |
entities = new HashMap<Long, Entity>();
|
339 |
entities = new HashMap<Long, Entity>();
|
| - |
|
340 |
dbg_entities = CreationUtils.getEntities();
|
| 320 |
entities.put(Long.parseLong(ENTITY_ID),
|
341 |
entities.put(Long.parseLong(ENTITY_ID),
|
| 321 |
CreationUtils.getEntity(Long.parseLong(ENTITY_ID)));
|
342 |
CreationUtils.getEntity(Long.parseLong(ENTITY_ID)));
|
| 322 |
lastGenerationTime = new Long(0);
|
343 |
lastGenerationTime = new Long(0);
|
| 323 |
} else {
|
344 |
} else {
|
| 324 |
entities = CreationUtils.getEntities();
|
345 |
entities = CreationUtils.getEntities();
|
| - |
|
346 |
// When we read lastGenerationTime from database
|
| - |
|
347 |
// then only we should mark the
|
| - |
|
348 |
// current time as newLastGenerationTime
|
| - |
|
349 |
if(timeStamp == null) {
|
| 325 |
newLastGenerationTime = new Date().getTime();
|
350 |
newLastGenerationTime = new Date().getTime();
|
| 326 |
lastGenerationTime = CreationUtils.getLastContentGenerationTime();
|
351 |
lastGenerationTime = CreationUtils.getLastContentGenerationTime();
|
| - |
|
352 |
} else {
|
| - |
|
353 |
lastGenerationTime = timeStamp.getTime();
|
| - |
|
354 |
}
|
| - |
|
355 |
|
| 327 |
log.info("lastGenerationTime: " + lastGenerationTime);
|
356 |
log.info("lastGenerationTime: " + lastGenerationTime);
|
| 328 |
if (lastGenerationTime == null) {
|
357 |
if (lastGenerationTime == null) {
|
| 329 |
lastGenerationTime = new Long(0);
|
358 |
lastGenerationTime = new Long(0);
|
| 330 |
}
|
359 |
}
|
| 331 |
}
|
360 |
}
|
| 332 |
|
361 |
|
| 333 |
// Filter invalid entities here
|
362 |
// Filter invalid entities here
|
| 334 |
List<Entity> validEntities = new ArrayList<Entity>();
|
363 |
List<Entity> validEntities = new ArrayList<Entity>();
|
| 335 |
for (long entityID : entities.keySet()) {
|
364 |
for (long entityID : entities.keySet()) {
|
| 336 |
if (isValidEntity(entities.get(entityID))) {
|
365 |
if (isValidEntity(entities.get(entityID))) {
|