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;
199 naveen 10
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
64 naveen 11
import in.shop2020.util.DBUtils;
70 naveen 12
import in.shop2020.util.Utils;
17 naveen 13
 
457 rajveer 14
import java.io.File;
10 shop2020 15
import java.io.Serializable;
18 naveen 16
import java.util.ArrayList;
17
import java.util.Iterator;
18
import java.util.List;
10 shop2020 19
import java.util.Map;
20
 
21
/**
49 naveen 22
 * Single point of access to all definition objects
23
 * 
10 shop2020 24
 * @author naveen
25
 *
26
 */
27
public class DefinitionsContainer implements Serializable {
28
 
41 naveen 29
	/** 
10 shop2020 30
	 * 
31
	 */
32
	private static final long serialVersionUID = 1L;
49 naveen 33
 
34
	/**
35
	 * Hashtable of Category ID to Category object
36
	 */
10 shop2020 37
	private Map<Long, Category> categories;
49 naveen 38
 
39
	/**
40
	 * Hashtable of Slide ID to SlideDefinition object
41
	 */
10 shop2020 42
	private Map<Long, SlideDefinition> slideDefinitions;
49 naveen 43
 
44
	/**
45
	 * Hashtable of Feature Definition ID to FeatureDefinition object
46
	 */
10 shop2020 47
	private Map<Long, FeatureDefinition> featureDefinitions;
49 naveen 48
 
49
	/**
50
	 * Hashtable of Datatype Definition ID to DatatypeDefinition object
51
	 */
10 shop2020 52
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
49 naveen 53
 
54
	/**
55
	 * Hashtable of Enum value ID to EnumValue object
56
	 */
24 naveen 57
	private Map<Long, EnumValue> enumValues;
49 naveen 58
 
59
	/**
60
	 * Hashtable of Unit ID to Unit object
61
	 */
10 shop2020 62
	private Map<Long, Unit> units;
63
 
64
	/**
62 naveen 65
	 * Hashtable of Facet Definition ID to FacetDefinition object
66
	 */
67
	private Map<Long, FacetDefinition> facetDefinitions;
68
 
69
	/**
70
	 * Hashtable of Category Facet Definition ID to CategoryFacetDefinition 
71
	 * object
72
	 */
73
	private Map<Long, CategoryFacetDefinition> categoryFacetDefinitions;
74
 
75
	/**
76
	 * Hashtable of IR Data Rule ID to RuleDefinition object
77
	 */
78
	private Map<Long, RuleDefinition> irDataRuleDefinitions;	
79
 
80
	/**
81
	 * Hashtable of IR Meta Data Rule ID to RuleDefinition object
82
	 */
83
	private Map<Long, RuleDefinition> irMetaDataRuleDefinitions;
84
 
85
 
86
	/**
70 naveen 87
	 * Hashtable of Comparison Rule ID to CMPRuleDefinition object
88
	 */
89
	private Map<Long, CMPRuleDefinition> cmpRuleDefinitions;	
90
 
91
	/**
92
	 * Hashtable of SlideDefinition ID to CMPSlideRuleDefinition object
93
	 */
94
	private Map<Long, CMPSlideRuleDefinition> cmpSlideRuleDefinitions;
95
 
96
	/**
72 naveen 97
	 * Hashtable of Category ID to list of CMPBucketDefinition object
98
	 */
99
	private Map<Long, List<CMPBucketDefinition>> cmpBucketDefinitions;
102 naveen 100
 
101
	/**
102
	 * Hashtable of feature definition ID to normalization rule definition ID
103
	 */
104
	private Map<Long, RuleDefinition> normalizationRuleDefinitions;
199 naveen 105
 
106
	/**
107
	 * Hashtable of feature definition ID to normalization rule definition ID
108
	 */
109
	private Map<Long, List<Long>> categorySlideSequence;
72 naveen 110
 
111
	/**
49 naveen 112
	 * Empty constructor. Data structures are initialised as needed
10 shop2020 113
	 */
114
	public DefinitionsContainer() {
17 naveen 115
		// Lazy initialization
10 shop2020 116
	}
117
 
118
	/**
199 naveen 119
	 * Returns Slide sequence for a category in the database
120
	 * 
121
	 * @return Map Null if Category-Slide definitions are not imported into 
122
	 * definitions db 
123
	 * (serialized java objects)
124
	 * 
125
	 * @throws Exception 
126
	 */
127
	@SuppressWarnings("unchecked")
128
	public Map<Long, List<Long>> getCategorySlideSequence() throws Exception {		
129
		// De-serialize
130
		if(this.categorySlideSequence == null) {
457 rajveer 131
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "categoryslidesequence"+
199 naveen 132
				".ser";
133
 
134
			this.categorySlideSequence = (Map<Long, List<Long>>) 
135
				DBUtils.read(dbFile);
136
		}
137
 
138
		return this.categorySlideSequence;
139
	}
140
 
141
	/**
142
	 * Given a category ID, returns all slide definition IDs in sequence 
143
	 * provided by content editor
144
	 * 
145
	 * @param categoryID
146
	 * @return List of Slide Definition IDs
147
	 * @throws Exception
148
	 */
149
	public List<Long> getCategorySlideSequence(long categoryID) 
150
		throws Exception {	
151
		this.getCategorySlideSequence();
152
 
153
		return this.categorySlideSequence.get(new Long(categoryID));
154
	}
155
 
156
	/**
49 naveen 157
	 * Returns all Unit objects in the database
10 shop2020 158
	 * 
49 naveen 159
	 * @return Map Null if units are not imported into definitions db 
160
	 * (serialized java objects)
161
	 * 
18 naveen 162
	 * @throws Exception 
10 shop2020 163
	 */
18 naveen 164
	@SuppressWarnings("unchecked")
165
	public Map<Long, Unit> getUnits() throws Exception {		
17 naveen 166
		// De-serialize
167
		if(this.units == null) {
457 rajveer 168
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "units" + ".ser";
18 naveen 169
 
170
			this.units = (Map<Long, Unit>) DBUtils.read(dbFile);
17 naveen 171
		}
18 naveen 172
 
10 shop2020 173
		return this.units;
174
	}
175
 
176
	/**
49 naveen 177
	 * Resolves Unit ID into Unit object
10 shop2020 178
	 * 
49 naveen 179
	 * @param unitID Unit ID
10 shop2020 180
	 * @return Unit
18 naveen 181
	 * @throws Exception 
10 shop2020 182
	 */
18 naveen 183
	public Unit getUnit(long unitID) throws Exception {		
184
		// Initialize 
185
		if(this.units == null) {
186
			this.getUnits();
187
		}
17 naveen 188
 
10 shop2020 189
		return this.units.get(new Long(unitID));
190
	}
191
 
192
	/**
49 naveen 193
	 * Returns all DatatypeDefintion object in database
194
	 * 
195
	 * @return the datatypeDefinitions List of DatatypeDefinition objects
18 naveen 196
	 * @throws Exception 
10 shop2020 197
	 */
18 naveen 198
	@SuppressWarnings("unchecked")
199
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() 
200
		throws Exception {
201
 
202
		// De-serialize
203
		if(this.datatypeDefinitions == null) {
457 rajveer 204
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "datatypedefinitions" + 
19 naveen 205
				".ser";
18 naveen 206
 
207
			this.datatypeDefinitions = 
208
				(Map<Long, DatatypeDefinition>) DBUtils.read(dbFile);
209
		}
210
		return this.datatypeDefinitions;
10 shop2020 211
	}
18 naveen 212
 
213
	/**
49 naveen 214
	 * Resolves Datatype Definition ID into DatetypeDefinition object
18 naveen 215
	 * 
49 naveen 216
	 * @param unitID Unit ID
18 naveen 217
	 * @return Unit
218
	 * @throws Exception 
219
	 */
220
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
221
 
222
		// Initialize 
223
		if(this.datatypeDefinitions == null) {
224
			this.getDatatypeDefinitions();
225
		}
226
 
227
		return this.datatypeDefinitions.get(new Long(id));
228
	}
