Subversion Repositories SmartDukaan

Rev

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

Rev 69 Rev 70
Line 21... Line 21...
21
import in.shop2020.metamodel.definitions.FeatureDefinition;
21
import in.shop2020.metamodel.definitions.FeatureDefinition;
22
import in.shop2020.metamodel.definitions.RuleDefinition;
22
import in.shop2020.metamodel.definitions.RuleDefinition;
23
import in.shop2020.metamodel.definitions.SlideDefinition;
23
import in.shop2020.metamodel.definitions.SlideDefinition;
24
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
24
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
25
import in.shop2020.metamodel.definitions.Unit;
25
import in.shop2020.metamodel.definitions.Unit;
26
import in.shop2020.metamodel.jaxb.comparison.CMPCategorySlideRuleDefinitionType;
-
 
27
import in.shop2020.metamodel.jaxb.comparison.CMPDefinitionType;
26
import in.shop2020.metamodel.jaxb.comparison.CMPDefinitionType;
28
import in.shop2020.metamodel.jaxb.comparison.CMPRuleDefinitionType;
27
import in.shop2020.metamodel.jaxb.comparison.CMPRuleDefinitionType;
29
import in.shop2020.metamodel.jaxb.comparison.CMPSlideRuleDefinitionType;
28
import in.shop2020.metamodel.jaxb.comparison.CMPSlideRuleDefinitionType;
30
import in.shop2020.metamodel.jaxb.core.BulletDefinitionType;
29
import in.shop2020.metamodel.jaxb.core.BulletDefinitionType;
31
import in.shop2020.metamodel.jaxb.core.CategorySlideDefinitionType;
30
import in.shop2020.metamodel.jaxb.core.CategorySlideDefinitionType;
Line 95... Line 94...
95
 * 
94
 * 
96
 * @author naveen
95
 * @author naveen
97
 *
96
 *
98
 */
97
 */
