Subversion Repositories SmartDukaan

Rev

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