| Line 7... |
Line 7... |
| 7 |
import com.mongodb.client.MongoCollection;
|
7 |
import com.mongodb.client.MongoCollection;
|
| 8 |
import com.mongodb.client.MongoDatabase;
|
8 |
import com.mongodb.client.MongoDatabase;
|
| 9 |
import com.mongodb.util.JSON;
|
9 |
import com.mongodb.util.JSON;
|
| 10 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
10 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
| 11 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
11 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
| - |
|
12 |
import com.spice.profitmandi.dao.model.external.CatalogContentModel;
|
| 12 |
import com.spice.profitmandi.dao.model.FofoForm;
|
13 |
import com.spice.profitmandi.dao.model.FofoForm;
|
| 13 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
14 |
import com.spice.profitmandi.dao.model.RetailerFofoInterest;
|
| 14 |
import org.apache.logging.log4j.LogManager;
|
15 |
import org.apache.logging.log4j.LogManager;
|
| 15 |
import org.apache.logging.log4j.Logger;
|
16 |
import org.apache.logging.log4j.Logger;
|
| 16 |
import org.bson.Document;
|
17 |
import org.bson.Document;
|
| Line 98... |
Line 99... |
| 98 |
}
|
99 |
}
|
| 99 |
cursor.close();
|
100 |
cursor.close();
|
| 100 |
return result;
|
101 |
return result;
|
| 101 |
}
|
102 |
}
|
| 102 |
|
103 |
|
| - |
|
104 |
/**
|
| - |
|
105 |
* siteContent docs for the /external catalogMaster feed, ordered by _id.
|
| - |
|
106 |
* sinceMillis == null: all docs. Otherwise docs whose lastModified >= since
|
| - |
|
107 |
* OR that have no lastModified yet (pre-backfill docs stay visible).
|
| - |
|
108 |
*/
|
| - |
|
109 |
public List<CatalogContentModel> getSiteContentPage(Long sinceMillis, int offset, int limit) {
|
| - |
|
110 |
List<CatalogContentModel> result = new ArrayList<>();
|
| - |
|
111 |
DB db = contentMongoClient.getDB(CONTENT);
|
| - |
|
112 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| - |
|
113 |
DBCursor cursor = collection.find(siteContentSinceFilter(sinceMillis))
|
| - |
|
114 |
.sort(new BasicDBObject("_id", 1)).skip(offset).limit(limit);
|
| - |
|
115 |
while (cursor.hasNext()) {
|
| - |
|
116 |
DBObject doc = cursor.next();
|
| - |
|
117 |
try {
|
| - |
|
118 |
long docId = ((Number) doc.get("_id")).longValue();
|
| - |
|
119 |
// read directly off the doc: NumberLong renders as {"$numberLong":...}
|
| - |
|
120 |
// in toJson, which gson cannot map onto a Long field
|
| - |
|
121 |
Object lastModified = doc.get("lastModified");
|
| - |
|
122 |
ContentPojo cp = gson.fromJson(new BasicDBObject(doc.toMap()).toJson(), ContentPojo.class);
|
| - |
|
123 |
if (cp.getDefaultImageUrl() != null) {
|
| - |
|
124 |
cp.setDefaultImageUrl(cp.getDefaultImageUrl().replaceAll("saholic", "smartdukaan"));
|
| - |
|
125 |
}
|
| - |
|
126 |
result.add(new CatalogContentModel(docId,
|
| - |
|
127 |
lastModified == null ? null : ((Number) lastModified).longValue(), cp));
|
| - |
|
128 |
} catch (Exception e) {
|
| - |
|
129 |
// skip malformed entries
|
| - |
|
130 |
}
|
| - |
|
131 |
}
|
| - |
|
132 |
cursor.close();
|
| - |
|
133 |
return result;
|
| - |
|
134 |
}
|
| - |
|
135 |
|
| - |
|
136 |
public long countSiteContent(Long sinceMillis) {
|
| - |
|
137 |
DB db = contentMongoClient.getDB(CONTENT);
|
| - |
|
138 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| - |
|
139 |
return collection.count(siteContentSinceFilter(sinceMillis));
|
| - |
|
140 |
}
|
| - |
|
141 |
|
| - |
|
142 |
private static DBObject siteContentSinceFilter(Long sinceMillis) {
|
| - |
|
143 |
if (sinceMillis == null) {
|
| - |
|
144 |
return new BasicDBObject();
|
| - |
|
145 |
}
|
| - |
|
146 |
List<DBObject> or = new ArrayList<>();
|
| - |
|
147 |
or.add(new BasicDBObject("lastModified", new BasicDBObject("$gte", sinceMillis)));
|
| - |
|
148 |
or.add(new BasicDBObject("lastModified", new BasicDBObject("$exists", false)));
|
| - |
|
149 |
return new BasicDBObject("$or", or);
|
| - |
|
150 |
}
|
| - |
|
151 |
|
| 103 |
public ContentPojo getEntityByName(String name) throws Exception {
|
152 |
public ContentPojo getEntityByName(String name) throws Exception {
|
| 104 |
//LOGGER.info("Name --- {}", name);
|
153 |
//LOGGER.info("Name --- {}", name);
|
| 105 |
DB db = contentMongoClient.getDB(CONTENT);
|
154 |
DB db = contentMongoClient.getDB(CONTENT);
|
| 106 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
155 |
DBCollection collection = db.getCollection(SITE_CONTENT);
|
| 107 |
BasicDBObject obj = new BasicDBObject();
|
156 |
BasicDBObject obj = new BasicDBObject();
|
| Line 122... |
Line 171... |
| 122 |
|
171 |
|
| 123 |
private static <T> void insertOrUpdateById(DBCollection collection, long id, T obj) {
|
172 |
private static <T> void insertOrUpdateById(DBCollection collection, long id, T obj) {
|
| 124 |
DBObject dbo = BasicDBObject.parse(gson.toJson(obj));
|
173 |
DBObject dbo = BasicDBObject.parse(gson.toJson(obj));
|
| 125 |
LOGGER.info("dbo {}", dbo);
|
174 |
LOGGER.info("dbo {}", dbo);
|
| 126 |
dbo.put("_id", id);
|
175 |
dbo.put("_id", id);
|
| - |
|
176 |
// full-document replace below, so the delta-sync marker must be (re)stamped here
|
| - |
|
177 |
dbo.put("lastModified", System.currentTimeMillis());
|
| 127 |
Object result = collection.update(new BasicDBObject("_id", id), dbo, true, false);
|
178 |
Object result = collection.update(new BasicDBObject("_id", id), dbo, true, false);
|
| 128 |
LOGGER.info("result mongo {}", result);
|
179 |
LOGGER.info("result mongo {}", result);
|
| 129 |
}
|
180 |
}
|
| 130 |
|
181 |
|
| 131 |
public JSONObject getItemsByBundleId(long bundleId) throws Exception {
|
182 |
public JSONObject getItemsByBundleId(long bundleId) throws Exception {
|