Subversion Repositories SmartDukaan

Rev

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

Rev 45 Rev 49
Line 12... Line 12...
12
import java.util.Iterator;
12
import java.util.Iterator;
13
import java.util.List;
13
import java.util.List;
14
import java.util.Map;
14
import java.util.Map;
15
 
15
 
16
/**
16
/**
-
 
17
 * Single point of access to all definition objects
-
 
18
 * 
17
 * @author naveen
19
 * @author naveen
18
 *
20
 *
19
 */
21
 */
20
public class DefinitionsContainer implements Serializable {
22
public class DefinitionsContainer implements Serializable {
21
 
23
 
22
	/** 
24
	/** 
23
	 * 
25
	 * 
24
	 */
26
	 */
25
	private static final long serialVersionUID = 1L;
27
	private static final long serialVersionUID = 1L;
-
 
28
	
-
 
29
	/**
-
 
30
	 * Hashtable of Category ID to Category object
-
 
31
	 */
26
	private Map<Long, Category> categories;
32
	private Map<Long, Category> categories;
-
 
33
	
-
 
34
	/**
-
 
35
	 * Hashtable of Slide ID to SlideDefinition object
-
 
36
	 */
27
	private Map<Long, SlideDefinition> slideDefinitions;
37
	private Map<Long, SlideDefinition> slideDefinitions;
-
 
38
	
-
 
39
	/**
-
 
40
	 * Hashtable of Feature Definition ID to FeatureDefinition object
-
 
41
	 */
28
	private Map<Long, FeatureDefinition> featureDefinitions;
42
	private Map<Long, FeatureDefinition> featureDefinitions;
-
 
43
	
-
 
44
	/**
-
 
45
	 * Hashtable of Datatype Definition ID to DatatypeDefinition object
-
 
46
	 */
29
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
47
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
-
 
48
	
-
 
49
	/**
-
 
50
	 * Hashtable of Enum value ID to EnumValue object
-
 
51
	 */
30
	private Map<Long, EnumValue> enumValues;
52
	private Map<Long, EnumValue> enumValues;
-
 
53
	
-
 
54
	/**
-
 
55
	 * Hashtable of Unit ID to Unit object
-
 
56
	 */
31
	private Map<Long, Unit> units;
57
	private Map<Long, Unit> units;
32
	
58
	
33
	/**
59
	/**
34
	 * 
-
 
-
 
60
	 * Empty constructor. Data structures are initialised as needed
35
	 */
61
	 */
36
	public DefinitionsContainer() {
62
	public DefinitionsContainer() {
37
		// Lazy initialization
63
		// Lazy initialization
38
	}
64
	}
39
	
65
	
40
	/**
66
	/**
-
 
67
	 * Returns all Unit objects in the database
-
 
68
	 * 
-
 
69
	 * @return Map Null if units are not imported into definitions db 
-
 
70
	 * (serialized java objects)
41
	 * 
71
	 * 
42
	 * @return Map
-
 
43
	 * @throws Exception 
72
	 * @throws Exception 
44
	 */
73
	 */
45
	@SuppressWarnings("unchecked")
74
	@SuppressWarnings("unchecked")
46
	public Map<Long, Unit> getUnits() throws Exception {		
75
	public Map<Long, Unit> getUnits() throws Exception {		
47
		// De-serialize
76
		// De-serialize
Line 53... Line 82...
53
		
82
		
54
		return this.units;
83
		return this.units;
55
	}
84
	}
56
 
85
 
57
	/**
86
	/**
-
 
87
	 * Resolves Unit ID into Unit object
58
	 * 
88
	 * 
59
	 * @param unitID
89
	 * @param unitID Unit ID
60
	 * @return Unit
90
	 * @return Unit
61
	 * @throws Exception 
91
	 * @throws Exception 
62
	 */
92
	 */
63
	public Unit getUnit(long unitID) throws Exception {		
93
	public Unit getUnit(long unitID) throws Exception {		
64
		// Initialize 
94
		// Initialize 
Line 68... Line 98...
68
		
98
		
69
		return this.units.get(new Long(unitID));
99
		return this.units.get(new Long(unitID));
70
	}
100
	}
71
 
101
 
72
	/**
102
	/**
73
	 * @return the datatypeDefinitions
103
	 * Returns all DatatypeDefintion object in database
-
 
104
	 * 
-
 
105
	 * @return the datatypeDefinitions List of DatatypeDefinition objects
74
	 * @throws Exception 
106
	 * @throws Exception 
75
	 */
107
	 */
76
	@SuppressWarnings("unchecked")
108
	@SuppressWarnings("unchecked")
77
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() 
109
	public Map<Long, DatatypeDefinition> getDatatypeDefinitions() 
78
		throws Exception {
110
		throws Exception {
Line 87... Line 119...
87
		}
119
		}
88
		return this.datatypeDefinitions;
120
		return this.datatypeDefinitions;
89
	}
121
	}
