Subversion Repositories SmartDukaan

Rev

Rev 5106 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5106 Rev 5311
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;
4
import in.shop2020.metamodel.core.Slide;
6
import in.shop2020.metamodel.core.Slide;
5
import in.shop2020.metamodel.definitions.Catalog;
7
import in.shop2020.metamodel.definitions.Catalog;
6
import in.shop2020.metamodel.definitions.Category;
8
import in.shop2020.metamodel.definitions.Category;
7
import in.shop2020.metamodel.definitions.DefinitionsContainer;
9
import in.shop2020.metamodel.definitions.DefinitionsContainer;
8
import in.shop2020.metamodel.util.CreationUtils;
10
import in.shop2020.metamodel.util.CreationUtils;
Line 19... Line 21...
19
import java.util.Map;
21
import java.util.Map;
20
import java.util.Map.Entry;
22
import java.util.Map.Entry;
21
import java.util.Set;
23
import java.util.Set;
22
 
24
 
23
import org.apache.commons.lang.StringUtils;
25
import org.apache.commons.lang.StringUtils;
-
 
26
import org.apache.commons.logging.Log;
-
 
27
import org.apache.commons.logging.LogFactory;
24
 
28
 
25
 
29
 
26
public class AccessoriesFinder {
30
public class AccessoriesFinder {
27
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
31
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
28
	Set<Long> entityIds;
32
	Set<Long> entityIds;
29
	
33
	
-
 
34
	private static Log log = LogFactory.getLog(ContentGenerationUtility.class);
-
 
35
	
30
	public static void main(String[] args) throws Exception {
36
	public static void main(String[] args) throws Exception {
-
 
37
		Map<Long,Entity> map = CreationUtils.getEntities();
-
 
38
		Map<Long,Entity> map1 = new HashMap<Long, Entity>();
-
 
39
		for (Map.Entry<Long, Entity> entry : map.entrySet()){
-
 
40
			EntityState es = CreationUtils.getEntityState(entry.getKey());
-
 
41
			if(es.getStatus().equals(EntityStatus.READY)){
-
 
42
				map1.put(entry.getKey(), entry.getValue());
-
 
43
			}
-
 
44
		}
31
//		AccessoriesFinder af = new AccessoriesFinder();
45
		AccessoriesFinder af = new AccessoriesFinder(map1.keySet());
32
//		Map<Long, Map<Long, List<Long>>> relatedAccessories = af.findAccessories();
46
		Map<Long, Map<Long, List<Long>>> relatedAccessories = af.findAccessories();
-
 
47
		for(Map.Entry<Long, Map<Long, List<Long>>> entry : relatedAccessories.entrySet()){
-
 
48
			for(Map.Entry<Long, List<Long>> entry1 : entry.getValue().entrySet()){
-
 
49
				if(entry1.getValue().size()<1){
-
 
50
					log.error("Could not find accessories for :" + entry.getKey());
-
 
51
				}
-
 
52
			}
-
 
53
			
-
 
54
		}
33
//		CreationUtils.storeRelatedAccessories(relatedAccessories);
55
		CreationUtils.storeRelatedAccessories(relatedAccessories);
34
	}
56
	}
35
 
57
 
36
 
58
 
37
	
59
	
38
	public AccessoriesFinder(Set<Long> entityIds){
60
	public AccessoriesFinder(Set<Long> entityIds){
Line 59... Line 81...
59
				Category cat = defContainer.getCategory(entity.getCategoryID()).getParentCategory();
81
				Category cat = defContainer.getCategory(entity.getCategoryID()).getParentCategory();
60
				if(cat.isHasAccessories()){
82
				if(cat.isHasAccessories()){
61
					entityAccessories.put(entity.getID(), getRelatedAccessories(entityCategoryParameters, categoryParameterMap));
83
					entityAccessories.put(entity.getID(), getRelatedAccessories(entityCategoryParameters, categoryParameterMap));
62
				}
84
				}
63
			}catch (Exception e) {
85
			}catch (Exception e) {
64
				System.out.println("Error for entity " + entityID + " "+ e);
86
				log.error("Error for entity " + entityID);
65
			}
87
			}
66
		}
88
		}
67
		return entityAccessories;
89
		return entityAccessories;
68
	}
90
	}
69
 
91
 
Line 83... Line 105...
83
 
105
 
