use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class EmailProcessApi method get.
@Get
public GenericResponse get(GenericRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
RtdbAccessor rtdbAccessor = DataAccessorFactory.getRtdbAccessor();
Map<Long, UserPreferenceRtdb> userPreferences = null;
List<Email> emailList = new ArrayList<>();
DataListIterator<Email> it = dataAccessor.getEmailListIteratorForStatePending(null, false);
Set<Long> userIds = new HashSet<>();
while (it.hasNext()) {
Email email = it.next();
emailList.add(email);
userIds.add(email.getUserId());
}
userPreferences = rtdbAccessor.getUserPreferences(userIds);
Map<Long, User> users = dataAccessor.getUsers(userPreferences.keySet());
// Re-scheduling for all Emails
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss z");
dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
for (Email email : emailList) {
UserPreferenceRtdb preference = userPreferences.get(email.getUserId());
User user = users.get(email.getUserId());
if (email.getScheduledDate().before(new Date()))
continue;
if (email.getScheduledDate().equals(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate())))
continue;
email.setScheduledDate(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate()));
email.setLastUpdated(new Date());
if (email.getScheduledDate() == null) {
// User changed setting to NEVER -> Scheduled Date will be null
email.setState(EmailState.DROPPED);
} else {
logger.log(Level.INFO, "Rescheduling email: " + email.getId() + " from " + dateFormat.format(email.getScheduledDate()) + " to " + dateFormat.format(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate())));
}
}
// Creating Tasks
List<Task> taskList = new ArrayList<>();
Set<Long> userIdTaskSet = new HashSet<>();
for (Email email : emailList) {
if (// User changed setting to NEVER -> Email Dropped
email.getState() != EmailState.PENDING)
continue;
if (email.getScheduledDate().after(new Date()))
continue;
UserPreferenceRtdb preference = userPreferences.get(email.getUserId());
if (preference.getEmailFrequency() == EmailFrequency.IMMEDIATELY)
taskList.add(TaskQueueFactory.newTask().setUrl("/email/process").addParam("emailId", email.getId().toString()));
else
userIdTaskSet.add(email.getUserId());
email.setState(EmailState.IN_PROGRESS);
email.setLastUpdated(new Date());
}
for (Long userId : userIdTaskSet) taskList.add(TaskQueueFactory.newTask().setUrl("/email/process").addParam("userId", userId.toString()));
TaskQueueFactory.getEmailHpTaskQueue().addAll(taskList);
emailList = dataAccessor.createOrUpdateEmailList(emailList);
return new GenericResponse();
}
use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class EcsContentApi method get.
@Get
public GenericResponse get(GetRequest request) throws InvalidArgumentException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(request.pratilipiId);
if (pratilipi != null && pratilipi.getState() == PratilipiState.DELETED)
throw new InvalidArgumentException("Deleted pratilipiId");
return new GetResponse(request.pratilipiId, PratilipiDocUtil._validateChapterIdInContent(request.pratilipiId));
}
use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class AuthorListByReadCountApi method get.
@Get
public GetResponse get(GetRequest request) throws UnexpectedServerException {
DataListCursorTuple<AuthorByReadCountData> dataListCursorTuple = AuthorDataUtil.getAuthorListByReadCount(request.getLanguage(), request.getResultCount(), request.getCursor());
if (dataListCursorTuple == null) {
Logger.getLogger(AuthorListByReadCountApi.class.getSimpleName()).log(Level.INFO, "DB returned null cursor tuple");
throw new UnexpectedServerException();
}
Date date = AppPropertyUtil.getTopAuthorLoadDate();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Logger.getLogger(AuthorListByReadCountApi.class.getSimpleName()).log(Level.INFO, "Date : " + dateFormat.format(date));
return new GetResponse(dataListCursorTuple.getDataList(), dateFormat.format(date), dataListCursorTuple.getCursor());
}
use of com.pratilipi.api.annotation.Get in project pratilipi by Pratilipi.
the class AuthorProcessApi method get.
@Get
public GenericResponse get(GenericRequest request) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Fetching AppProperty
String appPropertyId = "Api.AuthorProcess.ValidateData";
AppProperty appProperty = dataAccessor.getAppProperty(appPropertyId);
if (appProperty == null) {
appProperty = dataAccessor.newAppProperty(appPropertyId);
appProperty.setValue(new Date(0));
}
// Fetching list of author ids.
AuthorFilter authorFilter = new AuthorFilter();
authorFilter.setMinLastUpdate((Date) appProperty.getValue(), false);
List<Long> authorIdList = dataAccessor.getAuthorIdList(authorFilter, null, 10000).getDataList();
// Updating AppProperty.
if (authorIdList.size() > 0) {
appProperty.setValue(dataAccessor.getAuthor(authorIdList.get(authorIdList.size() - 1)).getLastUpdated());
appProperty = dataAccessor.createOrUpdateAppProperty(appProperty);
}
return new GenericResponse();
}
Aggregations