Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 shop2020 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.definitions;
5
 
17 naveen 6
import in.shop2020.metamodel.util.DBUtils;
7
import in.shop2020.metamodel.util.MM;
8
 
10 shop2020 9
import java.io.Serializable;
18 naveen 10
import java.util.ArrayList;
11
import java.util.Iterator;
12
import java.util.List;
10 shop2020 13
import java.util.Map;
14
 
15
/**
16
 * @author naveen
17
 *
18
 */
19
public class DefinitionsContainer implements Serializable {
20
 
21
	/**
22
	 * 
23
	 */
24
	private static final long serialVersionUID = 1L;
25
	private Map<Long, Category> categories;
26
	private Map<Long, SlideDefinition> slideDefinitions;
27
	private Map<Long, FeatureDefinition> featureDefinitions;
28
	private Map<Long, DatatypeDefinition> datatypeDefinitions;
29
	private Map<Long, Unit> units;
30
 
31
	/**
32
	 * 
33
	 */
34
	public DefinitionsContainer() {
17 naveen 35
		// Lazy initialization
10 shop2020 36
	}
37
 
38
	/**
39
	 * 
40
	 * @return Map
18 naveen 41
	 * @throws Exception 
10 shop2020 42
	 */
18 naveen 43
	@SuppressWarnings("unchecked")
44
	public Map<Long, Unit> getUnits() throws Exception {		
17 naveen 45
		// De-serialize
46
		if(this.units == null) {
18 naveen 47
			String dbFile = MM.DEFINITIONS_DB_PATH + "units" + ".ser";
48
 
49
			this.units = (Map<Long, Unit>) DBUtils.read(dbFile);
17 naveen 50
		}
18 naveen 51
 
10 shop2020 52
		return this.units;
53
	}
54
 
55
	/**
56
	 * 
57
	 * @param unitID
58
	 * @return Unit
18 naveen 59
	 * @throws Exception 
10 shop2020 60
	 */
18 naveen 61
	public Unit getUnit(long unitID) throws Exception {		
62
		// Initialize 
63
		if(this.units == null) {
64
			this.getUnits();
65
		}
17 naveen 66
 
10 shop2020 67
		return this.units.get(new Long(unitID));
68
	}
69
 
70
	/**
17 naveen 71
	 * @return the datatypeDefinitions
18 naveen 72
	 * @throws Exception 
10 shop2020 73
	 */
18 naveen 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;
10 shop2020 86
	}
18 naveen 87
 
88
	/**
89
	 * 
90
	 * @param unitID
91
	 * @return Unit
92
	 * @throws Exception 
93
	 */
94
	public DatatypeDefinition getDatatypeDefinition(long id) throws Exception {
95
 
96
		// Initialize 
97
		if(this.datatypeDefinitions == null) {
98
			this.getDatatypeDefinitions();
99
		}
100
 
101
		return this.datatypeDefinitions.get(new Long(id));
102
	}
17 naveen 103
 
10 shop2020 104
	/**
105
	 * @return the categories
17 naveen 106
	 * @throws Exception 
10 shop2020 107
	 */
17 naveen 108
	@SuppressWarnings("unchecked")
109
	public Map<Long, Category> getCategories() throws Exception {
110
 
111
		// De-serialize
112
		if(this.categories == null) {
113
			String dbFile = MM.DEFINITIONS_DB_PATH + "categories" + ".ser";
114
 
115
			this.categories = (Map<Long, Category>) DBUtils.read(dbFile);
116
		}
117
		return this.categories;
10 shop2020 118
	}
17 naveen 119
 
10 shop2020 120
	/**
17 naveen 121
	 * 
122
	 * @param categoryID
123
	 * @return Category
124
	 * @throws Exception 
10 shop2020 125
	 */
17 naveen 126
	public Category getCategory(long categoryID) throws Exception {
127
 
18 naveen 128
		// Initialize 
17 naveen 129
		if(this.categories == null) {
130
			this.getCategories();
131
		}
132
 
133
		return this.categories.get(new Long(categoryID));
10 shop2020 134
	}
17 naveen 135
 
10 shop2020 136
	/**
18 naveen 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
	/**
10 shop2020 150
	 * @return the slideDefinitions
18 naveen 151
	 * @throws Exception 
10 shop2020 152
	 */
18 naveen 153
	@SuppressWarnings("unchecked")
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
		}
164
		return this.slideDefinitions;
10 shop2020 165
	}
18 naveen 166
 
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
187
	 * @return List<SlideDefinition>
188
	 * @throws Exception 
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")
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
		}
228
		return this.featureDefinitions;
229
	}
10 shop2020 230
 
231
	/**
18 naveen 232
	 * 
233
	 * @param id
234
	 * @return
235
	 * @throws Exception
10 shop2020 236
	 */
18 naveen 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
	}	
10 shop2020 246
}