Subversion Repositories SmartDukaan

Rev

Rev 70 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 70 Rev 72
Line 2... Line 2...
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.metamodel.util;
4
package in.shop2020.metamodel.util;
5
 
5
 
6
import in.shop2020.metamodel.definitions.BulletDefinition;
6
import in.shop2020.metamodel.definitions.BulletDefinition;
-
 
7
import in.shop2020.metamodel.definitions.CMPBucketDefinition;
7
import in.shop2020.metamodel.definitions.CMPRuleDefinition;
8
import in.shop2020.metamodel.definitions.CMPRuleDefinition;
8
import in.shop2020.metamodel.definitions.CMPSlideRuleDefinition;
9
import in.shop2020.metamodel.definitions.CMPSlideRuleDefinition;
9
import in.shop2020.metamodel.definitions.Catalog;
10
import in.shop2020.metamodel.definitions.Catalog;
10
import in.shop2020.metamodel.definitions.Category;
11
import in.shop2020.metamodel.definitions.Category;
11
import in.shop2020.metamodel.definitions.CategoryFacetDefinition;
12
import in.shop2020.metamodel.definitions.CategoryFacetDefinition;
Line 21... Line 22...
21
import in.shop2020.metamodel.definitions.FeatureDefinition;
22
import in.shop2020.metamodel.definitions.FeatureDefinition;
22
import in.shop2020.metamodel.definitions.RuleDefinition;
23
import in.shop2020.metamodel.definitions.RuleDefinition;
23
import in.shop2020.metamodel.definitions.SlideDefinition;
24
import in.shop2020.metamodel.definitions.SlideDefinition;
24
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
25
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
25
import in.shop2020.metamodel.definitions.Unit;
26
import in.shop2020.metamodel.definitions.Unit;
-
 
27
import in.shop2020.metamodel.jaxb.comparison.CMPBucketDefinitionType;
26
import in.shop2020.metamodel.jaxb.comparison.CMPDefinitionType;
28
import in.shop2020.metamodel.jaxb.comparison.CMPDefinitionType;
27
import in.shop2020.metamodel.jaxb.comparison.CMPRuleDefinitionType;
29
import in.shop2020.metamodel.jaxb.comparison.CMPRuleDefinitionType;
28
import in.shop2020.metamodel.jaxb.comparison.CMPSlideRuleDefinitionType;
30
import in.shop2020.metamodel.jaxb.comparison.CMPSlideRuleDefinitionType;
29
import in.shop2020.metamodel.jaxb.core.BulletDefinitionType;
31
import in.shop2020.metamodel.jaxb.core.BulletDefinitionType;
30
import in.shop2020.metamodel.jaxb.core.CategorySlideDefinitionType;
32
import in.shop2020.metamodel.jaxb.core.CategorySlideDefinitionType;
Line 76... Line 78...
76
 * 	 - Categories
78
 * 	 - Categories
77
 *   - Facet Definition
79
 *   - Facet Definition
78
 *   - Category Facet Definition
80
 *   - Category Facet Definition
79
 *   - IR Data Rules
81
 *   - IR Data Rules
80
 *   - IR Meta-data Rules
82
 *   - IR Meta-data Rules
-
 
83
 *   - Comparison Rules
-
 
84
 *   - Comparison Definitions
-
 
85
 *   - Comparison Buckets
81
 * 
86
 * 
82
 * - Show
87
 * - Show
83
 * 	 - Datatype definitions
88
 * 	 - Datatype definitions
84
 * 	 - Feature definitions
89
 * 	 - Feature definitions
85
 * 	 - Slide definitions
90
 * 	 - Slide definitions
86
 * 	 - Categories
91
 * 	 - Categories
87
 *   - Facet Definition
92
 *   - Facet Definition
88
 *   - Category Facet Definition
93
 *   - Category Facet Definition
89
 *   - IR Data Rules
94
 *   - IR Data Rules
90
 *   - IR Meta-data Rules
95
 *   - IR Meta-data Rules
-
 
96
 *   - Comparison Rules
-
 
97
 *   - Comparison Definitions
-
 
98
 *   - Comparison Buckets
91
 * 
99
 * 
92
 * - Show all definition objects that define a category 
