Subversion Repositories SmartDukaan

Rev

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

Rev 24011 Rev 24031
Line 4... Line 4...
4
import java.util.ArrayList;
4
import java.util.ArrayList;
5
import java.util.Arrays;
5
import java.util.Arrays;
6
import java.util.List;
6
import java.util.List;
7
import java.util.Map;
7
import java.util.Map;
8
 
8
 
9
import org.json.JSONObject;
9
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.Logger;
11
import org.bson.Document;
11
import org.bson.Document;
12
import org.apache.logging.log4j.LogManager;
12
import org.json.JSONObject;
13
 
13
 
14
import com.google.gson.Gson;
14
import com.google.gson.Gson;
15
import com.google.gson.reflect.TypeToken;
15
import com.google.gson.reflect.TypeToken;
16
import com.mongodb.BasicDBObject;
16
import com.mongodb.BasicDBObject;
17
import com.mongodb.DB;
17
import com.mongodb.DB;
Line 24... Line 24...
24
import com.mongodb.client.MongoDatabase;
24
import com.mongodb.client.MongoDatabase;
25
import com.mongodb.util.JSON;
25
import com.mongodb.util.JSON;
26
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
26
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
27
import com.spice.profitmandi.dao.model.FofoForm;
27
import com.spice.profitmandi.dao.model.FofoForm;
28
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
28
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
29
import com.spice.profitmandi.dao.repository.transaction.OrderRepositoryImpl;
-
 
30
 
29
 
31
public class Mongo {
30
public class Mongo {
32
 
31
 
33
	private static final Logger LOGGER = LogManager.getLogger(Mongo.class);
32
	private static final Logger LOGGER = LogManager.getLogger(Mongo.class);
34
 
33
 
Line 56... Line 55...
56
			contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
55
			contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
57
		} catch (Exception e) {
56
		} catch (Exception e) {
58
			e.printStackTrace();
57
			e.printStackTrace();
59
		}
58
		}
60
	}
59
	}
61
	
60
 
62
	public Mongo(String mongoHost, String contentMongoHost, String dtrDataMongoHost) {
61
	public Mongo(String mongoHost, String contentMongoHost, String dtrDataMongoHost) {
63
		try {
62
		try {
64
			LOGGER.info("mongoHost => {}, contentMongoHost {},dtrDataMongoHost {} ", mongoHost, contentMongoHost,dtrDataMongoHost);
63
			LOGGER.info("mongoHost => {}, contentMongoHost {},dtrDataMongoHost {} ", mongoHost, contentMongoHost,
-
 
64
					dtrDataMongoHost);
65
			mongoClient = new MongoClient(mongoHost, MONGO_PORT);
65
			mongoClient = new MongoClient(mongoHost, MONGO_PORT);
66
			contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
66
			contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
67
			dtrDataMongoClient=new MongoClient(dtrDataMongoHost, MONGO_PORT);
67
			dtrDataMongoClient = new MongoClient(dtrDataMongoHost, MONGO_PORT);
68
		} catch (Exception e) {
68
		} catch (Exception e) {
69
			e.printStackTrace();
69
			e.printStackTrace();
70
		}
70
		}
71
	}
71
	}
72
 
72
 
Line 231... Line 231...
231
		}
231
		}
232
		BasicDBObject newDocument = new BasicDBObject();
232
		BasicDBObject newDocument = new BasicDBObject();
233
		newDocument.append("$set", updateFields);
233
		newDocument.append("$set", updateFields);
234
		collection.update(filter, newDocument);
234
		collection.update(filter, newDocument);
235
	}
235
	}
236
	
236
 
237
	public List<DBObject> getBrandsToDisplay() {
237
	public List<DBObject> getBrandsToDisplay(int categoryId) {
238
		DB db = mongoClient.getDB(FOFO_DB);
238
		DB db = mongoClient.getDB(FOFO_DB);
239
		BasicDBObject filter = new BasicDBObject();
239
		BasicDBObject filter = new BasicDBObject();
240
		filter.append("active", true);
240
		filter.append("active", true);
-
 
241
		if (categoryId != 0) {
-
 
242
			filter.append("categoryId", categoryId);
-
 
243
		}
241
		return db.getCollection(FOFO_BRANDS).find(filter).toArray();
244
		return db.getCollection(FOFO_BRANDS).find(filter).toArray();
242
	}
245
	}
243
	
246
 
