Subversion Repositories SmartDukaan

Rev

Rev 2668 | Rev 3719 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2668 Rev 2726
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
3
import in.shop2020.metamodel.core.Entity;
3
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.core.EntityState;
-
 
5
import in.shop2020.metamodel.core.EntityStatus;
-
 
6
import in.shop2020.metamodel.core.Slide;
4
import in.shop2020.metamodel.core.Slide;
7
import in.shop2020.metamodel.util.CreationUtils;
5
import in.shop2020.metamodel.util.CreationUtils;
8
import in.shop2020.metamodel.util.ExpandedBullet;
6
import in.shop2020.metamodel.util.ExpandedBullet;
9
import in.shop2020.metamodel.util.ExpandedEntity;
7
import in.shop2020.metamodel.util.ExpandedEntity;
10
import in.shop2020.metamodel.util.ExpandedFeature;
8
import in.shop2020.metamodel.util.ExpandedFeature;
Line 16... Line 14...
16
import java.util.Collection;
14
import java.util.Collection;
17
import java.util.HashMap;
15
import java.util.HashMap;
18
import java.util.List;
16
import java.util.List;
19
import java.util.Map;
17
import java.util.Map;
20
import java.util.Map.Entry;
18
import java.util.Map.Entry;
-
 
19
import java.util.Set;
21
 
20
 
22
import org.apache.commons.lang.StringUtils;
21
import org.apache.commons.lang.StringUtils;
23
 
22
 
24
 
23
 
