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