244
	public List<DBObject> getBannersByType(String bannerType) {
247
	public List<DBObject> getBannersByType(String bannerType) {
245
		DB db = mongoClient.getDB(CATALOG_DB);
248
		DB db = mongoClient.getDB(CATALOG_DB);
246
		BasicDBObject filter = new BasicDBObject();
249
		BasicDBObject filter = new BasicDBObject();
247
		filter.append("type", bannerType);
250
		filter.append("type", bannerType);
248
		BasicDBObject orderBy = new BasicDBObject();
251
		BasicDBObject orderBy = new BasicDBObject();
Line 253... Line 256...
253
	@SuppressWarnings("unchecked")
256
	@SuppressWarnings("unchecked")
254
	public List<Document> getSubcategoriesToDisplay() {
257
	public List<Document> getSubcategoriesToDisplay() {
255
		MongoDatabase db = mongoClient.getDatabase("Catalog");
258
		MongoDatabase db = mongoClient.getDatabase("Catalog");
256
		System.out.println("Connection to MongoDB database successfully");
259
		System.out.println("Connection to MongoDB database successfully");
257
		MongoCollection<Document> collection = db.getCollection("Deals");
260
		MongoCollection<Document> collection = db.getCollection("Deals");
258
		
261
 
259
		Document object = new Document().append("$match", new Document()
262
		Document object = new Document().append("$match", new Document().append("category_id", 6).append("showDeal", 1)
260
											.append("category_id", 6)
-
 
261
											.append("showDeal", 1)
-
 
262
											.append("dealRankPoints", new Document("$gt", 0))
263
				.append("dealRankPoints", new Document("$gt", 0)));
263
							);
-
 
264
		Document ob = new Document("$group",
264
		Document ob = new Document("$group",
265
							new Document()
-
 
266
								.append("_id",
265
				new Document().append("_id",
267
									new Document()
-
 
268
										.append("subCategoryId", "$subCategoryId")
266
						new Document().append("subCategoryId", "$subCategoryId").append("subCategory", "$subCategory"))
269
										.append("subCategory", "$subCategory"))
-
 
270
								.append("count", new Document("$sum", 1)));
267
						.append("count", new Document("$sum", 1)));
271
		List<Document> pipeline = Arrays.asList(object, ob);
268
		List<Document> pipeline = Arrays.asList(object, ob);
272
		AggregateIterable<Document> cursor = collection.aggregate(pipeline);
269
		AggregateIterable<Document> cursor = collection.aggregate(pipeline);
273
 
270
 
274
		List<Document> resultDocuments = new ArrayList<>();
271
		List<Document> resultDocuments = new ArrayList<>();
275
		for (Document dbo : cursor) {
272
		for (Document dbo : cursor) {
Line 294... Line 291...
294
		BasicDBObject filter = new BasicDBObject();
291
		BasicDBObject filter = new BasicDBObject();
295
		filter.append("userId", userId);
292
		filter.append("userId", userId);
296
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
293
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
297
		return fofoInterestCollection.findOne(filter) != null;
294
		return fofoInterestCollection.findOne(filter) != null;
298
	}
295
	}
299
	
296
 
300
	public void persistNotificationCmpInfo(NotificationCampaigns ff) {
297
	public void persistNotificationCmpInfo(NotificationCampaigns ff) {
301
		DB db = dtrDataMongoClient.getDB(USER_DB);
298
		DB db = dtrDataMongoClient.getDB(USER_DB);
302
		DBCollection collection = db.getCollection(NOTIFICATION_CAMPAIGNS);
299
		DBCollection collection = db.getCollection(NOTIFICATION_CAMPAIGNS);
303
		if (ff.get_id() == 0) {
300
		if (ff.get_id() == 0) {
304
			BasicDBObject orderBy = new BasicDBObject();
301
			BasicDBObject orderBy = new BasicDBObject();
305
			orderBy.put("_id", -1);
302
			orderBy.put("_id", -1);
306
			DBCursor cursor = collection.find().sort(orderBy).limit(1);
303
			DBCursor cursor = collection.find().sort(orderBy).limit(1);
307
			long id = 1l;
304
			long id = 1l;
308
			while (cursor.hasNext()) {
305
			while (cursor.hasNext()) {
309
				Gson gson = new Gson();
306
				Gson gson = new Gson();
310
				NotificationCampaigns existingFofo = gson.fromJson(cursor.next().toString(), NotificationCampaigns.class);
307
				NotificationCampaigns existingFofo = gson.fromJson(cursor.next().toString(),
-
 
308
						NotificationCampaigns.class);
311
				id = existingFofo.get_id() + 1;
309
				id = existingFofo.get_id() + 1;
312
			}
310
			}
313
			ff.set_id(id);
311
			ff.set_id(id);
314
		}
312
		}
315
		Gson gs = new Gson();
313
		Gson gs = new Gson();