Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 shop2020 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.definitions;
5
 
70 naveen 6
import in.shop2020.metamodel.util.ExpandedCMPSlideRuleDefinition;
45 naveen 7
import in.shop2020.metamodel.util.ExpandedCategory;
62 naveen 8
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
9
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
64 naveen 10
import in.shop2020.util.DBUtils;
70 naveen 11
import in.shop2020.util.Utils;
17 naveen 12
 
10 shop2020 13
import java.io.Serializable;
18 naveen 14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
10 shop2020 17
import java.util.Map;
18
 
19
/**
49 naveen 20
 * Single point of access to all definition objects
21
 * 
10 shop2020 22
 * @author naveen
23
 *
24
 */
25
public class DefinitionsContainer implements Serializable {
26
 
41 naveen 27
	/** 
10 shop2020 28
	 * 
29
	 */
30
	private static final long serialVersionUID = 1L;
49 naveen 31
 
32
	/**
33
	 * Hashtable of Category ID to Category object
34
	 */
10 shop2020 35
	private Map<Long, Category> categories;
49 naveen 36
 
37
	/**
38
	 * Hashtable of Slide ID to SlideDefinition object
39
	 */
10 shop2020 40
	private Map<Long, SlideDefinition> slideDefinitions;
49 naveen 41
 
42
	/**
43
	 * Hashtable of Feature Definition ID to FeatureDefinition object
44
	 */
10 shop2020 45
	private Map<Long, FeatureDefinition> featureDefinitions;
49 naveen 46
 
47
	/**
48
	 * Hashtable of Datatype Definition ID to DatatypeDefinition object
49
	 */
10 shop2020 50
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
49 naveen 51
 
52
	/**
53
	 * Hashtable of Enum value ID to EnumValue object
54
	 */
24 naveen 55
	private Map<Long, EnumValue> enumValues;
49 naveen 56
 
57
	/**
58
	 * Hashtable of Unit ID to Unit object
59
	 */
10 shop2020 60
	private Map<Long, Unit> units;
61
 
62
	/**
62 naveen 63
	 * Hashtable of Facet Definition ID to FacetDefinition object
64
	 */
65
	private Map<Long, FacetDefinition> facetDefinitions;
66
 
67
	/**
68
	 * Hashtable of Category Facet Definition ID to CategoryFacetDefinition 
69
	 * object
70
	 */
71
	private Map<Long, CategoryFacetDefinition> categoryFacetDefinitions;
72
 
73
	/**
74
	 * Hashtable of IR Data Rule ID to RuleDefinition object
75
	 */
76
	private Map<Long, RuleDefinition> irDataRuleDefinitions;	
77
 
78
	/**
79
	 * Hashtable of IR Meta Data Rule ID to RuleDefinition object
80
	 */
81
	private Map<Long, RuleDefinition> irMetaDataRuleDefinitions;
82
 
83
 
84
	/**
70 naveen 85
	 * Hashtable of Comparison Rule ID to CMPRuleDefinition object
86
	 */
87
	private Map<Long, CMPRuleDefinition> cmpRuleDefinitions;	
88
 
89
	/**
90
	 * Hashtable of SlideDefinition ID to CMPSlideRuleDefinition object
91
	 */
92
	private Map<Long, CMPSlideRuleDefinition> cmpSlideRuleDefinitions;
93
 
94
	/**
72 naveen 95
	 * Hashtable of Category ID to list of CMPBucketDefinition object
96
	 */
97
	private Map<Long, List<CMPBucketDefinition>> cmpBucketDefinitions;
98
 
99
	/**
49 naveen 100
	 * Empty constructor. Data structures are initialised as needed
10 shop2020 101
	 */
102
	public DefinitionsContainer() {
17 naveen 103
		// Lazy initialization
10 shop2020 104
	}
105
 
106
	/**
49 naveen 107
	 * Returns all Unit objects in the database
10 shop2020 108
	 * 
49 naveen 109
	 * @return Map Null if units are not imported into definitions db 
110
	 * (serialized java objects)
111
	 * 
18 naveen 112
	 * @throws Exception 
10 shop2020 113
	 */
18 naveen 114
	@SuppressWarnings("unchecked")
115
	public Map<Long, Unit> getUnits() throws Exception {		
17 naveen 116
		// De-serialize
117
		if(this.units == null) {
70 naveen 118
			String dbFile = Utils.DEFINITIONS_DB_PATH + "units" + ".ser";
18 naveen 119
 
120
			this.units = (Map<Long, Unit>) DBUtils.read(dbFile);
17 naveen 121
		}
18 naveen 122
 
10 shop2020 123
		return this.units;
124
	}
125
 
126
	/**
49 naveen 127
	 * Resolves Unit ID into Unit object
10 shop2020 128
	 * 
49 naveen 129
	 * @param unitID Unit ID
10 shop2020 130
	 * @return Unit
18 naveen 131
	 * @throws Exception 
10 shop2020 132
	 */
18 naveen 133
	public Unit getUnit(long unitID) throws Exception {		
134
		// Initialize 
135
		if(this.units == null) {
136
			this.getUnits();
137
		}
17 naveen 138
 
10 shop2020 139
		return this.units.get(new Long(unitID));
140
	}
141
 
142
	/**
49 naveen 143
	 * Returns all DatatypeDefintion object in database
144
	 * 
145
	 * @return the datatypeDefinitions List of DatatypeDefinition objects
18 naveen 146
	 * @throws Exception 
10 shop2020 147
	 */
18 naveen 148
	@SuppressWarnings("unchecked")
149
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() 
150
		throws Exception {
151
 
152
		// De-serialize
153
		if(this.datatypeDefinitions == null) {
70 naveen 154
			String dbFile = Utils.DEFINITIONS_DB_PATH + "datatypedefinitions" + 
19 naveen 155
				".ser";
18 naveen 156
 
157
			this.datatypeDefinitions = 
158
				(Map<Long, DatatypeDefinition>) DBUtils.read(dbFile);
159
		}
160
		return this.datatypeDefinitions;
10 shop2020 161
	}
18 naveen 162
 
163
	/**
49 naveen 164
	 * Resolves Datatype Definition ID into DatetypeDefinition object
18 naveen 165
	 * 
49 naveen 166
	 * @param unitID Unit ID
18 naveen 167
	 * @return Unit
168
	 * @throws Exception 
169
	 */
170
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
171
 
172
		// Initialize 
173
		if(this.datatypeDefinitions == null) {
174
			this.getDatatypeDefinitions();
175
		}
176
 
177
		return this.datatypeDefinitions.get(new Long(id));
178
	}
