Subversion Repositories SmartDukaan

Rev

Rev 8024 | Rev 8865 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8024 Rev 8749
Line 6... Line 6...
6
import in.shop2020.metamodel.core.ExpertReviewSource;
6
import in.shop2020.metamodel.core.ExpertReviewSource;
7
import in.shop2020.metamodel.core.Feature;
7
import in.shop2020.metamodel.core.Feature;
8
import in.shop2020.metamodel.core.Helpdoc;
8
import in.shop2020.metamodel.core.Helpdoc;
9
import in.shop2020.metamodel.core.Slide;
9
import in.shop2020.metamodel.core.Slide;
10
import in.shop2020.metamodel.core.SpecialPage;
10
import in.shop2020.metamodel.core.SpecialPage;
11
import in.shop2020.metamodel.definitions.Catalog;
-
 
12
import in.shop2020.metamodel.definitions.Category;
-
 
13
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
-
 
14
import in.shop2020.storage.bdb.StorageManager;
11
import in.shop2020.storage.mongo.StorageManager;
15
import in.shop2020.util.Utils;
12
import in.shop2020.util.Utils;
16
 
13
 
17
import java.io.File;
14
import java.io.File;
18
import java.io.PrintWriter;
15
import java.io.PrintWriter;
19
import java.io.StringWriter;
16
import java.io.StringWriter;
20
import java.io.Writer;
17
import java.io.Writer;
-
 
18
import java.lang.reflect.Type;
21
import java.util.ArrayList;
19
import java.util.ArrayList;
22
import java.util.Collection;
20
import java.util.Collection;
23
import java.util.Date;
-
 
24
import java.util.HashMap;
21
import java.util.HashMap;
25
import java.util.HashSet;
-
 
26
import java.util.List;
22
import java.util.List;
27
import java.util.Map;
23
import java.util.Map;
28
import java.util.Set;
24
import java.util.Set;
29
 
25
 
-
 
26
import com.google.gson.reflect.TypeToken;
-
 
27
 
30
/**
28
/**
31
 * All storage and retrival utility methods
29
 * All storage and retrival utility methods
32
 * @author rajveer
30
 * @author rajveer
33
 *
31
 *
34
 */
32
 */
Line 48... Line 46...
48
	private static final String SYNONYMS = "SYNONYMS";
46
	private static final String SYNONYMS = "SYNONYMS";
49
	private static final String EXPERT_REVIEWS = "EXPERT_REVIEWS";
47
	private static final String EXPERT_REVIEWS = "EXPERT_REVIEWS";
50
	private static final String EXPERT_REVIEW_SOURCES = "EXPERT_REVIEW_SOURCES";
48
	private static final String EXPERT_REVIEW_SOURCES = "EXPERT_REVIEW_SOURCES";
51
	private static long helpDocId;
49
	private static long helpDocId;
52
    private static long specialPageId;
50
    private static long specialPageId;
53
 
51
    
54
	/**
52
	/**
55
	 * 
53
	 * 
56
	 * @param aThrowable
54
	 * @param aThrowable
57
	 * @return
55
	 * @return
58
	 */
56
	 */
Line 77... Line 75...
77
     * @return
75
     * @return
78
     * @throws Exception
76
     * @throws Exception
79
     */
77
     */
80
    @SuppressWarnings("unchecked")
78
    @SuppressWarnings("unchecked")
81
    public static List<Long> getInconsistentEntities() throws Exception {
79
    public static List<Long> getInconsistentEntities() throws Exception {
-
 
80
    	Type t = new TypeToken<List<Long>>() {}.getType();
82
        return (List<Long>) StorageManager.getStorageManager().getDataObject(CreationUtils.INCONSISTENT_ENTITIES);       
81
        return (List<Long>) StorageManager.getStorageManager().getDataObject(CreationUtils.INCONSISTENT_ENTITIES,t);       
83
    }
82
    }
84
    
83
    
85
    /**
-
 
86
     * 
-
 
87
     * @param entity
-
 
88
     * @throws Exception
-
 
89
     */
-
 
90
    public static void storeLearnedBullets(Map<Long, List<ExpandedBullet>> learnedBullets) throws Exception {
-
 
91
        StorageManager.getStorageManager().storeDataObject(CreationUtils.LEARNED_BULLETS, learnedBullets);      
-
 
92
    }
-
 
93
    
84
    
94
    /**
-
 
95
     * 
-
 
96
     * @return
-
 
97
     * @throws Exception
-
 
98
     */
-
 
99
    @SuppressWarnings("unchecked")
-
 
100
    public static Map<Long, List<ExpandedBullet>> getLearnedBullets() throws Exception {
-
 
101
        return (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);       
-
 
102
    }
-
 
103
    
-
 
104
    /**
-
 
105
     * 
-
 
106
     * @param entity
-
 
107
     * @throws Exception
-
 
108
     */
-
 
