Subversion Repositories SmartDukaan

Rev

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

Rev 17 Rev 18
Line 5... Line 5...
5
 
5
 
6
import in.shop2020.metamodel.util.DBUtils;
6
import in.shop2020.metamodel.util.DBUtils;
7
import in.shop2020.metamodel.util.MM;
7
import in.shop2020.metamodel.util.MM;
8
 
8
 
9
import java.io.Serializable;
9
import java.io.Serializable;
-
 
10
import java.util.ArrayList;
-
 
11
import java.util.Iterator;
10
import java.util.HashMap;
12
import java.util.List;
11
import java.util.Map;
13
import java.util.Map;
12
 
14
 
13
/**
15
/**
14
 * @author naveen
16
 * @author naveen
15
 *
17
 *
Line 34... Line 36...
34
	}
36
	}
35
	
37
	
36
	/**
38
	/**
37
	 * 
39
	 * 
38
	 * @return Map
40
	 * @return Map
-
 
41
	 * @throws Exception 
39
	 */
42
	 */
40
	public Map<Long, Unit> getUnits() {
43
	@SuppressWarnings("unchecked")
41
		System.out.println("getUnits()");
44
	public Map<Long, Unit> getUnits() throws Exception {		
42
		
-
 
43
		// De-serialize
45
		// De-serialize
44
		if(this.units == null) {
46
		if(this.units == null) {
-
 
47
			String dbFile = MM.DEFINITIONS_DB_PATH + "units" + ".ser";
45
			// TODO
48
			
-
 
49
			this.units = (Map<Long, Unit>) DBUtils.read(dbFile);
46
		}
50
		}
-
 
51
		
47
		return this.units;
52
		return this.units;
48
	}
53
	}
49
 
54
 
50
	/**
55
	/**
51
	 * 
56
	 * 
52
	 * @param unitID
57
	 * @param unitID
53
	 * @return Unit
58
	 * @return Unit
-
 
59
	 * @throws Exception 
54
	 */
60
	 */
55
	public Unit getUnit(long unitID) {
61
	public Unit getUnit(long unitID) throws Exception {		
56
		System.out.println("getUnit("+ unitID +")");
-
 
57
		
-
 
58
		// Inititial 
62
		// Initialize 
-
 
63
		if(this.units == null) {
59
		this.getUnits();
64
			this.getUnits();
-
 
65
		}
60
		
66
		
61
		return this.units.get(new Long(unitID));
67
		return this.units.get(new Long(unitID));
62
	}
68
	}
63
 
69
 
64
	/**
70
	/**
65
	 * @return the datatypeDefinitions
71
	 * @return the datatypeDefinitions
-
 
72
	 * @throws Exception 
-
 
73
	 */
-
 
74
	@SuppressWarnings("unchecked")
-
 
75
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() 
-
 
76
		throws Exception {
-
 
77
		
-
 
78
		// De-serialize
-
 
79
		if(this.datatypeDefinitions == null) {
-
 
80
			String dbFile = MM.DEFINITIONS_DB_PATH + "datatypedefinitions" + ".ser";
-
 
81
			
-
 
82
			this.datatypeDefinitions = 
-
 
83
				(Map<Long, DatatypeDefinition>) DBUtils.read(dbFile);
-
 
84
		}
-
 
85
		return this.datatypeDefinitions;
-
 
86
	}
-
 
87
 
-
 
88
	/**
-
 
89
	 * 
-
 
90
	 * @param unitID
-
 
91
	 * @return Unit
-
 
92
	 * @throws Exception 
66
	 */
93
	 */
67
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() {
94
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
-
 
95
		
-
 
96
		// Initialize 
-
 
97
		if(this.datatypeDefinitions == null) {
68
		return datatypeDefinitions;
98
			this.getDatatypeDefinitions();
-
 
99
		}
-
 
100
		
-
 
101
		return this.datatypeDefinitions.get(new Long(id));
69
	}
102
	}
70
	
103
	
71
	/**
104
	/**
72
	 * @return the categories
105
	 * @return the categories
73
	 * @throws Exception 
106
	 * @throws Exception 
74
	 */
107
	 */
75
	@SuppressWarnings("unchecked")
108
	@SuppressWarnings("unchecked")
