Subversion Repositories SmartDukaan

Rev

Rev 26869 | Rev 27122 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21723 ashik.ali 1
package com.spice.profitmandi.dao.repository.dtr;
21545 ashik.ali 2
 
22097 kshitij.so 3
import java.lang.reflect.Type;
4
import java.util.ArrayList;
23793 tejbeer 5
import java.util.Arrays;
24995 amit.gupta 6
import java.util.HashMap;
27120 amit.gupta 7
import java.util.Iterator;
22097 kshitij.so 8
import java.util.List;
22125 ashik.ali 9
import java.util.Map;
24995 amit.gupta 10
import java.util.stream.Collectors;
21545 ashik.ali 11
 
24031 amit.gupta 12
import org.apache.logging.log4j.LogManager;
23568 govind 13
import org.apache.logging.log4j.Logger;
23793 tejbeer 14
import org.bson.Document;
24031 amit.gupta 15
import org.json.JSONObject;
21545 ashik.ali 16
 
22097 kshitij.so 17
import com.google.gson.Gson;
18
import com.google.gson.reflect.TypeToken;
21545 ashik.ali 19
import com.mongodb.BasicDBObject;
20
import com.mongodb.DB;
21
import com.mongodb.DBCollection;
22097 kshitij.so 22
import com.mongodb.DBCursor;
21545 ashik.ali 23
import com.mongodb.DBObject;
24
import com.mongodb.MongoClient;
23793 tejbeer 25
import com.mongodb.client.AggregateIterable;
26
import com.mongodb.client.MongoCollection;
27
import com.mongodb.client.MongoDatabase;
21545 ashik.ali 28
import com.mongodb.util.JSON;
24011 tejbeer 29
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
25380 amit.gupta 30
import com.spice.profitmandi.dao.model.ContentPojo;
22097 kshitij.so 31
import com.spice.profitmandi.dao.model.FofoForm;
22496 amit.gupta 32
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
21545 ashik.ali 33
 