19 naveen 229
 
230
	/**
49 naveen 231
	 * Returns EnumValue ID for datatype definition ID and enum value string 
232
	 * to match. Match is case insensitive
19 naveen 233
	 * 
49 naveen 234
	 * @param datatypeDefID DatatypeDefinition ID
235
	 * @param value query enum value string
19 naveen 236
	 * @return long enumValueID - "-1" if not found
237
	 * @throws Exception 
238
	 */
239
	public long getEnumValueID(long datatypeDefID, String value) 
240
		throws Exception {
241
		long enumValueID = -1L;
242
 
243
		// Let the callers catch ClassCastException
244
		EnumDefinition enumDef = 
245
			(EnumDefinition)this.getDatatypeDefinition(datatypeDefID);
246
 
24 naveen 247
		List<EnumValue> enumValues = enumDef.getEnumValues();
19 naveen 248
		for(EnumValue enumValue : enumValues) {
249
			if(value.equalsIgnoreCase(enumValue.getValue())) {
250
				enumValueID = enumValue.getID();
251
				break;
252
			}
253
		}
254
 
255
		return enumValueID;
256
	}
17 naveen 257
 
10 shop2020 258
	/**
49 naveen 259
	 * Returns all category objects in the database
260
	 * 
10 shop2020 261
	 * @return the categories
17 naveen 262
	 * @throws Exception 
10 shop2020 263
	 */
17 naveen 264
	@SuppressWarnings("unchecked")
265
	public Map<Long, Category> getCategories() throws Exception {
266
 
267
		// De-serialize
268
		if(this.categories == null) {
457 rajveer 269
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "categories" + ".ser";
17 naveen 270
 
271
			this.categories = (Map<Long, Category>) DBUtils.read(dbFile);
272
		}
273
		return this.categories;
10 shop2020 274
	}
17 naveen 275
 
10 shop2020 276
	/**
49 naveen 277
	 * Resolves Category ID into Category object
17 naveen 278
	 * 
49 naveen 279
	 * @param categoryID Category ID
17 naveen 280
	 * @return Category
281
	 * @throws Exception 
10 shop2020 282
	 */
17 naveen 283
	public Category getCategory(long categoryID) throws Exception {
284
 
18 naveen 285
		// Initialize 
17 naveen 286
		if(this.categories == null) {
287
			this.getCategories();
288
		}
289
 
290
		return this.categories.get(new Long(categoryID));
10 shop2020 291
	}
17 naveen 292
 
10 shop2020 293
	/**
49 naveen 294
	 * Returns expanded Category object. All numeric identifiers are resolved 
295
	 * into detailed objects
18 naveen 296
	 * 
297
	 * @param categoryID
45 naveen 298
	 * @return ExpandedCategory
299
	 * @throws Exception
300
	 */
301
	public ExpandedCategory getExpandedCategory(long categoryID) 
302
		throws Exception {
303
		Category category = this.getCategory(categoryID);
304
 
305
		ExpandedCategory expCategory = new ExpandedCategory(category);
306
 
307
		return expCategory;
308
	}
