Subversion Repositories SmartDukaan

Rev

Rev 35527 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35527 Rev 36437
Line 17... Line 17...
17
import org.json.JSONObject;
17
import org.json.JSONObject;
18
 
18
 
19
import java.lang.reflect.Type;
19
import java.lang.reflect.Type;
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Arrays;
21
import java.util.Arrays;
-
 
22
import java.util.HashMap;
22
import java.util.List;
23
import java.util.List;
23
import java.util.Map;
24
import java.util.Map;
24
 
25
 
25
public class Mongo {
26
public class Mongo {
26
 
27
 
Line 73... Line 74...
73
        //LOGGER.info("cp" + cp);
74
        //LOGGER.info("cp" + cp);
74
 
75
 
75
        return cp;
76
        return cp;
76
    }
77
    }
77
 
78
 
-
 
79
    public Map<Long, ContentPojo> getEntitiesByIds(List<Long> ids) {
-
 
80
        Map<Long, ContentPojo> result = new HashMap<>();
-
 
81
        if (ids == null || ids.isEmpty()) return result;
-
 
82
        DB db = contentMongoClient.getDB(CONTENT);
-
 
83
        DBCollection collection = db.getCollection(SITE_CONTENT);
-
 
84
        BasicDBObject query = new BasicDBObject("_id", new BasicDBObject("$in", ids));
-
 
85
        DBCursor cursor = collection.find(query);
-
 
86
        while (cursor.hasNext()) {
-
 
87
            DBObject doc = cursor.next();
-
 
88
            try {
-
 
89
                long docId = ((Number) doc.get("_id")).longValue();
-
 
90
                ContentPojo cp = gson.fromJson(new BasicDBObject(doc.toMap()).toJson(), ContentPojo.class);
-
 
91
                if (cp.getDefaultImageUrl() != null) {
-
 
92
                    cp.setDefaultImageUrl(cp.getDefaultImageUrl().replaceAll("saholic", "smartdukaan"));
-
 
93
                }
-
 
94
                result.put(docId, cp);
-
 
95
            } catch (Exception e) {
-
 
96
                // skip malformed entries
-
 
97
            }
-
 
98
        }
-
 
99
        cursor.close();
-
 
100
        return result;
-
 
101
    }
-
 
102
 
78
    public ContentPojo getEntityByName(String name) throws Exception {
103
    public ContentPojo getEntityByName(String name) throws Exception {
79
        //LOGGER.info("Name --- {}", name);
104
        //LOGGER.info("Name --- {}", name);
80
        DB db = contentMongoClient.getDB(CONTENT);
105
        DB db = contentMongoClient.getDB(CONTENT);
81
        DBCollection collection = db.getCollection(SITE_CONTENT);
106
        DBCollection collection = db.getCollection(SITE_CONTENT);
82
        BasicDBObject obj = new BasicDBObject();
107
        BasicDBObject obj = new BasicDBObject();