Subversion Repositories SmartDukaan

Rev

Rev 2322 | Rev 4959 | 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());
4802 amit.gupta 983
		cat.setHasAccessories(jaxbCat.isHasAccessories());
984
		cat.setComparable(jaxbCat.isComparable());
1050 rajveer 985
		if(parentCat != null) {
986
			cat.setParentCategory(parentCat);
17 naveen 987
 
1050 rajveer 988
			// Copy parent's category-slide definitions
989
			ArrayList<CategorySlideDefinition> parentCSDef = 
990
				(ArrayList<CategorySlideDefinition>) 
991
				parentCat.getCategorySlideDefintions();
992
 
993
			if(parentCSDef != null) {
994
				cat.setCategorySlideDefintions(
995
					(List<CategorySlideDefinition>) parentCSDef.clone());
996
			}
17 naveen 997
		}
1050 rajveer 998
 
999
		// Category Slide Definition
1000
		List<CategorySlideDefinitionType> jaxbDefs = 
1001
			jaxbCat.getCategorySlideDefinition();
1002
 
1003
		Iterator<CategorySlideDefinitionType> it = jaxbDefs.iterator();
1004
		while(it.hasNext()) {
1005
			CategorySlideDefinitionType jaxbDef = it.next();
1006
			CategorySlideDefinition catSlideDef 
1007
			= this.convertCategorySlideDefinitionType(jaxbCat.getID(), jaxbDef);
1008
 
1009
			cat.addCategorySlideDefintion(catSlideDef);
1010
		}
1011
 
1012
		// Children
1013
		List<CategoryType> jaxbChildren = jaxbCat.getChildCategory();
1014
		//Utils.info("jaxbChildren.size: " + jaxbChildren.size());
1015
 
1016
		Iterator<CategoryType> itChildren = jaxbChildren.iterator();
1017
		while(itChildren.hasNext()) {
1018
			CategoryType jaxbChildCat = itChildren.next();
1019
			Category childCat = this.convertCategoryType(jaxbChildCat, cat, 
1020
					catMap);
1021
			cat.addChild(childCat);
1022
		}
1023
 
1024
		//FIXME put debug messages
1025
		//Utils.info("Parent cat: " + cat);
1026
		// DEBUG ONLY
1027
		Utils.info("####### Cat ID: " + cat.getID());
1028
		if(cat.getCategorySlideDefintions() != null) {
1029
			for(CategorySlideDefinition csd : cat.getCategorySlideDefintions()){
1030
				Utils.info("####### SlideDefintionID=" + csd.getSlideDefintionID());
1031
			}
1032
		}
1033
 
1034
		catMap.put(new Long(jaxbCat.getID()), cat);
1035
		return cat;
10 shop2020 1036
	}
17 naveen 1037
 
10 shop2020 1038
	/**
1050 rajveer 1039
	 * 
1040
	 * @param categoryID
1041
	 * @param jaxbDef
1042
	 * @return
1043
	 */
1044
	private CategorySlideDefinition convertCategorySlideDefinitionType(
1045
			long categoryID, CategorySlideDefinitionType jaxbDef) {
1046
 
1047
		CategorySlideDefinition catSlideDef = new CategorySlideDefinition(
1048
				jaxbDef.getSlideDefinitionID());
1049
 
1050
		catSlideDef.setDescription(jaxbDef.getDescription());
1051
 
1052
		EditorialImportanceType jaxbEdImp = jaxbDef.getEditorialImportance();
1053
		EditorialImportance edImp = this.convertEditorialImportance(jaxbEdImp);
1054
		catSlideDef.setEditorialImportance(edImp);
1055
 
1056
		return catSlideDef;
1057
	}
1058
 
1059
	/**
1060
	 * 
1061
	 * @param jaxbEdImp
1062
	 * @return EditorialImportance
1063
	 */
1064
	private EditorialImportance convertEditorialImportance(
1065
			EditorialImportanceType jaxbEdImp) {
1066
 
1067
		String strEdImp = jaxbEdImp.value();
1068
		EditorialImportance edImp = null;
1069
 
1070
		if(strEdImp.equals("Mandatory"))
1071
			edImp = EditorialImportance.MANDATORY;
1072
		else if(strEdImp.equals("Optional"))
1073
			edImp = EditorialImportance.OPTIONAL;
1074
		else 
1075
			edImp = EditorialImportance.RECOMMENDED;
1076
 
1077
		return edImp;
1078
	}
1079
 
1080
 
1081
	/**
49 naveen 1082
	 * Resolves Category ID into Category object
17 naveen 1083
	 * 
49 naveen 1084
	 * @param categoryID Category ID
17 naveen 1085
	 * @return Category
1086
	 * @throws Exception 
10 shop2020 1087
	 */
1050 rajveer 1088
	public Category getCategory(long categoryID) {
17 naveen 1089
		return this.categories.get(new Long(categoryID));
10 shop2020 1090
	}
17 naveen 1091
 
10 shop2020 1092
	/**
49 naveen 1093
	 * Returns expanded Category object. All numeric identifiers are resolved 
1094
	 * into detailed objects
18 naveen 1095
	 * 
1096
	 * @param categoryID
45 naveen 1097
	 * @return ExpandedCategory
1098
	 * @throws Exception
1099
	 */
1100
	public ExpandedCategory getExpandedCategory(long categoryID) 
1101
		throws Exception {
1102
		Category category = this.getCategory(categoryID);
1103
 
1104
		ExpandedCategory expCategory = new ExpandedCategory(category);
1105
 
1106
		return expCategory;
1107
	}