34
public class Mongo {
22384 amit.gupta 35
 
23568 govind 36
	private static final Logger LOGGER = LogManager.getLogger(Mongo.class);
21545 ashik.ali 37
 
22165 amit.gupta 38
	private static final String CONTENT = "CONTENT";
21545 ashik.ali 39
	private static final String SITE_CONTENT = "siteContent";
40
	private static final String CATALOG_DB = "Catalog";
41
	private static final String MASTER_DATA = "MasterData";
22097 kshitij.so 42
	private static final String FOFO_DB = "Fofo";
22335 amit.gupta 43
	private static final String FOFO_BRANDS = "brands";
22446 amit.gupta 44
	private static final String PROFITMANDI_BANNERS = "banners";
22496 amit.gupta 45
	private static final String RETAILER_FOFO_INTEREST = "RetailerFofoInterest";
22097 kshitij.so 46
	private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
24011 tejbeer 47
	private static final String NOTIFICATION_CAMPAIGNS = "notificationcampaigns";
48
	private static final String USER_DB = "User";
21545 ashik.ali 49
	private static final int MONGO_PORT = 27017;
25380 amit.gupta 50
 
51
	private static final Gson gson = new Gson();
27120 amit.gupta 52
	private static final List<String> BLOCKED_BRANDS = Arrays.asList("Realme");
25560 amit.gupta 53
	public static final Map<Integer, List<String>> PARTNER_BLoCKED_BRANDS = new HashMap<>();
27120 amit.gupta 54
	public static final Map<Integer, List<String>> PARTNER_ALLOWED_BRANDS = new HashMap<>();
55
 
22165 amit.gupta 56
 
24995 amit.gupta 57
	static {
26343 tejbeer 58
		PARTNER_BLoCKED_BRANDS.put(175135597, Arrays.asList("Vivo"));
59
		PARTNER_BLoCKED_BRANDS.put(175135183, Arrays.asList("Vivo"));
60
		PARTNER_BLoCKED_BRANDS.put(175137445, Arrays.asList("Vivo"));
61
		PARTNER_BLoCKED_BRANDS.put(175137557, Arrays.asList("Vivo"));
62
		PARTNER_BLoCKED_BRANDS.put(175138281, Arrays.asList("Vivo"));
63
		PARTNER_BLoCKED_BRANDS.put(175138441, Arrays.asList("Vivo"));
64
		PARTNER_BLoCKED_BRANDS.put(175138447, Arrays.asList("Vivo"));
65
		PARTNER_BLoCKED_BRANDS.put(175138570, Arrays.asList("Vivo"));
66
		// TITU
67
		PARTNER_BLoCKED_BRANDS.put(175138610, Arrays.asList("Vivo"));
68
		PARTNER_BLoCKED_BRANDS.put(175138611, Arrays.asList("Vivo"));
69
		PARTNER_BLoCKED_BRANDS.put(175138639, Arrays.asList("Vivo"));
70
		PARTNER_BLoCKED_BRANDS.put(175138716, Arrays.asList("Vivo"));
26811 amit.gupta 71
		//Pardeep Telecom
26869 amit.gupta 72
		//PARTNER_BLoCKED_BRANDS.put(175138843, Arrays.asList("Vivo"));
26343 tejbeer 73
		// PARTNER_BLoCKED_BRANDS.put(175138733,Arrays.asList("Vivo"));
26600 amit.gupta 74
		//Venus Agencies
75
		//PARTNER_BLoCKED_BRANDS.put(175138801, Arrays.asList("Vivo"));
26459 tejbeer 76
		//PARTNER_BLoCKED_BRANDS.put(175138717, Arrays.asList("Vivo"));
26343 tejbeer 77
		PARTNER_BLoCKED_BRANDS.put(175138803, Arrays.asList("Vivo"));
78
		PARTNER_BLoCKED_BRANDS.put(175138821, Arrays.asList("Vivo"));
79
		// PARTNER_BLoCKED_BRANDS.put(175138820,Arrays.asList("Vivo"));
80
		PARTNER_BLoCKED_BRANDS.put(175138718, Arrays.asList("Vivo"));
81
		PARTNER_BLoCKED_BRANDS.put(175138637, Arrays.asList("Vivo"));
82
		// PARTNER_BLoCKED_BRANDS.put(175138814,Arrays.asList("Vivo"));
26421 tejbeer 83
		//PARTNER_BLoCKED_BRANDS.put(175138833, Arrays.asList("Vivo"));
26397 amit.gupta 84
		//Durga Enterprises
26459 tejbeer 85
		//PARTNER_BLoCKED_BRANDS.put(175138832, Arrays.asList("Vivo"));
27120 amit.gupta 86
		PARTNER_ALLOWED_BRANDS.put(172157716, Arrays.asList("Realme"));
87
		PARTNER_ALLOWED_BRANDS.put(175135227, Arrays.asList("Realme"));
88
		PARTNER_ALLOWED_BRANDS.put(175135707, Arrays.asList("Realme"));
89
		PARTNER_ALLOWED_BRANDS.put(175135923, Arrays.asList("Realme"));
90
		PARTNER_ALLOWED_BRANDS.put(175138372, Arrays.asList("Realme"));
91
		PARTNER_ALLOWED_BRANDS.put(175138520, Arrays.asList("Realme"));
92
		PARTNER_ALLOWED_BRANDS.put(175138522, Arrays.asList("Realme"));
93
		PARTNER_ALLOWED_BRANDS.put(175138541, Arrays.asList("Realme"));
94
		PARTNER_ALLOWED_BRANDS.put(175138674, Arrays.asList("Realme"));
95
		PARTNER_ALLOWED_BRANDS.put(175138716, Arrays.asList("Realme"));
96
		PARTNER_ALLOWED_BRANDS.put(175138801, Arrays.asList("Realme"));
97
		PARTNER_ALLOWED_BRANDS.put(175138812, Arrays.asList("Realme"));
98
		PARTNER_ALLOWED_BRANDS.put(175138813, Arrays.asList("Realme"));
99
		PARTNER_ALLOWED_BRANDS.put(175138814, Arrays.asList("Realme"));
100
		PARTNER_ALLOWED_BRANDS.put(175138816, Arrays.asList("Realme"));
101
		PARTNER_ALLOWED_BRANDS.put(175138820, Arrays.asList("Realme"));
102
		PARTNER_ALLOWED_BRANDS.put(175138836, Arrays.asList("Realme"));
103
		PARTNER_ALLOWED_BRANDS.put(175138838, Arrays.asList("Realme"));
104
		PARTNER_ALLOWED_BRANDS.put(175138840, Arrays.asList("Realme"));
105
		PARTNER_ALLOWED_BRANDS.put(175138842, Arrays.asList("Realme"));
106
		PARTNER_ALLOWED_BRANDS.put(175138843, Arrays.asList("Realme"));
107
		PARTNER_ALLOWED_BRANDS.put(175138847, Arrays.asList("Realme"));
108
		PARTNER_ALLOWED_BRANDS.put(175138858, Arrays.asList("Realme"));
109
		PARTNER_ALLOWED_BRANDS.put(175138859, Arrays.asList("Realme"));
110
		PARTNER_ALLOWED_BRANDS.put(175138860, Arrays.asList("Realme"));
111
		PARTNER_ALLOWED_BRANDS.put(175138862, Arrays.asList("Realme"));
112
		PARTNER_ALLOWED_BRANDS.put(175138863, Arrays.asList("Realme"));
113
		PARTNER_ALLOWED_BRANDS.put(175138865, Arrays.asList("Realme"));
114
		PARTNER_ALLOWED_BRANDS.put(175138868, Arrays.asList("Realme"));
26343 tejbeer 115
 
24995 amit.gupta 116
	}
117
 
22162 amit.gupta 118
	private MongoClient mongoClient;
119
	private MongoClient contentMongoClient;
120
 
22171 amit.gupta 121
	public Mongo(String mongoHost, String contentMongoHost) {
22165 amit.gupta 122
		try {
22170 amit.gupta 123
			LOGGER.info("mongoHost => {}, contentMongoHost {} ", mongoHost, contentMongoHost);
22165 amit.gupta 124
			mongoClient = new MongoClient(mongoHost, MONGO_PORT);
22169 amit.gupta 125
			contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
22165 amit.gupta 126
		} catch (Exception e) {
127
			e.printStackTrace();
128
		}
21545 ashik.ali 129
	}
24031 amit.gupta 130
 
25380 amit.gupta 131
	public ContentPojo getEntityById(long id) throws Exception {
22162 amit.gupta 132
		DB db = contentMongoClient.getDB(CONTENT);
21545 ashik.ali 133
		DBCollection collection = db.getCollection(SITE_CONTENT);
134
		BasicDBObject obj = new BasicDBObject();
135
		obj.append("_id", id);
136
		DBObject result = collection.findOne(obj);
22165 amit.gupta 137
		if (result == null) {
21545 ashik.ali 138
			throw new Exception();
139
		}
26480 amit.gupta 140
		ContentPojo cp = gson.fromJson(new BasicDBObject(result.toMap()).toJson(), ContentPojo.class);
26530 amit.gupta 141
		if(cp.getDefaultImageUrl()!=null) {
142
			cp.setDefaultImageUrl(cp.getDefaultImageUrl().replaceAll("saholic", "smartdukaan"));
143
		}
26480 amit.gupta 144
		return cp;
21545 ashik.ali 145
	}
25380 amit.gupta 146
 
24995 amit.gupta 147
	public List<DBObject> getMongoBrands(int fofoId, String email, int categoryId) {
148
		List<DBObject> brandsDisplay = this.getBrandsToDisplay(categoryId);
27120 amit.gupta 149
		Iterator<DBObject> brandsDisplayIterator = brandsDisplay.iterator();
150
		List<String> partnerAllowedBrands = PARTNER_ALLOWED_BRANDS.get(fofoId);
151
		while(brandsDisplayIterator.hasNext()) {
152
			String brand = brandsDisplayIterator.next().get("name").toString();
153
			if(BLOCKED_BRANDS.contains(brand)) {
154
				if(partnerAllowedBrands == null || !partnerAllowedBrands.contains(brand)) {
155
					brandsDisplayIterator.remove();
156
				}
157
			}
158
		}
25560 amit.gupta 159
		if (PARTNER_BLoCKED_BRANDS.containsKey(fofoId)) {
160
			List<String> blockedBrands = PARTNER_BLoCKED_BRANDS.get(fofoId);
24995 amit.gupta 161
			brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.get("name")))
162
					.collect(Collectors.toList());
163
		}
