public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
PersistenceManager pm = PMF.get().getPersistenceManager();
String userId = req.getParameter("uniqueid");
UserAccount user = null;
Query q = null;
if (!ChannelServer.channelAPIEnabled()) {
return;
}
try {
user = getUserAccount(userId, pm);
logger.info("in UserNotifServlet doPost for user " + user.getId());
if (user != null) {
// see if there exist any stream items associated with that user, newer than the lastReported date
q = pm.newQuery(StreamItem.class, "date > :d1 && ukeys == :u1");
q.setOrdering("date desc");
q.setRange(0, 1);
@SuppressWarnings("unchecked")
List<StreamItem> sitems = (List<StreamItem>) q.execute(user.getLastReported(), user.getId());
if (sitems.iterator().hasNext()) {
// if so (if newer), call pushMessage to trigger the 'push' of the new content notification
StreamItem sitem = sitems.iterator().next();
user.setLastReported(sitem.getDate());
logger.info("pushing 'new content' notification");
ChannelServer.pushMessage(user, new ContentAvailableMessage());
}
}
}