Package com.metadot.book.connectr.server.domain

Examples of com.metadot.book.connectr.server.domain.UserAccount


public class UserNotifServlet extends HttpServlet {
 
  private static Logger logger = Logger.getLogger(UserNotifServlet.class.getName());
 
  private UserAccount getUserAccount(String userId, PersistenceManager pm) {
    UserAccount userPrefs = null;
    Query q = null;
    try {
      q = pm.newQuery(UserAccount.class, "uniqueId == :uniqueId");
      q.setRange(0,1);
      @SuppressWarnings("unchecked") List<UserAccount> results = (List<UserAccount>) q.execute(userId);
View Full Code Here


  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());
        }
      }
    }
View Full Code Here

    try {
      // do this operation under transactional control
      for (int i = 0; i < NUM_RETRIES; i++) {
        pm.currentTransaction().begin();

        UserAccount currentUser = LoginHelper.getLoggedInUser(getThreadLocalRequest().getSession(), pm);

        friend = new Friend(friendDTO);
        currentUser.getFriends().add(friend);
        pm.makePersistent(currentUser);
        fid = friend.getId();
       
        if (!(friendDTO.getUrls().isEmpty())) {
          // build task payload:
View Full Code Here

    ArrayList<FriendSummaryDTO> friendsSummaries = new ArrayList<FriendSummaryDTO>();
    PersistenceManager pm = PMF.getNonTxnPm();

    try {
      UserAccount user = LoginHelper.getLoggedInUser(getThreadLocalRequest().getSession(), pm);
      if (user == null)
        return null;

      Set<Friend> friends = user.getFriends();
      for (Friend friend : friends) {
        friendsSummaries.add(friend.toLightWeightDTO());
      }
    } finally {
      pm.close();
View Full Code Here

       */
      String url = "https://graph.facebook.com/me?access_token=" + token;
      log.info("requesting user info: " + url);
      resp = UrlFetcher.get(url);
      log.info("Response: " + resp);
      UserAccount connectr = extractUserInfo(resp);
      connectr = new LoginHelper()
          .loginStarts(request.getSession(), connectr);
      log.info("User id is logged in:" + connectr.getId().toString());

      /*
       * All done. Let's go home.
       */
      response.sendRedirect(LoginHelper.getApplitionURL(request));
View Full Code Here

  }

  private UserAccount extractUserInfo(String resp) {
    log.info("Extracting user info");
    JSONObject j;
    UserAccount u = null;
    try {
      j = new JSONObject(resp);
      String first = j.getString("first_name");
      String last = j.getString("last_name");
      String id = j.getString("id");
      log.info("User info from JSON: " + first + " " + last + " id = "
          + id);
      u = new UserAccount(id, AuthenticationProvider.FACEBOOK);
      u.setName(first + " " + last);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return u;
  }
View Full Code Here

 
  /**
   * return a UserAccount object given its id
   */
  private UserAccount getUserAccount(String userId, PersistenceManager pm) {
    UserAccount userPrefs = null;
    Query q = null;
    try {
      q = pm.newQuery(UserAccount.class, "uniqueId == :uniqueId");
      q.setRange(0,1);
      @SuppressWarnings("unchecked")
View Full Code Here

  throws IOException {

    PersistenceManager pm = PMF.get().getPersistenceManager();
    String userId = req.getParameter("uid");
    String notify = req.getParameter("notify");
    UserAccount userPrefs = null;
    try {
      userPrefs = getUserAccount(userId, pm);
      if (userPrefs != null) {
        Set<Friend> friends = userPrefs.getFriends();
        // get the default queue
        Queue queue = QueueFactory.getQueue("userfeedupdates");
        for (Friend fr : friends ){
          // spawn off tasks to fetch the Friend-associated urls
          queue.add(url("/feedupdatefr").param("fkey", fr.getId()));
          // logger.fine("queueing for " + fr.getId());
        }
        if (notify != null && notify.equalsIgnoreCase("true") && ChannelServer.channelAPIEnabled()) {
          // now add task, to run later, to see if a notification needs to be sent for that user.
          queue.add(url("/usernotif").param("uniqueid", userPrefs.getUniqueId()).countdownMillis(1000 * DELAY));
          logger.info("queueing usernotif for " + userPrefs.getUniqueId());
        }
      }
    }
    finally {
      pm.close();
View Full Code Here

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    Principal googleUser = request.getUserPrincipal();
    if (googleUser != null) {
      // update or create user
      UserAccount u = new UserAccount(googleUser.getName(),  AuthenticationProvider.GOOGLE);
      u.setName(googleUser.getName());
      UserAccount connectr = new LoginHelper().loginStarts(request.getSession(), u);
 
      log.info("User id:" + connectr.getId().toString() + " " + request.getUserPrincipal().getName());
    }
    response.sendRedirect(LoginHelper.getApplitionURL(request));
  }
View Full Code Here

      return;
    }
   
    HttpSession session = req.getSession();
    PersistenceManager pm = PMF.get().getPersistenceManager();
    UserAccount user = LoginHelper.getLoggedInUser(session, pm);

    logger.info("trying to push a message to channel: " + user.getChannelId());
    ChannelServer.pushMessage(user, new ChannelTextMessage("Hello from push"));
  }
View Full Code Here

TOP

Related Classes of com.metadot.book.connectr.server.domain.UserAccount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.