309
 
310
	/**
49 naveen 311
	 * Returns all children categories for a Category ID
45 naveen 312
	 * 
313
	 * @param categoryID
49 naveen 314
	 * @return List<Category> Children Categories
34 naveen 315
	 * @throws Exception
316
	 */
317
	public List<Category> getChildrenCategories(long categoryID) 
318
		throws Exception {
319
 
320
		// Initialize 
321
		if(this.categories == null) {
322
			this.getCategories();
323
		}
324
 
325
		return this.categories.get(new Long(categoryID)).getChildrenCategory();
326
	}
49 naveen 327
 
34 naveen 328
	/**
49 naveen 329
	 * Returns all CategorySlideDefinition objects for a Category ID
34 naveen 330
	 * 
49 naveen 331
	 * @param categoryID Category ID
18 naveen 332
	 * @return List<CategorySlideDefinition> 
333
	 * @throws Exception 
334
	 */
335
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
336
			long categoryID) throws Exception {
337
		Category category = this.getCategory(categoryID);
338
 
339
		return category.getCategorySlideDefintions();
340
	}
341
 
342
	/**
49 naveen 343
	 * Returns All SlideDefinition objects in database
344
	 * 
10 shop2020 345
	 * @return the slideDefinitions
18 naveen 346
	 * @throws Exception 
10 shop2020 347
	 */
18 naveen 348
	@SuppressWarnings("unchecked")
349
	public Map<Long, SlideDefinition> getSlideDefinitions() throws Exception {
350
 
351
		// De-serialize
352
		if(this.slideDefinitions == null) {
457 rajveer 353
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "slidedefinitions" + 
18 naveen 354
				".ser";
355
 
356
			this.slideDefinitions = 
357
				(Map<Long, SlideDefinition>) DBUtils.read(dbFile);
358
		}
359
		return this.slideDefinitions;
10 shop2020 360
	}
18 naveen 361
 
362
	/**
49 naveen 363
	 * Resolves SlideDefinition ID into SlideDefinition object
18 naveen 364
	 * 
365
	 * @param id
366
	 * @return SlideDefinition
367
	 * @throws Exception
368
	 */
369
	public SlideDefinition getSlideDefinition(long id) throws Exception {
370
 
371
		// Initialize 
372
		if(this.slideDefinitions == null) {
373
			this.getSlideDefinitions();
374
		}
375
 
376
		return this.slideDefinitions.get(new Long(id));
377
	}
378
 
379
	/**
199 naveen 380
	 * 
381
	 * @param slideID
382
	 * @return ExpandedSlideDefinition 
383
	 * @throws Exception 
384
	 */
385
	public ExpandedSlideDefinition getExpandedSlideDefinition(long slideID) 
386
		throws Exception {
387
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
388
 
389
		return new ExpandedSlideDefinition(slideDef);
390
	}
391
 
392
	/**
49 naveen 393
	 * Returns SlideDefinition objects for a category and matching slide label
18 naveen 394
	 * 
19 naveen 395
	 * @param label
396
	 * @return List<SlideDefinition>
397
	 * @throws Exception
398
	 */
32 naveen 399
	public List<SlideDefinition> getSlideDefinitions(long categoryID, 
400
			String label) throws Exception {
401
 
402
		// RE-VISIT
403
		// May be we need a new data structure, category id to slide definitions
404
		// for now
405
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
19 naveen 406
 
32 naveen 407
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
408
				categoryID);
409
 
410
		for(CategorySlideDefinition csDef : csDefs) {
411
			SlideDefinition sDef = this.getSlideDefinition(
412
					csDef.getSlideDefintionID());
413
 
414
			if(sDef.getLabel().equalsIgnoreCase(label)) {
415
				matchingSlides.add(sDef);
416
			}
19 naveen 417
		}
418
 
32 naveen 419
		return matchingSlides;
420
	}
421
 
422
	/**
49 naveen 423
	 * Resolves Category ID into Category object
32 naveen 424
	 * 
425
	 * @param categoryID
49 naveen 426
	 * @return List<SlideDefinition> 
32 naveen 427
	 * @throws Exception
428
	 */
429
	public List<SlideDefinition> getSlideDefinitions(long categoryID) 
430
		throws Exception {
431
 
432
		// RE-VISIT
433
		// May be we need a new data structure, category id to slide definitions
434
		// for now
19 naveen 435
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
32 naveen 436
 
437
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
438
				categoryID);
439
 
440
		for(CategorySlideDefinition csDef : csDefs) {
441
			SlideDefinition sDef = this.getSlideDefinition(
442
					csDef.getSlideDefintionID());
19 naveen 443
 
32 naveen 444
			matchingSlides.add(sDef);
19 naveen 445
		}
446
 
447
		return matchingSlides;
448
	}
49 naveen 449
 
19 naveen 450
	/**
49 naveen 451
	 * Returns list of SlideDefinition objects for a category and editorial 
452
	 * importance value
19 naveen 453
	 * 
18 naveen 454
	 * @param categoryID
455
	 * @param EditorialImportance imp
456
	 * @return List<SlideDefinition>
457
	 * @throws Exception 
458
	 */
459
	public List<SlideDefinition> getSlides(long categoryID, 
460
			EditorialImportance imp) 
