Subversion Repositories SmartDukaan

Rev

Rev 2314 | Rev 2367 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2171 rajveer 1
package in.shop2020.ui.util;
2
 
3
import in.shop2020.metamodel.core.Bullet;
4
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.Feature;
6
import in.shop2020.metamodel.core.PrimitiveDataObject;
7
import in.shop2020.metamodel.definitions.Catalog;
8
import in.shop2020.metamodel.util.CreationUtils;
9
import in.shop2020.metamodel.util.ExpandedBullet;
10
import in.shop2020.metamodel.util.ExpandedEntity;
11
import in.shop2020.metamodel.util.ExpandedFeature;
12
import in.shop2020.metamodel.util.ExpandedSlide;
13
import in.shop2020.model.v1.catalog.InventoryService.Client;
14
import in.shop2020.model.v1.catalog.Item;
15
import in.shop2020.thrift.clients.CatalogServiceClient;
16
import in.shop2020.util.Utils;
17
 
18
import java.io.BufferedWriter;
19
import java.io.File;
20
import java.io.FileInputStream;
21
import java.io.FileOutputStream;
22
import java.io.IOException;
23
import java.io.InputStream;
24
import java.io.OutputStream;
25
import java.io.OutputStreamWriter;
26
import java.io.StringWriter;
2227 rajveer 27
import java.net.URLEncoder;
2171 rajveer 28
import java.text.DecimalFormat;
29
import java.util.ArrayList;
30
import java.util.Date;
31
import java.util.HashMap;
32
import java.util.List;
33
import java.util.Map;
34
 
35
import org.apache.velocity.Template;
36
import org.apache.velocity.VelocityContext;
37
import org.apache.velocity.app.Velocity;
38
import org.apache.velocity.exception.MethodInvocationException;
39
import org.apache.velocity.exception.ParseErrorException;
40
import org.apache.velocity.exception.ResourceNotFoundException;
2305 vikas 41
import org.json.JSONObject;
2171 rajveer 42
 
43
/**
44
 * utility class to generated all html stuff from java objects
45
 * Driver class to merge Java data objects with VTL script. 
46
 * 
47
 * @author rajveer
48
 *
49
 */
50
public class NewVUI {
51
	CatalogServiceClient catalogServiceClient = null;
52
	Client client = null;
53
	String lastContentVersion;
54
	String contentVersion;  
55
 
56
	StringBuffer problems = new StringBuffer();
57
 
58
	public NewVUI(Long contentVersion) throws Exception {
59
		catalogServiceClient = new CatalogServiceClient();
60
		client = catalogServiceClient.getClient();
61
		this.lastContentVersion = contentVersion.toString();
62
		this.contentVersion =  (new Date()).getTime() +"" ;
63
	}
64
 
65
	/**
66
	 * Generates content for the specified entity embedding links to the
67
	 * specified domain name.
68
	 * 
69
	 * The method updates the member variable problems in any of the following
70
	 * four cases:
71
	 * <ol>
72
	 * <li>The entity is not ready.
73
	 * <li>The category has not been updated yet. (Set to -1).
74
	 * <li>There are no items in the catalog corresponding to this entity.
75
	 * <li>There are no active or content-complete items in the catalog
76
	 * corresponding to this entity.
77
	 * <li>Neither the items have been updated nor the content has been updated.
78
	 * </ol>
79
	 * 
80
	 * @param entity
81
	 *            - Entity for which the content has to be generated.
82
	 * @param domain
83
	 *            - The domain name to be used to serve static content.
84
	 * @param exportPath
85
	 *            - Local file system path where content has to be generated.
86
	 * @return -True if content is generated successfully, False otherwise.
87
	 * @throws Exception
88
	 */
89
	public boolean generateHtmlForOneEntity(Entity entity, String domain, String exportPath, List<Item> items) throws Exception{
90
		String mediaPath = Utils.EXPORT_MEDIA_PATH + entity.getID();
91
 
92
        deleteOldResources(mediaPath, exportPath + entity.getID());
93
 
94
		ExpandedEntity expEntity = new ExpandedEntity(entity);
95
 
96
		long catalogId = expEntity.getID();
97
		String templateFile;
98
 
99
 
100
		//Create new directory
101
		File exportDir = new File(exportPath + catalogId);
102
		if(!exportDir.exists()) {
103
			exportDir.mkdir();
104
		}
105
 
106
		/*
107
		 * To delete 
108
		 */
109
 
110
 
111
		// This URL is used to ensure that images such as icon and thumbnail for
112
		// a particular entity are always downloaded from the same location.
113
		String staticurl = "http://static" + entity.getID()%3 + "." + domain;
114
 
115
		templateFile= Utils.VTL_SRC_PATH + "product_summary.vm";
2227 rajveer 116
		getProductSummaryHtml(expEntity, items, templateFile, exportPath, domain);
2171 rajveer 117
 
118
		templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_widget.vm";
119
		getEntityWidgetSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
120
 
121
		templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_homepage.vm";
122
		getEntityHomeSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
123
 
124
		templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_searchpage.vm";
125
		getEntitySearchSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
126
 
127
		templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_categorypage.vm";
128
		getEntityCategorySnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
129
 
130
		templateFile= Utils.VTL_SRC_PATH + "slideguide_img_video.vm";
131
		getEntitySlideGuideHtml(expEntity, templateFile, domain, exportPath);
2205 rajveer 132
 
2171 rajveer 133
		templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_phones_i_own.vm";
134
		getEntityPhonesIOwnSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
135
 
136
		if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
137
 
138
		    templateFile= Utils.VTL_SRC_PATH + "slideguide_for_comparison.vm";
139
	        getEntitySnippetForComparison(expEntity, templateFile, domain, exportPath);
140
 
141
	        templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage.vm";
142
	        getEntityCompareSnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
2205 rajveer 143
 
2171 rajveer 144
            templateFile= Utils.VTL_SRC_PATH + "entity_snippet_for_comparisonpage_summary.vm";
145
            getEntityCompareSummarySnippetHtml(expEntity, items, templateFile, staticurl, exportPath);
2205 rajveer 146
 
2171 rajveer 147
            getSlidenamesSnippet(expEntity, exportPath);
148
		}
149
 
2305 vikas 150
		getProductPropertiesSnippet(expEntity, exportPath);
2171 rajveer 151
 
152
		generateImages(expEntity.getID(), getImagePrefix(expEntity));
153
 
154
		return true;
155
	}