164
		return brandsDisplay;
25380 amit.gupta 165
 
24995 amit.gupta 166
	}
22165 amit.gupta 167
 
25380 amit.gupta 168
	public ContentPojo getEntityByName(String name) throws Exception {
22385 amit.gupta 169
		LOGGER.info("Name --- {}", name);
22384 amit.gupta 170
		DB db = contentMongoClient.getDB(CONTENT);
171
		DBCollection collection = db.getCollection(SITE_CONTENT);
172
		BasicDBObject obj = new BasicDBObject();
173
		obj.append("title", name);
25380 amit.gupta 174
		DBObject result = collection.findOne();
22384 amit.gupta 175
		if (result == null) {
176
			throw new Exception();
177
		}
25380 amit.gupta 178
		return gson.fromJson(new BasicDBObject(result.toMap()).toJson(), ContentPojo.class);
22384 amit.gupta 179
	}
180
 
25380 amit.gupta 181
	public void persistEntity(ContentPojo contentPojo) {
182
		DB db = contentMongoClient.getDB(CONTENT);
183
		DBCollection collection = db.getCollection(SITE_CONTENT);
184
		insertOrUpdateById(collection, contentPojo.getId(), contentPojo);
185
 
186
	}
187
 
188
	private static <T> void insertOrUpdateById(DBCollection collection, long id, T obj) {
189
		DBObject dbo = BasicDBObject.parse(gson.toJson(obj));
190
		dbo.put("_id", id);
191
		collection.update(new BasicDBObject("_id", id), dbo, true, false);
192
	}