19 naveen 179
 
180
	/**
49 naveen 181
	 * Returns EnumValue ID for datatype definition ID and enum value string 
182
	 * to match. Match is case insensitive
19 naveen 183
	 * 
49 naveen 184
	 * @param datatypeDefID DatatypeDefinition ID
185
	 * @param value query enum value string
19 naveen 186
	 * @return long enumValueID - "-1" if not found
187
	 * @throws Exception 
188
	 */
189
	public long getEnumValueID(long datatypeDefID, String value) 
190
		throws Exception {
191
		long enumValueID = -1L;
192
 
193
		// Let the callers catch ClassCastException
194
		EnumDefinition enumDef = 
195
			(EnumDefinition)this.getDatatypeDefinition(datatypeDefID);
196
 
24 naveen 197
		List<EnumValue> enumValues = enumDef.getEnumValues();
19 naveen 198
		for(EnumValue enumValue : enumValues) {
199
			if(value.equalsIgnoreCase(enumValue.getValue())) {
200
				enumValueID = enumValue.getID();
201
				break;
202
			}
203
		}
204
 
205
		return enumValueID;
206
	}
17 naveen 207
 
10 shop2020 208
	/**
49 naveen 209
	 * Returns all category objects in the database
210
	 * 
10 shop2020 211
	 * @return the categories
17 naveen 212
	 * @throws Exception 
10 shop2020 213
	 */
17 naveen 214
	@SuppressWarnings("unchecked")
215
	public Map<Long, Category> getCategories() throws Exception {
216
 
217
		// De-serialize
218
		if(this.categories == null) {
70 naveen 219
			String dbFile = Utils.DEFINITIONS_DB_PATH + "categories" + ".ser";
17 naveen 220
 
221
			this.categories = (Map<Long, Category>) DBUtils.read(dbFile);
222
		}
223
		return this.categories;
10 shop2020 224
	}
17 naveen 225
 
10 shop2020 226
	/**
49 naveen 227
	 * Resolves Category ID into Category object
17 naveen 228
	 * 
49 naveen 229
	 * @param categoryID Category ID
17 naveen 230
	 * @return Category
231
	 * @throws Exception 
10 shop2020 232
	 */
