Subversion Repositories SmartDukaan

Rev

Rev 1061 | Rev 1073 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 shop2020 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.definitions;
5
 
1050 rajveer 6
import in.shop2020.metamodel.jaxb.comparison.CMPBucketDefinitionType;
7
import in.shop2020.metamodel.jaxb.comparison.CMPDefinitionType;
8
import in.shop2020.metamodel.jaxb.comparison.CMPRuleDefinitionType;
9
import in.shop2020.metamodel.jaxb.comparison.CMPSlideRuleDefinitionType;
10
import in.shop2020.metamodel.jaxb.core.BulletDefinitionType;
11
import in.shop2020.metamodel.jaxb.core.CategorySlideDefinitionType;
12
import in.shop2020.metamodel.jaxb.core.CategorySlideSequenceType;
13
import in.shop2020.metamodel.jaxb.core.CategoryType;
14
import in.shop2020.metamodel.jaxb.core.CompositeDefinitionType;
15
import in.shop2020.metamodel.jaxb.core.CompositePartDefinitionType;
16
import in.shop2020.metamodel.jaxb.core.DatatypeDefinitionType;
17
import in.shop2020.metamodel.jaxb.core.DefinitionType;
18
import in.shop2020.metamodel.jaxb.core.EditorialImportanceType;
19
import in.shop2020.metamodel.jaxb.core.EnumDefinitionType;
20
import in.shop2020.metamodel.jaxb.core.EnumValueType;
21
import in.shop2020.metamodel.jaxb.core.FeatureDefinitionType;
22
import in.shop2020.metamodel.jaxb.core.SlideDefinitionType;
23
import in.shop2020.metamodel.jaxb.core.SlideFeatureDefinitionType;
24
import in.shop2020.metamodel.jaxb.core.UnitType;
25
import in.shop2020.metamodel.jaxb.facets.CategoryFacetDefinitionType;
26
import in.shop2020.metamodel.jaxb.facets.FacetDefinitionType;
27
import in.shop2020.metamodel.jaxb.facets.FacetRuleDefinitionType;
28
import in.shop2020.metamodel.jaxb.facets.IRDefinitionType;
29
import in.shop2020.metamodel.jaxb.facets.RuleDefinitionType;
70 naveen 30
import in.shop2020.metamodel.util.ExpandedCMPSlideRuleDefinition;
45 naveen 31
import in.shop2020.metamodel.util.ExpandedCategory;
62 naveen 32
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
33
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
199 naveen 34
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
70 naveen 35
import in.shop2020.util.Utils;
17 naveen 36
 
457 rajveer 37
import java.io.File;
1050 rajveer 38
import java.io.FileInputStream;
10 shop2020 39
import java.io.Serializable;
18 naveen 40
import java.util.ArrayList;
1050 rajveer 41
import java.util.HashMap;
18 naveen 42
import java.util.Iterator;
43
import java.util.List;
10 shop2020 44
import java.util.Map;
1050 rajveer 45
import java.util.TreeMap;
10 shop2020 46
 
1050 rajveer 47
import javax.xml.bind.JAXBContext;
48
import javax.xml.bind.JAXBElement;
49
import javax.xml.bind.Unmarshaller;
50
 
10 shop2020 51
/**
49 naveen 52
 * Single point of access to all definition objects
53
 * 
10 shop2020 54
 * @author naveen
55
 *
56
 */
