Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 shop2020 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.util;
5
 
16 naveen 6
import in.shop2020.metamodel.definitions.BulletDefinition;
45 naveen 7
import in.shop2020.metamodel.definitions.Catalog;
10 shop2020 8
import in.shop2020.metamodel.definitions.Category;
9
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
16 naveen 10
import in.shop2020.metamodel.definitions.CompositeDefinition;
11
import in.shop2020.metamodel.definitions.CompositePartDefinition;
12
import in.shop2020.metamodel.definitions.DatatypeDefinition;
45 naveen 13
import in.shop2020.metamodel.definitions.DefinitionsContainer;
10 shop2020 14
import in.shop2020.metamodel.definitions.EditorialImportance;
16 naveen 15
import in.shop2020.metamodel.definitions.EnumDefinition;
16
import in.shop2020.metamodel.definitions.EnumValue;
17
import in.shop2020.metamodel.definitions.FeatureDefinition;
18
import in.shop2020.metamodel.definitions.SlideDefinition;
19
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
10 shop2020 20
import in.shop2020.metamodel.definitions.Unit;
16 naveen 21
import in.shop2020.metamodel.jaxb.BulletDefinitionType;
10 shop2020 22
import in.shop2020.metamodel.jaxb.CategorySlideDefinitionType;
23
import in.shop2020.metamodel.jaxb.CategoryType;
16 naveen 24
import in.shop2020.metamodel.jaxb.CompositeDefinitionType;
25
import in.shop2020.metamodel.jaxb.CompositePartDefinitionType;
26
import in.shop2020.metamodel.jaxb.DatatypeDefinitionType;
10 shop2020 27
import in.shop2020.metamodel.jaxb.DefinitionType;
28
import in.shop2020.metamodel.jaxb.EditorialImportanceType;
16 naveen 29
import in.shop2020.metamodel.jaxb.EnumDefinitionType;
30
import in.shop2020.metamodel.jaxb.EnumValueType;
31
import in.shop2020.metamodel.jaxb.FeatureDefinitionType;
32
import in.shop2020.metamodel.jaxb.SlideDefinitionType;
33
import in.shop2020.metamodel.jaxb.SlideFeatureDefinitionType;
10 shop2020 34
import in.shop2020.metamodel.jaxb.UnitType;
18 naveen 35
import in.shop2020.util.Utils;
10 shop2020 36
 
37
import java.io.FileInputStream;
16 naveen 38
import java.util.ArrayList;
10 shop2020 39
import java.util.HashMap;
40
import java.util.Iterator;
41
import java.util.List;
42
import java.util.Map;
24 naveen 43
import java.util.TreeMap;
10 shop2020 44
 
45
import javax.xml.bind.JAXBContext;
46
import javax.xml.bind.JAXBElement;
47
import javax.xml.bind.Unmarshaller;
48
 
49
import org.apache.commons.lang.ArrayUtils;
50
import org.apache.commons.lang.StringUtils;
51
 
52
/**
51 naveen 53
 * Command line utility that imports model properties defined in XML
54
 * 
17 naveen 55
 * MM - Meta-Model Tool
10 shop2020 56
 * 
51 naveen 57
 * It can be used to do following things
58
 * 
59
 * - Import
60
 * 	 - Datatype definitions
61
 * 	 - Feature definitions
62
 * 	 - Slide definitions
63
 * 	 - Categories
64
 * 
65
 * - Show
66
 * 	 - Datatype definitions
67
 * 	 - Feature definitions
68
 * 	 - Slide definitions
69
 * 	 - Categories
70
 * 
71
 * - Show all definition objects that define a category 
72
 * 
73
 * 
10 shop2020 74
 * @author naveen
75
 *
76
 */
