Search in sources :

Example 1 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.

the class AddUserRoleAction method execute.

/**
 * AddUserRoleAction.
 *
 * @param mapping
 *            action mapping
 * @param form
 *            action form
 * @param request
 *            http servlet request
 * @param response
 *            http servlet response
 *
 * @return action forward instance
 *
 * @throws Exception
 *             any errors happened
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check admin
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        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);
    return this.handleSuccess(mapping, context, "success", "?userId=" + userId);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward)

Example 2 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.

the class SubmissionPersistenceImplTest method newUserProfile.

/**
 * Creates a new user profile.
 * @param id the id
 * @return a new user profile instance
 */
private UserProfile newUserProfile(long id) {
    UserProfile profile = new UserProfile();
    profile.setId(id);
    profile.setHandle("myHandle" + id);
    profile.setPassword("myPassword");
    profile.setEmail("myEmail" + id);
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(new Date(0));
    profile.setGender('M');
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false);
    return profile;
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 3 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.

the class UserManager method getUserProfile.

public UserProfile getUserProfile(long userId) throws PersistenceException {
    Object key = new Long(userId);
    synchronized (this.userCache) {
        UserProfile user = this.userCache.get(key);
        if (user == null) {
            UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
            user = userPersistence.getUserProfile(userId);
            this.userCache.put(key, user);
        }
        return user;
    }
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Example 4 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.

the class UserPersistenceImplTest method testCreateUserProfile.

/**
 * 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);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile)

Example 5 with UserProfile

use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.

the class UserPersistenceImplTest method testGetUserProfileByHandle.

/**
 * 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);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile)

Aggregations

UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)32 ActionForward (org.apache.struts.action.ActionForward)9 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)7 ActionMessage (org.apache.struts.action.ActionMessage)6 ActionMessages (org.apache.struts.action.ActionMessages)6 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)3 Country (cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)3 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 List (java.util.List)3