57
public class DefinitionsContainer implements Serializable {
58
 
41 naveen 59
	/** 
10 shop2020 60
	 * 
61
	 */
62
	private static final long serialVersionUID = 1L;
49 naveen 63
 
64
	/**
65
	 * Hashtable of Category ID to Category object
66
	 */
10 shop2020 67
	private Map<Long, Category> categories;
49 naveen 68
 
69
	/**
70
	 * Hashtable of Slide ID to SlideDefinition object
71
	 */
10 shop2020 72
	private Map<Long, SlideDefinition> slideDefinitions;
49 naveen 73
 
74
	/**
75
	 * Hashtable of Feature Definition ID to FeatureDefinition object
76
	 */
10 shop2020 77
	private Map<Long, FeatureDefinition> featureDefinitions;
49 naveen 78
 
79
	/**
80
	 * Hashtable of Datatype Definition ID to DatatypeDefinition object
81
	 */
10 shop2020 82
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
49 naveen 83
 
84
	/**
85
	 * Hashtable of Enum value ID to EnumValue object
86
	 */
24 naveen 87
	private Map<Long, EnumValue> enumValues;
49 naveen 88
 
89
	/**
90
	 * Hashtable of Unit ID to Unit object
91
	 */
10 shop2020 92
	private Map<Long, Unit> units;
93
 
94
	/**
62 naveen 95
	 * Hashtable of Facet Definition ID to FacetDefinition object
96
	 */
97
	private Map<Long, FacetDefinition> facetDefinitions;
98
 
99
	/**
100
	 * Hashtable of Category Facet Definition ID to CategoryFacetDefinition 
101
	 * object
102
	 */
103
	private Map<Long, CategoryFacetDefinition> categoryFacetDefinitions;
104
 
105
	/**
106
	 * Hashtable of IR Data Rule ID to RuleDefinition object
107
	 */
108
	private Map<Long, RuleDefinition> irDataRuleDefinitions;	
109
 
110
	/**
111
	 * Hashtable of IR Meta Data Rule ID to RuleDefinition object
112
	 */
113
	private Map<Long, RuleDefinition> irMetaDataRuleDefinitions;
114
 
115
 
116
	/**
70 naveen 117
	 * Hashtable of Comparison Rule ID to CMPRuleDefinition object
118
	 */
119
	private Map<Long, CMPRuleDefinition> cmpRuleDefinitions;	
120
 
121
	/**
122
	 * Hashtable of SlideDefinition ID to CMPSlideRuleDefinition object
123
	 */
124
	private Map<Long, CMPSlideRuleDefinition> cmpSlideRuleDefinitions;
125
 
126
	/**
72 naveen 127
	 * Hashtable of Category ID to list of CMPBucketDefinition object
128
	 */
129
	private Map<Long, List<CMPBucketDefinition>> cmpBucketDefinitions;
102 naveen 130
 
131
	/**
132
	 * Hashtable of feature definition ID to normalization rule definition ID
133
	 */
134
	private Map<Long, RuleDefinition> normalizationRuleDefinitions;
199 naveen 135
 
136
	/**
137
	 * Hashtable of feature definition ID to normalization rule definition ID
138
	 */
139
	private Map<Long, List<Long>> categorySlideSequence;
72 naveen 140
 
141
	/**
473 rajveer 142
	 * Database path. Just in case we want to override
143
	 */
1050 rajveer 144
	private String xmlDefinitionsPath =  Utils.CONTENT_DB_PATH + "definitions" + File.separator;
473 rajveer 145
 
146
	/**
49 naveen 147
	 * Empty constructor. Data structures are initialised as needed
1050 rajveer 148
	 * @throws Exception 
10 shop2020 149
	 */
1050 rajveer 150
	public DefinitionsContainer(){
151
		try {
152
			initialize();
153
		} catch (Exception e) {
154
			// TODO Auto-generated catch block
155
			e.printStackTrace();
156
		}
10 shop2020 157
	}
158
 
159
	/**
473 rajveer 160
	 * Empty constructor. Just dbPath is initialised
1050 rajveer 161
	 * @throws Exception 
473 rajveer 162
	 */
1050 rajveer 163
	public DefinitionsContainer(String xmlDefinitionsPath) throws Exception {
164
		this.xmlDefinitionsPath = xmlDefinitionsPath;
165
		initialize();
473 rajveer 166
	}
1050 rajveer 167
 
473 rajveer 168
 
1050 rajveer 169
	private void initialize() throws Exception{
170
		initializeCoreDefinitionObjects();
171
		initializeFacetsDefinitionObjects();
172
		initializeComparisonDefinitionObjects();
173
	}
174
 
175
	private void initializeCoreDefinitionObjects() throws Exception{
176
		DefinitionType defType = null;
177
		String srcFile;
178
		Object oDefType = null;
179
 
180
		// categoriy slide sequence
181
		srcFile = xmlDefinitionsPath+ "categories.xml";
182
		oDefType = this.unmarshallSrcFile(srcFile, "core");
183
		defType = (DefinitionType)oDefType;
184
		//FIXME
185
		categories = new HashMap<Long, Category>();
186
		Category root = this.convertCategories(defType, categories, srcFile);
187
 
188
		// category slide sequence
189
		srcFile = xmlDefinitionsPath+ "categoryslidesequence.xml";
190
		oDefType = this.unmarshallSrcFile(srcFile, "core");
191
		defType = (DefinitionType)oDefType;
192
		this.categorySlideSequence = this.convertCategorySlideSequence(defType);
193
 
194
		// units
195
		srcFile = xmlDefinitionsPath+ "units.xml";
196
		oDefType = this.unmarshallSrcFile(srcFile, "core");
197
		defType = (DefinitionType)oDefType;
198
		this.units = this.convertUnits(defType);
199
 
200
		//data type definitions
201
		srcFile = xmlDefinitionsPath+ "datatypedefinitions.xml";
202
		oDefType = this.unmarshallSrcFile(srcFile, "core");
203
		defType = (DefinitionType)oDefType;
204
		this.datatypeDefinitions = this.convertDatatypeDefinition(defType);
205
 
206
		//enum values
207
		populateEnumValues();
208
 
209
		//feature definitions
210
		srcFile = xmlDefinitionsPath+ "featuredefinitions.xml";
211
		oDefType = this.unmarshallSrcFile(srcFile, "core");
212
		defType = (DefinitionType)oDefType;
213
		this.featureDefinitions = this.convertFeatureDefinitions(defType);
214
 
215
		//slide definitions
216
		srcFile = xmlDefinitionsPath+ "slidedefinitions.xml";
217
		oDefType = this.unmarshallSrcFile(srcFile, "core");
218
		defType = (DefinitionType)oDefType;
219
		this.slideDefinitions = this.convertSlideDefinitions(defType);
220
 
221
	}
222
 
223
	private void initializeFacetsDefinitionObjects() throws Exception{
224
		IRDefinitionType irDefType = null;
225
		String srcFile;
226
		Object oDefType = null;
227
 
228
		//all facet definitions
229
		srcFile = xmlDefinitionsPath+ "facetdefinitions.xml";
230
		oDefType = this.unmarshallSrcFile(srcFile, "facets");
231
		irDefType = (IRDefinitionType)oDefType;
232
		this.facetDefinitions = this.convertFacetDefinitions(irDefType);
233
 
234
		//category facet definitions
235
		srcFile = xmlDefinitionsPath+ "categoryfacetdefinitions.xml";
236
		oDefType = this.unmarshallSrcFile(srcFile, "facets");
237
		irDefType = (IRDefinitionType)oDefType;
238
		this.categoryFacetDefinitions = this.convertCategoryFacetDefinitions(irDefType);
239
 
240
 
241
		//ir data rules
242
		srcFile = xmlDefinitionsPath+ "irdatarules.xml";
243
		oDefType = this.unmarshallSrcFile(srcFile, "facets");
244
		irDefType = (IRDefinitionType)oDefType;
245
		irDataRuleDefinitions =  this.convertRuleDefinitions(irDefType);
246
 
247
		//ir meta data rules
248
		srcFile = xmlDefinitionsPath+ "irmetadatarules.xml";
249
		oDefType = this.unmarshallSrcFile(srcFile, "facets");
250
		irDefType = (IRDefinitionType)oDefType;
1071 chandransh 251
		irMetaDataRuleDefinitions =  this.convertRuleDefinitions(irDefType);
1050 rajveer 252
 
253
		//normalization rules
254
		srcFile = xmlDefinitionsPath+ "normalizationrules.xml";
255
		oDefType = this.unmarshallSrcFile(srcFile, "facets");
256
		irDefType = (IRDefinitionType)oDefType;
257
		normalizationRuleDefinitions = this.convertNormalizationRuleDefinitions(irDefType);
258
	}
259
 
260
	private void initializeComparisonDefinitionObjects() throws Exception{
261
		CMPDefinitionType cmpDefType = null;
262
		String srcFile;
263
		Object oDefType = null;
264
 
265
		//all facet definitions
266
		srcFile = xmlDefinitionsPath+ "comparisonrules.xml";
267
		oDefType = this.unmarshallSrcFile(srcFile, "comparison");
268
		cmpDefType = (CMPDefinitionType)oDefType;
269
		this.cmpRuleDefinitions = this.convertComparisonRuleDefinitions(cmpDefType);
270
 
271
 
272
		//all f
273
		srcFile = xmlDefinitionsPath+ "comparisondefinitions.xml";
274
		oDefType = this.unmarshallSrcFile(srcFile, "comparison");
275
		cmpDefType = (CMPDefinitionType)oDefType;
276
		this.cmpSlideRuleDefinitions = this.convertComparisonDefinitions(cmpDefType);
277
 
278
		//all facet definitions
279
		srcFile = xmlDefinitionsPath+ "comparisonbuckets.xml";
280
		oDefType = this.unmarshallSrcFile(srcFile, "comparison");
281
		cmpDefType = (CMPDefinitionType)oDefType;
282
		this.cmpBucketDefinitions = this.convertComparisonBuckets(cmpDefType);
283
 
284
	}
285
 
286
 
473 rajveer 287
	/**
1050 rajveer 288
	 * 
289
	 * @param irDefType
290
	 * @return
291
	 */
292
	private Map<Long, RuleDefinition> convertNormalizationRuleDefinitions(
293
			IRDefinitionType defType) {
294
 
295
		Map<Long, RuleDefinition> idRuleDef = 
296
			new TreeMap<Long, RuleDefinition>();
297
 
298
		List<RuleDefinitionType> jaxbRuleDefs = defType.getRuleDefinition();
299
 
300
		for(RuleDefinitionType jaxbRuleDef : jaxbRuleDefs) {
301
			long id = jaxbRuleDef.getID();
302
			String script = jaxbRuleDef.getScript();
303
 
304
			RuleDefinition ruleDef = new RuleDefinition(id, script);
305
			ruleDef.setDescription(jaxbRuleDef.getDescription());
306
 
307
			idRuleDef.put(new Long(id), ruleDef);
308
		}
309
 
310
		Utils.info("idRuleDef=" + idRuleDef);
311
 
312
		return idRuleDef;
313
	}
314
 
315
 
316
 
317
	/**
318
	 * 
319
	 * @param defType
320
	 * @return Map<Long, CMPRuleDefinition>
321
	 */
322
	private Map<Long, CMPRuleDefinition> convertComparisonRuleDefinitions(
323
			CMPDefinitionType defType) {
324
		Map<Long, CMPRuleDefinition> idRuleDef = 
325
			new TreeMap<Long, CMPRuleDefinition>();
326
 
327
		List<CMPRuleDefinitionType> jaxbRuleDefs = 
328
			defType.getCMPRuleDefinition();
329
 
330
		for(CMPRuleDefinitionType jaxbRuleDef : jaxbRuleDefs) {
331
			long id = jaxbRuleDef.getID();
332
			String script = jaxbRuleDef.getScript();
333
 
334
			CMPRuleDefinition ruleDef = new CMPRuleDefinition(id, script);
335
			ruleDef.setDescription(jaxbRuleDef.getDescription());
336
 
337
			idRuleDef.put(new Long(id), ruleDef);
338
		}
339
 
340
		Utils.info("idRuleDef=" + idRuleDef);
341
		return idRuleDef;
342
	}
343
 
344
	/**
345
	 * 
346
	 * @param defType
347
	 * @return Map<Long, CMPSlideRuleDefinition> 
348
	 */
349
	private Map<Long, CMPSlideRuleDefinition> convertComparisonDefinitions(
350
			CMPDefinitionType defType) {
351
 
352
		Map<Long, CMPSlideRuleDefinition> slideRuleDefs = 
353
			new TreeMap<Long, CMPSlideRuleDefinition>();
354
 
355
		List<CMPSlideRuleDefinitionType> jaxbDefs = 
356
			defType.getCMPSlideRuleDefinition();
357
 
358
		for(CMPSlideRuleDefinitionType jaxbDef : jaxbDefs) {
359
			long ruleDefID = jaxbDef.getRuleDefinitionID();
360
			long slideDefID = jaxbDef.getSlideDefinitionID();
361
 
362
			CMPSlideRuleDefinition slideRuleDef = 
363
				new CMPSlideRuleDefinition(slideDefID, ruleDefID);
364
 
365
			slideRuleDef.setDescription(jaxbDef.getDescription());
366
 
367
			slideRuleDefs.put(new Long(slideDefID), slideRuleDef);
368
		}
369
 
370
		Utils.info("slideRuleDefs=" + slideRuleDefs);
371
		return slideRuleDefs;
372
	}
373
 
374
	/**
375
	 * 
376
	 * @param defType
377
	 * @return
378
	 */
379
	private Map<Long, List<CMPBucketDefinition>> convertComparisonBuckets(
380
			CMPDefinitionType defType) {
381
 
382
		Map<Long, List<CMPBucketDefinition>> cmpBuckets = 
383
			new HashMap<Long, List<CMPBucketDefinition>>();
384
 
385
		List<CMPBucketDefinitionType> jaxbBuckets = 
386
			defType.getCMPBucketDefinition();
387
 
388
		for(CMPBucketDefinitionType jaxbBucket : jaxbBuckets) {
389
			String name = jaxbBucket.getName();
390
			long categoryID = jaxbBucket.getCategoryID();
391
 
392
			CMPBucketDefinition bucketDef = 
393
				new CMPBucketDefinition(name, categoryID);
394
 
395
			bucketDef.setDescription(jaxbBucket.getDescription());
396
			bucketDef.setDefaultWeight(
397
					jaxbBucket.getDefaultWeight().intValue());
398
			bucketDef.setSlideDefinitionIDs(jaxbBucket.getSlideDefinitionID());
399
 
400
			List<CMPBucketDefinition> categoryBuckets = 
401
				cmpBuckets.get(new Long(categoryID));
402
 
403
			if(categoryBuckets == null) {
404
				categoryBuckets = new ArrayList<CMPBucketDefinition>();
405
				cmpBuckets.put(new Long(categoryID), categoryBuckets);
406
			}
407
 
408
			categoryBuckets.add(bucketDef);
409
		}
410
		Utils.info("cmpBuckets=" + cmpBuckets);
411
 
412
		return cmpBuckets;
413
	}
414
 
415
 
416
	/**
417
	 * 
418
	 * @param defType
419
	 * @return
420
	 */
421
	private Map<Long, RuleDefinition> convertRuleDefinitions(
422
			IRDefinitionType defType) {
423
		Map<Long, RuleDefinition> idRuleDef = 
424
			new TreeMap<Long, RuleDefinition>();
425
 
426
		List<RuleDefinitionType> jaxbRuleDefs = defType.getRuleDefinition();
427
 
428
		for(RuleDefinitionType jaxbRuleDef : jaxbRuleDefs) {
429
			long id = jaxbRuleDef.getID();
430
			String script = jaxbRuleDef.getScript();
431
 
432
			RuleDefinition ruleDef = new RuleDefinition(id, script);
433
			ruleDef.setDescription(jaxbRuleDef.getDescription());
434
 
435
			idRuleDef.put(new Long(id), ruleDef);
436
		}
437
 
438
		Utils.info("idRuleDef=" + idRuleDef);
439
		return idRuleDef;
440
	}
441
 
442
 
443
	/**
444
	 * 
445
	 * @param defType
446
	 * @return
447
	 */
448
	private Map<Long, FacetDefinition> convertFacetDefinitions(
449
			IRDefinitionType defType) {
450
		List<FacetDefinitionType> jaxbFacetDefs = defType.getFacetDefinition();
451
 
452
		Map<Long, FacetDefinition> idFacetDefs = 
453
			new TreeMap<Long, FacetDefinition>();
454
 
455
		for(FacetDefinitionType jaxbFacetDef : jaxbFacetDefs) {
456
			long id = jaxbFacetDef.getID();
457
			String target = jaxbFacetDef.getTarget();
458
 
459
			FacetDefinition facetDef = new FacetDefinition(id, target);
460
 
461
			if(jaxbFacetDef.getFeatureDefinitionID() != null) {
462
				long featureDefID = jaxbFacetDef.getFeatureDefinitionID();
463
				facetDef.setFeatureDefinitionID(featureDefID);
464
			}
465
 
466
			if(jaxbFacetDef.getSlideDefinitionID() != null) {
467
				long slideDefID = jaxbFacetDef.getSlideDefinitionID();
468
				facetDef.setSlideDefinitionID(slideDefID);
469
			}
470
 
471
			long irMetaDataRuleID = jaxbFacetDef.getIRMetaDataRuleID();
472
			facetDef.setIrMetaDataRuleID(irMetaDataRuleID);
473
 
474
			facetDef.setDescription(jaxbFacetDef.getDescription());
475
 
476
			idFacetDefs.put(new Long(id), facetDef);
477
		}
478
		Utils.info("idFacetDefs=" + idFacetDefs);
479
		return idFacetDefs;
480
	}
481
 
482
	/**
483
	 * 
484
	 * @param defType
485
	 * @return
486
	 * @throws Exception 
487
	 */
488
	private Map<Long, CategoryFacetDefinition> convertCategoryFacetDefinitions(
489
			IRDefinitionType defType) throws Exception {
490
		List<CategoryFacetDefinitionType> jaxbCategoryFacetDefs = 
491
			defType.getCategoryFacetDefinition();
492
 
493
		Map<Long, CategoryFacetDefinition> idCategoryFacetDefs = 
494
			new TreeMap<Long, CategoryFacetDefinition>();
495
 
496
		for(CategoryFacetDefinitionType jaxbCategoryFacetDef : 
497
			jaxbCategoryFacetDefs) {
498
			long categoryID = jaxbCategoryFacetDef.getCategoryID();
499
 
500
			CategoryFacetDefinition categoryFacetDef = 
501
				new CategoryFacetDefinition(categoryID);
502
 
503
			List<FacetRuleDefinitionType> jaxbFacetRuleDefs = 
504
					jaxbCategoryFacetDef.getFacetRuleDefinition();
505
 
506
			for(FacetRuleDefinitionType jaxbFacetRuleDef : jaxbFacetRuleDefs) {
507
 
508
				FacetRuleDefinition facetRuleDef = 
509
					this.convertFacetRuleDefinition(jaxbFacetRuleDef);
510
 
511
				categoryFacetDef.addFacetRuleDefinition(facetRuleDef);
512
			}
513
 
514
			idCategoryFacetDefs.put(new Long(categoryID), categoryFacetDef);
515
		}
516
 
517
		// Append parent's facets 
518
		// Go only one level for now
519
		// Categories need to be imported first
520
 
521
		for(Long categoryID : idCategoryFacetDefs.keySet()) {
522
			Category category = this.getCategory(categoryID.longValue());
523
			Category parentCategory = category.getParentCategory();
524
 
525
			if(parentCategory != null) {
526
				long parentCategoryID = parentCategory.getID();
527
 
528
				CategoryFacetDefinition parentCategoryFacetDef = 
529
					idCategoryFacetDefs.get(new Long(parentCategoryID));
530
 
531
				if(parentCategoryFacetDef != null) {
532
					List<FacetRuleDefinition> parentsFacetRuleDefs = 
533
						parentCategoryFacetDef.getFacetRuleDefinitions();
534
 
535
					if(parentsFacetRuleDefs != null) {
536
						CategoryFacetDefinition categoryFacetDef = 
537
							idCategoryFacetDefs.get(categoryID);
538
 
539
						categoryFacetDef.appendFacetRuleDefinitions(
540
								parentsFacetRuleDefs);
541
					}
542
				}
543
			}
544
		}
545
 
546
		Utils.info("idCategoryFacetDefs=" + idCategoryFacetDefs);
547
		return idCategoryFacetDefs;
548
	}
549
 
550
	/**
551
	 * 
552
	 * @param jaxbFacetRuleDef
553
	 * @return
554
	 */
555
	private FacetRuleDefinition convertFacetRuleDefinition(
556
			FacetRuleDefinitionType jaxbFacetRuleDef) {
557
		long facetDefID = jaxbFacetRuleDef.getFacetDefinitionID();
558
		long irDataRuleID = jaxbFacetRuleDef.getIRDataRuleID();
559
 
560
		FacetRuleDefinition facetRuleDef = new FacetRuleDefinition(facetDefID, 
561
				irDataRuleID);
562
 
563
		facetRuleDef.setDescription(jaxbFacetRuleDef.getDescription());
564
 
565
		if(jaxbFacetRuleDef.getFeatureDefinitionID() != null) {
566
			facetRuleDef.setFeatureDefinitionID(
567
					jaxbFacetRuleDef.getFeatureDefinitionID().longValue());
568
		}
569
 
570
		if(jaxbFacetRuleDef.getSlideDefinitionID() != null) {
571
			facetRuleDef.setSlideDefinitionID(
572
					jaxbFacetRuleDef.getSlideDefinitionID().longValue());
573
		}
574
 
575
		return facetRuleDef;
576
	}
577
 
578
	private void populateEnumValues(){
579
		// RE-VISIT - May not be optimal
580
		Map<Long, EnumValue> enumValuesMap = new TreeMap<Long, EnumValue>();
581
		for(Long datatypeDefID : datatypeDefinitions.keySet()) {
582
			DatatypeDefinition datatypeDef = 
583
				datatypeDefinitions.get(datatypeDefID);
584
 
585
			if(datatypeDef instanceof EnumDefinition) {
586
				List<EnumValue> enumValues = 
587
					((EnumDefinition) datatypeDef).getEnumValues();
588
 
589
				for(EnumValue enumValue : enumValues) {
590
					enumValuesMap.put(new Long(enumValue.getID()), 
591
							enumValue);
592
				}
593
			}
594
		}
595
		this.enumValues = enumValuesMap;
596
	}
597
 
598
 
599
	/**
199 naveen 600
	 * Returns Slide sequence for a category in the database
601
	 * 
602
	 * @return Map Null if Category-Slide definitions are not imported into 
603
	 * definitions db 
604
	 * (serialized java objects)
605
	 * 
606
	 * @throws Exception 
607
	 */
608
	public Map<Long, List<Long>> getCategorySlideSequence() throws Exception {		
1050 rajveer 609
		return this.categorySlideSequence;
610
	}
611
 
612
 
613
	/**
614
	 * 
615
	 * @param defType
616
	 * @return
617
	 */
618
	private Map<Long, List<Long>> convertCategorySlideSequence(
619
			DefinitionType defType) {
620
		Map<Long, List<Long>> catSlideSeq = new HashMap<Long, List<Long>>();
621
 
622
		List<CategorySlideSequenceType> jaxbCatSlideSeqs = 
623
			defType.getCategorySlideSequence();
624
 
625
		for(CategorySlideSequenceType jaxbCatSlideSeq : jaxbCatSlideSeqs) {
626
			long catID = jaxbCatSlideSeq.getCategoryID();
627
			List<Long> slideDefIDs = jaxbCatSlideSeq.getSlideDefinitionID();
199 naveen 628
 
1050 rajveer 629
			Long lCatID = new Long(catID);
630
			catSlideSeq.put(lCatID, slideDefIDs);
199 naveen 631
		}
632
 
1050 rajveer 633
		return catSlideSeq;
199 naveen 634
	}
635
 
1050 rajveer 636
 
199 naveen 637
	/**
638
	 * Given a category ID, returns all slide definition IDs in sequence 
639
	 * provided by content editor
640
	 * 
641
	 * @param categoryID
642
	 * @return List of Slide Definition IDs
643
	 * @throws Exception
644
	 */
1050 rajveer 645
	public List<Long> getCategorySlideSequence(long categoryID) throws Exception {	
199 naveen 646
		return this.categorySlideSequence.get(new Long(categoryID));
647
	}
648
 
649
	/**
49 naveen 650
	 * Returns all Unit objects in the database
10 shop2020 651
	 * 
49 naveen 652
	 * @return Map Null if units are not imported into definitions db 
653
	 * (serialized java objects)
654
	 * 
18 naveen 655
	 * @throws Exception 
10 shop2020 656
	 */
1050 rajveer 657
	public Map<Long, Unit> getUnits() throws Exception {
658
		return this.units;
659
	}
660
 
661
 
662
	/**
663
	 * 
664
	 * @param srcFile
665
	 * @return
666
	 * @throws Exception
667
	 */
668
	private Object unmarshallSrcFile(String srcFile, String type) 
669
		throws Exception {
670
 
671
        JAXBContext jc = JAXBContext.newInstance("in.shop2020.metamodel.jaxb." +
672
        		type);
673
 
674
        // create an Unmarshaller
675
        Unmarshaller u = jc.createUnmarshaller();
676
 
677
        JAXBElement<?> element = (JAXBElement<?>)u.unmarshal(
678
        		new FileInputStream(srcFile));
679
 
680
        return element.getValue();
681
	}
682
 
683
	/**
684
	 * 
685
	 * @return Map
686
	 */
687
	private Map<Long, Unit> convertUnits(DefinitionType defType) {
688
 
689
		Map<Long, Unit> allUnits = new HashMap<Long, Unit>();
690
		List<UnitType> jaxbUnits = defType.getUnit();
691
		Iterator<UnitType> it = jaxbUnits.iterator();
692
 
693
		while(it.hasNext()) {
694
			UnitType jaxbUnit = it.next();
18 naveen 695
 
1050 rajveer 696
			Unit unit = new Unit(jaxbUnit.getID());
697
			unit.setDescription(jaxbUnit.getDescription());
698
			unit.setFullForm(jaxbUnit.getFullform());
699
			unit.setShortForm(jaxbUnit.getShortform());
700
			Utils.info("unit=" + unit);
701
 
702
			allUnits.put(new Long(jaxbUnit.getID()), unit);
17 naveen 703
		}
18 naveen 704
 
1050 rajveer 705
		return allUnits;
10 shop2020 706
	}
707
 
1050 rajveer 708
 
10 shop2020 709
	/**
49 naveen 710
	 * Resolves Unit ID into Unit object
10 shop2020 711
	 * 
49 naveen 712
	 * @param unitID Unit ID
10 shop2020 713
	 * @return Unit
18 naveen 714
	 * @throws Exception 
10 shop2020 715
	 */
18 naveen 716
	public Unit getUnit(long unitID) throws Exception {		
10 shop2020 717
		return this.units.get(new Long(unitID));
718
	}
719
 
720
	/**
49 naveen 721
	 * Returns all DatatypeDefintion object in database
722
	 * 
723
	 * @return the datatypeDefinitions List of DatatypeDefinition objects
18 naveen 724
	 * @throws Exception 
10 shop2020 725
	 */
1050 rajveer 726
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions(){
727
		return this.datatypeDefinitions;
728
	}
729
 
730
 
731
	/**
732
	 * 
733
	 * @param defType
734
	 * @return
735
	 */
736
	private Map<Long, DatatypeDefinition> convertDatatypeDefinition(DefinitionType defType) {
18 naveen 737
 
1050 rajveer 738
		Map<Long, DatatypeDefinition> defs = new HashMap<Long, DatatypeDefinition>();
739
 
740
		List<DatatypeDefinitionType> jaxbDefs = defType.getDatatypeDefinition();
741
		Iterator<DatatypeDefinitionType> it = jaxbDefs.iterator();
742
 
743
		while(it.hasNext()) {
744
			DatatypeDefinitionType jaxbDef = it.next();
18 naveen 745
 
1050 rajveer 746
			DatatypeDefinition def = null;
747
			CompositeDefinitionType compositeDefType = jaxbDef.getCompositeDefinition();
748
 
749
			EnumDefinitionType enumDefType = jaxbDef.getEnumDefinition();
750
 
751
			// Composite data type
752
			if(compositeDefType != null) {
753
				CompositeDefinition compDef = new CompositeDefinition(jaxbDef.getID(), jaxbDef.getName(), compositeDefType.getSeparator());
754
 
755
				List<CompositePartDefinitionType> jaxbPartDefs = compositeDefType.getCompositePartDefinition();
756
 
757
				Iterator<CompositePartDefinitionType> itPartDefs = jaxbPartDefs.iterator();
758
 
759
				// Collect parts
760
				while(itPartDefs.hasNext()) {
761
					CompositePartDefinitionType jaxbPartDef = itPartDefs.next();
762
					CompositePartDefinition partDef = this.convertCompositePartDefinition(jaxbPartDef);
763
 
764
					compDef.addCompositePartDefinition(partDef);
765
				}
766
 
767
				def = compDef;
768
			}
769
 
770
			// Enumerated values
771
			else if(enumDefType != null) {
772
				EnumDefinition enumDef = new EnumDefinition(jaxbDef.getID(), 
773
						jaxbDef.getName());
774
 
775
				List<EnumValueType> jaxbEnumValues = 
776
					enumDefType.getEnumValue();
777
 
778
				Iterator<EnumValueType> itEnumValues = 
779
					jaxbEnumValues.iterator();
780
 
781
				// Collect individual value
782
				while(itEnumValues.hasNext()) {
783
					EnumValueType jaxbEnumValue = itEnumValues.next();
784
					EnumValue enumValue = 
785
						this.convertEnumValueDefinition(jaxbEnumValue);
786
 
787
					enumDef.addEnumValue(enumValue);
788
				}
789
 
790
				def = enumDef;
791
			}
792
 
793
			// Primitive
794
			else {
795
				def = new DatatypeDefinition(jaxbDef.getID(), 
796
						jaxbDef.getName());
797
			}
798
 
799
			def.setDescription(jaxbDef.getDescription());
800
			Utils.info("def=" + def);
801
 
802
			defs.put(new Long(jaxbDef.getID()), def);
18 naveen 803
		}
1050 rajveer 804
 
805
		return defs;
10 shop2020 806
	}
18 naveen 807
 
808
	/**
1050 rajveer 809
	 * 
810
	 * @param jaxbPartDef
811
	 * @return CompositePartDefinition
812
	 */
813
	private CompositePartDefinition convertCompositePartDefinition(
814
			CompositePartDefinitionType jaxbPartDef) {
815
 
816
		CompositePartDefinition partDef = new CompositePartDefinition(
817
				jaxbPartDef.getLabel(), jaxbPartDef.getDatatypeDefinitionID(), 
818
				jaxbPartDef.getUnitID());
819
 
820
		partDef.setDescription(jaxbPartDef.getDescription());
821
 
822
		return partDef;
823
	}
824
 
825
	/**
49 naveen 826
	 * Resolves Datatype Definition ID into DatetypeDefinition object
18 naveen 827
	 * 
49 naveen 828
	 * @param unitID Unit ID
18 naveen 829
	 * @return Unit
830
	 * @throws Exception 
831
	 */
832
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
833
 
834
		// Initialize 
835
		if(this.datatypeDefinitions == null) {
836
			this.getDatatypeDefinitions();
837
		}
838
 
839
		return this.datatypeDefinitions.get(new Long(id));
840
	}
