Subversion Repositories SmartDukaan

Rev

Rev 13598 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4403 amit.gupta 1
package in.shop2020.util;
2
 
3
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.core.Feature;
5
import in.shop2020.metamodel.core.Media;
6
import in.shop2020.metamodel.core.Slide;
7
import in.shop2020.metamodel.definitions.Catalog;
4461 amit.gupta 8
import in.shop2020.metamodel.definitions.Category;
13164 amit.gupta 9
import in.shop2020.metamodel.util.CreationUtils;
4403 amit.gupta 10
import in.shop2020.metamodel.util.ExpandedBullet;
11
import in.shop2020.metamodel.util.ExpandedEntity;
12
import in.shop2020.metamodel.util.ExpandedFeature;
5945 mandeep.dh 13
import in.shop2020.model.v1.catalog.CatalogService.Client;
13386 manas 14
import in.shop2020.model.v1.catalog.CatalogServiceException;
4403 amit.gupta 15
import in.shop2020.model.v1.catalog.Item;
16
import in.shop2020.model.v1.catalog.status;
17
import in.shop2020.thrift.clients.CatalogClient;
4633 amit.gupta 18
import in.shop2020.thrift.clients.WarehouseClient;
4469 amit.gupta 19
import in.shop2020.thrift.clients.config.ConfigClient;
4403 amit.gupta 20
import in.shop2020.ui.util.NewVUI;
4428 amit.gupta 21
import in.shop2020.utils.GmailUtils;
4633 amit.gupta 22
import in.shop2020.warehouse.WarehouseService;
4403 amit.gupta 23
 
24
import java.io.File;
7708 amit.gupta 25
import java.io.FileNotFoundException;
26
import java.io.FileReader;
4403 amit.gupta 27
import java.io.FileWriter;
10042 amit.gupta 28
import java.io.FilenameFilter;
5900 amit.gupta 29
import java.io.IOException;
7708 amit.gupta 30
import java.io.Reader;
4492 amit.gupta 31
import java.text.SimpleDateFormat;
4403 amit.gupta 32
import java.util.ArrayList;
33
import java.util.Arrays;
4428 amit.gupta 34
import java.util.Calendar;
10042 amit.gupta 35
import java.util.Comparator;
4492 amit.gupta 36
import java.util.Date;
4403 amit.gupta 37
import java.util.HashMap;
13165 amit.gupta 38
import java.util.HashSet;
4403 amit.gupta 39
import java.util.List;
40
import java.util.Map;
13165 amit.gupta 41
import java.util.Set;
6069 amit.gupta 42
import java.util.regex.Matcher;
43
import java.util.regex.Pattern;
4403 amit.gupta 44
 
4428 amit.gupta 45
import javax.mail.MessagingException;
46
 
4403 amit.gupta 47
import org.apache.commons.collections.CollectionUtils;
48
import org.apache.commons.collections.Predicate;
49
import org.apache.commons.lang.StringUtils;
4995 amit.gupta 50
import org.apache.commons.logging.Log;
51
import org.apache.commons.logging.LogFactory;
8212 amit.gupta 52
import org.apache.commons.vfs.FileObject;
53
import org.apache.commons.vfs.FileSystemException;
54
import org.apache.commons.vfs.FileSystemOptions;
55
import org.apache.commons.vfs.Selectors;
56
import org.apache.commons.vfs.impl.StandardFileSystemManager;
57
import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder;
13386 manas 58
import org.apache.thrift.TException;
4633 amit.gupta 59
import org.apache.thrift.transport.TTransportException;
4403 amit.gupta 60
 
7708 amit.gupta 61
import com.google.gson.Gson;
62
import com.google.gson.reflect.TypeToken;
63
 
13386 manas 64
 
65
 
66
 
67
 
68
 
69
 
70
 
71
 
72
 
73
 
74
 
75
 
76
 
77
 
78
 
79
 
80
 
81
/* Added for generating the xml file: Starts*/ 
82
 
83
import javax.xml.parsers.DocumentBuilder;
84
import javax.xml.parsers.DocumentBuilderFactory;
85
import javax.xml.parsers.ParserConfigurationException;
86
import javax.xml.transform.OutputKeys;
87
import javax.xml.transform.Transformer;
88
import javax.xml.transform.TransformerException;
89
import javax.xml.transform.TransformerFactory;
90
import javax.xml.transform.dom.DOMSource;
91
import javax.xml.transform.stream.StreamResult;
92
 
93
import org.w3c.dom.Document;
94
import org.w3c.dom.Element;
95
import org.w3c.dom.Node;
96
import org.w3c.dom.NodeList;
97
import org.xml.sax.SAXException;
98
/* Added for generating the xml file: Ends*/ 
4403 amit.gupta 99
/**
100
 * 
8212 amit.gupta 101
 * @author amit
102
 * 
103
 *         Utity class to generate a TSV file to be uploaded to Amazon's seller
104
 *         central. ItemNumbers.xls which is fetched from Nilesh to get UPC/EAN.
105
 *         Accesses Catalog database to pull Mobile related entities and
106
 *         CMS(bdb) to pull the data to generate the tsv file.
4403 amit.gupta 107
 */