156
 
157
	public boolean deleteDir(File dir) {
158
	    if (dir.isDirectory()) {
159
	        String[] children = dir.list();
160
	        for (int i=0; i<children.length; i++) {
161
	            boolean success = deleteDir(new File(dir, children[i]));
162
	            if (!success) {
163
	                return false;
164
	            }
165
	        }
166
	    }
167
 
168
	    // The directory is now empty so delete it
169
	    return dir.delete();
170
	}
171
 
172
	private void deleteOldResources(String mediaPath, String contentPath) {
173
		File f = new File(contentPath);
174
		if(f.exists()){
175
			deleteDir(f);
176
		}
177
 
178
		f = new File(mediaPath);
179
		if(f.exists()){
180
			deleteDir(f);
181
		}
182
	}
183
 
184
	private void generateImages(long catalogId, String imagePrefix) throws IOException {
185
		String globalImageDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator;
186
		String globalDefaultImagePath = globalImageDirPath + "default.jpg";
187
 
188
		String imageDirPath = globalImageDirPath + catalogId + File.separator;
189
		String defaultImagePath = imageDirPath + "default.jpg";
190
 
191
		/*
192
		 * Create the directory for this entity if it didn't exist.
193
		 */
194
		File f = new File(globalImageDirPath + catalogId);
195
		if (!f.exists()) {
196
			f.mkdir();
197
		}
198
 
199
		/*
200
		 * If the default image is not present for this entity, copy the global
201
		 * default image.
202
		 * TODO: This part will be moved to the Jython Script
203
		 */
204
		File f3 = new File(defaultImagePath);
205
		if (!f3.exists()) {
206
		        copyFile(globalDefaultImagePath, defaultImagePath);
207
		    }
208
 
209
		String exportPath = Utils.EXPORT_MEDIA_PATH + catalogId;
210
		/*
211
		 * Copying the generated content from db/media to export/media. This
212
		 * will also insert a timestamp tag in the file names.
213
		 */
214
		File sourceFile = new File(globalImageDirPath + catalogId);
215
		File destinationFile = new File(exportPath);
2198 rajveer 216
		copyDirectory(sourceFile, destinationFile, imagePrefix);
2171 rajveer 217
 
218
		/*
219
		 * Copy the thumbnail and the icon files. This is required so that we can display the
220
		 * thumbnail on the cart page and icon on the facebook.
221
		 */
2198 rajveer 222
		copyFile(imageDirPath + "thumbnail.jpg", exportPath + File.separator + "thumbnail.jpg");
223
		copyFile(imageDirPath + "icon.jpg", exportPath + File.separator + "icon.jpg");
2171 rajveer 224
		}
225
 
226
	/**
227
	 * Copies the contents of the input file into the output file. Creates the
228
	 * output file if it doesn't exist already.
229
	 * 
230
	 * @param inputFile
231
	 *            File to be copied.
232
	 * @param outputFile
233
	 *            File to be created.
234
	 * @throws IOException
235
	 */
236
	private void copyFile(String inputFile, String outputFile) throws IOException {
237
		File sourceFile = new File(inputFile);
238
		File destinationFile = new File(outputFile);
2206 rajveer 239
 
2171 rajveer 240
		if (!destinationFile.exists())
241
			destinationFile.createNewFile();
242
 
243
		InputStream in = new FileInputStream(sourceFile);
2305 vikas 244
	    OutputStream out = new FileOutputStream(destinationFile);
2171 rajveer 245
		// Copy the bits from instream to outstream
246
		byte[] buf = new byte[1024];
247
		int len;
248
		while ((len = in.read(buf)) > 0) {
249
			out.write(buf, 0, len);
250
		}
251
		in.close();
252
		out.close();
253
	}
254
 
255
	// If targetLocation does not exist, it will be created.
256
	public void copyDirectory(File sourceLocation , File targetLocation, String imagePrefix) throws IOException {
257
 
258
	    if (sourceLocation.isDirectory()) {
259
	        if (!targetLocation.exists()) {
260
	            targetLocation.mkdir();
261
	        }
262
 
263
	        String[] children = sourceLocation.list();
264
	        for (int i=0; i<children.length; i++) {
265
	            copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]), imagePrefix);
266
	        }
267
	    } else {
268
	        InputStream in = new FileInputStream(sourceLocation);
269
 
270
        	String fileName = targetLocation.getName().split("\\.")[0];
271
        	String fileExt = targetLocation.getName().split("\\.")[1];
272
        	String newFileName = targetLocation.getParent() + File.separator + imagePrefix + "-" + fileName + "-" + this.contentVersion + "." + fileExt; 
273
 
274
 
275
	        //String fileName = targetLocation
276
	        OutputStream out = new FileOutputStream(newFileName);
277
 
278
	        // Copy the bits from instream to outstream
279
	        byte[] buf = new byte[1024];
280
	        int len;
281
	        while ((len = in.read(buf)) > 0) {
282
	            out.write(buf, 0, len);
283
	        }
284
	        in.close();
285
	        out.close();
286
	    }
287
	}
288
 
2305 vikas 289
	private  void getProductPropertiesSnippet(ExpandedEntity expEntity, String exportPath) {
290
        long catalogId = expEntity.getID();
291
        try {
292
            expEntity = CreationUtils.getExpandedEntity(catalogId);
293
        } catch (Exception e) {
294
            e.printStackTrace();
295
        }
296
 
297
        String metaDescription = "";
298
        String metaKeywords = "";
299
        String entityUrl = getEntityURL(expEntity);
300
        String title = "";
301
 
302
        List<Feature>  features = expEntity.getSlide(130054).getFeatures();
303
        for(Feature feature: features){
304
            if(feature.getFeatureDefinitionID() == 120132){
305
                PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
306
                title = dataObject.getValue(); 
307
            }
308
            if(feature.getFeatureDefinitionID() == 120133){
309
                PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
310
                metaDescription = dataObject.getValue();
311
            }
312
            if(feature.getFeatureDefinitionID() == 120134){
313
                PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
314
                metaKeywords = dataObject.getValue();
315
            }
316
        }
2171 rajveer 317
 
2305 vikas 318
        try {
2171 rajveer 319
 
2305 vikas 320
            JSONObject props = new JSONObject();
321
            props.put("metaDescription", metaDescription);
322
            props.put("metaKeywords", metaKeywords);
323
            props.put("entityUrl", entityUrl);
324
            props.put("title", title);
2171 rajveer 325
 
2305 vikas 326
            String exportFileName = exportPath + catalogId + File.separator
327
                    + "ProductPropertiesSnippet.html";
328
            File exportFile = new File(exportFileName);
329
            if (!exportFile.exists()) {
330
                exportFile.createNewFile();
331
            }
2171 rajveer 332
 
2305 vikas 333
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
334
                    new FileOutputStream(exportFile)));
