Subversion Repositories SmartDukaan

Rev

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