| 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;
|
| 22097 |
kshitij.so |
7 |
import java.util.List;
|
| 22125 |
ashik.ali |
8 |
import java.util.Map;
|
| 24995 |
amit.gupta |
9 |
import java.util.stream.Collectors;
|
| 21545 |
ashik.ali |
10 |
|
| 24031 |
amit.gupta |
11 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
12 |
import org.apache.logging.log4j.Logger;
|
| 23793 |
tejbeer |
13 |
import org.bson.Document;
|
| 24031 |
amit.gupta |
14 |
import org.json.JSONObject;
|
| 21545 |
ashik.ali |
15 |
|
| 22097 |
kshitij.so |
16 |
import com.google.gson.Gson;
|
|
|
17 |
import com.google.gson.reflect.TypeToken;
|
| 21545 |
ashik.ali |
18 |
import com.mongodb.BasicDBObject;
|
|
|
19 |
import com.mongodb.DB;
|
|
|
20 |
import com.mongodb.DBCollection;
|
| 22097 |
kshitij.so |
21 |
import com.mongodb.DBCursor;
|
| 21545 |
ashik.ali |
22 |
import com.mongodb.DBObject;
|
|
|
23 |
import com.mongodb.MongoClient;
|
| 23793 |
tejbeer |
24 |
import com.mongodb.client.AggregateIterable;
|
|
|
25 |
import com.mongodb.client.MongoCollection;
|
|
|
26 |
import com.mongodb.client.MongoDatabase;
|
| 21545 |
ashik.ali |
27 |
import com.mongodb.util.JSON;
|
| 24011 |
tejbeer |
28 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
| 25380 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
| 22097 |
kshitij.so |
30 |
import com.spice.profitmandi.dao.model.FofoForm;
|
| 22496 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
| 21545 |
ashik.ali |
32 |
|
|
|
33 |
public class Mongo {
|
| 22384 |
amit.gupta |
34 |
|
| 23568 |
govind |
35 |
private static final Logger LOGGER = LogManager.getLogger(Mongo.class);
|
| 21545 |
ashik.ali |
36 |
|
| 22165 |
amit.gupta |
37 |
private static final String CONTENT = "CONTENT";
|
| 21545 |
ashik.ali |
38 |
private static final String SITE_CONTENT = "siteContent";
|
|
|
39 |
private static final String CATALOG_DB = "Catalog";
|
|
|
40 |
private static final String MASTER_DATA = "MasterData";
|
| 22097 |
kshitij.so |
41 |
private static final String FOFO_DB = "Fofo";
|
| 22335 |
amit.gupta |
42 |
private static final String FOFO_BRANDS = "brands";
|
| 22446 |
amit.gupta |
43 |
private static final String PROFITMANDI_BANNERS = "banners";
|
| 22496 |
amit.gupta |
44 |
private static final String RETAILER_FOFO_INTEREST = "RetailerFofoInterest";
|
| 22097 |
kshitij.so |
45 |
private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
|
| 24011 |
tejbeer |
46 |
private static final String NOTIFICATION_CAMPAIGNS = "notificationcampaigns";
|
|
|
47 |
private static final String USER_DB = "User";
|
| 21545 |
ashik.ali |
48 |
private static final int MONGO_PORT = 27017;
|
| 25380 |
amit.gupta |
49 |
|
|
|
50 |
private static final Gson gson = new Gson();
|
|
|
51 |
|
| 24995 |
amit.gupta |
52 |
public static final Map<String, List<String>> EMAIL_BLOCKED_BRANDS = new HashMap<>();
|
| 22165 |
amit.gupta |
53 |
|
| 24995 |
amit.gupta |
54 |
static {
|
| 25446 |
amit.gupta |
55 |
EMAIL_BLOCKED_BRANDS.put("babitaranirk@gmail.com", Arrays.asList("Vivo"));
|
| 24995 |
amit.gupta |
56 |
EMAIL_BLOCKED_BRANDS.put("akamboj828@gmail.com", Arrays.asList("Vivo"));
|
| 25446 |
amit.gupta |
57 |
EMAIL_BLOCKED_BRANDS.put("arunmittal299@gmail.com", Arrays.asList("Vivo"));
|
|
|
58 |
EMAIL_BLOCKED_BRANDS.put("nareandergupta@gmail.com", Arrays.asList("Vivo"));
|
|
|
59 |
EMAIL_BLOCKED_BRANDS.put("lakshaydhulla62@gmail.com", Arrays.asList("Vivo"));
|
|
|
60 |
EMAIL_BLOCKED_BRANDS.put("sahilnarang0009@gmail.com", Arrays.asList("Vivo"));
|
|
|
61 |
EMAIL_BLOCKED_BRANDS.put("smartdukan.ynr@gmail.com", Arrays.asList("Vivo"));
|
|
|
62 |
EMAIL_BLOCKED_BRANDS.put("supertelecomjind@gmail.com", Arrays.asList("Vivo"));
|
|
|
63 |
EMAIL_BLOCKED_BRANDS.put("amitv70003@gmail.com", Arrays.asList("Vivo"));
|
|
|
64 |
EMAIL_BLOCKED_BRANDS.put("rohitbatra106@gmail.com", Arrays.asList("Vivo"));
|
|
|
65 |
EMAIL_BLOCKED_BRANDS.put("sonisunil9050873061@gmail.com", Arrays.asList("Vivo"));
|
|
|
66 |
EMAIL_BLOCKED_BRANDS.put("moderncohsr@gmail.com", Arrays.asList("Vivo"));
|
|
|
67 |
EMAIL_BLOCKED_BRANDS.put("aman007singla@gmail.com", Arrays.asList("Vivo"));
|
|
|
68 |
EMAIL_BLOCKED_BRANDS.put("bindraelectricals1987@gmail.com", Arrays.asList("Vivo"));
|
|
|
69 |
EMAIL_BLOCKED_BRANDS.put("madaanelectronics@gmail.com", Arrays.asList("Vivo"));
|
|
|
70 |
EMAIL_BLOCKED_BRANDS.put("khuranamobile753@gmail.COM", Arrays.asList("Vivo"));
|
|
|
71 |
EMAIL_BLOCKED_BRANDS.put("rameshvashist175@gmail.com", Arrays.asList("Vivo"));
|
| 24995 |
amit.gupta |
72 |
EMAIL_BLOCKED_BRANDS.put("testpxps@gmail.com", Arrays.asList("Gionee"));
|
|
|
73 |
}
|
|
|
74 |
|
| 22162 |
amit.gupta |
75 |
private MongoClient mongoClient;
|
|
|
76 |
private MongoClient contentMongoClient;
|
|
|
77 |
|
| 22171 |
amit.gupta |
78 |
public Mongo(String mongoHost, String contentMongoHost) {
|
| 22165 |
amit.gupta |
79 |
try {
|
| 22170 |
amit.gupta |
80 |
LOGGER.info("mongoHost => {}, contentMongoHost {} ", mongoHost, contentMongoHost);
|
| 22165 |
amit.gupta |
81 |
mongoClient = new MongoClient(mongoHost, MONGO_PORT);
|
| 22169 |
amit.gupta |
82 |
contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
|
| 22165 |
amit.gupta |
83 |
} catch (Exception e) {
|
|
|
84 |
e.printStackTrace();
|
|
|
85 |
}
|
| 21545 |
ashik.ali |
86 |
}
|
| 24031 |
amit.gupta |
87 |
|
| 25380 |
amit.gupta |
88 |
public ContentPojo getEntityById(long id) throws Exception {
|
| 22162 |
amit.gupta |
89 |
DB db = contentMongoClient.getDB(CONTENT);
|
| 21545 |
ashik.ali |
90 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
|
|
91 |
BasicDBObject obj = new BasicDBObject();
|
|
|
92 |
obj.append("_id", id);
|
|
|
93 |
DBObject result = collection.findOne(obj);
|
| 22165 |
amit.gupta |
94 |
if (result == null) {
|
| 21545 |
ashik.ali |
95 |
throw new Exception();
|
|
|
96 |
}
|
| 25380 |
amit.gupta |
97 |
return gson.fromJson(new BasicDBObject(result.toMap()).toJson(), ContentPojo.class);
|
| 21545 |
ashik.ali |
98 |
}
|
| 25380 |
amit.gupta |
99 |
|
| 24995 |
amit.gupta |
100 |
public List<DBObject> getMongoBrands(int fofoId, String email, int categoryId) {
|
|
|
101 |
List<DBObject> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
| 25447 |
amit.gupta |
102 |
if (EMAIL_BLOCKED_BRANDS.containsKey(email.toLowerCase())) {
|
| 24995 |
amit.gupta |
103 |
List<String> blockedBrands = EMAIL_BLOCKED_BRANDS.get(email);
|
|
|
104 |
brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.get("name")))
|
|
|
105 |
.collect(Collectors.toList());
|
|
|
106 |
}
|
|
|
107 |
return brandsDisplay;
|
| 25380 |
amit.gupta |
108 |
|
| 24995 |
amit.gupta |
109 |
}
|
| 22165 |
amit.gupta |
110 |
|
| 25380 |
amit.gupta |
111 |
public ContentPojo getEntityByName(String name) throws Exception {
|
| 22385 |
amit.gupta |
112 |
LOGGER.info("Name --- {}", name);
|
| 22384 |
amit.gupta |
113 |
DB db = contentMongoClient.getDB(CONTENT);
|
|
|
114 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
|
|
115 |
BasicDBObject obj = new BasicDBObject();
|
|
|
116 |
obj.append("title", name);
|
| 25380 |
amit.gupta |
117 |
DBObject result = collection.findOne();
|
| 22384 |
amit.gupta |
118 |
if (result == null) {
|
|
|
119 |
throw new Exception();
|
|
|
120 |
}
|
| 25380 |
amit.gupta |
121 |
return gson.fromJson(new BasicDBObject(result.toMap()).toJson(), ContentPojo.class);
|
| 22384 |
amit.gupta |
122 |
}
|
|
|
123 |
|
| 25380 |
amit.gupta |
124 |
public void persistEntity(ContentPojo contentPojo) {
|
|
|
125 |
DB db = contentMongoClient.getDB(CONTENT);
|
|
|
126 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
|
|
127 |
insertOrUpdateById(collection, contentPojo.getId(), contentPojo);
|
|
|
128 |
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
private static <T> void insertOrUpdateById(DBCollection collection, long id, T obj) {
|
|
|
132 |
DBObject dbo = BasicDBObject.parse(gson.toJson(obj));
|
|
|
133 |
dbo.put("_id", id);
|
|
|
134 |
collection.update(new BasicDBObject("_id", id), dbo, true, false);
|
|
|
135 |
}
|
|
|
136 |
|
| 22165 |
amit.gupta |
137 |
public JSONObject getItemsByBundleId(long bundleId) throws Exception {
|
| 22162 |
amit.gupta |
138 |
DB db = mongoClient.getDB(CATALOG_DB);
|
| 21545 |
ashik.ali |
139 |
DBCollection collection = db.getCollection(MASTER_DATA);
|
|
|
140 |
BasicDBObject obj = new BasicDBObject();
|
|
|
141 |
BasicDBObject in_query = new BasicDBObject();
|
|
|
142 |
obj.append("skuBundleId", bundleId);
|
| 22165 |
amit.gupta |
143 |
in_query.append("$in", new int[] { 1, 2, 3, 4, 5, 6, 7 });
|
| 21545 |
ashik.ali |
144 |
obj.append("source_id", in_query);
|
|
|
145 |
DBObject result = collection.findOne(obj);
|
| 22165 |
amit.gupta |
146 |
if (result == null) {
|
| 21545 |
ashik.ali |
147 |
throw new Exception();
|
|
|
148 |
}
|
|
|
149 |
return new JSONObject(JSON.serialize(result));
|
|
|
150 |
}
|
| 22165 |
amit.gupta |
151 |
|
|
|
152 |
public JSONObject getItemByID(long id) throws Exception {
|
| 22162 |
amit.gupta |
153 |
DB db = mongoClient.getDB(CATALOG_DB);
|
| 21545 |
ashik.ali |
154 |
DBCollection collection = db.getCollection(MASTER_DATA);
|
|
|
155 |
BasicDBObject obj = new BasicDBObject();
|
|
|
156 |
obj.append("_id", id);
|
|
|
157 |
DBObject result = collection.findOne(obj);
|
| 22165 |
amit.gupta |
158 |
if (result == null) {
|
| 21545 |
ashik.ali |
159 |
throw new Exception();
|
|
|
160 |
}
|
|
|
161 |
return new JSONObject(JSON.serialize(result));
|
|
|
162 |
}
|
| 22165 |
amit.gupta |
163 |
|
|
|
164 |
public void persistFofoRegInfo(FofoForm ff) {
|
|
|
165 |
DB db = mongoClient.getDB(FOFO_DB);
|
| 22097 |
kshitij.so |
166 |
DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
|
| 22165 |
amit.gupta |
167 |
if (ff.get_id() == 0) {
|
| 22097 |
kshitij.so |
168 |
BasicDBObject orderBy = new BasicDBObject();
|
|
|
169 |
orderBy.put("_id", -1);
|
|
|
170 |
DBCursor cursor = collection.find().sort(orderBy).limit(1);
|
|
|
171 |
long id = 1l;
|
|
|
172 |
while (cursor.hasNext()) {
|
|
|
173 |
FofoForm existingFofo = gson.fromJson(cursor.next().toString(), FofoForm.class);
|
|
|
174 |
id = existingFofo.get_id() + 1;
|
|
|
175 |
}
|
|
|
176 |
ff.set_id(id);
|
|
|
177 |
}
|
| 25380 |
amit.gupta |
178 |
DBObject dbObject = (DBObject) JSON.parse(gson.toJson(ff));
|
| 22097 |
kshitij.so |
179 |
collection.save(dbObject);
|
|
|
180 |
}
|
| 22165 |
amit.gupta |
181 |
|
| 22162 |
amit.gupta |
182 |
public List<FofoForm> getFofoForms(int offset, int limit) {
|
| 22165 |
amit.gupta |
183 |
List<FofoForm> ffList = new ArrayList<FofoForm>();
|
| 22162 |
amit.gupta |
184 |
DB db = mongoClient.getDB(FOFO_DB);
|
| 22097 |
kshitij.so |
185 |
DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
|
|
|
186 |
BasicDBObject orderBy = new BasicDBObject();
|
|
|
187 |
orderBy.put("_id", -1);
|
|
|
188 |
DBCursor dbc = collection.find().sort(orderBy).limit(limit).skip(offset);
|
|
|
189 |
while (dbc.hasNext()) {
|
|
|
190 |
ffList.add(convertJSONToPojo(dbc.next().toString()));
|
|
|
191 |
}
|
|
|
192 |
return ffList;
|
|
|
193 |
}
|
| 22165 |
amit.gupta |
194 |
|
|
|
195 |
public String getFofoFormJsonStringByFofoId(int fofoId) {
|
| 22162 |
amit.gupta |
196 |
DB db = mongoClient.getDB(FOFO_DB);
|
| 22097 |
kshitij.so |
197 |
BasicDBObject filter = new BasicDBObject();
|
|
|
198 |
filter.append("_id", fofoId);
|
|
|
199 |
DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
|
| 22105 |
ashik.ali |
200 |
DBObject fofoDbOject = collection.findOne(filter);
|
| 22165 |
amit.gupta |
201 |
if (fofoDbOject != null) {
|
| 22161 |
amit.gupta |
202 |
return fofoDbOject.toString();
|
|
|
203 |
} else {
|
|
|
204 |
return null;
|
|
|
205 |
}
|
| 22097 |
kshitij.so |
206 |
}
|
| 22165 |
amit.gupta |
207 |
|
|
|
208 |
public String getFofoFormJsonStringByEmail(String email) {
|
| 22162 |
amit.gupta |
209 |
DB db = mongoClient.getDB(FOFO_DB);
|
| 22155 |
amit.gupta |
210 |
BasicDBObject filter = new BasicDBObject();
|
|
|
211 |
filter.append("registeredEmail1", email);
|
|
|
212 |
DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
|
|
|
213 |
DBObject fofoDbOject = collection.findOne(filter);
|
| 22165 |
amit.gupta |
214 |
if (fofoDbOject != null) {
|
| 22161 |
amit.gupta |
215 |
return fofoDbOject.toString();
|
|
|
216 |
} else {
|
|
|
217 |
return null;
|
|
|
218 |
}
|
| 22155 |
amit.gupta |
219 |
}
|
| 22165 |
amit.gupta |
220 |
|
|
|
221 |
public String getFofoFormsJsonString() {
|
| 22162 |
amit.gupta |
222 |
DB db = mongoClient.getDB(FOFO_DB);
|
| 22125 |
ashik.ali |
223 |
DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
|
|
|
224 |
DBCursor cursor = collection.find();
|
|
|
225 |
StringBuilder fofoFormsJsonString = new StringBuilder();
|
|
|
226 |
fofoFormsJsonString.append("[");
|
| 22165 |
amit.gupta |
227 |
while (cursor.hasNext()) {
|
| 22125 |
ashik.ali |
228 |
fofoFormsJsonString.append(cursor.next().toString());
|
| 22165 |
amit.gupta |
229 |
if (cursor.hasNext()) {
|
| 22125 |
ashik.ali |
230 |
fofoFormsJsonString.append(",");
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
fofoFormsJsonString.append("]");
|
|
|
234 |
return fofoFormsJsonString.toString();
|
|
|
235 |
}
|
| 22165 |
amit.gupta |
236 |
|
| 22162 |
amit.gupta |
237 |
public FofoForm getFofoForm(int fofoId) {
|
| 22097 |
kshitij.so |
238 |
String fofoFormJsonString = getFofoFormJsonStringByFofoId(fofoId);
|
|
|
239 |
System.out.println(fofoFormJsonString);
|
|
|
240 |
return new Gson().fromJson(fofoFormJsonString, FofoForm.class);
|
| 22165 |
amit.gupta |
241 |
// return convertJSONToPojo(fofoDbOject.toString());
|
| 22097 |
kshitij.so |
242 |
}
|
| 22165 |
amit.gupta |
243 |
|
| 22162 |
amit.gupta |
244 |
public FofoForm getFofoForm(String email) {
|
| 22155 |
amit.gupta |
245 |
String fofoFormJsonString = getFofoFormJsonStringByEmail(email);
|
|
|
246 |
System.out.println(fofoFormJsonString);
|
|
|
247 |
return new Gson().fromJson(fofoFormJsonString, FofoForm.class);
|
| 22165 |
amit.gupta |
248 |
// return convertJSONToPojo(fofoDbOject.toString());
|
| 22155 |
amit.gupta |
249 |
}
|
| 21545 |
ashik.ali |
250 |
|
| 22165 |
amit.gupta |
251 |
private static FofoForm convertJSONToPojo(String json) {
|
| 22097 |
kshitij.so |
252 |
|
| 22165 |
amit.gupta |
253 |
Type type = new TypeToken<FofoForm>() {
|
|
|
254 |
}.getType();
|
| 22097 |
kshitij.so |
255 |
|
| 22165 |
amit.gupta |
256 |
return new Gson().fromJson(json, type);
|
|
|
257 |
|
| 22097 |
kshitij.so |
258 |
}
|
| 22165 |
amit.gupta |
259 |
|
|
|
260 |
public void updateColumnsById(Map<String, Integer> map, int fofoId) {
|
| 22162 |
amit.gupta |
261 |
DB db = mongoClient.getDB(FOFO_DB);
|
| 22125 |
ashik.ali |
262 |
BasicDBObject filter = new BasicDBObject();
|
|
|
263 |
filter.append("_id", fofoId);
|
|
|
264 |
DBCollection collection = db.getCollection(FOFO_FORM_COLLECTION);
|
|
|
265 |
BasicDBObject updateFields = new BasicDBObject();
|
| 22165 |
amit.gupta |
266 |
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
| 22125 |
ashik.ali |
267 |
updateFields.append(entry.getKey(), entry.getValue());
|
|
|
268 |
}
|
|
|
269 |
BasicDBObject newDocument = new BasicDBObject();
|
|
|
270 |
newDocument.append("$set", updateFields);
|
|
|
271 |
collection.update(filter, newDocument);
|
|
|
272 |
}
|
| 24031 |
amit.gupta |
273 |
|
|
|
274 |
public List<DBObject> getBrandsToDisplay(int categoryId) {
|
| 22335 |
amit.gupta |
275 |
DB db = mongoClient.getDB(FOFO_DB);
|
|
|
276 |
BasicDBObject filter = new BasicDBObject();
|
|
|
277 |
filter.append("active", true);
|
| 24031 |
amit.gupta |
278 |
if (categoryId != 0) {
|
|
|
279 |
filter.append("categoryId", categoryId);
|
|
|
280 |
}
|
| 22335 |
amit.gupta |
281 |
return db.getCollection(FOFO_BRANDS).find(filter).toArray();
|
|
|
282 |
}
|
| 24031 |
amit.gupta |
283 |
|
| 22447 |
amit.gupta |
284 |
public List<DBObject> getBannersByType(String bannerType) {
|
| 22446 |
amit.gupta |
285 |
DB db = mongoClient.getDB(CATALOG_DB);
|
|
|
286 |
BasicDBObject filter = new BasicDBObject();
|
| 22449 |
amit.gupta |
287 |
filter.append("type", bannerType);
|
| 22992 |
amit.gupta |
288 |
BasicDBObject orderBy = new BasicDBObject();
|
| 23008 |
amit.gupta |
289 |
orderBy.put("rank", 1);
|
| 22992 |
amit.gupta |
290 |
return db.getCollection(PROFITMANDI_BANNERS).find(filter).sort(orderBy).toArray();
|
| 22446 |
amit.gupta |
291 |
}
|
| 23793 |
tejbeer |
292 |
|
|
|
293 |
@SuppressWarnings("unchecked")
|
|
|
294 |
public List<Document> getSubcategoriesToDisplay() {
|
|
|
295 |
MongoDatabase db = mongoClient.getDatabase("Catalog");
|
|
|
296 |
System.out.println("Connection to MongoDB database successfully");
|
|
|
297 |
MongoCollection<Document> collection = db.getCollection("Deals");
|
| 24031 |
amit.gupta |
298 |
|
|
|
299 |
Document object = new Document().append("$match", new Document().append("category_id", 6).append("showDeal", 1)
|
|
|
300 |
.append("dealRankPoints", new Document("$gt", 0)));
|
| 23793 |
tejbeer |
301 |
Document ob = new Document("$group",
|
| 24031 |
amit.gupta |
302 |
new Document().append("_id",
|
|
|
303 |
new Document().append("subCategoryId", "$subCategoryId").append("subCategory", "$subCategory"))
|
|
|
304 |
.append("count", new Document("$sum", 1)));
|
| 23793 |
tejbeer |
305 |
List<Document> pipeline = Arrays.asList(object, ob);
|
|
|
306 |
AggregateIterable<Document> cursor = collection.aggregate(pipeline);
|
|
|
307 |
|
|
|
308 |
List<Document> resultDocuments = new ArrayList<>();
|
|
|
309 |
for (Document dbo : cursor) {
|
|
|
310 |
System.out.println(dbo.toString());
|
|
|
311 |
LOGGER.info("categories" + dbo.toString());
|
|
|
312 |
resultDocuments.add(dbo);
|
|
|
313 |
}
|
|
|
314 |
return resultDocuments;
|
|
|
315 |
}
|
|
|
316 |
|
| 22496 |
amit.gupta |
317 |
public boolean saveRetailerInterestOnFofo(RetailerFofoInterest retailerInterest) {
|
|
|
318 |
DB db = mongoClient.getDB(FOFO_DB);
|
|
|
319 |
Gson gs = new Gson();
|
|
|
320 |
DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
|
|
|
321 |
DBObject dbObject = (DBObject) JSON.parse(gs.toJson(retailerInterest));
|
|
|
322 |
fofoInterestCollection.save(dbObject);
|
|
|
323 |
return true;
|
|
|
324 |
}
|
| 23793 |
tejbeer |
325 |
|
| 22496 |
amit.gupta |
326 |
public boolean hasRetailerShownInterest(int userId) {
|
|
|
327 |
DB db = mongoClient.getDB(FOFO_DB);
|
|
|
328 |
BasicDBObject filter = new BasicDBObject();
|
| 23793 |
tejbeer |
329 |
filter.append("userId", userId);
|
| 22496 |
amit.gupta |
330 |
DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
|
| 23793 |
tejbeer |
331 |
return fofoInterestCollection.findOne(filter) != null;
|
| 22496 |
amit.gupta |
332 |
}
|
| 24031 |
amit.gupta |
333 |
|
| 24011 |
tejbeer |
334 |
public void persistNotificationCmpInfo(NotificationCampaigns ff) {
|
| 24383 |
amit.gupta |
335 |
DB db = mongoClient.getDB(USER_DB);
|
| 24011 |
tejbeer |
336 |
DBCollection collection = db.getCollection(NOTIFICATION_CAMPAIGNS);
|
|
|
337 |
if (ff.get_id() == 0) {
|
|
|
338 |
BasicDBObject orderBy = new BasicDBObject();
|
|
|
339 |
orderBy.put("_id", -1);
|
|
|
340 |
DBCursor cursor = collection.find().sort(orderBy).limit(1);
|
|
|
341 |
long id = 1l;
|
|
|
342 |
while (cursor.hasNext()) {
|
|
|
343 |
Gson gson = new Gson();
|
| 24031 |
amit.gupta |
344 |
NotificationCampaigns existingFofo = gson.fromJson(cursor.next().toString(),
|
|
|
345 |
NotificationCampaigns.class);
|
| 24011 |
tejbeer |
346 |
id = existingFofo.get_id() + 1;
|
|
|
347 |
}
|
|
|
348 |
ff.set_id(id);
|
|
|
349 |
}
|
|
|
350 |
Gson gs = new Gson();
|
|
|
351 |
DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
|
|
|
352 |
collection.save(dbObject);
|
|
|
353 |
}
|
| 22097 |
kshitij.so |
354 |
|
| 21545 |
ashik.ali |
355 |
}
|