335
 
336
            writer.write(props.toString());
337
 
338
            writer.flush();
339
            writer.close();
340
        } catch (Exception e) {
341
            e.printStackTrace();
342
        }
2171 rajveer 343
	}
2305 vikas 344
 
345
    private void getSlidenamesSnippet(ExpandedEntity expEntity, String exportPath) throws ResourceNotFoundException, ParseErrorException, Exception{
2171 rajveer 346
	    long catalogId = expEntity.getID();
347
 
348
	    StringBuilder slideNames = new StringBuilder();
349
 
350
	    slideNames.append(expEntity.getBrand() + " " + expEntity.getModelNumber() + " " + expEntity.getModelName() + "\n");
351
 
352
	    Map<Long, Double> slideScores = CreationUtils.getSlideComparisonScores(catalogId);
353
 
354
	    for(ExpandedSlide expSlide: expEntity.getExpandedSlides()){
355
	        if(expSlide.getSlideDefinitionID() == 130054){
356
	            continue;
357
	        }
358
	        slideNames.append(expSlide.getSlideDefinition().getLabel() + "!!!");
359
 
360
	        String bucketName = "None";
361
	        if(Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID()) != null){
362
	            bucketName = Catalog.getInstance().getDefinitionsContainer().getComparisonBucketName(expEntity.getCategoryID(), expSlide.getSlideDefinitionID());
363
	        }
364
	        slideNames.append(bucketName + "!!!");
365
 
366
	        double score = 0;
367
	        if(slideScores.get(expSlide.getSlideDefinitionID())!=null){
368
	            score = slideScores.get(expSlide.getSlideDefinitionID());
369
	        }
370
 
371
	        DecimalFormat oneDForm = new DecimalFormat("#.#");
372
	        score = Double.valueOf(oneDForm.format(score));
373
 
374
	        slideNames.append(score + "\n");
375
	    }
376
 
377
        String exportFileName = exportPath + catalogId + File.separator + "SlideNamesSnippet.html";
378
        File exportFile = new File(exportFileName);
379
        if(!exportFile.exists()) {
380
            exportFile.createNewFile();
381
        }
382
 
383
        BufferedWriter writer = new BufferedWriter(
384
            new OutputStreamWriter(new FileOutputStream(exportFile)));
385
 
386
        writer.write(slideNames.toString());
387
        writer.flush();
388
        writer.close();
389
 
390
	}
391
 
392
 
393
	private  void getEntitySnippetForComparison(ExpandedEntity expEntity, String templateFile, String domain, String exportPath) throws Exception {
394
		long catalogId = expEntity.getID();
395
		VelocityContext context = new VelocityContext();
396
 
397
		context.put("imagePrefix", getImagePrefix(expEntity));
398
		context.put("expentity", expEntity);
399
		context.put("domain", domain);
400
		context.put("contentVersion", this.contentVersion);
401
 
402
		String exportFileName = null;
403
 
404
		Template template = Velocity.getTemplate(templateFile);
405
		exportFileName = exportPath + catalogId + File.separator + "ComparisonSnippet.html";
406
 
407
		File exportFile = new File(exportFileName);
408
		if(!exportFile.exists()) {
409
			exportFile.createNewFile();
410
		}
411
 
412
		BufferedWriter writer = new BufferedWriter(
413
		    new OutputStreamWriter(new FileOutputStream(exportFile)));
414
 
415
		//Template template = Velocity.getTemplate(templateFile);
416
		template.merge(context, writer);
417
 
418
		writer.flush();
419
		writer.close();
420
		Utils.info("Export Complete!");
421
 
422
	}
423
 
424
	private  void getEntitySlideGuideHtml(ExpandedEntity expEntity, String templateFile, String domain, String exportPath) throws Exception {
425
        long catalogId = expEntity.getID();
426
        VelocityContext context = new VelocityContext();
427
 
428
        context.put("imagePrefix", getImagePrefix(expEntity));
429
        context.put("expentity", expEntity);
430
        context.put("domain", domain);
431
        context.put("contentVersion", this.contentVersion);
432
        context.put("defs", Catalog.getInstance().getDefinitionsContainer());
2319 rajveer 433
        context.put("helpdocs", CreationUtils.getHelpdocs());
434
 
2171 rajveer 435
        String exportFileName = null;
436
 
437
        Template template = Velocity.getTemplate(templateFile);
438
        exportFileName = exportPath + catalogId + File.separator + "SlideGuide.html";
439
 
440
        File exportFile = new File(exportFileName);
441
        if(!exportFile.exists()) {
442
            exportFile.createNewFile();
443
        }
444
 
445
        BufferedWriter writer = new BufferedWriter(
446
            new OutputStreamWriter(new FileOutputStream(exportFile)));
447
 
448
        //Template template = Velocity.getTemplate(templateFile);
449
        template.merge(context, writer);
450
 
451
        writer.flush();
452
        writer.close();
453
        Utils.info("Export Complete!");
454
 
455
    }
456
 