461
		throws Exception {
462
 
463
		List<CategorySlideDefinition> catSlideDefs = 
464
			this.getCategorySlideDefinitions(categoryID);
465
 
466
		Iterator<CategorySlideDefinition> itCatSlideDefs = 
467
			catSlideDefs.iterator();
468
 
469
		List<SlideDefinition> slideDefs = new ArrayList<SlideDefinition>();
470
		while(itCatSlideDefs.hasNext()) {
471
			CategorySlideDefinition catSlideDef = itCatSlideDefs.next();
472
			if(catSlideDef.getEditorialImportance() == imp) {
473
				long slideDefID = catSlideDef.getSlideDefintionID();
474
				slideDefs.add(this.getSlideDefinition(slideDefID));
475
			}
476
		}
477
		return slideDefs;
478
	}
479
 
480
	/**
49 naveen 481
	 * Returns all FeatureDefinition object in database
18 naveen 482
	 * 
483
	 * @return Map<Long, FeatureDefinition>
484
	 * @throws Exception
485
	 */
486
	@SuppressWarnings("unchecked")
487
	public Map<Long, FeatureDefinition> getFeatureDefinitions() 
488
		throws Exception {
489
 
490
		// De-serialize
491
		if(this.featureDefinitions == null) {
457 rajveer 492
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "featuredefinitions" + 
18 naveen 493
				".ser";
494
 
495
			this.featureDefinitions = 
496
				(Map<Long, FeatureDefinition>) DBUtils.read(dbFile);
497
		}
498
		return this.featureDefinitions;
499
	}
19 naveen 500
 
10 shop2020 501
	/**
49 naveen 502
	 * Returns all FeatureDefinition objects for a slide
18 naveen 503
	 * 
19 naveen 504
	 * @param slideID
505
	 * @return List<FeatureDefinition> 
506
	 * @throws Exception
507
	 */
508
	public List<FeatureDefinition> getFeatureDefinitions(long slideID) 
509
		throws Exception {
510
		List<FeatureDefinition> featureDefs = 
511
			new ArrayList<FeatureDefinition>();
512
 
513
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
514
		List<SlideFeatureDefinition> slideFeatureDefs = 
515
			slideDef.getSlideFeatureDefinitions();
516
 
517
		for(int i=0; i<slideFeatureDefs.size(); i++) {
518
			featureDefs.add(this.getFeatureDefinition(
519
					slideFeatureDefs.get(i).getFeatureDefintionID()));
520
		}
521
 
522
		return featureDefs;
523
	}
524
 
525
	/**
49 naveen 526
	 * Returns list of FeatureDefinition objects for a slide given editorial 
527
	 * importance
19 naveen 528
	 * 
529
	 * @param slideID
49 naveen 530
	 * @param imp Editorial Importance enum object
19 naveen 531
	 * @return List<FeatureDefinition>
532
	 * @throws Exception
533
	 */
534
	public List<FeatureDefinition> getFeatureDefinitions(long slideID, 
535
			EditorialImportance imp)  throws Exception {
536
		List<FeatureDefinition> featureDefs = 
537
			new ArrayList<FeatureDefinition>();
538
 
539
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
540
		List<SlideFeatureDefinition> slideFeatureDefs = 
541
			slideDef.getSlideFeatureDefinitions();
542
 
543
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
544
			if(slideFeatureDef.getEditorialImportance() == imp) {
545
				featureDefs.add(this.getFeatureDefinition(
546
						slideFeatureDef.getFeatureDefintionID()));
547
			}
548
		}
549
 
550
		return featureDefs;
551
	}
552
 
553
	/**
49 naveen 554
	 * Resolves Feature Definition ID into FeatureDefinition object
19 naveen 555
	 * 
49 naveen 556
	 * @param id Feature Definition ID 
19 naveen 557
	 * @return FeatureDefinition
18 naveen 558
	 * @throws Exception
10 shop2020 559
	 */
18 naveen 560
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
561
 
562
		// Initialize 
563
		if(this.featureDefinitions == null) {
564
			this.getFeatureDefinitions();
565
		}
566
 
567
		return this.featureDefinitions.get(new Long(id));
568
	}	
19 naveen 569
 
570
	/**
49 naveen 571
	 * Returns matching FeatureDefinition object for slide ID and feature label.
572
	 * Label matching is case insensitive.
19 naveen 573
	 * 
49 naveen 574
	 * @param slideID Slide ID
575
	 * @param featureLabel label to match, case is ignored
19 naveen 576
	 * @return FeatureDefinition 
577
	 * @throws Exception
578
	 */
579
	public FeatureDefinition getFeatureDefinition(long slideID, 
580
			String featureLabel) throws Exception {
581
		FeatureDefinition featureDef = null;
582
 
583
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
584
		for(SlideFeatureDefinition slideFeatureDef : 
585
			slideDef.getSlideFeatureDefinitions()) {
586
 
587
			long featureDefID = slideFeatureDef.getFeatureDefintionID();
588
 
589
			FeatureDefinition thisFeatureDef = this.getFeatureDefinition(
590
					featureDefID);
591
 
28 naveen 592
			if(featureLabel.equalsIgnoreCase(thisFeatureDef.getLabel())) {
19 naveen 593
				featureDef = thisFeatureDef;
594
			}
595
		}
596
 
597
		return featureDef;
598
	}
24 naveen 599
 
600
	/**
49 naveen 601
	 * Returns all EnumValue objects in the database
602
	 * 
24 naveen 603
	 * @return the enumValues
604
	 * @throws Exception 
605
	 */
606
	@SuppressWarnings("unchecked")