84
	private Object populateEntityParameters(Long categoryID,	Entity entity) throws Exception {
106
	private Object populateEntityParameters(Long categoryID,	Entity entity) throws Exception {
85
		ExpandedEntity expEntity = new ExpandedEntity(entity);
107
		ExpandedEntity expEntity = new ExpandedEntity(entity);
86
		ExpandedSlide batterySlide = expEntity.getExpandedSlide(130043);
108
		ExpandedSlide batterySlide = expEntity.getExpandedSlide(130043);
87
		Map<String, String> params = new HashMap<String, String>();		
109
		Map<String, String> params = new HashMap<String, String>();		
88
		
110
		Long entityId = entity.getID();
89
		switch (categoryID.intValue()) {
111
		switch (categoryID.intValue()) {
90
		//Battery
112
		//Battery
91
		case (int) Utils.BATTERY:
113
		case (int) Utils.BATTERY:
92
			if(expEntity.getBrand() == null)
114
			if(expEntity.getBrand() == null)
93
				return null;
115
				return null;
-
 
116
			//All brand of batteries are now permissible.
94
			if(expEntity.getBrand().trim().compareToIgnoreCase("nokia")!=0){
117
			/*if(expEntity.getBrand().trim().compareToIgnoreCase("nokia")!=0){
95
				return null;
118
				return null;
96
			}
119
			}*/
97
			if(batterySlide == null)
120
			if(batterySlide == null)
98
				return null;
121
				return null;
99
			List<ExpandedFeature> expFeatures = batterySlide.getExpandedFeatures();
122
			List<ExpandedFeature> expFeatures = batterySlide.getExpandedFeatures();
100
			for(ExpandedFeature expFeature: expFeatures){
123
			for(ExpandedFeature expFeature: expFeatures){
101
				if(expFeature.getFeatureDefinitionID() == 120072){
124
				if(expFeature.getFeatureDefinitionID() == 120072){
102
					ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
125
					this.getBulletDisplayText(expFeature.getExpandedBullets());
103
					String type = expBullet.displayText();
126
					String type = this.getBulletDisplayText(expFeature.getExpandedBullets());
-
 
127
					if(StringUtils.isEmpty(type)){
-
 
128
						continue;
-
 
129
					}
104
					//Li-Ion 1020 mAh battery BL-5C;
130
					//Li-Ion 1020 mAh battery BL-5C;
105
					String[] parts =  type.split("battery");
131
					String[] parts =  type.split("battery");
106
					if(parts.length >= 2){
132
					if(parts.length >= 2){
107
						params.put("BATTERY_MODEL", parts[1]);
133
						params.put("BATTERY_MODEL", parts[1]);
-
 
134
					} else {
-
 
135
						log.info("Could not find Battery Model for : " + entityId);
-
 
136
						return null;
108
					} 
137
					}
109
					String last = "";
138
					String last = "";
110
					parts = type.split(" ");
139
					parts = type.split(" ");
111
					for(String part: parts){
140
					for(String part: parts){
112
						if(part.contains("mAh")){
141
						if(part.contains("mAh")){
113
							params.put("BATTERY_CAPACITY", last);
142
							params.put("BATTERY_CAPACITY", last);
-
 
143
						} else {
-
 
144
							log.info("Could not find Battery Capacity for : " + entityId);
-
 
145
							return null;
114
						}
146
						}
115
						last = part;
147
						last = part;
116
					}
148
					}
117
					return params;
149
					return params;
118
				}
150
				}
Line 141... Line 173...
141
			if(memorySlide == null)
173
			if(memorySlide == null)
142
				return null;
174
				return null;
143
			List<ExpandedFeature> memoryExpandedFeatures = memorySlide.getExpandedFeatures();
175
			List<ExpandedFeature> memoryExpandedFeatures = memorySlide.getExpandedFeatures();
144
			for(ExpandedFeature expFeature: memoryExpandedFeatures){
176
			for(ExpandedFeature expFeature: memoryExpandedFeatures){
145
				if(expFeature.getFeatureDefinitionID() == 120032){
177
				if(expFeature.getFeatureDefinitionID() == 120032){
146
					ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
178
					ExpandedBullet bull = getBullet(expFeature.getExpandedBullets());
-
 
179
					if(bull !=null) {
147
					params.put("MEMORY_TYPE", expBullet.getValue().split(" ")[0]);
180
						params.put("MEMORY_TYPE", bull.getValue().split(" ")[0]);
-
 
181
					} else {
-
 
182
						log.info("Could not find memory type for entity : " + entityId);
-
 
183
						return null;
-
 
184
					}
148
				}
185
				}
149
				
186
				
150
				if(expFeature.getFeatureDefinitionID() == 120033){
187
				if(expFeature.getFeatureDefinitionID() == 120033){
151
					ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
188
					ExpandedBullet expBullet = getBullet(expFeature.getExpandedBullets());
-
 
189
					if(expBullet != null){
152
					long memory = Long.parseLong(expBullet.getValue());
190
						long memory = Long.parseLong(expBullet.getValue());
153
					long unitId = expBullet.getUnitID();
191
						long unitId = expBullet.getUnitID();
154
					if(unitId == 50008){
192
						if(unitId == 50008){
155
						memory = 1024 * memory;
193
							memory = 1024 * memory;
-
 
194
						}
-
 
195
						params.put("MEMORY", memory+"");
-
 
196
					} else {
-
 
197
						log.info("Could not find memory size for entity : " + entityId);
-
 
198
						return null;
156
					}
199
					}
157
					params.put("MEMORY", memory+"");
-
 
158
					return params;
-
 
159
				}
200
				}
-
 
201
				return params;
160
			}
202
			}
161
			break;
203
			break;
162
 
204
 
163
			//Bluetooth headset
205
			//Bluetooth headset
164
			case (int) Utils.BLUETOOTH_HEADSET:
206
			case (int) Utils.BLUETOOTH_HEADSET:
Line 186... Line 228...
186
				List<ExpandedFeature> musicFeatures = musicSlide.getExpandedFeatures();
228
				List<ExpandedFeature> musicFeatures = musicSlide.getExpandedFeatures();
187
				for(ExpandedFeature expFeature: musicFeatures){
229
				for(ExpandedFeature expFeature: musicFeatures){
188
					if(expFeature.getFeatureDefinitionID() == 120023){
230
					if(expFeature.getFeatureDefinitionID() == 120023){
189
						List<ExpandedBullet> bullets = expFeature.getExpandedBullets();
231
						List<ExpandedBullet> bullets = expFeature.getExpandedBullets();
190
						if(bullets!=null){
232
						if(bullets!=null){
-
 
233
							ExpandedBullet expBullet = getBullet(bullets);
-
 
234
							if(expBullet != null){
191
							return expFeature.getExpandedBullets().get(0).getValue();
235
								return expBullet.getValue();
-
 
236
							} 
-
 
237
							log.info("Could not fild Headphones pin size for entity : " + entityId);
-
 
238
							return null;
192
						}
239
						}
193
					}
240
					}
194
				}
241
				}
195
				break;
242
				break;
196
 
243
 
Line 202... Line 249...
202
					return null;
249
					return null;
203
				Map<String, String> chargerparams = new HashMap<String, String>();
250
				Map<String, String> chargerparams = new HashMap<String, String>();
204
				List<ExpandedFeature> batteryFeatures = batterySlide.getExpandedFeatures();
251
				List<ExpandedFeature> batteryFeatures = batterySlide.getExpandedFeatures();
205
				for(ExpandedFeature expFeature: batteryFeatures){
252
				for(ExpandedFeature expFeature: batteryFeatures){
206
					if(expFeature.getFeatureDefinitionID() == 120073){
253
					if(expFeature.getFeatureDefinitionID() == 120073){
207
						ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
254
						ExpandedBullet expBullet = getBullet(expFeature.getExpandedBullets());
-
 
255
						if(expBullet != null){
208
						chargerparams.put("POWER_ADAPTOR", expBullet.getValue());
256
							chargerparams.put("POWER_ADAPTOR", expBullet.getValue());
209
						chargerparams.put("BRAND", expEntity.getBrand().trim());
257
							chargerparams.put("BRAND", expEntity.getBrand().trim());
210
						return chargerparams;
258
							return chargerparams;
-
 
259
						} else {
-
 
260
							log.info("Could not find adaptor detail for entity: " + entityId);
-
 
261
							return null;
-
 
262
						}
211
					}
263
					}
212
				}
264
				}
213
				return null;			
265
				return null;			
214
			
266
			
215
		default:
267
		default:
Line 348... Line 400...
348
					}
400
					}
349
					if(mobileParameter==null){
401
					if(mobileParameter==null){
350
						continue;
402
						continue;
351
					}
403
					}
352
					String parts[] = accessoryParameter.split(" |-");
404
					String parts[] = accessoryParameter.split(" |-");
-
 
405
					try{
353
					long cardMemory = 1024*Long.parseLong(parts[parts.length - 1].replaceAll("GB", "").replaceAll("MB", ""));
406
						long cardMemory = 1024*Long.parseLong(parts[parts.length - 1].replaceAll("GB", "").replaceAll("MB", ""));
354
					String memoryCapacity = mobileParameter.get("MEMORY");
407
						String memoryCapacity = mobileParameter.get("MEMORY");
355
					String memoryType = mobileParameter.get("MEMORY_TYPE");
408
						String memoryType = mobileParameter.get("MEMORY_TYPE");
356
					if(memoryCapacity == null || memoryType == null ){
409
						if(memoryCapacity == null || memoryType == null ){
357
						continue;
-
 
358
					}
-
 
359
					if(Long.parseLong(memoryCapacity.trim()) < cardMemory){
-
 
360
						continue;
410
							continue;
361
					}
-
 
362
					
-
 
363
					
-
 
364
					if(StringUtils.containsIgnoreCase(accessoryParameter, memoryType)){
-
 
365
						List<Long> accessories = relatedAccessories.get(categoryID);
-
 
366
						if(accessories == null){
-
 
367
							accessories = new ArrayList<Long>();
-
 
368
							relatedAccessories.put(categoryID, accessories);
-
 
369
						}
411
						}
-
 
412
						if(Long.parseLong(memoryCapacity.trim()) < cardMemory){
-
 
413
							continue;
-
 
414
						}
-
 
415
						if(StringUtils.containsIgnoreCase(accessoryParameter, memoryType)){
-
 
416
							List<Long> accessories = relatedAccessories.get(categoryID);
-
 
417
							if(accessories == null){
-
 
418
								accessories = new ArrayList<Long>();
-
 
419
								relatedAccessories.put(categoryID, accessories);
-
 
420
							}
370
						accessories.add(entityID);
421
							accessories.add(entityID);
-
 
422
						}
-
 
423
					}catch (NumberFormatException e) {
-
 
424
						log.error("Could not parse to Long \n + " + e.getMessage());
-
 
425
					} catch (Exception e){
-
 
426
						log.error(e.getMessage());
371
					}
427
					}
372
				}
428
				}
373
				break;
429
				break;
374
				
430
				
375
			//Bluetooth Headset
431
			//Bluetooth Headset
Line 458... Line 514...
458
 
514
 
459
	
515
	
460
	private void populateParameters(Map<Long, Map<Long, Object>> categoryParameterMap) throws Exception {
516
	private void populateParameters(Map<Long, Map<Long, Object>> categoryParameterMap) throws Exception {
461
		for(Long entityID: entityIds){
517
		for(Long entityID: entityIds){
462
			Entity entity = CreationUtils.getEntity(entityID);
518
			Entity entity = CreationUtils.getEntity(entityID);
-
 
519
			if(entity == null){
-
 
520
				log.info("Entity is null: " + entityID);
-
 
521
				continue;
-
 
522
			}
463
			ExpandedEntity expEntity = new ExpandedEntity(entity);
523
			ExpandedEntity expEntity = new ExpandedEntity(entity);
464
			Long categoryID = entity.getCategoryID();
524
			Long categoryID = entity.getCategoryID();
465
			switch (categoryID.intValue()) {
525
			switch (categoryID.intValue()) {
466
			//Battery
526
			//Battery
467
			case (int) Utils.BATTERY:
527
			case (int) Utils.BATTERY:
Line 717... Line 777...
717
			break;
777
			break;
718
		}
778
		}
719
		return entityParameterMap;
779
		return entityParameterMap;
720
	}
780
	}
721
	
781
	
-
 
782
	private ExpandedBullet getBullet(List<ExpandedBullet> expBullets){
-
 
783
		for(ExpandedBullet expBullet : expBullets){
-
 
784
			String type = expBullet.getValue();
-
 
785
			if(StringUtils.isEmpty(type)){
-
 
786
				continue;
-
 
787
			} else {
-
 
788
				return expBullet;
-
 
789
			}
-
 
790
		}
-
 
791
		return null;
-
 
792
	}
-
 
793
	
-
 
794
	private String getBulletDisplayText(List<ExpandedBullet> expBullets){
-
 
795
		for(ExpandedBullet expBullet : expBullets){
-
 
796
			String type = expBullet.displayText();
-
 
797
			if(StringUtils.isEmpty(type)){
-
 
798
				continue;
-
 
799
			} else {
-
 
800
				return type;
-
 
801
			}
-
 
802
		}
-
 
803
		return "";
-
 
804
	}
-
 
805
	
722
}
806
}
723
807