90
 
122
 
91
	/**
123
	/**
-
 
124
	 * Resolves Datatype Definition ID into DatetypeDefinition object
92
	 * 
125
	 * 
93
	 * @param unitID
126
	 * @param unitID Unit ID
94
	 * @return Unit
127
	 * @return Unit
95
	 * @throws Exception 
128
	 * @throws Exception 
96
	 */
129
	 */
97
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
130
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
98
		
131
		
Line 103... Line 136...
103
		
136
		
104
		return this.datatypeDefinitions.get(new Long(id));
137
		return this.datatypeDefinitions.get(new Long(id));
105
	}
138
	}
106
 
139
 
107
	/**
140
	/**
-
 
141
	 * Returns EnumValue ID for datatype definition ID and enum value string 
-
 
142
	 * to match. Match is case insensitive
108
	 * 
143
	 * 
109
	 * @param datatypeDefID
144
	 * @param datatypeDefID DatatypeDefinition ID
110
	 * @param value
145
	 * @param value query enum value string
111
	 * @return long enumValueID - "-1" if not found
146
	 * @return long enumValueID - "-1" if not found
112
	 * @throws Exception 
147
	 * @throws Exception 
113
	 */
148
	 */
114
	public long getEnumValueID(long datatypeDefID, String value) 
149
	public long getEnumValueID(long datatypeDefID, String value) 
115
		throws Exception {
150
		throws Exception {
Line 129... Line 164...
129
		
164
		
130
		return enumValueID;
165
		return enumValueID;
131
	}
166
	}
132
	
167
	
133
	/**
168
	/**
-
 
169
	 * Returns all category objects in the database
-
 
170
	 * 
134
	 * @return the categories
171
	 * @return the categories
135
	 * @throws Exception 
172
	 * @throws Exception 
136
	 */
173
	 */
137
	@SuppressWarnings("unchecked")
174
	@SuppressWarnings("unchecked")
138
	public Map<Long, Category> getCategories() throws Exception {
175
	public Map<Long, Category> getCategories() throws Exception {
Line 145... Line 182...
145
		}
182
		}
146
		return this.categories;
183
		return this.categories;
147
	}
184
	}
148
	
185
	
149
	/**
186
	/**
-
 
187
	 * Resolves Category ID into Category object
150
	 * 
188
	 * 
151
	 * @param categoryID
189
	 * @param categoryID Category ID
152
	 * @return Category
190
	 * @return Category
153
	 * @throws Exception 
191
	 * @throws Exception 
154
	 */
192
	 */
155
	public Category getCategory(long categoryID) throws Exception {
193
	public Category getCategory(long categoryID) throws Exception {
156
		
194
		
Line 161... Line 199...
161
		
199
		
162
		return this.categories.get(new Long(categoryID));
200
		return this.categories.get(new Long(categoryID));
163
	}
201
	}
164
	
202
	
165
	/**
203
	/**
-
 
204
	 * Returns expanded Category object. All numeric identifiers are resolved 
-
 
205
	 * into detailed objects
166
	 * 
206
	 * 
167
	 * @param categoryID
207
	 * @param categoryID
168
	 * @return ExpandedCategory
208
	 * @return ExpandedCategory
169
	 * @throws Exception
209
	 * @throws Exception
170
	 */
210
	 */
Line 176... Line 216...
176
		
216
		
177
		return expCategory;
217
		return expCategory;
178
	}
218
	}
179
	
219
	
180
	/**
220
	/**
-
 
221
	 * Returns all children categories for a Category ID
181
	 * 
222
	 * 
182
	 * @param categoryID
223
	 * @param categoryID
183
	 * @return List<Category> 
224
	 * @return List<Category> Children Categories
184
	 * @throws Exception
225
	 * @throws Exception
185
	 */
226
	 */
186
	public List<Category> getChildrenCategories(long categoryID) 
227
	public List<Category> getChildrenCategories(long categoryID) 
187
		throws Exception {
228
		throws Exception {
188
		
229
		
Line 191... Line 232...
191
			this.getCategories();
232
			this.getCategories();
192
		}
233
		}