1108
 
1109
	/**
49 naveen 1110
	 * Returns all children categories for a Category ID
45 naveen 1111
	 * 
1112
	 * @param categoryID
49 naveen 1113
	 * @return List<Category> Children Categories
34 naveen 1114
	 * @throws Exception
1115
	 */
1050 rajveer 1116
	public List<Category> getChildrenCategories(long categoryID){
34 naveen 1117
		return this.categories.get(new Long(categoryID)).getChildrenCategory();
1118
	}
49 naveen 1119
 
34 naveen 1120
	/**
49 naveen 1121
	 * Returns all CategorySlideDefinition objects for a Category ID
34 naveen 1122
	 * 
49 naveen 1123
	 * @param categoryID Category ID
18 naveen 1124
	 * @return List<CategorySlideDefinition> 
1125
	 * @throws Exception 
1126
	 */
1127
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
1128
			long categoryID) throws Exception {
1129
		Category category = this.getCategory(categoryID);
1130
 
1131
		return category.getCategorySlideDefintions();
1132
	}
1133
 
1134
	/**
49 naveen 1135
	 * Returns All SlideDefinition objects in database
1136
	 * 
10 shop2020 1137
	 * @return the slideDefinitions
18 naveen 1138
	 * @throws Exception 
10 shop2020 1139
	 */
1050 rajveer 1140
	public Map<Long, SlideDefinition> getSlideDefinitions(){
1141
		return this.slideDefinitions;
1142
	}
1143
 
1144
	/**
1145
	 * 
1146
	 * @return Map
1147
	 */
1148
	private Map<Long, SlideDefinition> convertSlideDefinitions(
1149
			DefinitionType defType) {
18 naveen 1150
 
1050 rajveer 1151
		Map<Long, SlideDefinition> defs = 
1152
			new HashMap<Long, SlideDefinition>();
1153
 
1154
		List<SlideDefinitionType> jaxbDefs = defType.getSlideDefinition();
1155
		Iterator<SlideDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1156
 
1157
		// Slide definitions
1158
		while(itjaxbDefs.hasNext()) {
1159
			SlideDefinitionType jaxbDef = itjaxbDefs.next();
18 naveen 1160
 
1050 rajveer 1161
			Utils.info("Slide label=" + jaxbDef.getLabel());
1162
			SlideDefinition def = new SlideDefinition(jaxbDef.getID(),
1163
					jaxbDef.getLabel());
1164
			def.setDescription(jaxbDef.getDescription());
1165
 
2322 rajveer 1166
			Long helpDocDefID = jaxbDef.getHelpDocDefinitionID();
1167
            if(helpDocDefID != null) {
1168
                def.setHelpDocDefinitionID(helpDocDefID.longValue());
1169
            }
1170
 
1050 rajveer 1171
			// Children Slides
1172
			Utils.info("jaxbDef.getChildSlideID=" + jaxbDef.getChildSlideID());
1173
			def.setChildrenSlideDefinitionIDs(jaxbDef.getChildSlideID());
1174
 
1175
			// Slide Feature Definition
1176
			List<SlideFeatureDefinitionType> jaxbSlideFeatureDefs = 
1177
				jaxbDef.getSlideFeatureDefinition();
1178
 
1179
			if(jaxbSlideFeatureDefs != null) {
1180
				def.setSlideFeatureDefinitions((
1181
						this.convertSlideFeatureDefinitions(
1182
								jaxbSlideFeatureDefs)));
1183
			}
1184
			Utils.info("def=" + def);
1185
 
1186
			defs.put(new Long(jaxbDef.getID()), def);
18 naveen 1187
		}
1050 rajveer 1188
 
1189
		return defs;
10 shop2020 1190
	}
1050 rajveer 1191
 
18 naveen 1192
 
1193
	/**
2170 rajveer 1194
     * 
1195
     * @return Map
1196
     */
1197
    private Map<Long, HelpDocDefinition> convertHelpDocDefinitions(DefinitionType defType) {
1198
 
1199
        Map<Long, HelpDocDefinition> defs = 
1200
            new HashMap<Long, HelpDocDefinition>();
1201
 
1202
        List<HelpDocDefinitionType> jaxbDefs = defType.getHelpDocDefinition();
1203
        Iterator<HelpDocDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1204
 
1205
        // Help Doc definitions
1206
        while(itjaxbDefs.hasNext()) {
1207
            HelpDocDefinitionType jaxbDef = itjaxbDefs.next();
1208
 
1209
            Utils.info("Helo doc name is =" + jaxbDef.getName());
1210
            HelpDocDefinition def = new HelpDocDefinition(jaxbDef.getID(), jaxbDef.getName());
1211
 
1212
            Utils.info("def=" + def);
1213
 
1214
            defs.put(new Long(jaxbDef.getID()), def);
1215
        }
1216
 
1217
        return defs;
1218
    }
1219
 
1220
 
1221
	/**
1050 rajveer 1222
	 * 
1223
	 * @param jaxbDefs
1224
	 * @return List<SlideFeatureDefinition>
1225
	 */