2227 rajveer 457
	public void getProductSummaryHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String exportPath, String domain) {
2171 rajveer 458
		long catalogId = expEntity.getID();
459
		try {
460
			List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
461
			for(Item item: items){
462
				Map<String, String> itemDetail = new HashMap<String, String>();
463
				double sellingPrice = item.getSellingPrice();
464
				double mrp = item.getMrp();
465
				boolean showmrp = true;
466
				if (mrp <= sellingPrice) {
467
					showmrp = false;
468
				}
469
 
470
				double saving = Math.round((mrp-sellingPrice)/mrp*100);
471
				itemDetail.put("ITEM_ID", ((int)item.getId())+"");
472
				itemDetail.put("CATALOG_ID", ((int)item.getCatalogItemId())+"");
473
				itemDetail.put("SP", ((int)item.getSellingPrice())+"");
474
				itemDetail.put("MRP", ((int)item.getMrp())+"");
475
				itemDetail.put("SAVING", ((int)saving)+"");
476
				itemDetail.put("COLOR", item.getColor());
477
				itemDetail.put("SHOWMRP", showmrp +"");
478
				itemDetail.put("IS_SELECTED", item.isDefaultForEntity() ? "SELECTED" : "");
479
				itemDetails.add(itemDetail);
480
			}
481
 
482
			String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
2314 vikas 483
			String brandName = expEntity.getBrand().trim();
2305 vikas 484
			String productName = expEntity.getModelName() + " " + expEntity.getModelNumber();
2171 rajveer 485
			String categoryName = expEntity.getCategory().getLabel();
486
			String tagline = "";
487
			String warranty = "";
488
			List<Feature>  features = expEntity.getSlide(130054).getFeatures();
489
			for(Feature feature: features){
490
				if(feature.getFeatureDefinitionID() == 120084){
491
					PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
492
					tagline = dataObject.getValue(); 
493
				}
494
				if(feature.getFeatureDefinitionID() == 120125){
495
					ExpandedFeature expFeature = new ExpandedFeature(feature);
496
					ExpandedBullet expBullet =expFeature.getExpandedBullets().get(0);
497
					if(expBullet != null){
498
						warranty = expBullet.getValue() + " "+ expBullet.getUnit().getShortForm();
499
					}
500
				}
501
			}
502
 
503
 
504
 
505
			long categoryId = expEntity.getCategory().getID();
506
			Map<String,String> params = new HashMap<String, String>();
507
			params.put("TITLE", title);
2305 vikas 508
			params.put("BRAND_NAME", brandName);
509
			params.put("PRODUCT_NAME", productName);
2171 rajveer 510
			params.put("CATEGORY_ID", ((int)categoryId)+"");
511
			params.put("CATEGORY_NAME", categoryName);
512
			params.put("CATEGORY_URL", categoryName.replaceAll(" ", "-").toLowerCase() + "/" + categoryId);
2227 rajveer 513
			params.put("PRODUCT_URL", URLEncoder.encode("http://www."+ domain + this.getEntityURL(expEntity), "UTF-8"));
514
			if(expEntity.getCategory().getParentCategory().getID() == Utils.MOBILE_PHONES_CATAGOEY){
515
				params.put("IS_MOBILE", "TRUE" );	
516
			}else{
517
				params.put("IS_MOBILE", "FALSE" );
518
			}
2171 rajveer 519
			params.put("CATALOG_ID", ((int)catalogId)+"");
520
			params.put("TAGLINE", tagline);
521
			params.put("WARRANTY", warranty);
522
 
523
			VelocityContext context = new VelocityContext();
524
 
525
			context.put("itemDetails", itemDetails);
526
 
527
			context.put("params", params);
528
 
529
			String exportFileName = exportPath + catalogId + File.separator + "ProductDetail.html";
530
 
531
			File exportFile = new File(exportFileName);
532
			if(!exportFile.exists()) {
533
				exportFile.createNewFile();
534
			}
535
 
536
			BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile)));
537
 
538
			Template template = Velocity.getTemplate(templateFile);
539
			template.merge(context, writer);
540
 
541
			writer.flush();
542
			writer.close();
543
			Utils.info("Export Complete!");
544
 
545
		} catch (Exception e) {
546
			e.printStackTrace();
547
		}
548
	}
549
 
550
	private String getEntityURL(ExpandedEntity expEntity){
551
		String url = "/" + expEntity.getCategory().getParentCategory().getLabel().toLowerCase().replace(' ', '-') + "/";
552
		String productUrl = expEntity.getBrand().toLowerCase().replace(' ', '-')
553
        + "-" + expEntity.getModelName().toLowerCase().replace(' ', '-') 
554
	    + "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-')
555
        + "-" + expEntity.getID();
556
		productUrl = productUrl.replaceAll("/", "-");
557
		url = url + productUrl;
2305 vikas 558
		url = url.replaceAll("-+", "-");
2171 rajveer 559
		return url;
560
	}
561
 
562
	private String getImagePrefix(ExpandedEntity expEntity){
563
		String imagePrefix = expEntity.getBrand().toLowerCase().replace(' ', '-')
564
        + "-" + expEntity.getModelName().toLowerCase().replace(' ', '-') 
565
	    + "-" + expEntity.getModelNumber().toLowerCase().replace(' ', '-');
566
		imagePrefix = imagePrefix.replaceAll("/", "-");
567
		imagePrefix = imagePrefix.replaceAll("--", "-");
568
		return imagePrefix;
569
	}
570
 
571
	private void getEntityWidgetSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
572
		long catalogId = expEntity.getID();
573
		try {
574
			expEntity = CreationUtils.getExpandedEntity(catalogId);
575
			String title = expEntity.getBrand() + " " + expEntity.getModelName() + " " + expEntity.getModelNumber();
2197 rajveer 576
			String prodName = title;
577
			if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
578
				prodName = expEntity.getBrand() + " " + expEntity.getModelName();
579
			}
2171 rajveer 580
			String imagePrefix = getImagePrefix(expEntity);
581
			String url = getEntityURL(expEntity);
582
 
583
			String tinySnippet = "";
584
			List<Feature>  features = expEntity.getSlide(130054).getFeatures();
585
			for(Feature feature: features){
586
				if(feature.getFeatureDefinitionID() == 120089){
587
					PrimitiveDataObject dataObject= (PrimitiveDataObject)feature.getBullets().get(0).getDataObject();
588
					tinySnippet = dataObject.getValue(); 
589
				}
590
			}
591
 
592
			List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
593
 
594
			Item minPriceItem = null; 
595
			for(Item item: items){
596
				Map<String, String> itemDetail = new HashMap<String, String>();
597
				if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
598
					minPriceItem = item;
599
				}
600
				double sellingPrice = item.getSellingPrice();
601
				double mrp = item.getMrp();
602
				double saving = Math.round((mrp-sellingPrice)/mrp*100);
603
				itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
604
				itemDetail.put("SP", ((int)item.getSellingPrice())+"");
605
				itemDetail.put("MRP", ((int)item.getMrp())+"");
606
				itemDetail.put("SAVING", ((int)saving)+"");
607
				itemDetail.put("COLOR", item.getColor());
608
				itemDetails.add(itemDetail);
609
			}
610
 
611
			boolean showmrp = true;
612
			if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
613
				showmrp = false;
614
			}
615
			Map<String,String> params = new HashMap<String, String>();
616
			params.put("TITLE", title);
2197 rajveer 617
			params.put("PROD_NAME", prodName);