100
 * - Show all definition objects that define a category 
93
 * 
101
 * 
94
 * 
102
 * 
95
 * @author naveen
103
 * @author naveen
Line 114... Line 122...
114
	
122
	
115
	/**
123
	/**
116
	 * Usage: MM [show|import|showcategory] [units|datatypedefinitions|
124
	 * Usage: MM [show|import|showcategory] [units|datatypedefinitions|
117
	 * featuredefinitions|slidedefinitions|categories|facetdefinitions|
125
	 * featuredefinitions|slidedefinitions|categories|facetdefinitions|
118
	 * categoryfacetdefinitions|irdatarules|irmetadatarules|comparisonrules|
126
	 * categoryfacetdefinitions|irdatarules|irmetadatarules|comparisonrules|
119
	 * comparisondefinitions] {Category ID}
127
	 * comparisondefinitions|comparisonbuckets] {Category ID}
120
	 * 
128
	 * 
121
	 * @param args
129
	 * @param args
122
	 */
130
	 */
123
	public static void main(String[] args) throws Exception {
131
	public static void main(String[] args) throws Exception {
124
		String[] definitionSetNames = new String[] {"units", 
132
		String[] definitionSetNames = new String[] {"units", 
125
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
133
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
126
				"categories", "facetdefinitions", "categoryfacetdefinitions", 
134
				"categories", "facetdefinitions", "categoryfacetdefinitions", 
127
				"irdatarules", "irmetadatarules", "comparisonrules", 
135
				"irdatarules", "irmetadatarules", "comparisonrules", 
128
				"comparisondefinitions"};
136
				"comparisondefinitions", "comparisonbuckets"};
129
		
137
		
130
		String[] commands = new String[] {"show", "import", "showcategory"};
138
		String[] commands = new String[] {"show", "import", "showcategory"};
131
 
139
 
132
		String usage = "Usage: MM ["+ StringUtils.join(commands, "|") +"] ["+ 
140
		String usage = "Usage: MM ["+ StringUtils.join(commands, "|") +"] ["+ 
133
			StringUtils.join(definitionSetNames, "|") + "] {Category ID}";
141
			StringUtils.join(definitionSetNames, "|") + "] {Category ID}";
Line 221... Line 229...
221
				this.definitionSetName.equals("irdatarules") || 
229
				this.definitionSetName.equals("irdatarules") || 
222
						this.definitionSetName.equals("irmetadatarules")) {
230
						this.definitionSetName.equals("irmetadatarules")) {
223
			type = "facets";
231
			type = "facets";
224
		}
232
		}
225
		else if(this.definitionSetName.equals("comparisonrules") || 
233
		else if(this.definitionSetName.equals("comparisonrules") || 
226
				this.definitionSetName.equals("comparisondefinitions")){
234
				this.definitionSetName.equals("comparisondefinitions") ||
-
 
235
				this.definitionSetName.equals("comparisonbuckets")) {
227
			type = "comparison";
236
			type = "comparison";
228
		}
237
		}
229
		
238
		
230
		Object oDefType = this.unmarshallSrcFile(this.srcFile, type);
239
		Object oDefType = this.unmarshallSrcFile(this.srcFile, type);
231
		DefinitionType defType = null;
240
		DefinitionType defType = null;
Line 260... Line 269...
260
			//Utils.info(root);
269
			//Utils.info(root);
261
			//System.exit(0);
270
			//System.exit(0);
262
			
271
			
263
			// Tree
272
			// Tree
264
			String categoryTreeDBFile = Utils.DEFINITIONS_DB_PATH + 
273
			String categoryTreeDBFile = Utils.DEFINITIONS_DB_PATH + 
265
				"categorytree" + ".ser";
274
				"categorytree.ser";
266
			
275
			
267
			if(root != null) {
276
			if(root != null) {
268
				DBUtils.store(root, categoryTreeDBFile);
277
				DBUtils.store(root, categoryTreeDBFile);
269
			}
278
			}
270
			
279
			
Line 357... Line 366...
357
				this.convertComparisonRuleDefinitions(cmpDefType);
366
				this.convertComparisonRuleDefinitions(cmpDefType);
358
 