17 naveen 233
	public Category getCategory(long categoryID) throws Exception {
234
 
18 naveen 235
		// Initialize 
17 naveen 236
		if(this.categories == null) {
237
			this.getCategories();
238
		}
239
 
240
		return this.categories.get(new Long(categoryID));
10 shop2020 241
	}
17 naveen 242
 
10 shop2020 243
	/**
49 naveen 244
	 * Returns expanded Category object. All numeric identifiers are resolved 
245
	 * into detailed objects
18 naveen 246
	 * 
247
	 * @param categoryID
45 naveen 248
	 * @return ExpandedCategory
249
	 * @throws Exception
250
	 */
251
	public ExpandedCategory getExpandedCategory(long categoryID) 
252
		throws Exception {
253
		Category category = this.getCategory(categoryID);
254
 
255
		ExpandedCategory expCategory = new ExpandedCategory(category);
256
 
257
		return expCategory;
258
	}
259
 
260
	/**
49 naveen 261
	 * Returns all children categories for a Category ID
45 naveen 262
	 * 
263
	 * @param categoryID
49 naveen 264
	 * @return List<Category> Children Categories
34 naveen 265
	 * @throws Exception
266
	 */
267
	public List<Category> getChildrenCategories(long categoryID) 
268
		throws Exception {
269
 
270
		// Initialize 
271
		if(this.categories == null) {
272
			this.getCategories();
273
		}
274
 
275
		return this.categories.get(new Long(categoryID)).getChildrenCategory();
276
	}
49 naveen 277
 
34 naveen 278
	/**
49 naveen 279
	 * Returns all CategorySlideDefinition objects for a Category ID
34 naveen 280
	 * 
49 naveen 281
	 * @param categoryID Category ID
18 naveen 282
	 * @return List<CategorySlideDefinition> 
283
	 * @throws Exception 
284
	 */
285
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
286
			long categoryID) throws Exception {
287
		Category category = this.getCategory(categoryID);
288
 
289
		return category.getCategorySlideDefintions();
290
	}
291
 
292
	/**
49 naveen 293
	 * Returns All SlideDefinition objects in database
294
	 * 
10 shop2020 295
	 * @return the slideDefinitions
18 naveen 296
	 * @throws Exception 
10 shop2020 297
	 */
18 naveen 298
	@SuppressWarnings("unchecked")
299
	public Map<Long, SlideDefinition> getSlideDefinitions() throws Exception {
300
 
301
		// De-serialize
302
		if(this.slideDefinitions == null) {
70 naveen 303
			String dbFile = Utils.DEFINITIONS_DB_PATH + "slidedefinitions" + 
18 naveen 304
				".ser";
305
 
306
			this.slideDefinitions = 
307
				(Map<Long, SlideDefinition>) DBUtils.read(dbFile);
308
		}
309
		return this.slideDefinitions;
10 shop2020 310
	}
18 naveen 311
 
312
	/**
49 naveen 313
	 * Resolves SlideDefinition ID into SlideDefinition object
18 naveen 314
	 * 
315
	 * @param id
316
	 * @return SlideDefinition
317
	 * @throws Exception
318
	 */
319
	public SlideDefinition getSlideDefinition(long id) throws Exception {
320
 
321
		// Initialize 
322
		if(this.slideDefinitions == null) {
323
			this.getSlideDefinitions();
324
		}
325
 
326
		return this.slideDefinitions.get(new Long(id));
327
	}
328
 
329
	/**
49 naveen 330
	 * Returns SlideDefinition objects for a category and matching slide label
18 naveen 331
	 * 
19 naveen 332
	 * @param label
333
	 * @return List<SlideDefinition>
334
	 * @throws Exception
335
	 */
32 naveen 336
	public List<SlideDefinition> getSlideDefinitions(long categoryID, 
337
			String label) throws Exception {
338
 
339
		// RE-VISIT
340
		// May be we need a new data structure, category id to slide definitions
341
		// for now
342
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
19 naveen 343
 
32 naveen 344
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
345
				categoryID);
346
 
347
		for(CategorySlideDefinition csDef : csDefs) {
348
			SlideDefinition sDef = this.getSlideDefinition(
349
					csDef.getSlideDefintionID());
350
 
351
			if(sDef.getLabel().equalsIgnoreCase(label)) {
352
				matchingSlides.add(sDef);
353
			}
19 naveen 354
		}
355
 
32 naveen 356
		return matchingSlides;
357
	}
358
 
359
	/**
49 naveen 360
	 * Resolves Category ID into Category object
32 naveen 361
	 * 
362
	 * @param categoryID
49 naveen 363
	 * @return List<SlideDefinition> 
32 naveen 364
	 * @throws Exception
365
	 */