19 naveen 841
 
842
	/**
1050 rajveer 843
	 * 
844
	 * @param jaxbEnumValue
845
	 * @return EnumValue
846
	 */
847
	private EnumValue convertEnumValueDefinition(EnumValueType jaxbEnumValue) {
848
 
849
		EnumValue enumValue = new EnumValue(jaxbEnumValue.getID(), 
850
				jaxbEnumValue.getValue());
851
 
852
		return enumValue;
853
	}
854
	/**
49 naveen 855
	 * Returns EnumValue ID for datatype definition ID and enum value string 
856
	 * to match. Match is case insensitive
19 naveen 857
	 * 
49 naveen 858
	 * @param datatypeDefID DatatypeDefinition ID
859
	 * @param value query enum value string
19 naveen 860
	 * @return long enumValueID - "-1" if not found
861
	 * @throws Exception 
862
	 */
863
	public long getEnumValueID(long datatypeDefID, String value) 
864
		throws Exception {
865
		long enumValueID = -1L;
866
 
867
		// Let the callers catch ClassCastException
868
		EnumDefinition enumDef = 
869
			(EnumDefinition)this.getDatatypeDefinition(datatypeDefID);
870
 
24 naveen 871
		List<EnumValue> enumValues = enumDef.getEnumValues();
19 naveen 872
		for(EnumValue enumValue : enumValues) {
873
			if(value.equalsIgnoreCase(enumValue.getValue())) {
874
				enumValueID = enumValue.getID();
875
				break;
876
			}
877
		}
878
 
879
		return enumValueID;
880
	}