367
 
359
			objectToStore = comparisonRuleDefsMap;
368
			objectToStore = comparisonRuleDefsMap;
360
		}
369
		}
361
		
370
		
362
		// Category Comparison Definitions
371
		// Comparison Definitions
363
		else if(this.definitionSetName.equals("comparisondefinitions")){
372
		else if(this.definitionSetName.equals("comparisondefinitions")){
364
			Map categoryCMPDefsMap = 
373
			Map cmpDefsMap = 
365
				this.convertComparisonDefinitions(cmpDefType);
374
				this.convertComparisonDefinitions(cmpDefType);
366
 
375
 
367
			objectToStore = categoryCMPDefsMap;
376
			objectToStore = cmpDefsMap;
-
 
377
		}
-
 
378
		
-
 
379
		// Comparison Buckets
-
 
380
		else if(this.definitionSetName.equals("comparisonbuckets")){
-
 
381
			Map cmpBucketsMap = 
-
 
382
				this.convertComparisonBuckets(cmpDefType);
-
 
383
 
-
 
384
			objectToStore = cmpBucketsMap;
368
		}
385
		}
369
		
386
		
370
		if(objectToStore != null) {
387
		if(objectToStore != null) {
371
			DBUtils.store(objectToStore, this.dbFile);
388
			DBUtils.store(objectToStore, this.dbFile);
372
		}
389
		}
Line 474... Line 491...
474
	}
491
	}
475
	
492
	
476
	/**
493
	/**
477
	 * 
494
	 * 
478
	 * @param defType
495
	 * @param defType
-
 
496
	 * @return
-
 
497
	 */
-
 
498
	private Map<Long, List<CMPBucketDefinition>> convertComparisonBuckets(
-
 
499
			CMPDefinitionType defType) {
-
 
500
		
-
 
501
		Map<Long, List<CMPBucketDefinition>> cmpBuckets = 
-
 
502
			new HashMap<Long, List<CMPBucketDefinition>>();
-
 
503
		
-
 
504
		List<CMPBucketDefinitionType> jaxbBuckets = 
-
 
505
			defType.getCMPBucketDefinition();
-
 
506
		
-
 
507
		for(CMPBucketDefinitionType jaxbBucket : jaxbBuckets) {
-
 
508
			String name = jaxbBucket.getName();
-
 
509
			long categoryID = jaxbBucket.getCategoryID();
-
 
510
			
-
 
511
			CMPBucketDefinition bucketDef = 
-
 
512
				new CMPBucketDefinition(name, categoryID);
-
 
513
			
-
 
514
			bucketDef.setDescription(jaxbBucket.getDescription());
-
 
515
			bucketDef.setDefaultWeight(
-
 
516
					jaxbBucket.getDefaultWeight().intValue());
-
 
517
			bucketDef.setSlideDefinitionIDs(jaxbBucket.getSlideDefinitionID());
-
 
518
			
-
 
519
			List<CMPBucketDefinition> categoryBuckets = 
-
 
520
				cmpBuckets.get(new Long(categoryID));
-
 
521
			
-
 
522
			if(categoryBuckets == null) {
-
 
523
				categoryBuckets = new ArrayList<CMPBucketDefinition>();
-
 
524
				cmpBuckets.put(new Long(categoryID), categoryBuckets);
-
 
525
			}
-
 
526
			
-
 
527
			categoryBuckets.add(bucketDef);
-
 
528
		}
-
 
529
		Utils.info("cmpBuckets=" + cmpBuckets);
-
 
530
		
-
 
531
		return cmpBuckets;
-
 
532
	}
-
 
533
	
-
 
534
	/**
-
 
535
	 * 
-
 
536
	 * @param defType
479
	 * @return
537
	 * @return
480
	 */
538
	 */
481
	private Map<Long, FacetDefinition> convertFacetDefinitions(
539
	private Map<Long, FacetDefinition> convertFacetDefinitions(
482
			IRDefinitionType defType) {
540
			IRDefinitionType defType) {
483
		List<FacetDefinitionType> jaxbFacetDefs = defType.getFacetDefinition();
541
		List<FacetDefinitionType> jaxbFacetDefs = defType.getFacetDefinition();