Subversion Repositories SmartDukaan

Rev

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

Rev 62 Rev 63
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.util;
4
package in.shop2020.util;
5
 
5
 
-
 
6
import java.util.List;
-
 
7
 
-
 
8
import in.shop2020.metamodel.core.Entity;
-
 
9
import in.shop2020.metamodel.core.Feature;
-
 
10
import in.shop2020.metamodel.core.Slide;
-
 
11
import in.shop2020.metamodel.definitions.Catalog;
-
 
12
import in.shop2020.metamodel.definitions.DefinitionsContainer;
-
 
13
import in.shop2020.metamodel.definitions.EntityContainer;
-
 
14
import in.shop2020.metamodel.definitions.FeatureDefinition;
-
 
15
import in.shop2020.metamodel.definitions.SlideDefinition;
-
 
16
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
-
 
17
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
-
 
18
 
6
/**
19
/**
7
 * Command line utility to convert IR Definitions into IR Data and IR Meta-data
20
 * Command line utility to convert IR Definitions into IR Data and IR Meta-data
8
 * 
21
 * 
9
 * @author naveen
22
 * @author naveen
10
 *
23
 *
11
 */
24
 */
12
public class IR {
25
public class IR {
13
 
26
	
-
 
27
	/**
-
 
28
	 * Jython source path
-
 
29
	 */
-
 
30
	public static String JYTHON_SRC_PATH = "src/jython/";
-
 
31
	
-
 
32
	/**
-
 
33
	 * IR XML export path
-
 
34
	 */
-
 
35
	public static String EXPORT_IR_PATH = 
-
 
36
		"/home/naveen/workspace/eclipse/export/ir/";
-
 
37
	
-
 
38
	private long categoryID;
-
 
39
	
14
	/**
40
	/**
15
	 * @param args
41
	 * @param args
-
 
42
	 * @throws Exception 
16
	 */
43
	 */
17
	public static void main(String[] args) {
44
	public static void main(String[] args) throws Exception {
-
 
45
		String usage = "Usage: IR {Category ID}";
-
 
46
		
-
 
47
		if(args.length < 1) {
-
 
48
			System.out.println(usage);
-
 
49
			System.exit(-1);
-
 
50
		}
-
 
51
		
-
 
52
		long categoryID = 0;
-
 
53
		try {
-
 
54
			categoryID = Long.parseLong(args[0]);
-
 
55
		}
-
 
56
		catch (NumberFormatException nfe) {
-
 
57
			System.out.println(usage);
-
 
58
			System.exit(-1);
-
 
59
		}
-
 
60
		
-
 
61
		IR ir = new IR(categoryID);
-
 
62
		ir.exportIRData();
-
 
63
	}
-
 
64
	
-
 
65
	/**
-
 
66
	 * 
-
 
67
	 * @param categoryID
-
 
68
	 */
-
 
69
	public IR(long categoryID) {
-
 
70
		this.categoryID = categoryID;
-
 
71
	}
-
 
72
	
-
 
73
	/**
-
 
74
	 * @throws Exception 
-
 
75
	 * 
-
 
76
	 */
-
 
77
	@SuppressWarnings("unchecked")
-
 
78
	public void exportIRData() throws Exception {
-
 
79
		DefinitionsContainer defs = 
-
 
80
			Catalog.getInstance().getDefinitionsContainer();
-
 
81
		
-
 
82
		EntityContainer ents = 
-
 
83
			Catalog.getInstance().getEntityContainer();
-
 
84
		
-
 
85
		// Get all facets for the category
-
 
86
		ExpandedCategoryFacetDefinition expCategoryFacetDef = 
-
 
87
			defs.getExpandedCategoryFacetDefinition(this.categoryID);
-
 
88
		
-
 
89
		List<ExpandedFacetDefinition> expFacetDefs = 
-
 
90
			expCategoryFacetDef.getExpandedFacetDefinitions();
-
 
91
		
-
 
92
		// Get all entities for the category
-
 
93
		List<Entity> entities = ents.getEntities(this.categoryID);
-
 
94
		
-
 
95
		JythonWrapper jw = new JythonWrapper();
18
		
96
		
-
 
97
		// For each entity 
-
 
98
		if(entities != null) {
-
 
99
			for(Entity entity : entities) {
-
 
100
				
-
 
101
				// For each facet execute Rule
-
 
102
				for(ExpandedFacetDefinition expFacetDef : expFacetDefs) {
-
 
103
					jw.initialize();
-
 
104
					
-
 
105
					jw.setEntity(entity);
-
 
106
					jw.setExpandedFacetDefinition(expFacetDef);
-
 
107
					
-
 
108
					// To reduce scripts work
-
 
109
					
-
 
110
					// Set FeatureDefinition
-
 
111
					FeatureDefinition featureDef = 
-
 
112
						expFacetDef.getFeatureDefinition();
-
 
113
					if(featureDef != null) {
-
 
114
						jw.setFeatureDefinition(featureDef);
-
 
115
						
-
 
116
						// Set Feature
-
 
117
						Feature feature = 
-
 
118
							ents.getFeature(entity.getID(), featureDef.getID());
-
 
119
						jw.setFeature(feature);
-
 
120
					}
-
 
121
					
-
 
122
					// Set SlideDefinition
-
 
123
					SlideDefinition slideDef = expFacetDef.getSlideDefinition();
-
 
124
					if(slideDef != null) {
-
 
125
						jw.setSlideDefinition(slideDef);
-
 
126
						
-
 
127
						// Set Slide
-
 
128
						Slide slide = ents.getSlide(entity.getID(), 
-
 
129
								slideDef.getID());
-
 
130
						jw.setSlide(slide);
-
 
131
					}
-
 
132
					
-
 
133
					jw.execIRDataRule();
-
 
134
					
-
 
135
					List<Object> values = (List<Object>)jw.getValues();
-
 
136
					Utils.info("values=" + values);
-
 
137
				}
-
 
138
				
-
 
139
			}
-
 
140
		}
19
	}
141
	}
20
}
142
}