17 naveen 881
 
10 shop2020 882
	/**
49 naveen 883
	 * Returns all category objects in the database
884
	 * 
10 shop2020 885
	 * @return the categories
17 naveen 886
	 * @throws Exception 
10 shop2020 887
	 */
1050 rajveer 888
	public Map<Long, Category> getCategories() {
889
		return this.categories;
890
	}
891
 
892
 
893
	/**
894
	 * 
895
	 * @param defType
896
	 * @param catMap
897
	 * @return
898
	 */
899
	private Category convertCategories(DefinitionType defType, 
900
			Map<Long, Category> catMap, String srcFile) {
901
 
902
		List<CategoryType> jaxbCats = defType.getCategory();
903
		Iterator<CategoryType> it = jaxbCats.iterator();
904
 
905
		// Get root category
906
		CategoryType jaxbCat = it.next();
907
		if(jaxbCat == null) {
908
			Utils.info("Invalid file: " + srcFile);
909
			return null;
910
		}
911
 
912
		Category root = this.convertCategoryType(jaxbCat, null, catMap);
913
		return root;
914
	}
915
 
916
 
917
	/**
918
	 * 
919
	 * @param jaxbCat
920
	 * @param parentCat
921
	 * @param catMap
922
	 * @return
923
	 */
17 naveen 924
	@SuppressWarnings("unchecked")