1226
	private List<SlideFeatureDefinition> convertSlideFeatureDefinitions(
1227
			List<SlideFeatureDefinitionType> jaxbDefs) {
1228
 
1229
		List<SlideFeatureDefinition> defs = 
1230
			new ArrayList<SlideFeatureDefinition>();
1231
 
1232
		Iterator<SlideFeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1233
 
1234
		// Slide-feature definitions
1235
		while(itjaxbDefs.hasNext()) {
1236
			SlideFeatureDefinitionType jaxbDef = itjaxbDefs.next();
1237
			SlideFeatureDefinition def = new SlideFeatureDefinition(
1238
					jaxbDef.getFeatureDefinitionID());
1239
 
1240
			def.setEditorialImportance(this.convertEditorialImportance(
1241
					jaxbDef.getEditorialImportance()));
1242
 
1243
			def.setDescription(jaxbDef.getDescription());
1244
 
1245
			defs.add(def);
1246
		}
1247
 
1248
		return defs;
1249
	}
1250
 
1251
 
1252
	/**
49 naveen 1253
	 * Resolves SlideDefinition ID into SlideDefinition object
18 naveen 1254
	 * 
1255
	 * @param id
1256
	 * @return SlideDefinition
1257
	 * @throws Exception
1258
	 */
1259
	public SlideDefinition getSlideDefinition(long id) throws Exception {
1260
 
1261
		// Initialize 
1262
		if(this.slideDefinitions == null) {
1263
			this.getSlideDefinitions();
1264
		}
1265
 
1266
		return this.slideDefinitions.get(new Long(id));
1267
	}
1268
 
1269
	/**
199 naveen 1270
	 * 
1271
	 * @param slideID
1272
	 * @return ExpandedSlideDefinition 
1273
	 * @throws Exception 
1274
	 */
1275
	public ExpandedSlideDefinition getExpandedSlideDefinition(long slideID) 
1276
		throws Exception {
1277
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1278
 
1279
		return new ExpandedSlideDefinition(slideDef);
1280
	}
1281
 
1282
	/**
49 naveen 1283
	 * Returns SlideDefinition objects for a category and matching slide label
18 naveen 1284
	 * 
19 naveen 1285
	 * @param label
1286
	 * @return List<SlideDefinition>
1287
	 * @throws Exception
1288
	 */
32 naveen 1289
	public List<SlideDefinition> getSlideDefinitions(long categoryID, 
1290
			String label) throws Exception {
1291
 
1292
		// RE-VISIT
1293
		// May be we need a new data structure, category id to slide definitions
1294
		// for now
1295
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
19 naveen 1296
 
32 naveen 1297
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
1298
				categoryID);
1299
 
1300
		for(CategorySlideDefinition csDef : csDefs) {
1301
			SlideDefinition sDef = this.getSlideDefinition(
1302
					csDef.getSlideDefintionID());
1303
 
1304
			if(sDef.getLabel().equalsIgnoreCase(label)) {
1305
				matchingSlides.add(sDef);
1306
			}
19 naveen 1307
		}
1308
 
32 naveen 1309
		return matchingSlides;
1310
	}
1311
 
1312
	/**
49 naveen 1313
	 * Resolves Category ID into Category object
32 naveen 1314
	 * 
1315
	 * @param categoryID
49 naveen 1316
	 * @return List<SlideDefinition> 
32 naveen 1317
	 * @throws Exception
1318
	 */
1319
	public List<SlideDefinition> getSlideDefinitions(long categoryID) 
1320
		throws Exception {
1321
 
1322
		// RE-VISIT
1323
		// May be we need a new data structure, category id to slide definitions
1324
		// for now
19 naveen 1325
		List<SlideDefinition> matchingSlides = new ArrayList<SlideDefinition>();
32 naveen 1326
 
1327
		List<CategorySlideDefinition> csDefs = this.getCategorySlideDefinitions(
1328
				categoryID);
1329
 
1330
		for(CategorySlideDefinition csDef : csDefs) {
1331
			SlideDefinition sDef = this.getSlideDefinition(
1332
					csDef.getSlideDefintionID());
19 naveen 1333
 
32 naveen 1334
			matchingSlides.add(sDef);
19 naveen 1335
		}
1336
 
1337
		return matchingSlides;
1338
	}
49 naveen 1339
 
19 naveen 1340
	/**
49 naveen 1341
	 * Returns list of SlideDefinition objects for a category and editorial 
1342
	 * importance value
19 naveen 1343
	 * 
18 naveen 1344
	 * @param categoryID
1345
	 * @param EditorialImportance imp
1346
	 * @return List<SlideDefinition>
1347
	 * @throws Exception 
1348
	 */
1349
	public List<SlideDefinition> getSlides(long categoryID, 
1350
			EditorialImportance imp) 
1351
		throws Exception {
1352
 
1353
		List<CategorySlideDefinition> catSlideDefs = 
1354
			this.getCategorySlideDefinitions(categoryID);
1355
 
1356
		Iterator<CategorySlideDefinition> itCatSlideDefs = 
1357
			catSlideDefs.iterator();
1358
 
1359
		List<SlideDefinition> slideDefs = new ArrayList<SlideDefinition>();
1360
		while(itCatSlideDefs.hasNext()) {
1361
			CategorySlideDefinition catSlideDef = itCatSlideDefs.next();
1362
			if(catSlideDef.getEditorialImportance() == imp) {
1363
				long slideDefID = catSlideDef.getSlideDefintionID();
1364
				slideDefs.add(this.getSlideDefinition(slideDefID));
1365
			}
1366
		}
1367
		return slideDefs;
1368
	}
1369
 
1370
	/**
49 naveen 1371
	 * Returns all FeatureDefinition object in database
18 naveen 1372
	 * 
1373
	 * @return Map<Long, FeatureDefinition>
1374
	 * @throws Exception
1375
	 */