366
	public List<SlideDefinition> getSlideDefinitions(long categoryID) 
367
		throws Exception {
368
 
369
		// RE-VISIT
370
		// May be we need a new data structure, category id to slide definitions
371
		// for now
19 naveen 372
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
32 naveen 373
 
374
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
375
				categoryID);
376
 
377
		for(CategorySlideDefinition csDef : csDefs) {
378
			SlideDefinition sDef = this.getSlideDefinition(
379
					csDef.getSlideDefintionID());
19 naveen 380
 
32 naveen 381
			matchingSlides.add(sDef);
19 naveen 382
		}
383
 
384
		return matchingSlides;
385
	}
49 naveen 386
 
19 naveen 387
	/**
49 naveen 388
	 * Returns list of SlideDefinition objects for a category and editorial 
389
	 * importance value
19 naveen 390
	 * 
18 naveen 391
	 * @param categoryID
392
	 * @param EditorialImportance imp
393
	 * @return List<SlideDefinition>
394
	 * @throws Exception 
395
	 */
396
	public List<SlideDefinition> getSlides(long categoryID, 
397
			EditorialImportance imp) 
398
		throws Exception {
399
 
400
		List<CategorySlideDefinition> catSlideDefs = 
401
			this.getCategorySlideDefinitions(categoryID);
402
 
403
		Iterator<CategorySlideDefinition> itCatSlideDefs = 
404
			catSlideDefs.iterator();
405
 
406
		List<SlideDefinition> slideDefs = new ArrayList<SlideDefinition>();
407
		while(itCatSlideDefs.hasNext()) {
408
			CategorySlideDefinition catSlideDef = itCatSlideDefs.next();
409
			if(catSlideDef.getEditorialImportance() == imp) {
410
				long slideDefID = catSlideDef.getSlideDefintionID();
411
				slideDefs.add(this.getSlideDefinition(slideDefID));
412
			}
413
		}
414
		return slideDefs;
415
	}
416
 
417
	/**
49 naveen 418
	 * Returns all FeatureDefinition object in database
18 naveen 419
	 * 
420
	 * @return Map<Long, FeatureDefinition>
421
	 * @throws Exception
422
	 */
423
	@SuppressWarnings("unchecked")
424
	public Map<Long, FeatureDefinition> getFeatureDefinitions() 
425
		throws Exception {
426
 
427
		// De-serialize
428
		if(this.featureDefinitions == null) {
70 naveen 429
			String dbFile = Utils.DEFINITIONS_DB_PATH + "featuredefinitions" + 
18 naveen 430
				".ser";
431
 
432
			this.featureDefinitions = 
433
				(Map<Long, FeatureDefinition>) DBUtils.read(dbFile);
434
		}
435
		return this.featureDefinitions;
436
	}
19 naveen 437
 
10 shop2020 438
	/**
49 naveen 439
	 * Returns all FeatureDefinition objects for a slide
18 naveen 440
	 * 
19 naveen 441
	 * @param slideID
442
	 * @return List<FeatureDefinition> 
443
	 * @throws Exception
444
	 */
445
	public List<FeatureDefinition> getFeatureDefinitions(long slideID) 
446
		throws Exception {
447
		List<FeatureDefinition> featureDefs = 
448
			new ArrayList<FeatureDefinition>();
449
 
450
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
451
		List<SlideFeatureDefinition> slideFeatureDefs = 
452
			slideDef.getSlideFeatureDefinitions();
453
 
454
		for(int i=0; i<slideFeatureDefs.size(); i++) {
455
			featureDefs.add(this.getFeatureDefinition(
456
					slideFeatureDefs.get(i).getFeatureDefintionID()));
457
		}
458
 
459
		return featureDefs;
460
	}
461
 
462
	/**
49 naveen 463
	 * Returns list of FeatureDefinition objects for a slide given editorial 
464
	 * importance
19 naveen 465
	 * 
466
	 * @param slideID
49 naveen 467
	 * @param imp Editorial Importance enum object
19 naveen 468
	 * @return List<FeatureDefinition>
469
	 * @throws Exception
470
	 */
471
	public List<FeatureDefinition> getFeatureDefinitions(long slideID, 
472
			EditorialImportance imp)  throws Exception {
473
		List<FeatureDefinition> featureDefs = 
474
			new ArrayList<FeatureDefinition>();
475
 
476
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
477
		List<SlideFeatureDefinition> slideFeatureDefs = 
478
			slideDef.getSlideFeatureDefinitions();
479
 
480
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
481
			if(slideFeatureDef.getEditorialImportance() == imp) {
482
				featureDefs.add(this.getFeatureDefinition(
483
						slideFeatureDef.getFeatureDefintionID()));
484
			}
485
		}
