| 22 |
naveen |
1 |
package in.shop2020.ui.util;
|
|
|
2 |
|
| 109 |
naveen |
3 |
import in.shop2020.metamodel.core.Bullet;
|
|
|
4 |
import in.shop2020.metamodel.core.Entity;
|
| 1357 |
rajveer |
5 |
import in.shop2020.metamodel.core.EntityState;
|
|
|
6 |
import in.shop2020.metamodel.core.EntityStatus;
|
| 109 |
naveen |
7 |
import in.shop2020.metamodel.core.Feature;
|
|
|
8 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
| 1949 |
rajveer |
9 |
import in.shop2020.metamodel.definitions.CMPBucketDefinition;
|
| 109 |
naveen |
10 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
11 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 1153 |
rajveer |
12 |
|
| 110 |
naveen |
13 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
| 512 |
rajveer |
14 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 457 |
rajveer |
15 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 109 |
naveen |
16 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 457 |
rajveer |
17 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 109 |
naveen |
18 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
| 1357 |
rajveer |
19 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
| 451 |
rajveer |
20 |
import in.shop2020.model.v1.catalog.Item;
|
| 512 |
rajveer |
21 |
import in.shop2020.model.v1.catalog.status;
|
| 451 |
rajveer |
22 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
| 109 |
naveen |
23 |
import in.shop2020.util.Utils;
|
|
|
24 |
|
| 1165 |
rajveer |
25 |
import java.awt.Graphics2D;
|
|
|
26 |
import java.awt.geom.AffineTransform;
|
|
|
27 |
import java.awt.image.BufferedImage;
|
| 1420 |
rajveer |
28 |
import java.io.BufferedReader;
|
| 22 |
naveen |
29 |
import java.io.BufferedWriter;
|
| 1420 |
rajveer |
30 |
import java.io.DataInputStream;
|
|
|
31 |
import java.io.DataOutputStream;
|
| 22 |
naveen |
32 |
import java.io.File;
|
| 1165 |
rajveer |
33 |
import java.io.FileInputStream;
|
| 1834 |
chandransh |
34 |
import java.io.FileNotFoundException;
|
| 22 |
naveen |
35 |
import java.io.FileOutputStream;
|
| 1420 |
rajveer |
36 |
import java.io.FileReader;
|
|
|
37 |
import java.io.FileWriter;
|
| 451 |
rajveer |
38 |
import java.io.IOException;
|
| 1165 |
rajveer |
39 |
import java.io.InputStream;
|
| 1420 |
rajveer |
40 |
import java.io.InputStreamReader;
|
| 1165 |
rajveer |
41 |
import java.io.OutputStream;
|
| 22 |
naveen |
42 |
import java.io.OutputStreamWriter;
|
| 451 |
rajveer |
43 |
import java.io.StringWriter;
|
| 1949 |
rajveer |
44 |
import java.text.DecimalFormat;
|
| 108 |
naveen |
45 |
import java.util.ArrayList;
|
| 110 |
naveen |
46 |
import java.util.Collection;
|
| 897 |
rajveer |
47 |
import java.util.Date;
|
| 451 |
rajveer |
48 |
import java.util.HashMap;
|
| 110 |
naveen |
49 |
import java.util.LinkedHashMap;
|
| 108 |
naveen |
50 |
import java.util.List;
|
| 110 |
naveen |
51 |
import java.util.Map;
|
| 22 |
naveen |
52 |
|
| 1165 |
rajveer |
53 |
import javax.imageio.ImageIO;
|
|
|
54 |
|
| 45 |
naveen |
55 |
import org.apache.commons.lang.StringUtils;
|
| 22 |
naveen |
56 |
import org.apache.velocity.Template;
|
|
|
57 |
import org.apache.velocity.VelocityContext;
|
|
|
58 |
import org.apache.velocity.app.Velocity;
|
| 451 |
rajveer |
59 |
import org.apache.velocity.exception.MethodInvocationException;
|
|
|
60 |
import org.apache.velocity.exception.ParseErrorException;
|
|
|
61 |
import org.apache.velocity.exception.ResourceNotFoundException;
|
| 22 |
naveen |
62 |
|
|
|
63 |
/**
|
| 1357 |
rajveer |
64 |
* utility class to generated all html stuff from java objects
|
|
|
65 |
* Driver class to merge Java data objects with VTL script.
|
| 49 |
naveen |
66 |
*
|
| 1357 |
rajveer |
67 |
* @author rajveer
|
| 22 |
naveen |
68 |
*
|
|
|
69 |
*/
|
|
|
70 |
public class VUI {
|
| 1357 |
rajveer |
71 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
72 |
Client client = null;
|
| 1420 |
rajveer |
73 |
String lastContentVersion;
|
|
|
74 |
String contentVersion;
|
| 1584 |
chandransh |
75 |
|
|
|
76 |
StringBuffer problems = new StringBuffer();
|
|
|
77 |
|
| 1443 |
rajveer |
78 |
public VUI(Long contentVersion) throws Exception {
|
| 1357 |
rajveer |
79 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
80 |
client = catalogServiceClient.getClient();
|
| 1443 |
rajveer |
81 |
this.lastContentVersion = contentVersion.toString();
|
| 1420 |
rajveer |
82 |
this.contentVersion = (new Date()).getTime() +"" ;
|
| 1357 |
rajveer |
83 |
}
|
|
|
84 |
|
|
|
85 |
|
| 22 |
naveen |
86 |
/**
|
| 1357 |
rajveer |
87 |
* Usage: VUI [entities | entity] [Entity ID] {Template file name}
|
| 49 |
naveen |
88 |
*
|
| 22 |
naveen |
89 |
* @param args
|
|
|
90 |
*/
|
|
|
91 |
public static void main(String[] args) throws Exception {
|
| 163 |
naveen |
92 |
|
| 1474 |
rajveer |
93 |
String[] commands = new String[] {"entity", "entities", "entitiesall"};
|
| 1357 |
rajveer |
94 |
String[] datatypes = new String[] {"Entity ID"};
|
| 45 |
naveen |
95 |
|
| 1357 |
rajveer |
96 |
String usage = "Usage: VUI ["+ StringUtils.join(commands, "|") +"] ["+ StringUtils.join(datatypes, "|") + "] ";
|
| 22 |
naveen |
97 |
|
| 512 |
rajveer |
98 |
if(args.length < 1) {
|
| 45 |
naveen |
99 |
System.out.println(usage);
|
|
|
100 |
System.exit(-1);
|
|
|
101 |
}
|
|
|
102 |
String inputCommand = args[0];
|
| 512 |
rajveer |
103 |
String inputID = null;
|
|
|
104 |
if(args.length == 2){
|
|
|
105 |
inputID = args[1];
|
|
|
106 |
}
|
| 22 |
naveen |
107 |
|
| 1443 |
rajveer |
108 |
Long lastGenerationTime = CreationUtils.getLastContentGenerationTime();
|
|
|
109 |
if(lastGenerationTime==null){
|
|
|
110 |
lastGenerationTime = new Long(0);
|
|
|
111 |
}
|
| 1420 |
rajveer |
112 |
|
| 1474 |
rajveer |
113 |
//If non incremental content needs to be generated
|
| 1584 |
chandransh |
114 |
if(inputCommand.equals("entitiesall") || inputCommand.equals("entity")) {
|
| 1474 |
rajveer |
115 |
lastGenerationTime = new Long(0);
|
|
|
116 |
}
|
|
|
117 |
|
| 1443 |
rajveer |
118 |
VUI vui = new VUI(lastGenerationTime);
|
| 109 |
naveen |
119 |
|
| 638 |
rajveer |
120 |
long catalogId = 0;
|
| 1357 |
rajveer |
121 |
if(inputCommand.equals("entity")) {
|
| 109 |
naveen |
122 |
try {
|
| 638 |
rajveer |
123 |
catalogId = Long.parseLong(inputID);
|
| 1589 |
rajveer |
124 |
vui.generateHtmlForOneEntity(CreationUtils.getEntity(catalogId), "saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
|
|
|
125 |
vui.generateHtmlForOneEntity(CreationUtils.getEntity(catalogId), "shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020);
|
| 1671 |
vikas |
126 |
vui.generateHtmlForOneEntity(CreationUtils.getEntity(catalogId), "localhost:8090", Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
|
| 109 |
naveen |
127 |
}
|
|
|
128 |
catch (NumberFormatException nfe) {
|
|
|
129 |
System.out.println("Invalid ID - " + inputID);
|
|
|
130 |
System.exit(-1);
|
|
|
131 |
}
|
| 45 |
naveen |
132 |
}
|
| 1357 |
rajveer |
133 |
|
| 1474 |
rajveer |
134 |
if(inputCommand.equals("entities") || inputCommand.equals("entitiesall")) {
|
| 1589 |
rajveer |
135 |
vui.generateHtmlForAllEntities("saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
|
|
|
136 |
vui.generateHtmlForAllEntities("shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020);
|
| 1671 |
vikas |
137 |
vui.generateHtmlForAllEntities("localhost:8090", Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
|
| 1357 |
rajveer |
138 |
}
|
| 22 |
naveen |
139 |
|
| 1420 |
rajveer |
140 |
|
| 1165 |
rajveer |
141 |
Velocity.init("src/main/java/in/shop2020/ui/util/velocity.properties");
|
| 1357 |
rajveer |
142 |
|
| 1443 |
rajveer |
143 |
CreationUtils.storeLastContentGenerationTime((new Date()).getTime());
|
| 1420 |
rajveer |
144 |
|
| 1357 |
rajveer |
145 |
}
|
| 45 |
naveen |
146 |
|
| 1606 |
chandransh |
147 |
/**
|
|
|
148 |
* Generates content for the specified entity embedding links to the
|
|
|
149 |
* specified domain name.
|
|
|
150 |
*
|
|
|
151 |
* The method updates the member variable problems in any of the following
|
|
|
152 |
* four cases:
|
|
|
153 |
* <ol>
|
|
|
154 |
* <li>The entity is not ready.
|
|
|
155 |
* <li>The category has not been updated yet. (Set to -1).
|
|
|
156 |
* <li>There are no items in the catalog corresponding to this entity.
|
|
|
157 |
* <li>There are no active or content-complete items in the catalog
|
|
|
158 |
* corresponding to this entity.
|
|
|
159 |
* <li>Neither the items have been updated nor the content has been updated.
|
|
|
160 |
* </ol>
|
|
|
161 |
*
|
|
|
162 |
* @param entity
|
|
|
163 |
* - Entity for which the content has to be generated.
|
|
|
164 |
* @param domain
|
|
|
165 |
* - The domain name to be used to serve static content.
|
|
|
166 |
* @param exportPath
|
|
|
167 |
* - Local file system path where content has to be generated.
|
|
|
168 |
* @return -True if content is generated successfully, False otherwise.
|
|
|
169 |
* @throws Exception
|
|
|
170 |
*/
|
| 1584 |
chandransh |
171 |
private boolean generateHtmlForOneEntity(Entity entity, String domain, String exportPath) throws Exception{
|
| 1589 |
rajveer |
172 |
String mediaPath = Utils.EXPORT_MEDIA_PATH + entity.getID();
|
|
|
173 |
|
| 1357 |
rajveer |
174 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
175 |
EntityState state = CreationUtils.getEntityState(entity.getID());
|
| 1445 |
rajveer |
176 |
long categoryID = expEntity.getCategoryID();
|
|
|
177 |
|
| 1357 |
rajveer |
178 |
if(state.getStatus() != EntityStatus.READY){
|
| 1362 |
rajveer |
179 |
problems.append(expEntity.getID() + ":" + "Entity Not Ready\n");
|
| 1589 |
rajveer |
180 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
| 1357 |
rajveer |
181 |
return false;
|
| 22 |
naveen |
182 |
}
|
| 1420 |
rajveer |
183 |
|
| 1445 |
rajveer |
184 |
if(categoryID == -1){
|
|
|
185 |
problems.append(expEntity.getID() + ":" + "Category is -1\n");
|
| 1589 |
rajveer |
186 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
| 1445 |
rajveer |
187 |
return false;
|
|
|
188 |
}
|
| 22 |
naveen |
189 |
|
| 1357 |
rajveer |
190 |
long catalogId = expEntity.getID();
|
|
|
191 |
String templateFile;
|
| 1589 |
rajveer |
192 |
|
| 1357 |
rajveer |
193 |
List<Item> items = client.getItemsByCatalogId(entity.getID());
|
|
|
194 |
if(items == null){
|
| 1362 |
rajveer |
195 |
problems.append(expEntity.getID() + ":" + "No item in Catalog\n");
|
| 1589 |
rajveer |
196 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
| 1357 |
rajveer |
197 |
return false;
|
| 108 |
naveen |
198 |
}
|
| 1357 |
rajveer |
199 |
|
|
|
200 |
Date todate = new Date();
|
|
|
201 |
Boolean hasActiveItem = false;
|
| 1443 |
rajveer |
202 |
Boolean hasItemUpdated = false;
|
| 1357 |
rajveer |
203 |
List<Item> activeItems = new ArrayList<Item>();
|
|
|
204 |
for(Item item: items){
|
| 2037 |
rajveer |
205 |
if((item.getItemStatus() == status.ACTIVE || item.getItemStatus()== status.CONTENT_COMPLETE || item.getItemStatus() == status.PAUSED)){
|
| 1412 |
rajveer |
206 |
if(todate.getTime() > item.getStartDate()){
|
|
|
207 |
hasActiveItem = true;
|
|
|
208 |
activeItems.add(item);
|
|
|
209 |
}
|
| 1443 |
rajveer |
210 |
if(item.getUpdatedOn() > Long.parseLong(this.lastContentVersion)){
|
|
|
211 |
hasItemUpdated = true;
|
|
|
212 |
}
|
| 109 |
naveen |
213 |
}
|
| 1443 |
rajveer |
214 |
|
| 109 |
naveen |
215 |
}
|
| 1357 |
rajveer |
216 |
if(!hasActiveItem){
|
| 1362 |
rajveer |
217 |
problems.append(expEntity.getID() + ":" + "No Active Item in Catalog\n");
|
| 1589 |
rajveer |
218 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
| 1357 |
rajveer |
219 |
return false;
|
|
|
220 |
}
|
|
|
221 |
|
| 1443 |
rajveer |
222 |
//Either item has been updated in catalog or item is marked as ready after last content generation
|
|
|
223 |
if(!(state.getMerkedReadyOn().getTime() > Long.parseLong(this.lastContentVersion) || hasItemUpdated)){
|
|
|
224 |
problems.append(expEntity.getID() + ":" + "Content already generated\n");
|
|
|
225 |
return false;
|
|
|
226 |
}
|
|
|
227 |
|
| 1589 |
rajveer |
228 |
//Delete old resources, because we will copy new data
|
|
|
229 |
deleteOldResources(mediaPath, exportPath + entity.getID());
|
|
|
230 |
|
|
|
231 |
//Create new directory
|
|
|
232 |
File exportFile = new File(exportPath + catalogId);
|
|
|
233 |
if(!exportFile.exists()) {
|
|
|
234 |
exportFile.mkdir();
|
|
|
235 |
}
|
| 1606 |
chandransh |
236 |
|
|
|
237 |
// This URL is used to ensure that images such as icon and thumbnail for
|
|
|
238 |
// a particular entity are always downloaded from the same location.
|
| 1401 |
rajveer |
239 |
String staticurl = "http://static" + entity.getID()%3 + "." + domain;
|
|
|
240 |
|
| 1357 |
rajveer |
241 |
templateFile= Utils.VTL_SRC_PATH + "product_summary.vm";
|
| 1412 |
rajveer |
242 |
getProductSummaryHtml(expEntity, activeItems, templateFile, exportPath);
|
| 1357 |
rajveer |
243 |
|
|
|
244 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
|
| 1412 |
rajveer |
245 |
getEntityWidgetSnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
| 1357 |
rajveer |
246 |
|
|
|
247 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
|
| 1412 |
rajveer |
248 |
getEntityHomeSnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
| 1357 |
rajveer |
249 |
|
|
|
250 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
|
| 1412 |
rajveer |
251 |
getEntitySearchSnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
| 1357 |
rajveer |
252 |
|
|
|
253 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_categorypage.vm";
|
| 1412 |
rajveer |
254 |
getEntityCategorySnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
| 1357 |
rajveer |
255 |
|
|
|
256 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
|
| 1401 |
rajveer |
257 |
getEntitySlideGuideHtml(expEntity, templateFile, domain, exportPath);
|
| 1779 |
rajveer |
258 |
|
|
|
259 |
|
| 1669 |
varun.gupt |
260 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_phones_i_own.vm";
|
|
|
261 |
getEntityPhonesIOwnSnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
|
|
262 |
|
| 1949 |
rajveer |
263 |
if(expEntity.getCategory().getParentCategory().getID() == 10001){
|
|
|
264 |
|
|
|
265 |
templateFile= Utils.VTL_SRC_PATH + "slideguide_for_comparison.vm";
|
|
|
266 |
getEntitySnippetForComparison(expEntity, templateFile, domain, exportPath);
|
|
|
267 |
|
|
|
268 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage.vm";
|
|
|
269 |
getEntityCompareSnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
|
|
270 |
|
|
|
271 |
templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage_summary.vm";
|
|
|
272 |
getEntityCompareSummarySnippetHtml(expEntity, activeItems, templateFile, staticurl, exportPath);
|
|
|
273 |
|
|
|
274 |
getSlidenamesSnippet(expEntity, exportPath);
|
|
|
275 |
}
|
| 1779 |
rajveer |
276 |
|
| 1401 |
rajveer |
277 |
getEntityTitleSnippetHtml(expEntity, exportPath);
|
| 1357 |
rajveer |
278 |
|
| 1401 |
rajveer |
279 |
getEntityMetaDescriptionSnippetHtml(expEntity, exportPath);
|
| 1357 |
rajveer |
280 |
|
| 1401 |
rajveer |
281 |
getEntityMetaKeywordSnippetHtml(expEntity, exportPath);
|
| 1357 |
rajveer |
282 |
|
| 1700 |
rajveer |
283 |
generateImages(expEntity.getID(), getImagePrefix(expEntity));
|
| 1357 |
rajveer |
284 |
|
| 1606 |
chandransh |
285 |
// Mark content-complete items as active after the content has been
|
|
|
286 |
// generated
|
| 1357 |
rajveer |
287 |
for(Item item: activeItems){
|
|
|
288 |
if(item.getItemStatus() == status.CONTENT_COMPLETE){
|
|
|
289 |
item.setItemStatus(status.ACTIVE);
|
| 2037 |
rajveer |
290 |
item.setStatus_description("This item is active");
|
| 1357 |
rajveer |
291 |
client.updateItem(item);
|
| 45 |
naveen |
292 |
}
|
|
|
293 |
}
|
| 1357 |
rajveer |
294 |
return true;
|
| 22 |
naveen |
295 |
}
|
| 1357 |
rajveer |
296 |
|
| 1401 |
rajveer |
297 |
private boolean generateHtmlForAllEntities(String domain, String exportPath) throws Exception{
|
| 1357 |
rajveer |
298 |
Map<Long, Entity> entities = CreationUtils.getEntities();
|
|
|
299 |
for(Entity entity: entities.values()){
|
| 1584 |
chandransh |
300 |
generateHtmlForOneEntity(entity, domain, exportPath);
|
| 1357 |
rajveer |
301 |
}
|
| 1362 |
rajveer |
302 |
System.out.println(problems);
|
| 1357 |
rajveer |
303 |
return true;
|
|
|
304 |
}
|
| 110 |
naveen |
305 |
|
| 1357 |
rajveer |
306 |
|
|
|
307 |
|
| 1420 |
rajveer |
308 |
public boolean deleteDir(File dir) {
|
|
|
309 |
if (dir.isDirectory()) {
|
|
|
310 |
String[] children = dir.list();
|
|
|
311 |
for (int i=0; i<children.length; i++) {
|
|
|
312 |
boolean success = deleteDir(new File(dir, children[i]));
|
|
|
313 |
if (!success) {
|
|
|
314 |
return false;
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
// The directory is now empty so delete it
|
|
|
320 |
return dir.delete();
|
|
|
321 |
}
|
|
|
322 |
|
| 1589 |
rajveer |
323 |
private void deleteOldResources(String mediaPath, String contentPath) {
|
|
|
324 |
File f = new File(contentPath);
|
| 1420 |
rajveer |
325 |
if(f.exists()){
|
|
|
326 |
deleteDir(f);
|
|
|
327 |
}
|
|
|
328 |
|
| 1589 |
rajveer |
329 |
f = new File(mediaPath);
|
| 1420 |
rajveer |
330 |
if(f.exists()){
|
|
|
331 |
deleteDir(f);
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
|
| 1357 |
rajveer |
336 |
public void scale(String src, int width, int height, String dest) throws IOException {
|
| 1165 |
rajveer |
337 |
BufferedImage bsrc = ImageIO.read(new File(src));
|
|
|
338 |
int newHeight = height;
|
|
|
339 |
int newWidth = width;
|
|
|
340 |
if((double)width/bsrc.getWidth() > (double)height/bsrc.getHeight()){
|
|
|
341 |
newWidth = bsrc.getWidth()*height/bsrc.getHeight();
|
|
|
342 |
}else{
|
|
|
343 |
newHeight = bsrc.getHeight()*width/bsrc.getHeight();
|
|
|
344 |
}
|
|
|
345 |
BufferedImage bdest = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
|
|
|
346 |
Graphics2D g = bdest.createGraphics();
|
|
|
347 |
System.out.println(newWidth + ":" + newHeight + (double)width/bsrc.getWidth() + ":"+ (double)height/bsrc.getHeight());
|
|
|
348 |
AffineTransform at = AffineTransform.getScaleInstance((double)newWidth/bsrc.getWidth(), (double)newHeight/bsrc.getHeight());
|
|
|
349 |
g.drawRenderedImage(bsrc,at);
|
|
|
350 |
ImageIO.write(bdest,"JPG",new File(dest));
|
|
|
351 |
}
|
| 457 |
rajveer |
352 |
|
| 1165 |
rajveer |
353 |
|
| 1700 |
rajveer |
354 |
private void generateImages(long catalogId, String imagePrefix) throws IOException {
|
| 1834 |
chandransh |
355 |
String globalImageDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator;
|
|
|
356 |
String globalDefaultImagePath = globalImageDirPath + "default.jpg";
|
|
|
357 |
|
| 1584 |
chandransh |
358 |
String imageDirPath = globalImageDirPath + catalogId + File.separator;
|
| 1834 |
chandransh |
359 |
String defaultImagePath = imageDirPath + "default.jpg";
|
|
|
360 |
|
| 1584 |
chandransh |
361 |
/*
|
|
|
362 |
* Create the directory for this entity if it didn't exist.
|
|
|
363 |
*/
|
|
|
364 |
File f = new File(globalImageDirPath + catalogId);
|
| 1834 |
chandransh |
365 |
if (!f.exists()) {
|
| 1165 |
rajveer |
366 |
f.mkdir();
|
|
|
367 |
}
|
| 1584 |
chandransh |
368 |
|
|
|
369 |
/*
|
| 1834 |
chandransh |
370 |
* If the default image is not present for this entity, copy the global
|
|
|
371 |
* default image.
|
| 1584 |
chandransh |
372 |
* TODO: This part will be moved to the Jython Script
|
|
|
373 |
*/
|
| 1165 |
rajveer |
374 |
File f3 = new File(defaultImagePath);
|
| 1834 |
chandransh |
375 |
if (!f3.exists()) {
|
| 1949 |
rajveer |
376 |
copyFile(globalDefaultImagePath, defaultImagePath);
|
|
|
377 |
}
|
| 1834 |
chandransh |
378 |
|
|
|
379 |
String exportPath = Utils.EXPORT_MEDIA_PATH + catalogId;
|
| 1584 |
chandransh |
380 |
/*
|
| 1834 |
chandransh |
381 |
* Copying the generated content from db/media to export/media. This
|
|
|
382 |
* will also insert a timestamp tag in the file names.
|
| 1584 |
chandransh |
383 |
*/
|
|
|
384 |
File sourceFile = new File(globalImageDirPath + catalogId);
|
| 1834 |
chandransh |
385 |
File destinationFile = new File(exportPath);
|
| 1700 |
rajveer |
386 |
copyDirectory(sourceFile, destinationFile, imagePrefix);
|
| 1584 |
chandransh |
387 |
|
| 1815 |
varun.gupt |
388 |
/*
|
| 1834 |
chandransh |
389 |
* Copy the thumbnail and the icon files. This is required so that we can display the
|
|
|
390 |
* thumbnail on the cart page and icon on the facebook.
|
| 1815 |
varun.gupt |
391 |
*/
|
| 1949 |
rajveer |
392 |
copyFile(imageDirPath + "thumbnail.jpg", exportPath + File.separator + "thumbnail.jpg");
|
|
|
393 |
copyFile(imageDirPath + "icon.jpg", exportPath + File.separator + "icon.jpg");
|
|
|
394 |
}
|
| 1165 |
rajveer |
395 |
|
| 1834 |
chandransh |
396 |
/**
|
|
|
397 |
* Copies the contents of the input file into the output file. Creates the
|
|
|
398 |
* output file if it doesn't exist already.
|
|
|
399 |
*
|
|
|
400 |
* @param inputFile
|
|
|
401 |
* File to be copied.
|
|
|
402 |
* @param outputFile
|
|
|
403 |
* File to be created.
|
|
|
404 |
* @throws IOException
|
|
|
405 |
*/
|
|
|
406 |
private void copyFile(String inputFile, String outputFile) throws IOException {
|
|
|
407 |
File sourceFile = new File(inputFile);
|
|
|
408 |
File destinationFile = new File(outputFile);
|
| 1165 |
rajveer |
409 |
|
| 1834 |
chandransh |
410 |
if (!destinationFile.exists())
|
|
|
411 |
destinationFile.createNewFile();
|
|
|
412 |
|
|
|
413 |
InputStream in = new FileInputStream(sourceFile);
|
|
|
414 |
OutputStream out = new FileOutputStream(destinationFile);
|
|
|
415 |
// Copy the bits from instream to outstream
|
|
|
416 |
byte[] buf = new byte[1024];
|
|
|
417 |
int len;
|
|
|
418 |
while ((len = in.read(buf)) > 0) {
|
|
|
419 |
out.write(buf, 0, len);
|
|
|
420 |
}
|
|
|
421 |
in.close();
|
|
|
422 |
out.close();
|
|
|
423 |
}
|
|
|
424 |
|
| 1420 |
rajveer |
425 |
// If targetLocation does not exist, it will be created.
|
| 1700 |
rajveer |
426 |
public void copyDirectory(File sourceLocation , File targetLocation, String imagePrefix) throws IOException {
|
| 1420 |
rajveer |
427 |
|
|
|
428 |
if (sourceLocation.isDirectory()) {
|
|
|
429 |
if (!targetLocation.exists()) {
|
|
|
430 |
targetLocation.mkdir();
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
String[] children = sourceLocation.list();
|
|
|
434 |
for (int i=0; i<children.length; i++) {
|
| 1700 |
rajveer |
435 |
copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]), imagePrefix);
|
| 1420 |
rajveer |
436 |
}
|
|
|
437 |
} else {
|
|
|
438 |
InputStream in = new FileInputStream(sourceLocation);
|
| 1700 |
rajveer |
439 |
|
|
|
440 |
String fileName = targetLocation.getName().split("\\.")[0];
|
|
|
441 |
String fileExt = targetLocation.getName().split("\\.")[1];
|
|
|
442 |
String newFileName = targetLocation.getParent() + File.separator + imagePrefix + "-" + fileName + "-" + this.contentVersion + "." + fileExt;
|
| 1165 |
rajveer |
443 |
|
| 1420 |
rajveer |
444 |
|
|
|
445 |
//String fileName = targetLocation
|
|
|
446 |
OutputStream out = new FileOutputStream(newFileName);
|
|
|
447 |
|
|
|
448 |
// Copy the bits from instream to outstream
|
|
|
449 |
byte[] buf = new byte[1024];
|
|
|
450 |
int len;
|
|
|
451 |
while ((len = in.read(buf)) > 0) {
|
|
|
452 |
out.write(buf, 0, len);
|
|
|
453 |
}
|
|
|
454 |
in.close();
|
|
|
455 |
out.close();
|
|
|
456 |
}
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
|
| 1401 |
rajveer |
460 |
private void getEntityMetaDescriptionSnippetHtml(ExpandedEntity expEntity, String exportPath) {
|
| 1357 |
rajveer |
461 |
long catalogId = expEntity.getID();
|
| 975 |
vikas |
462 |
try {
|
| 1153 |
rajveer |
463 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 975 |
vikas |
464 |
String description = "Best Price " + expEntity.getBrand() + " " + expEntity.getModelName()
|
| 988 |
vikas |
465 |
+ " " + expEntity.getModelNumber() + " ";
|
| 979 |
vikas |
466 |
|
|
|
467 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
468 |
description += expEntity.getCategory().getLabel() + " in India.";
|
|
|
469 |
}
|
|
|
470 |
else {
|
|
|
471 |
description += ".";
|
|
|
472 |
}
|
|
|
473 |
description += " Experience n' buy online. FREE Next Day delivery."
|
| 975 |
vikas |
474 |
+ " Original product - Full manufacturer warranty. Comprehensive reviews.";
|
| 979 |
vikas |
475 |
|
| 975 |
vikas |
476 |
description = description.replaceAll("--", "-");
|
| 1401 |
rajveer |
477 |
String exportFileName = exportPath + catalogId + File.separator + "MetaDescriptionSnippet.html";
|
| 975 |
vikas |
478 |
File exportFile = new File(exportFileName);
|
|
|
479 |
if(!exportFile.exists()) {
|
|
|
480 |
exportFile.createNewFile();
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
BufferedWriter writer = new BufferedWriter(
|
|
|
484 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
485 |
|
|
|
486 |
writer.write(description);
|
|
|
487 |
|
|
|
488 |
writer.flush();
|
|
|
489 |
writer.close();
|
|
|
490 |
} catch (Exception e) {
|
|
|
491 |
e.printStackTrace();
|
|
|
492 |
}
|
|
|
493 |
}
|
|
|
494 |
|
| 1401 |
rajveer |
495 |
private void getEntityMetaKeywordSnippetHtml(ExpandedEntity expEntity, String exportPath) {
|
| 1357 |
rajveer |
496 |
long catalogId = expEntity.getID();
|
| 975 |
vikas |
497 |
try {
|
| 1153 |
rajveer |
498 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 2166 |
vikas |
499 |
String keywords;
|
|
|
500 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
501 |
keywords = expEntity.getBrand() + " " + expEntity.getModelName() + ", ";
|
|
|
502 |
if (expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
503 |
keywords += expEntity.getBrand() + " mobile phones, ";
|
|
|
504 |
}
|
|
|
505 |
if (expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
506 |
keywords += "phone accessories, ";
|
|
|
507 |
}
|
|
|
508 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " Price, ";
|
|
|
509 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " India, ";
|
|
|
510 |
if (expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
511 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " Review, ";
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
else {
|
|
|
515 |
keywords = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + ", ";
|
|
|
516 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
517 |
keywords += expEntity.getBrand() + " mobile phones, ";
|
|
|
518 |
}
|
|
|
519 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
520 |
keywords += "phone accessories, ";
|
|
|
521 |
}
|
|
|
522 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " Price, ";
|
|
|
523 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " India, ";
|
|
|
524 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
525 |
keywords += expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber() + " Review, ";
|
|
|
526 |
}
|
| 975 |
vikas |
527 |
}
|
|
|
528 |
|
| 1401 |
rajveer |
529 |
String exportFileName = exportPath + catalogId + File.separator + "MetaKeywordsSnippet.html";
|
| 975 |
vikas |
530 |
File exportFile = new File(exportFileName);
|
|
|
531 |
if(!exportFile.exists()) {
|
|
|
532 |
exportFile.createNewFile();
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
BufferedWriter writer = new BufferedWriter(
|
|
|
536 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
537 |
|
|
|
538 |
writer.write(keywords);
|
|
|
539 |
|
|
|
540 |
writer.flush();
|
|
|
541 |
writer.close();
|
|
|
542 |
} catch (Exception e) {
|
|
|
543 |
e.printStackTrace();
|
|
|
544 |
}
|
|
|
545 |
}
|
| 1779 |
rajveer |
546 |
|
|
|
547 |
|
|
|
548 |
private void getSlidenamesSnippet(ExpandedEntity expEntity, String exportPath) throws ResourceNotFoundException, ParseErrorException, Exception{
|
|
|
549 |
long catalogId = expEntity.getID();
|
|
|
550 |
|
|
|
551 |
StringBuilder slideNames = new StringBuilder();
|
|
|
552 |
|
|
|
553 |
slideNames.append(expEntity.getBrand() + " " + expEntity.getModelNumber() + " " + expEntity.getModelName() + "\n");
|
|
|
554 |
|
| 1949 |
rajveer |
555 |
Map<Long, Double> slideScores = CreationUtils.getSlideComparisonScores(catalogId);
|
|
|
556 |
|
| 1779 |
rajveer |
557 |
for(ExpandedSlide expSlide: expEntity.getExpandedSlides()){
|
|
|
558 |
if(expSlide.getSlideDefinitionID() == 130054){
|
|
|
559 |
continue;
|
|
|
560 |
}
|
| 1949 |
rajveer |
561 |
slideNames.append(expSlide.getSlideDefinition().getLabel() + "!!!");
|
|
|
562 |
|
|
|
563 |
String bucketName = "None";
|
|
|
564 |
if(Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID()) != null){
|
|
|
565 |
bucketName = Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID());
|
|
|
566 |
}
|
|
|
567 |
slideNames.append(bucketName + "!!!");
|
|
|
568 |
|
|
|
569 |
double score = 0;
|
|
|
570 |
if(slideScores.get(expSlide.getSlideDefinitionID())!=null){
|
|
|
571 |
score = slideScores.get(expSlide.getSlideDefinitionID());
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
DecimalFormat oneDForm = new DecimalFormat("#.#");
|
|
|
575 |
score = Double.valueOf(oneDForm.format(score));
|
|
|
576 |
|
|
|
577 |
slideNames.append(score + "\n");
|
| 1779 |
rajveer |
578 |
}
|
| 975 |
vikas |
579 |
|
| 1779 |
rajveer |
580 |
String exportFileName = exportPath + catalogId + File.separator + "SlideNamesSnippet.html";
|
|
|
581 |
File exportFile = new File(exportFileName);
|
|
|
582 |
if(!exportFile.exists()) {
|
|
|
583 |
exportFile.createNewFile();
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
BufferedWriter writer = new BufferedWriter(
|
|
|
587 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
588 |
|
|
|
589 |
writer.write(slideNames.toString());
|
|
|
590 |
writer.flush();
|
|
|
591 |
writer.close();
|
|
|
592 |
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
|
|
|
596 |
private void getEntitySnippetForComparison(ExpandedEntity expEntity, String templateFile, String domain, String exportPath) throws Exception {
|
| 1357 |
rajveer |
597 |
long catalogId = expEntity.getID();
|
| 512 |
rajveer |
598 |
VelocityContext context = new VelocityContext();
|
| 1700 |
rajveer |
599 |
|
|
|
600 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
| 512 |
rajveer |
601 |
context.put("expentity", expEntity);
|
| 1401 |
rajveer |
602 |
context.put("domain", domain);
|
| 1420 |
rajveer |
603 |
context.put("contentVersion", this.contentVersion);
|
| 1700 |
rajveer |
604 |
|
| 512 |
rajveer |
605 |
String exportFileName = null;
|
|
|
606 |
|
|
|
607 |
Template template = Velocity.getTemplate(templateFile);
|
| 1779 |
rajveer |
608 |
exportFileName = exportPath + catalogId + File.separator + "ComparisonSnippet.html";
|
| 512 |
rajveer |
609 |
|
|
|
610 |
File exportFile = new File(exportFileName);
|
|
|
611 |
if(!exportFile.exists()) {
|
|
|
612 |
exportFile.createNewFile();
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
BufferedWriter writer = new BufferedWriter(
|
|
|
616 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
617 |
|
|
|
618 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
619 |
template.merge(context, writer);
|
|
|
620 |
|
|
|
621 |
writer.flush();
|
|
|
622 |
writer.close();
|
|
|
623 |
Utils.info("Export Complete!");
|
|
|
624 |
|
|
|
625 |
}
|
|
|
626 |
|
| 1779 |
rajveer |
627 |
private void getEntitySlideGuideHtml(ExpandedEntity expEntity, String templateFile, String domain, String exportPath) throws Exception {
|
|
|
628 |
long catalogId = expEntity.getID();
|
|
|
629 |
VelocityContext context = new VelocityContext();
|
|
|
630 |
|
|
|
631 |
context.put("imagePrefix", getImagePrefix(expEntity));
|
|
|
632 |
context.put("expentity", expEntity);
|
|
|
633 |
context.put("domain", domain);
|
|
|
634 |
context.put("contentVersion", this.contentVersion);
|
|
|
635 |
|
|
|
636 |
String exportFileName = null;
|
| 512 |
rajveer |
637 |
|
| 1779 |
rajveer |
638 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
639 |
exportFileName = exportPath + catalogId + File.separator + "SlideGuide.html";
|
|
|
640 |
|
|
|
641 |
File exportFile = new File(exportFileName);
|
|
|
642 |
if(!exportFile.exists()) {
|
|
|
643 |
exportFile.createNewFile();
|
|
|
644 |
}
|
|
|
645 |
|
|
|
646 |
BufferedWriter writer = new BufferedWriter(
|
|
|
647 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
648 |
|
|
|
649 |
//Template template = Velocity.getTemplate(templateFile);
|
|
|
650 |
template.merge(context, writer);
|
|
|
651 |
|
|
|
652 |
writer.flush();
|
|
|
653 |
writer.close();
|
|
|
654 |
Utils.info("Export Complete!");
|
|
|
655 |
|
|
|
656 |
}
|
|
|
657 |
|
| 451 |
rajveer |
658 |
|
|
|
659 |
/**
|
|
|
660 |
*
|
| 109 |
naveen |
661 |
* @param expEntity1
|
|
|
662 |
* @param expEntity2
|
| 110 |
naveen |
663 |
* @return
|
|
|
664 |
* @throws Exception
|
| 109 |
naveen |
665 |
*/
|
| 1357 |
rajveer |
666 |
private Collection<String[]> getMergedComparisonScores(
|
| 110 |
naveen |
667 |
ExpandedEntity expEntity1, ExpandedEntity expEntity2)
|
|
|
668 |
throws Exception {
|
|
|
669 |
DefinitionsContainer defs =
|
|
|
670 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
671 |
|
|
|
672 |
Map<String, String[]> mergedSlideScores =
|
|
|
673 |
new LinkedHashMap<String, String[]>();
|
|
|
674 |
|
| 1932 |
rajveer |
675 |
Map<Long, Double> cmpSlideScores1 = CreationUtils.getSlideComparisonScores(expEntity1.getID());
|
| 110 |
naveen |
676 |
|
|
|
677 |
for(Long slideID : cmpSlideScores1.keySet()) {
|
|
|
678 |
SlideDefinition slideDef = defs.getSlideDefinition(
|
|
|
679 |
slideID.longValue());
|
|
|
680 |
|
|
|
681 |
String slideLabel = slideDef.getLabel();
|
|
|
682 |
String[] details = new String[3];
|
|
|
683 |
|
|
|
684 |
details[0] = slideLabel;
|
|
|
685 |
|
| 1932 |
rajveer |
686 |
Double score = cmpSlideScores1.get(slideID);
|
| 110 |
naveen |
687 |
if(score != null) {
|
|
|
688 |
details[1] = score.toString();
|
|
|
689 |
}
|
|
|
690 |
else {
|
|
|
691 |
details[1] = "-1";
|
|
|
692 |
}
|
|
|
693 |
|
|
|
694 |
// To be determined in loop over 2nd entity's scores
|
|
|
695 |
details[2] = "-1";
|
|
|
696 |
|
|
|
697 |
mergedSlideScores.put(slideLabel, details);
|
|
|
698 |
}
|
|
|
699 |
|
| 1932 |
rajveer |
700 |
Map<Long, Double> cmpSlideScores2 = CreationUtils.getSlideComparisonScores(expEntity2.getID());
|
| 110 |
naveen |
701 |
|
|
|
702 |
for(Long slideID : cmpSlideScores2.keySet()) {
|
|
|
703 |
SlideDefinition slideDef = defs.getSlideDefinition(
|
|
|
704 |
slideID.longValue());
|
|
|
705 |
|
|
|
706 |
String slideLabel = slideDef.getLabel();
|
|
|
707 |
|
|
|
708 |
String[] details = null;
|
|
|
709 |
if(mergedSlideScores.containsKey(slideLabel)) {
|
|
|
710 |
details = mergedSlideScores.get(slideLabel);
|
|
|
711 |
}
|
|
|
712 |
else {
|
|
|
713 |
details = new String[3];
|
|
|
714 |
|
|
|
715 |
details[0] = slideLabel;
|
|
|
716 |
details[1] = "-1";
|
|
|
717 |
|
|
|
718 |
mergedSlideScores.put(slideLabel, details);
|
|
|
719 |
}
|
|
|
720 |
|
| 1932 |
rajveer |
721 |
Double score = cmpSlideScores2.get(slideID);
|
| 110 |
naveen |
722 |
if(score != null) {
|
|
|
723 |
details[2] = score.toString();
|
|
|
724 |
}
|
|
|
725 |
else {
|
|
|
726 |
details[2] = "-1";
|
|
|
727 |
}
|
|
|
728 |
}
|
|
|
729 |
|
|
|
730 |
return mergedSlideScores.values();
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
/**
|
|
|
734 |
*
|
|
|
735 |
* @param expEntity1
|
|
|
736 |
* @param expEntity2
|
|
|
737 |
*/
|
| 1357 |
rajveer |
738 |
private List<ExpandedSlide[]> getMergedSlides(
|
| 109 |
naveen |
739 |
ExpandedEntity expEntity1, ExpandedEntity expEntity2) {
|
|
|
740 |
List<ExpandedSlide[]> mergedSlides = new ArrayList<ExpandedSlide[]>();
|
|
|
741 |
|
|
|
742 |
List<ExpandedSlide> expSlidesEntity1 = expEntity1.getExpandedSlides();
|
|
|
743 |
|
|
|
744 |
for(ExpandedSlide expSlide1 : expSlidesEntity1) {
|
|
|
745 |
String slideLabel = expSlide1.getSlideDefinition().getLabel();
|
|
|
746 |
|
| 1153 |
rajveer |
747 |
ExpandedSlide expSlide2 = CreationUtils.getParentExpandedSlide(
|
| 109 |
naveen |
748 |
expEntity2, slideLabel);
|
|
|
749 |
|
|
|
750 |
if(expSlide2 != null) {
|
|
|
751 |
ExpandedSlide[] comparisonSlides = new ExpandedSlide[2];
|
|
|
752 |
comparisonSlides[0] = expSlide1;
|
|
|
753 |
comparisonSlides[1] = expSlide2;
|
|
|
754 |
|
|
|
755 |
mergedSlides.add(comparisonSlides);
|
|
|
756 |
}
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
return mergedSlides;
|
|
|
760 |
}
|
| 163 |
naveen |
761 |
|
| 1357 |
rajveer |
762 |
public void diffAll() throws Exception {
|
| 163 |
naveen |
763 |
long[] entityIDs = new long[] {
|
|
|
764 |
1000001,
|
|
|
765 |
1000002,
|
|
|
766 |
1000003,
|
|
|
767 |
1000004,
|
|
|
768 |
1000005,
|
|
|
769 |
1000006,
|
|
|
770 |
1000007,
|
|
|
771 |
1000008,
|
|
|
772 |
1000009,
|
|
|
773 |
1000010,
|
|
|
774 |
1000011,
|
|
|
775 |
1000012,
|
|
|
776 |
1000013,
|
|
|
777 |
1000014,
|
|
|
778 |
1000015
|
|
|
779 |
};
|
|
|
780 |
|
|
|
781 |
for(int i=0;i<entityIDs.length;i++) {
|
|
|
782 |
for(int j=0;j<entityIDs.length;j++) {
|
|
|
783 |
diff(entityIDs[i], entityIDs[j]);
|
|
|
784 |
}
|
|
|
785 |
}
|
|
|
786 |
}
|
|
|
787 |
|
| 1357 |
rajveer |
788 |
public void diff(long entityID1, long entityID2) throws Exception {
|
| 163 |
naveen |
789 |
// Setup
|
|
|
790 |
Velocity.init("src/in/shop2020/ui/util/velocity.properties");
|
|
|
791 |
VelocityContext context = new VelocityContext();
|
|
|
792 |
|
|
|
793 |
String templateFile = Utils.VTL_SRC_PATH + "jquery_diff_slideguide.vm";
|
|
|
794 |
|
|
|
795 |
Template template = null;
|
|
|
796 |
String exportFileName = null;
|
|
|
797 |
|
| 1153 |
rajveer |
798 |
ExpandedEntity expEntity1 = CreationUtils.getExpandedEntity(entityID1);
|
|
|
799 |
ExpandedEntity expEntity2 = CreationUtils.getExpandedEntity(entityID2);
|
| 163 |
naveen |
800 |
|
|
|
801 |
List<ExpandedSlide[]> mergedSlides =
|
|
|
802 |
getMergedSlides(expEntity1, expEntity2);
|
|
|
803 |
Utils.info("mergedSlides=" + mergedSlides);
|
|
|
804 |
|
|
|
805 |
Collection<String[]> mergedComparisonScores =
|
|
|
806 |
getMergedComparisonScores(expEntity1, expEntity2);
|
|
|
807 |
Utils.info("mergedComparisonScores=" + mergedComparisonScores);
|
|
|
808 |
|
| 1050 |
rajveer |
809 |
int scoreEntity1 = CreationUtils.getEntityComparisonScores(expEntity1.getID());
|
| 163 |
naveen |
810 |
|
| 1050 |
rajveer |
811 |
int scoreEntity2 = CreationUtils.getEntityComparisonScores(expEntity2.getID());
|
| 163 |
naveen |
812 |
|
|
|
813 |
context.put("expEntity1", expEntity1);
|
|
|
814 |
context.put("expEntity2", expEntity2);
|
|
|
815 |
context.put("mergedSlides", mergedSlides);
|
|
|
816 |
context.put("mergedComparisonScores", mergedComparisonScores);
|
|
|
817 |
context.put("scoreEntity1", scoreEntity1);
|
|
|
818 |
context.put("scoreEntity2", scoreEntity2);
|
|
|
819 |
|
|
|
820 |
template = Velocity.getTemplate(templateFile);
|
|
|
821 |
exportFileName = Utils.EXPORT_DIFF_PATH + entityID1 + "_" + entityID2 +
|
|
|
822 |
".html";
|
|
|
823 |
|
|
|
824 |
File exportFile = new File(exportFileName);
|
|
|
825 |
if(!exportFile.exists()) {
|
|
|
826 |
exportFile.createNewFile();
|
|
|
827 |
}
|
|
|
828 |
|
|
|
829 |
BufferedWriter writer = new BufferedWriter(
|
|
|
830 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
831 |
|
|
|
832 |
template.merge(context, writer);
|
|
|
833 |
|
|
|
834 |
writer.flush();
|
|
|
835 |
writer.close();
|
|
|
836 |
Utils.info("Export Complete!");
|
|
|
837 |
}
|
| 451 |
rajveer |
838 |
|
| 1401 |
rajveer |
839 |
public void getProductSummaryHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String exportPath) {
|
| 1357 |
rajveer |
840 |
long catalogId = expEntity.getID();
|
| 451 |
rajveer |
841 |
try {
|
| 638 |
rajveer |
842 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
843 |
for(Item item: items){
|
|
|
844 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
845 |
double sellingPrice = item.getSellingPrice();
|
|
|
846 |
double mrp = item.getMrp();
|
| 1451 |
vikas |
847 |
boolean showmrp = true;
|
|
|
848 |
if (mrp <= sellingPrice) {
|
|
|
849 |
showmrp = false;
|
|
|
850 |
}
|
| 1910 |
varun.gupt |
851 |
|
| 638 |
rajveer |
852 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
| 806 |
rajveer |
853 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
854 |
itemDetail.put("CATALOG_ID", ((int)item.getCatalogItemId())+"");
|
| 638 |
rajveer |
855 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
856 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
857 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
858 |
itemDetail.put("COLOR", item.getColor());
|
| 1451 |
vikas |
859 |
itemDetail.put("SHOWMRP", showmrp +"");
|
| 1910 |
varun.gupt |
860 |
itemDetail.put("IS_SELECTED", item.isDefaultForEntity() ? "SELECTED" : "");
|
| 638 |
rajveer |
861 |
itemDetails.add(itemDetail);
|
|
|
862 |
}
|
|
|
863 |
|
| 514 |
rajveer |
864 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 451 |
rajveer |
865 |
String categoryName = expEntity.getCategory().getLabel();
|
| 457 |
rajveer |
866 |
String tagline = "";
|
| 580 |
rajveer |
867 |
String warranty = "";
|
| 457 |
rajveer |
868 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
869 |
for(Feature feature: features){
|
|
|
870 |
if(feature.getFeatureDefinitionID() == 120084){
|
|
|
871 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
872 |
tagline = dataObject.getValue();
|
|
|
873 |
}
|
| 580 |
rajveer |
874 |
if(feature.getFeatureDefinitionID() == 120125){
|
|
|
875 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
876 |
ExpandedBullet expBullet =expFeature.getExpandedBullets().get(0);
|
|
|
877 |
if(expBullet != null){
|
|
|
878 |
warranty = expBullet.getValue() + " "+ expBullet.getUnit().getShortForm();
|
|
|
879 |
}
|
|
|
880 |
}
|
| 457 |
rajveer |
881 |
}
|
| 451 |
rajveer |
882 |
|
|
|
883 |
|
|
|
884 |
|
|
|
885 |
long categoryId = expEntity.getCategory().getID();
|
|
|
886 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
887 |
params.put("TITLE", title);
|
| 516 |
rajveer |
888 |
params.put("CATEGORY_ID", ((int)categoryId)+"");
|
| 451 |
rajveer |
889 |
params.put("CATEGORY_NAME", categoryName);
|
| 993 |
vikas |
890 |
params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
|
| 638 |
rajveer |
891 |
|
|
|
892 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
| 451 |
rajveer |
893 |
params.put("TAGLINE", tagline);
|
| 580 |
rajveer |
894 |
params.put("WARRANTY", warranty);
|
|
|
895 |
|
| 451 |
rajveer |
896 |
VelocityContext context = new VelocityContext();
|
| 512 |
rajveer |
897 |
|
| 638 |
rajveer |
898 |
context.put("itemDetails", itemDetails);
|
|
|
899 |
|
| 451 |
rajveer |
900 |
context.put("params", params);
|
|
|
901 |
|
| 1401 |
rajveer |
902 |
String exportFileName = exportPath + catalogId + File.separator + "ProductDetail.html";
|
| 451 |
rajveer |
903 |
|
|
|
904 |
File exportFile = new File(exportFileName);
|
|
|
905 |
if(!exportFile.exists()) {
|
|
|
906 |
exportFile.createNewFile();
|
|
|
907 |
}
|
|
|
908 |
|
| 1357 |
rajveer |
909 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile)));
|
| 451 |
rajveer |
910 |
|
|
|
911 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
912 |
template.merge(context, writer);
|
|
|
913 |
|
|
|
914 |
writer.flush();
|
|
|
915 |
writer.close();
|
|
|
916 |
Utils.info("Export Complete!");
|
|
|
917 |
|
|
|
918 |
} catch (Exception e) {
|
|
|
919 |
e.printStackTrace();
|
|
|
920 |
}
|
|
|
921 |
}
|
|
|
922 |
|
| 1637 |
rajveer |
923 |
private String getEntityURL(ExpandedEntity expEntity){
|
|
|
924 |
String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
|
|
|
925 |
String productUrl = expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
926 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
927 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
|
|
|
928 |
+ "-" + expEntity.getID();
|
|
|
929 |
productUrl = productUrl.replaceAll("/", "-");
|
|
|
930 |
url = url + productUrl;
|
|
|
931 |
url = url.replaceAll("--", "-");
|
|
|
932 |
return url;
|
|
|
933 |
}
|
|
|
934 |
|
| 1700 |
rajveer |
935 |
private String getImagePrefix(ExpandedEntity expEntity){
|
|
|
936 |
String imagePrefix = expEntity.getBrand().toLowerCase().replace(' ', '-')
|
|
|
937 |
+ "-" + expEntity.getModelName().toLowerCase().replace(' ', '-')
|
|
|
938 |
+ "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-');
|
|
|
939 |
imagePrefix = imagePrefix.replaceAll("/", "-");
|
|
|
940 |
imagePrefix = imagePrefix.replaceAll("--", "-");
|
|
|
941 |
return imagePrefix;
|
|
|
942 |
}
|
|
|
943 |
|
| 1401 |
rajveer |
944 |
private void getEntityWidgetSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
| 1357 |
rajveer |
945 |
long catalogId = expEntity.getID();
|
| 457 |
rajveer |
946 |
try {
|
| 1153 |
rajveer |
947 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 514 |
rajveer |
948 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
949 |
String prodName = title;
|
|
|
950 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
951 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
952 |
}
|
| 1700 |
rajveer |
953 |
String imagePrefix = getImagePrefix(expEntity);
|
| 1637 |
rajveer |
954 |
String url = getEntityURL(expEntity);
|
| 638 |
rajveer |
955 |
|
| 457 |
rajveer |
956 |
String tinySnippet = "";
|
|
|
957 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
958 |
for(Feature feature: features){
|
|
|
959 |
if(feature.getFeatureDefinitionID() == 120089){
|
|
|
960 |
PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
|
|
|
961 |
tinySnippet = dataObject.getValue();
|
|
|
962 |
}
|
|
|
963 |
}
|
| 638 |
rajveer |
964 |
|
|
|
965 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
966 |
|
|
|
967 |
Item minPriceItem = null;
|
|
|
968 |
for(Item item: items){
|
|
|
969 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
970 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
971 |
minPriceItem = item;
|
|
|
972 |
}
|
|
|
973 |
double sellingPrice = item.getSellingPrice();
|
|
|
974 |
double mrp = item.getMrp();
|
|
|
975 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
976 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
977 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
978 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
979 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
980 |
itemDetail.put("COLOR", item.getColor());
|
|
|
981 |
itemDetails.add(itemDetail);
|
|
|
982 |
}
|
|
|
983 |
|
| 1451 |
vikas |
984 |
boolean showmrp = true;
|
|
|
985 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
986 |
showmrp = false;
|
|
|
987 |
}
|
| 457 |
rajveer |
988 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
989 |
params.put("TITLE", title);
|
| 2166 |
vikas |
990 |
params.put("PROD_NAME", prodName);
|
| 975 |
vikas |
991 |
params.put("URL", url);
|
| 1700 |
rajveer |
992 |
params.put("IMAGE_PREFIX", imagePrefix);
|
| 638 |
rajveer |
993 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
994 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
| 1451 |
vikas |
995 |
params.put("SHOWMRP", showmrp +"");
|
| 638 |
rajveer |
996 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
997 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 457 |
rajveer |
998 |
params.put("TINY_SNIPPET", tinySnippet);
|
| 1401 |
rajveer |
999 |
params.put("staticurl", staticurl);
|
| 1420 |
rajveer |
1000 |
params.put("contentVersion", contentVersion);
|
| 457 |
rajveer |
1001 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
1002 |
context.put("itemDetails", itemDetails);
|
| 457 |
rajveer |
1003 |
context.put("params", params);
|
| 638 |
rajveer |
1004 |
|
| 1401 |
rajveer |
1005 |
String exportFileName = exportPath + catalogId + File.separator + "WidgetSnippet.html";
|
| 457 |
rajveer |
1006 |
File exportFile = new File(exportFileName);
|
|
|
1007 |
if(!exportFile.exists()) {
|
|
|
1008 |
exportFile.createNewFile();
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1012 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1013 |
|
|
|
1014 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1015 |
template.merge(context, writer);
|
|
|
1016 |
|
|
|
1017 |
writer.flush();
|
|
|
1018 |
writer.close();
|
|
|
1019 |
Utils.info("Export Complete!");
|
|
|
1020 |
|
|
|
1021 |
|
|
|
1022 |
} catch (Exception e) {
|
|
|
1023 |
e.printStackTrace();
|
|
|
1024 |
}
|
|
|
1025 |
}
|
| 1357 |
rajveer |
1026 |
|
|
|
1027 |
|
| 1401 |
rajveer |
1028 |
private void getEntityHomeSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
| 1357 |
rajveer |
1029 |
long catalogId = expEntity.getID();
|
|
|
1030 |
|
| 512 |
rajveer |
1031 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1032 |
|
|
|
1033 |
try {
|
| 1153 |
rajveer |
1034 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 514 |
rajveer |
1035 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
1036 |
String prodName = title;
|
|
|
1037 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1038 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1039 |
}
|
| 1637 |
rajveer |
1040 |
String url = getEntityURL(expEntity);
|
| 1700 |
rajveer |
1041 |
String imagePrefix = getImagePrefix(expEntity);
|
| 1637 |
rajveer |
1042 |
|
| 512 |
rajveer |
1043 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1044 |
client = catalogServiceClient.getClient();
|
| 638 |
rajveer |
1045 |
|
| 512 |
rajveer |
1046 |
String tinySnippet = "";
|
|
|
1047 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1048 |
for(Feature feature: features){
|
|
|
1049 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1050 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1051 |
int count = 1;
|
|
|
1052 |
for(Bullet bullet: bullets){
|
|
|
1053 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1054 |
tinySnippet = dataObject.getValue();
|
|
|
1055 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1056 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1057 |
}
|
|
|
1058 |
}
|
|
|
1059 |
}
|
|
|
1060 |
|
|
|
1061 |
|
| 516 |
rajveer |
1062 |
|
| 638 |
rajveer |
1063 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1064 |
|
| 897 |
rajveer |
1065 |
Item minPriceItem = null;
|
|
|
1066 |
|
| 638 |
rajveer |
1067 |
for(Item item: items){
|
|
|
1068 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1069 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1070 |
minPriceItem = item;
|
|
|
1071 |
}
|
|
|
1072 |
double sellingPrice = item.getSellingPrice();
|
|
|
1073 |
double mrp = item.getMrp();
|
|
|
1074 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1075 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1076 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1077 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1078 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1079 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1080 |
itemDetails.add(itemDetail);
|
|
|
1081 |
}
|
| 1451 |
vikas |
1082 |
boolean showmrp = true;
|
|
|
1083 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1084 |
showmrp = false;
|
|
|
1085 |
}
|
|
|
1086 |
|
| 512 |
rajveer |
1087 |
params.put("TITLE", title);
|
| 2166 |
vikas |
1088 |
params.put("PROD_NAME", prodName);
|
| 975 |
vikas |
1089 |
params.put("URL", url);
|
| 1700 |
rajveer |
1090 |
params.put("IMAGE_PREFIX", imagePrefix);
|
| 638 |
rajveer |
1091 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1092 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
| 1451 |
vikas |
1093 |
params.put("SHOWMRP", showmrp +"");
|
| 638 |
rajveer |
1094 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1095 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 1401 |
rajveer |
1096 |
params.put("staticurl", staticurl);
|
| 1420 |
rajveer |
1097 |
params.put("contentVersion", contentVersion);
|
| 512 |
rajveer |
1098 |
|
|
|
1099 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
1100 |
context.put("itemDetails", itemDetails);
|
| 512 |
rajveer |
1101 |
context.put("params", params);
|
| 1357 |
rajveer |
1102 |
|
| 512 |
rajveer |
1103 |
|
| 1401 |
rajveer |
1104 |
String exportFileName = exportPath + catalogId + File.separator + "HomeSnippet.html";
|
| 512 |
rajveer |
1105 |
File exportFile = new File(exportFileName);
|
|
|
1106 |
if(!exportFile.exists()) {
|
|
|
1107 |
exportFile.createNewFile();
|
|
|
1108 |
}
|
|
|
1109 |
|
|
|
1110 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1111 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1112 |
|
|
|
1113 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1114 |
template.merge(context, writer);
|
|
|
1115 |
|
|
|
1116 |
writer.flush();
|
|
|
1117 |
writer.close();
|
|
|
1118 |
Utils.info("Export Complete!");
|
|
|
1119 |
|
|
|
1120 |
} catch (Exception e) {
|
|
|
1121 |
e.printStackTrace();
|
|
|
1122 |
}
|
|
|
1123 |
}
|
| 457 |
rajveer |
1124 |
|
| 1401 |
rajveer |
1125 |
private void getEntityCategorySnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
| 532 |
rajveer |
1126 |
Map<String,String> params = new HashMap<String, String>();
|
| 1357 |
rajveer |
1127 |
long catalogId = expEntity.getID();
|
| 532 |
rajveer |
1128 |
|
|
|
1129 |
try {
|
| 1153 |
rajveer |
1130 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 532 |
rajveer |
1131 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
1132 |
String prodName = title;
|
|
|
1133 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1134 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1135 |
}
|
| 532 |
rajveer |
1136 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1137 |
client = catalogServiceClient.getClient();
|
| 1637 |
rajveer |
1138 |
String url = getEntityURL(expEntity);
|
| 1700 |
rajveer |
1139 |
String imagePrefix = getImagePrefix(expEntity);
|
| 1637 |
rajveer |
1140 |
|
| 532 |
rajveer |
1141 |
String tinySnippet = "";
|
|
|
1142 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1143 |
for(Feature feature: features){
|
|
|
1144 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1145 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1146 |
int count = 1;
|
|
|
1147 |
for(Bullet bullet: bullets){
|
|
|
1148 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1149 |
tinySnippet = dataObject.getValue();
|
|
|
1150 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1151 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1152 |
}
|
|
|
1153 |
}
|
|
|
1154 |
}
|
|
|
1155 |
|
| 638 |
rajveer |
1156 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
| 532 |
rajveer |
1157 |
|
| 897 |
rajveer |
1158 |
Item minPriceItem = null;
|
| 638 |
rajveer |
1159 |
for(Item item: items){
|
|
|
1160 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1161 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1162 |
minPriceItem = item;
|
|
|
1163 |
}
|
|
|
1164 |
double sellingPrice = item.getSellingPrice();
|
|
|
1165 |
double mrp = item.getMrp();
|
|
|
1166 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1167 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1168 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1169 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1170 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1171 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1172 |
itemDetails.add(itemDetail);
|
|
|
1173 |
}
|
| 1451 |
vikas |
1174 |
|
|
|
1175 |
boolean showmrp = true;
|
|
|
1176 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1177 |
showmrp = false;
|
|
|
1178 |
}
|
| 532 |
rajveer |
1179 |
params.put("TITLE", title);
|
| 2166 |
vikas |
1180 |
params.put("PROD_NAME", prodName);
|
| 975 |
vikas |
1181 |
params.put("URL", url);
|
| 1700 |
rajveer |
1182 |
params.put("IMAGE_PREFIX", imagePrefix);
|
| 638 |
rajveer |
1183 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1184 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
| 1451 |
vikas |
1185 |
params.put("SHOWMRP", showmrp +"");
|
| 638 |
rajveer |
1186 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1187 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 1401 |
rajveer |
1188 |
params.put("staticurl", staticurl);
|
| 1420 |
rajveer |
1189 |
params.put("contentVersion", contentVersion);
|
| 532 |
rajveer |
1190 |
|
|
|
1191 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
1192 |
context.put("itemDetails", itemDetails);
|
| 532 |
rajveer |
1193 |
context.put("params", params);
|
|
|
1194 |
|
| 1401 |
rajveer |
1195 |
String exportFileName = exportPath + catalogId + File.separator + "CategorySnippet.html";
|
| 532 |
rajveer |
1196 |
File exportFile = new File(exportFileName);
|
|
|
1197 |
if(!exportFile.exists()) {
|
|
|
1198 |
exportFile.createNewFile();
|
|
|
1199 |
}
|
|
|
1200 |
|
|
|
1201 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1202 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1203 |
|
|
|
1204 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1205 |
template.merge(context, writer);
|
|
|
1206 |
|
|
|
1207 |
writer.flush();
|
|
|
1208 |
writer.close();
|
|
|
1209 |
Utils.info("Export Complete!");
|
|
|
1210 |
|
|
|
1211 |
|
|
|
1212 |
} catch (Exception e) {
|
|
|
1213 |
e.printStackTrace();
|
|
|
1214 |
}
|
|
|
1215 |
}
|
|
|
1216 |
|
| 1401 |
rajveer |
1217 |
private void getEntityTitleSnippetHtml(ExpandedEntity expEntity, String exportPath) {
|
| 1357 |
rajveer |
1218 |
long catalogId = expEntity.getID();
|
|
|
1219 |
|
| 975 |
vikas |
1220 |
try {
|
| 1153 |
rajveer |
1221 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 2166 |
vikas |
1222 |
String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
|
|
|
1223 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1224 |
title = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1225 |
}
|
|
|
1226 |
|
| 979 |
vikas |
1227 |
if(expEntity.getCategory().getParentCategory().getID() == 10001) {
|
|
|
1228 |
title += " | " + expEntity.getBrand() + " Mobile Phones";
|
|
|
1229 |
}
|
|
|
1230 |
if(expEntity.getCategory().getParentCategory().getID() == 10011) {
|
|
|
1231 |
title += " " + expEntity.getCategory().getLabel()
|
|
|
1232 |
+ " | " + expEntity.getBrand() + " Mobile Phone Accessories";
|
|
|
1233 |
}
|
|
|
1234 |
title += " | Saholic.com";
|
| 975 |
vikas |
1235 |
|
| 1401 |
rajveer |
1236 |
String exportFileName = exportPath + catalogId + File.separator + "TitleSnippet.html";
|
| 975 |
vikas |
1237 |
File exportFile = new File(exportFileName);
|
|
|
1238 |
if(!exportFile.exists()) {
|
|
|
1239 |
exportFile.createNewFile();
|
|
|
1240 |
}
|
|
|
1241 |
|
|
|
1242 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1243 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1244 |
|
|
|
1245 |
writer.write(title);
|
|
|
1246 |
|
|
|
1247 |
writer.flush();
|
|
|
1248 |
writer.close();
|
|
|
1249 |
} catch (Exception e) {
|
|
|
1250 |
e.printStackTrace();
|
|
|
1251 |
}
|
|
|
1252 |
}
|
|
|
1253 |
|
| 532 |
rajveer |
1254 |
|
| 1401 |
rajveer |
1255 |
private void getEntitySearchSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
| 1357 |
rajveer |
1256 |
long catalogId = expEntity.getID();
|
| 516 |
rajveer |
1257 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1258 |
|
|
|
1259 |
try {
|
| 1153 |
rajveer |
1260 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
| 516 |
rajveer |
1261 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
1262 |
String prodName = title;
|
|
|
1263 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1264 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1265 |
}
|
| 1637 |
rajveer |
1266 |
String url = getEntityURL(expEntity);
|
| 1700 |
rajveer |
1267 |
String imagePrefix = getImagePrefix(expEntity);
|
| 1637 |
rajveer |
1268 |
|
| 516 |
rajveer |
1269 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1270 |
client = catalogServiceClient.getClient();
|
| 1357 |
rajveer |
1271 |
|
| 516 |
rajveer |
1272 |
String tinySnippet = "";
|
|
|
1273 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1274 |
for(Feature feature: features){
|
|
|
1275 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1276 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1277 |
int count = 1;
|
|
|
1278 |
for(Bullet bullet: bullets){
|
|
|
1279 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1280 |
tinySnippet = dataObject.getValue();
|
|
|
1281 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1282 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1283 |
}
|
|
|
1284 |
}
|
|
|
1285 |
}
|
|
|
1286 |
|
|
|
1287 |
|
| 638 |
rajveer |
1288 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
| 516 |
rajveer |
1289 |
|
| 897 |
rajveer |
1290 |
Item minPriceItem = null;
|
| 638 |
rajveer |
1291 |
for(Item item: items){
|
|
|
1292 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1293 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1294 |
minPriceItem = item;
|
|
|
1295 |
}
|
|
|
1296 |
double sellingPrice = item.getSellingPrice();
|
|
|
1297 |
double mrp = item.getMrp();
|
|
|
1298 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1299 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1300 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1301 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1302 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1303 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1304 |
itemDetails.add(itemDetail);
|
|
|
1305 |
}
|
| 1451 |
vikas |
1306 |
|
|
|
1307 |
boolean showmrp = true;
|
|
|
1308 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1309 |
showmrp = false;
|
|
|
1310 |
}
|
| 516 |
rajveer |
1311 |
params.put("TITLE", title);
|
| 2166 |
vikas |
1312 |
params.put("PROD_NAME", prodName);
|
| 975 |
vikas |
1313 |
params.put("URL", url);
|
| 1700 |
rajveer |
1314 |
params.put("IMAGE_PREFIX", imagePrefix);
|
| 638 |
rajveer |
1315 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1316 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
| 1451 |
vikas |
1317 |
params.put("SHOWMRP", showmrp +"");
|
| 638 |
rajveer |
1318 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1319 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
| 1401 |
rajveer |
1320 |
params.put("staticurl", staticurl);
|
| 1420 |
rajveer |
1321 |
params.put("contentVersion", contentVersion);
|
|
|
1322 |
|
| 516 |
rajveer |
1323 |
VelocityContext context = new VelocityContext();
|
| 638 |
rajveer |
1324 |
context.put("itemDetails", itemDetails);
|
| 516 |
rajveer |
1325 |
context.put("params", params);
|
|
|
1326 |
|
| 1401 |
rajveer |
1327 |
String exportFileName = exportPath + catalogId + File.separator + "SearchSnippet.html";
|
| 516 |
rajveer |
1328 |
File exportFile = new File(exportFileName);
|
|
|
1329 |
if(!exportFile.exists()) {
|
|
|
1330 |
exportFile.createNewFile();
|
|
|
1331 |
}
|
|
|
1332 |
|
|
|
1333 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1334 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1335 |
|
|
|
1336 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1337 |
template.merge(context, writer);
|
|
|
1338 |
|
|
|
1339 |
writer.flush();
|
|
|
1340 |
writer.close();
|
|
|
1341 |
Utils.info("Export Complete!");
|
|
|
1342 |
|
|
|
1343 |
|
|
|
1344 |
} catch (Exception e) {
|
|
|
1345 |
e.printStackTrace();
|
|
|
1346 |
}
|
|
|
1347 |
}
|
| 1779 |
rajveer |
1348 |
|
| 516 |
rajveer |
1349 |
|
| 1949 |
rajveer |
1350 |
private void getEntityCompareSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1351 |
long catalogId = expEntity.getID();
|
|
|
1352 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1353 |
|
|
|
1354 |
try {
|
|
|
1355 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1356 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
1357 |
String prodName = title;
|
|
|
1358 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1359 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1360 |
}
|
| 1949 |
rajveer |
1361 |
String url = getEntityURL(expEntity);
|
|
|
1362 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1363 |
|
|
|
1364 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1365 |
client = catalogServiceClient.getClient();
|
|
|
1366 |
|
|
|
1367 |
String tinySnippet = "";
|
|
|
1368 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1369 |
for(Feature feature: features){
|
|
|
1370 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1371 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1372 |
int count = 1;
|
|
|
1373 |
for(Bullet bullet: bullets){
|
|
|
1374 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1375 |
tinySnippet = dataObject.getValue();
|
|
|
1376 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1377 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1378 |
}
|
|
|
1379 |
}
|
|
|
1380 |
}
|
| 1779 |
rajveer |
1381 |
|
|
|
1382 |
|
| 1949 |
rajveer |
1383 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1384 |
|
|
|
1385 |
Item minPriceItem = null;
|
|
|
1386 |
for(Item item: items){
|
|
|
1387 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1388 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1389 |
minPriceItem = item;
|
|
|
1390 |
}
|
|
|
1391 |
double sellingPrice = item.getSellingPrice();
|
|
|
1392 |
double mrp = item.getMrp();
|
|
|
1393 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1394 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1395 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1396 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1397 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1398 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1399 |
itemDetails.add(itemDetail);
|
|
|
1400 |
}
|
|
|
1401 |
|
|
|
1402 |
boolean showmrp = true;
|
|
|
1403 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1404 |
showmrp = false;
|
|
|
1405 |
}
|
|
|
1406 |
params.put("TITLE", title);
|
| 2166 |
vikas |
1407 |
params.put("PROD_NAME", prodName);
|
| 1949 |
rajveer |
1408 |
params.put("URL", url);
|
|
|
1409 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
1410 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1411 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1412 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1413 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1414 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1415 |
params.put("staticurl", staticurl);
|
|
|
1416 |
params.put("contentVersion", contentVersion);
|
|
|
1417 |
|
|
|
1418 |
VelocityContext context = new VelocityContext();
|
|
|
1419 |
context.put("itemDetails", itemDetails);
|
|
|
1420 |
context.put("params", params);
|
|
|
1421 |
|
|
|
1422 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSnippet.html";
|
|
|
1423 |
File exportFile = new File(exportFileName);
|
|
|
1424 |
if(!exportFile.exists()) {
|
|
|
1425 |
exportFile.createNewFile();
|
|
|
1426 |
}
|
|
|
1427 |
|
|
|
1428 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1429 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1430 |
|
|
|
1431 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1432 |
template.merge(context, writer);
|
|
|
1433 |
|
|
|
1434 |
writer.flush();
|
|
|
1435 |
writer.close();
|
|
|
1436 |
Utils.info("Export Complete!");
|
| 1779 |
rajveer |
1437 |
|
| 1949 |
rajveer |
1438 |
|
|
|
1439 |
} catch (Exception e) {
|
|
|
1440 |
e.printStackTrace();
|
|
|
1441 |
}
|
|
|
1442 |
}
|
|
|
1443 |
|
|
|
1444 |
|
|
|
1445 |
private void getEntityCompareSummarySnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1446 |
long catalogId = expEntity.getID();
|
|
|
1447 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1448 |
|
|
|
1449 |
try {
|
|
|
1450 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1451 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
1452 |
String prodName = title;
|
|
|
1453 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1454 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1455 |
}
|
| 1949 |
rajveer |
1456 |
String url = getEntityURL(expEntity);
|
|
|
1457 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1458 |
|
|
|
1459 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1460 |
client = catalogServiceClient.getClient();
|
|
|
1461 |
|
|
|
1462 |
String tinySnippet = "";
|
|
|
1463 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1464 |
for(Feature feature: features){
|
|
|
1465 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1466 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1467 |
int count = 1;
|
|
|
1468 |
for(Bullet bullet: bullets){
|
|
|
1469 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1470 |
tinySnippet = dataObject.getValue();
|
|
|
1471 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1472 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1473 |
}
|
|
|
1474 |
}
|
|
|
1475 |
}
|
|
|
1476 |
|
|
|
1477 |
|
|
|
1478 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1479 |
|
|
|
1480 |
Item minPriceItem = null;
|
|
|
1481 |
for(Item item: items){
|
|
|
1482 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1483 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1484 |
minPriceItem = item;
|
|
|
1485 |
}
|
|
|
1486 |
double sellingPrice = item.getSellingPrice();
|
|
|
1487 |
double mrp = item.getMrp();
|
|
|
1488 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1489 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1490 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1491 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1492 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1493 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1494 |
itemDetails.add(itemDetail);
|
|
|
1495 |
}
|
|
|
1496 |
|
|
|
1497 |
boolean showmrp = true;
|
|
|
1498 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1499 |
showmrp = false;
|
|
|
1500 |
}
|
|
|
1501 |
params.put("TITLE", title);
|
| 2166 |
vikas |
1502 |
params.put("PROD_NAME", prodName);
|
| 1949 |
rajveer |
1503 |
params.put("URL", url);
|
|
|
1504 |
params.put("IMAGE_PREFIX", imagePrefix);
|
|
|
1505 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1506 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1507 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1508 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1509 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1510 |
params.put("staticurl", staticurl);
|
|
|
1511 |
params.put("contentVersion", contentVersion);
|
|
|
1512 |
|
|
|
1513 |
VelocityContext context = new VelocityContext();
|
|
|
1514 |
context.put("itemDetails", itemDetails);
|
|
|
1515 |
context.put("params", params);
|
|
|
1516 |
|
|
|
1517 |
String exportFileName = exportPath + catalogId + File.separator + "CompareProductSummarySnippet.html";
|
|
|
1518 |
File exportFile = new File(exportFileName);
|
|
|
1519 |
if(!exportFile.exists()) {
|
|
|
1520 |
exportFile.createNewFile();
|
|
|
1521 |
}
|
|
|
1522 |
|
|
|
1523 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1524 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1525 |
|
|
|
1526 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1527 |
template.merge(context, writer);
|
|
|
1528 |
|
|
|
1529 |
writer.flush();
|
|
|
1530 |
writer.close();
|
|
|
1531 |
Utils.info("Export Complete!");
|
|
|
1532 |
|
|
|
1533 |
|
|
|
1534 |
} catch (Exception e) {
|
|
|
1535 |
e.printStackTrace();
|
|
|
1536 |
}
|
|
|
1537 |
}
|
|
|
1538 |
|
| 1669 |
varun.gupt |
1539 |
private void getEntityPhonesIOwnSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
|
|
|
1540 |
long catalogId = expEntity.getID();
|
|
|
1541 |
Map<String,String> params = new HashMap<String, String>();
|
|
|
1542 |
|
|
|
1543 |
try {
|
|
|
1544 |
expEntity = CreationUtils.getExpandedEntity(catalogId);
|
|
|
1545 |
String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
|
| 2166 |
vikas |
1546 |
String prodName = title;
|
|
|
1547 |
if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
|
|
|
1548 |
prodName = expEntity.getBrand() + " " + expEntity.getModelName();
|
|
|
1549 |
}
|
|
|
1550 |
String url = getEntityURL(expEntity);
|
| 1724 |
rajveer |
1551 |
String imagePrefix = getImagePrefix(expEntity);
|
|
|
1552 |
|
| 1669 |
varun.gupt |
1553 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
1554 |
client = catalogServiceClient.getClient();
|
|
|
1555 |
|
|
|
1556 |
String tinySnippet = "";
|
|
|
1557 |
List<Feature> features = expEntity.getSlide(130054).getFeatures();
|
|
|
1558 |
for(Feature feature: features){
|
|
|
1559 |
if(feature.getFeatureDefinitionID() == 120081){
|
|
|
1560 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1561 |
int count = 1;
|
|
|
1562 |
for(Bullet bullet: bullets){
|
|
|
1563 |
PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
|
|
|
1564 |
tinySnippet = dataObject.getValue();
|
|
|
1565 |
params.put("SNIPPET_"+count++, tinySnippet);
|
|
|
1566 |
System.out.println("Tiny Snippets is " + dataObject.getValue());
|
|
|
1567 |
}
|
|
|
1568 |
}
|
|
|
1569 |
}
|
| 516 |
rajveer |
1570 |
|
| 1669 |
varun.gupt |
1571 |
|
|
|
1572 |
List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>();
|
|
|
1573 |
|
|
|
1574 |
Item minPriceItem = null;
|
|
|
1575 |
for(Item item: items){
|
|
|
1576 |
Map<String, String> itemDetail = new HashMap<String, String>();
|
|
|
1577 |
if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
|
|
|
1578 |
minPriceItem = item;
|
|
|
1579 |
}
|
|
|
1580 |
double sellingPrice = item.getSellingPrice();
|
|
|
1581 |
double mrp = item.getMrp();
|
|
|
1582 |
double saving = Math.round((mrp-sellingPrice)/mrp*100);
|
|
|
1583 |
itemDetail.put("ITEM_ID", ((int)item.getId())+"");
|
|
|
1584 |
itemDetail.put("SP", ((int)item.getSellingPrice())+"");
|
|
|
1585 |
itemDetail.put("MRP", ((int)item.getMrp())+"");
|
|
|
1586 |
itemDetail.put("SAVING", ((int)saving)+"");
|
|
|
1587 |
itemDetail.put("COLOR", item.getColor());
|
|
|
1588 |
itemDetails.add(itemDetail);
|
|
|
1589 |
}
|
|
|
1590 |
|
|
|
1591 |
boolean showmrp = true;
|
|
|
1592 |
if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
|
|
|
1593 |
showmrp = false;
|
|
|
1594 |
}
|
|
|
1595 |
params.put("TITLE", title);
|
| 2166 |
vikas |
1596 |
params.put("PROD_NAME", prodName);
|
| 1669 |
varun.gupt |
1597 |
params.put("URL", url);
|
| 1724 |
rajveer |
1598 |
params.put("IMAGE_PREFIX", imagePrefix);
|
| 1669 |
varun.gupt |
1599 |
params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
|
|
|
1600 |
params.put("MRP", ((int)minPriceItem.getMrp())+"");
|
|
|
1601 |
params.put("SHOWMRP", showmrp +"");
|
|
|
1602 |
params.put("CATALOG_ID", ((int)catalogId)+"");
|
|
|
1603 |
params.put("ITEM_ID", minPriceItem.getId()+"");
|
|
|
1604 |
params.put("staticurl", staticurl);
|
|
|
1605 |
params.put("contentVersion", contentVersion);
|
|
|
1606 |
|
|
|
1607 |
VelocityContext context = new VelocityContext();
|
|
|
1608 |
context.put("itemDetails", itemDetails);
|
|
|
1609 |
context.put("params", params);
|
|
|
1610 |
|
|
|
1611 |
String exportFileName = exportPath + catalogId + File.separator + "PhonesIOwnSnippet.html";
|
|
|
1612 |
File exportFile = new File(exportFileName);
|
|
|
1613 |
if(!exportFile.exists()) {
|
|
|
1614 |
exportFile.createNewFile();
|
|
|
1615 |
}
|
|
|
1616 |
|
|
|
1617 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1618 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1619 |
|
|
|
1620 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1621 |
template.merge(context, writer);
|
|
|
1622 |
|
|
|
1623 |
writer.flush();
|
|
|
1624 |
writer.close();
|
|
|
1625 |
Utils.info("Export Complete!");
|
|
|
1626 |
|
|
|
1627 |
|
|
|
1628 |
} catch (Exception e) {
|
|
|
1629 |
e.printStackTrace();
|
|
|
1630 |
}
|
|
|
1631 |
}
|
|
|
1632 |
|
| 451 |
rajveer |
1633 |
public String getHtmlFromVelocity(String templateFile, VelocityContext context){
|
|
|
1634 |
try {
|
|
|
1635 |
Velocity.init("velocity/velocity.properties");
|
|
|
1636 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
1637 |
if(template != null) {
|
|
|
1638 |
StringWriter writer = new StringWriter();
|
|
|
1639 |
template.merge(context, writer);
|
|
|
1640 |
writer.flush();
|
|
|
1641 |
writer.close();
|
|
|
1642 |
return writer.toString();
|
|
|
1643 |
}
|
|
|
1644 |
|
|
|
1645 |
} catch (ResourceNotFoundException e) {
|
|
|
1646 |
e.printStackTrace();
|
|
|
1647 |
} catch (ParseErrorException e) {
|
|
|
1648 |
e.printStackTrace();
|
|
|
1649 |
} catch (MethodInvocationException e) {
|
|
|
1650 |
e.printStackTrace();
|
|
|
1651 |
} catch (IOException e) {
|
|
|
1652 |
e.printStackTrace();
|
|
|
1653 |
} catch (Exception e) {
|
|
|
1654 |
e.printStackTrace();
|
|
|
1655 |
}
|
|
|
1656 |
|
|
|
1657 |
return null;
|
|
|
1658 |
}
|
|
|
1659 |
|
|
|
1660 |
|
| 22 |
naveen |
1661 |
}
|
| 1357 |
rajveer |
1662 |
|
|
|
1663 |
|
|
|
1664 |
|
|
|
1665 |
/*
|
|
|
1666 |
*
|
|
|
1667 |
|
|
|
1668 |
// Category definitions
|
|
|
1669 |
else if(inputCommand.equals("category")) {
|
|
|
1670 |
ExpandedCategory expCategory = defs.getExpandedCategory(catalogId);
|
|
|
1671 |
//Utils.info("expCategory=" + expCategory);
|
|
|
1672 |
|
|
|
1673 |
context.put("expcategory", expCategory);
|
|
|
1674 |
template = Velocity.getTemplate(templateFile);
|
|
|
1675 |
|
|
|
1676 |
exportFileName = Utils.EXPORT_DEFINITIONS_PATH + catalogId + ".html";
|
|
|
1677 |
}
|
|
|
1678 |
|
|
|
1679 |
// Category carousal
|
|
|
1680 |
else if(inputCommand.equals("category_carousal")) {
|
|
|
1681 |
String categoryName = defs.getCategory(catalogId).getLabel();
|
|
|
1682 |
|
|
|
1683 |
|
|
|
1684 |
Collection<Entity> entities = CreationUtils.getEntities(catalogId);
|
|
|
1685 |
|
|
|
1686 |
|
|
|
1687 |
List<String[]> entitiesToShow = new ArrayList<String[]>();
|
|
|
1688 |
|
|
|
1689 |
for(Entity entity : entities) {
|
|
|
1690 |
String snippets[] = new String[4];
|
|
|
1691 |
|
|
|
1692 |
// Entity ID
|
|
|
1693 |
snippets[0] = new Long(entity.getID()).toString();
|
|
|
1694 |
|
|
|
1695 |
Feature feature = CreationUtils.getFeature(entity.getID(),
|
|
|
1696 |
Utils.SNIPPETS_FEATURE_DEFINITIONID);
|
|
|
1697 |
|
|
|
1698 |
List<Bullet> bullets = feature.getBullets();
|
|
|
1699 |
|
|
|
1700 |
if(bullets.size() > 0) {
|
|
|
1701 |
snippets[1] = ((PrimitiveDataObject)bullets.get(0).
|
|
|
1702 |
getDataObject()).getValue();
|
|
|
1703 |
}
|
|
|
1704 |
|
|
|
1705 |
if(bullets.size() > 1) {
|
|
|
1706 |
snippets[2] = ((PrimitiveDataObject)bullets.get(1).
|
|
|
1707 |
getDataObject()).getValue();
|
|
|
1708 |
}
|
|
|
1709 |
|
|
|
1710 |
if(bullets.size() > 2) {
|
|
|
1711 |
snippets[3] = ((PrimitiveDataObject)bullets.get(2).
|
|
|
1712 |
getDataObject()).getValue();
|
|
|
1713 |
}
|
|
|
1714 |
|
|
|
1715 |
//Utils.info("snippets=" + Arrays.toString(snippets));
|
|
|
1716 |
entitiesToShow.add(snippets);
|
|
|
1717 |
}
|
|
|
1718 |
|
|
|
1719 |
//Utils.info("categoryName=" + categoryName);
|
|
|
1720 |
//Utils.info("entitiesToShow=" + entitiesToShow);
|
|
|
1721 |
|
|
|
1722 |
//context.put("categoryName", categoryName);
|
|
|
1723 |
//context.put("entitiesToShow", entitiesToShow);
|
|
|
1724 |
|
|
|
1725 |
template = Velocity.getTemplate(templateFile);
|
|
|
1726 |
exportFileName = Utils.EXPORT_CATEGORY_HOMES_PATH + catalogId + ".html";
|
|
|
1727 |
Utils.info("Export File Names " + exportFileName );
|
|
|
1728 |
}
|
|
|
1729 |
|
|
|
1730 |
// Difference
|
|
|
1731 |
else if(inputCommand.equals("diff")) {
|
|
|
1732 |
String[] entityIDs = StringUtils.split(inputID, "_");
|
|
|
1733 |
if(entityIDs.length < 2) {
|
|
|
1734 |
System.out.println("Invalid IDs - " + inputID);
|
|
|
1735 |
System.exit(-1);
|
|
|
1736 |
}
|
|
|
1737 |
|
|
|
1738 |
long entityID1 = 0L;
|
|
|
1739 |
long entityID2 = 0L;
|
|
|
1740 |
try {
|
|
|
1741 |
entityID1 = Long.parseLong(entityIDs[0]);
|
|
|
1742 |
entityID2 = Long.parseLong(entityIDs[1]);
|
|
|
1743 |
} catch(NumberFormatException nfe) {
|
|
|
1744 |
System.out.println("Invalid IDs - " + inputID);
|
|
|
1745 |
System.exit(-1);
|
|
|
1746 |
}
|
|
|
1747 |
|
|
|
1748 |
Utils.info("entityIDs=" + Arrays.toString(entityIDs));
|
|
|
1749 |
|
|
|
1750 |
ExpandedEntity expEntity1 = CreationUtils.getExpandedEntity(entityID1);
|
|
|
1751 |
ExpandedEntity expEntity2 = CreationUtils.getExpandedEntity(entityID2);
|
|
|
1752 |
|
|
|
1753 |
List<ExpandedSlide[]> mergedSlides =
|
|
|
1754 |
getMergedSlides(expEntity1, expEntity2);
|
|
|
1755 |
//Utils.info("mergedSlides=" + mergedSlides);
|
|
|
1756 |
|
|
|
1757 |
Collection<String[]> mergedComparisonScores =
|
|
|
1758 |
getMergedComparisonScores(expEntity1, expEntity2);
|
|
|
1759 |
//Utils.info("mergedComparisonScores=" + mergedComparisonScores);
|
|
|
1760 |
|
|
|
1761 |
int scoreEntity1 = CreationUtils.getEntityComparisonScores(expEntity1.getID());
|
|
|
1762 |
int scoreEntity2 = CreationUtils.getEntityComparisonScores(expEntity2.getID());
|
|
|
1763 |
|
|
|
1764 |
|
|
|
1765 |
context.put("expEntity1", expEntity1);
|
|
|
1766 |
context.put("expEntity2", expEntity2);
|
|
|
1767 |
context.put("mergedSlides", mergedSlides);
|
|
|
1768 |
context.put("mergedComparisonScores", mergedComparisonScores);
|
|
|
1769 |
context.put("scoreEntity1", scoreEntity1);
|
|
|
1770 |
context.put("scoreEntity2", scoreEntity2);
|
|
|
1771 |
|
|
|
1772 |
template = Velocity.getTemplate(templateFile);
|
|
|
1773 |
exportFileName = Utils.EXPORT_DIFF_PATH + entityIDs[0] + "_" +
|
|
|
1774 |
entityIDs[1] + ".html";
|
|
|
1775 |
}
|
|
|
1776 |
|
|
|
1777 |
if(template != null) {
|
|
|
1778 |
File exportFile = new File(exportFileName);
|
|
|
1779 |
if(!exportFile.exists()) {
|
|
|
1780 |
exportFile.createNewFile();
|
|
|
1781 |
}
|
|
|
1782 |
|
|
|
1783 |
BufferedWriter writer = new BufferedWriter(
|
|
|
1784 |
new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
1785 |
|
|
|
1786 |
template.merge(context, writer);
|
|
|
1787 |
|
|
|
1788 |
writer.flush();
|
|
|
1789 |
writer.close();
|
|
|
1790 |
Utils.info("Export Complete!");
|
|
|
1791 |
}
|
|
|
1792 |
*/
|