193
		
234
		
194
		return this.categories.get(new Long(categoryID)).getChildrenCategory();
235
		return this.categories.get(new Long(categoryID)).getChildrenCategory();
195
	}
236
	}
-
 
237
	
196
	/**
238
	/**
-
 
239
	 * Returns all CategorySlideDefinition objects for a Category ID
197
	 * 
240
	 * 
198
	 * @param categoryID
241
	 * @param categoryID Category ID
199
	 * @return List<CategorySlideDefinition> 
242
	 * @return List<CategorySlideDefinition> 
200
	 * @throws Exception 
243
	 * @throws Exception 
201
	 */
244
	 */
202
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
245
	public List<CategorySlideDefinition> getCategorySlideDefinitions(
203
			long categoryID) throws Exception {
246
			long categoryID) throws Exception {
Line 205... Line 248...
205
		
248
		
206
		return category.getCategorySlideDefintions();
249
		return category.getCategorySlideDefintions();
207
	}
250
	}
208
	
251
	
209
	/**
252
	/**
-
 
253
	 * Returns All SlideDefinition objects in database
-
 
254
	 * 
210
	 * @return the slideDefinitions
255
	 * @return the slideDefinitions
211
	 * @throws Exception 
256
	 * @throws Exception 
212
	 */
257
	 */
213
	@SuppressWarnings("unchecked")
258
	@SuppressWarnings("unchecked")
214
	public Map<Long, SlideDefinition> getSlideDefinitions() throws Exception {
259
	public Map<Long, SlideDefinition> getSlideDefinitions() throws Exception {
Line 223... Line 268...
223
		}
268
		}
224
		return this.slideDefinitions;
269
		return this.slideDefinitions;
225
	}
270
	}
226
	
271
	
227
	/**
272
	/**
-
 
273
	 * Resolves SlideDefinition ID into SlideDefinition object
228
	 * 
274
	 * 
229
	 * @param id
275
	 * @param id
230
	 * @return SlideDefinition
276
	 * @return SlideDefinition
231
	 * @throws Exception
277
	 * @throws Exception
232
	 */
278
	 */
Line 239... Line 285...
239
		
285
		
240
		return this.slideDefinitions.get(new Long(id));
286
		return this.slideDefinitions.get(new Long(id));
241
	}
287
	}
242
	
288
	
243
	/**
289
	/**
-
 
290
	 * Returns SlideDefinition objects for a category and matching slide label
244
	 * 
291
	 * 
245
	 * @param label
292
	 * @param label
246
	 * @return List<SlideDefinition>
293
	 * @return List<SlideDefinition>
247
	 * @throws Exception
294
	 * @throws Exception
248
	 */
295
	 */
Line 268... Line 315...
268
		
315
		
269
		return matchingSlides;
316
		return matchingSlides;
270
	}
317
	}
271
	
318
	
272
	/**
319
	/**
-
 
320
	 * Resolves Category ID into Category object
273
	 * 
321
	 * 
274
	 * @param categoryID
322
	 * @param categoryID
275
	 * @return
323
	 * @return List<SlideDefinition> 
276
	 * @throws Exception
324
	 * @throws Exception
277
	 */
325
	 */
278
	public List<SlideDefinition> getSlideDefinitions(long categoryID) 
326
	public List<SlideDefinition> getSlideDefinitions(long categoryID) 
279
		throws Exception {
327
		throws Exception {
280
 
328
 
Line 293... Line 341...
293
			matchingSlides.add(sDef);
341
			matchingSlides.add(sDef);
294
		}
342
		}
295
		
343
		
296
		return matchingSlides;
344
		return matchingSlides;
297
	}
345
	}
-
 
346
	
298
	/**
347
	/**
-
 
348
	 * Returns list of SlideDefinition objects for a category and editorial 
-
 
349
	 * importance value
299
	 * 
350
	 * 
300
	 * @param categoryID
351
	 * @param categoryID
301
	 * @param EditorialImportance imp
352
	 * @param EditorialImportance imp
302
	 * @return List<SlideDefinition>
353
	 * @return List<SlideDefinition>
303
	 * @throws Exception 
354
	 * @throws Exception 
Line 322... Line 373...
322
		}
373
		}
323
		return slideDefs;
374
		return slideDefs;
324
	}
375
	}
325
	
376
	
326
	/**
377
	/**
-
 
378
	 * Returns all FeatureDefinition object in database
327
	 * 
379
	 * 
328
	 * @return Map<Long, FeatureDefinition>
380
	 * @return Map<Long, FeatureDefinition>
329
	 * @throws Exception
381
	 * @throws Exception
330
	 */
