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