1050 rajveer 925
	private Category convertCategoryType(CategoryType jaxbCat, 
926
			Category parentCat, Map<Long, Category> catMap) {
17 naveen 927
 
1050 rajveer 928
		Category cat = new Category(jaxbCat.getID());
929
		cat.setLabel(jaxbCat.getName());
930
		cat.setDescription(jaxbCat.getDescription());
931
		if(parentCat != null) {
932
			cat.setParentCategory(parentCat);
17 naveen 933
 
1050 rajveer 934
			// Copy parent's category-slide definitions
935
			ArrayList<CategorySlideDefinition> parentCSDef = 
936
				(ArrayList<CategorySlideDefinition>) 
937
				parentCat.getCategorySlideDefintions();
938
 
939
			if(parentCSDef != null) {
940
				cat.setCategorySlideDefintions(
941
					(List<CategorySlideDefinition>) parentCSDef.clone());
942
			}
17 naveen 943
		}
1050 rajveer 944
 
945
		// Category Slide Definition
946
		List<CategorySlideDefinitionType> jaxbDefs = 
947
			jaxbCat.getCategorySlideDefinition();
948
 
949
		Iterator<CategorySlideDefinitionType> it = jaxbDefs.iterator();
950
		while(it.hasNext()) {
951
			CategorySlideDefinitionType jaxbDef = it.next();
952
			CategorySlideDefinition catSlideDef 
953
			= this.convertCategorySlideDefinitionType(jaxbCat.getID(), jaxbDef);
954
 
955
			cat.addCategorySlideDefintion(catSlideDef);
956
		}
957
 
958
		// Children
959
		List<CategoryType> jaxbChildren = jaxbCat.getChildCategory();
960
		//Utils.info("jaxbChildren.size: " + jaxbChildren.size());
961
 
962
		Iterator<CategoryType> itChildren = jaxbChildren.iterator();
963
		while(itChildren.hasNext()) {
964
			CategoryType jaxbChildCat = itChildren.next();
965
			Category childCat = this.convertCategoryType(jaxbChildCat, cat, 
966
					catMap);
967
			cat.addChild(childCat);
968
		}
969
 
970
		//FIXME put debug messages
971
		//Utils.info("Parent cat: " + cat);
972
		// DEBUG ONLY
973
		Utils.info("####### Cat ID: " + cat.getID());
974
		if(cat.getCategorySlideDefintions() != null) {
975
			for(CategorySlideDefinition csd : cat.getCategorySlideDefintions()){
976
				Utils.info("####### SlideDefintionID=" + csd.getSlideDefintionID());
977
			}
978
		}
979
 
980
		catMap.put(new Long(jaxbCat.getID()), cat);
981
		return cat;
10 shop2020 982
	}
17 naveen 983
 
10 shop2020 984
	/**
1050 rajveer 985
	 * 
986
	 * @param categoryID
987
	 * @param jaxbDef
988
	 * @return
989
	 */
990
	private CategorySlideDefinition convertCategorySlideDefinitionType(
991
			long categoryID, CategorySlideDefinitionType jaxbDef) {
992
 
993
		CategorySlideDefinition catSlideDef = new CategorySlideDefinition(
994
				jaxbDef.getSlideDefinitionID());
995
 
996
		catSlideDef.setDescription(jaxbDef.getDescription());
997
 
998
		EditorialImportanceType jaxbEdImp = jaxbDef.getEditorialImportance();
999
		EditorialImportance edImp = this.convertEditorialImportance(jaxbEdImp);
1000
		catSlideDef.setEditorialImportance(edImp);
1001
 
1002
		return catSlideDef;
1003
	}
1004
 
1005
	/**
1006
	 * 
1007
	 * @param jaxbEdImp
1008
	 * @return EditorialImportance
1009
	 */
1010
	private EditorialImportance convertEditorialImportance(
1011
			EditorialImportanceType jaxbEdImp) {
1012
 
1013
		String strEdImp = jaxbEdImp.value();
1014
		EditorialImportance edImp = null;
1015
 
1016
		if(strEdImp.equals("Mandatory"))
1017
			edImp = EditorialImportance.MANDATORY;
1018
		else if(strEdImp.equals("Optional"))
1019
			edImp = EditorialImportance.OPTIONAL;
1020
		else 
1021
			edImp = EditorialImportance.RECOMMENDED;
1022
 
1023
		return edImp;
1024
	}
1025
 
1026
 
1027
	/**
49 naveen 1028
	 * Resolves Category ID into Category object
17 naveen 1029
	 * 
49 naveen 1030
	 * @param categoryID Category ID
17 naveen 1031
	 * @return Category
1032
	 * @throws Exception 
10 shop2020 1033
	 */
1050 rajveer 1034
	public Category getCategory(long categoryID) {
17 naveen 1035
		return this.categories.get(new Long(categoryID));
10 shop2020 1036
	}
17 naveen 1037
 
10 shop2020 1038
	/**
49 naveen 1039
	 * Returns expanded Category object. All numeric identifiers are resolved 
1040
	 * into detailed objects
18 naveen 1041
	 * 
1042
	 * @param categoryID
45 naveen 1043
	 * @return ExpandedCategory
1044
	 * @throws Exception
1045
	 */
1046
	public ExpandedCategory getExpandedCategory(long categoryID) 
1047
		throws Exception {
1048
		Category category = this.getCategory(categoryID);
1049
 
1050
		ExpandedCategory expCategory = new ExpandedCategory(category);
1051
 
1052
		return expCategory;
1053
	}
1054
 
1055
	/**
49 naveen 1056
	 * Returns all children categories for a Category ID
45 naveen 1057
	 * 
1058
	 * @param categoryID
49 naveen 1059
	 * @return List<Category> Children Categories
34 naveen 1060
	 * @throws Exception
1061
	 */
1050 rajveer 1062
	public List<Category> getChildrenCategories(long categoryID){
34 naveen 1063
		return this.categories.get(new Long(categoryID)).getChildrenCategory();
1064
	}
49 naveen 1065
 
34 naveen 1066
	/**
49 naveen 1067
	 * Returns all CategorySlideDefinition objects for a Category ID
34 naveen 1068
	 * 
49 naveen 1069
	 * @param categoryID Category ID
18 naveen 1070
	 * @return List<CategorySlideDefinition> 
1071
	 * @throws Exception 
1072
	 */
1073
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
1074
			long categoryID) throws Exception {
1075
		Category category = this.getCategory(categoryID);
1076
 
1077
		return category.getCategorySlideDefintions();
1078
	}
1079
 
1080
	/**
49 naveen 1081
	 * Returns All SlideDefinition objects in database
1082
	 * 
10 shop2020 1083
	 * @return the slideDefinitions
18 naveen 1084
	 * @throws Exception 
10 shop2020 1085
	 */
1050 rajveer 1086
	public Map<Long, SlideDefinition> getSlideDefinitions(){
1087
		return this.slideDefinitions;
1088
	}
1089
 
1090
	/**
1091
	 * 
1092
	 * @return Map
1093
	 */
1094
	private Map<Long, SlideDefinition> convertSlideDefinitions(
1095
			DefinitionType defType) {
18 naveen 1096
 
1050 rajveer 1097
		Map<Long, SlideDefinition> defs = 
1098
			new HashMap<Long, SlideDefinition>();
1099
 
1100
		List<SlideDefinitionType> jaxbDefs = defType.getSlideDefinition();
1101
		Iterator<SlideDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1102
 
1103
		// Slide definitions
1104
		while(itjaxbDefs.hasNext()) {
1105
			SlideDefinitionType jaxbDef = itjaxbDefs.next();
18 naveen 1106
 
1050 rajveer 1107
			Utils.info("Slide label=" + jaxbDef.getLabel());
1108
			SlideDefinition def = new SlideDefinition(jaxbDef.getID(),
1109
					jaxbDef.getLabel());
1110
			def.setDescription(jaxbDef.getDescription());
1111
 
1112
			// Children Slides
1113
			Utils.info("jaxbDef.getChildSlideID=" + jaxbDef.getChildSlideID());
1114
			def.setChildrenSlideDefinitionIDs(jaxbDef.getChildSlideID());
1115
 
1116
			// Slide Feature Definition
1117
			List<SlideFeatureDefinitionType> jaxbSlideFeatureDefs = 
1118
				jaxbDef.getSlideFeatureDefinition();
1119
 
1120
			if(jaxbSlideFeatureDefs != null) {
1121
				def.setSlideFeatureDefinitions((
1122
						this.convertSlideFeatureDefinitions(
1123
								jaxbSlideFeatureDefs)));
1124
			}
1125
			Utils.info("def=" + def);
1126
 
1127
			defs.put(new Long(jaxbDef.getID()), def);
18 naveen 1128
		}
1050 rajveer 1129
 
1130
		return defs;
10 shop2020 1131
	}
1050 rajveer 1132
 
18 naveen 1133
 
1134
	/**
1050 rajveer 1135
	 * 
1136
	 * @param jaxbDefs
1137
	 * @return List<SlideFeatureDefinition>
1138
	 */
1139
	private List<SlideFeatureDefinition> convertSlideFeatureDefinitions(
1140
			List<SlideFeatureDefinitionType> jaxbDefs) {
1141
 
1142
		List<SlideFeatureDefinition> defs = 
1143
			new ArrayList<SlideFeatureDefinition>();
1144
 
1145
		Iterator<SlideFeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1146
 
1147
		// Slide-feature definitions
1148
		while(itjaxbDefs.hasNext()) {
1149
			SlideFeatureDefinitionType jaxbDef = itjaxbDefs.next();
1150
			SlideFeatureDefinition def = new SlideFeatureDefinition(
1151
					jaxbDef.getFeatureDefinitionID());
1152
 
1153
			def.setEditorialImportance(this.convertEditorialImportance(
1154
					jaxbDef.getEditorialImportance()));
1155
 
1156
			def.setDescription(jaxbDef.getDescription());
1157
 
1158
			defs.add(def);
1159
		}
1160
 
1161
		return defs;
1162
	}
1163
 
1164
 
1165
	/**
49 naveen 1166
	 * Resolves SlideDefinition ID into SlideDefinition object
18 naveen 1167
	 * 
1168
	 * @param id
1169
	 * @return SlideDefinition
1170
	 * @throws Exception
1171
	 */
1172
	public SlideDefinition getSlideDefinition(long id) throws Exception {
1173
 
1174
		// Initialize 
1175
		if(this.slideDefinitions == null) {
1176
			this.getSlideDefinitions();
1177
		}
1178
 
1179
		return this.slideDefinitions.get(new Long(id));
1180
	}
1181
 