1050 rajveer 1376
	public Map<Long, FeatureDefinition> getFeatureDefinitions(){
1377
		return this.featureDefinitions;
1378
	}
1379
 
1380
 
1381
	/**
1382
	 * 
1383
	 * @param defType
1384
	 * @return
1385
	 */
1386
	private Map<Long, FeatureDefinition> convertFeatureDefinitions(
1387
			DefinitionType defType) {
18 naveen 1388
 
1050 rajveer 1389
		Map<Long, FeatureDefinition> defs = 
1390
			new HashMap<Long, FeatureDefinition>();
1391
 
1392
		List<FeatureDefinitionType> jaxbDefs = defType.getFeatureDefinition();
1393
		Iterator<FeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
1394
 
1395
		// Feature definitions
1396
		while(itjaxbDefs.hasNext()) {
1397
			FeatureDefinitionType jaxbDef = itjaxbDefs.next();
1314 rajveer 1398
			Utils.info("******"+ jaxbDef.getID());
18 naveen 1399
 
1050 rajveer 1400
			//Utils.info("Feature label=" + jaxbDef.getLabel());
1401
			FeatureDefinition def = new FeatureDefinition(jaxbDef.getID(),
1402
					jaxbDef.getLabel());
1403
			def.setAllowsBlank(jaxbDef.isCanbeBlank());
1404
			def.setDescription(jaxbDef.getDescription());
1405
 
1406
			// Bullet Definition
1407
			BulletDefinitionType jaxbBulletDef = jaxbDef.getBulletDefinition();
1408
			if(jaxbBulletDef != null) {
1409
				def.setBulletDefinition(this.convertBulletDefinition(
1410
						jaxbBulletDef));
1411
			}
1412
 
1413
			Long normRuleDefID = jaxbDef.getNormalizationRuleDefinitionID();
1414
			if(normRuleDefID != null) {
1415
				def.setNormalizationRuleDefinitionID(normRuleDefID.longValue());
1416
			}
1417
			Utils.info("def=" + def);
1418
 
2170 rajveer 1419
			Long helpDocDefID = jaxbDef.getHelpDocDefinitionID();
1420
            if(helpDocDefID != null) {
1421
                def.setHelpDocDefinitionID(helpDocDefID.longValue());
1422
            }
1423
            Utils.info("def=" + def);
1424
 
1050 rajveer 1425
			defs.put(new Long(jaxbDef.getID()), def);
18 naveen 1426
		}
1050 rajveer 1427
 
1428
		return defs;
18 naveen 1429
	}
1050 rajveer 1430
 
19 naveen 1431
 
10 shop2020 1432
	/**
1050 rajveer 1433
	 * 
1434
	 * @param jaxbDef BulletDefinitionType
1435
	 * @return BulletDefinition
1436
	 */
1437
	private BulletDefinition convertBulletDefinition(
1438
			BulletDefinitionType jaxbDef) {
1439
 
1440
		BulletDefinition def = new BulletDefinition(
1441
				jaxbDef.getDatatypeDefinitionID());
1442
 
1443
		List<Long> unitIDs = jaxbDef.getUnitID();
1444
		if(unitIDs != null && !unitIDs.isEmpty()) {
1445
			def.setUnitIDs(unitIDs);
1446
		}
1447
		Utils.info("jaxbDef.isIsMultivalue=" + jaxbDef.isIsMultivalue());
1448
 
1449
		def.setMultivalue(jaxbDef.isIsMultivalue());
1450
		def.setLearned(jaxbDef.isIsLearned());
1451
		def.setDescription(jaxbDef.getDescription());
1452
 
1453
		return def;
1454
	}
1455
 
1456
 
1457
	/**
49 naveen 1458
	 * Returns all FeatureDefinition objects for a slide
18 naveen 1459
	 * 
19 naveen 1460
	 * @param slideID
1461
	 * @return List<FeatureDefinition> 
1462
	 * @throws Exception
1463
	 */
1464
	public List<FeatureDefinition> getFeatureDefinitions(long slideID) 
1465
		throws Exception {
1466
		List<FeatureDefinition> featureDefs = 
1467
			new ArrayList<FeatureDefinition>();
1468
 
1469
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1470
		List<SlideFeatureDefinition> slideFeatureDefs = 
1471
			slideDef.getSlideFeatureDefinitions();
1472
 
1473
		for(int i=0; i<slideFeatureDefs.size(); i++) {
1474
			featureDefs.add(this.getFeatureDefinition(
1475
					slideFeatureDefs.get(i).getFeatureDefintionID()));
1476
		}
1477
 
1478
		return featureDefs;
1479
	}
1480
 
1481
	/**
49 naveen 1482
	 * Returns list of FeatureDefinition objects for a slide given editorial 
1483
	 * importance
19 naveen 1484
	 * 
1485
	 * @param slideID
49 naveen 1486
	 * @param imp Editorial Importance enum object
19 naveen 1487
	 * @return List<FeatureDefinition>
1488
	 * @throws Exception
1489
	 */
1490
	public List<FeatureDefinition> getFeatureDefinitions(long slideID, 
1491
			EditorialImportance imp)  throws Exception {
1492
		List<FeatureDefinition> featureDefs = 
1493
			new ArrayList<FeatureDefinition>();
1494
 
1495
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1496
		List<SlideFeatureDefinition> slideFeatureDefs = 
1497
			slideDef.getSlideFeatureDefinitions();
1498
 
1499
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
1500
			if(slideFeatureDef.getEditorialImportance() == imp) {
1501
				featureDefs.add(this.getFeatureDefinition(
1502
						slideFeatureDef.getFeatureDefintionID()));
1503
			}
1504
		}
