Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.UserProfile


            return forward;
        }

        long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
        long roleId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("roleId")));
        UserProfile user = UserManager.getInstance().getUserProfile(userId);
        if (user == null) {
            return this.handleSuccess(mapping, context, "failure");
        }

        PersistenceManager.getInstance().getAuthorizationPersistence().addUserRole(userId, roleId);
View Full Code Here


     * @return ActionForward
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {

        UserProfile user = null;
        String handle = context.getRequest().getParameter("handle");
        if (handle != null && handle.length() > 0) {
            // TODO cache?
            user = PersistenceManager.getInstance().getUserPersistence().getUserProfileByHandle(handle);
        } else if (context.getRequest().getParameter("userId") != null) {
            long userId = Utility.parseLong(context.getRequest().getParameter("userId"));
            if (userId != -1) {
                user = PersistenceManager.getInstance().getUserPersistence().getUserProfile(userId);
            }
        } else {
            user = context.getUserProfile();
        }
        AbstractContest contest = null;
        if (user != null) {
            long contestId = Utility.parseLong(context.getRequest().getParameter("contestId"));
            if (contestId == -1) {
                contestId = ShowUserStatusAction.defaultProblemSetId;
            }
            contest = ContestManager.getInstance().getContest(contestId);
        }
        if (contest != null) {
            context.setAttribute("contest", contest);
            ActionForward forward = this.checkContestViewPermission(mapping, context, null, true);
            if (forward != null) {
                contest = null;
            }
        }

        UserStatistics statistics = null;
        UserPreference pref = null;
        if (contest != null && user != null) {
          // TODO cache?
          pref = PersistenceManager.getInstance().getUserPersistence().getUserPreference(user.getId());
            statistics = StatisticsManager.getInstance().getUserStatistics(contest.getId(), user.getId());
        }

        context.setAttribute("user", user);
        context.setAttribute("preference", pref);
        context.setAttribute("contest", contest);
View Full Code Here

            return null;
        }


        // user can always view their own submission
        UserProfile user = context.getUserProfile();
        if (user == null || user.getId() != submission.getUserProfileId()) {
            Problem problem = ContestManager.getInstance().getProblem(submission.getProblemId());
            context.setAttribute("problem", problem);
            ActionForward forward = this.checkProblemViewSourecPermission(mapping, context, null);
            if (forward != null) {
                response.sendError(404);
View Full Code Here

        if (!this.isLogin(context)) {
            return this.handleSuccess(mapping, context, "login");
        }
        UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
        ProfileForm profileForm = (ProfileForm) form;
        UserProfile profile = context.getUserProfile();
        UserPreference perference = userPersistence.getUserPreference(profile.getId());
        if (profileForm.getHandle() == null) {
            profileForm.populate(profile, perference);
            context.setAttribute("ProfileForm", profileForm);
            return this.handleSuccess(mapping, context, "failure");
        }

        if (userPersistence.login(profileForm.getHandle(), profileForm.getPassword()) == null) {
            return this.handleFailure(mapping, context, "password", "ProfileForm.password.invalid");
        }

        UserProfile newProfile = profileForm.toUserProfile();
        newProfile.setId(profile.getId());
        newProfile.setRegDate(profile.getRegDate());

        if (!profile.getHandle().equals(newProfile.getHandle())) {
            return this.handleFailure(mapping, context, "handle", "ProfileForm.handle.changed");
        }

        if (!profile.getEmail().equals(newProfile.getEmail())) {
            UserProfile temp = userPersistence.getUserProfileByEmail(newProfile.getEmail());
            if (temp != null && temp.getId() != profile.getId()) {
                return this.handleFailure(mapping, context, "email", "ProfileForm.email.used");
            }
        }

        userPersistence.updateUserProfile(newProfile, profile.getId());
View Full Code Here

   * Tests createUserProfile method
   * @throws Exception to JUnit
   */
  public void testCreateUserProfile() throws Exception {   
    persistence.createUserProfile(profile, 1);
    UserProfile profile1 = persistence.getUserProfile(profile.getId());
    checkUserProfile(profile, profile1);
  }
View Full Code Here

    profile.setStudentNumber("myNewStudentNumber");
    profile.setConfirmed(false);
   
    persistence.updateUserProfile(profile, 1);
   
    UserProfile profile1 = persistence.getUserProfile(profile.getId());
    checkUserProfile(profile, profile1);
  }
View Full Code Here

   */
  public void testDeleteUserProfile() throws Exception {   
    persistence.createUserProfile(profile, 1);
    persistence.deleteUserProfile(profile.getId(), 1);
   
    UserProfile profile1 = persistence.getUserProfile(profile.getId());
   
    assertFalse("should be removed", profile1.isActive());
   
  }
View Full Code Here

   * Tests getUserProfile method
   * @throws Exception to JUnit
   */
  public void testGetUserProfile() throws Exception {   
    persistence.createUserProfile(profile, 1);
    UserProfile profile1 = persistence.getUserProfile(profile.getId());
    checkUserProfile(profile, profile1);   
  }
View Full Code Here

   * Tests getUserProfileByHandle method
   * @throws Exception to JUnit
   */
  public void testGetUserProfileByHandle() throws Exception {   
    persistence.createUserProfile(profile, 1);
    UserProfile profile1 = persistence.getUserProfileByHandle(profile.getHandle());
    checkUserProfile(profile, profile1);   
  }
View Full Code Here

   * Tests getUserProfileByEmail method
   * @throws Exception to JUnit
   */
  public void testGetUserProfileByEmail() throws Exception {   
    persistence.createUserProfile(profile, 1);
    UserProfile profile1 = persistence.getUserProfileByEmail(profile.getEmail());
    checkUserProfile(profile, profile1);   
  }
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.UserProfile

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.