25
public class AccessoriesFinder {
24
public class AccessoriesFinder {
26
	CategoryManager catm = CategoryManager.getCategoryManager();
25
	CategoryManager catm = CategoryManager.getCategoryManager();
-
 
26
	Set<Long> entityIds;
27
	
27
	
28
	public static void main(String[] args) throws Exception {
28
	public static void main(String[] args) throws Exception {
29
		AccessoriesFinder af = new AccessoriesFinder();
29
//		AccessoriesFinder af = new AccessoriesFinder();
30
		Map<Long, Map<Long, List<Long>>> relatedAccessories = af.findAccessories();
30
//		Map<Long, Map<Long, List<Long>>> relatedAccessories = af.findAccessories();
31
		CreationUtils.storeRelatedAccessories(relatedAccessories);
31
//		CreationUtils.storeRelatedAccessories(relatedAccessories);
32
	}
32
	}
33
 
33
 
34
 
34
 
35
	
35
	
36
	public AccessoriesFinder(){
36
	public AccessoriesFinder(Set<Long> entityIds){
-
 
37
		this.entityIds = entityIds;	
37
	}
38
	}
38
	
39
	
39
	
40
	
40
	public Map<Long, Map<Long, List<Long>>> findAccessories() throws Exception {
41
	public Map<Long, Map<Long, List<Long>>> findAccessories() throws Exception {
41
		Map<Long, Map<Long, List<Long>>> entityAccessories = new HashMap<Long, Map<Long, List<Long>>>();
42
		Map<Long, Map<Long, List<Long>>> entityAccessories = new HashMap<Long, Map<Long, List<Long>>>();
42
		
43
		
43
		List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
44
		//List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
44
		Map<Long, Map<Long, Object>> categoryParameterMap = new HashMap<Long, Map<Long,Object>>();
45
		Map<Long, Map<Long, Object>> categoryParameterMap = new HashMap<Long, Map<Long,Object>>();
45
		for(Long categoryID: categoryIDs){
46
//		for(Long categoryID: categoryIDs){
46
			categoryParameterMap.put(categoryID, populateParameters(categoryID));
47
//			categoryParameterMap.put(categoryID, populateParameters(categoryID));
47
		}
48
//		}
48
		
49
		
49
		for(Entity entity: CreationUtils.getEntities().values()){
-
 
50
			if(entity.getCategoryID() == -1){
50
		populateParameters(categoryParameterMap);
51
				continue;
51
		
52
			}
52
		
53
			EntityState state = CreationUtils.getEntityState(entity.getID());
53
		for(Long entityID: entityIds){
54
			if(state.getStatus() != EntityStatus.READY){
54
			Entity entity = CreationUtils.getEntity(entityID);
55
				continue;
-
 
56
			}
-
 
57
			
-
 
58
			Map<Long, Object> entityCategoryParameters = getEntityCategoryParameters(entity);
55
			Map<Long, Object> entityCategoryParameters = getEntityCategoryParameters(entity);
59
			if(catm.getCategory(entity.getCategoryID()).getParent_category_id() != Utils.MOBILE_ACCESSORIES_CATEGORY){
56
			if(catm.getCategory(entity.getCategoryID()).getParent_category_id() != Utils.MOBILE_ACCESSORIES_CATEGORY){
60
				entityAccessories.put(entity.getID(), getRelatedAccessories(entityCategoryParameters, categoryParameterMap));
57
				entityAccessories.put(entity.getID(), getRelatedAccessories(entityCategoryParameters, categoryParameterMap));
61
			}
58
			}
62
		}
59
		}
63
 
-
 
64
		return entityAccessories;
60
		return entityAccessories;
65
		/*
-
 
66
		List<Long> includeCategories = new ArrayList<Long>();
-
 
67
		
-
 
68
		includeCategories.add((long) BATTERY);
-
 
69
		includeCategories.add((long) CARRYING_CASE);
-
 
70
		includeCategories.add((long) CHARGER);
-
 
71
		includeCategories.add((long) SCREEN_GUARD);
-
 
72
		includeCategories.add((long) MEMORY_CARD);
-
 
73
		includeCategories.add((long) HEADSET);
-
 
74
		includeCategories.add((long) BLUETOOTH_HEADSET);
-
 
75
		
-
 
76
		
-
 
77
		StringBuffer sb = new  StringBuffer();
-
 
78
		for(Entry<Long, Map<Long, List<Long>>> entry: entityAccessories.entrySet()){
-
 
79
			long entityID = entry.getKey();
-
 
80
			EntityState state = CreationUtils.getEntityState(entityID);
-
 
81
			String entityName = state.getBrand() + " " + state.getModelName() + " " + state.getModelNumber();
-
 
82
			sb.append(entityName + " " + entityID);
-
 
83
			for(Entry<Long, List<Long>> entry1: entry.getValue().entrySet()){
-
 
84
				long categoryID = entry1.getKey();
-
 
85
				if(!includeCategories.contains(categoryID) ){
-
 
86
					continue;
-
 
87
				}
-
 
88
				String catName = catm.getCategoryLabel(categoryID);
-
 
89
				sb.append("\n\t");
-
 
90
				sb.append(catName);
-
 
91
				sb.append("\t");
-
 
92
				for(Long accID: entry1.getValue()){
-
 
93
					EntityState astate = CreationUtils.getEntityState(accID);
-
 
94
					if(astate.getStatus() != EntityStatus.READY){
-
 
95
						continue;
-
 
96
					}
-
 
97
					String accName = astate.getBrand() + " " + astate.getModelName() + " " + astate.getModelNumber();
-
 
98
					sb.append(accName + " " + accID);
-
 
99
					sb.append("\t");
-
 
100
				}
-
 
101
			}
-
 
102
			sb.append("\n");
-
 
103
			
-
 
104
			
-
 
105
		}
-
 
106
		//System.out.println(sb.toString());
-
 
107
		FileUtils.writeStringToFile(new File("/home/rajveer/Desktop/accfile"), sb.toString());
-
 
108
		//System.out.println(entityAccessories); 
-
 
109
		*/
-
 
110
	}
61
	}
111
 
62
 
112
	private Map<Long, Object> getEntityCategoryParameters(Entity entity) throws Exception {
63
	private Map<Long, Object> getEntityCategoryParameters(Entity entity) throws Exception {
113
		Map<Long, Object> entityCategoryParameters = new HashMap<Long, Object>();
64
		Map<Long, Object> entityCategoryParameters = new HashMap<Long, Object>();
114
		List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
65
		List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
Line 196... Line 147...
196
					if(unitId == 50008){
147
					if(unitId == 50008){
197
						memory = 1024 * memory;
148
						memory = 1024 * memory;
198
					}
149
					}
199
					params.put("MEMORY", memory+"");
150
					params.put("MEMORY", memory+"");
200
					return params;
151
					return params;
201
					/*
-
 
202
					long memory = Long.parseLong(expBullet.getValue());
-
 
203
					long unitId = expBullet.getUnitID();
-
 
204
					if(unitId == 50008){
-
 
205
						memory = 1024 * memory;
-
 
206
					}
-
 
207
					*/
-
 
208
				}
152
				}
209
			}
153
			}
210
			break;
154
			break;
-
 
155
 
211
			//Bluetooth headset
156
			//Bluetooth headset
212
			case (int) Utils.BLUETOOTH_HEADSET:
157
			case (int) Utils.BLUETOOTH_HEADSET:
213
				if(expEntity.getBrand() == null){
158
				if(expEntity.getBrand() == null){
214
					return null;
159
					return null;
215
				}
160
				}