1505
 
1506
		return featureDefs;
1507
	}
1508
 
1509
	/**
49 naveen 1510
	 * Resolves Feature Definition ID into FeatureDefinition object
19 naveen 1511
	 * 
49 naveen 1512
	 * @param id Feature Definition ID 
19 naveen 1513
	 * @return FeatureDefinition
18 naveen 1514
	 * @throws Exception
10 shop2020 1515
	 */
18 naveen 1516
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
1517
 
1518
		// Initialize 
1519
		if(this.featureDefinitions == null) {
1520
			this.getFeatureDefinitions();
1521
		}
1522
 
1523
		return this.featureDefinitions.get(new Long(id));
1524
	}	
19 naveen 1525
 
1526
	/**
49 naveen 1527
	 * Returns matching FeatureDefinition object for slide ID and feature label.
1528
	 * Label matching is case insensitive.
19 naveen 1529
	 * 
49 naveen 1530
	 * @param slideID Slide ID
1531
	 * @param featureLabel label to match, case is ignored
19 naveen 1532
	 * @return FeatureDefinition 
1533
	 * @throws Exception
1534
	 */
1535
	public FeatureDefinition getFeatureDefinition(long slideID, 
1536
			String featureLabel) throws Exception {
1537
		FeatureDefinition featureDef = null;
1538
 
1539
		SlideDefinition slideDef = this.getSlideDefinition(slideID);
1540
		for(SlideFeatureDefinition slideFeatureDef : 
1541
			slideDef.getSlideFeatureDefinitions()) {
1542
 
1543
			long featureDefID = slideFeatureDef.getFeatureDefintionID();
1544
 
1545
			FeatureDefinition thisFeatureDef = this.getFeatureDefinition(
1546
					featureDefID);
1547
 
28 naveen 1548
			if(featureLabel.equalsIgnoreCase(thisFeatureDef.getLabel())) {
19 naveen 1549
				featureDef = thisFeatureDef;
1550
			}
1551
		}
1552
 
1553
		return featureDef;
1554
	}
24 naveen 1555
 
1556
	/**
49 naveen 1557
	 * Returns all EnumValue objects in the database
1558
	 * 
24 naveen 1559
	 * @return the enumValues
1560
	 * @throws Exception 
1561
	 */
1562
	public Map<Long, EnumValue> getEnumValues() throws Exception {
1563
		return this.enumValues;
1564
	}
19 naveen 1565
 
1050 rajveer 1566
 
24 naveen 1567
	/**
49 naveen 1568
	 * Resolves Enum value ID into EnumValue object
24 naveen 1569
	 * 
1570
	 * @param enumValueID
1571
	 * @return EnumValue
1572
	 * @throws Exception
1573
	 */
1574
	public EnumValue getEnumValue(long enumValueID) throws Exception {
1575
		return this.enumValues.get(new Long(enumValueID));
1576
	}
2170 rajveer 1577
 
62 naveen 1578
	/**
1579
	 * Returns all FacetDefinition objects in the database
1580
	 * 
1581
	 * @return Map Null if facet definitions are not imported into definitions 
1582
	 * db (serialized java objects)
1583
	 * 
1584
	 * @throws Exception 
1585
	 */
1050 rajveer 1586
	public Map<Long, FacetDefinition> getFacetDefinitions(){
62 naveen 1587
		return this.facetDefinitions;
1588
	}
1589
 
1590
	/**
1314 rajveer 1591
	 * Get List of Facets for a given slide.
1592
	 * 
1593
	 * @return
1594
	 */
1595
	public Map<Long, List<FacetDefinition>> getSlideFacetDefinitions(){
1596
		return slideFacetDefinitions;
1597
	}
1598
	/**
62 naveen 1599
	 * Resolves Facet Definition ID into FacetDefinition object
1600
	 * 
1601
	 * @param facetDefinitionID
1602
	 * @return FacetDefinition
1603
	 * @throws Exception
1604
	 */
1605
	public FacetDefinition getFacetDefinition(long facetDefinitionID) 
1606
		throws Exception {
1607
 
1608
		if(this.facetDefinitions == null) {
1609
			this.getFacetDefinitions();
1610
		}
1611
 
1612
		return this.facetDefinitions.get(new Long(facetDefinitionID));
1613
	}
1614
 
1615
	/**
1616
	 * Utility method to get Expanded version of ExpandedFacetDefinition object 
1617
	 * 
1618
	 * @param facetDefinitionID
1619
	 * @return ExpandedFacetDefinition
1620
	 * @throws Exception
1621
	 */
1314 rajveer 1622
	/*
62 naveen 1623
	public ExpandedFacetDefinition getExpandedFacetDefinition(
1624
			long facetDefinitionID) throws Exception {
1625
 
1626
		FacetDefinition facetDefinition = 
1627
			this.getFacetDefinition(facetDefinitionID);
1628
 
1629
		ExpandedFacetDefinition expFacetDefinition = 
1630
			new ExpandedFacetDefinition(facetDefinition);
1631
 
1632
		return expFacetDefinition;
1633
	}
1314 rajveer 1634
	*/
62 naveen 1635
	/**
1636
	 * Returns all CategoryFacetDefinition objects in the database
1637
	 * 
1638
	 * @return Map Null if category facet definitions are not imported into 
1639
	 * definitions db (serialized java objects)
1640
	 * 
1641
	 * @throws Exception 
1642
	 */
