| Line 24... |
Line 24... |
| 24 |
import com.mongodb.client.AggregateIterable;
|
24 |
import com.mongodb.client.AggregateIterable;
|
| 25 |
import com.mongodb.client.MongoCollection;
|
25 |
import com.mongodb.client.MongoCollection;
|
| 26 |
import com.mongodb.client.MongoDatabase;
|
26 |
import com.mongodb.client.MongoDatabase;
|
| 27 |
import com.mongodb.util.JSON;
|
27 |
import com.mongodb.util.JSON;
|
| 28 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
28 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
| - |
|
29 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
| 29 |
import com.spice.profitmandi.dao.model.FofoForm;
|
30 |
import com.spice.profitmandi.dao.model.FofoForm;
|
| 30 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
31 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
| 31 |
|
32 |
|
| 32 |
public class Mongo {
|
33 |
public class Mongo {
|
| 33 |
|
34 |
|
| Line 43... |
Line 44... |
| 43 |
private static final String RETAILER_FOFO_INTEREST = "RetailerFofoInterest";
|
44 |
private static final String RETAILER_FOFO_INTEREST = "RetailerFofoInterest";
|
| 44 |
private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
|
45 |
private static final String FOFO_FORM_COLLECTION = "RegistrationForm";
|
| 45 |
private static final String NOTIFICATION_CAMPAIGNS = "notificationcampaigns";
|
46 |
private static final String NOTIFICATION_CAMPAIGNS = "notificationcampaigns";
|
| 46 |
private static final String USER_DB = "User";
|
47 |
private static final String USER_DB = "User";
|
| 47 |
private static final int MONGO_PORT = 27017;
|
48 |
private static final int MONGO_PORT = 27017;
|
| - |
|
49 |
|
| - |
|
50 |
private static final Gson gson = new Gson();
|
| 48 |
|
51 |
|
| 49 |
public static final Map<String, List<String>> EMAIL_BLOCKED_BRANDS = new HashMap<>();
|
52 |
public static final Map<String, List<String>> EMAIL_BLOCKED_BRANDS = new HashMap<>();
|
| 50 |
|
53 |
|
| 51 |
static {
|
54 |
static {
|
| 52 |
EMAIL_BLOCKED_BRANDS.put("sachinindri2006@gmail.com", Arrays.asList("Vivo"));
|
55 |
EMAIL_BLOCKED_BRANDS.put("sachinindri2006@gmail.com", Arrays.asList("Vivo"));
|
| 53 |
EMAIL_BLOCKED_BRANDS.put("akamboj828@gmail.com", Arrays.asList("Vivo"));
|
56 |
EMAIL_BLOCKED_BRANDS.put("akamboj828@gmail.com", Arrays.asList("Vivo"));
|
| Line 66... |
Line 69... |
| 66 |
} catch (Exception e) {
|
69 |
} catch (Exception e) {
|
| 67 |
e.printStackTrace();
|
70 |
e.printStackTrace();
|
| 68 |
}
|
71 |
}
|
| 69 |
}
|
72 |
}
|
| 70 |
|
73 |
|
| 71 |
public JSONObject getEntityById(long id) throws Exception {
|
74 |
public ContentPojo getEntityById(long id) throws Exception {
|
| 72 |
DB db = contentMongoClient.getDB(CONTENT);
|
75 |
DB db = contentMongoClient.getDB(CONTENT);
|
| 73 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
76 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| 74 |
BasicDBObject obj = new BasicDBObject();
|
77 |
BasicDBObject obj = new BasicDBObject();
|
| 75 |
obj.append("_id", id);
|
78 |
obj.append("_id", id);
|
| 76 |
DBObject result = collection.findOne(obj);
|
79 |
DBObject result = collection.findOne(obj);
|
| 77 |
if (result == null) {
|
80 |
if (result == null) {
|
| 78 |
throw new Exception();
|
81 |
throw new Exception();
|
| 79 |
}
|
82 |
}
|
| 80 |
return new JSONObject(JSON.serialize(result));
|
83 |
return gson.fromJson(new BasicDBObject(result.toMap()).toJson(), ContentPojo.class);
|
| 81 |
}
|
84 |
}
|
| 82 |
|
85 |
|
| 83 |
public List<DBObject> getMongoBrands(int fofoId, String email, int categoryId) {
|
86 |
public List<DBObject> getMongoBrands(int fofoId, String email, int categoryId) {
|
| 84 |
List<DBObject> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
87 |
List<DBObject> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
| 85 |
if (EMAIL_BLOCKED_BRANDS.containsKey(email)) {
|
88 |
if (EMAIL_BLOCKED_BRANDS.containsKey(email)) {
|
| 86 |
List<String> blockedBrands = EMAIL_BLOCKED_BRANDS.get(email);
|
89 |
List<String> blockedBrands = EMAIL_BLOCKED_BRANDS.get(email);
|
| 87 |
brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.get("name")))
|
90 |
brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.get("name")))
|
| 88 |
.collect(Collectors.toList());
|
91 |
.collect(Collectors.toList());
|
| 89 |
}
|
92 |
}
|
| 90 |
return brandsDisplay;
|
93 |
return brandsDisplay;
|
| 91 |
|
94 |
|
| 92 |
}
|
95 |
}
|
| 93 |
|
96 |
|
| 94 |
public JSONObject getEntityByName(String name) throws Exception {
|
97 |
public ContentPojo getEntityByName(String name) throws Exception {
|
| 95 |
LOGGER.info("Name --- {}", name);
|
98 |
LOGGER.info("Name --- {}", name);
|
| 96 |
DB db = contentMongoClient.getDB(CONTENT);
|
99 |
DB db = contentMongoClient.getDB(CONTENT);
|
| 97 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
100 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| 98 |
BasicDBObject obj = new BasicDBObject();
|
101 |
BasicDBObject obj = new BasicDBObject();
|
| 99 |
obj.append("title", name);
|
102 |
obj.append("title", name);
|
| 100 |
DBObject result = collection.findOne(obj);
|
103 |
DBObject result = collection.findOne();
|
| 101 |
if (result == null) {
|
104 |
if (result == null) {
|
| 102 |
throw new Exception();
|
105 |
throw new Exception();
|
| 103 |
}
|
106 |
}
|
| - |
|
107 |
return gson.fromJson(new BasicDBObject(result.toMap()).toJson(), ContentPojo.class);
|
| - |
|
108 |
}
|
| - |
|
109 |
|
| - |
|
110 |
public void persistEntity(ContentPojo contentPojo) {
|
| - |
|
111 |
DB db = contentMongoClient.getDB(CONTENT);
|
| - |
|
112 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| - |
|
113 |
insertOrUpdateById(collection, contentPojo.getId(), contentPojo);
|
| - |
|
114 |
|
| - |
|
115 |
}
|
| - |
|
116 |
|
| - |
|
117 |
private static <T> void insertOrUpdateById(DBCollection collection, long id, T obj) {
|
| 104 |
return new JSONObject(JSON.serialize(result));
|
118 |
DBObject dbo = BasicDBObject.parse(gson.toJson(obj));
|
| - |
|
119 |
dbo.put("_id", id);
|
| - |
|
120 |
collection.update(new BasicDBObject("_id", id), dbo, true, false);
|
| 105 |
}
|
121 |
}
|
| 106 |
|
122 |
|
| 107 |
public JSONObject getItemsByBundleId(long bundleId) throws Exception {
|
123 |
public JSONObject getItemsByBundleId(long bundleId) throws Exception {
|
| 108 |
DB db = mongoClient.getDB(CATALOG_DB);
|
124 |
DB db = mongoClient.getDB(CATALOG_DB);
|
| 109 |
DBCollection collection = db.getCollection(MASTER_DATA);
|
125 |
DBCollection collection = db.getCollection(MASTER_DATA);
|
| Line 138... |
Line 154... |
| 138 |
BasicDBObject orderBy = new BasicDBObject();
|
154 |
BasicDBObject orderBy = new BasicDBObject();
|
| 139 |
orderBy.put("_id", -1);
|
155 |
orderBy.put("_id", -1);
|
| 140 |
DBCursor cursor = collection.find().sort(orderBy).limit(1);
|
156 |
DBCursor cursor = collection.find().sort(orderBy).limit(1);
|
| 141 |
long id = 1l;
|
157 |
long id = 1l;
|
| 142 |
while (cursor.hasNext()) {
|
158 |
while (cursor.hasNext()) {
|
| 143 |
Gson gson = new Gson();
|
- |
|
| 144 |
FofoForm existingFofo = gson.fromJson(cursor.next().toString(), FofoForm.class);
|
159 |
FofoForm existingFofo = gson.fromJson(cursor.next().toString(), FofoForm.class);
|
| 145 |
id = existingFofo.get_id() + 1;
|
160 |
id = existingFofo.get_id() + 1;
|
| 146 |
}
|
161 |
}
|
| 147 |
ff.set_id(id);
|
162 |
ff.set_id(id);
|
| 148 |
}
|
163 |
}
|
| 149 |
Gson gs = new Gson();
|
- |
|
| 150 |
DBObject dbObject = (DBObject) JSON.parse(gs.toJson(ff));
|
164 |
DBObject dbObject = (DBObject) JSON.parse(gson.toJson(ff));
|
| 151 |
collection.save(dbObject);
|
165 |
collection.save(dbObject);
|
| 152 |
}
|
166 |
}
|
| 153 |
|
167 |
|
| 154 |
public List<FofoForm> getFofoForms(int offset, int limit) {
|
168 |
public List<FofoForm> getFofoForms(int offset, int limit) {
|
| 155 |
List<FofoForm> ffList = new ArrayList<FofoForm>();
|
169 |
List<FofoForm> ffList = new ArrayList<FofoForm>();
|