109
    public static void storeHelpdocEntityIds(Map<Long, List<Long>> helpdocEntityIds) throws Exception {
-
 
110
        StorageManager.getStorageManager().storeDataObject(CreationUtils.HELPDOC_ENTITYIDS, helpdocEntityIds);      
-
 
111
    }
-
 
112
    
-
 
113
    /**
-
 
114
     * 
-
 
115
     * @return
-
 
116
     * @throws Exception
-
 
117
     */
-
 
118
    @SuppressWarnings("unchecked")
-
 
119
    public static Map<Long, List<Long>> getHelpdocEntityIds() throws Exception {
-
 
120
        return (Map<Long, List<Long>>) StorageManager.getStorageManager().getDataObject(CreationUtils.HELPDOC_ENTITYIDS);       
-
 
121
    }
-
 
122
 
-
 
123
 
-
 
124
    /**
-
 
125
     * 
-
 
126
     * @param entity
-
 
127
     * @throws Exception
-
 
128
     */
-
 
129
    public static void storeRelatedAccessories(Map<Long, Map<Long, List<Long>>> relatedAccessories) throws Exception {
-
 
130
        StorageManager.getStorageManager().storeDataObject(CreationUtils.RELATED_ACCESSORIES, relatedAccessories);      
-
 
131
    }
-
 
132
    
-
 
133
    /**
-
 
134
     * 
-
 
135
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
136
     * @throws Exception
-
 
137
     */
-
 
138
    @SuppressWarnings("unchecked")
-
 
139
    public static Map<String, Map<String, String>> getSynonyms() throws Exception {
-
 
140
    	return (Map<String, Map<String,String>>)StorageManager.getStorageManager().getDataObject(CreationUtils.SYNONYMS);      
-
 
141
    }
-
 
142
    
-
 
143
    /**
-
 
144
     * 
-
 
145
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
146
     * @throws Exception
-
 
147
     */
-
 
148
    public static void storeSynonyms(Map<String, Map<String, String>> synonyms) throws Exception {
-
 
149
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.SYNONYMS, synonyms);      
-
 
150
    }
-
 
151
 
-
 
152
    
-
 
153
    /**
-
 
154
     * 
-
 
155
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
156
     * @throws Exception
-
 
157
     */
-
 
158
    @SuppressWarnings("unchecked")
-
 
159
    public static Map<Long, List<ExpertReview>> getExpertReviews() throws Exception {
-
 
160
    	return (Map<Long, List<ExpertReview>>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEWS);      
-
 
161
    }
-
 
162
 
-
 
163
    /**
-
 
164
     * 
-
 
165
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
166
     * @throws Exception
-
 
167
     */
-
 
168
    @SuppressWarnings("unchecked")
-
 
169
    public static List<ExpertReview> getExpertReviewByEntity(long entityId) throws Exception {
-
 
170
    	return ((Map<Long, List<ExpertReview>>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEWS)).get(entityId);      
-
 
171
    }
-
 
172
    
-
 
173
    public static Set<ExpertReviewSource> getExpertReviewSources() throws Exception {
-
 
174
    	return (Set<ExpertReviewSource>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEW_SOURCES);      
-
 
175
    }
-
 
176
    
-
 
177
    public static void addExpertReviewSource(ExpertReviewSource expertReviewSource) throws Exception {
-
 
178
    	Set<ExpertReviewSource> expertReviewSources = (Set<ExpertReviewSource>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEW_SOURCES);
-
 
179
    	if(expertReviewSources == null){
-
 
180
    		expertReviewSources = new HashSet<ExpertReviewSource>();
-
 
181
    	}
-
 
182
    	expertReviewSources.add(expertReviewSource);
-
 
183
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.EXPERT_REVIEW_SOURCES, expertReviewSources);      
-
 
184
    	
-
 
185
    }
-
 
186
 
-
 
187
    public static void deleteExpertReviewSource(ExpertReviewSource expertReviewSource) throws Exception {
-
 
188
    	Set<ExpertReviewSource> expertReviewSources = (Set<ExpertReviewSource>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEW_SOURCES);
-
 
189
    	expertReviewSources.remove(expertReviewSource);
-
 
190
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.EXPERT_REVIEW_SOURCES, expertReviewSources);      
-
 
191
    	
-
 
192
    }
-
 
193
    
-
 
194
    /**
-
 
195
     * 
-
 
196
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
197
     * @throws Exception
-
 
198
     */
-
 
199
    public static void storeExpertReview(long entityId, ExpertReview expertReview) throws Exception {
-
 
200
    	Map<Long, List<ExpertReview>> expertReviewMap = (Map<Long, List<ExpertReview>>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEWS);
-
 
201
    	if(expertReviewMap == null){
-
 
202
    		expertReviewMap = new HashMap<Long, List<ExpertReview>>();
-
 
203
    	}
-
 
204
    	EntityState es = CreationUtils.getEntityState(entityId);
-
 
205
    	es.setMerkedReadyOn(new Date());
-
 
206
    	CreationUtils.updateEntityState(es);
-
 
207
    	List<ExpertReview> er  = expertReviewMap.get(entityId);
-
 
208
    	if(er == null) {
-
 
209
    		er = new ArrayList<ExpertReview>();
-
 
210
    		expertReviewMap.put(entityId, er);
-
 
211
    	}
-
 
212
    	er.add(expertReview);
-
 
213
    	
-
 
214
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.EXPERT_REVIEWS, expertReviewMap);      
-
 
