Subversion Repositories SmartDukaan

Rev

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

Rev 8749 Rev 8750
Line 240... Line 240...
240
     */
240
     */
241
    public void deleteSpecialPage(long specialPageId) {
241
    public void deleteSpecialPage(long specialPageId) {
242
    	removeById(views.specialPages, specialPageId);
242
    	removeById(views.specialPages, specialPageId);
243
    }
243
    }
244
    
244
    
245
    /*public long getSpecialPageId(){
245
    @SuppressWarnings("unchecked")
246
    	views.specialPages.
-
 
247
    }*/
-
 
248
    
-
 
249
    
-
 
250
    
-
 
251
    private static <T> DBObject toDBObject(T t) {
-
 
252
    	return (DBObject)JSON.parse(gs.toJson(t, t.getClass()));
-
 
253
    }
-
 
254
    
-
 
255
    private static String toGSON(Object obj){
-
 
256
    	return gs.toJson(obj);
-
 
257
    }
-
 
258
    
-
 
259
    private static <T> T toObject(DBObject dbo, Type t) {
246
    private static <T> T toObject(DBObject dbo, Type t) {
260
    	dbo.removeField("_id");
247
    	dbo.removeField("_id");
261
    	return gs.fromJson(dbo.toString(), t);
248
    	return gs.fromJson(dbo.toString(), t);
262
    }
249
    }
263
 
250
 
-
 
251
    @SuppressWarnings("unchecked")
264
    private static <T> T getById(DBCollection collection, Long id, Type t) {
252
    private static <T> T getById(DBCollection collection, Long id, Type t) {
265
    	DBObject dbo = collection.findOne(id);
253
    	DBObject dbo = collection.findOne(id);
266
    	if(dbo ==null) return null;
254
    	if(dbo ==null) return null;
267
    	if (dbo.get(id.toString()) != null){
255
    	if (dbo.get(id.toString()) != null){
268
    		return gs.fromJson(dbo.get(id.toString()).toString(), t);
256
    		return gs.fromJson(dbo.get(id.toString()).toString(), t);
269
    	}
257
    	}
270
    	dbo.removeField("_id");
258
    	dbo.removeField("_id");
271
    	return gs.fromJson(dbo.toString(), t);
259
    	return gs.fromJson(dbo.toString(), t);
272
    }
260
    }
273
 
261
 
-
 
262
    @SuppressWarnings("unchecked")
274
    private static <T> void insertOrUpdateById  (DBCollection collection, long id, T t) {
263
    private static <T> void insertOrUpdateById  (DBCollection collection, long id, T t) {
275
    	DBObject dbo = (DBObject)JSON.parse(gs.toJson(t));
264
    	DBObject dbo = (DBObject)JSON.parse(gs.toJson(t));
276
    	dbo.put("_id", id);
265
    	dbo.put("_id", id);
277
    	collection.update(new BasicDBObject("_id", id ), dbo, true, false);
266
    	collection.update(new BasicDBObject("_id", id ), dbo, true, false);
278
    	
267
    	
Line 287... Line 276...
287
    	Map <String, Object>  obj = new HashMap<String, Object>();
276
    	Map <String, Object>  obj = new HashMap<String, Object>();
288
    	obj.put("1", dataObject);
277
    	obj.put("1", dataObject);
289
    	insertOrUpdateById(collection, 1L, obj);
278
    	insertOrUpdateById(collection, 1L, obj);
290
    }
279
    }
291
    
280
    
-
 
281
    @SuppressWarnings("unchecked")
292
    public <T> T getDataObject(String dataObjectName, Type t) throws Exception{
282
    public <T> T getDataObject(String dataObjectName, Type t) throws Exception{
293
    	DBCollection collection = db.getCollection(dataObjectName);
283
    	DBCollection collection = db.getCollection(dataObjectName);
294
    	return getById(collection, 1L, t);
284
    	return getById(collection, 1L, t);
295
    }
285
    }
296
 
286
 
Line 328... Line 318...
328
			insertOrUpdateById(views.learnedBullets, learnedBullet.getKey(), new BasicDBObject(learnedBullet.getKey().toString(), learnedBullet.getValue()));
318
			insertOrUpdateById(views.learnedBullets, learnedBullet.getKey(), new BasicDBObject(learnedBullet.getKey().toString(), learnedBullet.getValue()));
329
		}
319
		}
330
	}
320
	}
331
	
321
	
332
 
322
 
333
	@SuppressWarnings(UNCHECKED)
323
	@SuppressWarnings("unchecked")
334
	public Map<Long, List<ExpandedBullet>> getLearnedBullets() {
324
	public Map<Long, List<ExpandedBullet>> getLearnedBullets() {
335
		Type t = new TypeToken<List<ExpandedBullet>>() {}.getType();
325
		Type t = new TypeToken<List<ExpandedBullet>>() {}.getType();
336
		Map<Long, List<ExpandedBullet>> learnedBullets  = new HashMap<Long, List<ExpandedBullet>>();
326
		Map<Long, List<ExpandedBullet>> learnedBullets  = new HashMap<Long, List<ExpandedBullet>>();
337
		Iterator<DBObject> iter = views.learnedBullets.find();
327
		Iterator<DBObject> iter = views.learnedBullets.find();
338
		while (iter.hasNext()) {
328
		while (iter.hasNext()) {
Line 404... Line 394...
404
		List<ExpertReview> er = getById(views.expertReviews, entityId, t);
394
		List<ExpertReview> er = getById(views.expertReviews, entityId, t);
405
		er.remove(index);
395
		er.remove(index);
406
		storeExpertReview(entityId, er);
396
		storeExpertReview(entityId, er);
407
	}
397
	}
408
 
398
 
409
	@SuppressWarnings(UNCHECKED)
399
	@SuppressWarnings("unchecked")
410
	public Map<Long, List<ExpertReview>> getExpertReviews() {
400
	public Map<Long, List<ExpertReview>> getExpertReviews() {
411
		Type t = new TypeToken<List<ExpertReview>>() {}.getType();
401
		Type t = new TypeToken<List<ExpertReview>>() {}.getType();
412
		Map<Long, List<ExpertReview>> er  = new HashMap<Long, List<ExpertReview>>();
402
		Map<Long, List<ExpertReview>> er  = new HashMap<Long, List<ExpertReview>>();
413
		Iterator<DBObject> iter = views.expertReviews.find();
403
		Iterator<DBObject> iter = views.expertReviews.find();
414
		while (iter.hasNext()) {
404
		while (iter.hasNext()) {
Line 422... Line 412...
422
	public void deleteExpertReview(long entityId) {
412
	public void deleteExpertReview(long entityId) {
423
		removeById(views.expertReviews, entityId);
413
		removeById(views.expertReviews, entityId);
424
	}
414
	}
425
 
415
 
426
 
416
 
427
	@SuppressWarnings(UNCHECKED)
417
	@SuppressWarnings("unchecked")
428
	public Map<Long, List<Long>> getHelpdocEntityIds() {
418
	public Map<Long, List<Long>> getHelpdocEntityIds() {
429
		Type t = new TypeToken<List<Long>>() {}.getType();
419
		Type t = new TypeToken<List<Long>>() {}.getType();
430
		Map<Long, List<Long>> er  = new HashMap<Long, List<Long>>();
420
		Map<Long, List<Long>> er  = new HashMap<Long, List<Long>>();
431
		Iterator<DBObject> iter = views.helpdocEntityIds.find().iterator();
421
		Iterator<DBObject> iter = views.helpdocEntityIds.find().iterator();
432
		while (iter.hasNext()) {
422
		while (iter.hasNext()) {