193
 
22165 amit.gupta 194
	public JSONObject getItemsByBundleId(long bundleId) throws Exception {
22162 amit.gupta 195
		DB db = mongoClient.getDB(CATALOG_DB);
21545 ashik.ali 196
		DBCollection collection = db.getCollection(MASTER_DATA);
197
		BasicDBObject obj = new BasicDBObject();
198
		BasicDBObject in_query = new BasicDBObject();
199
		obj.append("skuBundleId", bundleId);
22165 amit.gupta 200
		in_query.append("$in", new int[] { 1, 2, 3, 4, 5, 6, 7 });
21545 ashik.ali 201
		obj.append("source_id", in_query);
202
		DBObject result = collection.findOne(obj);
22165 amit.gupta 203
		if (result == null) {
21545 ashik.ali 204
			throw new Exception();
205
		}
206
		return new JSONObject(JSON.serialize(result));
207
	}
22165 amit.gupta 208
 
209
	public JSONObject getItemByID(long id) throws Exception {
22162 amit.gupta 210
		DB db = mongoClient.getDB(CATALOG_DB);
21545 ashik.ali 211
		DBCollection collection = db.getCollection(MASTER_DATA);
212
		BasicDBObject obj = new BasicDBObject();
213
		obj.append("_id", id);
214
		DBObject result = collection.findOne(obj);
22165 amit.gupta 215
		if (result == null) {
21545 ashik.ali 216
			throw new Exception();
217
		}
218
		return new JSONObject(JSON.serialize(result));
219
	}
22165 amit.gupta 220
 
221
	public void persistFofoRegInfo(FofoForm ff) {
222
		DB db = mongoClient.getDB(FOFO_DB);
22097 kshitij.so 223
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
22165 amit.gupta 224
		if (ff.get_id() == 0) {
22097 kshitij.so 225
			BasicDBObject orderBy = new BasicDBObject();
226
			orderBy.put("_id", -1);
227
			DBCursor cursor = collection.find().sort(orderBy).limit(1);
228
			long id = 1l;
229
			while (cursor.hasNext()) {
230
				FofoForm existingFofo = gson.fromJson(cursor.next().toString(), FofoForm.class);
231
				id = existingFofo.get_id() + 1;
232
			}
233
			ff.set_id(id);
234
		}
25380 amit.gupta 235
		DBObject dbObject = (DBObject) JSON.parse(gson.toJson(ff));
22097 kshitij.so 236
		collection.save(dbObject);
237
	}
22165 amit.gupta 238
 
22162 amit.gupta 239
	public List<FofoForm> getFofoForms(int offset, int limit) {
22165 amit.gupta 240
		List<FofoForm> ffList = new ArrayList<FofoForm>();
22162 amit.gupta 241
		DB db = mongoClient.getDB(FOFO_DB);
22097 kshitij.so 242
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
243
		BasicDBObject orderBy = new BasicDBObject();
244
		orderBy.put("_id", -1);
245
		DBCursor dbc = collection.find().sort(orderBy).limit(limit).skip(offset);
246
		while (dbc.hasNext()) {
247
			ffList.add(convertJSONToPojo(dbc.next().toString()));
248
		}
249
		return ffList;
250
	}
22165 amit.gupta 251
 
