Subversion Repositories SmartDukaan

Rev

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