607
	public Map<Long, EnumValue> getEnumValues() throws Exception {
608
		// De-serialise
609
		if(this.enumValues == null) {
457 rajveer 610
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "enumvalues" + 
24 naveen 611
				".ser";
612
 
613
			this.enumValues = 
614
				(Map<Long, EnumValue>) DBUtils.read(dbFile);
615
		}
616
 
617
		return this.enumValues;
618
	}
19 naveen 619
 
24 naveen 620
	/**
49 naveen 621
	 * Resolves Enum value ID into EnumValue object
24 naveen 622
	 * 
623
	 * @param enumValueID
624
	 * @return EnumValue
625
	 * @throws Exception
626
	 */
627
	public EnumValue getEnumValue(long enumValueID) throws Exception {
628
		// Initialise
629
		if(this.enumValues == null) {
630
			this.getEnumValues();
631
		}
632
 
633
		return this.enumValues.get(new Long(enumValueID));
634
	}
62 naveen 635
 
636
	/**
637
	 * Returns all FacetDefinition objects in the database
638
	 * 
639
	 * @return Map Null if facet definitions are not imported into definitions 
640
	 * db (serialized java objects)
641
	 * 
642
	 * @throws Exception 
643
	 */
644
	@SuppressWarnings("unchecked")
645
	public Map<Long, FacetDefinition> getFacetDefinitions() throws Exception {
646
 
647
		// De-serialize
648
		if(this.facetDefinitions == null) {
457 rajveer 649
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "facetdefinitions" + 
63 naveen 650
				".ser";
62 naveen 651
 
652
			this.facetDefinitions = 
653
				(Map<Long, FacetDefinition>) DBUtils.read(dbFile);
654
		}
655
 
656
		return this.facetDefinitions;
657
	}
658
 
659
	/**
660
	 * Resolves Facet Definition ID into FacetDefinition object
661
	 * 
662
	 * @param facetDefinitionID
663
	 * @return FacetDefinition
664
	 * @throws Exception
665
	 */
666
	public FacetDefinition getFacetDefinition(long facetDefinitionID) 
667
		throws Exception {
668
 
669
		if(this.facetDefinitions == null) {
670
			this.getFacetDefinitions();
671
		}
672
 
673
		return this.facetDefinitions.get(new Long(facetDefinitionID));
674
	}
675
 
676
	/**
677
	 * Utility method to get Expanded version of ExpandedFacetDefinition object 
678
	 * 
679
	 * @param facetDefinitionID
680
	 * @return ExpandedFacetDefinition
681
	 * @throws Exception
682
	 */
683
	public ExpandedFacetDefinition getExpandedFacetDefinition(
684
			long facetDefinitionID) throws Exception {
685
 
686
		FacetDefinition facetDefinition = 
687
			this.getFacetDefinition(facetDefinitionID);
688
 
689
		ExpandedFacetDefinition expFacetDefinition = 
690
			new ExpandedFacetDefinition(facetDefinition);
691
 
692
		return expFacetDefinition;
693
	}
694
 
695
	/**
696
	 * Returns all CategoryFacetDefinition objects in the database
697
	 * 
698
	 * @return Map Null if category facet definitions are not imported into 
699
	 * definitions db (serialized java objects)
700
	 * 
701
	 * @throws Exception 
702
	 */
703
	@SuppressWarnings("unchecked")
704
	public Map<Long, CategoryFacetDefinition> getCategoryFacetDefinitions() 
705
		throws Exception {
706
 
707
		// De-serialize
708
		if(this.categoryFacetDefinitions == null) {
457 rajveer 709
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + 
81 naveen 710
				"categoryfacetdefinitions.ser";
62 naveen 711
 
712
			this.categoryFacetDefinitions = 
713
				(Map<Long, CategoryFacetDefinition>) DBUtils.read(dbFile);
714
		}
715
 
716
		return this.categoryFacetDefinitions;
717
	}
718
 
719
	/**
720
	 * Resolves Category-Facet Definition ID into CategoryFacetDefinition object
721
	 * 
722
	 * @param categoryID
723
	 * @return CategoryFacetDefinition
724
	 * @throws Exception
725
	 */
726
	public CategoryFacetDefinition getCategoryFacetDefinition(
727
			long categoryID) throws Exception {
728
 
729
		if(this.categoryFacetDefinitions == null) {
730
			this.getCategoryFacetDefinitions();
731
		}
732
 
733
		return this.categoryFacetDefinitions.get(
734
				new Long(categoryID));
735
	}
736
 
737
	/**
738
	 * Utility method to get Expanded version of CategoryFacetDefinition object 
739
	 * 
740
	 * @param categoryID
741
	 * @return ExpandedCategoryFacetDefinition
742
	 * @throws Exception
743
	 */
744
	public ExpandedCategoryFacetDefinition getExpandedCategoryFacetDefinition(
745
			long categoryID) throws Exception  {
746
		CategoryFacetDefinition categoryFacetDef = 
747
			this.getCategoryFacetDefinition(categoryID);
748
 
749
		ExpandedCategoryFacetDefinition expCategoryFacetDef = 
750
			new ExpandedCategoryFacetDefinition(categoryFacetDef);
751
 
752
		return expCategoryFacetDef;
753
	}
754
 
755
	/**
756
	 * Returns all IR Data RuleDefintion objects in the database
757
	 * 
758
	 * @return Map Null if IR data rule definitions are not imported into 
759
	 * definitions db (serialized java objects)
760
	 * 
761
	 * @throws Exception 
762
	 */
763
	@SuppressWarnings("unchecked")
764
	public Map<Long, RuleDefinition> getIrDataRuleDefinitions() 
