| 2651 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.core.Entity;
|
| 5311 |
amit.gupta |
4 |
import in.shop2020.metamodel.core.EntityState;
|
|
|
5 |
import in.shop2020.metamodel.core.EntityStatus;
|
| 2651 |
rajveer |
6 |
import in.shop2020.metamodel.core.Slide;
|
| 4802 |
amit.gupta |
7 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
8 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
9 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 2651 |
rajveer |
10 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
11 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
|
|
12 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
13 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
|
|
14 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
|
|
15 |
|
|
|
16 |
import java.util.ArrayList;
|
|
|
17 |
import java.util.Arrays;
|
|
|
18 |
import java.util.Collection;
|
|
|
19 |
import java.util.HashMap;
|
|
|
20 |
import java.util.List;
|
|
|
21 |
import java.util.Map;
|
|
|
22 |
import java.util.Map.Entry;
|
| 2726 |
rajveer |
23 |
import java.util.Set;
|
| 2651 |
rajveer |
24 |
|
|
|
25 |
import org.apache.commons.lang.StringUtils;
|
| 5311 |
amit.gupta |
26 |
import org.apache.commons.logging.Log;
|
|
|
27 |
import org.apache.commons.logging.LogFactory;
|
| 2651 |
rajveer |
28 |
|
|
|
29 |
|
|
|
30 |
public class AccessoriesFinder {
|
| 4802 |
amit.gupta |
31 |
DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
|
| 2726 |
rajveer |
32 |
Set<Long> entityIds;
|
| 2651 |
rajveer |
33 |
|
| 5311 |
amit.gupta |
34 |
private static Log log = LogFactory.getLog(ContentGenerationUtility.class);
|
|
|
35 |
|
| 2651 |
rajveer |
36 |
public static void main(String[] args) throws Exception {
|
| 5311 |
amit.gupta |
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 |
}
|
|
|
45 |
AccessoriesFinder af = new AccessoriesFinder(map1.keySet());
|
|
|
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 |
}
|
|
|
55 |
CreationUtils.storeRelatedAccessories(relatedAccessories);
|
| 2651 |
rajveer |
56 |
}
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
| 2726 |
rajveer |
60 |
public AccessoriesFinder(Set<Long> entityIds){
|
|
|
61 |
this.entityIds = entityIds;
|
| 2651 |
rajveer |
62 |
}
|
|
|
63 |
|
|
|
64 |
|
| 2656 |
rajveer |
65 |
public Map<Long, Map<Long, List<Long>>> findAccessories() throws Exception {
|
| 2651 |
rajveer |
66 |
Map<Long, Map<Long, List<Long>>> entityAccessories = new HashMap<Long, Map<Long, List<Long>>>();
|
|
|
67 |
|
| 2726 |
rajveer |
68 |
//List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
|
| 2651 |
rajveer |
69 |
Map<Long, Map<Long, Object>> categoryParameterMap = new HashMap<Long, Map<Long,Object>>();
|
| 2726 |
rajveer |
70 |
// for(Long categoryID: categoryIDs){
|
|
|
71 |
// categoryParameterMap.put(categoryID, populateParameters(categoryID));
|
|
|
72 |
// }
|
| 2651 |
rajveer |
73 |
|
| 2726 |
rajveer |
74 |
populateParameters(categoryParameterMap);
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
for(Long entityID: entityIds){
|
| 5106 |
rajveer |
78 |
try{
|
|
|
79 |
Entity entity = CreationUtils.getEntity(entityID);
|
|
|
80 |
Map<Long, Object> entityCategoryParameters = getEntityCategoryParameters(entity);
|
|
|
81 |
Category cat = defContainer.getCategory(entity.getCategoryID()).getParentCategory();
|
|
|
82 |
if(cat.isHasAccessories()){
|
|
|
83 |
entityAccessories.put(entity.getID(), getRelatedAccessories(entityCategoryParameters, categoryParameterMap));
|
|
|
84 |
}
|
|
|
85 |
}catch (Exception e) {
|
| 5311 |
amit.gupta |
86 |
log.error("Error for entity " + entityID);
|
| 2651 |
rajveer |
87 |
}
|
|
|
88 |
}
|
|
|
89 |
return entityAccessories;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
private Map<Long, Object> getEntityCategoryParameters(Entity entity) throws Exception {
|
|
|
93 |
Map<Long, Object> entityCategoryParameters = new HashMap<Long, Object>();
|
| 4802 |
amit.gupta |
94 |
List<Category> categories = defContainer.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildrenCategory();
|
|
|
95 |
for(Category category : categories){
|
|
|
96 |
Object obj = populateEntityParameters(category.getID(), entity);
|
| 2651 |
rajveer |
97 |
if(obj != null){
|
| 4802 |
amit.gupta |
98 |
entityCategoryParameters.put(category.getID(), obj);
|
| 2651 |
rajveer |
99 |
}
|
|
|
100 |
}
|
|
|
101 |
return entityCategoryParameters;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
private Object populateEntityParameters(Long categoryID, Entity entity) throws Exception {
|
|
|
107 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
108 |
ExpandedSlide batterySlide = expEntity.getExpandedSlide(130043);
|
|
|
109 |
Map<String, String> params = new HashMap<String, String>();
|
| 5311 |
amit.gupta |
110 |
Long entityId = entity.getID();
|
| 2651 |
rajveer |
111 |
switch (categoryID.intValue()) {
|
|
|
112 |
//Battery
|
|
|
113 |
case (int) Utils.BATTERY:
|
|
|
114 |
if(expEntity.getBrand() == null)
|
|
|
115 |
return null;
|
| 5311 |
amit.gupta |
116 |
//All brand of batteries are now permissible.
|
|
|
117 |
/*if(expEntity.getBrand().trim().compareToIgnoreCase("nokia")!=0){
|
| 2651 |
rajveer |
118 |
return null;
|
| 5311 |
amit.gupta |
119 |
}*/
|
| 2651 |
rajveer |
120 |
if(batterySlide == null)
|
|
|
121 |
return null;
|
|
|
122 |
List<ExpandedFeature> expFeatures = batterySlide.getExpandedFeatures();
|
|
|
123 |
for(ExpandedFeature expFeature: expFeatures){
|
|
|
124 |
if(expFeature.getFeatureDefinitionID() == 120072){
|
| 5311 |
amit.gupta |
125 |
this.getBulletDisplayText(expFeature.getExpandedBullets());
|
|
|
126 |
String type = this.getBulletDisplayText(expFeature.getExpandedBullets());
|
|
|
127 |
if(StringUtils.isEmpty(type)){
|
|
|
128 |
continue;
|
|
|
129 |
}
|
| 2651 |
rajveer |
130 |
//Li-Ion 1020 mAh battery BL-5C;
|
|
|
131 |
String[] parts = type.split("battery");
|
|
|
132 |
if(parts.length >= 2){
|
|
|
133 |
params.put("BATTERY_MODEL", parts[1]);
|
| 5311 |
amit.gupta |
134 |
} else {
|
|
|
135 |
log.info("Could not find Battery Model for : " + entityId);
|
|
|
136 |
return null;
|
|
|
137 |
}
|
| 2651 |
rajveer |
138 |
String last = "";
|
|
|
139 |
parts = type.split(" ");
|
|
|
140 |
for(String part: parts){
|
|
|
141 |
if(part.contains("mAh")){
|
|
|
142 |
params.put("BATTERY_CAPACITY", last);
|
| 5311 |
amit.gupta |
143 |
} else {
|
|
|
144 |
log.info("Could not find Battery Capacity for : " + entityId);
|
|
|
145 |
return null;
|
| 2651 |
rajveer |
146 |
}
|
|
|
147 |
last = part;
|
|
|
148 |
}
|
|
|
149 |
return params;
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
break;
|
|
|
153 |
|
|
|
154 |
//Carrying Case
|
|
|
155 |
case (int) Utils.CARRYING_CASE:
|
|
|
156 |
|
|
|
157 |
//Screen Guard
|
|
|
158 |
case (int) Utils.SCREEN_GUARD:
|
|
|
159 |
if(expEntity.getBrand() == null){
|
|
|
160 |
return null;
|
|
|
161 |
}
|
|
|
162 |
else{
|
|
|
163 |
params.put("BRAND", expEntity.getBrand().trim());
|
|
|
164 |
params.put("MODEL_NUMBER", expEntity.getModelNumber().trim());
|
|
|
165 |
return params;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
//Memory Card
|
|
|
169 |
case (int) Utils.MEMORY_CARD:
|
|
|
170 |
if(expEntity.getBrand() == null)
|
|
|
171 |
return null;
|
|
|
172 |
ExpandedSlide memorySlide = expEntity.getExpandedSlide(130011);
|
|
|
173 |
if(memorySlide == null)
|
|
|
174 |
return null;
|
|
|
175 |
List<ExpandedFeature> memoryExpandedFeatures = memorySlide.getExpandedFeatures();
|
|
|
176 |
for(ExpandedFeature expFeature: memoryExpandedFeatures){
|
|
|
177 |
if(expFeature.getFeatureDefinitionID() == 120032){
|
| 5311 |
amit.gupta |
178 |
ExpandedBullet bull = getBullet(expFeature.getExpandedBullets());
|
|
|
179 |
if(bull !=null) {
|
|
|
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 |
}
|
| 2651 |
rajveer |
185 |
}
|
|
|
186 |
|
|
|
187 |
if(expFeature.getFeatureDefinitionID() == 120033){
|
| 5311 |
amit.gupta |
188 |
ExpandedBullet expBullet = getBullet(expFeature.getExpandedBullets());
|
|
|
189 |
if(expBullet != null){
|
|
|
190 |
long memory = Long.parseLong(expBullet.getValue());
|
|
|
191 |
long unitId = expBullet.getUnitID();
|
|
|
192 |
if(unitId == 50008){
|
|
|
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;
|
| 2651 |
rajveer |
199 |
}
|
|
|
200 |
}
|
| 5311 |
amit.gupta |
201 |
return params;
|
| 2651 |
rajveer |
202 |
}
|
|
|
203 |
break;
|
| 2726 |
rajveer |
204 |
|
| 2651 |
rajveer |
205 |
//Bluetooth headset
|
|
|
206 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
207 |
if(expEntity.getBrand() == null){
|
|
|
208 |
return null;
|
|
|
209 |
}
|
|
|
210 |
ExpandedSlide dataConnectivitySlide = expEntity.getExpandedSlide(130007);
|
|
|
211 |
if(dataConnectivitySlide == null)
|
|
|
212 |
return null;
|
|
|
213 |
List<ExpandedFeature> dataConnectivityFeatures = dataConnectivitySlide.getExpandedFeatures();
|
|
|
214 |
for(ExpandedFeature expFeature: dataConnectivityFeatures){
|
|
|
215 |
if(expFeature.getFeatureDefinitionID() == 120018){
|
|
|
216 |
return "TRUE";
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
break;
|
|
|
220 |
//Headset
|
|
|
221 |
case (int) Utils.HEADSET:
|
|
|
222 |
if(expEntity.getBrand() == null){
|
|
|
223 |
return null;
|
|
|
224 |
}
|
|
|
225 |
ExpandedSlide musicSlide = expEntity.getExpandedSlide(130029);
|
|
|
226 |
if(musicSlide == null)
|
|
|
227 |
return null;
|
|
|
228 |
List<ExpandedFeature> musicFeatures = musicSlide.getExpandedFeatures();
|
|
|
229 |
for(ExpandedFeature expFeature: musicFeatures){
|
|
|
230 |
if(expFeature.getFeatureDefinitionID() == 120023){
|
|
|
231 |
List<ExpandedBullet> bullets = expFeature.getExpandedBullets();
|
|
|
232 |
if(bullets!=null){
|
| 5311 |
amit.gupta |
233 |
ExpandedBullet expBullet = getBullet(bullets);
|
|
|
234 |
if(expBullet != null){
|
|
|
235 |
return expBullet.getValue();
|
|
|
236 |
}
|
|
|
237 |
log.info("Could not fild Headphones pin size for entity : " + entityId);
|
|
|
238 |
return null;
|
| 2651 |
rajveer |
239 |
}
|
|
|
240 |
}
|
|
|
241 |
}
|
|
|
242 |
break;
|
|
|
243 |
|
|
|
244 |
//Charger
|
|
|
245 |
case (int) Utils.CHARGER:
|
|
|
246 |
if(expEntity.getBrand() == null)
|
|
|
247 |
return null;
|
|
|
248 |
if(batterySlide == null)
|
|
|
249 |
return null;
|
|
|
250 |
Map<String, String> chargerparams = new HashMap<String, String>();
|
|
|
251 |
List<ExpandedFeature> batteryFeatures = batterySlide.getExpandedFeatures();
|
|
|
252 |
for(ExpandedFeature expFeature: batteryFeatures){
|
|
|
253 |
if(expFeature.getFeatureDefinitionID() == 120073){
|
| 5311 |
amit.gupta |
254 |
ExpandedBullet expBullet = getBullet(expFeature.getExpandedBullets());
|
|
|
255 |
if(expBullet != null){
|
|
|
256 |
chargerparams.put("POWER_ADAPTOR", expBullet.getValue());
|
|
|
257 |
chargerparams.put("BRAND", expEntity.getBrand().trim());
|
|
|
258 |
return chargerparams;
|
|
|
259 |
} else {
|
|
|
260 |
log.info("Could not find adaptor detail for entity: " + entityId);
|
|
|
261 |
return null;
|
|
|
262 |
}
|
| 2651 |
rajveer |
263 |
}
|
|
|
264 |
}
|
|
|
265 |
return null;
|
|
|
266 |
|
|
|
267 |
default:
|
|
|
268 |
break;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
return null;
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
@SuppressWarnings("unchecked")
|
|
|
277 |
private Map<Long, List<Long>> getRelatedAccessories(Map<Long, Object> entityCategoryParameters, Map<Long, Map<Long, Object>> categoryParameterMap){
|
|
|
278 |
Map<Long, List<Long>> relatedAccessories = new HashMap<Long, List<Long>>();
|
|
|
279 |
for(Entry<Long, Map<Long, Object>> entry: categoryParameterMap.entrySet()){
|
|
|
280 |
Map<Long, Object> entityParameterMap = entry.getValue();
|
|
|
281 |
long categoryID = entry.getKey().intValue();
|
|
|
282 |
switch ((int)categoryID) {
|
|
|
283 |
|
|
|
284 |
//Battery
|
|
|
285 |
case (int) Utils.BATTERY:
|
|
|
286 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
287 |
long entityID = entry1.getKey();
|
|
|
288 |
Map<String, String> accessoryParameter = (Map<String, String>) entry1.getValue();
|
|
|
289 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
290 |
if(accessoryParameter == null || mobileParameter == null){
|
|
|
291 |
continue;
|
|
|
292 |
}
|
|
|
293 |
String batteryCapacity = accessoryParameter.get("BATTERY_CAPACITY").trim();
|
|
|
294 |
String batteryModel = accessoryParameter.get("BATTERY_MODEL").trim();
|
|
|
295 |
String mobileBatteryCapacity = mobileParameter.get("BATTERY_CAPACITY").trim();
|
|
|
296 |
String mobileBatteryModel = mobileParameter.get("BATTERY_MODEL").trim();
|
|
|
297 |
if(batteryCapacity.equalsIgnoreCase(mobileBatteryCapacity) && batteryModel.equalsIgnoreCase(mobileBatteryModel)){
|
|
|
298 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
299 |
if(accessories == null){
|
|
|
300 |
accessories = new ArrayList<Long>();
|
|
|
301 |
relatedAccessories.put(categoryID, accessories);
|
|
|
302 |
}
|
|
|
303 |
accessories.add(entityID);
|
|
|
304 |
}
|
|
|
305 |
}
|
|
|
306 |
break;
|
|
|
307 |
|
|
|
308 |
//Carrying Case
|
|
|
309 |
case (int) Utils.CARRYING_CASE:
|
|
|
310 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
311 |
long entityID = entry1.getKey();
|
|
|
312 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
313 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
314 |
if(accessoryParameter != null){
|
|
|
315 |
accessoryParameter = accessoryParameter.trim();
|
|
|
316 |
}
|
|
|
317 |
if(mobileParameter.isEmpty()){
|
|
|
318 |
break;
|
|
|
319 |
}
|
|
|
320 |
String mobileBrand = mobileParameter.get("BRAND");
|
|
|
321 |
String mobileModel = mobileParameter.get("MODEL_NUMBER");
|
|
|
322 |
String[] lines = accessoryParameter.split("\n");
|
|
|
323 |
for(String line: lines){
|
|
|
324 |
boolean isRelated = false;
|
|
|
325 |
if(line.contains(mobileBrand)){
|
|
|
326 |
String[] parts = line.split(" ");
|
|
|
327 |
List<String> partsList = Arrays.asList(parts);
|
|
|
328 |
if(partsList.contains(mobileModel)){
|
|
|
329 |
isRelated = true;
|
|
|
330 |
}
|
|
|
331 |
}
|
|
|
332 |
if(isRelated){
|
|
|
333 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
334 |
if(accessories == null){
|
|
|
335 |
accessories = new ArrayList<Long>();
|
|
|
336 |
relatedAccessories.put(categoryID, accessories);
|
|
|
337 |
}
|
|
|
338 |
accessories.add(entityID);
|
|
|
339 |
}
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
break;
|
|
|
346 |
|
|
|
347 |
//Screen Guard
|
|
|
348 |
case (int) Utils.SCREEN_GUARD:
|
|
|
349 |
StringBuffer sb1 = new StringBuffer();
|
|
|
350 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
351 |
long entityID = entry1.getKey();
|
|
|
352 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
353 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
354 |
if(accessoryParameter != null){
|
|
|
355 |
accessoryParameter = accessoryParameter.trim();
|
|
|
356 |
}
|
|
|
357 |
if(mobileParameter.isEmpty()){
|
|
|
358 |
break;
|
|
|
359 |
}
|
|
|
360 |
sb1.append(accessoryParameter + " = "+ mobileParameter + "\t");
|
|
|
361 |
|
|
|
362 |
String mobileBrand = mobileParameter.get("BRAND");
|
|
|
363 |
String mobileModel = mobileParameter.get("MODEL_NUMBER");
|
|
|
364 |
boolean isRelated = false;
|
|
|
365 |
if(accessoryParameter.contains(mobileBrand)){
|
|
|
366 |
String[] parts = accessoryParameter.split(" ");
|
|
|
367 |
List<String> partsList = Arrays.asList(parts);
|
|
|
368 |
if(partsList.contains(mobileModel)){
|
|
|
369 |
isRelated = true;
|
|
|
370 |
}
|
|
|
371 |
}
|
|
|
372 |
if(isRelated){
|
|
|
373 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
374 |
if(accessories == null){
|
|
|
375 |
accessories = new ArrayList<Long>();
|
|
|
376 |
relatedAccessories.put(categoryID, accessories);
|
|
|
377 |
}
|
|
|
378 |
accessories.add(entityID);
|
|
|
379 |
}
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
break;
|
|
|
383 |
|
|
|
384 |
|
|
|
385 |
//Memory Card
|
|
|
386 |
case (int) Utils.MEMORY_CARD:
|
|
|
387 |
default:
|
|
|
388 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
389 |
long entityID = entry1.getKey();
|
|
|
390 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
391 |
if(entityCategoryParameters.get(entry.getKey()) == null){
|
|
|
392 |
continue;
|
|
|
393 |
}
|
|
|
394 |
if(entityCategoryParameters.get(entry.getKey()) == null){
|
|
|
395 |
continue;
|
|
|
396 |
}
|
|
|
397 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
398 |
if(accessoryParameter != null){
|
|
|
399 |
accessoryParameter = accessoryParameter.trim();
|
|
|
400 |
}
|
|
|
401 |
if(mobileParameter==null){
|
|
|
402 |
continue;
|
|
|
403 |
}
|
|
|
404 |
String parts[] = accessoryParameter.split(" |-");
|
| 5311 |
amit.gupta |
405 |
try{
|
|
|
406 |
long cardMemory = 1024*Long.parseLong(parts[parts.length - 1].replaceAll("GB", "").replaceAll("MB", ""));
|
|
|
407 |
String memoryCapacity = mobileParameter.get("MEMORY");
|
|
|
408 |
String memoryType = mobileParameter.get("MEMORY_TYPE");
|
|
|
409 |
if(memoryCapacity == null || memoryType == null ){
|
|
|
410 |
continue;
|
| 2651 |
rajveer |
411 |
}
|
| 5311 |
amit.gupta |
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 |
}
|
|
|
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());
|
| 2651 |
rajveer |
427 |
}
|
|
|
428 |
}
|
|
|
429 |
break;
|
|
|
430 |
|
|
|
431 |
//Bluetooth Headset
|
|
|
432 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
433 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
434 |
long entityID = entry1.getKey();
|
|
|
435 |
String mobileParameter = (String)entityCategoryParameters.get(entry.getKey());
|
| 2668 |
rajveer |
436 |
|
|
|
437 |
if(mobileParameter == null){
|
|
|
438 |
break;
|
| 2651 |
rajveer |
439 |
}
|
|
|
440 |
|
| 2668 |
rajveer |
441 |
if(mobileParameter.equals("TRUE")){
|
| 2651 |
rajveer |
442 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
443 |
if(accessories == null){
|
|
|
444 |
accessories = new ArrayList<Long>();
|
|
|
445 |
relatedAccessories.put(categoryID, accessories);
|
|
|
446 |
}
|
|
|
447 |
accessories.add(entityID);
|
|
|
448 |
}
|
|
|
449 |
}
|
|
|
450 |
break;
|
|
|
451 |
|
|
|
452 |
//Headset
|
|
|
453 |
case (int) Utils.HEADSET:
|
|
|
454 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
455 |
long entityID = entry1.getKey();
|
|
|
456 |
String mobileParameter = (String)entityCategoryParameters.get(entry.getKey());
|
| 2667 |
rajveer |
457 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
458 |
if(mobileParameter!=null && accessoryParameter != null){
|
| 2651 |
rajveer |
459 |
mobileParameter = mobileParameter.trim();
|
| 2667 |
rajveer |
460 |
accessoryParameter = accessoryParameter.trim();
|
|
|
461 |
if(StringUtils.containsIgnoreCase(mobileParameter, accessoryParameter)){
|
|
|
462 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
463 |
if(accessories == null){
|
|
|
464 |
accessories = new ArrayList<Long>();
|
|
|
465 |
relatedAccessories.put(categoryID, accessories);
|
|
|
466 |
}
|
|
|
467 |
accessories.add(entityID);
|
| 2651 |
rajveer |
468 |
}
|
|
|
469 |
}
|
|
|
470 |
}
|
|
|
471 |
break;
|
|
|
472 |
|
|
|
473 |
//Charger
|
|
|
474 |
case (int) Utils.CHARGER:
|
|
|
475 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
476 |
long entityID = entry1.getKey();
|
|
|
477 |
Map<String, String> accessoryParameter = (Map<String, String>) entry1.getValue();
|
|
|
478 |
if(entityCategoryParameters.get(entry.getKey()) == null){
|
|
|
479 |
continue;
|
|
|
480 |
}
|
|
|
481 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
482 |
if(accessoryParameter == null || mobileParameter==null){
|
|
|
483 |
continue;
|
|
|
484 |
}
|
|
|
485 |
String accBrand = accessoryParameter.get("BRAND");
|
|
|
486 |
String mobileBrand = mobileParameter.get("BRAND");
|
|
|
487 |
|
|
|
488 |
String accConnectorPin = accessoryParameter.get("CONNECTOR_PIN");
|
|
|
489 |
String mobilePowerAdaptor = mobileParameter.get("POWER_ADAPTOR");
|
|
|
490 |
|
|
|
491 |
String accModel = accessoryParameter.get("MODEL");
|
|
|
492 |
|
|
|
493 |
if(accBrand.trim().equalsIgnoreCase(mobileBrand.trim())){
|
|
|
494 |
if(StringUtils.containsIgnoreCase(mobilePowerAdaptor, accConnectorPin)){
|
|
|
495 |
if(StringUtils.containsIgnoreCase(mobilePowerAdaptor, accModel)){
|
|
|
496 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
497 |
if(accessories == null){
|
|
|
498 |
accessories = new ArrayList<Long>();
|
|
|
499 |
relatedAccessories.put(categoryID, accessories);
|
|
|
500 |
}
|
|
|
501 |
accessories.add(entityID);
|
|
|
502 |
}
|
|
|
503 |
}
|
|
|
504 |
}
|
|
|
505 |
}
|
|
|
506 |
break;
|
|
|
507 |
|
|
|
508 |
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
}
|
|
|
512 |
return relatedAccessories;
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
|
| 2726 |
rajveer |
516 |
private void populateParameters(Map<Long, Map<Long, Object>> categoryParameterMap) throws Exception {
|
|
|
517 |
for(Long entityID: entityIds){
|
|
|
518 |
Entity entity = CreationUtils.getEntity(entityID);
|
| 5311 |
amit.gupta |
519 |
if(entity == null){
|
|
|
520 |
log.info("Entity is null: " + entityID);
|
|
|
521 |
continue;
|
|
|
522 |
}
|
| 2726 |
rajveer |
523 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
524 |
Long categoryID = entity.getCategoryID();
|
|
|
525 |
switch (categoryID.intValue()) {
|
|
|
526 |
//Battery
|
|
|
527 |
case (int) Utils.BATTERY:
|
|
|
528 |
ExpandedSlide expCompatibilitySlide = expEntity.getExpandedSlide(130066);
|
|
|
529 |
if(expCompatibilitySlide != null){
|
|
|
530 |
List<ExpandedFeature> compatibilityFeatures = expCompatibilitySlide.getExpandedFeatures();
|
|
|
531 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
532 |
if(feature.getFeatureDefinitionID() == 120104){
|
|
|
533 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
534 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
535 |
String capacity = bullet.getValue();
|
|
|
536 |
capacity = capacity.split(" ")[0];
|
|
|
537 |
params.put("BATTERY_CAPACITY", capacity);
|
|
|
538 |
params.put("BATTERY_MODEL", entity.getModelNumber().trim());
|
|
|
539 |
putParameterIntoMap(categoryID, entityID, params, categoryParameterMap);
|
|
|
540 |
}
|
|
|
541 |
}
|
|
|
542 |
}
|
|
|
543 |
break;
|
|
|
544 |
|
|
|
545 |
//Screen Guard
|
|
|
546 |
case (int) Utils.SCREEN_GUARD:
|
|
|
547 |
Slide compatibilitySlide = entity.getSlide(130073);
|
|
|
548 |
if(compatibilitySlide != null){
|
|
|
549 |
String fft = compatibilitySlide.getFreeformContent().getFreeformText();
|
|
|
550 |
if(fft != null && !fft.trim().isEmpty()){
|
|
|
551 |
putParameterIntoMap(categoryID, entityID, fft, categoryParameterMap);
|
|
|
552 |
}
|
|
|
553 |
}
|
|
|
554 |
break;
|
|
|
555 |
|
|
|
556 |
//Carrying Case
|
|
|
557 |
case (int) Utils.CARRYING_CASE:
|
|
|
558 |
Slide ccCompatibilitySlide = entity.getSlide(130073);
|
|
|
559 |
if(ccCompatibilitySlide != null){
|
|
|
560 |
String fft = ccCompatibilitySlide.getFreeformContent().getFreeformText();
|
|
|
561 |
if(fft != null && !fft.trim().isEmpty()){
|
|
|
562 |
putParameterIntoMap(categoryID, entityID, fft, categoryParameterMap);
|
|
|
563 |
}
|
|
|
564 |
}
|
|
|
565 |
break;
|
|
|
566 |
|
|
|
567 |
//Memory Card
|
|
|
568 |
case (int) Utils.MEMORY_CARD:
|
|
|
569 |
putParameterIntoMap(categoryID, entityID, entity.getBrand() + " " + entity.getModelName() + " " + entity.getModelNumber(), categoryParameterMap);
|
|
|
570 |
/*
|
|
|
571 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
572 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130065);
|
|
|
573 |
List<ExpandedFeature> compatibilityExpandedFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
574 |
for(ExpandedFeature expFeature: compatibilityExpandedFeatures){
|
|
|
575 |
if(expFeature.getFeatureDefinitionID() == 120099){
|
|
|
576 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
577 |
if(expBullet.displayText() == null || expBullet.displayText().trim().equals("")){
|
|
|
578 |
continue;
|
|
|
579 |
}
|
|
|
580 |
long memory = Long.parseLong(expBullet.getValue());
|
|
|
581 |
long unitId = expBullet.getUnitID();
|
|
|
582 |
if(unitId == 50008){
|
|
|
583 |
memory = 1024 * memory;
|
|
|
584 |
}
|
|
|
585 |
entityParameterMap.put(entity.getID(), memory+"");
|
|
|
586 |
}
|
|
|
587 |
}
|
|
|
588 |
*/
|
|
|
589 |
break;
|
|
|
590 |
|
|
|
591 |
//Bluetooth Headset
|
|
|
592 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
593 |
putParameterIntoMap(categoryID, entityID, entity.getModelNumber().trim(), categoryParameterMap);
|
|
|
594 |
break;
|
|
|
595 |
|
|
|
596 |
//Headset
|
|
|
597 |
case (int) Utils.HEADSET:
|
|
|
598 |
ExpandedSlide headsetCompatibilitySlide = expEntity.getExpandedSlide(130068);
|
|
|
599 |
if(headsetCompatibilitySlide != null){
|
|
|
600 |
List<ExpandedFeature> compatibilityFeatures = headsetCompatibilitySlide.getExpandedFeatures();
|
|
|
601 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
602 |
if(feature.getFeatureDefinitionID() == 120105){
|
|
|
603 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
604 |
putParameterIntoMap(categoryID, entityID, bullet.getValue(), categoryParameterMap);
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
break;
|
|
|
609 |
|
|
|
610 |
//Charger
|
|
|
611 |
case (int) Utils.CHARGER:
|
|
|
612 |
ExpandedSlide chargerCompatibilitySlide = expEntity.getExpandedSlide(130069);
|
|
|
613 |
if(chargerCompatibilitySlide != null){
|
|
|
614 |
List<ExpandedFeature> compatibilityFeatures = chargerCompatibilitySlide.getExpandedFeatures();
|
|
|
615 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
616 |
if(feature.getFeatureDefinitionID() == 120107){
|
|
|
617 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
618 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
619 |
String model = entity.getModelName() + " " + entity.getModelNumber();
|
|
|
620 |
model = model.replaceAll("Charger", "").trim();
|
|
|
621 |
params.put("BRAND", entity.getBrand());
|
|
|
622 |
params.put("CONNECTOR_PIN", bullet.getValue());
|
|
|
623 |
params.put("MODEL", model);
|
|
|
624 |
putParameterIntoMap(categoryID, entityID, params, categoryParameterMap);
|
|
|
625 |
}
|
|
|
626 |
}
|
|
|
627 |
}
|
|
|
628 |
break;
|
|
|
629 |
|
|
|
630 |
default:
|
|
|
631 |
break;
|
|
|
632 |
}
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
|
|
|
637 |
void putParameterIntoMap(Long categoryID, Long entityID, Object params, Map<Long, Map<Long, Object>> categoryParameterMap){
|
|
|
638 |
Map<Long, Object> entityParameterMap = categoryParameterMap.get(categoryID);
|
|
|
639 |
if(entityParameterMap == null){
|
|
|
640 |
entityParameterMap = new HashMap<Long, Object>();
|
|
|
641 |
categoryParameterMap.put(categoryID, entityParameterMap);
|
|
|
642 |
}
|
|
|
643 |
entityParameterMap.put(entityID, params);
|
|
|
644 |
}
|
|
|
645 |
|
|
|
646 |
|
|
|
647 |
|
|
|
648 |
|
| 2651 |
rajveer |
649 |
private Map<Long, Object> populateParameters(long categoryID) throws Exception {
|
|
|
650 |
Map<Long, Object> entityParameterMap = new HashMap<Long, Object>();
|
|
|
651 |
Collection<Entity> entities = CreationUtils.getEntities(categoryID);
|
| 2726 |
rajveer |
652 |
|
| 2651 |
rajveer |
653 |
switch ((int)categoryID) {
|
|
|
654 |
|
|
|
655 |
//Battery
|
|
|
656 |
case (int) Utils.BATTERY:
|
|
|
657 |
for(Entity entity: entities){
|
|
|
658 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
659 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130066);
|
|
|
660 |
if(compatibilitySlide != null){
|
|
|
661 |
List<ExpandedFeature> compatibilityFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
662 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
663 |
if(feature.getFeatureDefinitionID() == 120104){
|
|
|
664 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
665 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
666 |
String capacity = bullet.getValue();
|
|
|
667 |
capacity = capacity.split(" ")[0];
|
|
|
668 |
params.put("BATTERY_CAPACITY", capacity);
|
|
|
669 |
params.put("BATTERY_MODEL", entity.getModelNumber().trim());
|
|
|
670 |
entityParameterMap.put(entity.getID(), params);
|
|
|
671 |
}
|
|
|
672 |
}
|
|
|
673 |
}
|
|
|
674 |
}
|
|
|
675 |
break;
|
|
|
676 |
|
|
|
677 |
//Screen Guard
|
|
|
678 |
case (int) Utils.SCREEN_GUARD:
|
|
|
679 |
for(Entity entity: entities){
|
|
|
680 |
Slide compatibilitySlide = entity.getSlide(130073);
|
|
|
681 |
if(compatibilitySlide != null){
|
|
|
682 |
String fft = compatibilitySlide.getFreeformContent().getFreeformText();
|
|
|
683 |
if(fft != null && !fft.trim().isEmpty()){
|
|
|
684 |
entityParameterMap.put(entity.getID(), fft);
|
|
|
685 |
}
|
|
|
686 |
}
|
|
|
687 |
}
|
|
|
688 |
break;
|
|
|
689 |
|
|
|
690 |
//Carrying Case
|
|
|
691 |
case (int) Utils.CARRYING_CASE:
|
|
|
692 |
for(Entity entity: entities){
|
|
|
693 |
Slide compatibilitySlide = entity.getSlide(130073);
|
|
|
694 |
if(compatibilitySlide != null){
|
|
|
695 |
String fft = compatibilitySlide.getFreeformContent().getFreeformText();
|
|
|
696 |
if(fft != null && !fft.trim().isEmpty()){
|
|
|
697 |
entityParameterMap.put(entity.getID(), fft);
|
|
|
698 |
}
|
|
|
699 |
}
|
|
|
700 |
}
|
|
|
701 |
break;
|
|
|
702 |
|
|
|
703 |
//Memory Card
|
|
|
704 |
case (int) Utils.MEMORY_CARD:
|
|
|
705 |
for(Entity entity: entities){
|
|
|
706 |
entityParameterMap.put(entity.getID(), entity.getBrand() + " " + entity.getModelName() + " " + entity.getModelNumber());
|
|
|
707 |
/*
|
|
|
708 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
709 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130065);
|
|
|
710 |
List<ExpandedFeature> compatibilityExpandedFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
711 |
for(ExpandedFeature expFeature: compatibilityExpandedFeatures){
|
|
|
712 |
if(expFeature.getFeatureDefinitionID() == 120099){
|
|
|
713 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
714 |
if(expBullet.displayText() == null || expBullet.displayText().trim().equals("")){
|
|
|
715 |
continue;
|
|
|
716 |
}
|
|
|
717 |
long memory = Long.parseLong(expBullet.getValue());
|
|
|
718 |
long unitId = expBullet.getUnitID();
|
|
|
719 |
if(unitId == 50008){
|
|
|
720 |
memory = 1024 * memory;
|
|
|
721 |
}
|
|
|
722 |
entityParameterMap.put(entity.getID(), memory+"");
|
|
|
723 |
}
|
|
|
724 |
}
|
|
|
725 |
*/
|
|
|
726 |
}
|
|
|
727 |
break;
|
|
|
728 |
|
|
|
729 |
//Bluetooth Headset
|
|
|
730 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
731 |
for(Entity entity: entities){
|
|
|
732 |
entityParameterMap.put(entity.getID(), entity.getModelNumber().trim());
|
|
|
733 |
}
|
|
|
734 |
break;
|
|
|
735 |
|
|
|
736 |
//Headset
|
|
|
737 |
case (int) Utils.HEADSET:
|
|
|
738 |
for(Entity entity: entities){
|
|
|
739 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
740 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130068);
|
|
|
741 |
if(compatibilitySlide != null){
|
|
|
742 |
List<ExpandedFeature> compatibilityFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
743 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
744 |
if(feature.getFeatureDefinitionID() == 120105){
|
|
|
745 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
746 |
entityParameterMap.put(entity.getID(), bullet.getValue());
|
|
|
747 |
}
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
}
|
|
|
751 |
break;
|
|
|
752 |
|
|
|
753 |
//Charger
|
|
|
754 |
case (int) Utils.CHARGER:
|
|
|
755 |
for(Entity entity: entities){
|
|
|
756 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
757 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130069);
|
|
|
758 |
if(compatibilitySlide != null){
|
|
|
759 |
List<ExpandedFeature> compatibilityFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
760 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
761 |
if(feature.getFeatureDefinitionID() == 120107){
|
|
|
762 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
763 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
764 |
String model = entity.getModelName() + " " + entity.getModelNumber();
|
|
|
765 |
model = model.replaceAll("Charger", "").trim();
|
|
|
766 |
params.put("BRAND", entity.getBrand());
|
|
|
767 |
params.put("CONNECTOR_PIN", bullet.getValue());
|
|
|
768 |
params.put("MODEL", model);
|
|
|
769 |
entityParameterMap.put(entity.getID(), params);
|
|
|
770 |
}
|
|
|
771 |
}
|
|
|
772 |
}
|
|
|
773 |
}
|
|
|
774 |
break;
|
|
|
775 |
|
|
|
776 |
default:
|
|
|
777 |
break;
|
|
|
778 |
}
|
|
|
779 |
return entityParameterMap;
|
|
|
780 |
}
|
|
|
781 |
|
| 5311 |
amit.gupta |
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 |
|
| 2726 |
rajveer |
806 |
}
|