2171 rajveer 618
			params.put("URL", url);
619
			params.put("IMAGE_PREFIX", imagePrefix);
620
			params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
621
			params.put("MRP", ((int)minPriceItem.getMrp())+"");
622
			params.put("SHOWMRP", showmrp +"");
623
			params.put("CATALOG_ID", ((int)catalogId)+"");
624
			params.put("ITEM_ID", minPriceItem.getId()+"");
625
			params.put("TINY_SNIPPET", tinySnippet);
626
			params.put("staticurl", staticurl);
627
			params.put("contentVersion", contentVersion);
628
			VelocityContext context = new VelocityContext();
629
			context.put("itemDetails", itemDetails);
630
			context.put("params", params);
631
 
632
			String exportFileName = exportPath + catalogId + File.separator + "WidgetSnippet.html";
633
			File exportFile = new File(exportFileName);
634
			if(!exportFile.exists()) {
635
				exportFile.createNewFile();
636
			}
637
 
638
			BufferedWriter writer = new BufferedWriter(
639
			    new OutputStreamWriter(new FileOutputStream(exportFile)));
640
 
641
			Template template = Velocity.getTemplate(templateFile);
642
			template.merge(context, writer);
643
 
644
			writer.flush();
645
			writer.close();
646
			Utils.info("Export Complete!");
647
 
648
 
649
		} catch (Exception e) {
650
			e.printStackTrace();
651
		}
652
	}
653
 
654
 
655
	private  void getEntityHomeSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
656
		long catalogId = expEntity.getID();
657
 
658
		Map<String,String> params = new HashMap<String, String>();
659
 
660
		try {
661
			expEntity = CreationUtils.getExpandedEntity(catalogId);
662
			String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
2197 rajveer 663
			String prodName = title;
664
			if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
665
				prodName = expEntity.getBrand() + " " + expEntity.getModelName();
666
			}
2171 rajveer 667
			String url = getEntityURL(expEntity);
668
			String imagePrefix = getImagePrefix(expEntity);
669
 
670
			catalogServiceClient = new CatalogServiceClient();
671
			client = catalogServiceClient.getClient();
672
 
673
			String tinySnippet = "";
674
			List<Feature>  features = expEntity.getSlide(130054).getFeatures();
675
			for(Feature feature: features){
676
				if(feature.getFeatureDefinitionID() == 120081){
677
					List<Bullet> bullets = feature.getBullets();
678
					int count = 1;
679
					for(Bullet bullet: bullets){
680
						PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
681
						tinySnippet = dataObject.getValue();
682
						params.put("SNIPPET_"+count++, tinySnippet);
683
						System.out.println("Tiny Snippets is " + dataObject.getValue());
684
					}
685
 				}
686
			}
687
 
688
 
689
 
690
			List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
691
 
692
			Item minPriceItem = null;
693
 
694
			for(Item item: items){
695
				Map<String, String> itemDetail = new HashMap<String, String>();
696
				if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
697
					minPriceItem = item;
698
				}
699
				double sellingPrice = item.getSellingPrice();
700
				double mrp = item.getMrp();
701
				double saving = Math.round((mrp-sellingPrice)/mrp*100);
702
				itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
703
				itemDetail.put("SP", ((int)item.getSellingPrice())+"");
704
				itemDetail.put("MRP", ((int)item.getMrp())+"");
705
				itemDetail.put("SAVING", ((int)saving)+"");
706
				itemDetail.put("COLOR", item.getColor());
707
				itemDetails.add(itemDetail);
708
			}
709
			boolean showmrp = true;
710
			if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
711
				showmrp = false;
712
			}
713
 
714
			params.put("TITLE", title);
2197 rajveer 715
			params.put("PROD_NAME", prodName);
2171 rajveer 716
			params.put("URL", url);
717
			params.put("IMAGE_PREFIX", imagePrefix);
718
			params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
719
			params.put("MRP", ((int)minPriceItem.getMrp())+"");
720
			params.put("SHOWMRP", showmrp +"");
721
			params.put("CATALOG_ID", ((int)catalogId)+"");
722
			params.put("ITEM_ID", minPriceItem.getId()+"");
723
			params.put("staticurl", staticurl);
724
			params.put("contentVersion", contentVersion);
725
 
726
			VelocityContext context = new VelocityContext();
727
			context.put("itemDetails", itemDetails);
728
			context.put("params", params);
729
 
730
 
731
			String exportFileName = exportPath + catalogId + File.separator + "HomeSnippet.html";
732
			File exportFile = new File(exportFileName);
733
			if(!exportFile.exists()) {
734
				exportFile.createNewFile();
735
			}
736
 
737
			BufferedWriter writer = new BufferedWriter(
738
			    new OutputStreamWriter(new FileOutputStream(exportFile)));
739
 
740
			Template template = Velocity.getTemplate(templateFile);
741
			template.merge(context, writer);
742
 
743
			writer.flush();
744
			writer.close();
745
			Utils.info("Export Complete!");
746
 
747
		} catch (Exception e) {
748
			e.printStackTrace();
749
		}
750
	}
751
 
752
	private  void getEntityCategorySnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
753
		Map<String,String> params = new HashMap<String, String>();
754
		long catalogId = expEntity.getID();
755
 
756
		try {
757
			expEntity = CreationUtils.getExpandedEntity(catalogId);
758
			String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
2197 rajveer 759
			String prodName = title;
760
			if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
761
				prodName = expEntity.getBrand() + " " + expEntity.getModelName();
762
			}
2171 rajveer 763
			catalogServiceClient = new CatalogServiceClient();
764
			client = catalogServiceClient.getClient();
765
			String url = getEntityURL(expEntity);
766
			String imagePrefix = getImagePrefix(expEntity);
767
 
768
			String tinySnippet = "";
769
			List<Feature>  features = expEntity.getSlide(130054).getFeatures();
770
			for(Feature feature: features){
771
				if(feature.getFeatureDefinitionID() == 120081){
772
					List<Bullet> bullets = feature.getBullets();
773
					int count = 1;
774
					for(Bullet bullet: bullets){
775
						PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
776
						tinySnippet = dataObject.getValue();
777
						params.put("SNIPPET_"+count++, tinySnippet);
778
						System.out.println("Tiny Snippets is " + dataObject.getValue());
779
					}
780
 				}
781
			}
782
 
783
			List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
784
 
785
			Item minPriceItem = null;
