| Line 21... |
Line 21... |
| 21 |
import com.mongodb.MongoClient;
|
21 |
import com.mongodb.MongoClient;
|
| 22 |
import com.mongodb.client.AggregateIterable;
|
22 |
import com.mongodb.client.AggregateIterable;
|
| 23 |
import com.mongodb.client.MongoCollection;
|
23 |
import com.mongodb.client.MongoCollection;
|
| 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.model.FofoForm;
|
27 |
import com.spice.profitmandi.dao.model.FofoForm;
|
| 27 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
28 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
| 28 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepositoryImpl;
|
29 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepositoryImpl;
|
| 29 |
|
30 |
|
| 30 |
public class Mongo {
|
31 |
public class Mongo {
|
| Line 38... |
Line 39... |
| 38 |
private static final String FOFO_DB = "Fofo";
|
39 |
private static final String FOFO_DB = "Fofo";
|
| 39 |
private static final String FOFO_BRANDS = "brands";
|
40 |
private static final String FOFO_BRANDS = "brands";
|
| 40 |
private static final String PROFITMANDI_BANNERS = "banners";
|
41 |
private static final String PROFITMANDI_BANNERS = "banners";
|
| 41 |
private static final String RETAILER_FOFO_INTEREST = "RetailerFofoInterest";
|
42 |
private static final String RETAILER_FOFO_INTEREST = "RetailerFofoInterest";
|
| 42 |
private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
|
43 |
private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
|
| - |
|
44 |
private static final String NOTIFICATION_CAMPAIGNS = "notificationcampaigns";
|
| - |
|
45 |
private static final String USER_DB = "User";
|
| 43 |
private static final int MONGO_PORT = 27017;
|
46 |
private static final int MONGO_PORT = 27017;
|
| 44 |
|
47 |
|
| 45 |
private MongoClient mongoClient;
|
48 |
private MongoClient mongoClient;
|
| 46 |
private MongoClient contentMongoClient;
|
49 |
private MongoClient contentMongoClient;
|
| - |
|
50 |
private MongoClient dtrDataMongoClient;
|
| 47 |
|
51 |
|
| 48 |
public Mongo(String mongoHost, String contentMongoHost) {
|
52 |
public Mongo(String mongoHost, String contentMongoHost) {
|
| 49 |
try {
|
53 |
try {
|
| 50 |
LOGGER.info("mongoHost => {}, contentMongoHost {} ", mongoHost, contentMongoHost);
|
54 |
LOGGER.info("mongoHost => {}, contentMongoHost {} ", mongoHost, contentMongoHost);
|
| 51 |
mongoClient = new MongoClient(mongoHost, MONGO_PORT);
|
55 |
mongoClient = new MongoClient(mongoHost, MONGO_PORT);
|
| 52 |
contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
|
56 |
contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
|
| 53 |
} catch (Exception e) {
|
57 |
} catch (Exception e) {
|
| 54 |
e.printStackTrace();
|
58 |
e.printStackTrace();
|
| 55 |
}
|
59 |
}
|
| 56 |
}
|
60 |
}
|
| - |
|
61 |
|
| - |
|
62 |
public Mongo(String mongoHost, String contentMongoHost, String dtrDataMongoHost) {
|
| - |
|
63 |
try {
|
| - |
|
64 |
LOGGER.info("mongoHost => {}, contentMongoHost {},dtrDataMongoHost {} ", mongoHost, contentMongoHost,dtrDataMongoHost);
|
| - |
|
65 |
mongoClient = new MongoClient(mongoHost, MONGO_PORT);
|
| - |
|
66 |
contentMongoClient = new MongoClient(contentMongoHost, MONGO_PORT);
|
| - |
|
67 |
dtrDataMongoClient=new MongoClient(dtrDataMongoHost, MONGO_PORT);
|
| - |
|
68 |
} catch (Exception e) {
|
| - |
|
69 |
e.printStackTrace();
|
| - |
|
70 |
}
|
| - |
|
71 |
}
|
| 57 |
|
72 |
|
| 58 |
public JSONObject getEntityById(long id) throws Exception {
|
73 |
public JSONObject getEntityById(long id) throws Exception {
|
| 59 |
DB db = contentMongoClient.getDB(CONTENT);
|
74 |
DB db = contentMongoClient.getDB(CONTENT);
|
| 60 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
75 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| 61 |
BasicDBObject obj = new BasicDBObject();
|
76 |
BasicDBObject obj = new BasicDBObject();
|
| Line 279... |
Line 294... |
| 279 |
BasicDBObject filter = new BasicDBObject();
|
294 |
BasicDBObject filter = new BasicDBObject();
|
| 280 |
filter.append("userId", userId);
|
295 |
filter.append("userId", userId);
|
| 281 |
DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
|
296 |
DBCollection fofoInterestCollection = db.getCollection(RETAILER_FOFO_INTEREST);
|
| 282 |
return fofoInterestCollection.findOne(filter) != null;
|
297 |
return fofoInterestCollection.findOne(filter) != null;
|
| 283 |
}
|
298 |
}
|
| - |
|
299 |
|
| - |
|
300 |
public void persistNotificationCmpInfo(NotificationCampaigns ff) {
|
| - |
|
301 |
DB db = dtrDataMongoClient.getDB(USER_DB);
|
| - |
|
302 |
DBCollection collection = db.getCollection(NOTIFICATION_CAMPAIGNS);
|
| - |
|
303 |
if (ff.get_id() == 0) {
|
| - |
|
304 |
BasicDBObject orderBy = new BasicDBObject();
|
| - |
|
305 |
orderBy.put("_id", -1);
|
| - |
|
306 |
DBCursor cursor = collection.find().sort(orderBy).limit(1);
|
| - |
|
307 |
long id = 1l;
|
| - |
|
308 |
while (cursor.hasNext()) {
|
| - |
|
309 |
Gson gson = new Gson();
|
| - |
|
310 |
NotificationCampaigns existingFofo = gson.fromJson(cursor.next().toString(), NotificationCampaigns.class);
|
| - |
|
311 |
id = existingFofo.get_id() + 1;
|
| - |
|
312 |
}
|
| - |
|
313 |
ff.set_id(id);
|
| - |
|
314 |
}
|
| - |
|
315 |
Gson gs = new Gson();
|
| - |
|
316 |
DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
|
| - |
|
317 |
collection.save(dbObject);
|
| - |
|
318 |
}
|
| 284 |
|
319 |
|
| 285 |
}
|
320 |
}
|