1182
	/**
199 naveen 1183
	 * 
1184
	 * @param slideID
1185
	 * @return ExpandedSlideDefinition 
1186
	 * @throws Exception 
1187
	 */
1188
	public ExpandedSlideDefinition getExpandedSlideDefinition(long slideID) 
1189
		throws Exception {
1190
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1191
 
1192
		return new ExpandedSlideDefinition(slideDef);
1193
	}
1194
 
1195
	/**
49 naveen 1196
	 * Returns SlideDefinition objects for a category and matching slide label
18 naveen 1197
	 * 
19 naveen 1198
	 * @param label
1199
	 * @return List<SlideDefinition>
1200
	 * @throws Exception
1201
	 */
32 naveen 1202
	public List<SlideDefinition> getSlideDefinitions(long categoryID, 
1203
			String label) throws Exception {
1204
 
1205
		// RE-VISIT
1206
		// May be we need a new data structure, category id to slide definitions
1207
		// for now
1208
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
19 naveen 1209
 
32 naveen 1210
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
1211
				categoryID);
1212
 
1213
		for(CategorySlideDefinition csDef : csDefs) {
1214
			SlideDefinition sDef = this.getSlideDefinition(
1215
					csDef.getSlideDefintionID());
1216
 
1217
			if(sDef.getLabel().equalsIgnoreCase(label)) {
1218
				matchingSlides.add(sDef);
1219
			}
19 naveen 1220
		}
1221
 
32 naveen 1222
		return matchingSlides;
1223
	}
1224
 
1225
	/**
49 naveen 1226
	 * Resolves Category ID into Category object
32 naveen 1227
	 * 
1228
	 * @param categoryID
49 naveen 1229
	 * @return List<SlideDefinition> 
32 naveen 1230
	 * @throws Exception
1231
	 */
1232
	public List<SlideDefinition> getSlideDefinitions(long categoryID) 
1233
		throws Exception {
1234
 
1235
		// RE-VISIT
1236
		// May be we need a new data structure, category id to slide definitions
1237
		// for now
19 naveen 1238
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
32 naveen 1239
 
1240
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
1241
				categoryID);
1242
 
1243
		for(CategorySlideDefinition csDef : csDefs) {
1244
			SlideDefinition sDef = this.getSlideDefinition(
1245
					csDef.getSlideDefintionID());
19 naveen 1246
 
32 naveen 1247
			matchingSlides.add(sDef);
19 naveen 1248
		}
1249
 
1250
		return matchingSlides;
1251
	}
49 naveen 1252
 
19 naveen 1253
	/**
49 naveen 1254
	 * Returns list of SlideDefinition objects for a category and editorial 
1255
	 * importance value
19 naveen 1256
	 * 
18 naveen 1257
	 * @param categoryID
1258
	 * @param EditorialImportance imp
1259
	 * @return List<SlideDefinition>
1260
	 * @throws Exception 
1261
	 */
1262
	public List<SlideDefinition> getSlides(long categoryID, 
1263
			EditorialImportance imp) 
1264
		throws Exception {
1265
 
1266
		List<CategorySlideDefinition> catSlideDefs = 
1267
			this.getCategorySlideDefinitions(categoryID);
1268
 
1269
		Iterator<CategorySlideDefinition> itCatSlideDefs = 
1270
			catSlideDefs.iterator();
1271
 
1272
		List<SlideDefinition> slideDefs = new ArrayList<SlideDefinition>();
1273
		while(itCatSlideDefs.hasNext()) {
1274
			CategorySlideDefinition catSlideDef = itCatSlideDefs.next();
1275
			if(catSlideDef.getEditorialImportance() == imp) {
1276
				long slideDefID = catSlideDef.getSlideDefintionID();
1277
				slideDefs.add(this.getSlideDefinition(slideDefID));
1278
			}
1279
		}
1280
		return slideDefs;
1281
	}
1282
 
1283
	/**
49 naveen 1284
	 * Returns all FeatureDefinition object in database
18 naveen 1285
	 * 
1286
	 * @return Map<Long, FeatureDefinition>
1287
	 * @throws Exception
1288
	 */
1050 rajveer 1289
	public Map<Long, FeatureDefinition> getFeatureDefinitions(){
1290
		return this.featureDefinitions;
1291
	}
1292
 
1293
 
1294
	/**
1295
	 * 
1296
	 * @param defType
1297
	 * @return
1298
	 */
1299
	private Map<Long, FeatureDefinition> convertFeatureDefinitions(
1300
			DefinitionType defType) {
18 naveen 1301
 
1050 rajveer 1302
		Map<Long, FeatureDefinition> defs = 
1303
			new HashMap<Long, FeatureDefinition>();
1304
 
1305
		List<FeatureDefinitionType> jaxbDefs = defType.getFeatureDefinition();
1306
		Iterator<FeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1307
 
1308
		// Feature definitions
1309
		while(itjaxbDefs.hasNext()) {
1310
			FeatureDefinitionType jaxbDef = itjaxbDefs.next();
18 naveen 1311
 
1050 rajveer 1312
			//Utils.info("Feature label=" + jaxbDef.getLabel());
1313
			FeatureDefinition def = new FeatureDefinition(jaxbDef.getID(),
1314
					jaxbDef.getLabel());
1315
			def.setAllowsBlank(jaxbDef.isCanbeBlank());
1316
			def.setDescription(jaxbDef.getDescription());
1317
 
1318
			// Bullet Definition
1319
			BulletDefinitionType jaxbBulletDef = jaxbDef.getBulletDefinition();
1320
			if(jaxbBulletDef != null) {
1321
				def.setBulletDefinition(this.convertBulletDefinition(
1322
						jaxbBulletDef));
1323
			}
1324
 
1325
			Long normRuleDefID = jaxbDef.getNormalizationRuleDefinitionID();
1326
			if(normRuleDefID != null) {
1327
				def.setNormalizationRuleDefinitionID(normRuleDefID.longValue());
1328
			}
1329
			Utils.info("def=" + def);
1330
 
1331
			defs.put(new Long(jaxbDef.getID()), def);
18 naveen 1332
		}
1050 rajveer 1333
 
1334
		return defs;
18 naveen 1335
	}
1050 rajveer 1336
 
19 naveen 1337
 
10 shop2020 1338
	/**
1050 rajveer 1339
	 * 
1340
	 * @param jaxbDef BulletDefinitionType
1341
	 * @return BulletDefinition
1342
	 */
1343
	private BulletDefinition convertBulletDefinition(
1344
			BulletDefinitionType jaxbDef) {
1345
 
1346
		BulletDefinition def = new BulletDefinition(
1347
				jaxbDef.getDatatypeDefinitionID());
1348
 
1349
		List<Long> unitIDs = jaxbDef.getUnitID();
1350
		if(unitIDs != null && !unitIDs.isEmpty()) {
1351
			def.setUnitIDs(unitIDs);
1352
		}
1353
		Utils.info("jaxbDef.isIsMultivalue=" + jaxbDef.isIsMultivalue());
1354
 
1355
		def.setMultivalue(jaxbDef.isIsMultivalue());
1356
		def.setLearned(jaxbDef.isIsLearned());
1357
		def.setDescription(jaxbDef.getDescription());
1358
 
1359
		return def;
1360
	}
1361
 
1362
 
1363
	/**
49 naveen 1364
	 * Returns all FeatureDefinition objects for a slide
18 naveen 1365
	 * 
19 naveen 1366
	 * @param slideID
1367
	 * @return List<FeatureDefinition> 
1368
	 * @throws Exception
1369
	 */
1370
	public List<FeatureDefinition> getFeatureDefinitions(long slideID) 
1371
		throws Exception {
1372
		List<FeatureDefinition> featureDefs = 
1373
			new ArrayList<FeatureDefinition>();
1374
 
1375
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1376
		List<SlideFeatureDefinition> slideFeatureDefs = 
1377
			slideDef.getSlideFeatureDefinitions();
1378
 
1379
		for(int i=0; i<slideFeatureDefs.size(); i++) {
1380
			featureDefs.add(this.getFeatureDefinition(
1381
					slideFeatureDefs.get(i).getFeatureDefintionID()));
1382
		}
1383
 
1384
		return featureDefs;
1385
	}
1386
 
1387
	/**
49 naveen 1388
	 * Returns list of FeatureDefinition objects for a slide given editorial 
1389
	 * importance
19 naveen 1390
	 * 
1391
	 * @param slideID
49 naveen 1392
	 * @param imp Editorial Importance enum object
19 naveen 1393
	 * @return List<FeatureDefinition>
1394
	 * @throws Exception
1395
	 */
1396
	public List<FeatureDefinition> getFeatureDefinitions(long slideID, 
1397
			EditorialImportance imp)  throws Exception {
1398
		List<FeatureDefinition> featureDefs = 
1399
			new ArrayList<FeatureDefinition>();
1400
 
1401
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1402
		List<SlideFeatureDefinition> slideFeatureDefs = 
1403
			slideDef.getSlideFeatureDefinitions();
1404
 
1405
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
1406
			if(slideFeatureDef.getEditorialImportance() == imp) {
1407
				featureDefs.add(this.getFeatureDefinition(
1408
						slideFeatureDef.getFeatureDefintionID()));
1409
			}
1410
		}
1411
 
1412
		return featureDefs;
1413
	}
1414
 
1415
	/**
49 naveen 1416
	 * Resolves Feature Definition ID into FeatureDefinition object
19 naveen 1417
	 * 
49 naveen 1418
	 * @param id Feature Definition ID 
19 naveen 1419
	 * @return FeatureDefinition
18 naveen 1420
	 * @throws Exception
10 shop2020 1421
	 */
18 naveen 1422
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
1423
 
1424
		// Initialize 
1425
		if(this.featureDefinitions == null) {
1426
			this.getFeatureDefinitions();
1427
		}