786
			for(Item item: items){
787
				Map<String, String> itemDetail = new HashMap<String, String>();
788
				if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
789
					minPriceItem = item;
790
				}
791
				double sellingPrice = item.getSellingPrice();
792
				double mrp = item.getMrp();
793
				double saving = Math.round((mrp-sellingPrice)/mrp*100);
794
				itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
795
				itemDetail.put("SP", ((int)item.getSellingPrice())+"");
796
				itemDetail.put("MRP", ((int)item.getMrp())+"");
797
				itemDetail.put("SAVING", ((int)saving)+"");
798
				itemDetail.put("COLOR", item.getColor());
799
				itemDetails.add(itemDetail);
800
			}
801
 
802
			boolean showmrp = true;
803
			if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
804
				showmrp = false;
805
			}
806
			params.put("TITLE", title);
2197 rajveer 807
			params.put("PROD_NAME", prodName);
2171 rajveer 808
			params.put("URL", url);
809
			params.put("IMAGE_PREFIX", imagePrefix);
810
			params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
811
			params.put("MRP", ((int)minPriceItem.getMrp())+"");
812
			params.put("SHOWMRP", showmrp +"");
813
			params.put("CATALOG_ID", ((int)catalogId)+"");
814
			params.put("ITEM_ID", minPriceItem.getId()+"");
815
			params.put("staticurl", staticurl);
816
			params.put("contentVersion", contentVersion);
817
 
818
			VelocityContext context = new VelocityContext();
819
			context.put("itemDetails", itemDetails);
820
			context.put("params", params);
821
 
822
			String exportFileName = exportPath + catalogId + File.separator + "CategorySnippet.html";
823
			File exportFile = new File(exportFileName);
824
			if(!exportFile.exists()) {
825
				exportFile.createNewFile();
826
			}
827
 
828
			BufferedWriter writer = new BufferedWriter(
829
			    new OutputStreamWriter(new FileOutputStream(exportFile)));
830
 
831
			Template template = Velocity.getTemplate(templateFile);
832
			template.merge(context, writer);
833
 
834
			writer.flush();
835
			writer.close();
836
			Utils.info("Export Complete!");
837
 
838
 
839
		} catch (Exception e) {
840
			e.printStackTrace();
841
		}
842
	}
843
 
2305 vikas 844
    private void getEntitySearchSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
2171 rajveer 845
		long catalogId = expEntity.getID();
846
		Map<String,String> params = new HashMap<String, String>();
847
 
848
		try {
849
			expEntity = CreationUtils.getExpandedEntity(catalogId);
850
			String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
2197 rajveer 851
			String prodName = title;
852
			if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
853
				prodName = expEntity.getBrand() + " " + expEntity.getModelName();
854
			}
2171 rajveer 855
 
856
			String url = getEntityURL(expEntity);
857
			String imagePrefix = getImagePrefix(expEntity);
858
 
859
			catalogServiceClient = new CatalogServiceClient();
860
			client = catalogServiceClient.getClient();
861
 
862
			String tinySnippet = "";
863
			List<Feature>  features = expEntity.getSlide(130054).getFeatures();
864
			for(Feature feature: features){
865
				if(feature.getFeatureDefinitionID() == 120081){
866
					List<Bullet> bullets = feature.getBullets();
867
					int count = 1;
868
					for(Bullet bullet: bullets){
869
						PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
870
						tinySnippet = dataObject.getValue();
871
						params.put("SNIPPET_"+count++, tinySnippet);
872
						System.out.println("Tiny Snippets is " + dataObject.getValue());
873
					}
874
 				}
875
			}
876
 
877
 
878
			List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
879
 
880
			Item minPriceItem = null;
881
			for(Item item: items){
882
				Map<String, String> itemDetail = new HashMap<String, String>();
883
				if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
884
					minPriceItem = item;
885
				}
886
				double sellingPrice = item.getSellingPrice();
887
				double mrp = item.getMrp();
888
				double saving = Math.round((mrp-sellingPrice)/mrp*100);
889
				itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
890
				itemDetail.put("SP", ((int)item.getSellingPrice())+"");
891
				itemDetail.put("MRP", ((int)item.getMrp())+"");
892
				itemDetail.put("SAVING", ((int)saving)+"");
893
				itemDetail.put("COLOR", item.getColor());
894
				itemDetails.add(itemDetail);
895
			}
896
 
897
			boolean showmrp = true;
898
			if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
899
				showmrp = false;
900
			}
901
			params.put("TITLE", title);
2197 rajveer 902
			params.put("PROD_NAME", prodName);
2171 rajveer 903
			params.put("URL", url);
904
			params.put("IMAGE_PREFIX", imagePrefix);
905
			params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
906
			params.put("MRP", ((int)minPriceItem.getMrp())+"");
907
			params.put("SHOWMRP", showmrp +"");
908
			params.put("CATALOG_ID", ((int)catalogId)+"");
909
			params.put("ITEM_ID", minPriceItem.getId()+"");
910
			params.put("staticurl", staticurl);
911
			params.put("contentVersion", contentVersion);
912
 
913
			VelocityContext context = new VelocityContext();
914
			context.put("itemDetails", itemDetails);
915
			context.put("params", params);
916
 
917
			String exportFileName = exportPath + catalogId + File.separator + "SearchSnippet.html";
918
			File exportFile = new File(exportFileName);
919
			if(!exportFile.exists()) {
920
				exportFile.createNewFile();
921
			}
922
 
923
			BufferedWriter writer = new BufferedWriter(
924
			    new OutputStreamWriter(new FileOutputStream(exportFile)));
925
 
926
			Template template = Velocity.getTemplate(templateFile);
927
			template.merge(context, writer);
928
 
929
			writer.flush();
930
			writer.close();
931
			Utils.info("Export Complete!");
932
 
933
 
934
		} catch (Exception e) {
935
			e.printStackTrace();
936
		}
937
	}
938
 
939
 
940
    private void getEntityCompareSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
941
        long catalogId = expEntity.getID();
942
        Map<String,String> params = new HashMap<String, String>();
943
 
944
        try {
945
            expEntity = CreationUtils.getExpandedEntity(catalogId);
946
            String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
2197 rajveer 947
            String prodName = title;
948
            if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
949
            prodName = expEntity.getBrand() + " " + expEntity.getModelName();
950
            }
2171 rajveer 951
            String url = getEntityURL(expEntity);
952
            String imagePrefix = getImagePrefix(expEntity);
953
 
954
            catalogServiceClient = new CatalogServiceClient();