215
    }
-
 
216
 
-
 
217
    public static void storeExpertReview(long entityId, List<ExpertReview> expertReviews) throws Exception {
-
 
218
    	Map<Long, List<ExpertReview>> expertReviewMap = (Map<Long, List<ExpertReview>>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEWS);
-
 
219
    	expertReviewMap.put(entityId, expertReviews);
-
 
220
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.EXPERT_REVIEWS, expertReviewMap);      
-
 
221
    }
-
 
222
 
-
 
223
    public static void deleteExpertReview(long entityId, int index) throws Exception {
-
 
224
    	Map<Long, List<ExpertReview>> expertReviewMap = (Map<Long, List<ExpertReview>>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEWS);
-
 
225
    	List<ExpertReview> er  = expertReviewMap.get(entityId);
-
 
226
    	er.remove(index);
-
 
227
    	EntityState es = CreationUtils.getEntityState(entityId);
-
 
228
    	es.setMerkedReadyOn(new Date());
-
 
229
    	CreationUtils.updateEntityState(es);
-
 
230
    	
-
 
231
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.EXPERT_REVIEWS, expertReviewMap);      
-
 
232
    }
-
 
233
 
-
 
234
    /**
-
 
235
     * 
-
 
236
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
237
     * @throws Exception
-
 
238
     */
-
 
239
    public static void deleteExpertReviews(long entityId) throws Exception {
-
 
240
    	Map<Long, List<ExpertReview>> expertReviewMap = (Map<Long, List<ExpertReview>>)StorageManager.getStorageManager().getDataObject(CreationUtils.EXPERT_REVIEWS);
-
 
241
    	expertReviewMap.remove(entityId);
-
 
242
    	EntityState es = CreationUtils.getEntityState(entityId);
-
 
243
    	es.setMerkedReadyOn(new Date());
-
 
244
    	CreationUtils.updateEntityState(es);
-
 
245
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.EXPERT_REVIEWS, expertReviewMap);      
-
 
246
    }
-
 
247
 
-
 
248
  
-
 
249
    /**
-
 
250
     * 
-
 
251
     * @return
-
 
252
     * @throws Exception
-
 
253
     */
-
 
254
    @SuppressWarnings("unchecked")
-
 
255
    public static Map<Long, Map<Long, List<Long>>> getRelatedAccessories() throws Exception {
-
 
256
        return (Map<Long, Map<Long, List<Long>>>) StorageManager.getStorageManager().getDataObject(CreationUtils.RELATED_ACCESSORIES);       
-
 
257
    }
-
 
258
 
-
 
259
  
-
 
260
    /**
-
 
261
     * 
-
 
262
     * @param entity
-
 
263
     * @throws Exception
-
 
264
     */
-
 
265
    public static void storeComparisonStats(Map<Long, Map<Long, Long>> comparisonStats) throws Exception {
-
 
266
        StorageManager.getStorageManager().storeDataObject(CreationUtils.COMPARISON_STATS, comparisonStats);      
-
 
267
    }
-
 
268
    
-
 
269
  
-
 
270
    /**
-
 
271
     * 
-
 
272
     * @return
-
 
273
     * @throws Exception
-
 
274
     */
-
 
275
    @SuppressWarnings("unchecked")
-
 
276
    public static Map<Long, Map<Long, Long>> getComparisonStats() throws Exception {
-
 
277
        return (Map<Long, Map<Long, Long>>) StorageManager.getStorageManager().getDataObject(CreationUtils.COMPARISON_STATS);       
-
 
278
    }
-
 
279
    
85
    
280
    /**
86
    /**
281
     * 
87
     * 
282
     * @param entity
88
     * @param entity
283
     * @throws Exception
89
     * @throws Exception
284
     */
90
     */
285
    public static void storeSearchStats(String date, List<String> searchStats) throws Exception {
91
    public static void storeSearchStats(String date, List<String> searchStats) throws Exception {
-
 
92
    	Map<String,List<String>> map = new HashMap<String, List<String>>();
-
 
93
    	map.put(date, searchStats);
286
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.SEARCH_STATS + date, searchStats);      
94
    	StorageManager.getStorageManager().storeSearchStats(Long.parseLong(date), map);      
287
    }
95
    }
288
 
96
 
289
    /**
97
    /**
290
     * 
98
     * 
291
     * @param entity
99
     * @param entity
292
     * @throws Exception
100
     * @throws Exception
293
     */
101
     */