Line 288... Line 233...
288
					}
233
					}
289
					String batteryCapacity = accessoryParameter.get("BATTERY_CAPACITY").trim();
234
					String batteryCapacity = accessoryParameter.get("BATTERY_CAPACITY").trim();
290
					String batteryModel = accessoryParameter.get("BATTERY_MODEL").trim();
235
					String batteryModel = accessoryParameter.get("BATTERY_MODEL").trim();
291
					String mobileBatteryCapacity = mobileParameter.get("BATTERY_CAPACITY").trim();
236
					String mobileBatteryCapacity = mobileParameter.get("BATTERY_CAPACITY").trim();
292
					String mobileBatteryModel  = mobileParameter.get("BATTERY_MODEL").trim();
237
					String mobileBatteryModel  = mobileParameter.get("BATTERY_MODEL").trim();
293
					//System.out.println(batteryCapacity + " = " + mobileBatteryCapacity);
-
 
294
					//System.out.println(batteryModel + " = " + mobileBatteryModel);
-
 
295
					if(batteryCapacity.equalsIgnoreCase(mobileBatteryCapacity) && batteryModel.equalsIgnoreCase(mobileBatteryModel)){
238
					if(batteryCapacity.equalsIgnoreCase(mobileBatteryCapacity) && batteryModel.equalsIgnoreCase(mobileBatteryModel)){
296
						List<Long> accessories = relatedAccessories.get(categoryID);
239
						List<Long> accessories = relatedAccessories.get(categoryID);
297
						if(accessories == null){
240
						if(accessories == null){
298
							accessories = new ArrayList<Long>();
241
							accessories = new ArrayList<Long>();
299
							relatedAccessories.put(categoryID, accessories);
242
							relatedAccessories.put(categoryID, accessories);
Line 374... Line 317...
374
							relatedAccessories.put(categoryID, accessories);
317
							relatedAccessories.put(categoryID, accessories);
375
						}
318
						}
376
						accessories.add(entityID);
319
						accessories.add(entityID);
377
					}
320
					}
378
				}
321
				}
379
				System.out.println(sb1.toString());
-
 
380
 
322
 
381
				break;
323
				break;
382
 
324
 
383
			
325
			
384
			//Memory Card
326
			//Memory Card
Line 506... Line 448...
506
		}
448
		}
507
		return relatedAccessories;
449
		return relatedAccessories;
508
	}
450
	}
509
 
451
 
510
	
452
	
-
 
