}
@Override
public JUser readDoc(String idAsStr, long version, Map<String, Object> doc) {
String userName = idAsStr;
JUser user = new JUser(userName);
if (doc.get(TWITTER_ID) != null)
user.setTwitterId(((Number) doc.get(TWITTER_ID)).longValue());
Boolean active = (Boolean) doc.get(ACTIVE);
if (active == null)
user.setActive(true);
else
user.setActive(active);
user.setRealName((String) doc.get("realName"));
user.setProfileImageUrl((String) doc.get("iconUrl"));
user.setWebUrl((String) doc.get("webUrl"));
user.setDescription((String) doc.get("bio"));
user.setTwitterToken((String) doc.get(TOKEN));
user.setTwitterTokenSecret((String) doc.get("tokenSecret_s"));
user.setMode((String) doc.get("mode"));
Collection<Map<String, Object>> topics = ((Collection<Map<String, Object>>) doc.get(TOPICS));
if (topics != null)
for (Map t : topics) {
Date date = Helper.toDateNoNPE((String) t.get("lastRead"));
user.updateTopic((String) t.get("name"), date);
}
if (doc.get("protected") != null)
user.setProtected((Boolean) doc.get("protected"));
if (doc.get("weekFallback") != null)
user.setWeekFallback((Boolean) doc.get("weekFallback"));
user.setLastVisit(Helper.toDateNoNPE((String) doc.get(LAST_VISIT_DT)));
user.setCreatedAt(Helper.toDateNoNPE((String) doc.get(CREATED_DT)));
user.setTwitterCreatedAt(Helper.toDateNoNPE((String) doc.get("twCreatedAt_dt")));
user.setLastFriendsUpdate(Helper.toDateNoNPE((String) doc.get("friendsUpdate_dt")));
user.setFriends((Collection<String>) doc.get("friends"));
if (doc.get("followersCount") != null)
user.setFollowersCount(((Number) doc.get("followersCount")).intValue());
if (doc.get("friendsCount") != null)
user.setFriendsCount(((Number) doc.get("friendsCount")).intValue());
if (doc.get("role") != null)
user.setRole((String) doc.get("role"));
user.setEmail((String) doc.get(EMAIL));
long counter = 1;
while (true) {
String qString = (String) doc.get("ss_" + counter + "_query_s");
if (qString == null)
// backward compatibility
break;
TweetQuery q = TweetQuery.parseQuery(qString);
SavedSearch ss = new SavedSearch(counter, q);
ss.setLastQueryDate(Helper.toDateNoNPE((String) doc.get("ss_" + counter + "_last_dt")));
user.addSavedSearch(ss);
counter++;
}
// only used for facet search? doc.get("lang");
Collection<Object> tags = (Collection<Object>) doc.get("tag");
if (tags != null)
for (Object tag : tags) {
user.addTag((String) tag);
}
Collection<Object> langs = (Collection<Object>) doc.get("lang");
if (langs != null)
for (Object lang : langs) {
user.addLanguage((String) lang);
}
return user;
}