1050 rajveer 1643
	public Map<Long, CategoryFacetDefinition> getCategoryFacetDefinitions(){
62 naveen 1644
		return this.categoryFacetDefinitions;
1645
	}
1646
 
1647
	/**
1648
	 * Resolves Category-Facet Definition ID into CategoryFacetDefinition object
1649
	 * 
1650
	 * @param categoryID
1651
	 * @return CategoryFacetDefinition
1652
	 * @throws Exception
1653
	 */
1050 rajveer 1654
	public CategoryFacetDefinition getCategoryFacetDefinition(long categoryID){
1655
		return this.categoryFacetDefinitions.get(new Long(categoryID));
62 naveen 1656
	}
1657
 
1050 rajveer 1658
 
62 naveen 1659
	/**
1660
	 * Utility method to get Expanded version of CategoryFacetDefinition object 
1661
	 * 
1662
	 * @param categoryID
1663
	 * @return ExpandedCategoryFacetDefinition
1664
	 * @throws Exception
1665
	 */
1666
	public ExpandedCategoryFacetDefinition getExpandedCategoryFacetDefinition(
1667
			long categoryID) throws Exception  {
1668
		CategoryFacetDefinition categoryFacetDef = 
1669
			this.getCategoryFacetDefinition(categoryID);
1670
 
1671
		ExpandedCategoryFacetDefinition expCategoryFacetDef = 
1672
			new ExpandedCategoryFacetDefinition(categoryFacetDef);
1673
 
1674
		return expCategoryFacetDef;
1675
	}
1676
 
1677
	/**
1678
	 * Returns all IR Data RuleDefintion objects in the database
1679
	 * 
1680
	 * @return Map Null if IR data rule definitions are not imported into 
1681
	 * definitions db (serialized java objects)
1682
	 * 
1683
	 * @throws Exception 
1684
	 */
1050 rajveer 1685
	public Map<Long, RuleDefinition> getIrDataRuleDefinitions(){
62 naveen 1686
		return this.irDataRuleDefinitions;
1687
	}
1688
 
1689
	/**
1690
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
1691
	 * 
1692
	 * @param irDataRuleDefinitionID
1693
	 * @return RuleDefinition
1694
	 * @throws Exception
1695
	 */
1050 rajveer 1696
	public RuleDefinition getIrDataRuleDefinition(long irDataRuleDefinitionID){
62 naveen 1697
		return this.irDataRuleDefinitions.get(new Long(irDataRuleDefinitionID));
1698
	}
1699
 
1700
	/**
1701
	 * Returns all IR Meta Data RuleDefintion objects in the database
1702
	 * 
1703
	 * @return Map Null if IR meta-data rule definitions are not imported into 
1704
	 * definitions db (serialized java objects)
1705
	 * 
1706
	 * @throws Exception 
1707
	 */
1050 rajveer 1708
	public Map<Long, RuleDefinition> getIrMetaDataRuleDefinitions(){
62 naveen 1709
		return this.irMetaDataRuleDefinitions;
1710
	}
1711
 
1712
	/**
1713
	 * Resolves IR Meta Data Rule Definition ID into RuleDefinition object
1714
	 * 
1715
	 * @param irMetaDataRuleDefinitionID
1716
	 * @return RuleDefinition
1717
	 * @throws Exception
1718
	 */
1050 rajveer 1719
	public RuleDefinition getIrMetaDataRuleDefinition(long irMetaDataRuleDefinitionID) {
1720
		return this.irMetaDataRuleDefinitions.get(new Long(irMetaDataRuleDefinitionID));
62 naveen 1721
	}
70 naveen 1722
 
1723
	/**
1724
	 * Returns all Comparison RuleDefintion objects in the database
1725
	 * 
1726
	 * @return Map Null if Comparison rule definitions are not imported into 
1727
	 * definitions db (serialized java objects)
1728
	 * 
1729
	 * @throws Exception 
1730
	 */
1050 rajveer 1731
	public Map<Long, CMPRuleDefinition> getComparisonRuleDefinitions(){
70 naveen 1732
		return this.cmpRuleDefinitions;
1733
	}
1734
 
1735
	/**
1736
	 * Resolves IR Data Rule Definition ID into RuleDefinition object
1737
	 * 
1738
	 * @param cmpRuleDefinitionID
1739
	 * @return CMPRuleDefinition
1740
	 * @throws Exception
1741
	 */
1050 rajveer 1742
	public CMPRuleDefinition getComparisonRuleDefinition(long cmpRuleDefinitionID) {
70 naveen 1743
		return this.cmpRuleDefinitions.get(new Long(cmpRuleDefinitionID));
1744
	}
1745
 
1746
 
1747
	/**
1748
	 * Returns all ComparisonSlideRuleDefintion objects in the database
1749
	 * 
1750
	 * @return Map Null if Comparison slide-rule definitions are not imported 
1751
	 * into definitions db (serialized java objects)
1752
	 * 
1753
	 * @throws Exception 
1754
	 */
1050 rajveer 1755
	public Map<Long, CMPSlideRuleDefinition> getComparisonSlideRuleDefinitions() {
70 naveen 1756
		return this.cmpSlideRuleDefinitions;
1757
	}
1758
 
1759
	/**
1760
	 * Resolves Category ID into List of CMPSlideRuleDefinition object
1761
	 * 
1762
	 * @param categoryID
1763
	 * @return List<CMPSlideRuleDefinition> 
1764
	 * @throws Exception
1765
	 */
