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