252
	public String getFofoFormJsonStringByFofoId(int fofoId) {
22162 amit.gupta 253
		DB db = mongoClient.getDB(FOFO_DB);
22097 kshitij.so 254
		BasicDBObject filter = new BasicDBObject();
255
		filter.append("_id", fofoId);
256
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
22105 ashik.ali 257
		DBObject fofoDbOject = collection.findOne(filter);
22165 amit.gupta 258
		if (fofoDbOject != null) {
22161 amit.gupta 259
			return fofoDbOject.toString();
260
		} else {
261
			return null;
262
		}
22097 kshitij.so 263
	}
22165 amit.gupta 264
 
265
	public String getFofoFormJsonStringByEmail(String email) {
22162 amit.gupta 266
		DB db = mongoClient.getDB(FOFO_DB);
22155 amit.gupta 267
		BasicDBObject filter = new BasicDBObject();
268
		filter.append("registeredEmail1", email);
269
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
270
		DBObject fofoDbOject = collection.findOne(filter);
22165 amit.gupta 271
		if (fofoDbOject != null) {
22161 amit.gupta 272
			return fofoDbOject.toString();
273
		} else {
274
			return null;
275
		}
22155 amit.gupta 276
	}
22165 amit.gupta 277
 
278
	public String getFofoFormsJsonString() {
22162 amit.gupta 279
		DB db = mongoClient.getDB(FOFO_DB);
22125 ashik.ali 280
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
281
		DBCursor cursor = collection.find();
282
		StringBuilder fofoFormsJsonString = new StringBuilder();
283
		fofoFormsJsonString.append("[");
22165 amit.gupta 284
		while (cursor.hasNext()) {
22125 ashik.ali 285
			fofoFormsJsonString.append(cursor.next().toString());
22165 amit.gupta 286
			if (cursor.hasNext()) {
22125 ashik.ali 287
				fofoFormsJsonString.append(",");
288
			}
289
		}
290
		fofoFormsJsonString.append("]");
291
		return fofoFormsJsonString.toString();
292
	}
22165 amit.gupta 293
 
22162 amit.gupta 294
	public FofoForm getFofoForm(int fofoId) {
22097 kshitij.so 295
		String fofoFormJsonString = getFofoFormJsonStringByFofoId(fofoId);
296
		System.out.println(fofoFormJsonString);
297
		return new Gson().fromJson(fofoFormJsonString, FofoForm.class);
22165 amit.gupta 298
		// return convertJSONToPojo(fofoDbOject.toString());
22097 kshitij.so 299
	}
22165 amit.gupta 300
 
22162 amit.gupta 301
	public FofoForm getFofoForm(String email) {
22155 amit.gupta 302
		String fofoFormJsonString = getFofoFormJsonStringByEmail(email);
303
		System.out.println(fofoFormJsonString);
304
		return new Gson().fromJson(fofoFormJsonString, FofoForm.class);
22165 amit.gupta 305
		// return convertJSONToPojo(fofoDbOject.toString());
22155 amit.gupta 306
	}
21545 ashik.ali 307
 
22165 amit.gupta 308
	private static FofoForm convertJSONToPojo(String json) {
22097 kshitij.so 309
 
22165 amit.gupta 310
		Type type = new TypeToken<FofoForm>() {
311
		}.getType();
22097 kshitij.so 312
 
22165 amit.gupta 313
		return new Gson().fromJson(json, type);
314
 
22097 kshitij.so 315
	}
22165 amit.gupta 316
 
317
	public void updateColumnsById(Map<String, Integer> map, int fofoId) {
22162 amit.gupta 318
		DB db = mongoClient.getDB(FOFO_DB);
22125 ashik.ali 319
		BasicDBObject filter = new BasicDBObject();
320
		filter.append("_id", fofoId);
321
		DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
322
		BasicDBObject updateFields = new BasicDBObject();
22165 amit.gupta 323
		for (Map.Entry<String, Integer> entry : map.entrySet()) {
22125 ashik.ali 324
			updateFields.append(entry.getKey(), entry.getValue());
325
		}
326
		BasicDBObject newDocument = new BasicDBObject();
327
		newDocument.append("$set", updateFields);
328
		collection.update(filter, newDocument);
329
	}
24031 amit.gupta 330
 
331
	public List<DBObject> getBrandsToDisplay(int categoryId) {
22335 amit.gupta 332
		DB db = mongoClient.getDB(FOFO_DB);
333
		BasicDBObject filter = new BasicDBObject();
334
		filter.append("active", true);
24031 amit.gupta 335
		if (categoryId != 0) {
336
			filter.append("categoryId", categoryId);
337
		}
22335 amit.gupta 338
		return db.getCollection(FOFO_BRANDS).find(filter).toArray();
339
	}
