Examples of UserSession


Examples of com.google.gsa.sessions.UserSession

    public UserSession createUserSession(String userName,
                                         long sessionCreationTime,
                                         Credentials userCredentials,
                                         Cookie[] cookies) {

        UserSession userSession = null;

        try {
            userSession =
                    new UserSession(userName, sessionCreationTime, userCredentials,
                                    cookies);
        } catch (Exception ex) {
            logger.error("Error during the instatiation of the User Session: " +
                         ex);
        } finally {
View Full Code Here

Examples of com.google.ytd.model.UserSession

      }
      if (util.isNullOrEmpty(description)) {
        throw new IllegalArgumentException("'description' parameter is null or empty.");
      }

      UserSession userSession = userSessionManager.getUserSession(req);
      if (userSession == null) {
        // TODO: Throw a better Exception class here.
        throw new IllegalArgumentException("No user session found.");
      }
      String authSubToken = userSession.getMetaData("authSubToken");
     
      // Assignment id might be set in the JSON object if there wasn't an assignment associated
      // with the embedded iframe, and the assignment was chosen at run time.
      if (util.isNullOrEmpty(assignmentId)) {
        assignmentId = userSession.getMetaData("assignmentId");
      } else {
        userSession.addMetaData("assignmentId", assignmentId);
      }
     
      Assignment assignment = assignmentDao.getAssignmentById(assignmentId);
      if (assignment == null) {
        throw new IllegalArgumentException(String.format(
            "Could not find an assignment with id '%s'.", assignmentId));
      }
      AssignmentStatus status = assignment.getStatus();
      if (status != AssignmentStatus.ACTIVE) {
        throw new IllegalArgumentException(String.format(
            "Could not add a video to a non ACTIVE assignment. "
                + "Current status of assignment id '%s' is '%s'.", assignmentId, status));
      }

      // Max title length is 60 characters or 100 bytes.
      if (title.length() > 60) {
        title = title.substring(0, 59);
      }

      VideoEntry newEntry = new VideoEntry();
      YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();

      mg.setTitle(new MediaTitle());
      mg.getTitle().setPlainTextContent(title);

      mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, assignment.getCategory()));

      mg.setKeywords(new MediaKeywords());

      List<String> tags = new ArrayList<String>();
      for (int i = 0; i < tagsArray.length(); i++) {
        String tag = tagsArray.getString(i).trim();
        mg.getKeywords().addKeyword(tag);
        tags.add(tag);
      }

      // Sort the list of tags and join with "," so that we can easily compare
      // what's in the
      // datastore with what we get back from the YouTube API.
      String sortedTags = util.sortedJoin(tags, ",");

      mg.setDescription(new MediaDescription());
      mg.getDescription().setPlainTextContent(description);

      String applicationNameTag = Util.CLIENT_ID_PREFIX + SystemProperty.applicationId.get();
      if (applicationNameTag.length() > 25) {
        applicationNameTag = applicationNameTag.substring(0, 24) + "!";
      }
      mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, applicationNameTag));

      // Maximum size of a developer tag is 25 characters, and we prepend 2
      // characters.
      if (assignmentId.length() <= 23) {
        // Minimum size of a developer tag is 3 characters, so always append 2
        // characters.
        String assignmentIdTag = String.format("A-%s", assignmentId);

        // Use a developer tag to make it easy for developers to query for all
        // videos uploaded for
        // a given assignment.
        mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, assignmentIdTag));
      } else {
        log.warning(String.format("Assignment id '%s' is longer than 25 characters, and can't be "
            + "used as a developer tag.", assignmentId));
      }
     
      if (jsonObj.has("latitude") && jsonObj.has("longitude")) {
        newEntry.setGeoCoordinates(new GeoRssWhere(jsonObj.getDouble("latitude"),
            jsonObj.getDouble("longitude")));
      } else if (!util.isNullOrEmpty(location)) {
        newEntry.setLocation(location);
      }

      userSession.addMetaData("videoTitle", title);
      userSession.addMetaData("videoDescription", description);
      userSession.addMetaData("videoLocation", location);
      userSession.addMetaData("phoneNumber", phoneNumber);
      userSession.addMetaData("videoDate", date);
      userSession.addMetaData("videoTags", sortedTags);
      userSession.addMetaData("email", email);
      userSessionManager.save(userSession);

      youTubeApi.setAuthSubToken(authSubToken);

      FormUploadToken token = youTubeApi.getFormUploadToken(newEntry);
View Full Code Here