955
            client = catalogServiceClient.getClient();
956
 
957
            String tinySnippet = "";
958
            List<Feature>  features = expEntity.getSlide(130054).getFeatures();
959
            for(Feature feature: features){
960
                if(feature.getFeatureDefinitionID() == 120081){
961
                    List<Bullet> bullets = feature.getBullets();
962
                    int count = 1;
963
                    for(Bullet bullet: bullets){
964
                        PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
965
                        tinySnippet = dataObject.getValue();
966
                        params.put("SNIPPET_"+count++, tinySnippet);
967
                        System.out.println("Tiny Snippets is " + dataObject.getValue());
968
                    }
969
                }
970
            }
971
 
972
 
973
            List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
974
 
975
            Item minPriceItem = null;
976
            for(Item item: items){
977
                Map<String, String> itemDetail = new HashMap<String, String>();
978
                if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
979
                    minPriceItem = item;
980
                }
981
                double sellingPrice = item.getSellingPrice();
982
                double mrp = item.getMrp();
983
                double saving = Math.round((mrp-sellingPrice)/mrp*100);
984
                itemDetail.put("ITEM_ID", ((int)item.getId())+"");  
985
                itemDetail.put("SP", ((int)item.getSellingPrice())+"");
986
                itemDetail.put("MRP", ((int)item.getMrp())+"");
987
                itemDetail.put("SAVING", ((int)saving)+"");
988
                itemDetail.put("COLOR", item.getColor());
989
                itemDetails.add(itemDetail);
990
            }
991
 
992
            boolean showmrp = true;
993
            if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
994
                showmrp = false;
995
            }
996
            params.put("TITLE", title);
2197 rajveer 997
            params.put("PROD_NAME", prodName);
2171 rajveer 998
            params.put("URL", url);
999
            params.put("IMAGE_PREFIX", imagePrefix);
1000
            params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
1001
            params.put("MRP", ((int)minPriceItem.getMrp())+"");
1002
            params.put("SHOWMRP", showmrp +"");
1003
            params.put("CATALOG_ID", ((int)catalogId)+"");
1004
            params.put("ITEM_ID", minPriceItem.getId()+"");
1005
            params.put("staticurl", staticurl);
1006
            params.put("contentVersion", contentVersion);
1007
 
1008
            VelocityContext context = new VelocityContext();
1009
            context.put("itemDetails", itemDetails);
1010
            context.put("params", params);
1011
 
1012
            String exportFileName = exportPath + catalogId + File.separator + "CompareProductSnippet.html";
1013
            File exportFile = new File(exportFileName);
1014
            if(!exportFile.exists()) {
1015
                exportFile.createNewFile();
1016
            }
1017
 
1018
            BufferedWriter writer = new BufferedWriter(
1019
                new OutputStreamWriter(new FileOutputStream(exportFile)));
1020
 
1021
            Template template = Velocity.getTemplate(templateFile);
1022
            template.merge(context, writer);
1023
 
1024
            writer.flush();
1025
            writer.close();
1026
            Utils.info("Export Complete!");
1027
 
1028
 
1029
        } catch (Exception e) {
1030
            e.printStackTrace();
1031
        }
1032
    }
1033
 
1034
 
1035
    private void getEntityCompareSummarySnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
1036
        long catalogId = expEntity.getID();
1037
        Map<String,String> params = new HashMap<String, String>();
1038
 
1039
        try {
1040
            expEntity = CreationUtils.getExpandedEntity(catalogId);
1041
            String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
2197 rajveer 1042
            String prodName = title;
1043
            if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
1044
            prodName = expEntity.getBrand() + " " + expEntity.getModelName();
1045
            }
2171 rajveer 1046
            String url = getEntityURL(expEntity);
1047
            String imagePrefix = getImagePrefix(expEntity);
1048
 
1049
            catalogServiceClient = new CatalogServiceClient();
1050
            client = catalogServiceClient.getClient();
1051
 
1052
            String tinySnippet = "";
1053
            List<Feature>  features = expEntity.getSlide(130054).getFeatures();
1054
            for(Feature feature: features){
1055
                if(feature.getFeatureDefinitionID() == 120081){
1056
                    List<Bullet> bullets = feature.getBullets();
1057
                    int count = 1;
1058
                    for(Bullet bullet: bullets){
1059
                        PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
1060
                        tinySnippet = dataObject.getValue();
1061
                        params.put("SNIPPET_"+count++, tinySnippet);
1062
                        System.out.println("Tiny Snippets is " + dataObject.getValue());
1063
                    }
1064
                }
1065
            }
1066
 
1067
 
1068
            List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
1069
 
1070
            Item minPriceItem = null;
1071
            for(Item item: items){
1072
                Map<String, String> itemDetail = new HashMap<String, String>();
1073
                if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
1074
                    minPriceItem = item;
1075
                }
1076
                double sellingPrice = item.getSellingPrice();
1077
                double mrp = item.getMrp();
1078
                double saving = Math.round((mrp-sellingPrice)/mrp*100);
1079
                itemDetail.put("ITEM_ID", ((int)item.getId())+"");  
1080
                itemDetail.put("SP", ((int)item.getSellingPrice())+"");
1081
                itemDetail.put("MRP", ((int)item.getMrp())+"");
1082
                itemDetail.put("SAVING", ((int)saving)+"");
1083
                itemDetail.put("COLOR", item.getColor());
1084
                itemDetails.add(itemDetail);
1085
            }
1086
 
1087
            boolean showmrp = true;
1088
            if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
1089
                showmrp = false;
1090
            }
1091
            params.put("TITLE", title);
2197 rajveer 1092
            params.put("PROD_NAME", prodName);
2171 rajveer 1093
            params.put("URL", url);
1094
            params.put("IMAGE_PREFIX", imagePrefix);
1095
            params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
1096
            params.put("MRP", ((int)minPriceItem.getMrp())+"");
1097
            params.put("SHOWMRP", showmrp +"");
1098
            params.put("CATALOG_ID", ((int)catalogId)+"");
1099
            params.put("ITEM_ID", minPriceItem.getId()+"");
1100
            params.put("staticurl", staticurl);
1101
            params.put("contentVersion", contentVersion);
1102
 
1103
            VelocityContext context = new VelocityContext();
1104
            context.put("itemDetails", itemDetails);
1105
            context.put("params", params);
1106
 
1107
            String exportFileName = exportPath + catalogId + File.separator + "CompareProductSummarySnippet.html";