382
	 */
331
	@SuppressWarnings("unchecked")
383
	@SuppressWarnings("unchecked")
Line 342... Line 394...
342
		}
394
		}
343
		return this.featureDefinitions;
395
		return this.featureDefinitions;
344
	}
396
	}
345
	
397
	
346
	/**
398
	/**
-
 
399
	 * Returns all FeatureDefinition objects for a slide
347
	 * 
400
	 * 
348
	 * @param slideID
401
	 * @param slideID
349
	 * @return List<FeatureDefinition> 
402
	 * @return List<FeatureDefinition> 
350
	 * @throws Exception
403
	 * @throws Exception
351
	 */
404
	 */
Line 365... Line 418...
365
		
418
		
366
		return featureDefs;
419
		return featureDefs;
367
	}
420
	}
368
	
421
	
369
	/**
422
	/**
-
 
423
	 * Returns list of FeatureDefinition objects for a slide given editorial 
-
 
424
	 * importance
370
	 * 
425
	 * 
371
	 * @param slideID
426
	 * @param slideID
372
	 * @param imp
427
	 * @param imp Editorial Importance enum object
373
	 * @return List<FeatureDefinition>
428
	 * @return List<FeatureDefinition>
374
	 * @throws Exception
429
	 * @throws Exception
375
	 */
430
	 */
376
	public List<FeatureDefinition> getFeatureDefinitions(long slideID, 
431
	public List<FeatureDefinition> getFeatureDefinitions(long slideID, 
377
			EditorialImportance imp)  throws Exception {
432
			EditorialImportance imp)  throws Exception {
Line 391... Line 446...
391
		
446
		
392
		return featureDefs;
447
		return featureDefs;
393
	}
448
	}
394
	
449
	
395
	/**
450
	/**
-
 
451
	 * Resolves Feature Definition ID into FeatureDefinition object
396
	 * 
452
	 * 
397
	 * @param id
453
	 * @param id Feature Definition ID 
398
	 * @return FeatureDefinition
454
	 * @return FeatureDefinition
399
	 * @throws Exception
455
	 * @throws Exception
400
	 */
456
	 */
401
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
457
	public FeatureDefinition getFeatureDefinition(long id) throws Exception {
402
		
458
		
Line 407... Line 463...
407
		
463
		
408
		return this.featureDefinitions.get(new Long(id));
464
		return this.featureDefinitions.get(new Long(id));
409
	}	
465
	}	
410
 
466
 
411
	/**
467
	/**
-
 
468
	 * Returns matching FeatureDefinition object for slide ID and feature label.
-
 
469
	 * Label matching is case insensitive.
412
	 * 
470
	 * 
413
	 * @param slideID
471
	 * @param slideID Slide ID
414
	 * @param featureLabel
472
	 * @param featureLabel label to match, case is ignored
415
	 * @return FeatureDefinition 
473
	 * @return FeatureDefinition 
416
	 * @throws Exception
474
	 * @throws Exception
417
	 */
475
	 */
418
	public FeatureDefinition getFeatureDefinition(long slideID, 
476
	public FeatureDefinition getFeatureDefinition(long slideID, 
419
			String featureLabel) throws Exception {
477
			String featureLabel) throws Exception {
Line 435... Line 493...
435
		
493
		
436
		return featureDef;
494
		return featureDef;
437
	}
495
	}
438
 
496
 
439
	/**
497
	/**
-
 
498
	 * Returns all EnumValue objects in the database
-
 
499
	 * 
440
	 * @return the enumValues
500
	 * @return the enumValues
441
	 * @throws Exception 
501
	 * @throws Exception 
442
	 */
502
	 */
443
	@SuppressWarnings("unchecked")
503
	@SuppressWarnings("unchecked")
444
	public Map<Long, EnumValue> getEnumValues() throws Exception {
504
	public Map<Long, EnumValue> getEnumValues() throws Exception {
Line 453... Line 513...
453
		
513
		
454
		return this.enumValues;
514
		return this.enumValues;
455
	}
515
	}
456
	
516
	
457
	/**
517
	/**
-
 
518
	 * Resolves Enum value ID into EnumValue object
458
	 * 
519
	 * 
459
	 * @param enumValueID
520
	 * @param enumValueID
460
	 * @return EnumValue
521
	 * @return EnumValue
461
	 * @throws Exception
522
	 * @throws Exception
462
	 */
523
	 */