1050 rajveer 1766
	public CMPSlideRuleDefinition getComparisonSlideRuleDefinition(long slideDefinitionID) {
70 naveen 1767
		return this.cmpSlideRuleDefinitions.get(new Long(slideDefinitionID));
1768
	}
1769
 
1770
 
1771
	/**
1772
	 * Resolves Slide Definition ID into ExpandedCMPSlideRuleDefinition object
1773
	 * 
1774
	 * @param categoryID
1775
	 * @return ExpandedCMPSlideRuleDefinition 
1776
	 * @throws Exception
1777
	 */
1050 rajveer 1778
	public ExpandedCMPSlideRuleDefinition getExpandedComparisonSlideRuleDefinition(long slideDefinitionID) throws Exception{
71 naveen 1779
		Utils.info("slideDefinitionID=" + slideDefinitionID);
70 naveen 1780
 
1050 rajveer 1781
		CMPSlideRuleDefinition cmpSlideRuleDef = this.getComparisonSlideRuleDefinition(slideDefinitionID);
70 naveen 1782
 
71 naveen 1783
		if(cmpSlideRuleDef == null) {
1784
			return null;
1785
		}
1786
 
1050 rajveer 1787
		ExpandedCMPSlideRuleDefinition expDef = new ExpandedCMPSlideRuleDefinition(cmpSlideRuleDef);
70 naveen 1788
		return expDef;
1789
	}
72 naveen 1790
 
70 naveen 1791
 
72 naveen 1792
	/**
1793
	 * Returns all ComparisonSlideRuleDefintion objects in the database
1794
	 * 
1795
	 * @return Map Null if Comparison slide-rule definitions are not imported 
1796
	 * into definitions db (serialized java objects)
1797
	 * 
1798
	 * @throws Exception 
1799
	 */
1050 rajveer 1800
 
1801
	public Map<Long, List<CMPBucketDefinition>> getComparisonBucketDefinitions(){
72 naveen 1802
		return this.cmpBucketDefinitions;
1803
	}
1804
 
1805
	/**
1806
	 * Resolves Category ID into List of CMPBucketDefinition object
1807
	 * 
1808
	 * @param categoryID
1809
	 * @return List<CMPBucketDefinition> 
1810
	 * @throws Exception
1811
	 */
1050 rajveer 1812
	public List<CMPBucketDefinition> getComparisonBucketDefinitions(long categoryID) {
72 naveen 1813
		return this.cmpBucketDefinitions.get(new Long(categoryID));
1814
	}
1815
 
1816
	/**
1817
	 * Resolve comparison bucket name for a slide in a particular category
1818
	 * 
1819
	 * @param categoryID
1820
	 * @param slideDefintionID
1821
	 * @return Bucket Name if found else Null
1822
	 * @throws Exception 
1823
	 */
1824
	public String getComparisonBucketName(long categoryID, 
1825
			long slideDefinitionID) throws Exception {
1826
		List<CMPBucketDefinition> cmpBuckets = 
1827
			this.getComparisonBucketDefinitions(categoryID);
1949 rajveer 1828
		if(cmpBuckets == null){
1829
		    return null;
1830
		}
72 naveen 1831
		for (CMPBucketDefinition cmpBucket : cmpBuckets) {
1832
			List<Long> slideDefinitionIDs = cmpBucket.getSlideDefinitionIDs();
1833
 
1834
			if(slideDefinitionIDs.contains(new Long(slideDefinitionID))) {
1835
				return cmpBucket.getName();
1836
			}
1837
		}
1838
		return null;
1839
	}
83 naveen 1840
 
1841
	/**
1842
	 * Returns list of facet definition IDs for given category ID
1843
	 * 
1844
	 * @param categoryID
1845
	 * @return list of facet definition IDs
1846
	 * @throws Exception 
1847
	 */
1848
	public List<Long> getFacetDefinitionIDs(long categoryID) throws Exception {
1849
		List<Long> facetDefIDs = new ArrayList<Long>();
1850
 
1851
		CategoryFacetDefinition categoryFacetDef = 
1852
			this.getCategoryFacetDefinition(categoryID);
516 rajveer 1853
		if(categoryFacetDef == null)
1854
			return null;
1314 rajveer 1855
		List<FacetDefinition> facetDefs = 
1856
			categoryFacetDef.getFacetDefinitions();
83 naveen 1857
 
1314 rajveer 1858
		for(FacetDefinition facetDef : facetDefs) {
1859
			facetDefIDs.add(new Long(facetDef.getID()));
83 naveen 1860
		}
1861
 
1862
		return facetDefIDs;
1863
	}
1864
 
1865
	/**
1866
	 * Returns list of feature definition IDs for given category ID
1867
	 * 
1868
	 * @param categoryID
1869
	 * @return list of feature definition IDs
1870
	 * @throws Exception 
1871
	 */
1872
	public List<Long> getFeatureDefinitionIDs(long categoryID) 
1873
		throws Exception {
1874
 
1875
		List<Long> featureDefIDs = new ArrayList<Long>();
1876
 
1877
		List<SlideDefinition> slideDefs = this.getSlideDefinitions(categoryID);
1878
 
1879
		for(SlideDefinition slideDef : slideDefs) {
1880
			List<Long> slideFeatureDefIDs = 
1881
				this.getFeatureDefintionIDs(slideDef);
1882
 
1883
			featureDefIDs.addAll(slideFeatureDefIDs);
1884
		}
1885
 
1886
		return featureDefIDs;
1887
	}
1888
 