1108
            File exportFile = new File(exportFileName);
1109
            if(!exportFile.exists()) {
1110
                exportFile.createNewFile();
1111
            }
1112
 
1113
            BufferedWriter writer = new BufferedWriter(
1114
                new OutputStreamWriter(new FileOutputStream(exportFile)));
1115
 
1116
            Template template = Velocity.getTemplate(templateFile);
1117
            template.merge(context, writer);
1118
 
1119
            writer.flush();
1120
            writer.close();
1121
            Utils.info("Export Complete!");
1122
 
1123
 
1124
        } catch (Exception e) {
1125
            e.printStackTrace();
1126
        }
1127
    }
1128
 
1129
	private void getEntityPhonesIOwnSnippetHtml(ExpandedEntity expEntity, List<Item> items, String templateFile, String staticurl, String exportPath) {
1130
		long catalogId = expEntity.getID();
1131
		Map<String,String> params = new HashMap<String, String>();
1132
 
1133
		try {
1134
			expEntity = CreationUtils.getExpandedEntity(catalogId);
1135
			String title = expEntity.getBrand() + " " + expEntity.getModelName()+ " " + expEntity.getModelNumber();
2197 rajveer 1136
			String prodName = title;
1137
			if (expEntity.getModelName() != null && !expEntity.getModelName().isEmpty() && (expEntity.getBrand().equals("Samsung") || expEntity.getBrand().equals("Sony Ericsson"))) {
1138
				 prodName = expEntity.getBrand() + " " + expEntity.getModelName();
1139
			}
2171 rajveer 1140
			String url = getEntityURL(expEntity);
2197 rajveer 1141
 
2171 rajveer 1142
			String imagePrefix = getImagePrefix(expEntity);
1143
 
1144
			catalogServiceClient = new CatalogServiceClient();
1145
			client = catalogServiceClient.getClient();
1146
 
1147
			String tinySnippet = "";
1148
			List<Feature>  features = expEntity.getSlide(130054).getFeatures();
1149
			for(Feature feature: features){
1150
				if(feature.getFeatureDefinitionID() == 120081){
1151
					List<Bullet> bullets = feature.getBullets();
1152
					int count = 1;
1153
					for(Bullet bullet: bullets){
1154
						PrimitiveDataObject dataObject = (PrimitiveDataObject)bullet.getDataObject();
1155
						tinySnippet = dataObject.getValue();
1156
						params.put("SNIPPET_"+count++, tinySnippet);
1157
						System.out.println("Tiny Snippets is " + dataObject.getValue());
1158
					}
1159
 				}
1160
			}
1161
 
1162
 
1163
			List<Map<String, String>> itemDetails = new ArrayList<Map<String,String>>(); 
1164
 
1165
			Item minPriceItem = null;
1166
			for(Item item: items){
1167
				Map<String, String> itemDetail = new HashMap<String, String>();
1168
				if(minPriceItem == null || minPriceItem.getSellingPrice() > item.getSellingPrice()){
1169
					minPriceItem = item;
1170
				}
1171
				double sellingPrice = item.getSellingPrice();
1172
				double mrp = item.getMrp();
1173
				double saving = Math.round((mrp-sellingPrice)/mrp*100);
1174
				itemDetail.put("ITEM_ID", ((int)item.getId())+"");	
1175
				itemDetail.put("SP", ((int)item.getSellingPrice())+"");
1176
				itemDetail.put("MRP", ((int)item.getMrp())+"");
1177
				itemDetail.put("SAVING", ((int)saving)+"");
1178
				itemDetail.put("COLOR", item.getColor());
1179
				itemDetails.add(itemDetail);
1180
			}
1181
 
1182
			boolean showmrp = true;
1183
			if (minPriceItem.getMrp() <= minPriceItem.getSellingPrice()) {
1184
				showmrp = false;
1185
			}
1186
			params.put("TITLE", title);
2197 rajveer 1187
			params.put("PROD_NAME", prodName);
2171 rajveer 1188
			params.put("URL", url);
1189
			params.put("IMAGE_PREFIX", imagePrefix);
1190
			params.put("SELLING_PRICE", ((int)minPriceItem.getSellingPrice())+"");
1191
			params.put("MRP", ((int)minPriceItem.getMrp())+"");
1192
			params.put("SHOWMRP", showmrp +"");
1193
			params.put("CATALOG_ID", ((int)catalogId)+"");
1194
			params.put("ITEM_ID", minPriceItem.getId()+"");
1195
			params.put("staticurl", staticurl);
1196
			params.put("contentVersion", contentVersion);
1197
 
1198
			VelocityContext context = new VelocityContext();
1199
			context.put("itemDetails", itemDetails);
1200
			context.put("params", params);
1201
 
1202
			String exportFileName = exportPath + catalogId + File.separator + "PhonesIOwnSnippet.html";
1203
			File exportFile = new File(exportFileName);
1204
			if(!exportFile.exists()) {
1205
				exportFile.createNewFile();
1206
			}
1207
 
1208
			BufferedWriter writer = new BufferedWriter(
1209
			    new OutputStreamWriter(new FileOutputStream(exportFile)));
1210
 
1211
			Template template = Velocity.getTemplate(templateFile);
1212
			template.merge(context, writer);
1213
 
1214
			writer.flush();
1215
			writer.close();
1216
			Utils.info("Export Complete!");
1217
 
1218
 
1219
		} catch (Exception e) {
1220
			e.printStackTrace();
1221
		}
1222
	}
1223
 
1224
	public String getHtmlFromVelocity(String templateFile, VelocityContext context){
1225
		try {
1226
			Velocity.init("velocity/velocity.properties");
1227
			Template template = Velocity.getTemplate(templateFile);
1228
			if(template != null) {
1229
				StringWriter writer = new StringWriter();
1230
				template.merge(context, writer);
1231
				writer.flush();
1232
				writer.close();
1233
				return writer.toString();
1234
			}
1235
 
1236
			} catch (ResourceNotFoundException e) {
1237
				e.printStackTrace();
1238
			} catch (ParseErrorException e) {
1239
				e.printStackTrace();
1240
			} catch (MethodInvocationException e) {
1241
				e.printStackTrace();
1242
			} catch (IOException e) {
1243
				e.printStackTrace();
1244
			} catch (Exception e) {
1245
				e.printStackTrace();
1246
			}
1247
 
1248
		return null;
1249
	}
1250
 
1251
 
1252
}
1253