453
	private void populateParameters(Map<Long, Map<Long, Object>> categoryParameterMap) throws Exception {
-
 
454
		for(Long entityID: entityIds){
-
 
455
			Entity entity = CreationUtils.getEntity(entityID);
-
 
456
			ExpandedEntity expEntity = new ExpandedEntity(entity);
-
 
457
			Long categoryID = entity.getCategoryID();
-
 
458
			switch (categoryID.intValue()) {
-
 
459
			//Battery
-
 
460
			case (int) Utils.BATTERY:
-
 
461
				ExpandedSlide expCompatibilitySlide = expEntity.getExpandedSlide(130066);
-
 
462
				if(expCompatibilitySlide != null){
-
 
463
					List<ExpandedFeature> compatibilityFeatures = expCompatibilitySlide.getExpandedFeatures();
-
 
464
					for(ExpandedFeature feature: compatibilityFeatures){
-
 
465
						if(feature.getFeatureDefinitionID() == 120104){
-
 
466
							ExpandedBullet bullet = feature.getExpandedBullets().get(0);
-
 
467
							Map<String, String> params = new HashMap<String, String>();
-
 
468
							String capacity = bullet.getValue();
-
 
469
							capacity = capacity.split(" ")[0];
-
 
470
							params.put("BATTERY_CAPACITY", capacity);
-
 
471
							params.put("BATTERY_MODEL", entity.getModelNumber().trim());
-
 
472
							putParameterIntoMap(categoryID, entityID, params, categoryParameterMap);
-
 
473
						}
-
 
474
					}
-
 
475
				}
-
 
476
				break;
-
 
477
				
-
 
478
			//Screen Guard
-
 
479
			case (int) Utils.SCREEN_GUARD:
-
 
480
				Slide compatibilitySlide = entity.getSlide(130073);
-
 
481
				if(compatibilitySlide != null){
-
 
482
					String fft =  compatibilitySlide.getFreeformContent().getFreeformText();
-
 
483
					if(fft != null && !fft.trim().isEmpty()){
-
 
484
						putParameterIntoMap(categoryID, entityID, fft, categoryParameterMap);
-
 
485
					}
-
 
486
				}
-
 
487
				break;
-
 
488
	
-
 
489
			//Carrying Case
-
 
490
			case (int) Utils.CARRYING_CASE:
-
 
491
				Slide ccCompatibilitySlide = entity.getSlide(130073);
-
 
492
				if(ccCompatibilitySlide != null){
-
 
493
					String fft =  ccCompatibilitySlide.getFreeformContent().getFreeformText();
-
 
494
					if(fft != null && !fft.trim().isEmpty()){
-
 
495
						putParameterIntoMap(categoryID, entityID, fft, categoryParameterMap);
-
 
496
					}
-
 
497
				}
-
 
498
				break;
-
 
499
 
-
 
500
				//Memory Card
-
 
501
				case (int) Utils.MEMORY_CARD:
-
 
502
					putParameterIntoMap(categoryID, entityID, entity.getBrand() + " " + entity.getModelName() + " " + entity.getModelNumber(), categoryParameterMap);
-
 
503
					/*
-
 
504
					ExpandedEntity expEntity = new ExpandedEntity(entity);
-
 
505
					ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130065);
-
 
506
					List<ExpandedFeature> compatibilityExpandedFeatures = compatibilitySlide.getExpandedFeatures();
-
 
507
					for(ExpandedFeature expFeature: compatibilityExpandedFeatures){
-
 
508
						if(expFeature.getFeatureDefinitionID() == 120099){
-
 
509
							ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
-
 
510
							if(expBullet.displayText() == null || expBullet.displayText().trim().equals("")){
-
 
511
								continue;
-
 
512
							}
-
 
513
							long memory = Long.parseLong(expBullet.getValue());
-
 
514
							long unitId = expBullet.getUnitID();
-
 
515
							if(unitId == 50008){
-
 
516
								memory = 1024 * memory;
-
 
517
							}
-
 
518
							entityParameterMap.put(entity.getID(), memory+"");
-
 
519
						}
-
 
520
					}
-
 
521
					*/
-
 
522
					break;
-
 
523
 
-
 
524
				//Bluetooth Headset
-
 
525
				case (int) Utils.BLUETOOTH_HEADSET:
-
 
526
					putParameterIntoMap(categoryID, entityID, entity.getModelNumber().trim(), categoryParameterMap);
-
 
527
					break;
-
 
528
 
-
 
529
				//Headset
-
 
530
				case (int) Utils.HEADSET:
-
 
531
					ExpandedSlide headsetCompatibilitySlide = expEntity.getExpandedSlide(130068);
-
 
532
					if(headsetCompatibilitySlide != null){
-
 
533
						List<ExpandedFeature> compatibilityFeatures = headsetCompatibilitySlide.getExpandedFeatures();
-
 
534
						for(ExpandedFeature feature: compatibilityFeatures){
-
 
535
							if(feature.getFeatureDefinitionID() == 120105){
-
 
536
								ExpandedBullet bullet = feature.getExpandedBullets().get(0);
-
 
537
								putParameterIntoMap(categoryID, entityID, bullet.getValue(), categoryParameterMap);
-
 
538
							}
-
 
539
						}
-
 
540
					}
-
 
541
					break;
-
 
542
 
-
 
543
				//Charger
-
 
544
				case (int) Utils.CHARGER:
-
 
545
					ExpandedSlide chargerCompatibilitySlide = expEntity.getExpandedSlide(130069);
-
 
546
					if(chargerCompatibilitySlide != null){
-
 
547
						List<ExpandedFeature> compatibilityFeatures = chargerCompatibilitySlide.getExpandedFeatures();
-
 
548
						for(ExpandedFeature feature: compatibilityFeatures){
-
 
549
							if(feature.getFeatureDefinitionID() == 120107){
-
 
550
								ExpandedBullet bullet = feature.getExpandedBullets().get(0);
-
 
551
								Map<String, String> params = new HashMap<String, String>();
-
 
552
								String model = entity.getModelName() + " " + entity.getModelNumber();
-
 
553
								model = model.replaceAll("Charger", "").trim();
-
 
554
								params.put("BRAND", entity.getBrand());
-
 
555
								params.put("CONNECTOR_PIN", bullet.getValue());
-
 
556
								params.put("MODEL", model);
-
 
557
								putParameterIntoMap(categoryID, entityID, params, categoryParameterMap);
-
 
558
							}
-
 
559
						}
-
 
560
					}
-
 
561
					break;
-
 
562
 
-
 
563
			default:
-
 
564
				break;
-
 
565
			}
-
 
566
		}
-
 
567
	}