486
 
487
		return featureDefs;
488
	}
489
 
490
	/**
49 naveen 491
	 * Resolves Feature Definition ID into FeatureDefinition object
19 naveen 492
	 * 
49 naveen 493
	 * @param id Feature Definition ID 
19 naveen 494
	 * @return FeatureDefinition
18 naveen 495
	 * @throws Exception
10 shop2020 496
	 */
18 naveen 497
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
498
 
499
		// Initialize 
500
		if(this.featureDefinitions == null) {
501
			this.getFeatureDefinitions();
502
		}
503
 
504
		return this.featureDefinitions.get(new Long(id));
505
	}	
19 naveen 506
 
507
	/**
49 naveen 508
	 * Returns matching FeatureDefinition object for slide ID and feature label.
509
	 * Label matching is case insensitive.
19 naveen 510
	 * 
49 naveen 511
	 * @param slideID Slide ID
512
	 * @param featureLabel label to match, case is ignored
19 naveen 513
	 * @return FeatureDefinition 
514
	 * @throws Exception
515
	 */
516
	public FeatureDefinition getFeatureDefinition(long slideID, 
517
			String featureLabel) throws Exception {
518
		FeatureDefinition featureDef = null;
519
 
520
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
521
		for(SlideFeatureDefinition slideFeatureDef : 
522
			slideDef.getSlideFeatureDefinitions()) {
523
 
524
			long featureDefID = slideFeatureDef.getFeatureDefintionID();
525
 
526
			FeatureDefinition thisFeatureDef = this.getFeatureDefinition(
527
					featureDefID);
528
 
28 naveen 529
			if(featureLabel.equalsIgnoreCase(thisFeatureDef.getLabel())) {
19 naveen 530
				featureDef = thisFeatureDef;
531
			}
532
		}
533
 
534
		return featureDef;
535
	}
24 naveen 536
 
537
	/**
49 naveen 538
	 * Returns all EnumValue objects in the database
539
	 * 
24 naveen 540
	 * @return the enumValues
541
	 * @throws Exception 
542
	 */
543
	@SuppressWarnings("unchecked")
544
	public Map<Long, EnumValue> getEnumValues() throws Exception {
545
		// De-serialise
546
		if(this.enumValues == null) {
70 naveen 547
			String dbFile = Utils.DEFINITIONS_DB_PATH + "enumvalues" + 
24 naveen 548
				".ser";
549
 
550
			this.enumValues = 
551
				(Map<Long, EnumValue>) DBUtils.read(dbFile);
552
		}
553
 
554
		return this.enumValues;
555
	}
19 naveen 556
 
24 naveen 557
	/**
49 naveen 558
	 * Resolves Enum value ID into EnumValue object
24 naveen 559
	 * 
560
	 * @param enumValueID
561
	 * @return EnumValue
562
	 * @throws Exception
563
	 */
564
	public EnumValue getEnumValue(long enumValueID) throws Exception {
565
		// Initialise
566
		if(this.enumValues == null) {
567
			this.getEnumValues();
568
		}
569
 
570
		return this.enumValues.get(new Long(enumValueID));
571
	}
62 naveen 572
 
573
	/**
574
	 * Returns all FacetDefinition objects in the database
575
	 * 
576
	 * @return Map Null if facet definitions are not imported into definitions 
577
	 * db (serialized java objects)
578
	 * 
579
	 * @throws Exception 
580
	 */
581
	@SuppressWarnings("unchecked")
582
	public Map<Long, FacetDefinition> getFacetDefinitions() throws Exception {
583
 
584
		// De-serialize
585
		if(this.facetDefinitions == null) {
70 naveen 586
			String dbFile = Utils.DEFINITIONS_DB_PATH + "facetdefinitions" + 
63 naveen 587
				".ser";
62 naveen 588
 
589
			this.facetDefinitions = 
590
				(Map<Long, FacetDefinition>) DBUtils.read(dbFile);
591
		}
592
 
593
		return this.facetDefinitions;
594
	}
595
 
596
	/**
597
	 * Resolves Facet Definition ID into FacetDefinition object
598
	 * 
599
	 * @param facetDefinitionID
600
	 * @return FacetDefinition
601
	 * @throws Exception
602
	 */