26343 tejbeer 340
 
26309 amit.gupta 341
	public List<DBObject> getAllBrandsToDisplay(int categoryId) {
342
		DB db = mongoClient.getDB(FOFO_DB);
343
		BasicDBObject filter = new BasicDBObject();
344
		if (categoryId != 0) {
345
			filter.append("categoryId", categoryId);
346
		}
347
		return db.getCollection(FOFO_BRANDS).find(filter).toArray();
348
	}
24031 amit.gupta 349
 
22447 amit.gupta 350
	public List<DBObject> getBannersByType(String bannerType) {
26661 amit.gupta 351
		DB db = mongoClient.getDB(FOFO_DB);
22446 amit.gupta 352
		BasicDBObject filter = new BasicDBObject();
22449 amit.gupta 353
		filter.append("type", bannerType);
22992 amit.gupta 354
		BasicDBObject orderBy = new BasicDBObject();
23008 amit.gupta 355
		orderBy.put("rank", 1);
22992 amit.gupta 356
		return db.getCollection(PROFITMANDI_BANNERS).find(filter).sort(orderBy).toArray();
22446 amit.gupta 357
	}
23793 tejbeer 358
 
359
	@SuppressWarnings("unchecked")
360
	public List<Document> getSubcategoriesToDisplay() {
361
		MongoDatabase db = mongoClient.getDatabase("Catalog");
362
		System.out.println("Connection to MongoDB database successfully");
363
		MongoCollection<Document> collection = db.getCollection("Deals");
24031 amit.gupta 364
 
365
		Document object = new Document().append("$match", new Document().append("category_id", 6).append("showDeal", 1)
366
				.append("dealRankPoints", new Document("$gt", 0)));
23793 tejbeer 367
		Document ob = new Document("$group",
24031 amit.gupta 368
				new Document().append("_id",
369
						new Document().append("subCategoryId", "$subCategoryId").append("subCategory", "$subCategory"))
370
						.append("count", new Document("$sum", 1)));
23793 tejbeer 371
		List<Document> pipeline = Arrays.asList(object, ob);
372
		AggregateIterable<Document> cursor = collection.aggregate(pipeline);
373
 
374
		List<Document> resultDocuments = new ArrayList<>();
375
		for (Document dbo : cursor) {
376
			System.out.println(dbo.toString());
377
			LOGGER.info("categories" + dbo.toString());
378
			resultDocuments.add(dbo);
379
		}
380
		return resultDocuments;
381
	}
382
 
22496 amit.gupta 383
	public boolean saveRetailerInterestOnFofo(RetailerFofoInterest retailerInterest) {
384
		DB db = mongoClient.getDB(FOFO_DB);
385
		Gson gs = new Gson();
386
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
387
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(retailerInterest));
388
		fofoInterestCollection.save(dbObject);
389
		return true;
390
	}
23793 tejbeer 391
 
22496 amit.gupta 392
	public boolean hasRetailerShownInterest(int userId) {
393
		DB db = mongoClient.getDB(FOFO_DB);
394
		BasicDBObject filter = new BasicDBObject();
23793 tejbeer 395
		filter.append("userId", userId);
22496 amit.gupta 396
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
23793 tejbeer 397
		return fofoInterestCollection.findOne(filter) != null;
22496 amit.gupta 398
	}
24031 amit.gupta 399
 
24011 tejbeer 400
	public void persistNotificationCmpInfo(NotificationCampaigns ff) {
24383 amit.gupta 401
		DB db = mongoClient.getDB(USER_DB);
24011 tejbeer 402
		DBCollection collection = db.getCollection(NOTIFICATION_CAMPAIGNS);
403
		if (ff.get_id() == 0) {
404
			BasicDBObject orderBy = new BasicDBObject();
405
			orderBy.put("_id", -1);
406
			DBCursor cursor = collection.find().sort(orderBy).limit(1);
407
			long id = 1l;
408
			while (cursor.hasNext()) {
409
				Gson gson = new Gson();
24031 amit.gupta 410
				NotificationCampaigns existingFofo = gson.fromJson(cursor.next().toString(),
411
						NotificationCampaigns.class);
24011 tejbeer 412
				id = existingFofo.get_id() + 1;
413
			}
414
			ff.set_id(id);
415
		}
416
		Gson gs = new Gson();
417
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
418
		collection.save(dbObject);
419
	}
22097 kshitij.so 420
 
21545 ashik.ali 421
}