-
 
568
	
-
 
569
	
-
 
570
	void putParameterIntoMap(Long categoryID, Long entityID, Object params, Map<Long, Map<Long, Object>> categoryParameterMap){
-
 
571
		Map<Long, Object> entityParameterMap = categoryParameterMap.get(categoryID); 
-
 
572
		if(entityParameterMap == null){
-
 
573
			entityParameterMap = new HashMap<Long, Object>();
-
 
574
			categoryParameterMap.put(categoryID, entityParameterMap);
-
 
575
		}
-
 
576
		entityParameterMap.put(entityID, params);	
-
 
577
	}
-
 
578
	
-
 
579
	
-
 
580
 
-
 
581
	
511
	private Map<Long, Object> populateParameters(long categoryID) throws Exception {
582
	private Map<Long, Object> populateParameters(long categoryID) throws Exception {
512
		Map<Long, Object> entityParameterMap = new HashMap<Long, Object>();
583
		Map<Long, Object> entityParameterMap = new HashMap<Long, Object>();
513
		Collection<Entity> entities = CreationUtils.getEntities(categoryID);
584
		Collection<Entity> entities = CreationUtils.getEntities(categoryID);
514
 
585
		
515
		switch ((int)categoryID) {
586
		switch ((int)categoryID) {
516
		
587
		
517
		//Battery
588
		//Battery
518
		case (int) Utils.BATTERY:
589
		case (int) Utils.BATTERY:
519
			for(Entity entity: entities){
590
			for(Entity entity: entities){
Line 545... Line 616...
545
					if(fft != null && !fft.trim().isEmpty()){
616
					if(fft != null && !fft.trim().isEmpty()){
546
						entityParameterMap.put(entity.getID(), fft);
617
						entityParameterMap.put(entity.getID(), fft);
547
					}
618
					}
548
				}
619
				}
549
			}
620
			}
550
			System.out.println(entityParameterMap);
-
 
551
			break;
621
			break;
552
 
622
 
553
		//Carrying Case
623
		//Carrying Case
554
		case (int) Utils.CARRYING_CASE:
624
		case (int) Utils.CARRYING_CASE:
555
			for(Entity entity: entities){
625
			for(Entity entity: entities){
Line 559... Line 629...
559
					if(fft != null && !fft.trim().isEmpty()){
629
					if(fft != null && !fft.trim().isEmpty()){
560
						entityParameterMap.put(entity.getID(), fft);
630
						entityParameterMap.put(entity.getID(), fft);
561
					}
631
					}
562
				}
632
				}
563
			}
633
			}
564
			System.out.println(entityParameterMap);
-
 
565
			break;
634
			break;
566
 
635
 
567
		//Memory Card
636
		//Memory Card
568
		case (int) Utils.MEMORY_CARD:
637
		case (int) Utils.MEMORY_CARD:
569
			for(Entity entity: entities){
638
			for(Entity entity: entities){
Line 638... Line 707...
638
			break;
707
			break;
639
 
708
 
640
		default:
709
		default:
641
			break;
710
			break;
642
		}
711
		}
643
		
-
 
644
		return entityParameterMap;
712
		return entityParameterMap;
645
	}
713
	}
646
	
714
	
647
}
-
 
648
 
-
 
649
 
-
 
650
/*
-
 
651
DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
-
 
652
 
-
 
653
IRMetaDataJythonWrapper jy = new IRMetaDataJythonWrapper();
-
 
654
 
-
 
655
Map<Long, FacetDefinition> facetDefs = defs.getFacetDefinitions();
-
 
656
for(FacetDefinition facetDef : facetDefs.values()) {
-
 
657
	
-
 
658
	jy.reset();
-
 
659
	jy.initialize();
-
 
660
 
-
 
661
	ExpandedFacetDefinition expFacetDef = 
-
 
662
		new ExpandedFacetDefinition(facetDef);
-
 
663
	
-
 
664
	jy.setExpandedFacetDefinition(expFacetDef);
-
 
665
	
-
 
666
	jy.setPossibleValues(facetIDFacetValues.get(facetDef.getID()));
-
 
667
	
-
 
668
	jy.executeRule();
-
 
669
	
-
 
670
	String facetXMLSnip = jy.getXMLSnippet();
-
 
671
	Utils.info("facetXMLSnip=" + facetXMLSnip);
-
 
672
}
-
 
673
*/
-
 
674
715
}
-
 
716
675
717