603
	public FacetDefinition getFacetDefinition(long facetDefinitionID) 
604
		throws Exception {
605
 
606
		if(this.facetDefinitions == null) {
607
			this.getFacetDefinitions();
608
		}
609
 
610
		return this.facetDefinitions.get(new Long(facetDefinitionID));
611
	}
612
 
613
	/**
614
	 * Utility method to get Expanded version of ExpandedFacetDefinition object 
615
	 * 
616
	 * @param facetDefinitionID
617
	 * @return ExpandedFacetDefinition
618
	 * @throws Exception
619
	 */
620
	public ExpandedFacetDefinition getExpandedFacetDefinition(
621
			long facetDefinitionID) throws Exception {
622
 
623
		FacetDefinition facetDefinition = 
624
			this.getFacetDefinition(facetDefinitionID);
625
 
626
		ExpandedFacetDefinition expFacetDefinition = 
627
			new ExpandedFacetDefinition(facetDefinition);
628
 
629
		return expFacetDefinition;
630
	}
631
 
632
	/**
633
	 * Returns all CategoryFacetDefinition objects in the database
634
	 * 
635
	 * @return Map Null if category facet definitions are not imported into 
636
	 * definitions db (serialized java objects)
637
	 * 
638
	 * @throws Exception 
639
	 */
640
	@SuppressWarnings("unchecked")
641
	public Map<Long, CategoryFacetDefinition> getCategoryFacetDefinitions() 
642
		throws Exception {
643
 
644
		// De-serialize
645
		if(this.categoryFacetDefinitions == null) {
70 naveen 646
			String dbFile = Utils.DEFINITIONS_DB_PATH + 
81 naveen 647
				"categoryfacetdefinitions.ser";
62 naveen 648
 
649
			this.categoryFacetDefinitions = 
650
				(Map<Long, CategoryFacetDefinition>) DBUtils.read(dbFile);
651
		}
652
 
653
		return this.categoryFacetDefinitions;
654
	}
655
 
656
	/**
657
	 * Resolves Category-Facet Definition ID into CategoryFacetDefinition object
658
	 * 
659
	 * @param categoryID
660
	 * @return CategoryFacetDefinition
661
	 * @throws Exception
662
	 */
663
	public CategoryFacetDefinition getCategoryFacetDefinition(
664
			long categoryID) throws Exception {
665
 
666
		if(this.categoryFacetDefinitions == null) {
667
			this.getCategoryFacetDefinitions();
668
		}
669
 
670
		return this.categoryFacetDefinitions.get(
671
				new Long(categoryID));
672
	}
673
 
674
	/**
675
	 * Utility method to get Expanded version of CategoryFacetDefinition object 
676
	 * 
677
	 * @param categoryID
678
	 * @return ExpandedCategoryFacetDefinition
679
	 * @throws Exception
680
	 */
681
	public ExpandedCategoryFacetDefinition getExpandedCategoryFacetDefinition(
682
			long categoryID) throws Exception  {
683
		CategoryFacetDefinition categoryFacetDef = 
684
			this.getCategoryFacetDefinition(categoryID);
685
 
686
		ExpandedCategoryFacetDefinition expCategoryFacetDef = 
687
			new ExpandedCategoryFacetDefinition(categoryFacetDef);
688
 
689
		return expCategoryFacetDef;
690
	}
691
 
692
	/**
693
	 * Returns all IR Data RuleDefintion objects in the database
694
	 * 
695
	 * @return Map Null if IR data rule definitions are not imported into 
696
	 * definitions db (serialized java objects)
697
	 * 
698
	 * @throws Exception 
699
	 */
700
	@SuppressWarnings("unchecked")
701
	public Map<Long, RuleDefinition> getIrDataRuleDefinitions() 
702
		throws Exception {
703
 
704
		// De-serialize
705
		if(this.irDataRuleDefinitions == null) {
70 naveen 706
			String dbFile = Utils.DEFINITIONS_DB_PATH + "irdatarules" + ".ser";
62 naveen 707
 
708
			this.irDataRuleDefinitions = 
709
				(Map<Long, RuleDefinition>) DBUtils.read(dbFile);
710
		}
711
 
712
		return this.irDataRuleDefinitions;
713
	}
714
 
715
	/**
716
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
717
	 * 
718
	 * @param irDataRuleDefinitionID
719
	 * @return RuleDefinition
720
	 * @throws Exception
721
	 */