765
		throws Exception {
766
 
767
		// De-serialize
768
		if(this.irDataRuleDefinitions == null) {
457 rajveer 769
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "irdatarules" + ".ser";
62 naveen 770
 
771
			this.irDataRuleDefinitions = 
772
				(Map<Long, RuleDefinition>) DBUtils.read(dbFile);
773
		}
774
 
775
		return this.irDataRuleDefinitions;
776
	}
777
 
778
	/**
779
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
780
	 * 
781
	 * @param irDataRuleDefinitionID
782
	 * @return RuleDefinition
783
	 * @throws Exception
784
	 */
785
	public RuleDefinition getIrDataRuleDefinition(
786
			long irDataRuleDefinitionID) throws Exception {
787
 
788
		if(this.irDataRuleDefinitions == null) {
789
			this.getIrDataRuleDefinitions();
790
		}
791
 
792
		return this.irDataRuleDefinitions.get(new Long(irDataRuleDefinitionID));
793
	}
794
 
795
	/**
796
	 * Returns all IR Meta Data RuleDefintion objects in the database
797
	 * 
798
	 * @return Map Null if IR meta-data rule definitions are not imported into 
799
	 * definitions db (serialized java objects)
800
	 * 
801
	 * @throws Exception 
802
	 */
803
	@SuppressWarnings("unchecked")
804
	public Map<Long, RuleDefinition> getIrMetaDataRuleDefinitions() 
805
		throws Exception {
806
 
807
		// De-serialize
808
		if(this.irMetaDataRuleDefinitions == null) {
457 rajveer 809
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "irmetadatarules" + 
70 naveen 810
				".ser";
62 naveen 811
 
812
			this.irMetaDataRuleDefinitions = 
813
				(Map<Long, RuleDefinition>) DBUtils.read(dbFile);
814
		}
815
 
816
		return this.irMetaDataRuleDefinitions;
817
	}
818
 
819
	/**
820
	 * Resolves IR Meta Data Rule Definition ID into RuleDefinition object
821
	 * 
822
	 * @param irMetaDataRuleDefinitionID
823
	 * @return RuleDefinition
824
	 * @throws Exception
825
	 */
826
	public RuleDefinition getIrMetaDataRuleDefinition(
827
			long irMetaDataRuleDefinitionID) throws Exception {
828
 
829
		if(this.irMetaDataRuleDefinitions == null) {
830
			this.getIrMetaDataRuleDefinitions();
831
		}
832
 
833
		return this.irMetaDataRuleDefinitions.get(
834
				new Long(irMetaDataRuleDefinitionID));
835
	}
70 naveen 836
 
837
	/**
838
	 * Returns all Comparison RuleDefintion objects in the database
839
	 * 
840
	 * @return Map Null if Comparison rule definitions are not imported into 
841
	 * definitions db (serialized java objects)
842
	 * 
843
	 * @throws Exception 
844
	 */
845
	@SuppressWarnings("unchecked")
846
	public Map<Long, CMPRuleDefinition> getComparisonRuleDefinitions() 
847
		throws Exception {
848
 
849
		// De-serialize
850
		if(this.cmpRuleDefinitions == null) {
457 rajveer 851
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator + "comparisonrules" + 
70 naveen 852
				".ser";
853
 
854
			this.cmpRuleDefinitions = 
855
				(Map<Long, CMPRuleDefinition>) DBUtils.read(dbFile);
856
		}
857
 
858
		return this.cmpRuleDefinitions;
859
	}
860
 
861
	/**
862
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
863
	 * 
864
	 * @param cmpRuleDefinitionID
865
	 * @return CMPRuleDefinition
866
	 * @throws Exception
867
	 */
868
	public CMPRuleDefinition getComparisonRuleDefinition(
869
			long cmpRuleDefinitionID) throws Exception {
870
 
871
		if(this.cmpRuleDefinitions == null) {
872
			this.getComparisonRuleDefinitions();
873
		}
874
 
875
		return this.cmpRuleDefinitions.get(new Long(cmpRuleDefinitionID));
876
	}
877
 
878
 
879
	/**
880
	 * Returns all ComparisonSlideRuleDefintion objects in the database
881
	 * 
882
	 * @return Map Null if Comparison slide-rule definitions are not imported 
883
	 * into definitions db (serialized java objects)
884
	 * 
885
	 * @throws Exception 
886
	 */
887
	@SuppressWarnings("unchecked")
888
	public Map<Long, CMPSlideRuleDefinition> getComparisonSlideRuleDefinitions() 
889
		throws Exception {
890
 
891
		// De-serialize
892
		if(this.cmpSlideRuleDefinitions == null) {
457 rajveer 893
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator +	
70 naveen 894
				"comparisondefinitions.ser";
71 naveen 895
			Utils.info("dbFile=" + dbFile);
70 naveen 896
 
897
			this.cmpSlideRuleDefinitions = 
898
				(Map<Long, CMPSlideRuleDefinition>) DBUtils.read(dbFile);
71 naveen 899
 
900
			//Utils.info("this.cmpSlideRuleDefinitions=" +
901
			//		this.cmpSlideRuleDefinitions);
70 naveen 902
		}
903
 
904
		return this.cmpSlideRuleDefinitions;
905
	}
906
 
907
	/**
908
	 * Resolves Category ID into List of CMPSlideRuleDefinition object
909
	 * 
910
	 * @param categoryID
911
	 * @return List<CMPSlideRuleDefinition> 
912
	 * @throws Exception
913
	 */
