Subversion Repositories SmartDukaan

Rev

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