Subversion Repositories SmartDukaan

Rev

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

Rev 23568 Rev 23793
Line 1... Line 1...
1
package com.spice.profitmandi.dao.repository.dtr;
1
package com.spice.profitmandi.dao.repository.dtr;
2
 
2
 
3
import java.lang.reflect.Type;
3
import java.lang.reflect.Type;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
-
 
5
import java.util.Arrays;
5
import java.util.List;
6
import java.util.List;
6
import java.util.Map;
7
import java.util.Map;
7
 
8
 
8
import org.json.JSONObject;
9
import org.json.JSONObject;
9
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.Logger;
-
 
11
import org.bson.Document;
10
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.LogManager;
11
 
13
 
12
import com.google.gson.Gson;
14
import com.google.gson.Gson;
13
import com.google.gson.reflect.TypeToken;
15
import com.google.gson.reflect.TypeToken;
14
import com.mongodb.BasicDBObject;
16
import com.mongodb.BasicDBObject;
15
import com.mongodb.DB;
17
import com.mongodb.DB;
16
import com.mongodb.DBCollection;
18
import com.mongodb.DBCollection;
17
import com.mongodb.DBCursor;
19
import com.mongodb.DBCursor;
18
import com.mongodb.DBObject;
20
import com.mongodb.DBObject;
19
import com.mongodb.MongoClient;
21
import com.mongodb.MongoClient;
-
 
22
import com.mongodb.client.AggregateIterable;
-
 
23
import com.mongodb.client.MongoCollection;
-
 
24
import com.mongodb.client.MongoDatabase;
20
import com.mongodb.util.JSON;
25
import com.mongodb.util.JSON;
21
import com.spice.profitmandi.dao.model.FofoForm;
26
import com.spice.profitmandi.dao.model.FofoForm;
22
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
27
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
-
 
28
import com.spice.profitmandi.dao.repository.transaction.OrderRepositoryImpl;
23
 
29
 
24
public class Mongo {
30
public class Mongo {
25
 
31
 
26
	private static final Logger LOGGER = LogManager.getLogger(Mongo.class);
32
	private static final Logger LOGGER = LogManager.getLogger(Mongo.class);
27
 
33
 
Line 226... Line 232...
226
		filter.append("type", bannerType);
232
		filter.append("type", bannerType);
227
		BasicDBObject orderBy = new BasicDBObject();
233
		BasicDBObject orderBy = new BasicDBObject();
228
		orderBy.put("rank", 1);
234
		orderBy.put("rank", 1);
229
		return db.getCollection(PROFITMANDI_BANNERS).find(filter).sort(orderBy).toArray();
235
		return db.getCollection(PROFITMANDI_BANNERS).find(filter).sort(orderBy).toArray();
230
	}
236
	}
-
 
237
 
-
 
238
	@SuppressWarnings("unchecked")
-
 
239
	public List<Document> getSubcategoriesToDisplay() {
-
 
240
		MongoDatabase db = mongoClient.getDatabase("Catalog");
-
 
241
		System.out.println("Connection to MongoDB database successfully");
-
 
242
		MongoCollection<Document> collection = db.getCollection("Deals");
231
	
243
		
-
 
244
		Document object = new Document().append("$match", new Document()
-
 
245
											.append("category_id", 6)
-
 
246
											.append("showDeal", 1)
-
 
247
											.append("dealRankPoints", new Document("$gt", 0))
-
 
248
							);
-
 
249
		Document ob = new Document("$group",
-
 
250
							new Document()
-
 
251
								.append("_id",
-
 
252
									new Document()
-
 
253
										.append("subCategoryId", "$subCategoryId")
-
 
254
										.append("subCategory", "$subCategory"))
-
 
255
								.append("count", new Document("$sum", 1)));
-
 
256
		List<Document> pipeline = Arrays.asList(object, ob);
-
 
257
		AggregateIterable<Document> cursor = collection.aggregate(pipeline);
-
 
258
 
-
 
259
		List<Document> resultDocuments = new ArrayList<>();
-
 
260
		for (Document dbo : cursor) {
-
 
261
			System.out.println(dbo.toString());
-
 
262
			LOGGER.info("categories" + dbo.toString());
-
 
263
			resultDocuments.add(dbo);
-
 
264
		}
-
 
265
		return resultDocuments;
-
 
266
	}
-
 
267
 
232
	public boolean saveRetailerInterestOnFofo(RetailerFofoInterest retailerInterest) {
268
	public boolean saveRetailerInterestOnFofo(RetailerFofoInterest retailerInterest) {
233
		DB db = mongoClient.getDB(FOFO_DB);
269
		DB db = mongoClient.getDB(FOFO_DB);
234
		Gson gs = new Gson();
270
		Gson gs = new Gson();
235
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
271
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
236
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(retailerInterest));
272
		DBObject dbObject = (DBObject) JSON.parse(gs.toJson(retailerInterest));
237
		fofoInterestCollection.save(dbObject);
273
		fofoInterestCollection.save(dbObject);
238
		return true;
274
		return true;
239
	}
275
	}
240
	
276
 
241
	public boolean hasRetailerShownInterest(int userId) {
277
	public boolean hasRetailerShownInterest(int userId) {
242
		DB db = mongoClient.getDB(FOFO_DB);
278
		DB db = mongoClient.getDB(FOFO_DB);
243
		BasicDBObject filter = new BasicDBObject();
279
		BasicDBObject filter = new BasicDBObject();
244
		filter.append("userId", userId);		
280
		filter.append("userId", userId);
245
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
281
		DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
246
		return fofoInterestCollection.findOne(filter)!=null;
282
		return fofoInterestCollection.findOne(filter) != null;
247
	}
283
	}
248
 
284
 
249
}
285
}