Subversion Repositories SmartDukaan

Rev

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