722
	public RuleDefinition getIrDataRuleDefinition(
723
			long irDataRuleDefinitionID) throws Exception {
724
 
725
		if(this.irDataRuleDefinitions == null) {
726
			this.getIrDataRuleDefinitions();
727
		}
728
 
729
		return this.irDataRuleDefinitions.get(new Long(irDataRuleDefinitionID));
730
	}
731
 
732
	/**
733
	 * Returns all IR Meta Data RuleDefintion objects in the database
734
	 * 
735
	 * @return Map Null if IR meta-data rule definitions are not imported into 
736
	 * definitions db (serialized java objects)
737
	 * 
738
	 * @throws Exception 
739
	 */
740
	@SuppressWarnings("unchecked")
741
	public Map<Long, RuleDefinition> getIrMetaDataRuleDefinitions() 
742
		throws Exception {
743
 
744
		// De-serialize
745
		if(this.irMetaDataRuleDefinitions == null) {
70 naveen 746
			String dbFile = Utils.DEFINITIONS_DB_PATH + "irmetadatarules" + 
747
				".ser";
62 naveen 748
 
749
			this.irMetaDataRuleDefinitions = 
750
				(Map<Long, RuleDefinition>) DBUtils.read(dbFile);
751
		}
752
 
753
		return this.irMetaDataRuleDefinitions;
754
	}
755
 
756
	/**
757
	 * Resolves IR Meta Data Rule Definition ID into RuleDefinition object
758
	 * 
759
	 * @param irMetaDataRuleDefinitionID
760
	 * @return RuleDefinition
761
	 * @throws Exception
762
	 */
763
	public RuleDefinition getIrMetaDataRuleDefinition(
764
			long irMetaDataRuleDefinitionID) throws Exception {
765
 
766
		if(this.irMetaDataRuleDefinitions == null) {
767
			this.getIrMetaDataRuleDefinitions();
768
		}
769
 
770
		return this.irMetaDataRuleDefinitions.get(
771
				new Long(irMetaDataRuleDefinitionID));
772
	}
70 naveen 773
 
774
	/**
775
	 * Returns all Comparison RuleDefintion objects in the database
776
	 * 
777
	 * @return Map Null if Comparison rule definitions are not imported into 
778
	 * definitions db (serialized java objects)
779
	 * 
780
	 * @throws Exception 
781
	 */
782
	@SuppressWarnings("unchecked")
783
	public Map<Long, CMPRuleDefinition> getComparisonRuleDefinitions() 
784
		throws Exception {
785
 
786
		// De-serialize
787
		if(this.cmpRuleDefinitions == null) {
788
			String dbFile = Utils.DEFINITIONS_DB_PATH + "comparisonrules" + 
789
				".ser";
790
 
791
			this.cmpRuleDefinitions = 
792
				(Map<Long, CMPRuleDefinition>) DBUtils.read(dbFile);
793
		}
794
 
795
		return this.cmpRuleDefinitions;
796
	}
797
 
798
	/**
799
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
800
	 * 
801
	 * @param cmpRuleDefinitionID
802
	 * @return CMPRuleDefinition
803
	 * @throws Exception
804
	 */
805
	public CMPRuleDefinition getComparisonRuleDefinition(
806
			long cmpRuleDefinitionID) throws Exception {
807
 
808
		if(this.cmpRuleDefinitions == null) {
809
			this.getComparisonRuleDefinitions();
810
		}
811
 
812
		return this.cmpRuleDefinitions.get(new Long(cmpRuleDefinitionID));
813
	}
814
 
815
 
816
	/**
817
	 * Returns all ComparisonSlideRuleDefintion objects in the database
818
	 * 
819
	 * @return Map Null if Comparison slide-rule definitions are not imported 
820
	 * into definitions db (serialized java objects)
821
	 * 
822
	 * @throws Exception 
823
	 */
824
	@SuppressWarnings("unchecked")
825
	public Map<Long, CMPSlideRuleDefinition> getComparisonSlideRuleDefinitions() 
826
		throws Exception {
827
 
828
		// De-serialize
829
		if(this.cmpSlideRuleDefinitions == null) {
830
			String dbFile = Utils.DEFINITIONS_DB_PATH +	
831
				"comparisondefinitions.ser";
71 naveen 832
			Utils.info("dbFile=" + dbFile);
70 naveen 833
 
834
			this.cmpSlideRuleDefinitions = 
835
				(Map<Long, CMPSlideRuleDefinition>) DBUtils.read(dbFile);
71 naveen 836
 
837
			//Utils.info("this.cmpSlideRuleDefinitions=" +
838
			//		this.cmpSlideRuleDefinitions);
70 naveen 839
		}
840
 
841
		return this.cmpSlideRuleDefinitions;
842
	}