914
	public CMPSlideRuleDefinition getComparisonSlideRuleDefinition(
915
			long slideDefinitionID) throws Exception {
916
 
917
		if(this.cmpSlideRuleDefinitions == null) {
918
			this.getComparisonSlideRuleDefinitions();
919
		}
920
 
921
		return this.cmpSlideRuleDefinitions.get(new Long(slideDefinitionID));
922
	}
923
 
924
 
925
	/**
926
	 * Resolves Slide Definition ID into ExpandedCMPSlideRuleDefinition object
927
	 * 
928
	 * @param categoryID
929
	 * @return ExpandedCMPSlideRuleDefinition 
930
	 * @throws Exception
931
	 */
932
	public ExpandedCMPSlideRuleDefinition
933
		getExpandedComparisonSlideRuleDefinition(long slideDefinitionID) 
934
		throws Exception {
71 naveen 935
		Utils.info("slideDefinitionID=" + slideDefinitionID);
70 naveen 936
 
937
		CMPSlideRuleDefinition cmpSlideRuleDef = 
938
			this.getComparisonSlideRuleDefinition(slideDefinitionID);
939
 
71 naveen 940
		if(cmpSlideRuleDef == null) {
941
			return null;
942
		}
943
 
70 naveen 944
		ExpandedCMPSlideRuleDefinition expDef = 
945
			new ExpandedCMPSlideRuleDefinition(cmpSlideRuleDef);
946
 
947
		return expDef;
948
	}
72 naveen 949
 
70 naveen 950
 
72 naveen 951
	/**
952
	 * Returns all ComparisonSlideRuleDefintion objects in the database
953
	 * 
954
	 * @return Map Null if Comparison slide-rule definitions are not imported 
955
	 * into definitions db (serialized java objects)
956
	 * 
957
	 * @throws Exception 
958
	 */
959
	@SuppressWarnings("unchecked")
960
	public Map<Long, List<CMPBucketDefinition>> getComparisonBucketDefinitions() 
961
		throws Exception {
962
 
963
		// De-serialize
964
		if(this.cmpBucketDefinitions == null) {
457 rajveer 965
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator +	"comparisonbuckets.ser";
72 naveen 966
			Utils.info("dbFile=" + dbFile);
967
 
968
			this.cmpBucketDefinitions = 
969
				(Map<Long, List<CMPBucketDefinition>>) DBUtils.read(dbFile);
970
		}
971
 
972
		return this.cmpBucketDefinitions;
973
	}
974
 
975
	/**
976
	 * Resolves Category ID into List of CMPBucketDefinition object
977
	 * 
978
	 * @param categoryID
979
	 * @return List<CMPBucketDefinition> 
980
	 * @throws Exception
981
	 */
982
	public List<CMPBucketDefinition> getComparisonBucketDefinitions(
983
			long categoryID) throws Exception {
984
 
985
		if(this.cmpBucketDefinitions == null) {
986
			this.getComparisonBucketDefinitions();
987
		}
988
 
989
		return this.cmpBucketDefinitions.get(new Long(categoryID));
990
	}
991
 
992
	/**
993
	 * Resolve comparison bucket name for a slide in a particular category
994
	 * 
995
	 * @param categoryID
996
	 * @param slideDefintionID
997
	 * @return Bucket Name if found else Null
998
	 * @throws Exception 
999
	 */
1000
	public String getComparisonBucketName(long categoryID, 
1001
			long slideDefinitionID) throws Exception {
1002
		List<CMPBucketDefinition> cmpBuckets = 
1003
			this.getComparisonBucketDefinitions(categoryID);
1004
 
1005
		for (CMPBucketDefinition cmpBucket : cmpBuckets) {
1006
			List<Long> slideDefinitionIDs = cmpBucket.getSlideDefinitionIDs();
1007
 
1008
			if(slideDefinitionIDs.contains(new Long(slideDefinitionID))) {
1009
				return cmpBucket.getName();
1010
			}
1011
		}
1012
 
1013
		return null;
1014
	}
83 naveen 1015
 
1016
	/**
1017
	 * Returns list of facet definition IDs for given category ID
1018
	 * 
1019
	 * @param categoryID
1020
	 * @return list of facet definition IDs
1021
	 * @throws Exception 
1022
	 */
1023
	public List<Long> getFacetDefinitionIDs(long categoryID) throws Exception {
1024
		List<Long> facetDefIDs = new ArrayList<Long>();
1025
 
1026
		CategoryFacetDefinition categoryFacetDef = 
1027
			this.getCategoryFacetDefinition(categoryID);
1028
 
1029
		List<FacetRuleDefinition> facetRuleDefs = 
1030
			categoryFacetDef.getFacetRuleDefinitions();
1031
 
1032
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1033
			facetDefIDs.add(new Long(facetRuleDef.getFacetDefinitionID()));
1034
		}
1035
 
1036
		return facetDefIDs;
1037
	}
1038
 
1039
	/**
1040
	 * Returns list of feature definition IDs for given category ID
1041
	 * 
1042
	 * @param categoryID
1043
	 * @return list of feature definition IDs
1044
	 * @throws Exception 
1045
	 */
1046
	public List<Long> getFeatureDefinitionIDs(long categoryID) 
1047
		throws Exception {
1048
 
1049
		List<Long> featureDefIDs = new ArrayList<Long>();
1050
 
1051
		List<SlideDefinition> slideDefs = this.getSlideDefinitions(categoryID);
1052
 
1053
		for(SlideDefinition slideDef : slideDefs) {
1054
			List<Long> slideFeatureDefIDs = 
1055
				this.getFeatureDefintionIDs(slideDef);
1056
 
1057
			featureDefIDs.addAll(slideFeatureDefIDs);
1058
		}
1059
 
1060
		return featureDefIDs;
1061
	}
