Subversion Repositories SmartDukaan

Rev

Rev 1153 | Rev 1165 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1153 Rev 1154
Line 13... Line 13...
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Collection;
14
import java.util.Collection;
15
import java.util.List;
15
import java.util.List;
16
import java.util.Map;
16
import java.util.Map;
17
 
17
 
18
 
-
 
19
/**
18
/**
-
 
19
 * All storage and retrival utility methods
20
 * @author rajveer
20
 * @author rajveer
21
 * @description 
-
 
22
 *
21
 *
23
 */
22
 */
24
public class CreationUtils {
23
public class CreationUtils {
25
	
24
	
26
	private static final String LEARNED_BULLETS = "LEARNED_BULLETS";
25
	private static final String LEARNED_BULLETS = "LEARNED_BULLETS";
Line 48... Line 47...
48
	 */
47
	 */
49
	public static void storeLearnedBullets(Map<Long, List<ExpandedBullet>> learnedBullets) throws Exception {
48
	public static void storeLearnedBullets(Map<Long, List<ExpandedBullet>> learnedBullets) throws Exception {
50
		StorageManager.getStorageManager().storeDataObject(CreationUtils.LEARNED_BULLETS, learnedBullets);		
49
		StorageManager.getStorageManager().storeDataObject(CreationUtils.LEARNED_BULLETS, learnedBullets);		
51
	}
50
	}
52
	
51
	
-
 
52
	/**
-
 
53
	 * 
-
 
54
	 * @return
-
 
55
	 * @throws Exception
-
 
56
	 */
53
	@SuppressWarnings("unchecked")
57
	@SuppressWarnings("unchecked")
54
	public static Map<Long, List<ExpandedBullet>> getLearnedBullets() throws Exception {
58
	public static Map<Long, List<ExpandedBullet>> getLearnedBullets() throws Exception {
55
		return (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);		
59
		return (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);		
56
	}
60
	}
57
	
61
	
-
 
62
	/**
-
 
63
	 * 
-
 
64
	 * @param featureDefinitionID
-
 
65
	 * @return
-
 
66
	 * @throws Exception
-
 
67
	 */
58
	@SuppressWarnings("unchecked")
68
	@SuppressWarnings("unchecked")
59
	public static List<ExpandedBullet> getLearnedBullets(long featureDefinitionID) throws Exception {
69
	public static List<ExpandedBullet> getLearnedBullets(long featureDefinitionID) throws Exception {
60
		Map<Long, List<ExpandedBullet>> learnedBullets = (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);
70
		Map<Long, List<ExpandedBullet>> learnedBullets = (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);
61
		if(learnedBullets==null){
71
		if(learnedBullets==null){
62
			return null;
72
			return null;
63
		}
73
		}
64
		return learnedBullets.get(featureDefinitionID);
74
		return learnedBullets.get(featureDefinitionID);
65
	}
75
	}
66
 
76
 
-
 
77
	/**
-
 
78
	 * 
-
 
79
	 * @param facetIDFacetValues
-
 
80
	 * @throws Exception
-
 
81
	 */
67
	public static void storeFacetValues(Map<Long, List<String>> facetIDFacetValues) throws Exception {
82
	public static void storeFacetValues(Map<Long, List<String>> facetIDFacetValues) throws Exception {
68
		StorageManager.getStorageManager().storeDataObject(CreationUtils.FACET_VALUES, facetIDFacetValues);
83
		StorageManager.getStorageManager().storeDataObject(CreationUtils.FACET_VALUES, facetIDFacetValues);
69
	}
84
	}
70
 
85
 
-
 
86
	/**
-
 
87
	 * 
-
 
88
	 * @return
-
 
89
	 * @throws Exception
-
 
90
	 */
71
	@SuppressWarnings("unchecked")
91
	@SuppressWarnings("unchecked")
72
	public static Map<Long, List<String>>  getFacetValues() throws Exception {
92
	public static Map<Long, List<String>>  getFacetValues() throws Exception {
73
		return (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
93
		return (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
74
	}
94
	}
75
 
95
 
-
 
96
	/**
-
 
97
	 * 
-
 
98
	 * @param facetDefinitionID
-
 
99
	 * @return
-
 
100
	 * @throws Exception
-
 
101
	 */
76
	@SuppressWarnings("unchecked")
102
	@SuppressWarnings("unchecked")
77
	public static List<String>  getFacetValues(long facetDefinitionID) throws Exception {
103
	public static List<String>  getFacetValues(long facetDefinitionID) throws Exception {
78
		Map<Long, List<String>> facetValues = (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
104
		Map<Long, List<String>> facetValues = (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
79
		return facetValues.get(facetDefinitionID);
105
		return facetValues.get(facetDefinitionID);
80
	}
106
	}
81
 
107
 
-
 
108
	/**
-
 
109
	 * 
-
 
110
	 * @param slideScoresByEntity
-
 
111
	 * @throws Exception
82
	
112
	 */
83
	public static void storeSlideScores( Map<Long, Map<Long, Integer>> slideScoresByEntity) throws Exception {
113
	public static void storeSlideScores( Map<Long, Map<Long, Integer>> slideScoresByEntity) throws Exception {
84
		StorageManager.getStorageManager().storeDataObject(CreationUtils.SLIDE_SCORES, slideScoresByEntity);
114
		StorageManager.getStorageManager().storeDataObject(CreationUtils.SLIDE_SCORES, slideScoresByEntity);
85
	}
115
	}
86
 
116
 
-
 
117
	/**
-
 
118
	 * 
-
 
119
	 * @return
-
 
120
	 * @throws Exception
-
 
121
	 */
87
	@SuppressWarnings("unchecked")
122
	@SuppressWarnings("unchecked")
88
	public static Map<Long, Map<Long, Integer>> getSlideScores() throws Exception {
123
	public static Map<Long, Map<Long, Integer>> getSlideScores() throws Exception {
89
		return (Map<Long, Map<Long, Integer>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
124
		return (Map<Long, Map<Long, Integer>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
90
	}
125
	}
91
 
126
 
-
 
127
	/**
-
 
128
	 * 
-
 
129
	 * @param entityID
-
 
130
	 * @return
-
 
131
	 * @throws Exception
-
 
132
	 */
92
	@SuppressWarnings("unchecked")
133
	@SuppressWarnings("unchecked")
93
	public static Map<Long, Integer> getSlideComparisonScores(long entityID) throws Exception{
134
	public static Map<Long, Integer> getSlideComparisonScores(long entityID) throws Exception{
94
		Map<Long, Map<Long, Integer>> slideScores = (Map<Long, Map<Long, Integer>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
135
		Map<Long, Map<Long, Integer>> slideScores = (Map<Long, Map<Long, Integer>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
95
		return slideScores.get(entityID);
136
		return slideScores.get(entityID);
96
	}
137
	}
97
	
138
	
98
	
139
	
-
 
140
	/**
-
 
141
	 * 
-
 
142
	 * @param finalScoreByEntityID
-
 
143
	 * @throws Exception
-
 
144
	 */
99
	public static void storeDefaultEntityScores(Map<Long, Integer> finalScoreByEntityID) throws Exception {
145
	public static void storeDefaultEntityScores(Map<Long, Integer> finalScoreByEntityID) throws Exception {
100
		StorageManager.getStorageManager().storeDataObject(CreationUtils.DEFAULT_ENTITY_SCORES, finalScoreByEntityID);
146
		StorageManager.getStorageManager().storeDataObject(CreationUtils.DEFAULT_ENTITY_SCORES, finalScoreByEntityID);
101
	}
147
	}
102
	
148
	
-
 
149
	/**
-
 
150
	 * 
-
 
151
	 * @return
-
 
152
	 * @throws Exception
-
 
153
	 */
103
	@SuppressWarnings("unchecked")
154
	@SuppressWarnings("unchecked")
104
	public static Map<Long, Integer> getDefaultEntityScores() throws Exception {
155
	public static Map<Long, Integer> getDefaultEntityScores() throws Exception {
105
		return (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
156
		return (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
106
	}
157
	}
107
	
158
	
-
 
159
	/**
-
 
160
	 * 
-
 
161
	 * @param entityID
-
 
162
	 * @return
-
 
163
	 * @throws Exception
-
 
164
	 */
108
	@SuppressWarnings("unchecked")
165
	@SuppressWarnings("unchecked")
109
	public static Integer getEntityComparisonScores(long entityID) throws Exception {
166
	public static Integer getEntityComparisonScores(long entityID) throws Exception {
110
		Map<Long, Integer> scoresMap =  (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
167
		Map<Long, Integer> scoresMap =  (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
111
		Integer objScore = scoresMap.get(entityID);
168
		Integer objScore = scoresMap.get(entityID);
112
		if(objScore==null){
169
		if(objScore==null){
Line 126... Line 183...
126
	 */
183
	 */
127
	public static Entity getEntity(long entityID) throws Exception{
184
	public static Entity getEntity(long entityID) throws Exception{
128
		return StorageManager.getStorageManager().getEntity(entityID);
185
		return StorageManager.getStorageManager().getEntity(entityID);
129
	}
186
	}
130
	
187
	
-
 
188
	/**
-
 
189
	 * 
-
 
190
	 * @param entity
-
 
191
	 * @throws Exception
-
 
192
	 */
131
	public static void updateEntity(Entity entity) throws Exception {
193
	public static void updateEntity(Entity entity) throws Exception {
132
		entity.reorderSlides(entity.getSlideSequence());
194
		entity.reorderSlides(entity.getSlideSequence());
133
		StorageManager.getStorageManager().updateEntity(entity);
195
		StorageManager.getStorageManager().updateEntity(entity);
134
		CreationUtils.learn(entity);
196
		CreationUtils.learn(entity);
135
	}
197
	}
136
 
198
 
-
 
199
	/**
-
 
200
	 * 
-
 
201
	 * @param entity
-
 
202
	 * @param entityMetadata
-
 
203
	 * @throws Exception
-
 
204
	 */
137
	public static void createEntity(Entity entity, EntityState entityMetadata) throws Exception {
205
	public static void createEntity(Entity entity, EntityState entityMetadata) throws Exception {
138
		StorageManager.getStorageManager().createEntity(entity, entityMetadata);
206
		StorageManager.getStorageManager().createEntity(entity, entityMetadata);
139
	}
207
	}
140
 
208
 
-
 
209
	/**
-
 
210
	 * 
-
 
211
	 * @param entityId
-
 
212
	 * @throws Exception
-
 
213
	 */
141
	public static void deleteEntity(long entityId) throws Exception  {
214
	public static void deleteEntity(long entityId) throws Exception  {
142
		StorageManager.getStorageManager().deleteEntity(entityId);
215
		StorageManager.getStorageManager().deleteEntity(entityId);
143
	}
216
	}
144
 
217
 
145
 
218
 
-
 
219
	/**
-
 
220
	 * 
-
 
221
	 * @return
-
 
222
	 * @throws Exception
-
 
223
	 */
146
	public static Map<Long, EntityState> getEntitiesState() throws Exception {
224
	public static Map<Long, EntityState> getEntitiesState() throws Exception {
147
		return StorageManager.getStorageManager().getEntitiesMetadata();
225
		return StorageManager.getStorageManager().getEntitiesMetadata();
148
	}
226
	}
149
	
227
	
-
 
228
	/**
-
 
229
	 * 
-
 
230
	 * @param entityId
-
 
231
	 * @return
-
 
232
	 * @throws Exception
-
 
233
	 */
150
	public static EntityState getEntityState(long entityId) throws Exception {
234
	public static EntityState getEntityState(long entityId) throws Exception {
151
		return StorageManager.getStorageManager().getEntityMetadata(entityId);
235
		return StorageManager.getStorageManager().getEntityMetadata(entityId);
152
	}
236
	}
153
 
237
 
-
 
238
	/**
-
 
239
	 * 
-
 
240
	 * @param entityMetadata
-
 
241
	 * @throws Exception
-
 
242
	 */
154
	public static void updateEntityState(EntityState entityMetadata) throws Exception {
243
	public static void updateEntityState(EntityState entityMetadata) throws Exception {
155
		StorageManager.getStorageManager().updateEntityMetadata(entityMetadata);
244
		StorageManager.getStorageManager().updateEntityMetadata(entityMetadata);
156
	}
245
	}
157
 
246
 
-
 
247
	/**
-
 
248
	 * 
-
 
249
	 * @param entity
-
 
250
	 * @throws Exception
-
 
251
	 */
158
	private static void learn(Entity entity) throws Exception{
252
	private static void learn(Entity entity) throws Exception{
159
		CN cn = new CN();
253
		CN cn = new CN();
160
		cn.learn(entity);	
254
		cn.learn(entity);	
161
	}
255
	}
162
 
256
 
-
 
257
	/**
-
 
258
	 * 
-
 
259
	 * @return
-
 
260
	 * @throws Exception
-
 
261
	 */
163
	public static Map<Long, Entity> getEntities() throws Exception {
262
	public static Map<Long, Entity> getEntities() throws Exception {
164
		return StorageManager.getStorageManager().getEntities();
263
		return StorageManager.getStorageManager().getEntities();
165
	}
264
	}
166
 
265
 
-
 
266
	/**
-
 
267
	 * 
-
 
268
	 * @param categoryId
-
 
269
	 * @return
-
 
270
	 * @throws Exception
-
 
271
	 */
167
	public static Collection<Entity> getEntities(long categoryId) throws Exception {
272
	public static Collection<Entity> getEntities(long categoryId) throws Exception {
168
		return StorageManager.getStorageManager().getEntitisByCategory(categoryId);
273
		return StorageManager.getStorageManager().getEntitisByCategory(categoryId);
169
	}
274
	}
170
 
275
 
171
	/**
276
	/**