1428
 
1429
		return this.featureDefinitions.get(new Long(id));
1430
	}	
19 naveen 1431
 
1432
	/**
49 naveen 1433
	 * Returns matching FeatureDefinition object for slide ID and feature label.
1434
	 * Label matching is case insensitive.
19 naveen 1435
	 * 
49 naveen 1436
	 * @param slideID Slide ID
1437
	 * @param featureLabel label to match, case is ignored
19 naveen 1438
	 * @return FeatureDefinition 
1439
	 * @throws Exception
1440
	 */
1441
	public FeatureDefinition getFeatureDefinition(long slideID, 
1442
			String featureLabel) throws Exception {
1443
		FeatureDefinition featureDef = null;
1444
 
1445
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1446
		for(SlideFeatureDefinition slideFeatureDef : 
1447
			slideDef.getSlideFeatureDefinitions()) {
1448
 
1449
			long featureDefID = slideFeatureDef.getFeatureDefintionID();
1450
 
1451
			FeatureDefinition thisFeatureDef = this.getFeatureDefinition(
1452
					featureDefID);
1453
 
28 naveen 1454
			if(featureLabel.equalsIgnoreCase(thisFeatureDef.getLabel())) {
19 naveen 1455
				featureDef = thisFeatureDef;
1456
			}
1457
		}
1458
 
1459
		return featureDef;
1460
	}
24 naveen 1461
 
1462
	/**
49 naveen 1463
	 * Returns all EnumValue objects in the database
1464
	 * 
24 naveen 1465
	 * @return the enumValues
1466
	 * @throws Exception 
1467
	 */
1468
	public Map<Long, EnumValue> getEnumValues() throws Exception {
1469
		return this.enumValues;
1470
	}
19 naveen 1471
 
1050 rajveer 1472
 
24 naveen 1473
	/**
49 naveen 1474
	 * Resolves Enum value ID into EnumValue object
24 naveen 1475
	 * 
1476
	 * @param enumValueID
1477
	 * @return EnumValue
1478
	 * @throws Exception
1479
	 */
1480
	public EnumValue getEnumValue(long enumValueID) throws Exception {
1481
		return this.enumValues.get(new Long(enumValueID));
1482
	}
62 naveen 1483
 
1484
	/**
1485
	 * Returns all FacetDefinition objects in the database
1486
	 * 
1487
	 * @return Map Null if facet definitions are not imported into definitions 
1488
	 * db (serialized java objects)
1489
	 * 
1490
	 * @throws Exception 
1491
	 */
1050 rajveer 1492
	public Map<Long, FacetDefinition> getFacetDefinitions(){
62 naveen 1493
		return this.facetDefinitions;
1494
	}
1495
 
1496
	/**
1497
	 * Resolves Facet Definition ID into FacetDefinition object
1498
	 * 
1499
	 * @param facetDefinitionID
1500
	 * @return FacetDefinition
1501
	 * @throws Exception
1502
	 */
1503
	public FacetDefinition getFacetDefinition(long facetDefinitionID) 
1504
		throws Exception {
1505
 
1506
		if(this.facetDefinitions == null) {
1507
			this.getFacetDefinitions();
1508
		}
1509
 
1510
		return this.facetDefinitions.get(new Long(facetDefinitionID));
1511
	}
1512
 
1513
	/**
1514
	 * Utility method to get Expanded version of ExpandedFacetDefinition object 
1515
	 * 
1516
	 * @param facetDefinitionID
1517
	 * @return ExpandedFacetDefinition
1518
	 * @throws Exception
1519
	 */
1520
	public ExpandedFacetDefinition getExpandedFacetDefinition(
1521
			long facetDefinitionID) throws Exception {
1522
 
1523
		FacetDefinition facetDefinition = 
1524
			this.getFacetDefinition(facetDefinitionID);
1525
 
1526
		ExpandedFacetDefinition expFacetDefinition = 
1527
			new ExpandedFacetDefinition(facetDefinition);
1528
 
1529
		return expFacetDefinition;
1530
	}
1531
 
1532
	/**
1533
	 * Returns all CategoryFacetDefinition objects in the database
1534
	 * 
1535
	 * @return Map Null if category facet definitions are not imported into 
1536
	 * definitions db (serialized java objects)
1537
	 * 
1538
	 * @throws Exception 
1539
	 */
1050 rajveer 1540
	public Map<Long, CategoryFacetDefinition> getCategoryFacetDefinitions(){
62 naveen 1541
		return this.categoryFacetDefinitions;
1542
	}
1543
 
1544
	/**
1545
	 * Resolves Category-Facet Definition ID into CategoryFacetDefinition object
1546
	 * 
1547
	 * @param categoryID
1548
	 * @return CategoryFacetDefinition
1549
	 * @throws Exception
1550
	 */
1050 rajveer 1551
	public CategoryFacetDefinition getCategoryFacetDefinition(long categoryID){
1552
		return this.categoryFacetDefinitions.get(new Long(categoryID));
62 naveen 1553
	}
1554
 
1050 rajveer 1555
 
62 naveen 1556
	/**
1557
	 * Utility method to get Expanded version of CategoryFacetDefinition object 
1558
	 * 
1559
	 * @param categoryID
1560
	 * @return ExpandedCategoryFacetDefinition
1561
	 * @throws Exception
1562
	 */
1563
	public ExpandedCategoryFacetDefinition getExpandedCategoryFacetDefinition(
1564
			long categoryID) throws Exception  {
1565
		CategoryFacetDefinition categoryFacetDef = 
1566
			this.getCategoryFacetDefinition(categoryID);
1567
 
1568
		ExpandedCategoryFacetDefinition expCategoryFacetDef = 
1569
			new ExpandedCategoryFacetDefinition(categoryFacetDef);
1570
 
1571
		return expCategoryFacetDef;
1572
	}
1573
 
1574
	/**
1575
	 * Returns all IR Data RuleDefintion objects in the database
1576
	 * 
1577
	 * @return Map Null if IR data rule definitions are not imported into 
1578
	 * definitions db (serialized java objects)
1579
	 * 
1580
	 * @throws Exception 
1581
	 */
1050 rajveer 1582
	public Map<Long, RuleDefinition> getIrDataRuleDefinitions(){
62 naveen 1583
		return this.irDataRuleDefinitions;
1584
	}
1585
 
1586
	/**
1587
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
1588
	 * 
1589
	 * @param irDataRuleDefinitionID
1590
	 * @return RuleDefinition
1591
	 * @throws Exception
1592
	 */
1050 rajveer 1593
	public RuleDefinition getIrDataRuleDefinition(long irDataRuleDefinitionID){
62 naveen 1594
		return this.irDataRuleDefinitions.get(new Long(irDataRuleDefinitionID));
1595
	}
1596
 
1597
	/**
1598
	 * Returns all IR Meta Data RuleDefintion objects in the database
1599
	 * 
1600
	 * @return Map Null if IR meta-data rule definitions are not imported into 
1601
	 * definitions db (serialized java objects)
1602
	 * 
1603
	 * @throws Exception 
1604
	 */
1050 rajveer 1605
	public Map<Long, RuleDefinition> getIrMetaDataRuleDefinitions(){
62 naveen 1606
		return this.irMetaDataRuleDefinitions;
1607
	}
1608
 
1609
	/**
1610
	 * Resolves IR Meta Data Rule Definition ID into RuleDefinition object
1611
	 * 
1612
	 * @param irMetaDataRuleDefinitionID
1613
	 * @return RuleDefinition
1614
	 * @throws Exception
1615
	 */
1050 rajveer 1616
	public RuleDefinition getIrMetaDataRuleDefinition(long irMetaDataRuleDefinitionID) {
1617
		return this.irMetaDataRuleDefinitions.get(new Long(irMetaDataRuleDefinitionID));
62 naveen 1618
	}
70 naveen 1619
 
1620
	/**
1621
	 * Returns all Comparison RuleDefintion objects in the database
1622
	 * 
1623
	 * @return Map Null if Comparison rule definitions are not imported into 
1624
	 * definitions db (serialized java objects)
1625
	 * 
1626
	 * @throws Exception 
1627
	 */
1050 rajveer 1628
	public Map<Long, CMPRuleDefinition> getComparisonRuleDefinitions(){
70 naveen 1629
		return this.cmpRuleDefinitions;
1630
	}
1631
 
1632
	/**
1633
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
1634
	 * 
1635
	 * @param cmpRuleDefinitionID
1636
	 * @return CMPRuleDefinition
1637
	 * @throws Exception
1638
	 */
1050 rajveer 1639
	public CMPRuleDefinition getComparisonRuleDefinition(long cmpRuleDefinitionID) {
70 naveen 1640
		return this.cmpRuleDefinitions.get(new Long(cmpRuleDefinitionID));
1641
	}
1642
 
1643
 
1644
	/**
1645
	 * Returns all ComparisonSlideRuleDefintion objects in the database
1646
	 * 
1647
	 * @return Map Null if Comparison slide-rule definitions are not imported 
1648
	 * into definitions db (serialized java objects)
1649
	 * 
1650
	 * @throws Exception 
1651
	 */
1050 rajveer 1652
	public Map<Long, CMPSlideRuleDefinition> getComparisonSlideRuleDefinitions() {
70 naveen 1653
		return this.cmpSlideRuleDefinitions;
1654
	}
1655
 
1656
	/**
1657
	 * Resolves Category ID into List of CMPSlideRuleDefinition object
1658
	 * 
1659
	 * @param categoryID
1660
	 * @return List<CMPSlideRuleDefinition> 
1661
	 * @throws Exception
1662
	 */
1050 rajveer 1663
	public CMPSlideRuleDefinition getComparisonSlideRuleDefinition(long slideDefinitionID) {
70 naveen 1664
		return this.cmpSlideRuleDefinitions.get(new Long(slideDefinitionID));
1665
	}