77
public class MM {
49 naveen 78
	/**
79
	 * 
80
	 */
16 naveen 81
	public static final String DEFINITIONS_SRC_PATH = 
82
		"/home/naveen/workspace/eclipse/webapp/src/xml/model/";
34 naveen 83
 
43 naveen 84
	// LOCAL
49 naveen 85
	/**
86
	 * 
87
	 */
16 naveen 88
	public static final String DEFINITIONS_DB_PATH = 
26 naveen 89
		"/home/naveen/workspace/eclipse/db/definitions/";
49 naveen 90
 
91
	/**
92
	 * 
93
	 */
16 naveen 94
	public static final String ENTITIES_DB_PATH = 
26 naveen 95
		"/home/naveen/workspace/eclipse/db/entities/";
10 shop2020 96
 
34 naveen 97
	/** WEB
98
	public static final String DEFINITIONS_DB_PATH = 
99
		"/var/lib/tomcat6/webapps/shop2020/db/definitions/";
100
	public static final String ENTITIES_DB_PATH = 
101
		"/var/lib/tomcat6/webapps/shop2020/db/entities/";
102
	*/
43 naveen 103
 
104
	/** Validation tool
105
	public static final String DEFINITIONS_DB_PATH = 
106
		"./db/definitions/";
107
	public static final String ENTITIES_DB_PATH = 
108
		"./db/entities/";
109
	*/
34 naveen 110
 
49 naveen 111
	/**
112
	 * 
113
	 */
10 shop2020 114
	private String definitionSetName;
49 naveen 115
 
116
	/**
117
	 * 
118
	 */
10 shop2020 119
	private String srcFile;
49 naveen 120
 
121
	/**
122
	 * 
123
	 */
10 shop2020 124
	private String dbFile;
125
 
126
	/**
51 naveen 127
	 * Usage: MM [show|import|showcategory] [units|datatypedefinitions|featuredefinitions|slidedefinitions|categories] {Category ID}
128
	 * 
10 shop2020 129
	 * @param args
130
	 */
131
	public static void main(String[] args) throws Exception {
16 naveen 132
		String[] definitionSetNames = new String[] {"units", 
133
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
134
				"categories"};
10 shop2020 135
 
45 naveen 136
		String[] commands = new String[] {"show", "import", "showcategory"};
10 shop2020 137
 
16 naveen 138
		String usage = "Usage: MM ["+ StringUtils.join(commands, "|") +"] ["+ 
45 naveen 139
			StringUtils.join(definitionSetNames, "|") + "] {Category ID}";
16 naveen 140
 
10 shop2020 141
		if(args.length < 2) {
142
			System.out.println(usage);
143
			System.exit(-1);
144
		}
42 naveen 145
		Utils.info("MM "+ args[0] + " " + args[1]);
17 naveen 146
 
10 shop2020 147
		String inputCommand = args[0];
148
 
149
		if(!ArrayUtils.contains(commands, inputCommand)) {
150
			System.out.println(usage);
151
			System.exit(-1);
152
		}
153
 
45 naveen 154
		if(inputCommand.equals("show") || inputCommand.endsWith("import")) {
155
			String inputDefinitionSet = args[1];
156
			if(!ArrayUtils.contains(definitionSetNames, inputDefinitionSet)) {
157
				System.out.println(usage);
158
				System.exit(-1);
159
			}
160
 
161
			MM mm = new MM(inputDefinitionSet);
162
			if(inputCommand.equals("import")) {
163
				mm.importDefinitionSet();
164
			}
165
			else if(inputCommand.equals("show")) {
166
				mm.showDefinitionSet();
167
			}
10 shop2020 168
		}
169
 
45 naveen 170
		if(inputCommand.equals("showcategory")) {
171
			String categoryID = args[1];
172
			long catID = 0;
173
			try {
174
				catID = Long.parseLong(categoryID);
175
			} 
176
			catch (NumberFormatException nfe) {
177
				System.out.println("Invalid category ID");
178
				System.exit(-1);
179
			}
180
 
181
			MM mm = new MM();
182
			mm.showCategory(catID);
10 shop2020 183
		}
184
	}
185
 
186
	/**
187
	 * 
45 naveen 188
	 */
189
	public MM() {
190
	}
191
 
192
	/**
193
	 * 
10 shop2020 194
	 * @param definitionSet
195
	 */
196
	public MM(String definitionSetName) {
197
		this.definitionSetName = definitionSetName;
198
		this.srcFile = DEFINITIONS_SRC_PATH + this.definitionSetName + ".xml";
199
		this.dbFile = DEFINITIONS_DB_PATH + this.definitionSetName + ".ser";
200
	}
201
 
202
	/**
203
	 * 
45 naveen 204
	 * @param categoryID
205
	 * @throws Exception 
10 shop2020 206
	 */
45 naveen 207
	public void showCategory(long categoryID) throws Exception {
208
		DefinitionsContainer defs = 
209
			Catalog.getInstance().getDefinitionsContainer();
210
 
211
		ExpandedCategory expCategory = defs.getExpandedCategory(categoryID);
212
 
213
		Utils.info(expCategory);
214
	}
215
 
216
	/**
217
	 * 
218
	 */
10 shop2020 219
	@SuppressWarnings("unchecked")
220
	public void importDefinitionSet() throws Exception {
221
		DefinitionType defType = this.unmarshallSrcFile(this.srcFile);
16 naveen 222
		Object objectToStore = null;
10 shop2020 223
 
224
		// Units
225
		if(this.definitionSetName.equals("units")) {
226
			Map unitsMap = this.convertUnits(defType);
16 naveen 227
			objectToStore = unitsMap;
10 shop2020 228
		}
229
 
230
		// Categories
231
		else if(this.definitionSetName.equals("categories")) {
232
			Map<Long, Category> categoriesMap = new HashMap<Long, Category>();
233
			Category root = this.convertCategories(defType, categoriesMap);
42 naveen 234
			//Utils.info(categoriesMap);
235
			//Utils.info(root);
10 shop2020 236
			//System.exit(0);
237
 
238
			// Tree
16 naveen 239
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
240
				".ser";
241
 
10 shop2020 242
			if(root != null) {
17 naveen 243
				DBUtils.store(root, categoryTreeDBFile);
10 shop2020 244
			}
245
 
246
			// Map
16 naveen 247
			objectToStore = categoriesMap;
10 shop2020 248
		}
16 naveen 249
 
250
		// Datatype Definitions
251
		else if(this.definitionSetName.equals("datatypedefinitions")) {
24 naveen 252
			Map<Long, DatatypeDefinition> datatypeDefsMap = 
253
				this.convertDatatypeDefinition(defType);
16 naveen 254
 
24 naveen 255
			// Store enum value id to value map separately
256
			String enumValueDBFile = DEFINITIONS_DB_PATH + "enumvalues" + 
257
				".ser";
258
 
259
			// RE-VISIT - May not be optimal
260
			Map<Long, EnumValue> enumValuesMap = new TreeMap<Long, EnumValue>();
261
			for(Long datatypeDefID : datatypeDefsMap.keySet()) {
262
				DatatypeDefinition datatypeDef = 
263
					datatypeDefsMap.get(datatypeDefID);
264
 
265
				if(datatypeDef instanceof EnumDefinition) {
266
					List<EnumValue> enumValues = 
267
						((EnumDefinition) datatypeDef).getEnumValues();
268
 
269
					for(EnumValue enumValue : enumValues) {
270
						enumValuesMap.put(new Long(enumValue.getID()), 
271
								enumValue);
272
					}
273
				}
274
			}
42 naveen 275
			Utils.info("enumValuesMap=" + enumValuesMap);
24 naveen 276
			DBUtils.store(enumValuesMap, enumValueDBFile);
277
 
16 naveen 278
			objectToStore = datatypeDefsMap;
279
		}
280
 
281
		// Feature Definitions
282
		else if(this.definitionSetName.equals("featuredefinitions")) {
283
			Map featureDefsMap = this.convertFeatureDefinitions(defType);
284
 
285
			objectToStore = featureDefsMap;
286
		}
287
 
288
		// Slide Definitions
289
		else if(this.definitionSetName.equals("slidedefinitions")) {
290
			Map slideDefsMap = this.convertSlideDefinitions(defType);
291
 
292
			objectToStore = slideDefsMap;
293
		}
294
 
295
		if(objectToStore != null) {
17 naveen 296
			DBUtils.store(objectToStore, this.dbFile);
16 naveen 297
		}
10 shop2020 298
	}
299
 
300
	/**
301
	 * 
302
	 */
303
	public void showDefinitionSet() throws Exception {
17 naveen 304
		Object obj = DBUtils.read(this.dbFile);
42 naveen 305
		Utils.info(obj.toString());
10 shop2020 306
 
307
		if(this.definitionSetName.equals("categories")) {
16 naveen 308
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
309
				".ser";
310
 
17 naveen 311
			Category root = (Category)DBUtils.read(categoryTreeDBFile);
42 naveen 312
			Utils.info(root.toString());
313
			//Utils.info("root.getChildrenCategory().size: " + 
18 naveen 314
			//		root.getChildrenCategory().size());
10 shop2020 315
		}
316
	}
317
 
318
	/**
319
	 * 
320
	 * @return Map
321
	 */
16 naveen 322
	private Map<Long, SlideDefinition> convertSlideDefinitions(
323
			DefinitionType defType) {
324
 
325
		Map<Long, SlideDefinition> defs = 
326
			new HashMap<Long, SlideDefinition>();
327
 
328
		List<SlideDefinitionType> jaxbDefs = defType.getSlideDefinition();
329
		Iterator<SlideDefinitionType> itjaxbDefs = jaxbDefs.iterator();
330
 
331
		// Slide definitions
332
		while(itjaxbDefs.hasNext()) {
333
			SlideDefinitionType jaxbDef = itjaxbDefs.next();
334
 
42 naveen 335
			Utils.info("Slide label=" + jaxbDef.getLabel());
16 naveen 336
			SlideDefinition def = new SlideDefinition(jaxbDef.getID(),
337
					jaxbDef.getLabel());
338
			def.setDescription(jaxbDef.getDescription());
339
 
42 naveen 340
			// Children Slides
341
			Utils.info("jaxbDef.getChildSlideID=" + jaxbDef.getChildSlideID());
342
			def.setChildrenSlideDefinitionIDs(jaxbDef.getChildSlideID());
343
 
16 naveen 344
			// Slide Feature Definition
345
			List<SlideFeatureDefinitionType> jaxbSlideFeatureDefs = 
346
				jaxbDef.getSlideFeatureDefinition();
347
 
348
			if(jaxbSlideFeatureDefs != null) {
349
				def.setSlideFeatureDefinitions((
350
						this.convertSlideFeatureDefinitions(
351
								jaxbSlideFeatureDefs)));
352
			}
42 naveen 353
			Utils.info("def=" + def);
16 naveen 354
 
355
			defs.put(new Long(jaxbDef.getID()), def);
356
		}
357
 
358
		return defs;
359
	}
360
 
361
	/**
362
	 * 
363
	 * @param jaxbDefs
364
	 * @return List<SlideFeatureDefinition>
365
	 */
366
	private List<SlideFeatureDefinition> convertSlideFeatureDefinitions(
367
			List<SlideFeatureDefinitionType> jaxbDefs) {
368
 
369
		List<SlideFeatureDefinition> defs = 
370
			new ArrayList<SlideFeatureDefinition>();
371
 
372
		Iterator<SlideFeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
373
 
374
		// Slide-feature definitions
375
		while(itjaxbDefs.hasNext()) {
376
			SlideFeatureDefinitionType jaxbDef = itjaxbDefs.next();
377
			SlideFeatureDefinition def = new SlideFeatureDefinition(
378
					jaxbDef.getFeatureDefinitionID());
379
 
380
			def.setEditorialImportance(this.convertEditorialImportance(
381
					jaxbDef.getEditorialImportance()));
382
 
383
			def.setDescription(jaxbDef.getDescription());
384
 
385
			defs.add(def);
386
		}
387
 
388
		return defs;
389
	}
390
 
391
	/**
392
	 * 
49 naveen 393
	 * @param defType
394
	 * @return
16 naveen 395
	 */
396
	private Map<Long, FeatureDefinition> convertFeatureDefinitions(
397
			DefinitionType defType) {
398
 
399
		Map<Long, FeatureDefinition> defs = 
400
			new HashMap<Long, FeatureDefinition>();
401
 
402
		List<FeatureDefinitionType> jaxbDefs = defType.getFeatureDefinition();
403
		Iterator<FeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
404
 
405
		// Feature definitions
406
		while(itjaxbDefs.hasNext()) {
407
			FeatureDefinitionType jaxbDef = itjaxbDefs.next();
408
 
42 naveen 409
			//Utils.info("Feature label=" + jaxbDef.getLabel());
16 naveen 410
			FeatureDefinition def = new FeatureDefinition(jaxbDef.getID(),
411
					jaxbDef.getLabel());
412
			def.setAllowsBlank(jaxbDef.isCanbeBlank());
413
			def.setDescription(jaxbDef.getDescription());
414
 
415
			// Bullet Definition
416
			BulletDefinitionType jaxbBulletDef = jaxbDef.getBulletDefinition();
417
			if(jaxbBulletDef != null) {
418
				def.setBulletDefinition(this.convertBulletDefinition(
419
						jaxbBulletDef));
420
			}
42 naveen 421
			Utils.info("def=" + def);
16 naveen 422
 
423
			defs.put(new Long(jaxbDef.getID()), def);
424
		}
425
 
426
		return defs;
427
	}
428
 
429
	/**
430
	 * 
431
	 * @param jaxbDef BulletDefinitionType
432
	 * @return BulletDefinition
433
	 */
434
	private BulletDefinition convertBulletDefinition(
435
			BulletDefinitionType jaxbDef) {
436
 
437
		BulletDefinition def = new BulletDefinition(
438
				jaxbDef.getDatatypeDefinitionID());
439
 
440
		Long unitID = jaxbDef.getUnitID();
441
		if(unitID != null) {
442
			def.setUnitID(unitID.longValue());
443
		}
47 naveen 444
		Utils.info("jaxbDef.isIsMultivalue=" + jaxbDef.isIsMultivalue());
445
 
16 naveen 446
		def.setMultivalue(jaxbDef.isIsMultivalue());
447
		def.setLearned(jaxbDef.isIsLearned());
448
		def.setDescription(jaxbDef.getDescription());
449
 
450
		return def;
451
	}
49 naveen 452
 
16 naveen 453
	/**
454
	 * 
49 naveen 455
	 * @param defType
456
	 * @return
16 naveen 457
	 */
458
	private Map<Long, DatatypeDefinition> convertDatatypeDefinition(
459
			DefinitionType defType) {
460
 
461
		Map<Long, DatatypeDefinition> defs = 
462
			new HashMap<Long, DatatypeDefinition>();
463
 
464
		List<DatatypeDefinitionType> jaxbDefs = defType.getDatatypeDefinition();
465
		Iterator<DatatypeDefinitionType> it = jaxbDefs.iterator();
466
 
467
		while(it.hasNext()) {
468
			DatatypeDefinitionType jaxbDef = it.next();
469
 
470
			DatatypeDefinition def = null;
471
			CompositeDefinitionType compositeDefType = 
472
				jaxbDef.getCompositeDefinition();
473
 
474
			EnumDefinitionType enumDefType = 
475
				jaxbDef.getEnumDefinition();
476
 
477
			// Composite data type
478
			if(compositeDefType != null) {
479
				CompositeDefinition compDef = new CompositeDefinition(
20 naveen 480
						jaxbDef.getID(), jaxbDef.getName(), 
481
						compositeDefType.getSeparator());
16 naveen 482
 
483
				List<CompositePartDefinitionType> jaxbPartDefs = 
484
					compositeDefType.getCompositePartDefinition();
485
 
486
				Iterator<CompositePartDefinitionType> itPartDefs = 
487
					jaxbPartDefs.iterator();
488
 
489
				// Collect parts
490
				while(itPartDefs.hasNext()) {
491
					CompositePartDefinitionType jaxbPartDef = itPartDefs.next();
492
					CompositePartDefinition partDef = 
493
						this.convertCompositePartDefinition(jaxbPartDef);
494
 
495
					compDef.addCompositePartDefinition(partDef);
496
				}
497
 
498
				def = compDef;
499
			}
500
 
501
			// Enumerated values
502
			else if(enumDefType != null) {
503
				EnumDefinition enumDef = new EnumDefinition(jaxbDef.getID(), 
504
						jaxbDef.getName());
505
 
506
				List<EnumValueType> jaxbEnumValues = 
507
					enumDefType.getEnumValue();
508
 
509
				Iterator<EnumValueType> itEnumValues = 
510
					jaxbEnumValues.iterator();
511
 
512
				// Collect individual value
513
				while(itEnumValues.hasNext()) {
514
					EnumValueType jaxbEnumValue = itEnumValues.next();
515
					EnumValue enumValue = 
516
						this.convertEnumValueDefinition(jaxbEnumValue);
517
 
518
					enumDef.addEnumValue(enumValue);
519
				}
520
 
521
				def = enumDef;
522
			}
523
 
524
			// Primitive
525
			else {
526
				def = new DatatypeDefinition(jaxbDef.getID(), 
527
						jaxbDef.getName());
528
			}
529
 
530
			def.setDescription(jaxbDef.getDescription());
42 naveen 531
			Utils.info("def=" + def);
16 naveen 532
 
533
			defs.put(new Long(jaxbDef.getID()), def);
534
		}
535
 
536
		return defs;
537
	}
538
 
539
	/**
540
	 * 
541
	 * @param jaxbEnumValue
542
	 * @return EnumValue
543
	 */
544
	private EnumValue convertEnumValueDefinition(EnumValueType jaxbEnumValue) {
545
 
546
		EnumValue enumValue = new EnumValue(jaxbEnumValue.getID(), 
547
				jaxbEnumValue.getValue());
548
 
549
		return enumValue;
550
	}
551
	/**
552
	 * 
553
	 * @param jaxbPartDef
554
	 * @return CompositePartDefinition
555
	 */
556
	private CompositePartDefinition convertCompositePartDefinition(
557
			CompositePartDefinitionType jaxbPartDef) {
558
 
559
		CompositePartDefinition partDef = new CompositePartDefinition(
560
				jaxbPartDef.getLabel(), jaxbPartDef.getDatatypeDefinitionID(), 
561
				jaxbPartDef.getUnitID());
562
 
563
		partDef.setDescription(jaxbPartDef.getDescription());
564
 
565
		return partDef;
566
	}
49 naveen 567
 
16 naveen 568
	/**
569
	 * 
49 naveen 570
	 * @param defType
571
	 * @param catMap
572
	 * @return
16 naveen 573
	 */
574
	private Category convertCategories(DefinitionType defType, 
575
			Map<Long, Category> catMap) {
10 shop2020 576
 
577
		List<CategoryType> jaxbCats = defType.getCategory();
578
		Iterator<CategoryType> it = jaxbCats.iterator();
579
 
580
		// Get root category
581
		CategoryType jaxbCat = it.next();
582
		if(jaxbCat == null) {
42 naveen 583
			Utils.info("Invalid file: " + this.srcFile);
10 shop2020 584
			return null;
585
		}
586
 
587
		Category root = this.convertCategoryType(jaxbCat, null, catMap);
42 naveen 588
		Utils.info("catMap.get(10002)=" + catMap.get(new Long(10002)));
32 naveen 589
 
10 shop2020 590
		return root;
591
	}
592
 
593
	/**
594
	 * 
595
	 * @param jaxbCat
49 naveen 596
	 * @param parentCat
597
	 * @param catMap
598
	 * @return
10 shop2020 599
	 */
32 naveen 600
	@SuppressWarnings("unchecked")
16 naveen 601
	private Category convertCategoryType(CategoryType jaxbCat, 
602
			Category parentCat, Map<Long, Category> catMap) {
18 naveen 603
 
10 shop2020 604
		Category cat = new Category(jaxbCat.getID());
605
		cat.setLabel(jaxbCat.getName());
606
		cat.setDescription(jaxbCat.getDescription());
607
		if(parentCat != null) {
608
			cat.setParentCategory(parentCat);
32 naveen 609
 
610
			// Copy parent's category-slide definitions
611
			ArrayList<CategorySlideDefinition> parentCSDef = 
612
				(ArrayList<CategorySlideDefinition>) 
613
				parentCat.getCategorySlideDefintions();
614
 
615
			if(parentCSDef != null) {
616
				cat.setCategorySlideDefintions(
617
					(List<CategorySlideDefinition>) parentCSDef.clone());
618
			}
10 shop2020 619
		}
620
 
621
		// Category Slide Definition
32 naveen 622
		List<CategorySlideDefinitionType> jaxbDefs = 
623
			jaxbCat.getCategorySlideDefinition();
624
 
10 shop2020 625
		Iterator<CategorySlideDefinitionType> it = jaxbDefs.iterator();
626
		while(it.hasNext()) {
627
			CategorySlideDefinitionType jaxbDef = it.next();
32 naveen 628
			CategorySlideDefinition catSlideDef 
629
			= this.convertCategorySlideDefinitionType(jaxbCat.getID(), jaxbDef);
630
 
10 shop2020 631
			cat.addCategorySlideDefintion(catSlideDef);
632
		}
633
 
634
		// Children
635
		List<CategoryType> jaxbChildren = jaxbCat.getChildCategory();
42 naveen 636
		//Utils.info("jaxbChildren.size: " + jaxbChildren.size());
10 shop2020 637
 
638
		Iterator<CategoryType> itChildren = jaxbChildren.iterator();
639
		while(itChildren.hasNext()) {
640
			CategoryType jaxbChildCat = itChildren.next();
32 naveen 641
			Category childCat = this.convertCategoryType(jaxbChildCat, cat, 
642
					catMap);
10 shop2020 643
			cat.addChild(childCat);
644
		}
42 naveen 645
		//Utils.info("Parent cat: " + cat);
32 naveen 646
		// DEBUG ONLY
42 naveen 647
		Utils.info("####### Cat ID: " + cat.getID());
32 naveen 648
		if(cat.getCategorySlideDefintions() != null) {
649
			for(CategorySlideDefinition csd : cat.getCategorySlideDefintions()){
42 naveen 650
				Utils.info("####### SlideDefintionID=" + 
32 naveen 651
						csd.getSlideDefintionID());
652
			}
653
		}
654
 
10 shop2020 655
		catMap.put(new Long(jaxbCat.getID()), cat);
656
		return cat;
657
	}
658
 
659
	/**
660
	 * 
49 naveen 661
	 * @param categoryID
10 shop2020 662
	 * @param jaxbDef
663
	 * @return
664
	 */
16 naveen 665
	private CategorySlideDefinition convertCategorySlideDefinitionType(
666
			long categoryID, CategorySlideDefinitionType jaxbDef) {
667
 
10 shop2020 668
		CategorySlideDefinition catSlideDef = new CategorySlideDefinition(
32 naveen 669
				jaxbDef.getSlideDefinitionID());
10 shop2020 670
 
671
		catSlideDef.setDescription(jaxbDef.getDescription());
672
 
673
		EditorialImportanceType jaxbEdImp = jaxbDef.getEditorialImportance();
674
		EditorialImportance edImp = this.convertEditorialImportance(jaxbEdImp);
675
		catSlideDef.setEditorialImportance(edImp);
676
 
677
		return catSlideDef;
678
	}
679
 
680
	/**
681
	 * 
682
	 * @return Map
683
	 */
684
	private Map<Long, Unit> convertUnits(DefinitionType defType) {
685
 
686
		Map<Long, Unit> allUnits = new HashMap<Long, Unit>();
687
		List<UnitType> jaxbUnits = defType.getUnit();
688
		Iterator<UnitType> it = jaxbUnits.iterator();
689
 
690
		while(it.hasNext()) {
691
			UnitType jaxbUnit = it.next();
692
 
693
			Unit unit = new Unit(jaxbUnit.getID());
694
			unit.setDescription(jaxbUnit.getDescription());
695
			unit.setFullForm(jaxbUnit.getFullform());
696
			unit.setShortForm(jaxbUnit.getShortform());
42 naveen 697
			Utils.info("unit=" + unit);
10 shop2020 698
 
699
			allUnits.put(new Long(jaxbUnit.getID()), unit);
700
		}
701
 
702
		return allUnits;
703
	}
49 naveen 704
 
10 shop2020 705
	/**
706
	 * 
49 naveen 707
	 * @param srcFile
708
	 * @return
709
	 * @throws Exception
10 shop2020 710
	 */
711
	private DefinitionType unmarshallSrcFile(String srcFile) throws Exception {
712
 
16 naveen 713
        JAXBContext jc = JAXBContext.newInstance("in.shop2020.metamodel.jaxb");
10 shop2020 714
 
715
        // create an Unmarshaller
716
        Unmarshaller u = jc.createUnmarshaller();
717
 
16 naveen 718
        JAXBElement<?> element = (JAXBElement<?>)u.unmarshal(
719
        		new FileInputStream(srcFile));
10 shop2020 720
 
721
        return (DefinitionType)element.getValue();
722
	}
723
 
724
	/**
725
	 * 
16 naveen 726
	 * @param jaxbEdImp
727
	 * @return EditorialImportance
728
	 */
729
	private EditorialImportance convertEditorialImportance(
730
			EditorialImportanceType jaxbEdImp) {
731
 
732
		String strEdImp = jaxbEdImp.value();
733
		EditorialImportance edImp = null;
734
 
735
		if(strEdImp.equals("Mandatory"))
736
			edImp = EditorialImportance.MANDATORY;
737
		else if(strEdImp.equals("Optional"))
738
			edImp = EditorialImportance.OPTIONAL;
739
		else 
740
			edImp = EditorialImportance.RECOMMENDED;
741
 
742
		return edImp;
743
	}
10 shop2020 744
}