Examples of com.google.ytd.model.UserSession

  }

  public UserSession save(UserSession session) {
    String oldNamespace = NamespaceManager.get();
    NamespaceManager.set("");
    UserSession userSession = (UserSession) pmfUtil.persistJdo(session);
    NamespaceManager.set(oldNamespace);
    return userSession;
  }
View Full Code Here

Examples of com.google.ytd.model.UserSession

    NamespaceManager.set(oldNamespace);
  }

  @SuppressWarnings("unchecked")
  public UserSession getUserSession(HttpServletRequest request) {
    UserSession userSession = null;

    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
      for (Cookie cookie : cookies) {
        if (USER_SESSION_ID_NAME.equals(cookie.getName())) {
View Full Code Here

Examples of com.google.ytd.model.UserSession

  public UserSession getUserSessionById(String id) {
    String oldNamespace = NamespaceManager.get();
    NamespaceManager.set("");
   
    PersistenceManager pm = pmf.getPersistenceManager();
    UserSession userSession = null;

    String filters = "id == id_";
    Query query = pm.newQuery(UserSession.class, filters);
    query.declareParameters("String id_");
    List<UserSession> list = (List<UserSession>) query.executeWithArray(new Object[] { id });
View Full Code Here

Examples of com.google.ytd.model.UserSession

      }

      PrivateKey privateKey = adminConfigDao.getPrivateKey();
      String authSubToken = AuthSubUtil.exchangeForSessionToken(token, privateKey);

      UserSession userSession = userSessionManager.getUserSession(request);

      if (userSession == null) {
        // TODO: Throw a better Exception class here.
        throw new IllegalArgumentException("No user session found.");
      }

      // userSession.setAuthSubToken(authSubToken);
      userSession.addMetaData("authSubToken", authSubToken);

      youTubeApiHelper.setAuthSubToken(authSubToken);

      String youTubeName = youTubeApiHelper.getCurrentUsername();
      if (util.isNullOrEmpty(youTubeName)) {
        // TODO: Throw a better Exception class here.
        throw new IllegalArgumentException("Unable to retrieve a YouTube username for "
            + "the authenticated user.");
      }
      userSession.addMetaData("youTubeName", youTubeName);
      userSessionManager.save(userSession);

      // Create or update the UserAuthToken entry, which maps a username to an AuthSub token.
      userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);

      response.sendRedirect(articleUrl + "#return-sessionId-" + userSession.getId());
    } catch (ServiceException e) {
      log.log(Level.WARNING, "", e);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (IllegalArgumentException e) {
      log.log(Level.WARNING, "", e);
View Full Code Here

Examples of com.google.ytd.model.UserSession

      if (videoIds.length() < 1) {
        throw new IllegalArgumentException("No video ids were provided.");
      }

      // Grab user session meta data
      UserSession userSession = userSessionManager.getUserSession(req);
      String youTubeName = userSession.getMetaData("youTubeName");
      String authSubToken = userSession.getMetaData("authSubToken");
      String articleUrl = userSession.getMetaData("articleUrl");

      // Assignment id might be set in the JSON object if there wasn't an assignment associated
      // with the embedded iframe, and the assignment was chosen at run time.
      if (util.isNullOrEmpty(assignmentId)) {
        assignmentId = userSession.getMetaData("assignmentId");
      } else {
        userSession.addMetaData("assignmentId", assignmentId);
      }
     
      apiManager.setAuthSubToken(authSubToken);

      for (int i = 0; i < videoIds.length(); i++) {
View Full Code Here

Examples of com.google.ytd.model.UserSession

    // TODO(austinchau) This request object is before the JspForwarder, the url
    // is not correct
    String selfUrl = util.getSelfUrl(request);

    if (userSession == null) {
      userSession = new UserSession();
      userSession = userSessionManager.save(userSession);
      // stick the session id as cookie
      userSessionManager.sendSessionIdCookie(userSession.getId(), response);
    }

    userSession.addMetaData("assignmentId", assignmentId);
    userSession.addMetaData("articleUrl", articleUrl);
    userSession.addMetaData("selfUrl", selfUrl);

    userSession = userSessionManager.save(userSession);

    String authSubToken = userSession.getMetaData("authSubToken");

    if (authSubToken != null) {
      // check for bad token
      if (!isTokenValid(authSubToken)) {
        log.finer(String.format("AuthSub token '%s' is invalid. Creating new session.",
            authSubToken));

        authSubToken = null;

        userSessionManager.delete(userSession);

        // replace with new session

        userSession = new UserSession();
        userSession.addMetaData("assignmentId", assignmentId);
        userSession.addMetaData("articleUrl", articleUrl);
        userSession.addMetaData("selfUrl", selfUrl);
        userSession = userSessionManager.save(userSession);
View Full Code Here

Examples of com.google.ytd.model.UserSession

  @Inject
  private UserSessionManager userSessionManager;

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserSession userSession = userSessionManager.getUserSession(req);

    // Don't revoke the AuthSub token, since that's needed for branding the
    // video after moderation.
    // If the user wants to revoke their token, they can do it from youtube.com.

    // Remove local cookie.
    userSessionManager.destroySessionIdCookie(resp);

    // Get the original URL to redirect.
    String redirectUrl = userSession.getMetaData("selfUrl");

    log.info(redirectUrl);

    // Remove the session entry.
    userSessionManager.delete(userSession);
View Full Code Here

Examples of com.google.ytd.model.UserSession

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String videoId = req.getParameter("id");
    String status = req.getParameter("status");

    UserSession userSession = userSessionManager.getUserSession(req);

    if (status.equals("200")) {
      String authSubToken = userSession.getMetaData("authSubToken");
      String articleUrl = userSession.getMetaData("articleUrl");
      String assignmentId = userSession.getMetaData("assignmentId");
      String videoTitle = userSession.getMetaData("videoTitle");
      String videoDescription = userSession.getMetaData("videoDescription");
      String youTubeName = userSession.getMetaData("youTubeName");
      String email = userSession.getMetaData("email");
      String phoneNumber = userSession.getMetaData("phoneNumber");
      String videoTags = userSession.getMetaData("videoTags");
      String videoLocation = userSession.getMetaData("videoLocation");
      String videoDate = userSession.getMetaData("videoDate");

      log.fine(String.format("Attempting to persist VideoSubmission with YouTube id '%s' "
          + "for assignment id '%s'...", videoId, assignmentId));

      VideoSubmission submission = submissionDao.newSubmission(Long.parseLong(assignmentId));

      submission.setArticleUrl(articleUrl);
      submission.setVideoId(videoId);
      submission.setVideoTitle(videoTitle);
      submission.setVideoDescription(videoDescription);
      submission.setVideoTags(videoTags);
      submission.setVideoLocation(videoLocation);
      submission.setVideoDate(videoDate);
      submission.setYouTubeName(youTubeName);
      submission.setVideoSource(VideoSubmission.VideoSource.NEW_UPLOAD);
      submission.setNotifyEmail(email);
      submission.setPhoneNumber(phoneNumber);

      userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);

      AdminConfig adminConfig = adminConfigDao.getAdminConfig();

      youTubeApiHelper.setAuthSubToken(adminConfig.getYouTubeAuthSubToken());

      if (adminConfig.getModerationMode() == AdminConfig.ModerationModeType.NO_MOD.ordinal()) {
        // NO_MOD is set, auto approve all submission
        // TODO: This isn't enough, as the normal approval flow (adding the branding, tags, emails,
        // etc.) isn't taking place.
        submission.setStatus(VideoSubmission.ModerationStatus.APPROVED);
        youTubeApiHelper.updateModeration(videoId, true);
       
        // Add video to YouTube playlist if it isn't in it already.
        // This code is kind of ugly and is mostly copy/pasted from UpdateVideoSubmissionStatus
        // TODO: It should be refactored into a common helper method somewhere...
        if (!submission.isInPlaylist()) {
          Assignment assignment = assignmentDao.getAssignmentById(assignmentId);

          if (assignment == null) {
            log.warning(String.format("Couldn't find assignment id '%d' for video id '%s'.",
                assignmentId, videoId));
          } else {
            String playlistId = assignment.getPlaylistId();
            if (util.isNullOrEmpty(playlistId)) {
              log.warning(String.format("Assignment id '%d' does not have an associated playlist.",
                  assignmentId));
            } else {
              if (youTubeApiHelper.insertVideoIntoPlaylist(playlistId, videoId)) {
                submission.setIsInPlaylist(true);
              }
            }
          }
        }
      } else {
        youTubeApiHelper.updateModeration(videoId, false);
      }

      submission = submissionDao.save(submission);

      log.fine("...VideoSubmission persisted.");

      emailUtil.sendNewSubmissionEmail(submission);

      try {
        JSONObject responseJsonObj = new JSONObject();
        responseJsonObj.put("videoId", videoId);
        responseJsonObj.put("status", status);
        resp.setContentType("text/html");
        resp.getWriter().println(responseJsonObj.toString());
      } catch (JSONException e) {
        log.warning(e.toString());
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
      }
    } else {
      String code = req.getParameter("code");
      log.warning(String.format("Upload request for user with session id '%s' failed with "
          + "status '%s' and code '%s'.", userSession.getId(), status, code));
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, code);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.