1889
	/**
1890
	 * Returns list of feature definition IDs for given slide definition ID
1891
	 * 
1892
	 * @param slideDef
1893
	 * @return list of feature definition IDs
1894
	 */
1895
	public List<Long> getFeatureDefintionIDs(SlideDefinition slideDef) {
1896
		List<Long> featureDefIDs = new ArrayList<Long>();
1897
 
1898
		List<SlideFeatureDefinition> slideFeatureDefs = 
1899
			slideDef.getSlideFeatureDefinitions();
1900
 
1901
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
1050 rajveer 1902
			featureDefIDs.add(new Long(slideFeatureDef.getFeatureDefintionID()));
83 naveen 1903
		}
1904
 
1905
		return featureDefIDs;
1906
	}
88 naveen 1907
 
1908
	/**
1909
	 * 
1910
	 * @param borrowedSlideDefID
1911
	 * @return
1912
	 * @throws Exception 
1913
	 */
1914
	public boolean isValidSlideDefinitionID(long borrowedSlideDefID) 
1915
		throws Exception {
1916
		this.getSlideDefinitions();
1917
 
1918
		return this.slideDefinitions.containsKey(new Long(borrowedSlideDefID));
1919
	}
1920
 
1921
	/**
1922
	 * Returns Facet-Rule definition object defined for a category and 
1923
	 * slide definition
1924
	 * 
1925
	 * @param borrowedCategoryID
1926
	 * @param slideDefID
1927
	 * @return FacetRuleDefinition 
1928
	 * @throws Exception 
1929
	 */
1314 rajveer 1930
	/*
88 naveen 1931
	public FacetRuleDefinition getFacetRuleDefinitionForSlide(long categoryID,
1932
			long slideDefinitionID) throws Exception {
1933
		CategoryFacetDefinition categoryFacetDef = 
1934
			this.getCategoryFacetDefinition(categoryID);
1073 chandransh 1935
		//FIXME Quick fix. Need to investigate
1936
		if(categoryFacetDef == null){
1937
			return null;
1938
		}
88 naveen 1939
		List<FacetRuleDefinition> facetRuleDefs = 
1940
			categoryFacetDef.getFacetRuleDefinitions();
1941
 
1942
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1943
			if(facetRuleDef.getSlideDefinitionID() == slideDefinitionID) {
1944
				return facetRuleDef;
1945
			}
1946
		}
1947
 
1948
		return null;
1949
	}
1314 rajveer 1950
	*/
88 naveen 1951
	/**
1952
	 * Returns Facet-Rule definition object defined for a category and 
1953
	 * feature definition
1954
	 * 
1955
	 * @param categoryID
1956
	 * @param featureDefinitionID
1957
	 * @return FacetRuleDefinition
1958
	 * @throws Exception
1959
	 */
1314 rajveer 1960
 
1961
/*
88 naveen 1962
	public FacetRuleDefinition getFacetRuleDefinitionForFeature(long categoryID,
1963
			long featureDefinitionID) throws Exception {
1964
		CategoryFacetDefinition categoryFacetDef = 
1965
			this.getCategoryFacetDefinition(categoryID);
1074 chandransh 1966
		if(categoryFacetDef == null){
1967
			return null;
1968
		}
88 naveen 1969
		List<FacetRuleDefinition> facetRuleDefs = 
1970
			categoryFacetDef.getFacetRuleDefinitions();
1971
 
1972
		for(FacetRuleDefinition facetRuleDef : facetRuleDefs) {
1973
			if(facetRuleDef.getFeatureDefinitionID() == featureDefinitionID) {
1974
				return facetRuleDef;
1975
			}
1976
		}
1977
 
1978
		return null;
1979
	}
1314 rajveer 1980
*/
102 naveen 1981
	/**
1982
	 * Returns all normalization rule defined
1983
	 * 
1984
	 * @return Map<Long, RuleDefinition> 
1985
	 * @throws Exception 
1986
	 */
1050 rajveer 1987
	public Map<Long, RuleDefinition> getNormalizationRules() {
102 naveen 1988
		return this.normalizationRuleDefinitions;
1989
	}
1990
 
1991
 
1992
	/**
1993
	 * True if feature has normalization rule defined
1994
	 * 
1995
	 * @param feature
1996
	 * @return boolean 
1997
	 * @throws Exception 
1998
	 */
1999
	public boolean needsNormalization(long featureDefinitionID) 
2000
		throws Exception {
2001
		this.getFeatureDefinitions();
2002
 
2003
		FeatureDefinition featureDef = 
2004
			this.featureDefinitions.get(new Long(featureDefinitionID));
2005
 
2006
		if(featureDef.getNormalizationRuleDefinitionID() != 0L) {
2007
			return true;
2008
		}
2009
 
2010
		return false;
2011
	}
2012
 
2013
	/**
2014
	 * Returns normalization rule definition for rule definition ID
2015
	 * 
2016
	 * @param ruleID
2017
	 * @return RuleDefinition 
2018
	 * @throws Exception 
2019
	 */
1050 rajveer 2020
	public RuleDefinition getNormalizationRuleDefinition(long ruleDefinitionID){
2021
		return this.normalizationRuleDefinitions.get(new Long(ruleDefinitionID));
102 naveen 2022
	}
2170 rajveer 2023
 
2024
	public HelpDocDefinition getHelpDocDefinition(long helpDocDefinitionID){
2025
	    return this.helpDocDefinitions.get(helpDocDefinitionID);
2026
	}
10 shop2020 2027
}