| 2651 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.core.Entity;
|
|
|
4 |
import in.shop2020.metamodel.core.Slide;
|
|
|
5 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
6 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
|
|
7 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
8 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
|
|
9 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
|
|
10 |
import in.shop2020.utils.CategoryManager;
|
|
|
11 |
|
|
|
12 |
import java.util.ArrayList;
|
|
|
13 |
import java.util.Arrays;
|
|
|
14 |
import java.util.Collection;
|
|
|
15 |
import java.util.HashMap;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
import java.util.Map;
|
|
|
18 |
import java.util.Map.Entry;
|
| 2726 |
rajveer |
19 |
import java.util.Set;
|
| 2651 |
rajveer |
20 |
|
|
|
21 |
import org.apache.commons.lang.StringUtils;
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
public class AccessoriesFinder {
|
|
|
25 |
CategoryManager catm = CategoryManager.getCategoryManager();
|
| 2726 |
rajveer |
26 |
Set<Long> entityIds;
|
| 2651 |
rajveer |
27 |
|
|
|
28 |
public static void main(String[] args) throws Exception {
|
| 2726 |
rajveer |
29 |
// AccessoriesFinder af = new AccessoriesFinder();
|
|
|
30 |
// Map<Long, Map<Long, List<Long>>> relatedAccessories = af.findAccessories();
|
|
|
31 |
// CreationUtils.storeRelatedAccessories(relatedAccessories);
|
| 2651 |
rajveer |
32 |
}
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
| 2726 |
rajveer |
36 |
public AccessoriesFinder(Set<Long> entityIds){
|
|
|
37 |
this.entityIds = entityIds;
|
| 2651 |
rajveer |
38 |
}
|
|
|
39 |
|
|
|
40 |
|
| 2656 |
rajveer |
41 |
public Map<Long, Map<Long, List<Long>>> findAccessories() throws Exception {
|
| 2651 |
rajveer |
42 |
Map<Long, Map<Long, List<Long>>> entityAccessories = new HashMap<Long, Map<Long, List<Long>>>();
|
|
|
43 |
|
| 2726 |
rajveer |
44 |
//List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
|
| 2651 |
rajveer |
45 |
Map<Long, Map<Long, Object>> categoryParameterMap = new HashMap<Long, Map<Long,Object>>();
|
| 2726 |
rajveer |
46 |
// for(Long categoryID: categoryIDs){
|
|
|
47 |
// categoryParameterMap.put(categoryID, populateParameters(categoryID));
|
|
|
48 |
// }
|
| 2651 |
rajveer |
49 |
|
| 2726 |
rajveer |
50 |
populateParameters(categoryParameterMap);
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
for(Long entityID: entityIds){
|
|
|
54 |
Entity entity = CreationUtils.getEntity(entityID);
|
| 2651 |
rajveer |
55 |
Map<Long, Object> entityCategoryParameters = getEntityCategoryParameters(entity);
|
| 3719 |
mandeep.dh |
56 |
if(catm.getCategory(entity.getCategoryID()).getParent_category_id() != Utils.MOBILE_ACCESSORIES_CATEGORY && catm.getCategory(entity.getCategoryID()).getId() != Utils.LAPTOPS_CATEGORY){
|
| 2651 |
rajveer |
57 |
entityAccessories.put(entity.getID(), getRelatedAccessories(entityCategoryParameters, categoryParameterMap));
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
return entityAccessories;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
private Map<Long, Object> getEntityCategoryParameters(Entity entity) throws Exception {
|
|
|
64 |
Map<Long, Object> entityCategoryParameters = new HashMap<Long, Object>();
|
|
|
65 |
List<Long> categoryIDs = catm.getCategory(Utils.MOBILE_ACCESSORIES_CATEGORY).getChildren_category_ids();
|
|
|
66 |
for(Long categoryID: categoryIDs){
|
|
|
67 |
Object obj = populateEntityParameters(categoryID, entity);
|
|
|
68 |
if(obj != null){
|
|
|
69 |
entityCategoryParameters.put(categoryID, obj);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
return entityCategoryParameters;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
private Object populateEntityParameters(Long categoryID, Entity entity) throws Exception {
|
|
|
78 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
79 |
ExpandedSlide batterySlide = expEntity.getExpandedSlide(130043);
|
|
|
80 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
81 |
|
|
|
82 |
switch (categoryID.intValue()) {
|
|
|
83 |
//Battery
|
|
|
84 |
case (int) Utils.BATTERY:
|
|
|
85 |
if(expEntity.getBrand() == null)
|
|
|
86 |
return null;
|
|
|
87 |
if(expEntity.getBrand().trim().compareToIgnoreCase("nokia")!=0){
|
|
|
88 |
return null;
|
|
|
89 |
}
|
|
|
90 |
if(batterySlide == null)
|
|
|
91 |
return null;
|
|
|
92 |
List<ExpandedFeature> expFeatures = batterySlide.getExpandedFeatures();
|
|
|
93 |
for(ExpandedFeature expFeature: expFeatures){
|
|
|
94 |
if(expFeature.getFeatureDefinitionID() == 120072){
|
|
|
95 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
96 |
String type = expBullet.displayText();
|
|
|
97 |
//Li-Ion 1020 mAh battery BL-5C;
|
|
|
98 |
String[] parts = type.split("battery");
|
|
|
99 |
if(parts.length >= 2){
|
|
|
100 |
params.put("BATTERY_MODEL", parts[1]);
|
|
|
101 |
}
|
|
|
102 |
String last = "";
|
|
|
103 |
parts = type.split(" ");
|
|
|
104 |
for(String part: parts){
|
|
|
105 |
if(part.contains("mAh")){
|
|
|
106 |
params.put("BATTERY_CAPACITY", last);
|
|
|
107 |
}
|
|
|
108 |
last = part;
|
|
|
109 |
}
|
|
|
110 |
return params;
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
break;
|
|
|
114 |
|
|
|
115 |
//Carrying Case
|
|
|
116 |
case (int) Utils.CARRYING_CASE:
|
|
|
117 |
|
|
|
118 |
//Screen Guard
|
|
|
119 |
case (int) Utils.SCREEN_GUARD:
|
|
|
120 |
if(expEntity.getBrand() == null){
|
|
|
121 |
return null;
|
|
|
122 |
}
|
|
|
123 |
else{
|
|
|
124 |
params.put("BRAND", expEntity.getBrand().trim());
|
|
|
125 |
params.put("MODEL_NUMBER", expEntity.getModelNumber().trim());
|
|
|
126 |
return params;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
//Memory Card
|
|
|
130 |
case (int) Utils.MEMORY_CARD:
|
|
|
131 |
if(expEntity.getBrand() == null)
|
|
|
132 |
return null;
|
|
|
133 |
ExpandedSlide memorySlide = expEntity.getExpandedSlide(130011);
|
|
|
134 |
if(memorySlide == null)
|
|
|
135 |
return null;
|
|
|
136 |
List<ExpandedFeature> memoryExpandedFeatures = memorySlide.getExpandedFeatures();
|
|
|
137 |
for(ExpandedFeature expFeature: memoryExpandedFeatures){
|
|
|
138 |
if(expFeature.getFeatureDefinitionID() == 120032){
|
|
|
139 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
140 |
params.put("MEMORY_TYPE", expBullet.getValue().split(" ")[0]);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
if(expFeature.getFeatureDefinitionID() == 120033){
|
|
|
144 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
145 |
long memory = Long.parseLong(expBullet.getValue());
|
|
|
146 |
long unitId = expBullet.getUnitID();
|
|
|
147 |
if(unitId == 50008){
|
|
|
148 |
memory = 1024 * memory;
|
|
|
149 |
}
|
|
|
150 |
params.put("MEMORY", memory+"");
|
|
|
151 |
return params;
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
break;
|
| 2726 |
rajveer |
155 |
|
| 2651 |
rajveer |
156 |
//Bluetooth headset
|
|
|
157 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
158 |
if(expEntity.getBrand() == null){
|
|
|
159 |
return null;
|
|
|
160 |
}
|
|
|
161 |
ExpandedSlide dataConnectivitySlide = expEntity.getExpandedSlide(130007);
|
|
|
162 |
if(dataConnectivitySlide == null)
|
|
|
163 |
return null;
|
|
|
164 |
List<ExpandedFeature> dataConnectivityFeatures = dataConnectivitySlide.getExpandedFeatures();
|
|
|
165 |
for(ExpandedFeature expFeature: dataConnectivityFeatures){
|
|
|
166 |
if(expFeature.getFeatureDefinitionID() == 120018){
|
|
|
167 |
return "TRUE";
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
break;
|
|
|
171 |
//Headset
|
|
|
172 |
case (int) Utils.HEADSET:
|
|
|
173 |
if(expEntity.getBrand() == null){
|
|
|
174 |
return null;
|
|
|
175 |
}
|
|
|
176 |
ExpandedSlide musicSlide = expEntity.getExpandedSlide(130029);
|
|
|
177 |
if(musicSlide == null)
|
|
|
178 |
return null;
|
|
|
179 |
List<ExpandedFeature> musicFeatures = musicSlide.getExpandedFeatures();
|
|
|
180 |
for(ExpandedFeature expFeature: musicFeatures){
|
|
|
181 |
if(expFeature.getFeatureDefinitionID() == 120023){
|
|
|
182 |
List<ExpandedBullet> bullets = expFeature.getExpandedBullets();
|
|
|
183 |
if(bullets!=null){
|
|
|
184 |
return expFeature.getExpandedBullets().get(0).getValue();
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
break;
|
|
|
189 |
|
|
|
190 |
//Charger
|
|
|
191 |
case (int) Utils.CHARGER:
|
|
|
192 |
if(expEntity.getBrand() == null)
|
|
|
193 |
return null;
|
|
|
194 |
if(batterySlide == null)
|
|
|
195 |
return null;
|
|
|
196 |
Map<String, String> chargerparams = new HashMap<String, String>();
|
|
|
197 |
List<ExpandedFeature> batteryFeatures = batterySlide.getExpandedFeatures();
|
|
|
198 |
for(ExpandedFeature expFeature: batteryFeatures){
|
|
|
199 |
if(expFeature.getFeatureDefinitionID() == 120073){
|
|
|
200 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
201 |
chargerparams.put("POWER_ADAPTOR", expBullet.getValue());
|
|
|
202 |
chargerparams.put("BRAND", expEntity.getBrand().trim());
|
|
|
203 |
return chargerparams;
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
return null;
|
|
|
207 |
|
|
|
208 |
default:
|
|
|
209 |
break;
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
return null;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
@SuppressWarnings("unchecked")
|
|
|
218 |
private Map<Long, List<Long>> getRelatedAccessories(Map<Long, Object> entityCategoryParameters, Map<Long, Map<Long, Object>> categoryParameterMap){
|
|
|
219 |
Map<Long, List<Long>> relatedAccessories = new HashMap<Long, List<Long>>();
|
|
|
220 |
for(Entry<Long, Map<Long, Object>> entry: categoryParameterMap.entrySet()){
|
|
|
221 |
Map<Long, Object> entityParameterMap = entry.getValue();
|
|
|
222 |
long categoryID = entry.getKey().intValue();
|
|
|
223 |
switch ((int)categoryID) {
|
|
|
224 |
|
|
|
225 |
//Battery
|
|
|
226 |
case (int) Utils.BATTERY:
|
|
|
227 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
228 |
long entityID = entry1.getKey();
|
|
|
229 |
Map<String, String> accessoryParameter = (Map<String, String>) entry1.getValue();
|
|
|
230 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
231 |
if(accessoryParameter == null || mobileParameter == null){
|
|
|
232 |
continue;
|
|
|
233 |
}
|
|
|
234 |
String batteryCapacity = accessoryParameter.get("BATTERY_CAPACITY").trim();
|
|
|
235 |
String batteryModel = accessoryParameter.get("BATTERY_MODEL").trim();
|
|
|
236 |
String mobileBatteryCapacity = mobileParameter.get("BATTERY_CAPACITY").trim();
|
|
|
237 |
String mobileBatteryModel = mobileParameter.get("BATTERY_MODEL").trim();
|
|
|
238 |
if(batteryCapacity.equalsIgnoreCase(mobileBatteryCapacity) && batteryModel.equalsIgnoreCase(mobileBatteryModel)){
|
|
|
239 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
240 |
if(accessories == null){
|
|
|
241 |
accessories = new ArrayList<Long>();
|
|
|
242 |
relatedAccessories.put(categoryID, accessories);
|
|
|
243 |
}
|
|
|
244 |
accessories.add(entityID);
|
|
|
245 |
}
|
|
|
246 |
}
|
|
|
247 |
break;
|
|
|
248 |
|
|
|
249 |
//Carrying Case
|
|
|
250 |
case (int) Utils.CARRYING_CASE:
|
|
|
251 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
252 |
long entityID = entry1.getKey();
|
|
|
253 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
254 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
255 |
if(accessoryParameter != null){
|
|
|
256 |
accessoryParameter = accessoryParameter.trim();
|
|
|
257 |
}
|
|
|
258 |
if(mobileParameter.isEmpty()){
|
|
|
259 |
break;
|
|
|
260 |
}
|
|
|
261 |
String mobileBrand = mobileParameter.get("BRAND");
|
|
|
262 |
String mobileModel = mobileParameter.get("MODEL_NUMBER");
|
|
|
263 |
String[] lines = accessoryParameter.split("\n");
|
|
|
264 |
for(String line: lines){
|
|
|
265 |
boolean isRelated = false;
|
|
|
266 |
if(line.contains(mobileBrand)){
|
|
|
267 |
String[] parts = line.split(" ");
|
|
|
268 |
List<String> partsList = Arrays.asList(parts);
|
|
|
269 |
if(partsList.contains(mobileModel)){
|
|
|
270 |
isRelated = true;
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
if(isRelated){
|
|
|
274 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
275 |
if(accessories == null){
|
|
|
276 |
accessories = new ArrayList<Long>();
|
|
|
277 |
relatedAccessories.put(categoryID, accessories);
|
|
|
278 |
}
|
|
|
279 |
accessories.add(entityID);
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
break;
|
|
|
287 |
|
|
|
288 |
//Screen Guard
|
|
|
289 |
case (int) Utils.SCREEN_GUARD:
|
|
|
290 |
StringBuffer sb1 = new StringBuffer();
|
|
|
291 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
292 |
long entityID = entry1.getKey();
|
|
|
293 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
294 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
295 |
if(accessoryParameter != null){
|
|
|
296 |
accessoryParameter = accessoryParameter.trim();
|
|
|
297 |
}
|
|
|
298 |
if(mobileParameter.isEmpty()){
|
|
|
299 |
break;
|
|
|
300 |
}
|
|
|
301 |
sb1.append(accessoryParameter + " = "+ mobileParameter + "\t");
|
|
|
302 |
|
|
|
303 |
String mobileBrand = mobileParameter.get("BRAND");
|
|
|
304 |
String mobileModel = mobileParameter.get("MODEL_NUMBER");
|
|
|
305 |
boolean isRelated = false;
|
|
|
306 |
if(accessoryParameter.contains(mobileBrand)){
|
|
|
307 |
String[] parts = accessoryParameter.split(" ");
|
|
|
308 |
List<String> partsList = Arrays.asList(parts);
|
|
|
309 |
if(partsList.contains(mobileModel)){
|
|
|
310 |
isRelated = true;
|
|
|
311 |
}
|
|
|
312 |
}
|
|
|
313 |
if(isRelated){
|
|
|
314 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
315 |
if(accessories == null){
|
|
|
316 |
accessories = new ArrayList<Long>();
|
|
|
317 |
relatedAccessories.put(categoryID, accessories);
|
|
|
318 |
}
|
|
|
319 |
accessories.add(entityID);
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
break;
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
//Memory Card
|
|
|
327 |
case (int) Utils.MEMORY_CARD:
|
|
|
328 |
default:
|
|
|
329 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
330 |
long entityID = entry1.getKey();
|
|
|
331 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
332 |
if(entityCategoryParameters.get(entry.getKey()) == null){
|
|
|
333 |
continue;
|
|
|
334 |
}
|
|
|
335 |
if(entityCategoryParameters.get(entry.getKey()) == null){
|
|
|
336 |
continue;
|
|
|
337 |
}
|
|
|
338 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
339 |
if(accessoryParameter != null){
|
|
|
340 |
accessoryParameter = accessoryParameter.trim();
|
|
|
341 |
}
|
|
|
342 |
if(mobileParameter==null){
|
|
|
343 |
continue;
|
|
|
344 |
}
|
|
|
345 |
String parts[] = accessoryParameter.split(" |-");
|
|
|
346 |
long cardMemory = 1024*Long.parseLong(parts[parts.length - 1].replaceAll("GB", "").replaceAll("MB", ""));
|
|
|
347 |
String memoryCapacity = mobileParameter.get("MEMORY");
|
|
|
348 |
String memoryType = mobileParameter.get("MEMORY_TYPE");
|
|
|
349 |
if(memoryCapacity == null || memoryType == null ){
|
|
|
350 |
continue;
|
|
|
351 |
}
|
|
|
352 |
if(Long.parseLong(memoryCapacity.trim()) < cardMemory){
|
|
|
353 |
continue;
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
if(StringUtils.containsIgnoreCase(accessoryParameter, memoryType)){
|
|
|
358 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
359 |
if(accessories == null){
|
|
|
360 |
accessories = new ArrayList<Long>();
|
|
|
361 |
relatedAccessories.put(categoryID, accessories);
|
|
|
362 |
}
|
|
|
363 |
accessories.add(entityID);
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
break;
|
|
|
367 |
|
|
|
368 |
//Bluetooth Headset
|
|
|
369 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
370 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
371 |
long entityID = entry1.getKey();
|
|
|
372 |
String mobileParameter = (String)entityCategoryParameters.get(entry.getKey());
|
| 2668 |
rajveer |
373 |
|
|
|
374 |
if(mobileParameter == null){
|
|
|
375 |
break;
|
| 2651 |
rajveer |
376 |
}
|
|
|
377 |
|
| 2668 |
rajveer |
378 |
if(mobileParameter.equals("TRUE")){
|
| 2651 |
rajveer |
379 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
380 |
if(accessories == null){
|
|
|
381 |
accessories = new ArrayList<Long>();
|
|
|
382 |
relatedAccessories.put(categoryID, accessories);
|
|
|
383 |
}
|
|
|
384 |
accessories.add(entityID);
|
|
|
385 |
}
|
|
|
386 |
}
|
|
|
387 |
break;
|
|
|
388 |
|
|
|
389 |
//Headset
|
|
|
390 |
case (int) Utils.HEADSET:
|
|
|
391 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
392 |
long entityID = entry1.getKey();
|
|
|
393 |
String mobileParameter = (String)entityCategoryParameters.get(entry.getKey());
|
| 2667 |
rajveer |
394 |
String accessoryParameter = (String) entry1.getValue();
|
|
|
395 |
if(mobileParameter!=null && accessoryParameter != null){
|
| 2651 |
rajveer |
396 |
mobileParameter = mobileParameter.trim();
|
| 2667 |
rajveer |
397 |
accessoryParameter = accessoryParameter.trim();
|
|
|
398 |
if(StringUtils.containsIgnoreCase(mobileParameter, accessoryParameter)){
|
|
|
399 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
400 |
if(accessories == null){
|
|
|
401 |
accessories = new ArrayList<Long>();
|
|
|
402 |
relatedAccessories.put(categoryID, accessories);
|
|
|
403 |
}
|
|
|
404 |
accessories.add(entityID);
|
| 2651 |
rajveer |
405 |
}
|
|
|
406 |
}
|
|
|
407 |
}
|
|
|
408 |
break;
|
|
|
409 |
|
|
|
410 |
//Charger
|
|
|
411 |
case (int) Utils.CHARGER:
|
|
|
412 |
for(Entry<Long, Object> entry1 : entityParameterMap.entrySet()){
|
|
|
413 |
long entityID = entry1.getKey();
|
|
|
414 |
Map<String, String> accessoryParameter = (Map<String, String>) entry1.getValue();
|
|
|
415 |
if(entityCategoryParameters.get(entry.getKey()) == null){
|
|
|
416 |
continue;
|
|
|
417 |
}
|
|
|
418 |
Map<String, String> mobileParameter = (Map<String, String>)entityCategoryParameters.get(entry.getKey());
|
|
|
419 |
if(accessoryParameter == null || mobileParameter==null){
|
|
|
420 |
continue;
|
|
|
421 |
}
|
|
|
422 |
String accBrand = accessoryParameter.get("BRAND");
|
|
|
423 |
String mobileBrand = mobileParameter.get("BRAND");
|
|
|
424 |
|
|
|
425 |
String accConnectorPin = accessoryParameter.get("CONNECTOR_PIN");
|
|
|
426 |
String mobilePowerAdaptor = mobileParameter.get("POWER_ADAPTOR");
|
|
|
427 |
|
|
|
428 |
String accModel = accessoryParameter.get("MODEL");
|
|
|
429 |
|
|
|
430 |
if(accBrand.trim().equalsIgnoreCase(mobileBrand.trim())){
|
|
|
431 |
if(StringUtils.containsIgnoreCase(mobilePowerAdaptor, accConnectorPin)){
|
|
|
432 |
if(StringUtils.containsIgnoreCase(mobilePowerAdaptor, accModel)){
|
|
|
433 |
List<Long> accessories = relatedAccessories.get(categoryID);
|
|
|
434 |
if(accessories == null){
|
|
|
435 |
accessories = new ArrayList<Long>();
|
|
|
436 |
relatedAccessories.put(categoryID, accessories);
|
|
|
437 |
}
|
|
|
438 |
accessories.add(entityID);
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
break;
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
}
|
|
|
449 |
return relatedAccessories;
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
|
| 2726 |
rajveer |
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 |
|
| 2651 |
rajveer |
582 |
private Map<Long, Object> populateParameters(long categoryID) throws Exception {
|
|
|
583 |
Map<Long, Object> entityParameterMap = new HashMap<Long, Object>();
|
|
|
584 |
Collection<Entity> entities = CreationUtils.getEntities(categoryID);
|
| 2726 |
rajveer |
585 |
|
| 2651 |
rajveer |
586 |
switch ((int)categoryID) {
|
|
|
587 |
|
|
|
588 |
//Battery
|
|
|
589 |
case (int) Utils.BATTERY:
|
|
|
590 |
for(Entity entity: entities){
|
|
|
591 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
592 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130066);
|
|
|
593 |
if(compatibilitySlide != null){
|
|
|
594 |
List<ExpandedFeature> compatibilityFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
595 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
596 |
if(feature.getFeatureDefinitionID() == 120104){
|
|
|
597 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
598 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
599 |
String capacity = bullet.getValue();
|
|
|
600 |
capacity = capacity.split(" ")[0];
|
|
|
601 |
params.put("BATTERY_CAPACITY", capacity);
|
|
|
602 |
params.put("BATTERY_MODEL", entity.getModelNumber().trim());
|
|
|
603 |
entityParameterMap.put(entity.getID(), params);
|
|
|
604 |
}
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
break;
|
|
|
609 |
|
|
|
610 |
//Screen Guard
|
|
|
611 |
case (int) Utils.SCREEN_GUARD:
|
|
|
612 |
for(Entity entity: entities){
|
|
|
613 |
Slide compatibilitySlide = entity.getSlide(130073);
|
|
|
614 |
if(compatibilitySlide != null){
|
|
|
615 |
String fft = compatibilitySlide.getFreeformContent().getFreeformText();
|
|
|
616 |
if(fft != null && !fft.trim().isEmpty()){
|
|
|
617 |
entityParameterMap.put(entity.getID(), fft);
|
|
|
618 |
}
|
|
|
619 |
}
|
|
|
620 |
}
|
|
|
621 |
break;
|
|
|
622 |
|
|
|
623 |
//Carrying Case
|
|
|
624 |
case (int) Utils.CARRYING_CASE:
|
|
|
625 |
for(Entity entity: entities){
|
|
|
626 |
Slide compatibilitySlide = entity.getSlide(130073);
|
|
|
627 |
if(compatibilitySlide != null){
|
|
|
628 |
String fft = compatibilitySlide.getFreeformContent().getFreeformText();
|
|
|
629 |
if(fft != null && !fft.trim().isEmpty()){
|
|
|
630 |
entityParameterMap.put(entity.getID(), fft);
|
|
|
631 |
}
|
|
|
632 |
}
|
|
|
633 |
}
|
|
|
634 |
break;
|
|
|
635 |
|
|
|
636 |
//Memory Card
|
|
|
637 |
case (int) Utils.MEMORY_CARD:
|
|
|
638 |
for(Entity entity: entities){
|
|
|
639 |
entityParameterMap.put(entity.getID(), entity.getBrand() + " " + entity.getModelName() + " " + entity.getModelNumber());
|
|
|
640 |
/*
|
|
|
641 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
642 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130065);
|
|
|
643 |
List<ExpandedFeature> compatibilityExpandedFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
644 |
for(ExpandedFeature expFeature: compatibilityExpandedFeatures){
|
|
|
645 |
if(expFeature.getFeatureDefinitionID() == 120099){
|
|
|
646 |
ExpandedBullet expBullet = expFeature.getExpandedBullets().get(0);
|
|
|
647 |
if(expBullet.displayText() == null || expBullet.displayText().trim().equals("")){
|
|
|
648 |
continue;
|
|
|
649 |
}
|
|
|
650 |
long memory = Long.parseLong(expBullet.getValue());
|
|
|
651 |
long unitId = expBullet.getUnitID();
|
|
|
652 |
if(unitId == 50008){
|
|
|
653 |
memory = 1024 * memory;
|
|
|
654 |
}
|
|
|
655 |
entityParameterMap.put(entity.getID(), memory+"");
|
|
|
656 |
}
|
|
|
657 |
}
|
|
|
658 |
*/
|
|
|
659 |
}
|
|
|
660 |
break;
|
|
|
661 |
|
|
|
662 |
//Bluetooth Headset
|
|
|
663 |
case (int) Utils.BLUETOOTH_HEADSET:
|
|
|
664 |
for(Entity entity: entities){
|
|
|
665 |
entityParameterMap.put(entity.getID(), entity.getModelNumber().trim());
|
|
|
666 |
}
|
|
|
667 |
break;
|
|
|
668 |
|
|
|
669 |
//Headset
|
|
|
670 |
case (int) Utils.HEADSET:
|
|
|
671 |
for(Entity entity: entities){
|
|
|
672 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
673 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130068);
|
|
|
674 |
if(compatibilitySlide != null){
|
|
|
675 |
List<ExpandedFeature> compatibilityFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
676 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
677 |
if(feature.getFeatureDefinitionID() == 120105){
|
|
|
678 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
679 |
entityParameterMap.put(entity.getID(), bullet.getValue());
|
|
|
680 |
}
|
|
|
681 |
}
|
|
|
682 |
}
|
|
|
683 |
}
|
|
|
684 |
break;
|
|
|
685 |
|
|
|
686 |
//Charger
|
|
|
687 |
case (int) Utils.CHARGER:
|
|
|
688 |
for(Entity entity: entities){
|
|
|
689 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
690 |
ExpandedSlide compatibilitySlide = expEntity.getExpandedSlide(130069);
|
|
|
691 |
if(compatibilitySlide != null){
|
|
|
692 |
List<ExpandedFeature> compatibilityFeatures = compatibilitySlide.getExpandedFeatures();
|
|
|
693 |
for(ExpandedFeature feature: compatibilityFeatures){
|
|
|
694 |
if(feature.getFeatureDefinitionID() == 120107){
|
|
|
695 |
ExpandedBullet bullet = feature.getExpandedBullets().get(0);
|
|
|
696 |
Map<String, String> params = new HashMap<String, String>();
|
|
|
697 |
String model = entity.getModelName() + " " + entity.getModelNumber();
|
|
|
698 |
model = model.replaceAll("Charger", "").trim();
|
|
|
699 |
params.put("BRAND", entity.getBrand());
|
|
|
700 |
params.put("CONNECTOR_PIN", bullet.getValue());
|
|
|
701 |
params.put("MODEL", model);
|
|
|
702 |
entityParameterMap.put(entity.getID(), params);
|
|
|
703 |
}
|
|
|
704 |
}
|
|
|
705 |
}
|
|
|
706 |
}
|
|
|
707 |
break;
|
|
|
708 |
|
|
|
709 |
default:
|
|
|
710 |
break;
|
|
|
711 |
}
|
|
|
712 |
return entityParameterMap;
|
|
|
713 |
}
|
|
|
714 |
|
| 2726 |
rajveer |
715 |
}
|