Subversion Repositories SmartDukaan

Rev

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