1062
 
1063
	/**
1064
	 * Returns list of feature definition IDs for given slide definition ID
1065
	 * 
1066
	 * @param slideDef
1067
	 * @return list of feature definition IDs
1068
	 */
1069
	public List<Long> getFeatureDefintionIDs(SlideDefinition slideDef) {
1070
		List<Long> featureDefIDs = new ArrayList<Long>();
1071
 
1072
		List<SlideFeatureDefinition> slideFeatureDefs = 
1073
			slideDef.getSlideFeatureDefinitions();
1074
 
1075
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
1076
			featureDefIDs.add(
1077
					new Long(slideFeatureDef.getFeatureDefintionID()));
1078
		}
1079
 
1080
		return featureDefIDs;
1081
	}
88 naveen 1082
 
1083
	/**
1084
	 * 
1085
	 * @param borrowedSlideDefID
1086
	 * @return
1087
	 * @throws Exception 
1088
	 */
1089
	public boolean isValidSlideDefinitionID(long borrowedSlideDefID) 
1090
		throws Exception {
1091
		this.getSlideDefinitions();
1092
 
1093
		return this.slideDefinitions.containsKey(new Long(borrowedSlideDefID));
1094
	}
1095
 
1096
	/**
1097
	 * Returns Facet-Rule definition object defined for a category and 
1098
	 * slide definition
1099
	 * 
1100
	 * @param borrowedCategoryID
1101
	 * @param slideDefID
1102
	 * @return FacetRuleDefinition 
1103
	 * @throws Exception 
1104
	 */
1105
	public FacetRuleDefinition getFacetRuleDefinitionForSlide(long categoryID,
1106
			long slideDefinitionID) throws Exception {
1107
		CategoryFacetDefinition categoryFacetDef = 
1108
			this.getCategoryFacetDefinition(categoryID);
1109
 
1110
		List<FacetRuleDefinition> facetRuleDefs = 
1111
			categoryFacetDef.getFacetRuleDefinitions();
1112
 
1113
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1114
			if(facetRuleDef.getSlideDefinitionID() == slideDefinitionID) {
1115
				return facetRuleDef;
1116
			}
1117
		}
1118
 
1119
		return null;
1120
	}
1121
 
1122
	/**
1123
	 * Returns Facet-Rule definition object defined for a category and 
1124
	 * feature definition
1125
	 * 
1126
	 * @param categoryID
1127
	 * @param featureDefinitionID
1128
	 * @return FacetRuleDefinition
1129
	 * @throws Exception
1130
	 */
1131
	public FacetRuleDefinition getFacetRuleDefinitionForFeature(long categoryID,
1132
			long featureDefinitionID) throws Exception {
1133
		CategoryFacetDefinition categoryFacetDef = 
1134
			this.getCategoryFacetDefinition(categoryID);
1135
 
1136
		List<FacetRuleDefinition> facetRuleDefs = 
1137
			categoryFacetDef.getFacetRuleDefinitions();
1138
 
1139
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1140
			if(facetRuleDef.getFeatureDefinitionID() == featureDefinitionID) {
1141
				return facetRuleDef;
1142
			}
1143
		}
1144
 
1145
		return null;
1146
	}
102 naveen 1147
 
1148
	/**
1149
	 * Returns all normalization rule defined
1150
	 * 
1151
	 * @return Map<Long, RuleDefinition> 
1152
	 * @throws Exception 
1153
	 */
1154
	@SuppressWarnings("unchecked")
1155
	public Map<Long, RuleDefinition> getNormalizationRules() throws Exception {
1156
 
1157
		// De-serialize
1158
		if(this.normalizationRuleDefinitions == null) {
457 rajveer 1159
			String dbFile = Utils.CONTENT_DB_PATH + "definitions" + File.separator +	
102 naveen 1160
				"normalizationrules.ser";
1161
 
1162
			Utils.info("dbFile=" + dbFile);
1163
 
1164
			this.normalizationRuleDefinitions = 
1165
				(Map<Long, RuleDefinition>) DBUtils.read(dbFile);
1166
		}
1167
 
1168
		return this.normalizationRuleDefinitions;
1169
	}
1170
 
1171
 
1172
	/**
1173
	 * True if feature has normalization rule defined
1174
	 * 
1175
	 * @param feature
1176
	 * @return boolean 
1177
	 * @throws Exception 
1178
	 */
1179
	public boolean needsNormalization(long featureDefinitionID) 
1180
		throws Exception {
1181
		this.getFeatureDefinitions();
1182
 
1183
		FeatureDefinition featureDef = 
1184
			this.featureDefinitions.get(new Long(featureDefinitionID));
1185
 
1186
		if(featureDef.getNormalizationRuleDefinitionID() != 0L) {
1187
			return true;
1188
		}
1189
 
1190
		return false;
1191
	}
1192
 
1193
	/**
1194
	 * Returns normalization rule definition for rule definition ID
1195
	 * 
1196
	 * @param ruleID
1197
	 * @return RuleDefinition 
1198
	 * @throws Exception 
1199
	 */
1200
	public RuleDefinition getNormalizationRuleDefinition(
1201
			long ruleDefinitionID) throws Exception {
1202
		this.getNormalizationRules();
1203
 
1204
		return this.normalizationRuleDefinitions.get(
1205
				new Long(ruleDefinitionID));
1206
	}
10 shop2020 1207
}