108
public class AmazonSCDataGenerator {
109
 
4473 amit.gupta 110
	public static final String FTP_UPLOAD_URL = "dar-eu.amazon-digital-ftp.com";
4461 amit.gupta 111
	public static final String FTP_USER_NAME = "M_SAHOLIC_107503884";
8193 amit.gupta 112
	public static final int FTP_PORT = 22;
8175 amit.gupta 113
	public static final String FTP_PASSWORD = "S2rT2qvKLG";
7708 amit.gupta 114
	public static final List<Long> PAUSED_BY_RISK_ITEMS = getPausedByRiskItems();
6069 amit.gupta 115
	Pattern patt = Pattern.compile("(\\d*\\.?\\d+)");
8212 amit.gupta 116
	// private static DecimalFormat numberFormat = new DecimalFormat("#");
4654 amit.gupta 117
	private static SimpleDateFormat dateformatYYYYMMDDHHMM = new SimpleDateFormat(
118
			"yyyyMMdd-kkmm");
9994 amit.gupta 119
	private static Predicate predicateLive;
13386 manas 120
/*	private static Predicate predicateLaptopTables;
10042 amit.gupta 121
	private static Predicate predicateMobileNAcc;
13386 manas 122
	private static Predicate predicateCameras;*/
123
	String mobileXML;
124
	String filePath;
125
	File mobileXMLFile;
126
	Document docu;
127
	DocumentBuilderFactory docFactory1;
128
	DocumentBuilder docBuilder1;
129
	Element rootElement;
130
	String rowHeader="row";
4950 amit.gupta 131
	public static StringBuffer mailAlerMessage = new StringBuffer();
4995 amit.gupta 132
	private static Log log = LogFactory.getLog(AmazonSCDataGenerator.class);
4441 amit.gupta 133
	static {
9994 amit.gupta 134
		predicateLive = new Predicate() {
4403 amit.gupta 135
			@Override
136
			public boolean evaluate(Object obj) {
137
				Item item = (Item) obj;
4428 amit.gupta 138
				return Arrays.asList(
139
						new status[] { status.ACTIVE, status.PAUSED,
8212 amit.gupta 140
								status.PAUSED_BY_RISK, status.COMING_SOON })
141
						.contains(item.getItemStatus());
4428 amit.gupta 142
			}
4633 amit.gupta 143
		};
4441 amit.gupta 144
	}
145
 
5257 amit.gupta 146
	private WarehouseService.Client whc = null;
147
	private Client cc = null;
13386 manas 148
//	private Client catalogClient = null;
5900 amit.gupta 149
	private FileWriter productFileWriter;
6069 amit.gupta 150
	private FileWriter cameraFileWriter;
5900 amit.gupta 151
	private FileWriter laptopFileWriter;
13580 manas 152
	private FileWriter smartWatchWriter;
5900 amit.gupta 153
	private List<Entity> validEntites;
154
	private String generationType;
13386 manas 155
	String dateString = dateformatYYYYMMDDHHMM.format(new Date());
156
	List<Entity> fullValidEntities;
157
	List<String> skuPresent;
158
	private boolean isFullUpload;
9996 amit.gupta 159
	public AmazonSCDataGenerator(List<Entity> validEntities) {
5257 amit.gupta 160
		try {
161
			whc = new WarehouseClient().getClient();
162
		} catch (TTransportException e) {
163
			System.out.println("Error accessing warehouse Service: " + e);
164
		}
165
		try {
166
			cc = new CatalogClient().getClient();
167
		} catch (TTransportException e) {
168
			System.out.println("Error accessing warehouse Service: " + e);
169
		}
13386 manas 170
		/*try {
171
			catalogClient = new CatalogClient(
172
					ConfigClientKeys.catalog_service_server_host_prod.toString(),
173
					ConfigClientKeys.catalog_service_server_port.toString()).getClient();
6193 amit.gupta 174
		} catch (TTransportException e) {
175
			System.out.println("Error accessing warehouse Service: " + e);
13386 manas 176
		}*/
177
 
178
		File laptopsFile = new File(Utils.EXPORT_PATH + "Laptops" + dateString
179
				+ ".tsv");
5900 amit.gupta 180
		try {
181
			laptopFileWriter = new FileWriter(laptopsFile, true);
182
		} catch (IOException e) {
183
			e.printStackTrace();
184
		}
13580 manas 185
		File smartWatchFile = new File(Utils.EXPORT_PATH + "SmartWatches" + dateString
186
				+ ".tsv");
187
		try {
188
			smartWatchWriter = new FileWriter(smartWatchFile, true);
189
		} catch (IOException e) {
190
			e.printStackTrace();
191
		}
13386 manas 192
		File productsFile = new File(Utils.EXPORT_PATH + "Products"
193
				+ dateString + ".tsv");
5900 amit.gupta 194
		try {
195
			productFileWriter = new FileWriter(productsFile, true);
196
		} catch (IOException e) {
197
			e.printStackTrace();
198
		}
6069 amit.gupta 199
 
13386 manas 200
		File camerasFile = new File(Utils.EXPORT_PATH + "Cameras" + dateString
201
				+ ".tsv");
6069 amit.gupta 202
		try {
203
			cameraFileWriter = new FileWriter(camerasFile, true);
204
		} catch (IOException e) {
205
			e.printStackTrace();
206
		}
5900 amit.gupta 207
		this.validEntites = validEntities;
5257 amit.gupta 208
	}
13386 manas 209
	public AmazonSCDataGenerator(List<Entity> validEntities, boolean fullUpload) throws IOException {
210
 
211
		try {
212
			whc = new WarehouseClient().getClient();
213
		} catch (TTransportException e) {
214
			System.out.println("Error accessing warehouse Service: " + e);
215
		}
216
		try {
217
			cc = new CatalogClient().getClient();
218
		} catch (TTransportException e) {
219
			System.out.println("Error accessing warehouse Service: " + e);
220
		}
221
		/*try {
222
			catalogClient = new CatalogClient().getClient();
223
		} catch (TTransportException e) {
224
			System.out.println("Error accessing warehouse Service: " + e);
225
		}*/
226
		this.isFullUpload = fullUpload;
227
		this.validEntites = validEntities;
228
		docFactory1 = DocumentBuilderFactory.newInstance();
229
		try {
230
			docBuilder1 = docFactory1.newDocumentBuilder();
231
		} catch (ParserConfigurationException e) {
232
			e.printStackTrace();
233
		}
234
		mobileXML = "Catalog.xml";
13397 amit.gupta 235
		mobileXMLFile = new File(Utils.EXPORT_PARTNERS_CONTENT_PATH+ mobileXML);
13580 manas 236
	/*	mobileXMLFile = new File(Utils.EXPORT_PATH+ mobileXML);*/
13386 manas 237
		if(isFullUpload==true){
13580 manas 238
			//To generate smart watch tsv file only when full upload is true
239
			File smartWatchFile = new File(Utils.EXPORT_PATH + "SmartWatches" + dateString
240
					+ ".tsv");
241
			/*File smartWatchFile = new File(Utils.EXPORT_PARTNERS_CONTENT_PATH + "SmartWatches" + dateString
242
					+ ".tsv");*/
243
			try {
244
				smartWatchWriter = new FileWriter(smartWatchFile, true);
245
			} catch (IOException e) {
246
				e.printStackTrace();
247
			}
13386 manas 248
			dateString="";
249
			docu = docBuilder1.newDocument();
250
			rootElement = docu.createElement("junglee-feed");
251
	        docu.appendChild(rootElement);
252
		}
253
		else{
254
			if(!mobileXMLFile.exists()){
255
				throw new IOException("File not found");
256
			}
257
			try {
258
				docu = docBuilder1.parse(mobileXMLFile);
259
			} catch (SAXException e) {
260
				e.printStackTrace();
261
			} 
262
		}
263
	}
4441 amit.gupta 264
	/**
265
	 * @param args
266
	 */
13386 manas 267
	public static void main(String[] args) {
268
		if (args != null && args.length > 0) {
269
			try {
270
				Client cc = new CatalogClient("catalog_service_server_host_prod",
271
							"catalog_service_server_port").getClient();
13251 amit.gupta 272
				List<Item> l1 = cc.getAllItemsByStatus(status.ACTIVE);
13386 manas 273
				Set<Entity> entities = new HashSet<Entity>();
274
				for (Item i : l1) {
13251 amit.gupta 275
					entities.add(CreationUtils.getEntity(i.getCatalogItemId()));
276
				}
277
				AmazonSCDataGenerator ascdg = new AmazonSCDataGenerator(new ArrayList<Entity>(entities));
13386 manas 278
				ascdg.generateSCProdData();
13164 amit.gupta 279
			}
13386 manas 280
			catch (CatalogServiceException e) {
281
				e.printStackTrace();
282
			}catch (TTransportException e) {
283
				e.printStackTrace();
284
			}catch (TException e) {
285
				e.printStackTrace();
286
			}catch (Exception e) {
287
				e.printStackTrace();
288
			}
289
		} else {
290
			try {
291
				//AmazonSCDataGenerator.generatePricesAndAvailability();
292
				log.info("Here");
293
				Set<Entity> entities = new HashSet<Entity>();
294
				AmazonSCDataGenerator ascdg = null;
295
				ascdg = new AmazonSCDataGenerator(new ArrayList<Entity>(entities),true);
296
				ascdg.generateSCProdData();
297
				} catch (IOException e) {
298
					GmailUtils gm = new GmailUtils();
299
					String[] sendTo = { "manas.kapoor@shop2020.in" };
300
					try {
301
						gm.sendSSLMessage(sendTo,
302
							"Amazon Products Content Generation Failed",
303
							e.getMessage() + " "
304
									+ Calendar.getInstance().getTime().toString(),
305
							"build@shop2020.in", "cafe@nes", new ArrayList<File>());
306
					} catch (MessagingException e1) {
307
					System.out.println("Could not send status mail" + e);
308
					}
309
				}
310
				catch (Exception e) {
311
					e.printStackTrace();
312
				}
313
		}
4403 amit.gupta 314
	}
315
 
316
	private static String normalizeBatteryType(String batteryType) {
317
		if (batteryType.contains("Li-Ion") || batteryType.contains("Li-ion")
318
				|| batteryType.contains("Lithium-ion")) {
319
			batteryType = "lithium_ion";
320
		} else if (batteryType.contains("Li-Po")) {
321
			batteryType = "lithium_metal";
322
		} else {
323
			batteryType = "";
324
		}
325
		return batteryType;
326
	}
327
 
328
	private static String normalizeFormFactor(String formFactor) {
329
		if (formFactor.equals("Candybar")) {
330
			formFactor = "candy-bar";
331
		} else if (formFactor.equals("Slider")) {
332
			formFactor = "slide";
333
		} else if (formFactor.equals("Flip") || formFactor.equals("Clamshell")) {
334
			formFactor = "slide";
335
		} else {
336
			formFactor = "";
337
		}
338
		return formFactor;
339
	}
340
 
341
	private static String normalizeOperatingSystem(String opsys) {
342
		if (opsys.contains("Android")) {
343
			opsys = "Android";
344
		} else if (opsys.contains("Symbian")) {
345
			opsys = "Symbian";
4409 amit.gupta 346
		} else if (opsys.contains("BlackBerry")) {
4403 amit.gupta 347
			opsys = "Blackberry";
348
		} else if (opsys.contains("Windows")) {
349
			opsys = "Windows Phone";
350
		} else if (opsys.contains("bada") || opsys.contains("Bada")) {
351
			opsys = "Bada";
352
		} else if (opsys.contains("iOS")) {
353
			opsys = "iOS";
354
		} else {
355
			opsys = "";
356
		}
357
 
358
		return opsys;
359
	}
360
 
361
	/**
362
	 * 
363
	 * @return the complete URL of a phone.
364
	 */
4461 amit.gupta 365
	private static String getUrl(Item item, String type) {
366
		String url = "http://www.saholic.com/" + type + "/";
4403 amit.gupta 367
		String productUrl = getHyphenatdName(item);
368
		productUrl = productUrl + "-" + item.getCatalogItemId();
369
		url = url + productUrl;
370
		url = url.replace("--", "-");
15457 amit.gupta 371
		return url + "?afid=112";
4403 amit.gupta 372
	}
4654 amit.gupta 373
 
4441 amit.gupta 374
	/**
375
	 * 
4403 amit.gupta 376
	 * @param item
377
	 * @return the URL path for a mobile phone.
378
	 */
379
	private static String getHyphenatdName(Item item) {
380
		String productUrl = item.getBrand();
381
		if (item.getModelName() != null) {
382
			productUrl = productUrl + "-" + item.getModelName();
383
		}
384
		if (item.getModelNumber() != null) {
385
			productUrl = productUrl + '-' + item.getModelNumber();
386
		}
387
		productUrl = productUrl.replace("/", "-");
388
		productUrl = productUrl.replace(" ", "-");
389
		productUrl = productUrl.replace("--", "-");
390
		productUrl = productUrl.toLowerCase();
391
		return productUrl;
392
	}
393
 
394
	public static Map<Long, String> extractFeatureValuesForEntity(
395
			List<Long> featureIds, Entity entity) throws Exception {
396
		Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
397
 
398
		for (Slide slide : entity.getSlides()) {
4654 amit.gupta 399
			if (slide.getSlideDefinitionID() == 130001L) {
400
				featureIdValuesMap.put(AmazonFeatures.DESCRIPTION.getValue(),
401
						slide.getFreeformContent().getFreeformText().trim()
402
								.replaceAll("\\s+", " "));
4492 amit.gupta 403
			}
4403 amit.gupta 404
			if (slide.hasChildrenSlides()) {
405
				for (Slide sl : slide.getChildrenSlides()) {
406
					if (sl.getFeatures() != null) {
407
						slide.getFeatures().addAll(sl.getFeatures());
408
					}
409
					if (sl.hasChildrenSlides()) {
410
						for (Slide sl2 : sl.getChildrenSlides()) {
411
							if (sl2.getFeatures() != null) {
412
								slide.getFeatures().addAll(sl2.getFeatures());
413
							}
414
						}
415
					}
416
				}
417
 
418
			}
419
			if (slide.getFeatures() == null) {
420
				continue;
421
			}
422
			for (Feature feature : slide.getFeatures()) {
423
				if (featureIds.contains(feature.getFeatureDefinitionID())) {
424
					String value = "";
425
					ExpandedFeature expFeature = new ExpandedFeature(feature);
426
					if (expFeature.getExpandedBullets() != null) {
427
						int count = 0;
428
						for (ExpandedBullet expBullet : expFeature
429
								.getExpandedBullets()) {
430
							if (count == 0) {
431
								value = value + expBullet.displayText();
432
							} else {
433
								value = value + " -- "
434
										+ expBullet.displayText();
435
							}
436
							count++;
437
						}
438
					}
439
					featureIdValuesMap.put(feature.getFeatureDefinitionID(),
440
							value);
441
				}
442
			}
443
		}
444
		return featureIdValuesMap;
445
	}
4654 amit.gupta 446
 
447
	public static Map<Long, String> extractFeatureValuesForEntity(Entity entity)
448
			throws Exception {
4441 amit.gupta 449
		Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
450
		for (Slide slide : entity.getSlides()) {
4654 amit.gupta 451
			if (slide.getSlideDefinitionID() == 130001L) {
452
				featureIdValuesMap.put(AmazonFeatures.DESCRIPTION.getValue(),
453
						slide.getFreeformContent().getFreeformText().trim()
454
								.replaceAll("\\s+", " "));
4577 amit.gupta 455
			}
4441 amit.gupta 456
			if (slide.hasChildrenSlides()) {
457
				for (Slide sl : slide.getChildrenSlides()) {
458
					if (sl.getFeatures() != null) {
459
						slide.getFeatures().addAll(sl.getFeatures());
460
					}
461
					if (sl.hasChildrenSlides()) {
462
						for (Slide sl2 : sl.getChildrenSlides()) {
463
							if (sl2.getFeatures() != null) {
464
								slide.getFeatures().addAll(sl2.getFeatures());
465
							}
466
						}
467
					}
468
				}
4403 amit.gupta 469
 
4441 amit.gupta 470
			}
471
			if (slide.getFeatures() == null) {
472
				continue;
4654 amit.gupta 473
 
4441 amit.gupta 474
			}
475
			for (Feature feature : slide.getFeatures()) {
4480 amit.gupta 476
				String value = "";
477
				ExpandedFeature expFeature = new ExpandedFeature(feature);
478
				if (expFeature.getExpandedBullets() != null) {
479
					int count = 0;
480
					for (ExpandedBullet expBullet : expFeature
481
							.getExpandedBullets()) {
482
						if (count == 0) {
483
							value = value + expBullet.displayText();
484
						} else {
4654 amit.gupta 485
							value = value + " -- " + expBullet.displayText();
4441 amit.gupta 486
						}
4480 amit.gupta 487
						count++;
488
					}
4441 amit.gupta 489
				}
4654 amit.gupta 490
				featureIdValuesMap.put(feature.getFeatureDefinitionID(), value);
4441 amit.gupta 491
			}
4654 amit.gupta 492
 
4441 amit.gupta 493
		}
494
		return featureIdValuesMap;
495
	}
496
 
13386 manas 497
	public static Map<Long, String> getAllImageUrls(Entity entity,
498
			List<Item> items) throws Exception {
4403 amit.gupta 499
		Map<Long, String> imageUrlMap = new HashMap<Long, String>();
500
		ExpandedEntity expEntity = new ExpandedEntity(entity);
501
		Map<String, Media> medias = expEntity.getAllMedias();
5257 amit.gupta 502
		for (Item item : items) {
4403 amit.gupta 503
			String url = "";
504
			String color = item.getColor();
505
			if (color == null) {
506
				color = "jsfhdjsfdhjfdfhdjffh";
507
			}
508
			String parts[] = color.split("(-|&|\\s|\\+|and|NA|\\.)+");
509
			url = "http://static0.saholic.com/images/media"
510
					+ File.separator
511
					+ entity.getID()
512
					+ File.separator
513
					+ NewVUI.computeNewFileName(EntityUtils
514
							.getMediaPrefix(expEntity), "default.jpg", String
515
							.valueOf(EntityUtils
516
									.getCreationTimeFromSummarySlide(expEntity,
517
											"default")));
518
			for (String part : parts) {
519
				if (part.length() < 3) {
520
					continue;
521
				}
522
				for (String label : expEntity.getAllImageLabels()) {
523
					if (!StringUtils.containsIgnoreCase(label, part.trim())) {
524
						url = "http://static0.saholic.com/images/media"
525
								+ File.separator
526
								+ entity.getID()
527
								+ File.separator
528
								+ NewVUI.computeNewFileName(
529
										EntityUtils.getMediaPrefix(expEntity),
530
										"default.jpg",
531
										String.valueOf(EntityUtils
532
												.getCreationTimeFromSummarySlide(
533
														expEntity, "default")));
534
						continue;
535
					} else {
536
						url = "http://static0.saholic.com/images/media"
537
								+ File.separator
538
								+ entity.getID()
539
								+ File.separator
540
								+ NewVUI.computeNewFileName(
541
										EntityUtils.getMediaPrefix(expEntity),
542
										medias.get(label).getFileName(),
543
										String.valueOf(medias.get(label)
544
												.getCreationTime().getTime()));
545
						break;
546
					}
547
				}
548
			}
549
			imageUrlMap.put(item.getId(), url);
550
		}
551
 
552
		return imageUrlMap;
553
	}
554
 
555
	/**
556
	 * 
557
	 * @return the title of the Item in the format required by Amazon: <Brand>
558
	 *         <Model Name> <Model Number> | <Color>
559
	 */
560
	private static String getTitle(Item item) {
561
		String title = item.getBrand();
562
		if (!StringUtils.isEmpty(item.getModelName())) {
563
			title = title + " " + item.getModelName();
564
		}
565
		if (!StringUtils.isEmpty(item.getModelNumber())) {
566
			title = title + " " + item.getModelNumber();
567
		}
4654 amit.gupta 568
		if (!(StringUtils.isEmpty(item.getColor()) || item.getColor()
569
				.equalsIgnoreCase("NA"))) {
4403 amit.gupta 570
			title = title + " | " + item.getColor();
571
		}
572
		return title;
573
	}
4654 amit.gupta 574
 
4403 amit.gupta 575
	private static String normalizeScreenType(String screenType) {
576
		if (screenType == null) {
577
			return "";
578
		}
579
		if (screenType.indexOf("LCD") >= 0 || screenType.indexOf("Nova") >= 0
580
				|| screenType.indexOf("Retina") >= 0) {
581
			screenType = "LCD";
582
		} else if (screenType.indexOf("LED") >= 0) {
583
			screenType = "LED";
584
		} else {
585
			screenType = "";
586
		}
587
		return screenType;
588
	}
589
 
590
	private static String getCellularTechnology(String multipleSIM,
591
			String network3G) {
592
		String cellularTechnology = "";
593
		if ("Dual-SIM".equals(multipleSIM)) {
594
			cellularTechnology = "Dual SIM";
595
		}
596
		if (StringUtils.isEmpty(cellularTechnology)) {
597
			if (!"".equals(network3G)) {
598
				cellularTechnology = "3G";
599
			} else {
600
				cellularTechnology = "GSM";
601
			}
602
		}
603
		return cellularTechnology;
604
	}
13386 manas 605
	private Element elementData(Document doc, String name,String value) {
606
	    Element el = doc.createElement(name);
607
	    el.appendChild(doc.createTextNode(value));
608
	    return el;
609
	}
13580 manas 610
	public void generateLaptopAccessoriesXML(List<Entity> entities) throws Exception {
611
		String headerArray[] = {"SKU", "Title", "Link",
612
				"Price", "DeliveryTime", "RecommendedBrowseNode",
613
				"StandardProductID", "ProductIDType", "Category",
614
				"Brand", "Manufacturer", "Mfrpartnumber",
615
				"ModelNumber", "Description", "ShippingCost",
616
				"Image", "ListPrice", "Availability",
617
				"OperatingSystem", "ProcessorType",
618
				"ProcessorBrand", "ComputerCPUSpeed",
619
				"HardDiskSize", "IncludedRAMsize", "DisplaySize",
620
				"DisplayTechnology", "MemoryStorageCapacity",
621
				"ConnectivityTechnology", "WirelessType",
622
				"ScreenResolution", "MemoryCardType", "ColourName",
623
				"ColourMap", "ItemPackageQuantity", "Warranty",
624
				"AssemblyRequired", "BatteryCellComposition",
625
				"BatteriesIncluded", "BatteriesRequired",
626
				"PowerSource", "PowerAdapterIncluded",
627
				"ShippingWeight", "Weight", "Length", "Height",
628
				"Width", "Keywords1", "Keywords2", "Keywords3",
629
				"Keywords4", "Keywords5", "BulletPoint1",
630
				"BulletPoint2", "BulletPoint3", "BulletPoint4",
631
				"BulletPoint5", "OtherImageurl1",
632
				"OtherImageurl2", "OtherImageurl3",
633
				"OtherImageurl4", "OtherImageurl5", "OfferNote",
634
				"DiscountAmount", "JungleeExclusiveOffer",
635
				"OfferPromoCode", "IsGiftWrapAvailable",
636
				"RegisteredParameter", "UpdateDelete",
637
				"HardDiskFormat", "AcceptedPaymentMethods"};
638
 
639
				// filter only laptop related entities
640
				for (Entity entity : entities) {
641
					List<Item> items = getItemsByCatalogId(entity.getID());
642
					Category category = Catalog.getInstance().getDefinitionsContainer()
643
							.getCategory(entity.getCategoryID());
644
					if (category == null) {
645
						continue;
646
					}
647
					if (entity == null || entity.getSlides() == null
648
							|| category.getParentCategory().getID() != 10070) {
649
						continue;
650
					}
651
 
652
 
653
					AmazonCategories azCategory = null;
654
					Long categoryId = category.getID();
655
					if (categoryId.equals(10071L)) {
656
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_RAM;
657
					}else if (categoryId.equals(10074L)) {
658
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_USB_HUBS;
659
					}/*else if (categoryId.equals(10075L)) {
660
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_SOLID_STATE_DRIVERS;
661
					}*/else if (categoryId.equals(10076L)) {
662
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_WI_FI_ROUTERS;
663
					}else if (categoryId.equals(10080L)) {
664
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_KEYBOARDS;
665
					}else if (categoryId.equals(10081L)) {
666
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_MICE;
667
					}else if (categoryId.equals(10072L)) {
668
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_COOLINGS_STAND;
669
					}else if (categoryId.equals(10084L)) {
670
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_MOUSE_PADS;
671
					}else if (categoryId.equals(10085L)) {
672
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_LAPTOPS_BAGS;
673
					}else if (categoryId.equals(10087L)) {
674
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_PRINTER_CATRIDGES;
675
					}else {
676
						continue;
677
					}
678
					System.out.println("Category " + azCategory);
679
					Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
680
 
681
					Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
682
					String metaKeywords = StringUtils.defaultString(fvalues.get(AmazonFeatures.META_KEYWORDS.getValue()));
683
					List<String> keywords = new ArrayList<String>();
684
 
685
					String bulletsString = StringUtils.defaultString(fvalues.get(120081L));
686
					List<String> bullets = new ArrayList<String>();
687
					for (String keyword : bulletsString.split("--")) {
688
						bullets.add(keyword.trim().replaceAll("\\s+", " "));
689
					}
690
					for (String keyword : metaKeywords.split(",")) {
691
						keywords.add(keyword.trim());
692
					}
693
 
694
					int length1 = keywords.size();
695
					if (length1 < 5) {
696
						while (length1 < 5) {
697
							keywords.add("");
698
							length1 = length1 + 1;
699
						}
700
					}
701
					int length2 = bullets.size();
702
					if (length2 < 5) {
703
						while (length2 < 5) {
704
							bullets.add("");
705
							length2 = length2 + 1;
706
						}
707
					}
708
 
709
					CollectionUtils.filter(items, predicateLive);
710
					if (CollectionUtils.isEmpty(items))
711
						continue;
712
					/*	String storageCapacity = "";
713
					String warranty = StringUtils.defaultString(fvalues.get(120125L))
714
							+ " " + StringUtils.defaultString(fvalues.get(120219L));
715
					String batteryType = StringUtils
716
							.defaultString(fvalues.get(120103L));*/
717
					/*if (azCategory.equals(AmazonCategories.COMPUTER_ACCESSORY_FLASH_DRIVE)) {
718
						storageCapacity = StringUtils.defaultString(fvalues.get(120112L));
719
					}
720
					if (azCategory.equals(AmazonCategories.MOBILE_ACCESSORY_BATTERIES)) {
721
 
722
					}
723
					if (azCategory.equals(AmazonCategories.ACCESSORY_MICROSD)) {
724
						storageCapacity = StringUtils.defaultString(fvalues
725
								.get(120099L));
726
					}*/
727
 
728
					for (Item item : items) {
729
						String productType = "";
730
						String productId = "";
731
						Long itemId = item.getId();
732
						List<String> itemNumbers = getItemNumbers(itemId);
733
						if (!itemNumbers.isEmpty()) {
734
							for (String itemNumber : itemNumbers) {
735
								itemNumber = itemNumber.replaceAll("-", "");
736
								try {
737
									Long.parseLong(itemNumber);
738
								} catch (NumberFormatException nfe) {
739
									continue;
740
								}
741
								if (itemNumber.length() == 13) {
742
									productType = "EAN";
743
								} else if (itemNumber.length() == 12) {
744
									productType = "UPC";
745
								}
746
								productId = itemNumber;
747
								break;
748
							}
749
						}
750
						Element row = docu.createElement(rowHeader);
751
						rootElement.appendChild(row);
752
						String dataArray[] =  {
753
								new Long(item.getId()).toString(),
754
								getTitle(item),
755
								getUrl(item, "laptop-accessories"),
756
								"" + (int) (item.getSellingPrice()),
757
								"1",
758
								azCategory == null ? "" : azCategory
759
										.getValue().toString(),
760
								productId,
761
								productType,
762
								"LaptopAndAccessories",
763
								item.getBrand(),
764
								item.getBrand(),
765
								"",
766
								item.getModelNumber(),
767
								item.getFeatureDescription(),
768
								"0",
769
								itemIdImageUrlMap.get(item.getId()),
770
								""
771
										+ (item.getMrp() == 0 ? (int) item
772
												.getSellingPrice()
773
												: (int) (item.getMrp())),
774
								getAvailability(item),
775
								"",
776
								"",
777
								"",
778
								"",
779
								"",
780
								"",
781
								"",
782
								"",
783
								"",
784
								"",
785
								"",
786
								"",
787
								"",
788
								item.getColor(),
789
								"",
790
								"",
791
								"",
792
								"",
793
								"",
794
								"",
795
								"",
796
								"",
797
								"",
798
								"",
799
								"",
800
								"",
801
								"",
802
								"",
803
								keywords.get(0),
804
								keywords.get(1),
805
								keywords.get(2),
806
								keywords.get(3),
807
								keywords.get(4),
808
								bullets.get(0),
809
								bullets.get(1),
810
								bullets.get(2),
811
								bullets.get(3),
812
								bullets.get(4),
813
								"",
814
								"",
815
								"",
816
								"",
817
								"",
818
								"",
819
								"",
820
								"",
821
								"",
822
								item.getItemStatus().equals(
823
										status.PHASED_OUT) ? "Delete"
824
										: "",
825
								"credit_card|debit_card|net_banking|emi"
826
										+ (Double
827
												.valueOf(250D)
828
												.compareTo(
829
														item.getSellingPrice()) <= 0
830
												&& Double
831
														.valueOf(25000D)
832
														.compareTo(
833
																item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
834
												: "") };
835
 
836
						for(int loopCount=0;loopCount<dataArray.length;loopCount++){
837
							if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
838
								continue;
839
							row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
840
						}
841
					}					
842
				}
843
	}
844
 
845
	public void generateSmartWatchData(List<Entity> entities) throws Exception {
846
		String headerArray[] = {"SKU", "Title", "Link",
847
		"Price", "DeliveryTime", "RecommendedBrowseNode",
848
		"StandardProductID", "ProductIDType", "Category",
849
		"Brand", "Manufacturer", "MfrPartNumber",
850
		"ModelNumber", "Description", "ShippingCost",
851
		"Image", "ListPrice", "Availability",
852
		"OperatingSystem", "WirelessType", "Digitalzoom",
853
		"Megapixels", "DisplaySize", "CellularTechnology",
854
		"TalkTime", "StandbyTime", "ChargingTime",
855
		"UserInput", "DeviceType", "FormFactor",
856
		"ConnectivityTechnology", "SpecialFeatures",
857
		"MemoryStorageCapacity", "OpticalZoom",
858
		"MemoryCardType", "ColourName", "ColourMap",
859
		"ItemPackageQuantity", "Warranty",
860
		"AssemblyRequired", "BatteryCellComposition",
861
		"BatteriesIncluded", "BatteriesRequired",
862
		"PowerSource", "PowerAdapterIncluded",
863
		"ShippingWeight", "Weight", "Length", "Height",
864
		"Width", "Keywords1", "Keywords2", "Keywords3",
865
		"Keywords4", "Keywords5", "BulletPoint1",
866
		"BulletPoint2", "BulletPoint3", "BulletPoint4",
867
		"BulletPoint5", "OtherImageurl1",
868
		"OtherImageurl2", "OtherImageurl3",
869
		"OtherImageurl4", "OtherImageurl5", "OfferNote",
870
		"DiscountAmount", "JungleeExclusiveOffer",
871
		"OfferPromoCode", "IsGiftWrapAvailable",
872
		"RegisteredParameter", "UpdateDelete",
873
		"AcceptedPaymentMethods"};
874
 
875
		rootElement=docu.getDocumentElement();
876
		for (Entity entity : entities) {
877
			if (Catalog.getInstance().getDefinitionsContainer()
878
					.getCategory(entity.getCategoryID()) == null) {
879
				continue;
880
			}
881
			if (entity == null
882
					|| entity.getSlides() == null
883
					|| Catalog.getInstance().getDefinitionsContainer()
884
							.getCategory(entity.getCategoryID())
885
							.getParentCategory().getID() != 12100) {
886
				continue;
887
			}
888
			// Treat phone related entities now.
889
			// get Feature values for all entities required for amazon.
890
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
891
			List<Item> items = getItemsByCatalogId(entity.getID());
892
			CollectionUtils.filter(items, predicateLive);
893
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
894
			if (CollectionUtils.isEmpty(items))
895
				continue;
896
			String screenSize = StringUtils.defaultString(fvalues.get(AmazonFeatures.SCREEN_SIZE_IN.getValue()));
897
			String weight = StringUtils.defaultString(fvalues.get(AmazonFeatures.WEIGHT.getValue()));
898
			String screenResolution = StringUtils.defaultString(fvalues.get(AmazonFeatures.SCREEN_RESOLUTION.getValue()));
899
			String formFactor = StringUtils.defaultString(fvalues.get(AmazonFeatures.FORM_FACTOR.getValue()));
900
			String warranty = StringUtils.defaultString(fvalues.get(AmazonFeatures.WARRANTY.getValue()));
901
			String connectivityTechonology = StringUtils.defaultString(fvalues.get(120500L));
902
			String size = StringUtils.defaultString(fvalues.get(120496L));
903
			String metaKeywords = StringUtils.defaultString(fvalues.get(AmazonFeatures.META_KEYWORDS.getValue()));
904
			String color = StringUtils.defaultString(fvalues.get(AmazonFeatures.COLOR.getValue())).split("--")[0];
905
 
906
			String display = StringUtils.defaultString(fvalues.get(120407L));
907
			System.out.println("Display " + display);
908
			String storageCapacity = StringUtils.defaultString(fvalues.get(120499L));
909
 
910
			String battery = StringUtils.defaultString(fvalues.get(120448L));
911
			if (!StringUtils.isEmpty(screenSize)) {
912
				screenSize = screenSize.split("\\s+")[0];
913
			}
914
			if (!StringUtils.isEmpty(screenResolution)) {
915
				screenResolution = screenResolution.substring(0,
916
						screenResolution.lastIndexOf(" "));
917
			}
918
 
919
			display = normalizeScreenType(display);
920
 
921
			formFactor = normalizeFormFactor(formFactor);
922
 
923
			if (StringUtils.isNotEmpty(warranty)) {
924
				warranty = warranty + " manufacturer warranty";
925
			}
926
			battery = normalizeBatteryType(battery);
927
 
928
			String[] weightParts = weight.split("\\s+");
929
			if (weightParts.length > 1) {
930
				weight = weightParts[0];
931
				try {
932
					Float.parseFloat(weight);
933
				} catch (NumberFormatException e) {
934
					System.out.println(entity.getID()
935
							+ "has invalid weight format");
936
					// e.printStackTrace();
937
					weight = "";
938
				}
939
			}
940
			String length = "", width = "", height = "";
941
 
942
			System.out.println("Size " + size.replaceAll("[^?0-9.]+", " "));
943
			String replaceSize = size.replaceAll("[^?0-9.]+", " ");
944
			if (!(size.equals("Not available") || size.equals(""))) {
945
				String[] list = replaceSize.split(" ");
13594 amit.gupta 946
				length = list[0] + " MM";
947
				width = list[1] + " MM";
948
				height = list[2] + " MM";
13580 manas 949
			}
950
 
951
			List<String> keywords = new ArrayList<String>();
952
			for (String keyword : metaKeywords.split(",")) {
953
				keywords.add(keyword.trim());
954
			}
955
			int length1 = keywords.size();
956
			if (length1 < 5) {
957
				while (length1 < 5) {
958
					keywords.add("");
959
					length1 = length1 + 1;
960
				}
961
			}
962
			for (String keyword : keywords) {
963
				if (keyword.length() > 50)
964
					System.out.println(keyword);
965
			}
966
 
967
			for (Item item : items) {
968
				Long itemId = item.getId();
969
 
970
				List<String> itemNumbers = getItemNumbers(itemId);
971
				String productId = "";
972
				String productType = "";
973
				if (!itemNumbers.isEmpty()) {
974
					for (String itemNumber : itemNumbers) {
975
						System.out.println("itemNumber " + itemNumber);
976
						itemNumber = itemNumber.replaceAll("-", "");
977
						try {
978
							Long.parseLong(itemNumber);
979
						} catch (NumberFormatException nfe) {
980
							nfe.printStackTrace();
981
							continue;
982
						}
983
						if (itemNumber.length() == 13) {
984
							productType = "EAN";
985
						} else if (itemNumber.length() == 12) {
986
							productType = "UPC";
987
						}
988
						productId = itemNumber;
989
						if (!productType.equals("")) {
990
							break;
991
						}
992
					}
993
				}
994
 
995
				if (item.getColor() != null) {
996
					color = item.getColor();
997
				}
998
				String imageUrl = itemIdImageUrlMap.get(itemId);
999
				Element row = docu.createElement(rowHeader);
1000
				rootElement.appendChild(row);
1001
 
1002
				String dataArray[] ={
1003
						new Long(item.getId()).toString(),
1004
						getTitle(item),
1005
						getUrl(item, "smart-watches"),
1006
						"" + (int) (item.getSellingPrice()),
1007
						"1",
1008
						"5605729031",
1009
						productId,
1010
						productType,
1011
						"SmartWatches",
1012
						item.getBrand(),
1013
						item.getBrand(),
1014
						"",
1015
						item.getModelNumber(),
1016
						StringUtils.defaultString(fvalues
1017
								.get(AmazonFeatures.DESCRIPTION
1018
										.getValue())),
1019
						"0",
1020
						imageUrl,
1021
						""
1022
								+ (item.getMrp() == 0 ? (int) item
1023
										.getSellingPrice()
1024
										: (int) (item.getMrp())),
1025
						getAvailability(item),
1026
						"",
1027
						"",
1028
						"",
1029
						StringUtils.defaultString(
1030
								fvalues.get(120026L))
1031
								.split(" ")[0],// Digital zoom,
1032
												// Megapixel
1033
						screenSize,
1034
						"",
1035
						"",// Talktime
1036
						"",// Standby time
1037
						"", // charging time
1038
						"",
1039
						"", // device type
1040
						formFactor,
1041
						connectivityTechonology, // connectivity Technologies
1042
						"", // Special features
1043
						StringUtils.defaultString(fvalues
1044
								.get(AmazonFeatures.BUILTIN_MEMORY
1045
										.getValue())),
1046
						"",// Optical zoom
1047
						"", // Memory Card Type
1048
						color,
1049
						"", // color map
1050
						"1",
1051
						warranty,
1052
						"false",// assembly
1053
						battery,
1054
						"true", // Batteries Included
1055
						"true", // Batteries Required
1056
						"battery-powered", // Power Source
1057
						"true", // Power Adapter inculded
1058
						"", // shipping weight
1059
						weight, // Weight
1060
						length,
1061
						height,
1062
						width,
1063
						keywords.get(0),
1064
						keywords.get(1),
1065
						keywords.get(2),
1066
						keywords.get(3),
1067
						keywords.get(4),
1068
						"",
1069
						"",
1070
						"",
1071
						"",
1072
						"",
1073
						"",
1074
						"",
1075
						"",
1076
						"",
1077
						"",
1078
						"",
1079
						"",
1080
						"",
1081
						"",
1082
						"",
1083
						"",
1084
						item.getItemStatus().equals(
1085
								status.PHASED_OUT) ? "Delete"
1086
								: "",
1087
						"credit_card|debit_card|net_banking|emi"
1088
								+ (Double
1089
										.valueOf(250D)
1090
										.compareTo(
1091
												item.getSellingPrice()) <= 0
1092
										&& Double
1093
												.valueOf(25000D)
1094
												.compareTo(
1095
														item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
1096
										: "") };
1097
 
1098
				for(int loopCount=0;loopCount<dataArray.length;loopCount++){
1099
					if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
1100
						continue;
1101
						row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
1102
					}
1103
				}
1104
 
1105
		}
1106
		System.out.println("INFO : Smart Watches data successfully created at /home/amit/Desktop/cms/ successfully generated.");
1107
	}
1108
 
13386 manas 1109
	public void generateMobileAccessoriesXML(List<Entity> entities, String generationType) throws Exception {
1110
		String headerArray[] = {"SKU", "Title", "Link",
1111
				"Price", "DeliveryTime", "RecommendedBrowseNode",
1112
				"StandardProductID", "ProductIDType", "Category",
1113
				"Brand", "Manufacturer", "MfrPartNumber",
1114
				"ModelNumber", "Description", "ShippingCost",
1115
				"Image", "ListPrice", "Availability",
1116
				"OperatingSystem", "WirelessType", "Digitalzoom",
1117
				"Megapixels", "DisplaySize", "CellularTechnology",
1118
				"TalkTime", "StandbyTime", "ChargingTime",
1119
				"UserInput", "DeviceType", "FormFactor",
1120
				"ConnectivityTechnology", "SpecialFeatures",
1121
				"MemoryStorageCapacity", "OpticalZoom",
1122
				"MemoryCardType", "ColourName", "ColourMap",
1123
				"ItemPackageQuantity", "Warranty",
1124
				"AssemblyRequired", "BatteryCellComposition",
1125
				"BatteriesIncluded", "BatteriesRequired",
1126
				"PowerSource", "PowerAdapterIncluded",
1127
				"ShippingWeight", "Weight", "Length", "Height",
1128
				"Width", "Keywords1", "Keywords2", "Keywords3",
1129
				"Keywords4", "Keywords5", "BulletPoint1",
1130
				"BulletPoint2", "BulletPoint3", "BulletPoint4",
1131
				"BulletPoint5", "OtherImageurl1",
1132
				"OtherImageurl2", "OtherImageurl3",
1133
				"OtherImageurl4", "OtherImageurl5", "OfferNote",
1134
				"DiscountAmount", "JungleeExclusiveOffer",
1135
				"OfferPromoCode", "IsGiftWrapAvailable",
1136
				"RegisteredParameter", "UpdateDelete",
1137
				"AcceptedPaymentMethods"};
1138
 
1139
		rootElement=docu.getDocumentElement();
1140
		// filter only phone related entities
1141
		for (Entity entity : entities) {
1142
 
1143
			List<Item> items = getItemsByCatalogId(entity.getID());
1144
			Category category = Catalog.getInstance().getDefinitionsContainer()
1145
					.getCategory(entity.getCategoryID());
1146
			if (category == null) {
1147
				continue;
1148
			}
1149
			if (entity == null || entity.getSlides() == null
1150
					|| category.getParentCategory().getID() != 10011) {
1151
				continue;
1152
			}
1153
 
1154
 
1155
			AmazonCategories azCategory = null;
1156
			Long categoryId = category.getID();
1157
			if (categoryId.equals(10012L)) {
1158
				azCategory = AmazonCategories.MOBILE_ACCESSORY_BLUETOOTH_HEADSETS;
1159
			} else if (categoryId.equals(10013L)) {
1160
				azCategory = AmazonCategories.ACCESSORY_MICROSD;
1161
			} else if (categoryId.equals(10014L)) {
1162
				azCategory = AmazonCategories.MOBILE_ACCESSORY_BATTERIES;
1163
			} else if (categoryId.equals(10015L)) {
1164
				azCategory = AmazonCategories.MOBILE_ACCESSORY_HEADSETS;
1165
			} else if (categoryId.equals(10016L)) {
1166
				azCategory = AmazonCategories.MOBILE_ACCESSORY_MAINS_CHARGERS;
1167
			} else if (categoryId.equals(10017L)) {
1168
				azCategory = AmazonCategories.COMPUTER_ACCESSORY_FLASH_DRIVE;
1169
			} else if (categoryId.equals(10018L) || categoryId.equals(10021L)
1170
					|| categoryId.equals(10022L)) {
1171
				azCategory = AmazonCategories.MOBILE_ACCESSORY_COVERS;
1172
			} else if (categoryId.equals(10019L)) {
1173
				azCategory = AmazonCategories.MOBILE_ACCESSORY_CAR_CHARGERS;
1174
			} else if (categoryId.equals(10020L)) {
1175
				azCategory = AmazonCategories.MOBILE_ACCESSORY_SCREEN_GUARDS;
1176
			} else if (categoryId.equals(10026L)) {
1177
				azCategory = AmazonCategories.MOBILE_ACCESSORY_SPEAKERS;
1178
			} else {
1179
				continue;
1180
			}
1181
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
4654 amit.gupta 1182
 
13386 manas 1183
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
1184
			String metaKeywords = StringUtils.defaultString(fvalues
1185
					.get(AmazonFeatures.META_KEYWORDS.getValue()));
1186
			List<String> keywords = new ArrayList<String>();
1187
 
1188
			String bulletsString = StringUtils.defaultString(fvalues
1189
					.get(120081L));
1190
			List<String> bullets = new ArrayList<String>();
1191
			for (String keyword : bulletsString.split("--")) {
1192
				bullets.add(keyword.trim().replaceAll("\\s+", " "));
1193
			}
1194
			for (String keyword : metaKeywords.split(",")) {
1195
				keywords.add(keyword.trim());
1196
			}
1197
 
1198
			int length1 = keywords.size();
1199
			if (length1 < 5) {
1200
				while (length1 < 5) {
1201
					keywords.add("");
1202
					length1 = length1 + 1;
1203
				}
1204
			}
1205
			int length2 = bullets.size();
1206
			if (length2 < 5) {
1207
				while (length2 < 5) {
1208
					bullets.add("");
1209
					length2 = length2 + 1;
1210
				}
1211
			}
1212
 
1213
			CollectionUtils.filter(items, predicateLive);
1214
			if (CollectionUtils.isEmpty(items))
1215
				continue;
1216
			String storageCapacity = "";
1217
			String warranty = StringUtils.defaultString(fvalues.get(120125L))
1218
					+ " " + StringUtils.defaultString(fvalues.get(120219L));
1219
			String batteryType = StringUtils
1220
					.defaultString(fvalues.get(120103L));
1221
		//	String batteryCap = StringUtils.defaultString(fvalues.get(120104L));
1222
			if (azCategory
1223
					.equals(AmazonCategories.COMPUTER_ACCESSORY_FLASH_DRIVE)) {
1224
				storageCapacity = StringUtils.defaultString(fvalues
1225
						.get(120112L));
1226
			}
1227
			if (azCategory.equals(AmazonCategories.MOBILE_ACCESSORY_BATTERIES)) {
1228
 
1229
			}
1230
			if (azCategory.equals(AmazonCategories.ACCESSORY_MICROSD)) {
1231
				storageCapacity = StringUtils.defaultString(fvalues
1232
						.get(120099L));
1233
			}
1234
 
1235
			for (Item item : items) {
1236
				String productType = "";
1237
				String productId = "";
1238
				Long itemId = item.getId();
1239
				List<String> itemNumbers = getItemNumbers(itemId);
1240
				if (!itemNumbers.isEmpty()) {
1241
					for (String itemNumber : itemNumbers) {
1242
						itemNumber = itemNumber.replaceAll("-", "");
1243
						try {
1244
							Long.parseLong(itemNumber);
1245
						} catch (NumberFormatException nfe) {
1246
							continue;
1247
						}
1248
						if (itemNumber.length() == 13) {
1249
							productType = "EAN";
1250
						} else if (itemNumber.length() == 12) {
1251
							productType = "UPC";
1252
						}
1253
						productId = itemNumber;
1254
						break;
1255
					}
1256
				}
1257
				Element row = docu.createElement(rowHeader);
1258
				rootElement.appendChild(row);
1259
				String dataArray[] =  {
1260
						new Long(item.getId()).toString(),
1261
						getTitle(item),
1262
						getUrl(item, "mobile-accessories"),
1263
						"" + (int) (item.getSellingPrice()),
1264
						"1",
1265
						azCategory == null ? "" : azCategory
1266
								.getValue().toString(),
1267
						productId,
1268
						productType,
1269
						"Wireless",
1270
						item.getBrand(),
1271
						item.getBrand(),
1272
						"",
1273
						item.getModelNumber(),
1274
						item.getFeatureDescription(),
1275
						"0",
1276
						itemIdImageUrlMap.get(item.getId()),
1277
						""
1278
								+ (item.getMrp() == 0 ? (int) item
1279
										.getSellingPrice()
1280
										: (int) (item.getMrp())),
1281
						getAvailability(item),
1282
						"",
1283
						"",
1284
						"",
1285
						"",
1286
						"",
1287
						"",
1288
						"",
1289
						"",
1290
						"",
1291
						"",
1292
						"",
1293
						"",
1294
						"",
1295
						"",
1296
						storageCapacity,
1297
						"",
1298
						"",
1299
						item.getColor(),
1300
						"",
1301
						"",
1302
						warranty,
1303
						"",
1304
						batteryType,
1305
						"",
1306
						"",
1307
						"",
1308
						"",
1309
						"",
1310
						"",
1311
						"",
1312
						"",
1313
						"",
1314
						keywords.get(0),
1315
						keywords.get(1),
1316
						keywords.get(2),
1317
						keywords.get(3),
1318
						keywords.get(4),
1319
						bullets.get(0),
1320
						bullets.get(1),
1321
						bullets.get(2),
1322
						bullets.get(3),
1323
						bullets.get(4),
1324
						"",
1325
						"",
1326
						"",
1327
						"",
1328
						"",
1329
						"",
1330
						"",
1331
						"",
1332
						"",
1333
						"",
1334
						"",
1335
						item.getItemStatus().equals(
1336
								status.PHASED_OUT) ? "Delete"
1337
								: "",
1338
						"credit_card|debit_card|net_banking|emi"
1339
								+ (Double
1340
										.valueOf(250D)
1341
										.compareTo(
1342
												item.getSellingPrice()) <= 0
1343
										&& Double
1344
												.valueOf(25000D)
1345
												.compareTo(
1346
														item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
1347
										: "") };
1348
 
1349
				for(int loopCount=0;loopCount<dataArray.length;loopCount++){
1350
					if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
1351
						continue;
1352
					row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
1353
				}
1354
			}
1355
		}
1356
		//generateXMLfile(mobileXMLFile, doc);
1357
		System.out.println("INFO : Accessories+Mobile.xml successfully created at /home/amit/Desktop/cms/ successfully generated.");
1358
	}
1359
 
1360
	public void generateMobileDataXML(List<Entity> entities) throws Exception {
1361
		String headerArray[] = {"SKU", "Title", "Link",
1362
		"Price", "DeliveryTime", "RecommendedBrowseNode",
1363
		"StandardProductID", "ProductIDType", "Category",
1364
		"Brand", "Manufacturer", "MfrPartNumber",
1365
		"ModelNumber", "Description", "ShippingCost",
1366
		"Image", "ListPrice", "Availability",
1367
		"OperatingSystem", "WirelessType", "Digitalzoom",
1368
		"Megapixels", "DisplaySize", "CellularTechnology",
1369
		"TalkTime", "StandbyTime", "ChargingTime",
1370
		"UserInput", "DeviceType", "FormFactor",
1371
		"ConnectivityTechnology", "SpecialFeatures",
1372
		"MemoryStorageCapacity", "OpticalZoom",
1373
		"MemoryCardType", "ColourName", "ColourMap",
1374
		"ItemPackageQuantity", "Warranty",
1375
		"AssemblyRequired", "BatteryCellComposition",
1376
		"BatteriesIncluded", "BatteriesRequired",
1377
		"PowerSource", "PowerAdapterIncluded",
1378
		"ShippingWeight", "Weight", "Length", "Height",
1379
		"Width", "Keywords1", "Keywords2", "Keywords3",
1380
		"Keywords4", "Keywords5", "BulletPoint1",
1381
		"BulletPoint2", "BulletPoint3", "BulletPoint4",
1382
		"BulletPoint5", "OtherImageurl1",
1383
		"OtherImageurl2", "OtherImageurl3",
1384
		"OtherImageurl4", "OtherImageurl5", "OfferNote",
1385
		"DiscountAmount", "JungleeExclusiveOffer",
1386
		"OfferPromoCode", "IsGiftWrapAvailable",
1387
		"RegisteredParameter", "UpdateDelete",
1388
		"AcceptedPaymentMethods"};
1389
 
1390
		/*DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1391
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
1392
 
1393
		//Document doc;
1394
		Element rootElement=null;
1395
		if (!mobileXMLFile.exists()) {
1396
			docu = docBuilder.newDocument();
1397
	        rootElement = docu.createElement("junglee-feed");
1398
	        docu.appendChild(rootElement);
1399
	        System.out.println("File" + mobileXML + " does not exists in the system.");
1400
	    } else {
1401
	    	docu = docBuilder.parse(mobileXMLFile);
1402
	        rootElement=docu.getDocumentElement();
1403
	    }
1404
		*/
1405
		rootElement=docu.getDocumentElement();
1406
		for (Entity entity : entities) {
1407
			if (Catalog.getInstance().getDefinitionsContainer()
1408
					.getCategory(entity.getCategoryID()) == null) {
1409
				continue;
1410
			}
1411
			if (entity == null
1412
					|| entity.getSlides() == null
1413
					|| Catalog.getInstance().getDefinitionsContainer()
1414
							.getCategory(entity.getCategoryID())
1415
							.getParentCategory().getID() != 10001) {
1416
				continue;
1417
			}
1418
			// Treat phone related entities now.
1419
			// get Feature values for all entities required for amazon.
1420
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
1421
			List<Item> items = getItemsByCatalogId(entity.getID());
1422
			CollectionUtils.filter(items, predicateLive);
1423
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
1424
			if (CollectionUtils.isEmpty(items))
1425
				continue;
1426
			String screenSize = StringUtils.defaultString(fvalues
1427
					.get(AmazonFeatures.SCREEN_SIZE_IN.getValue()));
1428
			String weight = StringUtils.defaultString(fvalues
1429
					.get(AmazonFeatures.WEIGHT.getValue()));
1430
			String screenResolution = StringUtils.defaultString(fvalues
1431
					.get(AmazonFeatures.SCREEN_RESOLUTION.getValue()));
1432
			String screenType = StringUtils.defaultString(fvalues
1433
					.get(AmazonFeatures.SCREEN_TYPE.getValue()));
1434
			String touchscreenType = StringUtils.defaultString(fvalues
1435
					.get(AmazonFeatures.TOUCHSCREEN_TYPE.getValue()));
1436
			String multipleSIM = StringUtils.defaultString(fvalues
1437
					.get(AmazonFeatures.MULTIPLE_SIM.getValue()));
1438
			String network3G = StringUtils.defaultString(fvalues
1439
					.get(AmazonFeatures.NETWORK_3G.getValue()));
1440
			String opsys = StringUtils.defaultString(fvalues
1441
					.get(AmazonFeatures.OS.getValue()));
1442
			String formFactor = StringUtils.defaultString(fvalues
1443
					.get(AmazonFeatures.FORM_FACTOR.getValue()));
1444
			String warranty = StringUtils.defaultString(fvalues
1445
					.get(AmazonFeatures.WARRANTY.getValue()));
1446
			String batteryType = StringUtils.defaultString(fvalues
1447
					.get(AmazonFeatures.BATTERY_TYPE.getValue()));
1448
			String size = StringUtils.defaultString(fvalues
1449
					.get(AmazonFeatures.SIZE.getValue()));
1450
			String metaKeywords = StringUtils.defaultString(fvalues
1451
					.get(AmazonFeatures.META_KEYWORDS.getValue()));
1452
 
1453
			String color = StringUtils.defaultString(
1454
					fvalues.get(AmazonFeatures.COLOR.getValue())).split("--")[0];
1455
 
1456
			if (!StringUtils.isEmpty(screenSize)) {
1457
				screenSize = screenSize.split("\\s+")[0];
1458
			}
1459
			if (!StringUtils.isEmpty(screenResolution)) {
1460
				screenResolution = screenResolution.substring(0,
1461
						screenResolution.lastIndexOf(" "));
1462
			}
1463
 
1464
			screenType = normalizeScreenType(screenType);
1465
 
1466
			String cellularTechnology = getCellularTechnology(multipleSIM,
1467
					network3G);
1468
 
1469
			opsys = normalizeOperatingSystem(opsys);
1470
 
1471
			String userInput = "keypad";
1472
			if (touchscreenType != "") {
1473
				userInput = "touch_screen";
1474
			}
1475
 
1476
			formFactor = normalizeFormFactor(formFactor);
1477
 
1478
			if (StringUtils.isNotEmpty(warranty)) {
1479
				warranty = warranty + " manufacturer warranty";
1480
			}
1481
			batteryType = normalizeBatteryType(batteryType);
1482
 
1483
			String[] weightParts = weight.split("\\s+");
1484
			if (weightParts.length > 1) {
1485
				weight = weightParts[0];
1486
				try {
1487
					Float.parseFloat(weight);
1488
				} catch (NumberFormatException e) {
1489
					System.out.println(entity.getID()
1490
							+ "has invalid weight format");
1491
					// e.printStackTrace();
1492
					weight = "";
1493
				}
1494
			}
1495
			String length = "", width = "", height = "";
1496
			if (!(size.equals("Not available") || size.equals(""))) {
1497
				String[] list = size.split("\\s+");
1498
				length = list[0] + " MM";
1499
				width = list[2] + " MM";
1500
				height = list[4] + " MM";
1501
			}
1502
 
1503
			List<String> keywords = new ArrayList<String>();
1504
			for (String keyword : metaKeywords.split(",")) {
1505
				keywords.add(keyword.trim());
1506
			}
1507
			int length1 = keywords.size();
1508
			if (length1 < 5) {
1509
				while (length1 < 5) {
1510
					keywords.add("");
1511
					length1 = length1 + 1;
1512
				}
1513
			}
1514
			for (String keyword : keywords) {
1515
				if (keyword.length() > 50)
1516
					System.out.println(keyword);
1517
			}
1518
 
1519
			for (Item item : items) {
1520
				Long itemId = item.getId();
1521
 
1522
				List<String> itemNumbers = getItemNumbers(itemId);
1523
				String productId = "";
1524
				String productType = "";
1525
				if (!itemNumbers.isEmpty()) {
1526
					for (String itemNumber : itemNumbers) {
1527
						itemNumber = itemNumber.replaceAll("-", "");
1528
						try {
1529
							Long.parseLong(itemNumber);
1530
						} catch (NumberFormatException nfe) {
1531
							continue;
1532
						}
1533
						if (itemNumber.length() == 13) {
1534
							productType = "EAN";
1535
						} else if (itemNumber.length() == 12) {
1536
							productType = "UPC";
1537
						}
1538
						productId = itemNumber;
1539
						if (!productType.equals("")) {
1540
							break;
1541
						}
1542
					}
1543
				}
1544
 
1545
				if (item.getColor() != null) {
1546
					color = item.getColor();
1547
				}
1548
				String imageUrl = itemIdImageUrlMap.get(itemId);
1549
				Element row = docu.createElement(rowHeader);
1550
				rootElement.appendChild(row);
1551
 
1552
				String dataArray[] ={
1553
						new Long(item.getId()).toString(),
1554
						getTitle(item),
1555
						getUrl(item, "mobile-phones"),
1556
						"" + (int) (item.getSellingPrice()),
1557
						"1",
1558
						"803073031",
1559
						productId,
1560
						productType,
1561
						"Wireless",
1562
						item.getBrand(),
1563
						item.getBrand(),
1564
						"",
1565
						item.getModelNumber(),
1566
						StringUtils.defaultString(fvalues
1567
								.get(AmazonFeatures.DESCRIPTION
1568
										.getValue())),
1569
						"0",
1570
						imageUrl,
1571
						""
1572
								+ (item.getMrp() == 0 ? (int) item
1573
										.getSellingPrice()
1574
										: (int) (item.getMrp())),
1575
						getAvailability(item),
1576
						opsys,
1577
						"",
1578
						"",
1579
						StringUtils.defaultString(
1580
								fvalues.get(120026L))
1581
								.split(" ")[0],// Digital zoom,
1582
												// Megapixel
1583
						screenSize,
1584
						cellularTechnology,
1585
						getMinutesForTalktime(fvalues),// Talktime
1586
						getHoursForStandBy(fvalues),// Standby
1587
													// time
1588
						"", // charging time
1589
						userInput,
1590
						"", // device type
1591
						formFactor,
1592
						"", // connectivity Technologies
1593
						"", // Special features
1594
						StringUtils.defaultString(fvalues
1595
								.get(AmazonFeatures.BUILTIN_MEMORY
1596
										.getValue())),
1597
						"",// Optical zoom
1598
						"", // Memory Card Type
1599
						color,
1600
						"", // color map
1601
						"1",
1602
						warranty,
1603
						"false",// assembly
1604
						batteryType,
1605
						"true", // Batteries Included
1606
						"true", // Batteries Required
1607
						"battery-powered", // Power Source
1608
						"true", // Power Adapter inculded
1609
						"", // shipping weight
1610
						weight, // Weight
1611
						length,
1612
						height,
1613
						width,
1614
						keywords.get(0),
1615
						keywords.get(1),
1616
						keywords.get(2),
1617
						keywords.get(3),
1618
						keywords.get(4),
1619
						"",
1620
						"",
1621
						"",
1622
						"",
1623
						"",
1624
						"",
1625
						"",
1626
						"",
1627
						"",
1628
						"",
1629
						"",
1630
						"",
1631
						"",
1632
						item.getItemStatus().equals(
1633
								status.PHASED_OUT) ? "Delete"
1634
								: "",
1635
						"credit_card|debit_card|net_banking|emi"
1636
								+ (Double
1637
										.valueOf(250D)
1638
										.compareTo(
1639
												item.getSellingPrice()) <= 0
1640
										&& Double
1641
												.valueOf(25000D)
1642
												.compareTo(
1643
														item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
1644
										: "") };
1645
 
1646
				for(int loopCount=0;loopCount<dataArray.length;loopCount++){
1647
					if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
1648
						continue;
1649
						row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
1650
					}
1651
				}
1652
 
1653
		}
1654
		//generateXMLfile(mobileXMLFile, doc);
1655
		generateMobileAccessoriesXML(entities, generationType);
1656
		System.out.println("INFO : MobileData.xml successfully created at /home/amit/Desktop/cms/ successfully generated.");
1657
 
1658
	}
1659
	private void generateCameraDataXML(List<Entity> entities) throws Exception {
1660
 
1661
		String headerArray[] = {"SKU", "Title", "Link",
1662
				"Price", "DeliveryTime", "RecommendedBrowseNode",
1663
				"StandardProductID", "ProductIDType", "Category",
1664
				"Brand", "Manufacturer", "MfrPartNumber",
1665
				"ModelNumber", "Description", "ShippingCost",
1666
				"Image", "ListPrice", "Availability", "OpticalZoom",
1667
				"DigitalZoom", "Megapixels", "Displaysize",
1668
				"MemoryCardType", "ViewFinderType", "FlashType",
1669
				"ImageStabilization", "MinFocalLength",
1670
				"MaxFocalLength", "MountingType", "OfferNote",
1671
				"DiscountAmount", "JungleeExclusiveOffer",
1672
				"OfferPromoCode", "AcceptedPaymentMethods",
1673
				"ScreenResolution", "DisplayTechnology",
1674
				"MemoryStorageCapacity", "ColourName", "ColourMap",
1675
				"ItemPackageQuantity", "Warranty",
1676
				"AssemblyRequired", "BatteryCellComposition",
1677
				"BatteriesIncluded", "BatteriesRequired",
1678
				"PowerSource", "PowerAdapterIncluded",
1679
				"ShippingWeight", "Weight", "Length", "Height",
1680
				"Width", "UpdateDelete" };
1681
 
1682
		/*DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1683
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
1684
 */
1685
		//Document doc;
1686
		/*Element rootElement=null;*/
1687
		/*if (!mobileXMLFile.exists()) {
1688
			//docu = docBuilder.newDocument();
1689
	        rootElement = docu.createElement("junglee-feed");
1690
	        docu.appendChild(rootElement);
1691
	        System.out.println("File" + mobileXML + " does not exists in the system.");
1692
	    } else {
1693
	    	//docu = docBuilder.parse(mobileXMLFile);
1694
	        rootElement=docu.getDocumentElement();
1695
	    }*/
1696
 
1697
		/*if (isFullUpload==true) {
1698
			//docu = docBuilder.newDocument();
1699
	        rootElement = docu.createElement("junglee-feed");
1700
	        docu.appendChild(rootElement);
1701
			rootElement=docu.getDocumentElement();
1702
	        System.out.println("File" + mobileXML + " does not exists in the system.");
1703
	    } else {
1704
	    	//docu = docBuilder.parse(mobileXMLFile);
1705
	        rootElement=docu.getDocumentElement();
1706
	    }
1707
		*/
1708
		rootElement=docu.getDocumentElement();
1709
		for (Entity entity : entities) {
1710
			if (Catalog.getInstance().getDefinitionsContainer()
1711
					.getCategory(entity.getCategoryID()) == null)
1712
				continue;
1713
			long categoryId = entity.getCategoryID();
1714
			if (entity == null || entity.getSlides() == null
1715
					|| (categoryId != 11002 && categoryId != 11003)) {
1716
				continue;
1717
			}
1718
 
1719
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
1720
 
1721
			List<Item> items = getItemsByCatalogId(entity.getID());
1722
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
1723
 
1724
			CollectionUtils.filter(items, predicateLive);
1725
			if (CollectionUtils.isEmpty(items))
1726
				continue;
1727
			String warranty = StringUtils.defaultString(fvalues
1728
					.get(AmazonFeatures.WARRANTY.getValue()));
1729
			String batteryType = StringUtils.defaultString(fvalues
1730
					.get(AmazonFeatures.BATTERY_TYPE.getValue()));
1731
			String weight = StringUtils.defaultString(fvalues
1732
					.get(AmazonFeatures.WEIGHT.getValue()));
1733
			String size = StringUtils.defaultString(fvalues
1734
					.get(AmazonFeatures.SIZE.getValue()));
1735
 
1736
			String length = "", width = "", height = "";
1737
			if (!(size.equals("Not available") || size.equals(""))) {
1738
				String[] list = size.split("\\s+");
1739
				length = list[0] + " MM";
1740
				width = list[2] + " MM";
1741
				height = list[4] + " MM";
1742
			}
1743
 
1744
			String flashmount = StringUtils.defaultString(fvalues.get(120392l))
1745
					.split(" ")[0];
1746
			if (flashmount.equals("Sony")) {
1747
				flashmount = "Minoltabayonet";
1748
			} else if (!flashmount.equals("")) {
1749
				flashmount = flashmount.concat("bayonet");
1750
			}
1751
			for (Item item : items) {
1752
				String productId = "";
1753
				String productType = "";
1754
				Long itemId = item.getId();
1755
				List<String> itemNumbers = getItemNumbers(itemId);
1756
				if (!itemNumbers.isEmpty()) {
1757
					for (String itemNumber : itemNumbers) {
1758
						itemNumber = itemNumber.replaceAll("-", "");
1759
						try {
1760
							Long.parseLong(itemNumber);
1761
						} catch (NumberFormatException nfe) {
1762
							continue;
1763
						}
1764
						if (itemNumber.length() == 13) {
1765
							productType = "EAN";
1766
						} else if (itemNumber.length() == 12) {
1767
							productType = "UPC";
1768
						}
1769
						productId = itemNumber;
1770
						break;
1771
					}
1772
				}
1773
				if (item.getColor() == null) {
1774
					item.setColor("");
1775
				}
1776
				String sensorResolution = "";
1777
				String viewFinder = "none";
1778
				if (categoryId == 11002l) {
1779
					sensorResolution = StringUtils.defaultString(fvalues
1780
							.get(120026l));
1781
					String vf = StringUtils.defaultString(fvalues.get(120342));
1782
					if (vf == "Optical viewfinder") {
1783
						viewFinder = "optical";
1784
					} else if (vf == "Electronic viewfinder") {
1785
						viewFinder = "digital";
1786
					}
1787
				} else {
1788
					viewFinder = "optical";
1789
				}
1790
 
1791
				String focalString = StringUtils.defaultString(fvalues
1792
						.get(120336l));
1793
				Matcher m = patt.matcher(focalString);
1794
				int i = 0;
1795
				String[] focalLength = { "", "" };
1796
				while (i < 2 && m.find()) {
1797
					focalLength[i] = m.group();
1798
					i++;
1799
				}
1800
 
1801
				String imageUrl = itemIdImageUrlMap.get(itemId);
1802
 
1803
				Element row = docu.createElement(rowHeader);
1804
 
1805
				if (categoryId != 10073) {
1806
					rootElement.appendChild(row);
1807
					String dataArray[] = {itemId.toString(),
1808
							getTitle(item),
1809
							getUrl(item, "cameras"),
1810
							"" + (int) (item.getSellingPrice()),
1811
							"1",
1812
							categoryId == 11002 ? "802863031"
1813
									: "802865031",
1814
							productId,// productId,
1815
							productType, // productType,
1816
							"CamerasAndAccessories",
1817
							item.getBrand(),
1818
							item.getBrand(),
1819
							"",
1820
							item.getModelNumber(),
1821
							StringUtils.defaultString(fvalues
1822
									.get(AmazonFeatures.DESCRIPTION
1823
											.getValue())),
1824
							"0",
1825
							imageUrl,
1826
							""
1827
									+ (item.getMrp() == 0 ? (int) item
1828
											.getSellingPrice()
1829
											: (int) (item
1830
													.getMrp())),
1831
							getAvailability(item),
1832
							StringUtils.defaultString(fvalues
1833
									.get(120332l)),// Optical
1834
													// Zoom
1835
							StringUtils.defaultString(fvalues
1836
									.get(120333l)),// Digital
1837
													// Zoom
1838
							sensorResolution, // Megapixels
1839
							StringUtils.defaultString(fvalues
1840
									.get(120005l)),// Display
1841
													// Size
1842
							"",// Memory card type
1843
							viewFinder,
1844
							"other",
1845
							fvalues.containsKey(120374l) ? "yes"
1846
									: "no", // image
1847
											// stabilization
1848
							focalLength[0],
1849
							focalLength[1],
1850
							flashmount,
1851
							"",
1852
							"",
1853
							"",
1854
							"",
1855
							"credit_card|debit_card|net_banking|emi"
1856
									+ (Double
1857
											.valueOf(250D)
1858
											.compareTo(
1859
													item.getSellingPrice()) <= 0
1860
											&& Double
1861
													.valueOf(
1862
															25000D)
1863
													.compareTo(
1864
															item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
1865
											: ""),
1866
							getResolution(Integer.parseInt(StringUtils
1867
									.defaultString(
1868
											fvalues.get(120340l)
1869
													.split(" ")[0],
1870
											"0"))),
1871
							StringUtils.defaultString(
1872
									fvalues.get(120091l))
1873
									.split(" ")[0],
1874
							"",
1875
							item.getColor(),
1876
							"",
1877
							"",
1878
							warranty.equals("") ? ""
1879
									: warranty
1880
											+ " manufacturer's warranty",
1881
							"false",
1882
							normalizeBatteryType(batteryType),
1883
							"true", "true", "battery-powered",
1884
							"true", "", weight, length, height,
1885
							width, "" }; 
1886
 
1887
					for(int loopCount=0;loopCount<dataArray.length;loopCount++){
1888
						if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
1889
							continue;
1890
						row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
1891
					}
1892
 
1893
				}
1894
 
1895
			}
1896
		}
1897
		//generateXMLfile(mobileXMLFile, doc);
1898
		System.out.println("INFO : Camera.xml successfully created at /home/amit/Desktop/cms/ successfully generated.");
1899
		return;
1900
 
1901
	}
1902
 
1903
	private void generateLaptopDataXML(List<Entity> entities) throws Exception {
1904
		String headerArray[] = {"SKU", "Title", "Link",
1905
				"Price", "DeliveryTime", "RecommendedBrowseNode",
1906
				"StandardProductID", "ProductIDType", "Category",
1907
				"Brand", "Manufacturer", "Mfrpartnumber",
1908
				"ModelNumber", "Description", "ShippingCost",
1909
				"Image", "ListPrice", "Availability",
1910
				"OperatingSystem", "ProcessorType",
1911
				"ProcessorBrand", "ComputerCPUSpeed",
1912
				"HardDiskSize", "IncludedRAMsize", "DisplaySize",
1913
				"DisplayTechnology", "MemoryStorageCapacity",
1914
				"ConnectivityTechnology", "WirelessType",
1915
				"ScreenResolution", "MemoryCardType", "ColourName",
1916
				"ColourMap", "ItemPackageQuantity", "Warranty",
1917
				"AssemblyRequired", "BatteryCellComposition",
1918
				"BatteriesIncluded", "BatteriesRequired",
1919
				"PowerSource", "PowerAdapterIncluded",
1920
				"ShippingWeight", "Weight", "Length", "Height",
1921
				"Width", "Keywords1", "Keywords2", "Keywords3",
1922
				"Keywords4", "Keywords5", "BulletPoint1",
1923
				"BulletPoint2", "BulletPoint3", "BulletPoint4",
1924
				"BulletPoint5", "OtherImageurl1",
1925
				"OtherImageurl2", "OtherImageurl3",
1926
				"OtherImageurl4", "OtherImageurl5", "OfferNote",
1927
				"DiscountAmount", "JungleeExclusiveOffer",
1928
				"OfferPromoCode", "IsGiftWrapAvailable",
1929
				"RegisteredParameter", "UpdateDelete",
1930
				"HardDiskFormat", "AcceptedPaymentMethods"};
1931
 
1932
		/*DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1933
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
1934
 
1935
		Document doc = docBuilder.newDocument();
1936
		Element rootElement = doc.createElement("junglee-feed");
1937
		doc.appendChild(rootElement);*/
1938
 
1939
		/*DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1940
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();*/
1941
 
1942
		//Document doc;
1943
		/*Element rootElement=null;
1944
		if (!mobileXMLFile.exists()) {
1945
	        doc = docBuilder.newDocument();
1946
	        rootElement = doc.createElement("junglee-feed");
1947
	        doc.appendChild(rootElement);
1948
		//	docu = docBuilder.newDocument();
1949
	        rootElement = docu.createElement("junglee-feed");
1950
	        docu.appendChild(rootElement);
1951
	        System.out.println("File" + mobileXML + " does not exists in the system.");
1952
	    } else {
1953
	    	//docu = docBuilder.parse(mobileXMLFile);
1954
	        rootElement=docu.getDocumentElement();
1955
	    }*/
1956
		 rootElement=docu.getDocumentElement();
1957
		for (Entity entity : entities) {
1958
			if (Catalog.getInstance().getDefinitionsContainer()
1959
					.getCategory(entity.getCategoryID()) == null)
1960
				continue;
1961
			long categoryId = Catalog.getInstance().getDefinitionsContainer()
1962
					.getCategory(entity.getCategoryID()).getID();
1963
			if (entity == null
1964
					|| entity.getSlides() == null
1965
					|| (categoryId != 10050 && categoryId != 10010 && categoryId != 10073)) {
1966
				continue;
1967
			}
1968
 
1969
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
1970
 
1971
			String displayTechnology = StringUtils.defaultString(fvalues.get(120008L));
1972
			if (displayTechnology.equals("")) {
1973
				displayTechnology = StringUtils.defaultString(fvalues.get(120175L));
1974
			}
1975
 
1976
			List<Item> items = getItemsByCatalogId(entity.getID());
1977
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
1978
 
1979
			CollectionUtils.filter(items, predicateLive);
1980
			if (CollectionUtils.isEmpty(items))
1981
				continue;
1982
			for (Item item : items) {
1983
				String productId = "";
1984
				String productType = "";
1985
				Long itemId = item.getId();
1986
				List<String> itemNumbers = getItemNumbers(itemId);
1987
				if (!itemNumbers.isEmpty()) {
1988
					for (String itemNumber : itemNumbers) {
1989
						itemNumber = itemNumber.replaceAll("-", "");
1990
						try {
1991
							Long.parseLong(itemNumber);
1992
						} catch (NumberFormatException nfe) {
1993
							continue;
1994
						}
1995
						if (itemNumber.length() == 13) {
1996
							productType = "EAN";
1997
						} else if (itemNumber.length() == 12) {
1998
							productType = "UPC";
1999
						}
2000
						productId = itemNumber;
2001
						break;
2002
					}
2003
				}
2004
				if (item.getColor() == null) {
2005
					item.setColor("");
2006
				}
2007
 
2008
				String imageUrl = itemIdImageUrlMap.get(itemId);
2009
 
2010
				Element row = docu.createElement(rowHeader);
2011
 
2012
				if (categoryId != 10073) {
2013
 
2014
					rootElement.appendChild(row);
2015
 
2016
					String dataArray[] ={itemId.toString(),
2017
					getTitle(item),
2018
					getUrl(item,
2019
							categoryId == 10010 ? "tablets"
2020
									: "laptops"),
2021
					"" + (int) (item.getSellingPrice()),
2022
					"1",
2023
					categoryId == 10010 ? "803574031"
2024
							: "803540031",
2025
					productId,// productId,
2026
					productType, // productType,
2027
					categoryId == 10010 ? "Tablet"
2028
							: "Laptop",
2029
					item.getBrand(),
2030
					item.getBrand(),
2031
					"",
2032
					item.getModelNumber(),
2033
					StringUtils.defaultString(fvalues
2034
							.get(AmazonFeatures.DESCRIPTION
2035
									.getValue())),
2036
					"0",
2037
					imageUrl,
2038
					""
2039
							+ (item.getMrp() == 0 ? (int) item
2040
									.getSellingPrice()
2041
									: (int) (item
2042
											.getMrp())),
2043
					getAvailability(item),
2044
					getOS(StringUtils
2045
							.defaultString(fvalues
2046
									.get(120197L))), // Operating
2047
														// System
2048
					getType(StringUtils
2049
							.defaultString(fvalues
2050
									.get(120160L))), // Processor
2051
														// Type
2052
					StringUtils.defaultString(
2053
							fvalues.get(120160L))
2054
							.split(" ")[0],
2055
					StringUtils.defaultString(fvalues
2056
							.get(120170L)),// Computer
2057
											// CPU
2058
											// Speed
2059
					StringUtils.defaultString(fvalues
2060
							.get(120112L)),// HD Size
2061
 
2062
					StringUtils.defaultString(fvalues
2063
							.get(120031L)),// RAM
2064
					getScreenSize(StringUtils
2065
							.defaultString(fvalues
2066
									.get(120005L))),// Screen
2067
													// Size
2068
					displayTechnology,// Display
2069
										// technology
2070
					StringUtils.defaultString(fvalues
2071
							.get(120112L)),// Memory
2072
											// Storage
2073
											// Capacity
2074
					"",// Connectivity Technology
2075
					getWirelessType(StringUtils
2076
							.defaultString(fvalues
2077
									.get(120178L))), // Wireless
2078
														// Type
2079
					getScreenResolution(StringUtils.defaultString(fvalues
2080
							.get(categoryId == 10010 ? 120006L
2081
									: 120174L))),// Screen
2082
													// Resolution
2083
					"",
2084
					item.getColor(),
2085
					"",
2086
					"",
2087
					"",
2088
					"",
2089
					"",
2090
					"",
2091
					"",
2092
					"",
2093
					"",
2094
					"",
2095
					"",
2096
					"",
2097
					"",
2098
					"",
2099
					"",
2100
					"",
2101
					"",
2102
					"",
2103
					"",
2104
					"",
2105
					"",
2106
					"",
2107
					"",
2108
					"",
2109
					"",
2110
					"",
2111
					"",
2112
					"",
2113
					"",
2114
					"",
2115
					"",
2116
					"",
2117
					"",
2118
					"",
2119
					"",
2120
					item.getItemStatus().equals(
2121
							status.PHASED_OUT) ? "Delete"
2122
							: "",
2123
					"",
2124
					"credit_card|debit_card|net_banking|emi|prepaid_card"
2125
							+ (Double
2126
									.valueOf(250D)
2127
									.compareTo(
2128
											item.getSellingPrice()) <= 0
2129
									&& Double
2130
											.valueOf(
2131
													25000D)
2132
											.compareTo(
2133
													item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
2134
									: "") };
2135
					for(int loopCount=0;loopCount<dataArray.length;loopCount++){
2136
						if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
2137
							continue;
2138
						row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
2139
					}
2140
				} else {
2141
					String hardDiskFormat = StringUtils.defaultString(
2142
							fvalues.get(120284l)).split(" ")[0];
2143
 
2144
					rootElement.appendChild(row);
2145
					String dataArray[] = {
2146
							itemId.toString(),
2147
							getTitle(item),
2148
							getUrl(item, "laptop-accessories"),
2149
							"" + (int) (item.getSellingPrice()),
2150
							"1",
2151
							"803511031",
2152
							productId,// productId,
2153
							productType, // productType,
2154
							"External Hard Drives",
2155
							item.getBrand(),
2156
							item.getBrand(),
2157
							"",
2158
							item.getModelNumber(),
2159
							StringUtils.defaultString(fvalues
2160
									.get(AmazonFeatures.DESCRIPTION
2161
											.getValue())),
2162
							"0",
2163
							imageUrl,
2164
							""
2165
									+ (item.getMrp() == 0 ? (int) item
2166
											.getSellingPrice()
2167
											: (int) (item
2168
													.getMrp())),
2169
							getAvailability(item),
2170
							"",// Operating System
2171
							"", // Processor Type
2172
							"", // Processor Brand
2173
							"",// Computer CPU Speed
2174
							StringUtils.defaultString(fvalues
2175
									.get(120112L)),// HD Size
2176
 
2177
							"",// RAM
2178
							"",// Screen Size
2179
							"",// Display technology
2180
							StringUtils.defaultString(fvalues
2181
									.get(120112L)),// Memory
2182
													// Storage
2183
													// Capacity
2184
							"",// Connectivity Technology
2185
							"", // Wireless Type
2186
							"",// Screen Resolution
2187
							"",
2188
							item.getColor(),
2189
							"",
2190
							"",
2191
							"",
2192
							"",
2193
							"",
2194
							"",
2195
							"",
2196
							"",
2197
							"",
2198
							"",
2199
							"",
2200
							"",
2201
							"",
2202
							"",
2203
							"",
2204
							"",
2205
							"",
2206
							"",
2207
							"",
2208
							"",
2209
							"",
2210
							"",
2211
							"",
2212
							"",
2213
							"",
2214
							"",
2215
							"",
2216
							"",
2217
							"",
2218
							"",
2219
							"",
2220
							"",
2221
							"",
2222
							"",
2223
							"",
2224
							item.getItemStatus().equals(
2225
									status.PHASED_OUT) ? "Delete"
2226
									: "",
2227
							hardDiskFormat,
2228
							"credit_card|debit_card|net_banking|emi"
2229
									+ (Double
2230
											.valueOf(250D)
2231
											.compareTo(
2232
													item.getSellingPrice()) <= 0
2233
											&& Double
2234
													.valueOf(
2235
															25000D)
2236
													.compareTo(
2237
															item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
2238
											: "") };
2239
					for(int loopCount=0;loopCount<dataArray.length;loopCount++){
2240
						if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
2241
							continue;
2242
						row.appendChild(elementData(docu,headerArray[loopCount],dataArray[loopCount]));
2243
					}
2244
 
2245
				}
2246
			}
2247
		}
2248
		/*File xmlFile = new File(Utils.EXPORT_PATH + "Laptop" + dateString + ".xml");*/
2249
		//generateXMLfile(mobileXMLFile, doc);
2250
 
2251
		System.out.println("INFO : Laptop.xml successfully created at /home/amit/Desktop/cms/ successfully generated.");
2252
		return;
2253
	}
2254
 
2255
	private void generateXMLfile(File xmlFile, Document doc ) throws TransformerException{
2256
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
2257
		Transformer transformer = transformerFactory.newTransformer();
2258
		DOMSource source = new DOMSource(doc);
2259
		StreamResult result = new StreamResult(xmlFile);
2260
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
2261
		transformer.setOutputProperty(OutputKeys.METHOD, "xml");
2262
		transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
2263
		transformer.transform(source, result);
2264
		System.out.println("File successfully updated");
2265
		return;
2266
	}
9996 amit.gupta 2267
	private void generateLaptopData(List<Entity> entities) throws Exception {
5900 amit.gupta 2268
		StringBuffer tsvBuffer = new StringBuffer();
13386 manas 2269
		tsvBuffer.append(
2270
				StringUtils.join(new String[] {
2271
						"Amazon.com Product Ads Header", "Purge-Replace=false",
2272
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2273
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2274
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2275
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2276
						"", "", "", "", "", "", "" }, "\t")).append("\n");
2277
		tsvBuffer
2278
				.append(StringUtils.join(new String[] { "SKU", "Title", "Link",
2279
						"Price", "Delivery Time", "Recommended Browse Node",
2280
						"Standard Product ID", "Product ID Type", "Category",
2281
						"Brand", "Manufacturer", "Mfr part number",
2282
						"Model Number", "Description", "Shipping Cost",
2283
						"Image", "List Price", "Availability",
2284
						"Operating System", "Processor Type",
2285
						"Processor Brand", "Computer CPU speed",
2286
						"Hard disk size", "Included RAM size", "Display size",
2287
						"Display Technology", "Memory Storage Capacity",
2288
						"Connectivity Technology", "Wireless Type",
2289
						"Screen Resolution", "Memory Card Type", "Colour Name",
2290
						"Colour Map", "Item package quantity", "Warranty",
2291
						"Assembly required", "Battery Cell Composition",
2292
						"Batteries Included", "Batteries Required",
2293
						"Power Source", "Power Adapter Included",
2294
						"Shipping Weight", "Weight", "Length", "Height",
2295
						"Width", "Keywords1", "Keywords2", "Keywords3",
2296
						"Keywords4", "Keywords5", "Bullet point1",
2297
						"Bullet point2", "Bullet point3", "Bullet point4",
2298
						"Bullet point5", "Other image-url1",
2299
						"Other image-url2", "Other image-url3",
2300
						"Other image-url4", "Other image-url5", "Offer note",
2301
						"Discount Amount", "Junglee Exclusive Offer",
2302
						"Offer Promo Code", "Is Gift Wrap Available",
2303
						"Registered Parameter", "Update Delete",
2304
						"Hard Disk Format", "Accepted Payment Methods" }, "\t"))
2305
				.append("\n");
2306
		laptopFileWriter.write(tsvBuffer.toString());
2307
		laptopFileWriter.flush();
2308
		tsvBuffer.setLength(0);
4492 amit.gupta 2309
		for (Entity entity : entities) {
13386 manas 2310
			if (Catalog.getInstance().getDefinitionsContainer()
2311
					.getCategory(entity.getCategoryID()) == null)
4654 amit.gupta 2312
				continue;
13386 manas 2313
			long categoryId = Catalog.getInstance().getDefinitionsContainer()
2314
					.getCategory(entity.getCategoryID()).getID();
2315
			if (entity == null
2316
					|| entity.getSlides() == null
2317
					|| (categoryId != 10050 && categoryId != 10010 && categoryId != 10073)) {
4441 amit.gupta 2318
				continue;
2319
			}
13386 manas 2320
 
4441 amit.gupta 2321
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
4654 amit.gupta 2322
 
5257 amit.gupta 2323
			String displayTechnology = StringUtils.defaultString(fvalues
2324
					.get(120008L));
13386 manas 2325
			if (displayTechnology.equals("")) {
2326
				displayTechnology = StringUtils.defaultString(fvalues
2327
						.get(120175L));
5257 amit.gupta 2328
			}
2329
 
2330
			List<Item> items = getItemsByCatalogId(entity.getID());
2331
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
9994 amit.gupta 2332
			CollectionUtils.filter(items, predicateLive);
4441 amit.gupta 2333
			if (CollectionUtils.isEmpty(items))
2334
				continue;
4654 amit.gupta 2335
 
2336
			for (Item item : items) {
4633 amit.gupta 2337
				String productId = "";
2338
				String productType = "";
2339
				Long itemId = item.getId();
5257 amit.gupta 2340
				List<String> itemNumbers = getItemNumbers(itemId);
4654 amit.gupta 2341
				if (!itemNumbers.isEmpty()) {
2342
					for (String itemNumber : itemNumbers) {
4633 amit.gupta 2343
						itemNumber = itemNumber.replaceAll("-", "");
2344
						try {
2345
							Long.parseLong(itemNumber);
2346
						} catch (NumberFormatException nfe) {
2347
							continue;
2348
						}
2349
						if (itemNumber.length() == 13) {
2350
							productType = "EAN";
2351
						} else if (itemNumber.length() == 12) {
2352
							productType = "UPC";
2353
						}
2354
						productId = itemNumber;
2355
						break;
2356
					}
2357
				}
4441 amit.gupta 2358
				if (item.getColor() == null) {
2359
					item.setColor("");
2360
				}
4654 amit.gupta 2361
 
4441 amit.gupta 2362
				String imageUrl = itemIdImageUrlMap.get(itemId);
8212 amit.gupta 2363
				if (categoryId != 10073) {
5524 amit.gupta 2364
					tsvBuffer
8212 amit.gupta 2365
							.append(StringUtils.join(
2366
									new String[] {
2367
											itemId.toString(),
2368
											getTitle(item),
2369
											getUrl(item,
2370
													categoryId == 10010 ? "tablets"
2371
															: "laptops"),
2372
											"" + (int) (item.getSellingPrice()),
2373
											"1",
2374
											categoryId == 10010 ? "803574031"
2375
													: "803540031",
2376
											productId,// productId,
2377
											productType, // productType,
2378
											categoryId == 10010 ? "Tablet"
2379
													: "Laptop",
2380
											item.getBrand(),
2381
											item.getBrand(),
2382
											"",
2383
											item.getModelNumber(),
2384
											StringUtils.defaultString(fvalues
2385
													.get(AmazonFeatures.DESCRIPTION
2386
															.getValue())),
2387
											"0",
2388
											imageUrl,
2389
											""
2390
													+ (item.getMrp() == 0 ? (int) item
2391
															.getSellingPrice()
2392
															: (int) (item
2393
																	.getMrp())),
2394
											getAvailability(item),
2395
											getOS(StringUtils
2396
													.defaultString(fvalues
2397
															.get(120197L))), // Operating
2398
																				// System
2399
											getType(StringUtils
2400
													.defaultString(fvalues
2401
															.get(120160L))), // Processor
2402
																				// Type
2403
											StringUtils.defaultString(
2404
													fvalues.get(120160L))
2405
													.split(" ")[0],
2406
											StringUtils.defaultString(fvalues
2407
													.get(120170L)),// Computer
2408
																	// CPU
2409
																	// Speed
2410
											StringUtils.defaultString(fvalues
2411
													.get(120112L)),// HD Size
4441 amit.gupta 2412
 
8212 amit.gupta 2413
											StringUtils.defaultString(fvalues
2414
													.get(120031L)),// RAM
2415
											getScreenSize(StringUtils
2416
													.defaultString(fvalues
2417
															.get(120005L))),// Screen
2418
																			// Size
2419
											displayTechnology,// Display
4890 amit.gupta 2420
																// technology
8212 amit.gupta 2421
											StringUtils.defaultString(fvalues
2422
													.get(120112L)),// Memory
2423
																	// Storage
2424
																	// Capacity
2425
											"",// Connectivity Technology
2426
											getWirelessType(StringUtils
2427
													.defaultString(fvalues
2428
															.get(120178L))), // Wireless
2429
																				// Type
2430
											getScreenResolution(StringUtils.defaultString(fvalues
2431
													.get(categoryId == 10010 ? 120006L
2432
															: 120174L))),// Screen
2433
																			// Resolution
2434
											"",
2435
											item.getColor(),
2436
											"",
2437
											"",
2438
											"",
2439
											"",
2440
											"",
2441
											"",
2442
											"",
2443
											"",
2444
											"",
2445
											"",
2446
											"",
2447
											"",
2448
											"",
2449
											"",
2450
											"",
2451
											"",
2452
											"",
2453
											"",
2454
											"",
2455
											"",
2456
											"",
2457
											"",
2458
											"",
2459
											"",
2460
											"",
2461
											"",
2462
											"",
2463
											"",
2464
											"",
2465
											"",
2466
											"",
9994 amit.gupta 2467
											"",
10006 amit.gupta 2468
											"",
13386 manas 2469
											"",
2470
											"",
8212 amit.gupta 2471
											item.getItemStatus().equals(
2472
													status.PHASED_OUT) ? "Delete"
2473
													: "",
2474
											"",
2475
											"credit_card|debit_card|net_banking|emi|prepaid_card"
2476
													+ (Double
2477
															.valueOf(250D)
2478
															.compareTo(
2479
																	item.getSellingPrice()) <= 0
2480
															&& Double
2481
																	.valueOf(
2482
																			25000D)
2483
																	.compareTo(
2484
																			item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
2485
															: "") }, "\t"))
2486
							.append("\n");
5524 amit.gupta 2487
				} else {
8212 amit.gupta 2488
					String hardDiskFormat = StringUtils.defaultString(
2489
							fvalues.get(120284l)).split(" ")[0];
5524 amit.gupta 2490
					tsvBuffer
8212 amit.gupta 2491
							.append(StringUtils.join(
2492
									new String[] {
2493
											itemId.toString(),
2494
											getTitle(item),
2495
											getUrl(item, "laptop-accessories"),
2496
											"" + (int) (item.getSellingPrice()),
2497
											"1",
2498
											"803511031",
2499
											productId,// productId,
2500
											productType, // productType,
2501
											"External Hard Drives",
2502
											item.getBrand(),
2503
											item.getBrand(),
2504
											"",
2505
											item.getModelNumber(),
2506
											StringUtils.defaultString(fvalues
2507
													.get(AmazonFeatures.DESCRIPTION
2508
															.getValue())),
2509
											"0",
2510
											imageUrl,
2511
											""
2512
													+ (item.getMrp() == 0 ? (int) item
2513
															.getSellingPrice()
2514
															: (int) (item
2515
																	.getMrp())),
2516
											getAvailability(item),
2517
											"",// Operating System
2518
											"", // Processor Type
2519
											"", // Processor Brand
2520
											"",// Computer CPU Speed
2521
											StringUtils.defaultString(fvalues
2522
													.get(120112L)),// HD Size
5524 amit.gupta 2523
 
8212 amit.gupta 2524
											"",// RAM
2525
											"",// Screen Size
2526
											"",// Display technology
2527
											StringUtils.defaultString(fvalues
2528
													.get(120112L)),// Memory
2529
																	// Storage
2530
																	// Capacity
2531
											"",// Connectivity Technology
2532
											"", // Wireless Type
2533
											"",// Screen Resolution
2534
											"",
2535
											item.getColor(),
2536
											"",
2537
											"",
2538
											"",
2539
											"",
2540
											"",
2541
											"",
2542
											"",
2543
											"",
2544
											"",
2545
											"",
2546
											"",
2547
											"",
2548
											"",
2549
											"",
2550
											"",
2551
											"",
2552
											"",
2553
											"",
2554
											"",
2555
											"",
2556
											"",
2557
											"",
2558
											"",
2559
											"",
2560
											"",
2561
											"",
2562
											"",
2563
											"",
2564
											"",
2565
											"",
2566
											"",
9994 amit.gupta 2567
											"",
10006 amit.gupta 2568
											"",
2569
											"",
2570
											"",
8212 amit.gupta 2571
											item.getItemStatus().equals(
2572
													status.PHASED_OUT) ? "Delete"
2573
													: "",
2574
											hardDiskFormat,
2575
											"credit_card|debit_card|net_banking|emi"
2576
													+ (Double
2577
															.valueOf(250D)
2578
															.compareTo(
2579
																	item.getSellingPrice()) <= 0
2580
															&& Double
2581
																	.valueOf(
2582
																			25000D)
2583
																	.compareTo(
2584
																			item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
2585
															: "") }, "\t"))
2586
							.append("\n");
2587
 
5524 amit.gupta 2588
				}
4654 amit.gupta 2589
			}
4441 amit.gupta 2590
 
2591
		}
5900 amit.gupta 2592
		laptopFileWriter.write(tsvBuffer.toString());
2593
		laptopFileWriter.flush();
2594
		tsvBuffer.setLength(0);
9994 amit.gupta 2595
		laptopFileWriter.close();
13580 manas 2596
		System.out.println("INFO : To generate Products List for Amazon type command : java AmazonSCDataGenerator products/prices");
13386 manas 2597
		return;
4654 amit.gupta 2598
 
4441 amit.gupta 2599
	}
13580 manas 2600
	public void generateLaptopAccessories(List<Entity> entities) throws Exception {
2601
		StringBuffer tsvBuffer = new StringBuffer();
2602
		tsvBuffer.append(
2603
				StringUtils.join(new String[] {
2604
						"Amazon.com Product Ads Header", "Purge-Replace=false",
2605
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2606
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2607
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2608
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2609
						"", "", "", "", "", "", "" }, "\t")).append("\n");
2610
		tsvBuffer
2611
				.append(StringUtils.join(new String[] {"SKU", "Title", "Link",
2612
						"Price", "Delivery Time", "Recommended Browse Node",
2613
						"Standard Product ID", "Product ID Type", "Category",
2614
						"Brand", "Manufacturer", "Mfr part number",
2615
						"Model Number", "Description", "Shipping Cost",
2616
						"Image", "List Price", "Availability",
2617
						"Operating System", "Processor Type",
2618
						"Processor Brand", "Computer CPU speed",
2619
						"Hard disk size", "Included RAM size", "Display size",
2620
						"Display Technology", "Memory Storage Capacity",
2621
						"Connectivity Technology", "Wireless Type",
2622
						"Screen Resolution", "Memory Card Type", "Colour Name",
2623
						"Colour Map", "Item package quantity", "Warranty",
2624
						"Assembly required", "Battery Cell Composition",
2625
						"Batteries Included", "Batteries Required",
2626
						"Power Source", "Power Adapter Included",
2627
						"Shipping Weight", "Weight", "Length", "Height",
2628
						"Width", "Keywords1", "Keywords2", "Keywords3",
2629
						"Keywords4", "Keywords5", "Bullet point1",
2630
						"Bullet point2", "Bullet point3", "Bullet point4",
2631
						"Bullet point5", "Other image-url1",
2632
						"Other image-url2", "Other image-url3",
2633
						"Other image-url4", "Other image-url5", "Offer note",
2634
						"Discount Amount", "Junglee Exclusive Offer",
2635
						"Offer Promo Code", "Is Gift Wrap Available",
2636
						"Registered Parameter", "Update Delete",
2637
						"Hard Disk Format", "Accepted Payment Methods" }, "\t"))
2638
				.append("\n");
2639
		laptopFileWriter.write(tsvBuffer.toString());
2640
		laptopFileWriter.flush();
2641
		tsvBuffer.setLength(0);
2642
				System.out.println("List of Entities " + entities.size());
2643
				// filter only laptop related entities
2644
				for (Entity entity : entities) {
2645
					List<Item> items = getItemsByCatalogId(entity.getID());
2646
					Category category = Catalog.getInstance().getDefinitionsContainer()
2647
							.getCategory(entity.getCategoryID());
2648
					if (category == null) {
2649
						continue;
2650
					}
2651
					if (entity == null || entity.getSlides() == null
2652
							|| category.getParentCategory().getID() != 10070) {
2653
						continue;
2654
					}
2655
 
2656
 
2657
					AmazonCategories azCategory = null;
2658
					Long categoryId = category.getID();
2659
					if (categoryId.equals(10071L)) {
2660
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_RAM;
2661
					}else if (categoryId.equals(10072L)) {
2662
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_COOLINGS_STAND;
2663
					}else if (categoryId.equals(10074L)) {
2664
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_USB_HUBS;
2665
					}else if (categoryId.equals(10076L)) {
2666
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_WI_FI_ROUTERS;
2667
					}else if (categoryId.equals(10077L)) {
2668
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_LAPTOP_BATTERIES;
2669
					}/*else if (categoryId.equals(10078L)) {
2670
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_ANTIVIRUS;
2671
					}else if (categoryId.equals(10079L)) {
2672
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_OFFICE_PACKS;
2673
					}*/else if (categoryId.equals(10080L)) {
2674
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_KEYBOARDS;
2675
					}else if (categoryId.equals(10081L)) {
2676
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_MICE;
2677
					}else if (categoryId.equals(10083L)) {
2678
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_DATA_CARDS;
2679
					}else if (categoryId.equals(10084L)) {
2680
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_MOUSE_PADS;
2681
					}else if (categoryId.equals(10085L)) {
2682
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_LAPTOPS_BAGS;
2683
					}else if (categoryId.equals(10086L)) {
2684
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_LAPTOP_CHARGERS;
2685
					}else if (categoryId.equals(10087L)) {
2686
						azCategory = AmazonCategories.LAPTOP_ACCESSORY_PRINTER_CATRIDGES;
2687
					}else {
2688
						continue;
2689
					}
2690
					Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
2691
 
2692
					Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
2693
					String metaKeywords = StringUtils.defaultString(fvalues.get(AmazonFeatures.META_KEYWORDS.getValue()));
2694
					List<String> keywords = new ArrayList<String>();
2695
 
2696
					String bulletsString = StringUtils.defaultString(fvalues.get(120081L));
2697
					List<String> bullets = new ArrayList<String>();
2698
					for (String keyword : bulletsString.split("--")) {
2699
						bullets.add(keyword.trim().replaceAll("\\s+", " "));
2700
					}
2701
					for (String keyword : metaKeywords.split(",")) {
2702
						keywords.add(keyword.trim());
2703
					}
2704
 
2705
					int length1 = keywords.size();
2706
					if (length1 < 5) {
2707
						while (length1 < 5) {
2708
							keywords.add("");
2709
							length1 = length1 + 1;
2710
						}
2711
					}
2712
					int length2 = bullets.size();
2713
					if (length2 < 5) {
2714
						while (length2 < 5) {
2715
							bullets.add("");
2716
							length2 = length2 + 1;
2717
						}
2718
					}
2719
 
2720
					CollectionUtils.filter(items, predicateLive);
2721
					if (CollectionUtils.isEmpty(items))
2722
						continue;
2723
 
2724
					for (Item item : items) {
2725
						String productType = "";
2726
						String productId = "";
2727
						Long itemId = item.getId();
2728
						List<String> itemNumbers = getItemNumbers(itemId);
2729
						if (!itemNumbers.isEmpty()) {
2730
							for (String itemNumber : itemNumbers) {
2731
								itemNumber = itemNumber.replaceAll("-", "");
2732
								try {
2733
									Long.parseLong(itemNumber);
2734
								} catch (NumberFormatException nfe) {
2735
									continue;
2736
								}
2737
								if (itemNumber.length() == 13) {
2738
									productType = "EAN";
2739
								} else if (itemNumber.length() == 12) {
2740
									productType = "UPC";
2741
								}
2742
								productId = itemNumber;
2743
								break;
2744
							}
2745
						}
2746
						tsvBuffer
2747
						.append(StringUtils.join(
2748
								new String[] {
2749
								new Long(item.getId()).toString(),
2750
								getTitle(item),
2751
								getUrl(item, "laptop-accessories"),
2752
								"" + (int) (item.getSellingPrice()),
2753
								"1",
2754
								azCategory == null ? "" : azCategory
2755
										.getValue().toString(),
2756
								productId,
2757
								productType,
2758
								"LaptopAndAccessories",
2759
								item.getBrand(),
2760
								item.getBrand(),
2761
								"",
2762
								item.getModelNumber(),
2763
								item.getFeatureDescription(),
2764
								"0",
2765
								itemIdImageUrlMap.get(item.getId()),
2766
								""
2767
										+ (item.getMrp() == 0 ? (int) item
2768
												.getSellingPrice()
2769
												: (int) (item.getMrp())),
2770
								getAvailability(item),
2771
								"",
2772
								"",
2773
								"",
2774
								"",
2775
								"",
2776
								"",
2777
								"",
2778
								"",
2779
								"",
2780
								"",
2781
								"",
2782
								"",
2783
								"",
2784
								item.getColor(),
2785
								"",
2786
								"",
2787
								"",
2788
								"",
2789
								"",
2790
								"",
2791
								"",
2792
								"",
2793
								"",
2794
								"",
2795
								"",
2796
								"",
2797
								"",
2798
								"",
2799
								keywords.get(0),
2800
								keywords.get(1),
2801
								keywords.get(2),
2802
								keywords.get(3),
2803
								keywords.get(4),
2804
								bullets.get(0),
2805
								bullets.get(1),
2806
								bullets.get(2),
2807
								bullets.get(3),
2808
								bullets.get(4),
2809
								"",
2810
								"",
2811
								"",
2812
								"",
2813
								"",
2814
								"",
2815
								"",
2816
								"",
2817
								"",
2818
								item.getItemStatus().equals(
2819
										status.PHASED_OUT) ? "Delete"
2820
										: "",
2821
								"credit_card|debit_card|net_banking|emi"
2822
										+ (Double
2823
												.valueOf(250D)
2824
												.compareTo(
2825
														item.getSellingPrice()) <= 0
2826
												&& Double
2827
														.valueOf(25000D)
2828
														.compareTo(
2829
																item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
2830
												: "") }, "\t"))
2831
												.append("\n");
2832
 
2833
					}					
2834
				}
2835
		laptopFileWriter.write(tsvBuffer.toString());
2836
		laptopFileWriter.flush();
2837
		tsvBuffer.setLength(0);
2838
		laptopFileWriter.close();
2839
		System.out.println("INFO : To generate Products List for Amazon type command : java AmazonSCDataGenerator products/prices");
2840
	return;
2841
	}
2842
	public void generateSmartWatch(List<Entity> entities) throws Exception {
2843
		StringBuffer tsvBuffer = new StringBuffer();
2844
		tsvBuffer.append(
2845
				StringUtils.join(new String[] {
2846
						"Amazon.com Product Ads Header", "Purge-Replace=false",
2847
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2848
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2849
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2850
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
2851
						"", "", "", "", "", "", "" }, "\t")).append("\n");
2852
 
2853
		tsvBuffer.append(StringUtils.join(new String[]  { "SKU", "Title", "Link",
2854
				"Price", "Delivery Time", "Recommended Browse Node",
2855
				"Standard Product ID", "Product ID Type", "Category",
2856
				"Brand", "Manufacturer", "Mfr part number",
2857
				"Model Number", "Description", "Shipping Cost",
2858
				"Image", "List Price", "Availability",
2859
				"Operating System", "Wireless Type", "Digital zoom",
2860
				"Megapixels", "Display size", "Cellular Technology",
2861
				"Talk Time", "Standby Time", "Charging Time",
2862
				"User Input", "Device Type", "Form Factor",
2863
				"Connectivity Technology", "Special Features",
2864
				"Memory Storage Capacity", "Optical Zoom",
2865
				"Memory Card Type", "Colour Name", "Colour Map",
2866
				"Item Package Quantity", "Warranty",
2867
				"Assembly required", "Battery Cell Composition",
2868
				"Batteries Included", "Batteries Required",
2869
				"Power Source", "Power Adapter Included",
2870
				"Shipping Weight", "Weight", "Length", "Height",
2871
				"Width", "Keywords1", "Keywords2", "Keywords3",
2872
				"Keywords4", "Keywords5", "Bullet point1",
2873
				"Bullet point2", "Bullet point3", "Bullet point4",
2874
				"Bullet point5", "Other image-url1",
2875
				"Other image-url2", "Other image-url3",
2876
				"Other image-url4", "Other image-url5", "Offer note",
2877
				"Discount Amount", "Junglee Exclusive Offer",
2878
				"Offer Promo Code", "Is Gift Wrap Available",
2879
				"Registered Parameter", "Update Delete",
2880
				"Accepted Payment Methods" }, "\t"))
2881
		.append("\n");
2882
		smartWatchWriter.write(tsvBuffer.toString());
2883
		smartWatchWriter.flush();
2884
		tsvBuffer.setLength(0);
2885
		for (Entity entity : entities) {
2886
			if (Catalog.getInstance().getDefinitionsContainer()
2887
					.getCategory(entity.getCategoryID()) == null) {
2888
				continue;
2889
			}
2890
			if (entity == null
2891
					|| entity.getSlides() == null
2892
					|| Catalog.getInstance().getDefinitionsContainer()
2893
							.getCategory(entity.getCategoryID())
2894
							.getParentCategory().getID() != 12100) {
2895
				continue;
2896
			}
2897
			// Treat phone related entities now.
2898
			// get Feature values for all entities required for amazon.
2899
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
2900
			List<Item> items = getItemsByCatalogId(entity.getID());
2901
			CollectionUtils.filter(items, predicateLive);
2902
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
2903
			if (CollectionUtils.isEmpty(items))
2904
				continue;
2905
			String screenSize = StringUtils.defaultString(fvalues.get(AmazonFeatures.SCREEN_SIZE_IN.getValue()));
2906
			String weight = StringUtils.defaultString(fvalues.get(AmazonFeatures.WEIGHT.getValue()));
2907
			String screenResolution = StringUtils.defaultString(fvalues.get(AmazonFeatures.SCREEN_RESOLUTION.getValue()));
2908
			String formFactor = StringUtils.defaultString(fvalues.get(AmazonFeatures.FORM_FACTOR.getValue()));
2909
			String warranty = StringUtils.defaultString(fvalues.get(AmazonFeatures.WARRANTY.getValue()));
2910
			String connectivityTechonology = StringUtils.defaultString(fvalues.get(120500L));
2911
			String size = StringUtils.defaultString(fvalues.get(120496L));
2912
			String metaKeywords = StringUtils.defaultString(fvalues.get(AmazonFeatures.META_KEYWORDS.getValue()));
2913
			String color = StringUtils.defaultString(fvalues.get(AmazonFeatures.COLOR.getValue())).split("--")[0];
2914
 
2915
			String display = StringUtils.defaultString(fvalues.get(120407L));
2916
			String storageCapacity = StringUtils.defaultString(fvalues.get(120499L));
2917
 
2918
			String battery = StringUtils.defaultString(fvalues.get(120448L));
2919
			if (!StringUtils.isEmpty(screenSize)) {
2920
				screenSize = screenSize.split("\\s+")[0];
2921
			}
2922
			if (!StringUtils.isEmpty(screenResolution)) {
2923
				screenResolution = screenResolution.substring(0,
2924
						screenResolution.lastIndexOf(" "));
2925
			}
2926
 
2927
			display = normalizeScreenType(display);
2928
 
2929
			formFactor = normalizeFormFactor(formFactor);
2930
 
2931
			if (StringUtils.isNotEmpty(warranty)) {
2932
				warranty = warranty + " manufacturer warranty";
2933
			}
2934
			battery = normalizeBatteryType(battery);
2935
 
2936
			String[] weightParts = weight.split("\\s+");
2937
			if (weightParts.length > 1) {
2938
				weight = weightParts[0];
2939
				try {
2940
					Float.parseFloat(weight);
2941
				} catch (NumberFormatException e) {
2942
					System.out.println(entity.getID()
2943
							+ "has invalid weight format");
2944
					// e.printStackTrace();
2945
					weight = "";
2946
				}
2947
			}
2948
			String length = "", width = "", height = "";
2949
 
2950
			String replaceSize = size.replaceAll("[^?0-9.]+", " ");
2951
			if (!(size.equals("Not available") || size.equals(""))) {
2952
				String[] list = replaceSize.split(" ");
13598 amit.gupta 2953
				length = list[0] + " MM";
2954
				width = list[1] + " MM";
2955
				height = list[2] + " MM";
13580 manas 2956
			}
2957
 
2958
			List<String> keywords = new ArrayList<String>();
2959
			for (String keyword : metaKeywords.split(",")) {
2960
				keywords.add(keyword.trim());
2961
			}
2962
			int length1 = keywords.size();
2963
			if (length1 < 5) {
2964
				while (length1 < 5) {
2965
					keywords.add("");
2966
					length1 = length1 + 1;
2967
				}
2968
			}
2969
			for (String keyword : keywords) {
2970
				if (keyword.length() > 50)
2971
					System.out.println(keyword);
2972
			}
2973
 
2974
			for (Item item : items) {
2975
				Long itemId = item.getId();
2976
 
2977
				List<String> itemNumbers = getItemNumbers(itemId);
2978
				String productId = "";
2979
				String productType = "";
2980
				if (!itemNumbers.isEmpty()) {
2981
					for (String itemNumber : itemNumbers) {
2982
						itemNumber = itemNumber.replaceAll("-", "");
2983
						try {
2984
							Long.parseLong(itemNumber);
2985
						} catch (NumberFormatException nfe) {
2986
							nfe.printStackTrace();
2987
							continue;
2988
						}
2989
						if (itemNumber.length() == 13) {
2990
							productType = "EAN";
2991
						} else if (itemNumber.length() == 12) {
2992
							productType = "UPC";
2993
						}
2994
						productId = itemNumber;
2995
						if (!productType.equals("")) {
2996
							break;
2997
						}
2998
					}
2999
				}
3000
 
3001
				if (item.getColor() != null) {
3002
					color = item.getColor();
3003
				}
3004
				String imageUrl = itemIdImageUrlMap.get(itemId);
3005
 
3006
				tsvBuffer
3007
				.append(StringUtils.join(
3008
						new String[] {
3009
						new Long(item.getId()).toString(),
3010
						getTitle(item),
3011
						getUrl(item, "smart-watches"),
3012
						"" + (int) (item.getSellingPrice()),
3013
						"1",
3014
						"5605729031",
3015
						productId,
3016
						productType,
3017
						"SmartWatches",
3018
						item.getBrand(),
3019
						item.getBrand(),
3020
						"",
3021
						item.getModelNumber(),
3022
						StringUtils.defaultString(fvalues
3023
								.get(AmazonFeatures.DESCRIPTION
3024
										.getValue())),
3025
						"0",
3026
						imageUrl,
3027
						""
3028
								+ (item.getMrp() == 0 ? (int) item
3029
										.getSellingPrice()
3030
										: (int) (item.getMrp())),
3031
						getAvailability(item),
3032
						"",
3033
						"",
3034
						"",
3035
						StringUtils.defaultString(
3036
								fvalues.get(120026L))
3037
								.split(" ")[0],// Digital zoom,
3038
												// Megapixel
3039
						screenSize,
3040
						"",
3041
						"",// Talktime
3042
						"",// Standby time
3043
						"", // charging time
3044
						"",
3045
						"", // device type
3046
						formFactor,
3047
						connectivityTechonology, // connectivity Technologies
3048
						"", // Special features
3049
						StringUtils.defaultString(fvalues
3050
								.get(AmazonFeatures.BUILTIN_MEMORY
3051
										.getValue())),
3052
						"",// Optical zoom
3053
						"", // Memory Card Type
3054
						color,
3055
						"", // color map
3056
						"1",
3057
						warranty,
3058
						"false",// assembly
3059
						battery,
3060
						"true", // Batteries Included
3061
						"true", // Batteries Required
3062
						"battery-powered", // Power Source
3063
						"true", // Power Adapter inculded
3064
						"", // shipping weight
3065
						weight, // Weight
3066
						length,
3067
						height,
3068
						width,
3069
						keywords.get(0),
3070
						keywords.get(1),
3071
						keywords.get(2),
3072
						keywords.get(3),
3073
						keywords.get(4),
3074
						"",
3075
						"",
3076
						"",
3077
						"",
3078
						"",
3079
						"",
3080
						"",
3081
						"",
3082
						"",
3083
						"",
3084
						"",
3085
						"",
3086
						"",
3087
						"",
3088
						"",
3089
						"",
3090
						item.getItemStatus().equals(
3091
								status.PHASED_OUT) ? "Delete"
3092
								: "",
3093
						"credit_card|debit_card|net_banking|emi"
3094
								+ (Double
3095
										.valueOf(250D)
3096
										.compareTo(
3097
												item.getSellingPrice()) <= 0
3098
										&& Double
3099
												.valueOf(25000D)
3100
												.compareTo(
3101
														item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
3102
										: "") }, "\t"))
3103
										.append("\n");
3104
 
3105
				}
3106
		}
3107
		smartWatchWriter.write(tsvBuffer.toString());
3108
		smartWatchWriter.flush();
3109
		tsvBuffer.setLength(0);
3110
		smartWatchWriter.close();
3111
		System.out.println("INFO : Smart Watches data successfully created at /home/amit/Desktop/cms/ successfully generated.");
3112
	}
13386 manas 3113
 
3114
	private void generateCameraData(List<Entity> entities) throws Exception {
4441 amit.gupta 3115
 
6069 amit.gupta 3116
		StringBuffer tsvBuffer = new StringBuffer();
9994 amit.gupta 3117
		tsvBuffer.append(
3118
				StringUtils.join(new String[] {
13386 manas 3119
						"Amazon.com Product Ads Header", "Purge-Replace=false",
3120
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
3121
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
3122
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
3123
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
3124
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
3125
						"", "", "", "", "", "", "", "", "" }, "\t")).append(
3126
				"\n");
9994 amit.gupta 3127
		tsvBuffer.append(
3128
				StringUtils.join(new String[] { "SKU", "Title", "Link",
13386 manas 3129
						"Price", "Delivery Time", "Recommended Browse Node",
3130
						"Standard Product ID", "Product ID Type", "Category",
3131
						"Brand", "Manufacturer", "Mfr part number",
3132
						"Model Number", "Description", "Shipping Cost",
3133
						"Image", "List Price", "Availability", "Optical Zoom",
9994 amit.gupta 3134
						"Digital Zoom", "Megapixels", "Display size",
13386 manas 3135
						"Memory Card Type", "Viewfinder type", "Flash type",
3136
						"Image Stabilization", "Min Focal Length",
3137
						"Max Focal Length", "Mounting Type", "Offer note",
3138
						"Discount Amount", "Junglee Exclusive Offer",
3139
						"Offer Promo Code", "Accepted Payment Methods",
3140
						"Screen Resolution", "Display Technology",
3141
						"Memory Storage Capacity", "Colour Name", "Colour Map",
9994 amit.gupta 3142
						"Item package quantity", "Warranty",
3143
						"Assembly required", "Battery Cell Composition",
3144
						"Batteries Included", "Batteries Required",
3145
						"Power Source", "Power Adapter Included",
3146
						"Shipping Weight", "Weight", "Length", "Height",
3147
						"Width", "Update Delete" }, "\t")).append("\n");
3148
		cameraFileWriter.write(tsvBuffer.toString());
3149
		cameraFileWriter.flush();
3150
		tsvBuffer.setLength(0);
6069 amit.gupta 3151
		for (Entity entity : entities) {
3152
			if (Catalog.getInstance().getDefinitionsContainer()
3153
					.getCategory(entity.getCategoryID()) == null)
3154
				continue;
3155
			long categoryId = entity.getCategoryID();
3156
			if (entity == null || entity.getSlides() == null
8212 amit.gupta 3157
					|| (categoryId != 11002 && categoryId != 11003)) {
6069 amit.gupta 3158
				continue;
3159
			}
8212 amit.gupta 3160
 
6069 amit.gupta 3161
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
8212 amit.gupta 3162
 
6069 amit.gupta 3163
			List<Item> items = getItemsByCatalogId(entity.getID());
3164
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
9994 amit.gupta 3165
			CollectionUtils.filter(items, predicateLive);
6069 amit.gupta 3166
			if (CollectionUtils.isEmpty(items))
3167
				continue;
3168
			String warranty = StringUtils.defaultString(fvalues
8212 amit.gupta 3169
					.get(AmazonFeatures.WARRANTY.getValue()));
6069 amit.gupta 3170
			String batteryType = StringUtils.defaultString(fvalues
3171
					.get(AmazonFeatures.BATTERY_TYPE.getValue()));
3172
			String weight = StringUtils.defaultString(fvalues
3173
					.get(AmazonFeatures.WEIGHT.getValue()));
3174
			String size = StringUtils.defaultString(fvalues
3175
					.get(AmazonFeatures.SIZE.getValue()));
8212 amit.gupta 3176
 
6069 amit.gupta 3177
			String length = "", width = "", height = "";
3178
			if (!(size.equals("Not available") || size.equals(""))) {
3179
				String[] list = size.split("\\s+");
3180
				length = list[0] + " MM";
3181
				width = list[2] + " MM";
3182
				height = list[4] + " MM";
3183
			}
8212 amit.gupta 3184
 
3185
			String flashmount = StringUtils.defaultString(fvalues.get(120392l))
3186
					.split(" ")[0];
3187
			if (flashmount.equals("Sony")) {
6069 amit.gupta 3188
				flashmount = "Minoltabayonet";
8212 amit.gupta 3189
			} else if (!flashmount.equals("")) {
6069 amit.gupta 3190
				flashmount = flashmount.concat("bayonet");
3191
			}
3192
			for (Item item : items) {
3193
				String productId = "";
3194
				String productType = "";
3195
				Long itemId = item.getId();
3196
				List<String> itemNumbers = getItemNumbers(itemId);
3197
				if (!itemNumbers.isEmpty()) {
3198
					for (String itemNumber : itemNumbers) {
3199
						itemNumber = itemNumber.replaceAll("-", "");
3200
						try {
3201
							Long.parseLong(itemNumber);
3202
						} catch (NumberFormatException nfe) {
3203
							continue;
3204
						}
3205
						if (itemNumber.length() == 13) {
3206
							productType = "EAN";
3207
						} else if (itemNumber.length() == 12) {
3208
							productType = "UPC";
3209
						}
3210
						productId = itemNumber;
3211
						break;
3212
					}
3213
				}
3214
				if (item.getColor() == null) {
3215
					item.setColor("");
3216
				}
3217
				String sensorResolution = "";
3218
				String viewFinder = "none";
8212 amit.gupta 3219
				if (categoryId == 11002l) {
3220
					sensorResolution = StringUtils.defaultString(fvalues
3221
							.get(120026l));
6069 amit.gupta 3222
					String vf = StringUtils.defaultString(fvalues.get(120342));
8212 amit.gupta 3223
					if (vf == "Optical viewfinder") {
6069 amit.gupta 3224
						viewFinder = "optical";
3225
					} else if (vf == "Electronic viewfinder") {
3226
						viewFinder = "digital";
3227
					}
8212 amit.gupta 3228
				} else {
6069 amit.gupta 3229
					viewFinder = "optical";
3230
				}
8212 amit.gupta 3231
 
3232
				String focalString = StringUtils.defaultString(fvalues
3233
						.get(120336l));
6069 amit.gupta 3234
				Matcher m = patt.matcher(focalString);
8212 amit.gupta 3235
				int i = 0;
3236
				String[] focalLength = { "", "" };
3237
				while (i < 2 && m.find()) {
3238
					focalLength[i] = m.group();
6069 amit.gupta 3239
					i++;
3240
				}
8212 amit.gupta 3241
 
6069 amit.gupta 3242
				String imageUrl = itemIdImageUrlMap.get(itemId);
8212 amit.gupta 3243
				if (categoryId != 10073) {
6069 amit.gupta 3244
					tsvBuffer
8212 amit.gupta 3245
							.append(StringUtils.join(
3246
									new String[] {
3247
											itemId.toString(),
3248
											getTitle(item),
3249
											getUrl(item, "cameras"),
3250
											"" + (int) (item.getSellingPrice()),
3251
											"1",
3252
											categoryId == 11002 ? "802863031"
3253
													: "802865031",
3254
											productId,// productId,
3255
											productType, // productType,
3256
											"CamerasAndAccessories",
3257
											item.getBrand(),
3258
											item.getBrand(),
3259
											"",
3260
											item.getModelNumber(),
3261
											StringUtils.defaultString(fvalues
3262
													.get(AmazonFeatures.DESCRIPTION
3263
															.getValue())),
3264
											"0",
3265
											imageUrl,
3266
											""
3267
													+ (item.getMrp() == 0 ? (int) item
3268
															.getSellingPrice()
3269
															: (int) (item
3270
																	.getMrp())),
3271
											getAvailability(item),
3272
											StringUtils.defaultString(fvalues
3273
													.get(120332l)),// Optical
3274
																	// Zoom
3275
											StringUtils.defaultString(fvalues
3276
													.get(120333l)),// Digital
3277
																	// Zoom
3278
											sensorResolution, // Megapixels
3279
											StringUtils.defaultString(fvalues
3280
													.get(120005l)),// Display
3281
																	// Size
3282
											"",// Memory card type
3283
												// StringUtils.defaultString(fvalues.get(120355l)).replaceAll("--",
3284
												// ", "),//Memory Card types
3285
											viewFinder,
3286
											"other",
3287
											fvalues.containsKey(120374l) ? "yes"
3288
													: "no", // image
3289
															// stabilization
3290
											focalLength[0],
3291
											focalLength[1],
3292
											flashmount,
13386 manas 3293
											"",
3294
											"",
3295
											"",
3296
											"",
8212 amit.gupta 3297
											"credit_card|debit_card|net_banking|emi"
3298
													+ (Double
3299
															.valueOf(250D)
3300
															.compareTo(
3301
																	item.getSellingPrice()) <= 0
3302
															&& Double
3303
																	.valueOf(
3304
																			25000D)
3305
																	.compareTo(
3306
																			item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
3307
															: ""),
3308
											getResolution(Integer.parseInt(StringUtils
3309
													.defaultString(
3310
															fvalues.get(120340l)
3311
																	.split(" ")[0],
3312
															"0"))),
3313
											StringUtils.defaultString(
3314
													fvalues.get(120091l))
3315
													.split(" ")[0],
3316
											"",
3317
											item.getColor(),
3318
											"",
3319
											"",
3320
											warranty.equals("") ? ""
3321
													: warranty
3322
															+ " manufacturer's warranty",
3323
											"false",
3324
											normalizeBatteryType(batteryType),
3325
											"true", "true", "battery-powered",
3326
											"true", "", weight, length, height,
3327
											width, "" }, "\t")).append("\n");
6069 amit.gupta 3328
				}
8212 amit.gupta 3329
 
6069 amit.gupta 3330
			}
3331
		}
3332
		cameraFileWriter.write(tsvBuffer.toString());
3333
		cameraFileWriter.flush();
3334
		tsvBuffer.setLength(0);
9994 amit.gupta 3335
		cameraFileWriter.close();
8212 amit.gupta 3336
 
6069 amit.gupta 3337
		return;
8212 amit.gupta 3338
 
6069 amit.gupta 3339
	}
8212 amit.gupta 3340
 
4441 amit.gupta 3341
	private static String getScreenResolution(String scrResolution) {
4654 amit.gupta 3342
		if (StringUtils.isEmpty(scrResolution)) {
4441 amit.gupta 3343
			return "";
4654 amit.gupta 3344
		}
3345
		try {
3346
			return scrResolution.split(":")[1].trim();
3347
		} catch (Exception e) {
5257 amit.gupta 3348
			String[] splitString = scrResolution.split(" ");
5479 amit.gupta 3349
			return splitString[0] + "X" + splitString[2];
4441 amit.gupta 3350
		}
3351
	}
3352
 
3353
	private static String getWirelessType(String wirelessType) {
3354
		wirelessType = StringUtils.remove(wirelessType, "/");
4654 amit.gupta 3355
		wirelessType = StringUtils.join(
3356
				StringUtils.splitByCharacterType(wirelessType), "_");
4441 amit.gupta 3357
		wirelessType = StringUtils.remove(wirelessType, "._");
3358
		return wirelessType.toUpperCase();
3359
	}
3360
 
3361
	private static String getScreenSize(String screenSize) {
3362
		return screenSize.split(" ")[0];
3363
	}
3364
 
3365
	private static String getOS(String os) {
4654 amit.gupta 3366
		if (StringUtils.contains(os, "Linux"))
4441 amit.gupta 3367
			return "Linux";
4654 amit.gupta 3368
		if (StringUtils.contains(os, "DOS"))
4441 amit.gupta 3369
			return "DOS";
4654 amit.gupta 3370
		if (StringUtils.contains(os, "Windows 7 Starter"))
5511 amit.gupta 3371
			return "Windows 7 Starter";
3372
		if (StringUtils.contains(os, "Windows 7 Basic"))
3373
			return "Windows 7 Home Basic";
3374
		if (StringUtils.contains(os, "Windows 7 Ultimate"))
3375
			return "Windows 7 Ultimate";
3376
		if (StringUtils.contains(os, "Windows 7 Premium"))
3377
			return "Windows 7 Home Premium";
3378
		if (StringUtils.contains(os, "Windows 7 Enterprise"))
3379
			return "Windows 7 Enterprise";
3380
		if (StringUtils.contains(os, "Windows 7 Professional"))
3381
			return "Windows 7 Professional";
5681 amit.gupta 3382
		if (StringUtils.contains(os, "Mac OS X"))
3383
			return "Mac OS X";
4654 amit.gupta 3384
		else
4784 amit.gupta 3385
			return "";
4654 amit.gupta 3386
 
4441 amit.gupta 3387
	}
3388
 
3389
	private static String getType(String processorType) {
4654 amit.gupta 3390
		if (StringUtils.contains(processorType, "Core 2 Duo"))
4441 amit.gupta 3391
			return "core_2_duo";
4654 amit.gupta 3392
		if (StringUtils.contains(processorType, "AMD Athlon II"))
4441 amit.gupta 3393
			return "athlon_64_x2";
4654 amit.gupta 3394
		if (StringUtils.contains(processorType, "Intel Atom"))
4441 amit.gupta 3395
			return "intel_atom";
4784 amit.gupta 3396
		if (StringUtils.contains(processorType, "Pentium"))
3397
			return "pentium";
3398
		if (StringUtils.contains(processorType, "Celeron"))
3399
			return "pentium";
3400
		if (StringUtils.contains(processorType, "Celeron"))
3401
			return "celeron";
3402
		if (StringUtils.contains(processorType, "Celeron"))
3403
			return "celeron";
3404
		if (StringUtils.contains(processorType, "Intel Core"))
3405
			return "intel_core_solo";
3406
		if (StringUtils.contains(processorType, "AMD"))
3407
			return "turion_64";
4654 amit.gupta 3408
		else
4759 amit.gupta 3409
			return processorType;
4441 amit.gupta 3410
 
3411
	}
3412
 
5900 amit.gupta 3413
	private void generateMobileAccessories(List<Entity> entities,
3414
			String generationType) throws Exception {
3415
		StringBuffer tsvStringBuffer = new StringBuffer();
4675 amit.gupta 3416
 
5900 amit.gupta 3417
		// filter only phone related entities
3418
		for (Entity entity : entities) {
5257 amit.gupta 3419
			List<Item> items = getItemsByCatalogId(entity.getID());
5900 amit.gupta 3420
			Category category = Catalog.getInstance().getDefinitionsContainer()
3421
					.getCategory(entity.getCategoryID());
3422
			if (category == null) {
3423
				continue;
3424
			}
3425
			if (entity == null || entity.getSlides() == null
3426
					|| category.getParentCategory().getID() != 10011) {
3427
				continue;
3428
			}
4461 amit.gupta 3429
			AmazonCategories azCategory = null;
3430
			Long categoryId = category.getID();
4654 amit.gupta 3431
			if (categoryId.equals(10012L)) {
4461 amit.gupta 3432
				azCategory = AmazonCategories.MOBILE_ACCESSORY_BLUETOOTH_HEADSETS;
4654 amit.gupta 3433
			} else if (categoryId.equals(10013L)) {
4461 amit.gupta 3434
				azCategory = AmazonCategories.ACCESSORY_MICROSD;
4654 amit.gupta 3435
			} else if (categoryId.equals(10014L)) {
4461 amit.gupta 3436
				azCategory = AmazonCategories.MOBILE_ACCESSORY_BATTERIES;
4654 amit.gupta 3437
			} else if (categoryId.equals(10015L)) {
4461 amit.gupta 3438
				azCategory = AmazonCategories.MOBILE_ACCESSORY_HEADSETS;
4654 amit.gupta 3439
			} else if (categoryId.equals(10016L)) {
3440
				azCategory = AmazonCategories.MOBILE_ACCESSORY_MAINS_CHARGERS;
3441
			} else if (categoryId.equals(10017L)) {
3442
				azCategory = AmazonCategories.COMPUTER_ACCESSORY_FLASH_DRIVE;
4890 amit.gupta 3443
			} else if (categoryId.equals(10018L) || categoryId.equals(10021L)
3444
					|| categoryId.equals(10022L)) {
4461 amit.gupta 3445
				azCategory = AmazonCategories.MOBILE_ACCESSORY_COVERS;
4654 amit.gupta 3446
			} else if (categoryId.equals(10019L)) {
3447
				azCategory = AmazonCategories.MOBILE_ACCESSORY_CAR_CHARGERS;
3448
			} else if (categoryId.equals(10020L)) {
3449
				azCategory = AmazonCategories.MOBILE_ACCESSORY_SCREEN_GUARDS;
3450
			} else if (categoryId.equals(10026L)) {
3451
				azCategory = AmazonCategories.MOBILE_ACCESSORY_SPEAKERS;
4461 amit.gupta 3452
			} else {
5900 amit.gupta 3453
				continue;
4461 amit.gupta 3454
			}
3455
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
4654 amit.gupta 3456
 
5257 amit.gupta 3457
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
4742 amit.gupta 3458
			String metaKeywords = StringUtils.defaultString(fvalues
3459
					.get(AmazonFeatures.META_KEYWORDS.getValue()));
3460
			List<String> keywords = new ArrayList<String>();
4890 amit.gupta 3461
 
3462
			String bulletsString = StringUtils.defaultString(fvalues
3463
					.get(120081L));
4742 amit.gupta 3464
			List<String> bullets = new ArrayList<String>();
3465
			for (String keyword : bulletsString.split("--")) {
3466
				bullets.add(keyword.trim().replaceAll("\\s+", " "));
3467
			}
3468
			for (String keyword : metaKeywords.split(",")) {
3469
				keywords.add(keyword.trim());
3470
			}
4890 amit.gupta 3471
 
4742 amit.gupta 3472
			int length1 = keywords.size();
3473
			if (length1 < 5) {
3474
				while (length1 < 5) {
3475
					keywords.add("");
3476
					length1 = length1 + 1;
3477
				}
3478
			}
3479
			int length2 = bullets.size();
3480
			if (length2 < 5) {
3481
				while (length2 < 5) {
3482
					bullets.add("");
3483
					length2 = length2 + 1;
3484
				}
3485
			}
4654 amit.gupta 3486
 
9994 amit.gupta 3487
			CollectionUtils.filter(items, predicateLive);
4461 amit.gupta 3488
			if (CollectionUtils.isEmpty(items))
5900 amit.gupta 3489
				continue;
4654 amit.gupta 3490
			String storageCapacity = "";
4890 amit.gupta 3491
			String warranty = StringUtils.defaultString(fvalues.get(120125L))
3492
					+ " " + StringUtils.defaultString(fvalues.get(120219L));
3493
			String batteryType = StringUtils
3494
					.defaultString(fvalues.get(120103L));
13386 manas 3495
			//String batteryCap = StringUtils.defaultString(fvalues.get(120104L));
4890 amit.gupta 3496
			if (azCategory
3497
					.equals(AmazonCategories.COMPUTER_ACCESSORY_FLASH_DRIVE)) {
3498
				storageCapacity = StringUtils.defaultString(fvalues
3499
						.get(120112L));
4633 amit.gupta 3500
			}
4890 amit.gupta 3501
			if (azCategory.equals(AmazonCategories.MOBILE_ACCESSORY_BATTERIES)) {
3502
 
4742 amit.gupta 3503
			}
4890 amit.gupta 3504
			if (azCategory.equals(AmazonCategories.ACCESSORY_MICROSD)) {
3505
				storageCapacity = StringUtils.defaultString(fvalues
3506
						.get(120099L));
4742 amit.gupta 3507
			}
8212 amit.gupta 3508
 
4654 amit.gupta 3509
			for (Item item : items) {
4675 amit.gupta 3510
				String productType = "";
3511
				String productId = "";
3512
				Long itemId = item.getId();
5257 amit.gupta 3513
				List<String> itemNumbers = getItemNumbers(itemId);
4675 amit.gupta 3514
				if (!itemNumbers.isEmpty()) {
3515
					for (String itemNumber : itemNumbers) {
3516
						itemNumber = itemNumber.replaceAll("-", "");
3517
						try {
3518
							Long.parseLong(itemNumber);
3519
						} catch (NumberFormatException nfe) {
3520
							continue;
3521
						}
3522
						if (itemNumber.length() == 13) {
3523
							productType = "EAN";
3524
						} else if (itemNumber.length() == 12) {
3525
							productType = "UPC";
3526
						}
3527
						productId = itemNumber;
3528
						break;
3529
					}
3530
				}
8212 amit.gupta 3531
				tsvStringBuffer
3532
						.append(StringUtils.join(
5900 amit.gupta 3533
								new String[] {
3534
										new Long(item.getId()).toString(),
3535
										getTitle(item),
3536
										getUrl(item, "mobile-accessories"),
8212 amit.gupta 3537
										"" + (int) (item.getSellingPrice()),
5900 amit.gupta 3538
										"1",
3539
										azCategory == null ? "" : azCategory
3540
												.getValue().toString(),
8212 amit.gupta 3541
										productId,
3542
										productType,
3543
										"Wireless",
3544
										item.getBrand(),
3545
										item.getBrand(),
3546
										"",
5900 amit.gupta 3547
										item.getModelNumber(),
8212 amit.gupta 3548
										item.getFeatureDescription(),
3549
										"0",
5900 amit.gupta 3550
										itemIdImageUrlMap.get(item.getId()),
8212 amit.gupta 3551
										""
3552
												+ (item.getMrp() == 0 ? (int) item
3553
														.getSellingPrice()
3554
														: (int) (item.getMrp())),
3555
										getAvailability(item),
3556
										"",
3557
										"",
3558
										"",
3559
										"",
3560
										"",
3561
										"",
3562
										"",
3563
										"",
3564
										"",
3565
										"",
3566
										"",
3567
										"",
3568
										"",
3569
										"",
3570
										storageCapacity,
3571
										"",
3572
										"",
3573
										item.getColor(),
3574
										"",
3575
										"",
3576
										warranty,
3577
										"",
3578
										batteryType,
3579
										"",
3580
										"",
3581
										"",
3582
										"",
3583
										"",
3584
										"",
3585
										"",
3586
										"",
3587
										"",
3588
										keywords.get(0),
3589
										keywords.get(1),
3590
										keywords.get(2),
3591
										keywords.get(3),
3592
										keywords.get(4),
3593
										bullets.get(0),
3594
										bullets.get(1),
3595
										bullets.get(2),
3596
										bullets.get(3),
3597
										bullets.get(4),
3598
										"",
3599
										"",
3600
										"",
3601
										"",
3602
										"",
3603
										"",
3604
										"",
9994 amit.gupta 3605
										"",
5900 amit.gupta 3606
										item.getItemStatus().equals(
3607
												status.PHASED_OUT) ? "Delete"
3608
												: "",
8212 amit.gupta 3609
										"credit_card|debit_card|net_banking|emi"
3610
												+ (Double
3611
														.valueOf(250D)
3612
														.compareTo(
3613
																item.getSellingPrice()) <= 0
3614
														&& Double
3615
																.valueOf(25000D)
3616
																.compareTo(
3617
																		item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
3618
														: "") }, "\t")).append(
3619
								"\n");
5900 amit.gupta 3620
 
4461 amit.gupta 3621
			}
3622
		}
5900 amit.gupta 3623
		productFileWriter.write(tsvStringBuffer.toString());
3624
		productFileWriter.flush();
3625
		tsvStringBuffer.setLength(0);
3626
	}
4654 amit.gupta 3627
 
9996 amit.gupta 3628
	public void generateMobileData(List<Entity> entities) throws Exception {
4461 amit.gupta 3629
		System.out.println("INFO : Generating Products List for Amazon");
4633 amit.gupta 3630
 
5900 amit.gupta 3631
		StringBuffer tsvStringBuffer = new StringBuffer();
9994 amit.gupta 3632
		tsvStringBuffer.append(generateTSVHeader());
3633
		productFileWriter.write(tsvStringBuffer.toString());
3634
		productFileWriter.flush();
3635
		tsvStringBuffer.setLength(0);
4461 amit.gupta 3636
		// filter only phone related entities
3637
		for (Entity entity : entities) {
13386 manas 3638
			if (Catalog.getInstance().getDefinitionsContainer()
3639
					.getCategory(entity.getCategoryID()) == null) {
5086 amit.gupta 3640
				continue;
3641
			}
13386 manas 3642
			if (entity == null
3643
					|| entity.getSlides() == null
3644
					|| Catalog.getInstance().getDefinitionsContainer()
3645
							.getCategory(entity.getCategoryID())
3646
							.getParentCategory().getID() != 10001) {
4461 amit.gupta 3647
				continue;
3648
			}
3649
			// Treat phone related entities now.
3650
			// get Feature values for all entities required for amazon.
4722 amit.gupta 3651
			Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
5257 amit.gupta 3652
			List<Item> items = getItemsByCatalogId(entity.getID());
9994 amit.gupta 3653
			CollectionUtils.filter(items, predicateLive);
5257 amit.gupta 3654
			Map<Long, String> itemIdImageUrlMap = getAllImageUrls(entity, items);
4461 amit.gupta 3655
			if (CollectionUtils.isEmpty(items))
3656
				continue;
3657
			String screenSize = StringUtils.defaultString(fvalues
3658
					.get(AmazonFeatures.SCREEN_SIZE_IN.getValue()));
3659
			String weight = StringUtils.defaultString(fvalues
3660
					.get(AmazonFeatures.WEIGHT.getValue()));
3661
			String screenResolution = StringUtils.defaultString(fvalues
3662
					.get(AmazonFeatures.SCREEN_RESOLUTION.getValue()));
3663
			String screenType = StringUtils.defaultString(fvalues
3664
					.get(AmazonFeatures.SCREEN_TYPE.getValue()));
3665
			String touchscreenType = StringUtils.defaultString(fvalues
3666
					.get(AmazonFeatures.TOUCHSCREEN_TYPE.getValue()));
3667
			String multipleSIM = StringUtils.defaultString(fvalues
3668
					.get(AmazonFeatures.MULTIPLE_SIM.getValue()));
3669
			String network3G = StringUtils.defaultString(fvalues
3670
					.get(AmazonFeatures.NETWORK_3G.getValue()));
4654 amit.gupta 3671
			String opsys = StringUtils.defaultString(fvalues
3672
					.get(AmazonFeatures.OS.getValue()));
4461 amit.gupta 3673
			String formFactor = StringUtils.defaultString(fvalues
3674
					.get(AmazonFeatures.FORM_FACTOR.getValue()));
3675
			String warranty = StringUtils.defaultString(fvalues
3676
					.get(AmazonFeatures.WARRANTY.getValue()));
3677
			String batteryType = StringUtils.defaultString(fvalues
3678
					.get(AmazonFeatures.BATTERY_TYPE.getValue()));
4654 amit.gupta 3679
			String size = StringUtils.defaultString(fvalues
3680
					.get(AmazonFeatures.SIZE.getValue()));
4461 amit.gupta 3681
			String metaKeywords = StringUtils.defaultString(fvalues
3682
					.get(AmazonFeatures.META_KEYWORDS.getValue()));
3683
 
4890 amit.gupta 3684
			String color = StringUtils.defaultString(
3685
					fvalues.get(AmazonFeatures.COLOR.getValue())).split("--")[0];
3686
 
4461 amit.gupta 3687
			if (!StringUtils.isEmpty(screenSize)) {
3688
				screenSize = screenSize.split("\\s+")[0];
3689
			}
3690
			if (!StringUtils.isEmpty(screenResolution)) {
3691
				screenResolution = screenResolution.substring(0,
3692
						screenResolution.lastIndexOf(" "));
3693
			}
3694
 
3695
			screenType = normalizeScreenType(screenType);
3696
 
3697
			String cellularTechnology = getCellularTechnology(multipleSIM,
3698
					network3G);
3699
 
3700
			opsys = normalizeOperatingSystem(opsys);
3701
 
3702
			String userInput = "keypad";
3703
			if (touchscreenType != "") {
3704
				userInput = "touch_screen";
3705
			}
3706
 
3707
			formFactor = normalizeFormFactor(formFactor);
3708
 
3709
			if (StringUtils.isNotEmpty(warranty)) {
3710
				warranty = warranty + " manufacturer warranty";
3711
			}
3712
			batteryType = normalizeBatteryType(batteryType);
3713
 
3714
			String[] weightParts = weight.split("\\s+");
3715
			if (weightParts.length > 1) {
3716
				weight = weightParts[0];
3717
				try {
3718
					Float.parseFloat(weight);
3719
				} catch (NumberFormatException e) {
3720
					System.out.println(entity.getID()
3721
							+ "has invalid weight format");
4654 amit.gupta 3722
					// e.printStackTrace();
4461 amit.gupta 3723
					weight = "";
3724
				}
3725
			}
3726
			String length = "", width = "", height = "";
3727
			if (!(size.equals("Not available") || size.equals(""))) {
3728
				String[] list = size.split("\\s+");
3729
				length = list[0] + " MM";
3730
				width = list[2] + " MM";
3731
				height = list[4] + " MM";
3732
			}
3733
 
3734
			List<String> keywords = new ArrayList<String>();
3735
			for (String keyword : metaKeywords.split(",")) {
3736
				keywords.add(keyword.trim());
3737
			}
3738
			int length1 = keywords.size();
3739
			if (length1 < 5) {
3740
				while (length1 < 5) {
3741
					keywords.add("");
3742
					length1 = length1 + 1;
3743
				}
3744
			}
3745
			for (String keyword : keywords) {
3746
				if (keyword.length() > 50)
3747
					System.out.println(keyword);
3748
			}
8212 amit.gupta 3749
 
4461 amit.gupta 3750
			for (Item item : items) {
3751
				Long itemId = item.getId();
8212 amit.gupta 3752
 
5257 amit.gupta 3753
				List<String> itemNumbers = getItemNumbers(itemId);
4461 amit.gupta 3754
				String productId = "";
3755
				String productType = "";
4654 amit.gupta 3756
				if (!itemNumbers.isEmpty()) {
3757
					for (String itemNumber : itemNumbers) {
4633 amit.gupta 3758
						itemNumber = itemNumber.replaceAll("-", "");
3759
						try {
3760
							Long.parseLong(itemNumber);
3761
						} catch (NumberFormatException nfe) {
3762
							continue;
3763
						}
3764
						if (itemNumber.length() == 13) {
3765
							productType = "EAN";
3766
						} else if (itemNumber.length() == 12) {
3767
							productType = "UPC";
3768
						}
3769
						productId = itemNumber;
4890 amit.gupta 3770
						if (!productType.equals("")) {
3771
							break;
3772
						}
4633 amit.gupta 3773
					}
3774
				}
4890 amit.gupta 3775
 
3776
				if (item.getColor() != null) {
3777
					color = item.getColor();
3778
				}
4461 amit.gupta 3779
				String imageUrl = itemIdImageUrlMap.get(itemId);
4654 amit.gupta 3780
 
3781
				tsvStringBuffer
3782
						.append(StringUtils.join(
4461 amit.gupta 3783
								new String[] {
3784
										new Long(item.getId()).toString(),
3785
										getTitle(item),
3786
										getUrl(item, "mobile-phones"),
8212 amit.gupta 3787
										"" + (int) (item.getSellingPrice()),
4461 amit.gupta 3788
										"1",
3789
										"803073031",
3790
										productId,
3791
										productType,
3792
										"Wireless",
4492 amit.gupta 3793
										item.getBrand(),
3794
										item.getBrand(),
3795
										"",
3796
										item.getModelNumber(),
4461 amit.gupta 3797
										StringUtils.defaultString(fvalues
4492 amit.gupta 3798
												.get(AmazonFeatures.DESCRIPTION
4461 amit.gupta 3799
														.getValue())),
3800
										"0",
3801
										imageUrl,
8212 amit.gupta 3802
										""
3803
												+ (item.getMrp() == 0 ? (int) item
3804
														.getSellingPrice()
3805
														: (int) (item.getMrp())),
4492 amit.gupta 3806
										getAvailability(item),
3807
										opsys,
4654 amit.gupta 3808
										"",
3809
										"",
4890 amit.gupta 3810
										StringUtils.defaultString(
3811
												fvalues.get(120026L))
3812
												.split(" ")[0],// Digital zoom,
3813
																// Megapixel
4492 amit.gupta 3814
										screenSize,
3815
										cellularTechnology,
4722 amit.gupta 3816
										getMinutesForTalktime(fvalues),// Talktime
4890 amit.gupta 3817
										getHoursForStandBy(fvalues),// Standby
3818
																	// time
4654 amit.gupta 3819
										"", // charging time
4492 amit.gupta 3820
										userInput,
4654 amit.gupta 3821
										"", // device type
4492 amit.gupta 3822
										formFactor,
4654 amit.gupta 3823
										"", // connectivity Technologies
3824
										"", // Special features
4461 amit.gupta 3825
										StringUtils.defaultString(fvalues
3826
												.get(AmazonFeatures.BUILTIN_MEMORY
3827
														.getValue())),
4654 amit.gupta 3828
										"",// Optical zoom
3829
										"", // Memory Card Type
4890 amit.gupta 3830
										color,
4654 amit.gupta 3831
										"", // color map
3832
										"1",
4492 amit.gupta 3833
										warranty,
4654 amit.gupta 3834
										"false",// assembly
3835
										batteryType,
3836
										"true", // Batteries Included
3837
										"true", // Batteries Required
3838
										"battery-powered", // Power Source
3839
										"true", // Power Adapter inculded
3840
										"", // shipping weight
3841
										weight, // Weight
4492 amit.gupta 3842
										length,
3843
										height,
3844
										width,
4654 amit.gupta 3845
										// StringUtils.defaultString(fvalues.get(AmazonFeatures.RAM_MEMORY.getValue())),
3846
										// "", "",
3847
										keywords.get(0),
3848
										keywords.get(1),
3849
										keywords.get(2),
3850
										keywords.get(3),
3851
										keywords.get(4),
3852
										"",
3853
										"",
3854
										"",
3855
										"",
3856
										"",
3857
										"",
3858
										"",
3859
										"",
3860
										"",
3861
										"",
3862
										"",
3863
										"",
9994 amit.gupta 3864
										"",
4654 amit.gupta 3865
										item.getItemStatus().equals(
3866
												status.PHASED_OUT) ? "Delete"
5526 amit.gupta 3867
												: "",
8212 amit.gupta 3868
										"credit_card|debit_card|net_banking|emi"
3869
												+ (Double
3870
														.valueOf(250D)
3871
														.compareTo(
3872
																item.getSellingPrice()) <= 0
3873
														&& Double
3874
																.valueOf(25000D)
3875
																.compareTo(
3876
																		item.getSellingPrice()) >= 0 ? "|cash_on_delivery"
3877
														: "") }, "\t")).append(
3878
								"\n");
4461 amit.gupta 3879
			}
3880
 
3881
		}
5900 amit.gupta 3882
		productFileWriter.write(tsvStringBuffer.toString());
3883
		productFileWriter.flush();
3884
		tsvStringBuffer.setLength(0);
8212 amit.gupta 3885
		generateMobileAccessories(entities, generationType);
9994 amit.gupta 3886
		productFileWriter.close();
13386 manas 3887
		System.out.println("INFO : Feed successfully created at"
3888
				+ Utils.EXPORT_PATH + " successfully generated.");
9994 amit.gupta 3889
		GmailUtils gm = new GmailUtils();
3890
		String[] sendTo = { "amit.gupta@shop2020.in" };
3891
		try {
13386 manas 3892
			gm.sendSSLMessage(sendTo,
9994 amit.gupta 3893
					"Amazon Products Content Generation Successful ? : true",
3894
					"Content generation completed at time : "
3895
							+ Calendar.getInstance().getTime().toString(),
3896
					"build@shop2020.in", "cafe@nes", new ArrayList<File>());
3897
		} catch (MessagingException e) {
3898
			System.out.println("Could not send status mail" + e);
4633 amit.gupta 3899
		}
3900
	}
4654 amit.gupta 3901
 
5479 amit.gupta 3902
	private List<Item> getItemsByCatalogId(long id) throws Exception {
5257 amit.gupta 3903
		try {
3904
			return cc.getItemsByCatalogId(id);
5479 amit.gupta 3905
		} catch (Exception e) {
5257 amit.gupta 3906
			cc = new CatalogClient().getClient();
3907
			return cc.getItemsByCatalogId(id);
3908
		}
3909
	}
5479 amit.gupta 3910
 
5257 amit.gupta 3911
	private List<String> getItemNumbers(Long itemId) throws Exception {
3912
		try {
3913
			return whc.getItemNumbers(itemId);
5479 amit.gupta 3914
		} catch (Exception e) {
5257 amit.gupta 3915
			whc = new WarehouseClient().getClient();
3916
			return whc.getItemNumbers(itemId);
3917
		}
3918
	}
8212 amit.gupta 3919
 
5900 amit.gupta 3920
	public void generateSCProdData() throws Exception {
13580 manas 3921
		/*try {
3922
			Map<Long, Entity> entities = CreationUtils.getEntities();
3923
			fullValidEntities = new ArrayList<Entity>();
3924
	        System.out.println("Size of entities is " + entities.size());
3925
	        for (long entityID : entities.keySet()) {
3926
	        	fullValidEntities.add(entities.get(entityID));
3927
	            }
3928
 
3929
		} catch (Exception e) {
3930
			e.printStackTrace();
3931
		}
3932
		this.validEntites = fullValidEntities;
3933
			generateMobileData(this.validEntites);
13386 manas 3934
			generateLaptopData(this.validEntites);
13580 manas 3935
			generateCameraData(this.validEntites);
3936
			generateLaptopAccessories(this.validEntites);
3937
 
3938
			generateSmartWatch(this.validEntites);
3939
 
3940
		*/
3941
 
13386 manas 3942
		if(isFullUpload==true){
3943
			System.out.println("Full upload is true");
3944
			try {
3945
				Map<Long, Entity> entities = CreationUtils.getEntities();
3946
				fullValidEntities = new ArrayList<Entity>();
3947
		        for (long entityID : entities.keySet()) {
3948
		        	fullValidEntities.add(entities.get(entityID));
3949
		            }
3950
 
3951
			} catch (Exception e) {
3952
				e.printStackTrace();
3953
			}
3954
			this.validEntites = fullValidEntities;
3955
			if(this.validEntites.size()<=0){
3956
				return;
3957
			}
3958
			System.out.println("Size of valid entities is " + this.validEntites.size());
3959
		}
3960
		else{
3961
			/*try {
3962
				Map<Long, Entity> entities = CreationUtils.getEntities();
3963
				fullValidEntities = new ArrayList<Entity>();
3964
		        for (long entityID : entities.keySet()) {
3965
		        	fullValidEntities.add(entities.get(entityID));
3966
		            }
3967
 
3968
			} catch (Exception e) {
3969
				e.printStackTrace();
3970
			}
3971
			this.validEntites = fullValidEntities;*/
3972
			if(this.validEntites.size()>0){
3973
			List<String> skuList = generateSKUList(this.validEntites);
3974
			deleteNode(skuList);
3975
			}
3976
			else{
13580 manas 3977
				System.out.println("Size of list is empty.. Please Check");	
13386 manas 3978
				return;
3979
			}
3980
		}
3981
			generateLaptopDataXML(this.validEntites);
3982
			generateCameraDataXML(this.validEntites);
3983
			generateMobileDataXML(this.validEntites);
13580 manas 3984
			generateSmartWatchData(this.validEntites);
3985
			if(isFullUpload==true){
3986
				generateSmartWatch(this.validEntites);
3987
			}
3988
			/*generateLaptopAccessoriesXML(this.validEntites);*/
13386 manas 3989
			generateXMLfile(mobileXMLFile, docu);
4461 amit.gupta 3990
	}
13386 manas 3991
 
3992
	public List<String> generateSKUList(List<Entity> vEntities) {
3993
		List<Item> items = null;
3994
		List<String> skuList = new ArrayList<String>();
13526 amit.gupta 3995
		for (Entity entity : vEntities) 
13386 manas 3996
		{
3997
			if (Catalog.getInstance().getDefinitionsContainer()
13526 amit.gupta 3998
				.getCategory(entity.getCategoryID()) == null) {
13386 manas 3999
				continue;
4000
			}
13526 amit.gupta 4001
			if (entity == null || entity.getSlides() == null) {
13386 manas 4002
				continue;
4003
			}
4004
			try {
13526 amit.gupta 4005
				items= getItemsByCatalogId(entity.getID());
13386 manas 4006
			} catch (Exception e) {
4007
				System.out.println("e");
4008
				e.printStackTrace();
4009
			}
4010
			for (Item item : items) {
4011
				Long itemId = item.getId();
4012
				skuList.add(String.valueOf(itemId));
4013
 
4014
			}
4015
		}
4016
		return skuList;
4017
	}
4018
 
4019
	public void deleteNode(List<String> skuList) {
4020
			NodeList list = docu.getElementsByTagName(rowHeader);
4021
			for (int s = 0; s < list.getLength(); s++) {
4022
			     Node fstNode = list.item(s);
4023
				 Element fstElmnt = (Element) fstNode;
4024
				 String sk = getTagValue("SKU", fstElmnt);
4025
				 if(skuList.contains(sk)){
4026
					 fstElmnt.getParentNode().removeChild(fstNode);
4027
					 System.out.println("Element deleted with SKU ID " + sk);
4028
				  }
4029
			}
13580 manas 4030
		System.out.println("Total number of elements to be deleted : " + list.getLength());
13386 manas 4031
		return;
4032
	}
4033
 
4034
 
4035
	private static String getTagValue(String tag, Element eElement) {
4036
	    NodeList nlList = eElement.getElementsByTagName(tag).item(0).getChildNodes();
4037
	    if(nlList == null) 
4038
	        return null;
4039
	    Node nValue = (Node) nlList.item(0);
4040
	    return nValue.getNodeValue();
4041
	}
4042
 
6193 amit.gupta 4043
	private String getAvailability(Item item) {
10002 amit.gupta 4044
		String availability = "FALSE";
8212 amit.gupta 4045
		if (item.getItemStatus().equals(status.ACTIVE)) {
4046
			if (!(item.isRisky() && PAUSED_BY_RISK_ITEMS.contains(item.getId()))) {
10002 amit.gupta 4047
				availability = "TRUE";
8212 amit.gupta 4048
			}
4049
		}
4492 amit.gupta 4050
		return availability;
4051
	}
4052
 
4461 amit.gupta 4053
	private static StringBuffer generateTSVHeader() {
4054
		StringBuffer tsvStringBuffer = new StringBuffer();
4055
		tsvStringBuffer.append(
4056
				StringUtils.join(new String[] {
4057
						"Amazon.com Product Ads Header", "Purge-Replace=false",
4058
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
4059
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
4060
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
4061
						"", "", "", "", "", "", "", "", "", "", "", "", "", "",
4654 amit.gupta 4062
						"", "", "", "", "", "", "", "", "", "", "" }, "\t"))
4063
				.append("\n");
4461 amit.gupta 4064
		tsvStringBuffer.append(
4654 amit.gupta 4065
				StringUtils.join(new String[] { "SKU", "Title", "Link",
4066
						"Price", "Delivery Time", "Recommended Browse Node",
4067
						"Standard Product ID", "Product ID Type", "Category",
4068
						"Brand", "Manufacturer", "Mfr part number",
4069
						"Model Number", "Description", "Shipping Cost",
4070
						"Image", "List Price", "Availability",
4071
						"Operating System", "Wireless Type", "Digital zoom",
4072
						"Megapixels", "Display size", "Cellular Technology",
4073
						"Talk Time", "Standby Time", "Charging Time",
4074
						"User Input", "Device Type", "Form Factor",
4075
						"Connectivity Technology", "Special Features",
4076
						"Memory Storage Capacity", "Optical Zoom",
4077
						"Memory Card Type", "Colour Name", "Colour Map",
4078
						"Item Package Quantity", "Warranty",
4079
						"Assembly required", "Battery Cell Composition",
4080
						"Batteries Included", "Batteries Required",
4081
						"Power Source", "Power Adapter Included",
4082
						"Shipping Weight", "Weight", "Length", "Height",
4083
						"Width", "Keywords1", "Keywords2", "Keywords3",
4084
						"Keywords4", "Keywords5", "Bullet point1",
4085
						"Bullet point2", "Bullet point3", "Bullet point4",
4086
						"Bullet point5", "Other image-url1",
4087
						"Other image-url2", "Other image-url3",
8212 amit.gupta 4088
						"Other image-url4", "Other image-url5", "Offer note",
4089
						"Discount Amount", "Junglee Exclusive Offer",
4090
						"Offer Promo Code", "Is Gift Wrap Available",
4091
						"Registered Parameter", "Update Delete",
4092
						"Accepted Payment Methods" }, "\t")).append("\n");
4461 amit.gupta 4093
		return tsvStringBuffer;
4094
	}
4095
 
5479 amit.gupta 4096
	public static void generatePricesAndAvailability(List<Item> items)
4097
			throws Exception {
8330 amit.gupta 4098
		System.out.println("INFO : Generating Products Prices and Availability for Amazon");
5479 amit.gupta 4099
		StringBuffer tsvStringBuffer = new StringBuffer();
9982 amit.gupta 4100
		tsvStringBuffer.append("Amazon.com Product Ads Header\tPurge-Replace=false\nSKU\tPrice\tAvailability\tDelivery Time\tUpdate Delete\n");
8330 amit.gupta 4101
 
5479 amit.gupta 4102
		for (Item item : items) {
4103
			Long itemId = item.getId();
8212 amit.gupta 4104
			String price = "" + (int) (item.getSellingPrice());
13386 manas 4105
			if (item.isRisky() && PAUSED_BY_RISK_ITEMS.contains(item.getId())) {
8330 amit.gupta 4106
				continue;
8212 amit.gupta 4107
			}
9982 amit.gupta 4108
			tsvStringBuffer.append(itemId + "\t" + price + "\tTRUE\t1\tPartialUpdate\n");
5479 amit.gupta 4109
		}
13386 manas 4110
 
4111
		String fileName = "PricesAndAvailabilityONE.tsv";
8212 amit.gupta 4112
		String filePath = Utils.EXPORT_PATH + fileName;
4113
		File f1 = new File(filePath);
5479 amit.gupta 4114
		FileWriter writer1 = new FileWriter(f1);
4115
		writer1.write(tsvStringBuffer.toString());
4116
		writer1.close();
13386 manas 4117
		System.out.println("INFO : PricesAndAvailability.tsv successfully created at /home/amit/Desktop/cms/ successfully generated.");
4118
		System.out.println("INFO : To generate Products List for Amazon type command : java AmazonSCDataGenerator products/prices");
5479 amit.gupta 4119
 
4120
		ConfigClient configClient = ConfigClient.getClient();
4121
		String isFtpUpload = configClient.get("UPLOAD_AMAZON_CONTENT_FTP");
4122
		// upload the file to Amazon ftp location only when app is run from
4123
		// staging
4124
		System.out.println("Is ftp Upload:" + isFtpUpload);
4125
		if (isFtpUpload.equals("TRUE")) {
8248 amit.gupta 4126
			try {
13386 manas 4127
				upload(FTP_UPLOAD_URL, FTP_USER_NAME, FTP_PASSWORD, filePath,
4128
						fileName);
4129
			} catch (Exception e) {
8271 amit.gupta 4130
				e.printStackTrace();
8248 amit.gupta 4131
				System.out.println("Couldnt upload" + e);
4132
				// Eventually other operations here ...
4133
				GmailUtils gm = new GmailUtils();
4134
				// "rajveer.singh@shop2020.in",
4135
				String[] sendTo = { "amit.gupta@shop2020.in" };
13386 manas 4136
 
8248 amit.gupta 4137
				try {
8249 amit.gupta 4138
					gm.sendSSLMessage(sendTo, "FTP upload failed",
4139
							"Upload time : "
13386 manas 4140
									+ Calendar.getInstance().getTime()
4141
											.toString(), "build@shop2020.in",
4142
							"cafe@nes", Utils.EXPORT_PATH
4143
									+ "PricesAndAvailabilityONE.tsv");
8248 amit.gupta 4144
				} catch (MessagingException me) {
4145
					System.out.println("Could not send status mail" + me);
4146
				}
4147
			}
5479 amit.gupta 4148
		}
4149
		return;
4150
	}
13386 manas 4151
	private static Element elementDataPricesAvailability(Document doc, String name,String value) {
4152
	    Element el = doc.createElement(name);
4153
	    el.appendChild(doc.createTextNode(value));
4154
	    return el;
4155
	}
5479 amit.gupta 4156
 
4654 amit.gupta 4157
	public static void generatePricesAndAvailability() throws Exception {
4461 amit.gupta 4158
		CatalogClient cc = new CatalogClient();
4159
		Client cl = cc.getClient();
4654 amit.gupta 4160
 
13386 manas 4161
		System.out.println("INFO : Generating Products Prices and Availability for Amazon");
4654 amit.gupta 4162
		StringBuffer tsvStringBuffer = new StringBuffer();
13386 manas 4163
		tsvStringBuffer.append("Amazon.com Product Ads Header\tPurge-Replace=false\nSKU\tPrice\tAvailability\tDelivery Time\tUpdate Delete\tOffer note\n");
4654 amit.gupta 4164
 
13386 manas 4165
		String headerArray[] ={"SKU","Price","Availability","DeliveryTime","UpdateDelete","OfferNote"};
4166
 
4167
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
4168
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
4169
 
4170
		Document doc = docBuilder.newDocument();
4171
		Element rootElement = doc.createElement("junglee-feed");
4172
		doc.appendChild(rootElement);
4173
 
8271 amit.gupta 4174
		List<Item> items = cl.getAllItemsByStatus(status.ACTIVE);
4175
		for (Item item : items) {
13386 manas 4176
 
8271 amit.gupta 4177
			Long itemId = item.getId();
8839 amit.gupta 4178
			String offerNote = item.getBestDealText();
13386 manas 4179
			if (offerNote == null || offerNote.trim().equals("")) {
8839 amit.gupta 4180
				offerNote = "NA";
4181
			}
13386 manas 4182
			Element row = doc.createElement("row");
8271 amit.gupta 4183
			String price = "" + (int) (item.getSellingPrice());
13386 manas 4184
			if (item.isRisky() && PAUSED_BY_RISK_ITEMS.contains(item.getId())) {
4185
				tsvStringBuffer.append(itemId + "\t" + price + "\tFALSE\t1\tPartialUpdate\t" + offerNote + "\n");
4186
				rootElement.appendChild(row);
4187
				String dataArray[] = {itemId+"",price,"FALSE",1+"","PartialUpdate",offerNote};
4188
 
4189
				for(int loopCount=0;loopCount<dataArray.length;loopCount++){
4190
					if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
4191
						continue;
4192
					row.appendChild(elementDataPricesAvailability(doc,headerArray[loopCount],dataArray[loopCount]));
4193
				}
4194
 
4195
 
4196
			} else {
4197
				tsvStringBuffer.append(itemId + "\t" + price + "\tTRUE\t1\tPartialUpdate\t" + offerNote + "\n");
4198
				String dataArray[] = {itemId+"",price,"TRUE",1+"","PartialUpdate",offerNote};
4199
				rootElement.appendChild(row);
4200
				for(int loopCount=0;loopCount<dataArray.length;loopCount++){
4201
					if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
4202
						continue;
4203
					row.appendChild(elementDataPricesAvailability(doc,headerArray[loopCount],dataArray[loopCount]));
4204
				}
4205
			}
4654 amit.gupta 4206
		}
8376 amit.gupta 4207
		items.clear();
4208
		items.addAll(cl.getAllItemsByStatus(status.PAUSED));
4209
		items.addAll(cl.getAllItemsByStatus(status.PHASED_OUT));
13386 manas 4210
		for (Item item : items) {
8839 amit.gupta 4211
			String offerNote = item.getBestDealText();
13386 manas 4212
			Element row = doc.createElement("row");
4213
			if (offerNote == null || offerNote.trim().equals("")) {
8839 amit.gupta 4214
				offerNote = "NA";
4215
			}
8376 amit.gupta 4216
			Long itemId = item.getId();
4217
			String price = "" + (int) (item.getSellingPrice());
13386 manas 4218
			tsvStringBuffer.append(itemId + "\t" + price + "\tFALSE\t1\tPartialUpdate\t" + offerNote + "\n");
4219
			String dataArray[] = {itemId+"",price,"FALSE",1+"","PartialUpdate",offerNote};
4220
			rootElement.appendChild(row);
4221
			for(int loopCount=0;loopCount<dataArray.length;loopCount++){
4222
				if(dataArray[loopCount]=="" || dataArray[loopCount]==null)
4223
					continue;
4224
				row.appendChild(elementDataPricesAvailability(doc,headerArray[loopCount],dataArray[loopCount]));
4225
			}
8376 amit.gupta 4226
		}
13386 manas 4227
 
4228
		String fileNameXML = "PricesAndAvailability.xml";
10042 amit.gupta 4229
		String filePath = Utils.EXPORT_PATH;
13386 manas 4230
 
4231
		String fileName = "PricesAndAvailability.tsv"; 
10043 amit.gupta 4232
		File f1 = new File(filePath + fileName);
4233
		FileWriter writer1 = new FileWriter(f1 + "");
4654 amit.gupta 4234
		writer1.write(tsvStringBuffer.toString());
4235
		writer1.close();
13386 manas 4236
 
4237
		File xmlFile = new File(filePath + fileNameXML);
4238
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
4239
		Transformer transformer = transformerFactory.newTransformer();
4240
		DOMSource source = new DOMSource(doc);
4241
		StreamResult result = new StreamResult(xmlFile);
4242
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
4243
		transformer.setOutputProperty(OutputKeys.METHOD, "xml");
4244
		transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
4245
		transformer.transform(source, result);
4246
		System.out.println("INFO : PricesAndAvailability.xml successfully created at /home/amit/Desktop/cms/ successfully generated.");
4247
 
4248
		System.out.println("INFO : PricesAndAvailability.tsv successfully created at /home/amit/Desktop/cms/ successfully generated.");
8212 amit.gupta 4249
		System.out.println("INFO : To generate Products List for Amazon type command : java AmazonSCDataGenerator products/prices");
4461 amit.gupta 4250
 
4654 amit.gupta 4251
		ConfigClient configClient = ConfigClient.getClient();
4252
		String isFtpUpload = configClient.get("UPLOAD_AMAZON_CONTENT_FTP");
4253
		// upload the file to Amazon ftp location only when app is run from
4254
		// staging
13386 manas 4255
		// Get all files with name tsv
10042 amit.gupta 4256
		File dir = new File(filePath);
13386 manas 4257
		File[] files = dir.listFiles(new FilenameFilter() {
4258
			@Override
4259
			public boolean accept(File dir, String name) {
4260
				return name.endsWith(".tsv")
4261
						&& !name.equals("PricesAndAvailabilityONE.tsv");
4262
			}
10042 amit.gupta 4263
		});
4264
		Comparator<File> comp = new Comparator<File>() {
4265
			@Override
4266
			public int compare(File arg0, File arg1) {
13386 manas 4267
				if (arg1.getName().equals("PricesAndAvailability.tsv")) {
10042 amit.gupta 4268
					return 1;
4269
				}
4270
				return 0;
4271
			}
4272
		};
4273
		Arrays.sort(files, comp);
4714 amit.gupta 4274
		System.out.println("Is ftp Upload:" + isFtpUpload);
13386 manas 4275
	/*	if (isFtpUpload.equals("TRUE")) {
8248 amit.gupta 4276
			System.out.println("Before upload call");
13386 manas 4277
			try {
4278
				upload(FTP_UPLOAD_URL, FTP_USER_NAME, FTP_PASSWORD, files);
4279
			} catch (Exception e1) {
8271 amit.gupta 4280
				System.out.println(e1.getMessage());
4281
				e1.printStackTrace();
4282
				// Eventually other operations here ...
4283
				GmailUtils gm = new GmailUtils();
4284
				// "rajveer.singh@shop2020.in",
4285
				String[] sendTo = { "amit.gupta@shop2020.in" };
13386 manas 4286
 
8271 amit.gupta 4287
				try {
13386 manas 4288
					gm.sendSSLMessage(sendTo,
4289
							"Failed to upload amazon Prices and Availability",
8271 amit.gupta 4290
							"Reupload prices and availability",
4291
							"build@shop2020.in", "cafe@nes", Utils.EXPORT_PATH
13386 manas 4292
									+ "PricesAndAvailability.tsv");
8271 amit.gupta 4293
				} catch (MessagingException e) {
4294
					System.out.println("Could not send status mail" + e);
4295
				}
4296
			}
13386 manas 4297
		}*/
4298
		// delete these files once uploaded
4299
		for (File f : files) {
4300
			f.renameTo(new File(f.getAbsolutePath() + "0"));
4654 amit.gupta 4301
		}
4302
		return;
4461 amit.gupta 4303
	}
4304
 
10042 amit.gupta 4305
	public static void upload(String hostName, String username,
4306
			String password, File[] files) {
4307
 
4308
		StandardFileSystemManager manager = new StandardFileSystemManager();
4309
 
4310
		try {
4311
			manager.init();
4312
 
4313
			// Create remote file object
13386 manas 4314
			for (File file : files) {
10044 amit.gupta 4315
				FileObject remoteFile = manager.resolveFile(
13386 manas 4316
						createConnectionString(hostName, username, password,
4317
								file.getName()), createDefaultOptions());
10042 amit.gupta 4318
				// Create local file object
13386 manas 4319
				FileObject localFile = manager.resolveFile(file
4320
						.getAbsolutePath());
4321
 
10042 amit.gupta 4322
				// Copy local file to sftp server
4323
				remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
4324
			}
4325
 
4326
			System.out.println("All files uploaded successfully");
4327
		} catch (Exception e) {
4328
			throw new RuntimeException(e);
4329
		} finally {
4330
			manager.close();
4331
		}
4332
	}
13386 manas 4333
 
4890 amit.gupta 4334
	private static String getHoursForStandBy(Map<Long, String> fvalues) {
4722 amit.gupta 4335
		String standby = fvalues.get(AmazonFeatures.STANDBY_2G.getValue());
4890 amit.gupta 4336
		if (standby == null) {
4722 amit.gupta 4337
			standby = fvalues.get(AmazonFeatures.STANDBY_2G.getValue());
4338
		}
4890 amit.gupta 4339
		if (standby == null) {
4722 amit.gupta 4340
			return "";
4341
		}
4890 amit.gupta 4342
		String[] dayshours = standby.split("\\D+");
4730 amit.gupta 4343
		String days = "0";
4722 amit.gupta 4344
		String hours = "0";
4890 amit.gupta 4345
		if (dayshours.length > 0) {
4730 amit.gupta 4346
			days = dayshours[0];
4890 amit.gupta 4347
			if (dayshours.length > 1) {
4730 amit.gupta 4348
				hours = dayshours[1];
4349
			}
4722 amit.gupta 4350
		}
4890 amit.gupta 4351
		try {
4730 amit.gupta 4352
 
4890 amit.gupta 4353
			String s = String.valueOf(Integer.parseInt(days) * 24
4354
					+ Integer.parseInt(hours));
4355
			return s.equals("0") ? "" : s;
4356
		} catch (Exception e) {
4722 amit.gupta 4357
			return "";
4358
		}
4359
	}
4633 amit.gupta 4360
 
4890 amit.gupta 4361
	private static String getMinutesForTalktime(Map<Long, String> fvalues) {
4722 amit.gupta 4362
		String talktime = fvalues.get(AmazonFeatures.TALKTIME_2G.getValue());
4890 amit.gupta 4363
		if (talktime == null) {
4722 amit.gupta 4364
			talktime = fvalues.get(AmazonFeatures.TALKTIME_3G.getValue());
4365
		}
4890 amit.gupta 4366
		if (talktime == null) {
4722 amit.gupta 4367
			return "";
4368
		}
4890 amit.gupta 4369
		String[] hourMins = talktime.split("\\D+");
4722 amit.gupta 4370
		String hours = "0";
4371
		String mins = "0";
4890 amit.gupta 4372
		if (hourMins.length > 0) {
4373
			if (!hourMins[0].equals("")) {
4722 amit.gupta 4374
				hours = hourMins[0];
4375
			}
4890 amit.gupta 4376
			if (hourMins.length > 3) {
4377
				if (!hourMins[3].equals("")) {
4730 amit.gupta 4378
					mins = hourMins[3];
4722 amit.gupta 4379
				}
4380
			}
4381
		}
4890 amit.gupta 4382
		try {
4383
			String s = String.valueOf(Integer.parseInt(hours) * 60
4384
					+ Integer.parseInt(mins));
4385
			return s.equals("0") ? "" : s;
4386
		} catch (Exception e) {
4722 amit.gupta 4387
			return "";
4388
		}
4389
	}
8212 amit.gupta 4390
 
4391
	private String getResolution(int dots) {
6069 amit.gupta 4392
		switch (dots) {
8212 amit.gupta 4393
		case 307200:
4394
			return "640 x 480";
4395
		case 480000:
4396
			return "800 x 600";
4397
		case 614400:
4398
			return "1024 x 600";
4399
		case 786432:
4400
			return "1024 x 768";
4401
		case 995328:
4402
			return "1152 x 864";
4403
		case 921600:
4404
			return "1280 x 720";
4405
		case 983040:
4406
			return "1280 x 768";
4407
		case 1024000:
4408
			return "1280 x 800";
4409
		case 1228800:
4410
			return "1280 x 960";
4411
		case 1310720:
4412
			return "1280 x 1024";
4413
		case 1044480:
4414
			return "1360 x 768";
4415
		case 1049088:
4416
			return "1366 x 768";
4417
		case 1470000:
4418
			return "1400 x 1050";
4419
		case 1296000:
4420
			return "1440 x 900";
4421
		case 1440000:
4422
			return "1600 x 900";
4423
		case 1920000:
4424
			return "1600 x 1200";
4425
		case 1764000:
4426
			return "1680 x 1050";
4427
		case 2073600:
4428
			return "1920 x 1080";
4429
		case 2304000:
4430
			return "1920 x 1200";
4431
		case 2359296:
4432
			return "2048 x 1152";
4433
		case 3686400:
4434
			return "2560 x 1440";
4435
		case 4096000:
4436
			return "2560 x 1600";
4437
		case 671102:
4438
			return "1093 x 614";
4439
		case 966207:
4440
			return "1311 x 737";
4441
		default:
4442
			return "";
6069 amit.gupta 4443
		}
4722 amit.gupta 4444
 
8212 amit.gupta 4445
	}
6069 amit.gupta 4446
 
7708 amit.gupta 4447
	private static List<Long> getPausedByRiskItems() {
4448
		try {
13386 manas 4449
			Reader reader = new FileReader(Utils.EXPORT_PATH + Utils.RISKY_PAUSED_JSON);
8212 amit.gupta 4450
			return new Gson().fromJson(reader, new TypeToken<List<Long>>() {
4451
			}.getType());
7708 amit.gupta 4452
		} catch (FileNotFoundException e) {
4453
			log.error("Could not read popularity file");
4454
			e.printStackTrace();
4455
			return new ArrayList<Long>();
4456
		}
8212 amit.gupta 4457
 
7708 amit.gupta 4458
	}
6069 amit.gupta 4459
 
8212 amit.gupta 4460
	public static void upload(String hostName, String username,
4461
			String password, String localFilePath, String remoteFilePath) {
4462
 
4463
		File file = new File(localFilePath);
4464
		if (!file.exists())
4465
			throw new RuntimeException("Error. Local file not found");
4466
 
4467
		StandardFileSystemManager manager = new StandardFileSystemManager();
4468
 
4469
		try {
4470
			manager.init();
4471
 
4472
			// Create local file object
4473
			FileObject localFile = manager.resolveFile(file.getAbsolutePath());
4474
 
4475
			// Create remote file object
4476
			FileObject remoteFile = manager.resolveFile(
4477
					createConnectionString(hostName, username, password,
4478
							remoteFilePath), createDefaultOptions());
4479
 
4480
			// Copy local file to sftp server
4481
			remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
4482
 
4483
			System.out.println("File upload success");
4484
		} catch (Exception e) {
4485
			throw new RuntimeException(e);
4486
		} finally {
4487
			manager.close();
4488
		}
4489
	}
4490
 
4491
	public static String createConnectionString(String hostName,
4492
			String username, String password, String remoteFilePath) {
4493
		return "sftp://" + username + ":" + password + "@" + hostName + "/"
4494
				+ remoteFilePath;
4495
	}
4496
 
4497
	// Method to setup default SFTP config:
4498
	public static FileSystemOptions createDefaultOptions()
4499
			throws FileSystemException {
4500
		// Create SFTP options
4501
		FileSystemOptions opts = new FileSystemOptions();
4502
 
4503
		// SSH Key checking
4504
		SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
4505
				opts, "no");
4506
 
4507
		// Root directory set to user home
4508
		SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
4509
 
4510
		// Timeout is count by Milliseconds
4511
		SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
4512
 
4513
		return opts;
4514
	}
4515
 
4403 amit.gupta 4516
}