843
 
844
	/**
845
	 * Resolves Category ID into List of CMPSlideRuleDefinition object
846
	 * 
847
	 * @param categoryID
848
	 * @return List<CMPSlideRuleDefinition> 
849
	 * @throws Exception
850
	 */
851
	public CMPSlideRuleDefinition getComparisonSlideRuleDefinition(
852
			long slideDefinitionID) throws Exception {
853
 
854
		if(this.cmpSlideRuleDefinitions == null) {
855
			this.getComparisonSlideRuleDefinitions();
856
		}
857
 
858
		return this.cmpSlideRuleDefinitions.get(new Long(slideDefinitionID));
859
	}
860
 
861
 
862
	/**
863
	 * Resolves Slide Definition ID into ExpandedCMPSlideRuleDefinition object
864
	 * 
865
	 * @param categoryID
866
	 * @return ExpandedCMPSlideRuleDefinition 
867
	 * @throws Exception
868
	 */
869
	public ExpandedCMPSlideRuleDefinition
870
		getExpandedComparisonSlideRuleDefinition(long slideDefinitionID) 
871
		throws Exception {
71 naveen 872
		Utils.info("slideDefinitionID=" + slideDefinitionID);
70 naveen 873
 
874
		CMPSlideRuleDefinition cmpSlideRuleDef = 
875
			this.getComparisonSlideRuleDefinition(slideDefinitionID);
876
 
71 naveen 877
		if(cmpSlideRuleDef == null) {
878
			return null;
879
		}
880
 
70 naveen 881
		ExpandedCMPSlideRuleDefinition expDef = 
882
			new ExpandedCMPSlideRuleDefinition(cmpSlideRuleDef);
883
 
884
		return expDef;
885
	}
72 naveen 886
 
70 naveen 887
 
72 naveen 888
	/**
889
	 * Returns all ComparisonSlideRuleDefintion objects in the database
890
	 * 
891
	 * @return Map Null if Comparison slide-rule definitions are not imported 
892
	 * into definitions db (serialized java objects)
893
	 * 
894
	 * @throws Exception 
895
	 */
896
	@SuppressWarnings("unchecked")
897
	public Map<Long, List<CMPBucketDefinition>> getComparisonBucketDefinitions() 
898
		throws Exception {
899
 
900
		// De-serialize
901
		if(this.cmpBucketDefinitions == null) {
902
			String dbFile = Utils.DEFINITIONS_DB_PATH +	"comparisonbuckets.ser";
903
			Utils.info("dbFile=" + dbFile);
904
 
905
			this.cmpBucketDefinitions = 
906
				(Map<Long, List<CMPBucketDefinition>>) DBUtils.read(dbFile);
907
		}
908
 
909
		return this.cmpBucketDefinitions;
910
	}
911
 
912
	/**
913
	 * Resolves Category ID into List of CMPBucketDefinition object
914
	 * 
915
	 * @param categoryID
916
	 * @return List<CMPBucketDefinition> 
917
	 * @throws Exception
918
	 */
919
	public List<CMPBucketDefinition> getComparisonBucketDefinitions(
920
			long categoryID) throws Exception {
921
 
922
		if(this.cmpBucketDefinitions == null) {
923
			this.getComparisonBucketDefinitions();
924
		}
925
 
926
		return this.cmpBucketDefinitions.get(new Long(categoryID));
927
	}
928
 
929
	/**
930
	 * Resolve comparison bucket name for a slide in a particular category
931
	 * 
932
	 * @param categoryID
933
	 * @param slideDefintionID
934
	 * @return Bucket Name if found else Null
935
	 * @throws Exception 
936
	 */
937
	public String getComparisonBucketName(long categoryID, 
938
			long slideDefinitionID) throws Exception {
939
		List<CMPBucketDefinition> cmpBuckets = 
940
			this.getComparisonBucketDefinitions(categoryID);
941
 
942
		for (CMPBucketDefinition cmpBucket : cmpBuckets) {
943
			List<Long> slideDefinitionIDs = cmpBucket.getSlideDefinitionIDs();
944
 
945
			if(slideDefinitionIDs.contains(new Long(slideDefinitionID))) {
946
				return cmpBucket.getName();
947
			}
948
		}
949
 
950
		return null;
951
	}
10 shop2020 952
}