use of com.pratilipi.data.type.UserPreferenceRtdb in project pratilipi by Pratilipi.
the class AuditLogProcessApi method _updateEmailTable.
private void _updateEmailTable(List<Email> emailList) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Set<Long> userIds = new HashSet<>(emailList.size());
for (Email email : emailList) userIds.add(email.getUserId());
Map<Long, UserPreferenceRtdb> userPreferenceMap = DataAccessorFactory.getRtdbAccessor().getUserPreferences(userIds);
Map<Long, User> users = dataAccessor.getUsers(userIds);
List<Email> emailsToUpdate = new ArrayList<>(emailList.size());
for (Email email : emailList) {
UserPreferenceRtdb preference = userPreferenceMap.get(email.getUserId());
User user = users.get(email.getUserId());
if (user.getEmail() == null)
continue;
if (preference.getEmailFrequency() == EmailFrequency.NEVER)
continue;
email.setScheduledDate(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate()));
emailsToUpdate.add(email);
}
emailsToUpdate = dataAccessor.createOrUpdateEmailList(emailsToUpdate);
}
use of com.pratilipi.data.type.UserPreferenceRtdb in project pratilipi by Pratilipi.
the class RtdbAccessorFirebaseImpl method getUserPreferences.
@Override
public Map<Long, UserPreferenceRtdb> getUserPreferences(Collection<Long> userIds) throws UnexpectedServerException {
if (userIds == null || userIds.isEmpty())
return new HashMap<>();
userIds = new HashSet<>(userIds);
List<String> targetUrlList = new ArrayList<>(userIds.size());
for (Long userId : userIds) targetUrlList.add(_getUserPreferenceDbUrl(userId));
Map<String, BlobEntry> blobEntries = HttpUtil.doGet(targetUrlList, headersMap);
Map<Long, UserPreferenceRtdb> userPreferences = new HashMap<>(userIds.size());
try {
for (Long userId : userIds) {
BlobEntry blobEntry = blobEntries.get(_getUserPreferenceDbUrl(userId));
String jsonStr = new String(blobEntry.getData(), "UTF-8");
userPreferences.put(userId, _getUserPreferenceRtdb(jsonStr));
}
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, "Failed to parse response from Firebase.", e);
throw new UnexpectedServerException();
}
return userPreferences;
}
use of com.pratilipi.data.type.UserPreferenceRtdb in project pratilipi by Pratilipi.
the class RtdbAccessorWithMemcache method getUserPreferences.
@Override
public Map<Long, UserPreferenceRtdb> getUserPreferences(Collection<Long> userIds) throws UnexpectedServerException {
if (userIds == null || userIds.isEmpty())
return new HashMap<>();
userIds = new HashSet<>(userIds);
Set<String> memcacheIds = new HashSet<>(userIds.size());
for (Long userId : userIds) memcacheIds.add(_getUserPreferenceMemcacheId(userId));
Map<String, UserPreferenceRtdb> userPrefs = memcache.getAll(memcacheIds);
Map<Long, UserPreferenceRtdb> userPreferences = new HashMap<>(userIds.size());
List<Long> missingUserIdList = new ArrayList<>();
for (Long userId : userIds) {
UserPreferenceRtdb userPref = userPrefs.get(_getUserPreferenceMemcacheId(userId));
if (userPref != null)
userPreferences.put(userId, userPref);
else
missingUserIdList.add(userId);
}
if (!missingUserIdList.isEmpty()) {
Map<Long, UserPreferenceRtdb> missingUserPreferences = rtdbAccessor.getUserPreferences(missingUserIdList);
userPreferences.putAll(missingUserPreferences);
Map<String, UserPreferenceRtdb> missingUserPrefs = new HashMap<>(missingUserIdList.size());
for (Long userId : missingUserIdList) missingUserPrefs.put(_getUserPreferenceMemcacheId(userId), missingUserPreferences.get(userId));
memcache.putAll(missingUserPrefs, expirationDeltaMinutes);
}
return userPreferences;
}
use of com.pratilipi.data.type.UserPreferenceRtdb in project pratilipi by Pratilipi.
the class RtdbAccessorFirebaseImpl method _getUserPreferences.
private Map<Long, UserPreferenceRtdb> _getUserPreferences(Map<String, String> paramsMap) throws UnexpectedServerException {
try {
BlobEntry blobEntry = HttpUtil.doGet(_getUserPreferenceDbUrl(), headersMap, paramsMap);
String jsonStr = new String(blobEntry.getData(), "UTF-8");
JsonObject json = new Gson().fromJson(jsonStr, JsonElement.class).getAsJsonObject();
Map<Long, UserPreferenceRtdb> userPreferenceMap = new HashMap<>();
for (Entry<String, JsonElement> entry : json.entrySet()) userPreferenceMap.put(Long.parseLong(entry.getKey()), _getUserPreferenceRtdb(entry.getValue().getAsJsonObject()));
return userPreferenceMap;
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, e.getMessage());
throw new UnexpectedServerException();
}
}
use of com.pratilipi.data.type.UserPreferenceRtdb in project pratilipi by Pratilipi.
the class RtdbAccessorWithMemcache method getUserPreference.
// PREFERENCE Table
@Override
public UserPreferenceRtdb getUserPreference(Long userId) throws UnexpectedServerException {
if (userId == null)
return null;
UserPreferenceRtdb userPref = memcache.get(_getUserPreferenceMemcacheId(userId));
if (userPref == null) {
userPref = rtdbAccessor.getUserPreference(userId);
memcache.put(_getUserPreferenceMemcacheId(userId), userPref, expirationDeltaMinutes);
}
return userPref;
}
Aggregations