99
public class MM {
98
public class MM {
100
	/**
-
 
101
	 * 
-
 
102
	 */
-
 
103
	public static final String DEFINITIONS_SRC_PATH = 
-
 
104
		"/home/naveen/workspace/eclipse/webapp/src/xml/model/";
-
 
105
	
-
 
106
	// LOCAL
-
 
107
	/**
-
 
108
	 * 
-
 
109
	 */
-
 
110
	public static final String DEFINITIONS_DB_PATH = 
-
 
111
		"/home/naveen/workspace/eclipse/db/definitions/";
-
 
112
	
-
 
113
	/**
-
 
114
	 * 
-
 
115
	 */
-
 
116
	public static final String ENTITIES_DB_PATH = 
-
 
117
		"/home/naveen/workspace/eclipse/db/entities/";
-
 
118
	
-
 
119
	/** WEB
-
 
120
	public static final String DEFINITIONS_DB_PATH = 
-
 
121
		"/var/lib/tomcat6/webapps/shop2020/db/definitions/";
-
 
122
	public static final String ENTITIES_DB_PATH = 
-
 
123
		"/var/lib/tomcat6/webapps/shop2020/db/entities/";
-
 
124
	*/
-
 
125
 
-
 
126
	/** Validation tool
-
 
127
	public static final String DEFINITIONS_DB_PATH = 
-
 
128
		"./db/definitions/";
-
 
129
	public static final String ENTITIES_DB_PATH = 
-
 
130
		"./db/entities/";
-
 
131
	*/
-
 
132
	
99
	
133
	/**
100
	/**
134
	 * 
101
	 * 
135
	 */
102
	 */
136
	private String definitionSetName;
103
	private String definitionSetName;
Line 147... Line 114...
147
	
114
	
148
	/**
115
	/**
149
	 * Usage: MM [show|import|showcategory] [units|datatypedefinitions|
116
	 * Usage: MM [show|import|showcategory] [units|datatypedefinitions|
150
	 * featuredefinitions|slidedefinitions|categories|facetdefinitions|
117
	 * featuredefinitions|slidedefinitions|categories|facetdefinitions|
151
	 * categoryfacetdefinitions|irdatarules|irmetadatarules|comparisonrules|
118
	 * categoryfacetdefinitions|irdatarules|irmetadatarules|comparisonrules|
152
	 * categorycomparisondefinitions] {Category ID}
119
	 * comparisondefinitions] {Category ID}
153
	 * 
120
	 * 
154
	 * @param args
121
	 * @param args
155
	 */
122
	 */
156
	public static void main(String[] args) throws Exception {
123
	public static void main(String[] args) throws Exception {
157
		String[] definitionSetNames = new String[] {"units", 
124
		String[] definitionSetNames = new String[] {"units", 
158
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
125
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
159
				"categories", "facetdefinitions", "categoryfacetdefinitions", 
126
				"categories", "facetdefinitions", "categoryfacetdefinitions", 
160
				"irdatarules", "irmetadatarules", "comparisonrules", 
127
				"irdatarules", "irmetadatarules", "comparisonrules", 
161
				"categorycomparisondefinitions"};
128
				"comparisondefinitions"};
162
		
129
		
163
		String[] commands = new String[] {"show", "import", "showcategory"};
130
		String[] commands = new String[] {"show", "import", "showcategory"};
164
 
131
 
165
		String usage = "Usage: MM ["+ StringUtils.join(commands, "|") +"] ["+ 
132
		String usage = "Usage: MM ["+ StringUtils.join(commands, "|") +"] ["+ 
166
			StringUtils.join(definitionSetNames, "|") + "] {Category ID}";
133
			StringUtils.join(definitionSetNames, "|") + "] {Category ID}";
Line 220... Line 187...
220
	 * 
187
	 * 
221
	 * @param definitionSet
188
	 * @param definitionSet
222
	 */
189
	 */
223
	public MM(String definitionSetName) {
190
	public MM(String definitionSetName) {
224
		this.definitionSetName = definitionSetName;
191
		this.definitionSetName = definitionSetName;
225
		this.srcFile = DEFINITIONS_SRC_PATH + this.definitionSetName + ".xml";
192
		this.srcFile = Utils.DEFINITIONS_SRC_PATH + this.definitionSetName + 
-
 
193
			".xml";
-
 
194
		
226
		this.dbFile = DEFINITIONS_DB_PATH + this.definitionSetName + ".ser";
195
		this.dbFile = Utils.DEFINITIONS_DB_PATH + this.definitionSetName + 
-
 
196
			".ser";
227
	}
197
	}
228
	
198
	
229
	/**
199
	/**
230
	 * 
200
	 * 
231
	 * @param categoryID
201
	 * @param categoryID
Line 251... Line 221...
251
				this.definitionSetName.equals("irdatarules") || 
221
				this.definitionSetName.equals("irdatarules") || 
252
						this.definitionSetName.equals("irmetadatarules")) {
222
						this.definitionSetName.equals("irmetadatarules")) {
253
			type = "facets";
223
			type = "facets";
254
		}
224
		}
255
		else if(this.definitionSetName.equals("comparisonrules") || 
225
		else if(this.definitionSetName.equals("comparisonrules") || 
256
				this.definitionSetName.equals("categorycomparisondefinitions")){
226
				this.definitionSetName.equals("comparisondefinitions")){
257
			type = "comparison";
227
			type = "comparison";
258
		}
228
		}
259
		
229
		
260
		Object oDefType = this.unmarshallSrcFile(this.srcFile, type);
230
		Object oDefType = this.unmarshallSrcFile(this.srcFile, type);
261
		DefinitionType defType = null;
231
		DefinitionType defType = null;
Line 289... Line 259...
289
			//Utils.info(categoriesMap);
259
			//Utils.info(categoriesMap);
290
			//Utils.info(root);
260
			//Utils.info(root);
291
			//System.exit(0);
261
			//System.exit(0);
292
			
262
			
293
			// Tree
263
			// Tree
294
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
264
			String categoryTreeDBFile = Utils.DEFINITIONS_DB_PATH + 
295
				".ser";
265
				"categorytree" + ".ser";
296
			
266
			
297
			if(root != null) {
267
			if(root != null) {
298
				DBUtils.store(root, categoryTreeDBFile);
268
				DBUtils.store(root, categoryTreeDBFile);
299
			}
269
			}
300
			
270
			
Line 306... Line 276...
306
		else if(this.definitionSetName.equals("datatypedefinitions")) {
276
		else if(this.definitionSetName.equals("datatypedefinitions")) {
307
			Map<Long, DatatypeDefinition> datatypeDefsMap = 
277
			Map<Long, DatatypeDefinition> datatypeDefsMap = 
308
				this.convertDatatypeDefinition(defType);
278
				this.convertDatatypeDefinition(defType);
309
			
279
			
310
			// Store enum value id to value map separately
280
			// Store enum value id to value map separately
311
			String enumValueDBFile = DEFINITIONS_DB_PATH + "enumvalues" + 
281
			String enumValueDBFile = Utils.DEFINITIONS_DB_PATH + "enumvalues" + 
312
				".ser";
282
				".ser";
313
			
283
			
314
			// RE-VISIT - May not be optimal
284
			// RE-VISIT - May not be optimal
315
			Map<Long, EnumValue> enumValuesMap = new TreeMap<Long, EnumValue>();
285
			Map<Long, EnumValue> enumValuesMap = new TreeMap<Long, EnumValue>();
316
			for(Long datatypeDefID : datatypeDefsMap.keySet()) {
286
			for(Long datatypeDefID : datatypeDefsMap.keySet()) {
Line 388... Line 358...
388
 
358
 
389
			objectToStore = comparisonRuleDefsMap;
359
			objectToStore = comparisonRuleDefsMap;
390
		}
360
		}
391
		
361
		
392
		// Category Comparison Definitions
362
		// Category Comparison Definitions
393
		else if(this.definitionSetName.equals("categorycomparisondefinitions")){
363
		else if(this.definitionSetName.equals("comparisondefinitions")){
394
			Map categoryCMPDefsMap = 
364
			Map categoryCMPDefsMap = 
395
				this.convertCategoryComparisonDefinitions(cmpDefType);
365
				this.convertComparisonDefinitions(cmpDefType);
396
 
366
 
397
			objectToStore = categoryCMPDefsMap;
367
			objectToStore = categoryCMPDefsMap;
398
		}
368
		}
399
		
369
		
400
		if(objectToStore != null) {
370
		if(objectToStore != null) {
Line 408... Line 378...
408
	public void showDefinitionSet() throws Exception {
378
	public void showDefinitionSet() throws Exception {
409
		Object obj = DBUtils.read(this.dbFile);
379
		Object obj = DBUtils.read(this.dbFile);
410
		Utils.info(obj.toString());
380
		Utils.info(obj.toString());
411
		
381
		
412
		if(this.definitionSetName.equals("categories")) {
382
		if(this.definitionSetName.equals("categories")) {
413
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
383
			String categoryTreeDBFile = Utils.DEFINITIONS_DB_PATH + 
414
				".ser";
384
				"categorytree" + ".ser";
415
			
385
			
416
			Category root = (Category)DBUtils.read(categoryTreeDBFile);
386
			Category root = (Category)DBUtils.read(categoryTreeDBFile);
417
			Utils.info(root.toString());
387
			Utils.info(root.toString());
418
			//Utils.info("root.getChildrenCategory().size: " + 
388
			//Utils.info("root.getChildrenCategory().size: " + 
419
			//		root.getChildrenCategory().size());
389
			//		root.getChildrenCategory().size());
Line 476... Line 446...
476
	/**
446
	/**
477
	 * 
447
	 * 
478
	 * @param defType
448
	 * @param defType
479
	 * @return Map<Long, CMPSlideRuleDefinition> 
449
	 * @return Map<Long, CMPSlideRuleDefinition> 
480
	 */
450
	 */
481
	private Map<Long, List<CMPSlideRuleDefinition>> 
451
	private Map<Long, CMPSlideRuleDefinition> convertComparisonDefinitions(
482
		convertCategoryComparisonDefinitions(CMPDefinitionType defType) {
452
			CMPDefinitionType defType) {
483
		Map<Long, List<CMPSlideRuleDefinition>> catidSlideRuleDef = 
-
 
484
			new TreeMap<Long, List<CMPSlideRuleDefinition>>();
-
 
485
		
453
		
486
		List<CMPCategorySlideRuleDefinitionType> jaxbDefs = 
454
		Map<Long, CMPSlideRuleDefinition> slideRuleDefs = 
487
			defType.getCMPCategorySlideRuleDefinition();
455
			new TreeMap<Long, CMPSlideRuleDefinition>();
488
		
456
		
489
		for(CMPCategorySlideRuleDefinitionType jaxbDef : jaxbDefs) {
-
 
490
			long catid = jaxbDef.getCategoryID();
-
 
491
			List<CMPSlideRuleDefinitionType> jaxbSlideRuleDefs = 
457
		List<CMPSlideRuleDefinitionType> jaxbDefs = 
492
				jaxbDef.getCMPSlideRuleDefinition();
458
			defType.getCMPSlideRuleDefinition();
493
			
-
 
494
			List<CMPSlideRuleDefinition> slideRuleDefs = 
-
 
495
				new ArrayList<CMPSlideRuleDefinition>();
-
 
496
			
459
		
497
			for(CMPSlideRuleDefinitionType jaxbSlideRuleDef : 
460
		for(CMPSlideRuleDefinitionType jaxbDef : jaxbDefs) {
498
				jaxbSlideRuleDefs) {
-
 
499
				long ruleDefID = jaxbSlideRuleDef.getRuleDefinitionID();
461
			long ruleDefID = jaxbDef.getRuleDefinitionID();
500
				long slideDefID = jaxbSlideRuleDef.getSlideDefinitionID();
462
			long slideDefID = jaxbDef.getSlideDefinitionID();
501
				
463
			
502
				CMPSlideRuleDefinition slideRuleDef = 
464
			CMPSlideRuleDefinition slideRuleDef = 
503
					new CMPSlideRuleDefinition(slideDefID, ruleDefID);
465
				new CMPSlideRuleDefinition(slideDefID, ruleDefID);
504
				
466
			
505
				slideRuleDef.setDescription(jaxbSlideRuleDef.getDescription());
467
			slideRuleDef.setDescription(jaxbDef.getDescription());
506
				
-
 
507
				slideRuleDefs.add(slideRuleDef);
-
 
508
			}
-
 
509
			
468
			
510
			catidSlideRuleDef.put(new Long(catid), slideRuleDefs);
469
			slideRuleDefs.put(new Long(slideDefID), slideRuleDef);
511
		}
470
		}
512
		
471
		
513
		Utils.info("catidSlideRuleDef=" + catidSlideRuleDef);
472
		Utils.info("slideRuleDefs=" + slideRuleDefs);
514
		return catidSlideRuleDef;
473
		return slideRuleDefs;
515
	}
474
	}
516
	
475
	
517
	/**
476
	/**
518
	 * 
477
	 * 
519
	 * @param defType
478
	 * @param defType