76
	public Map<Long, Category> getCategories() throws Exception {
109
	public Map<Long, Category> getCategories() throws Exception {
77
		System.out.println("getCategories()");
-
 
78
		
110
		
79
		// De-serialize
111
		// De-serialize
80
		if(this.categories == null) {
112
		if(this.categories == null) {
81
			String dbFile = MM.DEFINITIONS_DB_PATH + "categories" + ".ser";
113
			String dbFile = MM.DEFINITIONS_DB_PATH + "categories" + ".ser";
82
			
114
			
Line 90... Line 122...
90
	 * @param categoryID
122
	 * @param categoryID
91
	 * @return Category
123
	 * @return Category
92
	 * @throws Exception 
124
	 * @throws Exception 
93
	 */
125
	 */
94
	public Category getCategory(long categoryID) throws Exception {
126
	public Category getCategory(long categoryID) throws Exception {
95
		System.out.println("getCategory("+ categoryID +")");
-
 
96
		
127
		
97
		// Inititial 
128
		// Initialize 
98
		if(this.categories == null) {
129
		if(this.categories == null) {
99
			this.getCategories();
130
			this.getCategories();
100
		}
131
		}
101
		
132
		
102
		return this.categories.get(new Long(categoryID));
133
		return this.categories.get(new Long(categoryID));
103
	}
134
	}
104
	
135
	
105
	/**
136
	/**
-
 
137
	 * 
-
 
138
	 * @param categoryID
-
 
139
	 * @return List<CategorySlideDefinition> 
-
 
140
	 * @throws Exception 
-
 
141
	 */
-
 
142
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
-
 
143
			long categoryID) throws Exception {
-
 
144
		Category category = this.getCategory(categoryID);
-
 
145
		
-
 
146
		return category.getCategorySlideDefintions();
-
 
147
	}
-
 
148
	
-
 
149
	/**
106
	 * @return the slideDefinitions
150
	 * @return the slideDefinitions
-
 
151
	 * @throws Exception 
107
	 */
152
	 */
-
 
153
	@SuppressWarnings("unchecked")
108
	public Map<Long, SlideDefinition> getSlideDefinitions() {
154
	public Map<Long, SlideDefinition> getSlideDefinitions() throws Exception {
-
 
155
		
-
 
156
		// De-serialize
-
 
157
		if(this.slideDefinitions == null) {
-
 
158
			String dbFile = MM.DEFINITIONS_DB_PATH + "slidedefinitions" + 
-
 
159
				".ser";
-
 
160
			
-
 
161
			this.slideDefinitions = 
-
 
162
				(Map<Long, SlideDefinition>) DBUtils.read(dbFile);
-
 
163
		}
109
		return slideDefinitions;
164
		return this.slideDefinitions;
110
	}
165
	}
111
 
166
	
112
	/**
167
	/**
-
 
168
	 * 
-
 
169
	 * @param id
-
 
170
	 * @return SlideDefinition
-
 
171
	 * @throws Exception
-
 
172
	 */
-
 
173
	public SlideDefinition getSlideDefinition(long id) throws Exception {
-
 
174
		
-
 
175
		// Initialize 
-
 
176
		if(this.slideDefinitions == null) {
-
 
177
			this.getSlideDefinitions();
-
 
178
		}
-
 
179
		
-
 
180
		return this.slideDefinitions.get(new Long(id));
-
 
181
	}
-
 
182
	
-
 
183
	/**
-
 
184
	 * 
-
 
185
	 * @param categoryID
-
 
186
	 * @param EditorialImportance imp
113
	 * @return the featureDefinitions
187
	 * @return List<SlideDefinition>
-
 
188
	 * @throws Exception 
114
	 */
189
	 */
-
 
190
	public List<SlideDefinition> getSlides(long categoryID, 
-
 
191
			EditorialImportance imp) 
-
 
192
		throws Exception {
-
 
193
		
-
 
194
		List<CategorySlideDefinition> catSlideDefs = 
-
 
195
			this.getCategorySlideDefinitions(categoryID);
-
 
196
		
-
 
197
		Iterator<CategorySlideDefinition> itCatSlideDefs = 
-
 
198
			catSlideDefs.iterator();
-
 
199
		
-
 
200
		List<SlideDefinition> slideDefs = new ArrayList<SlideDefinition>();
-
 
201
		while(itCatSlideDefs.hasNext()) {
-
 
202
			CategorySlideDefinition catSlideDef = itCatSlideDefs.next();
-
 
203
			if(catSlideDef.getEditorialImportance() == imp) {
-
 
204
				long slideDefID = catSlideDef.getSlideDefintionID();
-
 
205
				slideDefs.add(this.getSlideDefinition(slideDefID));
-
 
206
			}
-
 
207
		}
-
 
208
		return slideDefs;
-
 
209
	}
-
 
210
	
-
 
211
	/**
-
 
212
	 * 
-
 
213
	 * @return Map<Long, FeatureDefinition>
-
 
214
	 * @throws Exception
-
 
215
	 */
-
 
216
	@SuppressWarnings("unchecked")
115
	public Map<Long, FeatureDefinition> getFeatureDefinitions() {
217
	public Map<Long, FeatureDefinition> getFeatureDefinitions() 
-
 
218
		throws Exception {
-
 
219
		
-
 
220
		// De-serialize
-
 
221
		if(this.featureDefinitions == null) {
-
 
222
			String dbFile = MM.DEFINITIONS_DB_PATH + "featuredefinitions" + 
-
 
223
				".ser";
-
 
224
			
-
 
225
			this.featureDefinitions = 
-
 
226
				(Map<Long, FeatureDefinition>) DBUtils.read(dbFile);
-
 
227
		}
116
		return featureDefinitions;
228
		return this.featureDefinitions;
117
	}
229
	}
-
 
230
 
-
 
231
	/**
-
 
232
	 * 
-
 
233
	 * @param id
-
 
234
	 * @return
-
 
235
	 * @throws Exception
-
 
236
	 */
-
 
237
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
-
 
238
		
-
 
239
		// Initialize 
-
 
240
		if(this.featureDefinitions == null) {
-
 
241
			this.getFeatureDefinitions();
-
 
242
		}
-
 
243
		
-
 
244
		return this.featureDefinitions.get(new Long(id));
-
 
245
	}	
118
}
246
}