294
    public static void deleteSearchStats(String date) throws Exception {
102
    public static void deleteSearchStats(String date) throws Exception {
295
    	StorageManager.getStorageManager().deleteDataObject(CreationUtils.SEARCH_STATS + date);      
103
    	StorageManager.getStorageManager().deleteSearchStats(Long.parseLong(date));      
296
    }
104
    }
297
    
105
    
298
    
106
    
299
    /**
107
    /**
300
     * 
108
     * 
301
     * @return
109
     * @return
302
     * @throws Exception
110
     * @throws Exception
303
     */
111
     */
304
    @SuppressWarnings("unchecked")
-
 
305
    public static List<String> getSearchStats(String date) throws Exception {
112
    public static List<String> getSearchStats(String date) throws Exception {
306
    	return (List<String>) StorageManager.getStorageManager().getDataObject(CreationUtils.SEARCH_STATS + date);       
113
    	return StorageManager.getStorageManager().getSearchStats(Long.parseLong(date));       
307
    }
114
    }
308
 
115
 
309
	/**
116
	/**
310
	 * 
117
	 * 
311
	 * @param featureDefinitionID
-
 
312
	 * @return
-
 
313
	 * @throws Exception
-
 
314
	 */
-
 
315
	@SuppressWarnings("unchecked")
-
 
316
	public static List<ExpandedBullet> getLearnedBullets(long featureDefinitionID) throws Exception {
-
 
317
		Map<Long, List<ExpandedBullet>> learnedBullets = (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);
-
 
318
		if(learnedBullets==null){
-
 
319
			return null;
-
 
320
		}
-
 
321
		return learnedBullets.get(featureDefinitionID);
-
 
322
	}
-
 
323
 
-
 
324
	/**
-
 
325
	 * 
-
 
326
	 * @param facetIDFacetValues
-
 
327
	 * @throws Exception
-
 
328
	 */
-
 
329
	public static void storeFacetValues(Map<Long, List<String>> facetIDFacetValues) throws Exception {
-
 
330
		StorageManager.getStorageManager().storeDataObject(CreationUtils.FACET_VALUES, facetIDFacetValues);
-
 
331
	}
-
 
332
 
-
 
333
	/**
-
 
334
	 * 
-
 
335
	 * @return
-
 
336
	 * @throws Exception
-
 
337
	 */
-
 
338
	@SuppressWarnings("unchecked")
-
 
