private void listMessages(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setCharacterEncoding("UTF-8"); if (!IrssiNotifier.versionCheck(req.getParameter("version"))) { IrssiNotifier.printError(resp.getWriter(), new OldVersionException()); return; } String id = req.getParameter("apiToken"); String guid = req.getParameter("guid"); if (id == null || guid == null || id.equals("") || guid.equals("")) { IrssiNotifier.printError(resp.getWriter(), "Virheellinen pyyntö"); return; } ObjectifyDAO dao = new ObjectifyDAO(); try { IrssiNotifierUser user = IrssiNotifier.getUser(dao, id); Query<Message> messages = dao.ofy().query(Message.class).order("-timestamp").ancestor(user).limit(LIMIT + 1); String starting = req.getParameter("starting"); if (starting != null) { try { long startingTimestamp = Long.parseLong(starting); messages = messages.filter("timestamp <=", startingTimestamp); } catch (NumberFormatException e) { } } Message next = null; if (messages.count() == LIMIT + 1) { IrssiNotifier.log.info("Lisää viestejä on saatavilla"); next = messages.list().get(LIMIT); } else { IrssiNotifier.log.info("Sisältää viestihistorian viimeiset viestit"); } MessageListResponse response = new MessageListResponse(messages.limit(LIMIT)); response.nextMessage = next; response.isNextFetch = starting != null; JSONSerializer serializer = new JSONSerializer(); String jsonObject = serializer .include("messages") .transform(new CustomTimeTransformer(), "messages.timestamp") .transform(new CustomTimeTransformer(), "nextMessage.timestamp") .exclude("*.class") .serialize(response); resp.setHeader("Content-Type", "application/json"); resp.getWriter().println(jsonObject); resp.getWriter().close(); } catch (UserNotFoundException e) { IrssiNotifier.printError(resp.getWriter(), e); } }
public ApplicationUser getByEMail(String email) { try { Query<ApplicationUser> query = ofy().query(ApplicationUser.class); // query.ancestor(companyKey); ApplicationUser user = query.filter("email", email).get(); return user; } catch (Exception e) { LOG.error("Cannot get ApplicationUser by email(" + email + ")", e); return null; } }
// FIXME: not working int countUsersActiveInLastNDays(DatastoreService ds, int numDays) { com.googlecode.objectify.Query<User> q = ofy().query(User.class); if (numDays > 0) { // This is ridiculous, but 30 days in milliseconds is 2.5B, and if numDays is // in int, the expression below overflows and we look for // lastSeen > some-future-date. To fix, just cast it to a long. long numDays64Bit = numDays; q.filter( "lastSeen >", new Date(System.currentTimeMillis() - numDays64Bit * 24 * 60 * 60 * 1000)); } return q.count(); }
public ArrayList<Model> Raffle(String accessToken, String eid) { Dao dao = new Dao(); Random r = new Random(); Query<VoteDetails> qRaffle = dao.ofy().query(VoteDetails.class); List<VoteDetails> droppers = qRaffle.filter("eid", eid).list(); VoteDetails winner = droppers.get(r.nextInt(droppers.size() - 1)); return Profile.GetFacebookProfileInfo(accessToken, winner.uid); }