1666
 
1667
 
1668
	/**
1669
	 * Resolves Slide Definition ID into ExpandedCMPSlideRuleDefinition object
1670
	 * 
1671
	 * @param categoryID
1672
	 * @return ExpandedCMPSlideRuleDefinition 
1673
	 * @throws Exception
1674
	 */
1050 rajveer 1675
	public ExpandedCMPSlideRuleDefinition getExpandedComparisonSlideRuleDefinition(long slideDefinitionID) throws Exception{
71 naveen 1676
		Utils.info("slideDefinitionID=" + slideDefinitionID);
70 naveen 1677
 
1050 rajveer 1678
		CMPSlideRuleDefinition cmpSlideRuleDef = this.getComparisonSlideRuleDefinition(slideDefinitionID);
70 naveen 1679
 
71 naveen 1680
		if(cmpSlideRuleDef == null) {
1681
			return null;
1682
		}
1683
 
1050 rajveer 1684
		ExpandedCMPSlideRuleDefinition expDef = new ExpandedCMPSlideRuleDefinition(cmpSlideRuleDef);
70 naveen 1685
		return expDef;
1686
	}
72 naveen 1687
 
70 naveen 1688
 
72 naveen 1689
	/**
1690
	 * Returns all ComparisonSlideRuleDefintion objects in the database
1691
	 * 
1692
	 * @return Map Null if Comparison slide-rule definitions are not imported 
1693
	 * into definitions db (serialized java objects)
1694
	 * 
1695
	 * @throws Exception 
1696
	 */
1050 rajveer 1697
 
1698
	public Map<Long, List<CMPBucketDefinition>> getComparisonBucketDefinitions(){
72 naveen 1699
		return this.cmpBucketDefinitions;
1700
	}
1701
 
1702
	/**
1703
	 * Resolves Category ID into List of CMPBucketDefinition object
1704
	 * 
1705
	 * @param categoryID
1706
	 * @return List<CMPBucketDefinition> 
1707
	 * @throws Exception
1708
	 */
1050 rajveer 1709
	public List<CMPBucketDefinition> getComparisonBucketDefinitions(long categoryID) {
72 naveen 1710
		return this.cmpBucketDefinitions.get(new Long(categoryID));
1711
	}
1712
 
1713
	/**
1714
	 * Resolve comparison bucket name for a slide in a particular category
1715
	 * 
1716
	 * @param categoryID
1717
	 * @param slideDefintionID
1718
	 * @return Bucket Name if found else Null
1719
	 * @throws Exception 
1720
	 */
1721
	public String getComparisonBucketName(long categoryID, 
1722
			long slideDefinitionID) throws Exception {
1723
		List<CMPBucketDefinition> cmpBuckets = 
1724
			this.getComparisonBucketDefinitions(categoryID);
1725
 
1726
		for (CMPBucketDefinition cmpBucket : cmpBuckets) {
1727
			List<Long> slideDefinitionIDs = cmpBucket.getSlideDefinitionIDs();
1728
 
1729
			if(slideDefinitionIDs.contains(new Long(slideDefinitionID))) {
1730
				return cmpBucket.getName();
1731
			}
1732
		}
1733
		return null;
1734
	}
83 naveen 1735
 
1736
	/**
1737
	 * Returns list of facet definition IDs for given category ID
1738
	 * 
1739
	 * @param categoryID
1740
	 * @return list of facet definition IDs
1741
	 * @throws Exception 
1742
	 */
1743
	public List<Long> getFacetDefinitionIDs(long categoryID) throws Exception {
1744
		List<Long> facetDefIDs = new ArrayList<Long>();
1745
 
1746
		CategoryFacetDefinition categoryFacetDef = 
1747
			this.getCategoryFacetDefinition(categoryID);
516 rajveer 1748
		if(categoryFacetDef == null)
1749
			return null;
83 naveen 1750
		List<FacetRuleDefinition> facetRuleDefs = 
1751
			categoryFacetDef.getFacetRuleDefinitions();
1752
 
1753
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1754
			facetDefIDs.add(new Long(facetRuleDef.getFacetDefinitionID()));
1755
		}
1756
 
1757
		return facetDefIDs;
1758
	}
1759
 
1760
	/**
1761
	 * Returns list of feature definition IDs for given category ID
1762
	 * 
1763
	 * @param categoryID
1764
	 * @return list of feature definition IDs
1765
	 * @throws Exception 
1766
	 */
1767
	public List<Long> getFeatureDefinitionIDs(long categoryID) 
1768
		throws Exception {
1769
 
1770
		List<Long> featureDefIDs = new ArrayList<Long>();
1771
 
1772
		List<SlideDefinition> slideDefs = this.getSlideDefinitions(categoryID);
1773
 
1774
		for(SlideDefinition slideDef : slideDefs) {
1775
			List<Long> slideFeatureDefIDs = 
1776
				this.getFeatureDefintionIDs(slideDef);
1777
 
1778
			featureDefIDs.addAll(slideFeatureDefIDs);
1779
		}
1780
 
1781
		return featureDefIDs;
1782
	}
1783
 
1784
	/**
1785
	 * Returns list of feature definition IDs for given slide definition ID
1786
	 * 
1787
	 * @param slideDef
1788
	 * @return list of feature definition IDs
1789
	 */
1790
	public List<Long> getFeatureDefintionIDs(SlideDefinition slideDef) {
1791
		List<Long> featureDefIDs = new ArrayList<Long>();
1792
 
1793
		List<SlideFeatureDefinition> slideFeatureDefs = 
1794
			slideDef.getSlideFeatureDefinitions();
1795
 
1796
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
1050 rajveer 1797
			featureDefIDs.add(new Long(slideFeatureDef.getFeatureDefintionID()));
83 naveen 1798
		}
1799
 
1800
		return featureDefIDs;
1801
	}
88 naveen 1802
 
1803
	/**
1804
	 * 
1805
	 * @param borrowedSlideDefID
1806
	 * @return
1807
	 * @throws Exception 
1808
	 */
1809
	public boolean isValidSlideDefinitionID(long borrowedSlideDefID) 
1810
		throws Exception {
1811
		this.getSlideDefinitions();
1812
 
1813
		return this.slideDefinitions.containsKey(new Long(borrowedSlideDefID));
1814
	}
1815
 
1816
	/**
1817
	 * Returns Facet-Rule definition object defined for a category and 
1818
	 * slide definition
1819
	 * 
1820
	 * @param borrowedCategoryID
1821
	 * @param slideDefID
1822
	 * @return FacetRuleDefinition 
1823
	 * @throws Exception 
1824
	 */
1825
	public FacetRuleDefinition getFacetRuleDefinitionForSlide(long categoryID,
1826
			long slideDefinitionID) throws Exception {
1827
		CategoryFacetDefinition categoryFacetDef = 
1828
			this.getCategoryFacetDefinition(categoryID);
1829
 
1830
		List<FacetRuleDefinition> facetRuleDefs = 
1831
			categoryFacetDef.getFacetRuleDefinitions();
1832
 
1833
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1834
			if(facetRuleDef.getSlideDefinitionID() == slideDefinitionID) {
1835
				return facetRuleDef;
1836
			}
1837
		}
1838
 
1839
		return null;
1840
	}
1841
 
1842
	/**
1843
	 * Returns Facet-Rule definition object defined for a category and 
1844
	 * feature definition
1845
	 * 
1846
	 * @param categoryID
1847
	 * @param featureDefinitionID
1848
	 * @return FacetRuleDefinition
1849
	 * @throws Exception
1850
	 */
1851
	public FacetRuleDefinition getFacetRuleDefinitionForFeature(long categoryID,
1852
			long featureDefinitionID) throws Exception {
1853
		CategoryFacetDefinition categoryFacetDef = 
1854
			this.getCategoryFacetDefinition(categoryID);
1855
 
1856
		List<FacetRuleDefinition> facetRuleDefs = 
1857
			categoryFacetDef.getFacetRuleDefinitions();
1858
 
1859
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1860
			if(facetRuleDef.getFeatureDefinitionID() == featureDefinitionID) {
1861
				return facetRuleDef;
1862
			}
1863
		}
1864
 
1865
		return null;
1866
	}
102 naveen 1867
 
1868
	/**
1869
	 * Returns all normalization rule defined
1870
	 * 
1871
	 * @return Map<Long, RuleDefinition> 
1872
	 * @throws Exception 
1873
	 */
1050 rajveer 1874
	public Map<Long, RuleDefinition> getNormalizationRules() {
102 naveen 1875
		return this.normalizationRuleDefinitions;
1876
	}
1877
 
1878
 
1879
	/**
1880
	 * True if feature has normalization rule defined
1881
	 * 
1882
	 * @param feature
1883
	 * @return boolean 
1884
	 * @throws Exception 
1885
	 */
1886
	public boolean needsNormalization(long featureDefinitionID) 
1887
		throws Exception {
1888
		this.getFeatureDefinitions();
1889
 
1890
		FeatureDefinition featureDef = 
1891
			this.featureDefinitions.get(new Long(featureDefinitionID));
1892
 
1893
		if(featureDef.getNormalizationRuleDefinitionID() != 0L) {
1894
			return true;
1895
		}
1896
 
1897
		return false;
1898
	}
1899
 
1900
	/**
1901
	 * Returns normalization rule definition for rule definition ID
1902
	 * 
1903
	 * @param ruleID
1904
	 * @return RuleDefinition 
1905
	 * @throws Exception 
1906
	 */
1050 rajveer 1907
	public RuleDefinition getNormalizationRuleDefinition(long ruleDefinitionID){
1908
		return this.normalizationRuleDefinitions.get(new Long(ruleDefinitionID));
102 naveen 1909
	}
10 shop2020 1910
}