339
	public static Map<Long, List<String>>  getFacetValues() throws Exception {
-
 
340
		return (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
-
 
341
	}
-
 
342
 
-
 
343
	/**
-
 
344
	 * 
-
 
345
	 * @param facetDefinitionID
-
 
346
	 * @return
-
 
347
	 * @throws Exception
-
 
348
	 */
-
 
349
	@SuppressWarnings("unchecked")
-
 
350
	public static List<String>  getFacetValues(long facetDefinitionID) throws Exception {
-
 
351
		Map<Long, List<String>> facetValues = (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
-
 
352
		return facetValues.get(facetDefinitionID);
-
 
353
	}
-
 
354
 
-
 
355
	/**
-
 
356
	 * 
-
 
357
	 * @param slideScoresByEntity
118
	 * @param slideScoresByEntity
358
	 * @throws Exception
119
	 * @throws Exception
359
	 */
120
	 */
360
	public static void storeSlideScores( Map<Long, Map<Long, Double>> slideScoresByEntity) throws Exception {
121
	public static void storeSlideScores( Map<Long, Map<Long, Double>> slideScoresByEntity) throws Exception {
361
		StorageManager.getStorageManager().storeDataObject(CreationUtils.SLIDE_SCORES, slideScoresByEntity);
122
		StorageManager.getStorageManager().storeDataObject(CreationUtils.SLIDE_SCORES, slideScoresByEntity);
362
	}
123
	}
363
 
124
	
364
	/**
-
 
365
	 * 
-
 
366
	 * @return
-
 
367
	 * @throws Exception
-
 
368
	 */
-
 
369
	@SuppressWarnings("unchecked")
-
 
370
	public static Map<Long, Map<Long, Double>> getSlideScores() throws Exception {
-
 
371
		return (Map<Long, Map<Long, Double>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
-
 
372
	}
125
	
373
 
126
 
374
	/**
127
	/**
375
	 * 
128
	 * 
376
	 * @param entityID
129
	 * @param entityID
377
	 * @return
130
	 * @return
378
	 * @throws Exception
131
	 * @throws Exception
379
	 */
132
	 */
380
	@SuppressWarnings("unchecked")
133
	@SuppressWarnings("unchecked")
381
	public static Map<Long, Double> getSlideComparisonScores(long entityID) throws Exception{
134
	public static Map<Long, Double> getSlideComparisonScores(long entityID) throws Exception{
-
 
135
		Type t = new TypeToken<Map<Long, Map<Long,Double>>>() {}.getType();
382
		Map<Long, Map<Long, Double>> slideScores = (Map<Long, Map<Long, Double>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
136
		return  ((Map<Long, Map<Long,Double>>)StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES, t)).get(entityID);
383
		return slideScores.get(entityID);
-
 
384
	}
137
	}
385
	
138
	
386
	/**
139
	/**
387
	 * 
140
	 * 
388
	 * @param entityID
141
	 * @param entityID
389
	 * @return
142
	 * @return
390
	 * @throws Exception
143
	 * @throws Exception
391
	 */
144
	 */
392
	@SuppressWarnings("unchecked")
145
	@SuppressWarnings("unchecked")
393
	public static Map<Long, Double> getCustomSlideComparisonScores(long entityID) throws Exception{
146
	public static Map<Long, Double> getCustomSlideComparisonScores(long entityID) throws Exception{
394
		return  (Map<Long, Double>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES + entityID);
147
		return  StorageManager.getStorageManager().getCustomSlideScores(entityID);
395
	}
148
	}
396
	
149
	
397
	/**
150
	/**
398
	 * 
151
	 * 
399
	 * @param entityID
152
	 * @param entityID
400
	 * @return
153
	 * @return
401
	 * @throws Exception
154
	 * @throws Exception
402
	 */
155
	 */
403
	public static void storeCustomSlideComparisonScores(long entityID, Map<Long, Double> customSlideScores) throws Exception{
156
	public static void storeCustomSlideComparisonScores(long entityID, Map<Long, Double> customSlideScores) throws Exception{
404
		StorageManager.getStorageManager().storeDataObject(CreationUtils.SLIDE_SCORES + entityID, customSlideScores);
157
		StorageManager.getStorageManager().storeCustomSlideScores(entityID, customSlideScores);
405
	}
-
 
406
	
-
 
407
	
-
 
408
	/**
-
 
409
	 * 
-
 
410
	 * @param finalScoreByEntityID
-
 
411
	 * @throws Exception
-
 
412
	 */
-
 
413
	public static void storeDefaultEntityScores(Map<Long, Double> finalScoreByEntityID) throws Exception {
-
 
414
		StorageManager.getStorageManager().storeDataObject(CreationUtils.DEFAULT_ENTITY_SCORES, finalScoreByEntityID);
-
 
415
	}
-
 
416
	
-
 
417
	/**
-
 
418
	 * 
-
 
419
	 * @return
-
 
420
	 * @throws Exception
-
 
421
	 */
-
 
422
	@SuppressWarnings("unchecked")
-
 
423
	public static Map<Long, Integer> getDefaultEntityScores() throws Exception {
-
 
424
		return (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
-
 
425
	}
-
 
426
	
-
 
427
	/**
-
 
428
	 * 
-
 
429
	 * @param entityID
-
 
430
	 * @return
-
 
431
	 * @throws Exception
-
 
432
	 */
-
 
433
	@SuppressWarnings("unchecked")
-
 
434
	public static Integer getEntityComparisonScores(long entityID) throws Exception {
-
 
435
		Map<Long, Integer> scoresMap =  (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
-
 
436
		Integer objScore = scoresMap.get(entityID);
-
 
437
		if(objScore==null){
-
 
438
			return -1;
-
 
439
		}
-
 
440
		return objScore;
-
 
441
	}
158
	}
442
	
159
	
443
	
160
	
444
	/**
161
	/**
445
	 * 
162
	 * 
446
	 * @return
163
	 * @return
447
	 * @throws Exception
164
	 * @throws Exception
448
	 */
165
	 */
449
	public static Long getLastContentGenerationTime() throws Exception {
166
	public static Long getLastContentGenerationTime() throws Exception {
450
		return (Long) StorageManager.getStorageManager().getDataObject(CreationUtils.CONTENT_GENERATION_TIME);
167
		return (Long) StorageManager.getStorageManager().getDataObject(CreationUtils.CONTENT_GENERATION_TIME, Long.class);
451
	}
168
	}
452
	
169
	
453
	/**
170
	/**
454
	 * 
171
	 * 
455
	 * @param storageTime
172
	 * @param storageTime
Line 515... Line 232...
515
	/**
232
	/**
516
	 * 
233
	 * 
517
	 * @return
234
	 * @return
518
	 * @throws Exception
235
	 * @throws Exception
519
	 */
236
	 */
520
	public static Map<Long, EntityState> getEntitiesState() throws Exception {
237
	public static Map<Long, EntityState> getEntitiesState() {
521
		return StorageManager.getStorageManager().getEntitiesMetadata();
238
		return StorageManager.getStorageManager().getEntitiesMetadata();
522
	}
239
	}
523
	
240
	
524
	/**
241
	/**
525
	 * 
242
	 * 
526
	 * @param entityId
243
	 * @param entityId
527
	 * @return
244
	 * @return
528
	 * @throws Exception
245
	 * @throws Exception
529
	 */
246
	 */
530
	public static EntityState getEntityState(long entityId) throws Exception {
247
	public static EntityState getEntityState(long entityId) {
531
		return StorageManager.getStorageManager().getEntityMetadata(entityId);
248
		return StorageManager.getStorageManager().getEntityMetadata(entityId);
532
	}
249
	}
533
 
250
 
534
	/**
251
	/**
535
	 * 
252
	 * 
536
	 * @param entityMetadata
253
	 * @param entityMetadata
537
	 * @throws Exception
254
	 * @throws Exception
538
	 */
255
	 */
539
	public static void updateEntityState(EntityState entityMetadata) throws Exception {
256
	public static void updateEntityState(EntityState entityMetadata) {
540
		StorageManager.getStorageManager().updateEntityMetadata(entityMetadata);
257
		StorageManager.getStorageManager().updateEntityMetadata(entityMetadata);
541
	}
258
	}
542
 
259
 
543
	/**
260
	/**
544
	 * 
261
	 * 
Line 757... Line 474...
757
		System.out.println( entity.getCategoryID());
474
		System.out.println( entity.getCategoryID());
758
		ExpandedEntity expEntity = new ExpandedEntity(entity);
475
		ExpandedEntity expEntity = new ExpandedEntity(entity);
759
		return expEntity;
476
		return expEntity;
760
	}
477
	}
761
	
478
	
762
	
-
 
763
	/**
-
 
764
	 * Returns list of borrowed slides
-
 
765
	 * 
-
 
766
	 * @param entity
-
 
767
	 * @return list of borrowed slides
-
 
768
	 */
-
 
769
	public static List<Slide> getBorrowedSlides(Entity entity) {
-
 
770
		List<Slide> borrowedSlides = new ArrayList<Slide>();
-
 
771
		
-
 
772
		List<Slide> slides = entity.getSlides();
-
 
773
		
-
 
774
		for(Slide slide : slides) {
-
 
775
			if(CreationUtils.isBorrowedSlide(slide.getSlideDefinitionID(), entity.getCategoryID())) {
-
 
776
				borrowedSlides.add(slide);
-
 
777
			}
-
 
778
		}
-
 
779
		
-
 
780
		return borrowedSlides;
-
 
781
	}
-
 
782
	
-
 
783
	/**
479
	/**
784
	 * Returns first parent slide with matching label
480
	 * Returns first parent slide with matching label
785
	 * 
481
	 * 
786
	 * @param expEntity2
482
	 * @param expEntity2
787
	 * @param slideLabel
483
	 * @param slideLabel
Line 799... Line 495...
799
			}
495
			}
800
		}
496
		}
801
		
497
		
802
		return matchingSlide;
498
		return matchingSlide;
803
	}
499
	}
804
	
-
 
805
	/**
-
 
806
	 * 
-
 
807
	 * @param slideDefinitionID
-
 
808
	 * @param categoryID
-
 
809
	 * @return
-
 
810
	 */
-
 
811
	public static boolean isBorrowedSlide(long slideDefinitionID,long categoryID) {
-
 
812
		List<CategorySlideDefinition> slideDefinitions;
-
 
813
		try {
-
 
814
			slideDefinitions = Catalog.getInstance().getDefinitionsContainer().getCategorySlideDefinitions(categoryID);
-
 
815
			for(CategorySlideDefinition slideDef: slideDefinitions){
-
 
816
				if(slideDefinitionID == slideDef.getSlideDefintionID()){
-
 
817
					return false;
-
 
818
				}
-
 
819
			}
-
 
820
		} catch (Exception e) {
-
 
821
			// TODO Auto-generated catch block
-
 
822
			e.printStackTrace();
-
 
823
		}
-
 
824
		return true;
-
 
825
	}
-
 
826
 
500
 
827
	/**
-
 
828
	 * 
-
 
829
	 * @param slideDefinitionID
-
 
830
	 * @param categoryID
-
 
831
	 * @return
-
 
832
	 */
-
 
833
	public static long getBorrowedCategoryID(long slideDefinitionID, long categoryID) {
-
 
834
		try {
-
 
835
			List<CategorySlideDefinition> slideDefinitions = Catalog.getInstance().getDefinitionsContainer().getCategorySlideDefinitions(categoryID);
-
 
836
			for(CategorySlideDefinition slideDef: slideDefinitions){
-
 
837
				if(slideDefinitionID == slideDef.getSlideDefintionID()){
-
 
838
					return categoryID;
-
 
839
				}
-
 
840
			}
-
 
841
			
-
 
842
			
-
 
843
			List<Category> cats =  Catalog.getInstance().getDefinitionsContainer().getCategory(categoryID).getParentCategory().getChildrenCategory();
-
 
844
			for(Category cat: cats){
-
 
845
				if(cat.getID() == categoryID){
-
 
846
					continue;
-
 
847
				}else{
-
 
848
					List<CategorySlideDefinition> slideDefs = Catalog.getInstance().getDefinitionsContainer().getCategorySlideDefinitions(cat.getID());
-
 
849
					for(CategorySlideDefinition slideDef: slideDefs){
-
 
850
						if(slideDefinitionID == slideDef.getSlideDefintionID()){
-
 
851
							return cat.getID();
-
 
852
						}
-
 
853
					}
-
 
854
					
-
 
855
				}
-
 
856
			}
-
 
857
		
-
 
858
		} catch (Exception e) {
-
 
859
			// TODO Auto-generated catch block
-
 
860
			e.printStackTrace();
-
 
861
		}
-
 
862
		return categoryID;
-
 
863
	}
-
 
864
 
501
 
865
	/**
502
	/**
866
	 * Special page ids start from 300000. Here, we pick the last one used and return
503
	 * Special page ids start from 300000. Here, we pick the last one used and return
867
     * a value one more than it.
504
     * a value one more than it.
868
	 */
505
	 */
869
    public static long getNewSpecialPageId() {
506
    public static long getNewSpecialPageId() {
870
        if (specialPageId == 0) {
507
    	if (specialPageId == 0) {
871
            specialPageId = 300000;
-
 
872
            Map<Long, SpecialPage> specialPages = StorageManager.getStorageManager().getSpecialPages();
508
    		specialPageId = StorageManager.getStorageManager().getMaxPageId();
873
            if (specialPages != null) {
509
    		if(specialPageId == 0) {
874
                for (long id : StorageManager.getStorageManager().getSpecialPages().keySet()) {
-
 
875
                    if (specialPageId <= id) {
-
 
876
                        specialPageId = id;
510
    			specialPageId = 300000;
877
                    }
-
 
878
                }
-
 
879
            }
511
    		}
880
        }
512
        }
881
 
513
 
882
        return ++specialPageId;
514
        return ++specialPageId;
883
    }
515
    }
884
 
516
 
Line 907... Line 539...
907
     * delete the special pages from database.
539
     * delete the special pages from database.
908
     */
540
     */
909
    public static void deleteSpecialPage(long specialPageId) {
541
    public static void deleteSpecialPage(long specialPageId) {
910
        StorageManager.getStorageManager().deleteSpecialPage(specialPageId);
542
        StorageManager.getStorageManager().deleteSpecialPage(specialPageId);
911
    }
543
    }
-
 
544
 
-
 
545
    /**
-
 
546
     * 
-
 
547
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
548
     * @throws Exception
-
 
549
     */
-
 
550
    public static List<ExpertReview> getExpertReviewByEntity(long entityId) throws Exception {
-
 
551
    	return StorageManager.getStorageManager().getExpertReviewByEntity(entityId);      
-
 
552
    }
-
 
553
    
-
 
554
    public static Set<ExpertReviewSource> getExpertReviewSources() throws Exception {
-
 
555
    	return StorageManager.getStorageManager().getExpertReviewSources();      
-
 
556
    }
-
 
557
    
-
 
558
    public static void addExpertReviewSource(ExpertReviewSource expertReviewSource) throws Exception {
-
 
559
    	StorageManager.getStorageManager().storeExpertReviewSource(expertReviewSource);      
-
 
560
    }
-
 
561
 
-
 
562
    public static void deleteExpertReviewSource(ExpertReviewSource expertReviewSource) throws Exception {
-
 
563
    	StorageManager.getStorageManager().deleteExpertReviewSource(expertReviewSource);      
-
 
564
    	
-
 
565
    }
-
 
566
    
-
 
567
 
-
 
568
    public static void storeExpertReview(long entityId, List<ExpertReview> expertReviews) throws Exception {
-
 
569
    	StorageManager.getStorageManager().storeExpertReview(entityId, expertReviews);      
-
 
570
    }
-
 
571
 
-
 
572
    public static void deleteExpertReview(long entityId, int index) throws Exception {
-
 
573
    	StorageManager.getStorageManager().deleteExpertReview(entityId, index);      
-
 
574
    }
-
 
575
 
-
 
576
    public static Map<Long, List<ExpertReview>> getExpertReviews() throws Exception {
-
 
577
    	return StorageManager.getStorageManager().getExpertReviews();      
-
 
578
    }
-
 
579
 
-
 
580
    /**
-
 
581
     * 
-
 
582
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
583
     * @throws Exception
-
 
584
     */
-
 
585
    public static void deleteExpertReviews(long entityId) throws Exception {
-
 
586
    	StorageManager.getStorageManager().deleteExpertReview(entityId);      
-
 
587
    }
-
 
588
    
-
 
589
  
-
 
590
    
-
 
591
    /**
-
 
592
     * 
-
 
593
     * @return
-
 
594
     * @throws Exception
-
 
595
     */
-
 
596
    @SuppressWarnings("unchecked")
-
 
597
    public static Map<Long, Map<Long, Long>> getComparisonStats() throws Exception {
-
 
598
    	Type t = new TypeToken<Map<Long, Map<Long, Long>>>() {}.getType();
-
 
599
    	return (Map<Long, Map<Long, Long>>) StorageManager.getStorageManager().getDataObject(CreationUtils.COMPARISON_STATS, t);       
-
 
600
    }
-
 
601
    /**
-
 
602
     * 
-
 
603
     * @param entity
-
 
604
     * @throws Exception
-
 
605
     */
-
 
606
    public static void storeComparisonStats(Map<Long, Map<Long, Long>> comparisonStats) throws Exception {
-
 
607
        StorageManager.getStorageManager().storeDataObject(CreationUtils.COMPARISON_STATS, comparisonStats);      
-
 
608
    }
-
 
609
    
-
 
610
     
-
 
611
    public static Map<Long, List<ExpandedBullet>> getLearnedBullets() throws Exception {
-
 
612
        return StorageManager.getStorageManager().getLearnedBullets();       
-
 
613
    }
-
 
614
    
-
 
615
    /**
-
 
616
     * 
-
 
617
     * @param entity
-
 
618
     * @throws Exception
-
 
619
     */
-
 
620
    public static void storeLearnedBullets(Map<Long, List<ExpandedBullet>> learnedBullets) throws Exception {
-
 
621
    	StorageManager.getStorageManager().storeLearnedBullets(learnedBullets);      
-
 
622
    }
-
 
623
    
-
 
624
	/**
-
 
625
	 * 
-
 
626
	 * @param featureDefinitionID
-
 
627
	 * @return
-
 
628
	 * @throws Exception
-
 
629
	 */
-
 
630
	public static List<ExpandedBullet> getLearnedBullets(long featureDefinitionID) throws Exception {
-
 
631
		Set<ExpandedBullet> expBullets = StorageManager.getStorageManager().getLearnedBulletsByFeatureId(featureDefinitionID);
-
 
632
		if(expBullets == null) return null;
-
 
633
		return new ArrayList<ExpandedBullet>(expBullets);
-
 
634
		
-
 
635
	}
-
 
636
    
-
 
637
    /**
-
 
638
     * 
-
 
639
     * @param entity
-
 
640
     * @throws Exception
-
 
641
     */
-
 
642
    public static void storeHelpdocEntityIds(Map<Long, List<Long>> helpdocEntityIds) throws Exception {
-
 
643
    	
-
 
644
        StorageManager.getStorageManager().storeDataObject(CreationUtils.HELPDOC_ENTITYIDS, helpdocEntityIds);      
-
 
645
    }
-
 
646
    
-
 
647
    /**
-
 
648
     * 
-
 
649
     * @return
-
 
650
     * @throws Exception
-
 
651
     */
-
 
652
    public static Map<Long,List<Long>> getHelpdocEntityIds() throws Exception {
-
 
653
        return StorageManager.getStorageManager().getHelpdocEntityIds();       
-
 
654
    }
-
 
655
 
-
 
656
    /**
-
 
657
     * 
-
 
658
     * @return
-
 
659
     * @throws Exception
-
 
660
     */
-
 
661
    @SuppressWarnings("unchecked")
-
 
662
    public static Map<Long, Map<Long, List<Long>>> getRelatedAccessories() throws Exception {
-
 
663
    	Type t = new TypeToken<Map<Long, Map<Long, List<Long>>>>() {}.getType();
-
 
664
        return (Map<Long, Map<Long, List<Long>>>) StorageManager.getStorageManager().getDataObject(CreationUtils.RELATED_ACCESSORIES, t);       
-
 
665
    }
-
 
666
    
-
 
667
    /**
-
 
668
     * 
-
 
669
     * @param entity
-
 
670
     * @throws Exception
-
 
671
     */
-
 
672
    public static void storeRelatedAccessories(Map<Long, Map<Long, List<Long>>> relatedAccessories) throws Exception {
-
 
673
        StorageManager.getStorageManager().storeDataObject(CreationUtils.RELATED_ACCESSORIES, relatedAccessories);      
-
 
674
    }
-
 
675
    
-
 
676
    /**
-
 
677
     * 
-
 
678
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
679
     * @throws Exception
-
 
680
     */
-
 
681
    @SuppressWarnings("unchecked")
-
 
682
    public static Map<String, Map<String, String>> getSynonyms() throws Exception {
-
 
683
    	Type t = new TypeToken<Map<String, Map<String, String>>>() {}.getType();
-
 
684
    	return (Map<String, Map<String,String>>)StorageManager.getStorageManager().getDataObject(CreationUtils.SYNONYMS, t);      
-
 
685
    }
-
 
686
    
-
 
687
    /**
-
 
688
     * 
-
 
689
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
-
 
690
     * @throws Exception
-
 
691
     */
-
 
692
    public static void storeSynonyms(Map<String, Map<String, String>> synonyms) throws Exception {
-
 
693
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.SYNONYMS, synonyms);      
-
 
694
    }
-
 
695
  
912
}
696
}