Search in sources :

Example 6 with UserPreference

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

the class UserPersistenceImplTest method testCreateUserPreference.

/**
	 * Tests getCreateUserPreference method
	 * @throws Exception to JUnit
	 */
public void testCreateUserPreference() throws Exception {
    persistence.createUserProfile(profile, 1);
    perference.setId(profile.getId());
    persistence.createUserPreference(perference, 1);
    UserPreference perference1 = persistence.getUserPreference(perference.getId());
    checkUserPreference(perference, perference1);
}
Also used : UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference)

Example 7 with UserPreference

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

the class UserPersistenceImplTest method testUpdateUserPreference.

/**
	 * Tests getUpdateUserPreference method
	 * @throws Exception to JUnit
	 */
public void testUpdateUserPreference() throws Exception {
    persistence.createUserProfile(profile, 1);
    perference.setId(profile.getId());
    persistence.createUserPreference(perference, 1);
    perference.setPlan("my new plan");
    perference.setPostPaging(11);
    perference.setProblemPaging(22);
    perference.setStatusPaging(33);
    perference.setSubmissionPaging(44);
    perference.setThreadPaging(55);
    perference.setUserPaging(66);
    persistence.updateUserPreference(perference, 1);
    UserPreference perference1 = persistence.getUserPreference(perference.getId());
    checkUserPreference(perference, perference1);
}
Also used : UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference)

Example 8 with UserPreference

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

the class RegisterAction method execute.

/**
     * Register.
     * 
     * @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 {
    if (!Features.register()) {
        context.getResponse().sendError(404);
        return null;
    }
    UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
    ProfileForm profileForm = (ProfileForm) form;
    if (profileForm.getHandle() == null) {
        return this.handleSuccess(mapping, context, "failure");
    }
    context.getRequest().getSession().invalidate();
    ActionMessages errors = this.validate(userPersistence, profileForm);
    if (errors.size() > 0) {
        return this.handleFailure(mapping, context, errors);
    }
    // create user profile
    UserProfile profile = profileForm.toUserProfile();
    userPersistence.createUserProfile(profile, 0);
    // create user perference
    UserPreference perference = profileForm.toUserPreference();
    perference.setId(profile.getId());
    userPersistence.createUserPreference(perference, 0);
    AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
    authorizationPersistence.addUserRole(profile.getId(), 2);
    context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
    // get UserSecurity
    UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());
    context.setUserProfile(profile);
    context.setUserSecurity(security);
    context.setUserPreference(perference);
    ActionMessages messages = new ActionMessages();
    messages.add("message", new ActionMessage("onlinejudge.register.success"));
    this.saveErrors(context.getRequest(), messages);
    context.setAttribute("back", "");
    return this.handleSuccess(mapping, context, "success");
}
Also used : UserSecurity(cn.edu.zju.acm.onlinejudge.security.UserSecurity) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionMessages(org.apache.struts.action.ActionMessages) ProfileForm(cn.edu.zju.acm.onlinejudge.form.ProfileForm) ActionMessage(org.apache.struts.action.ActionMessage) AuthorizationPersistence(cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence) UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference) UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Example 9 with UserPreference

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

the class ProfileForm method toUserPreference.

public UserPreference toUserPreference() throws PersistenceException {
    UserPreference preference = new UserPreference();
    preference.setPlan(this.plan);
    // TODO...
    preference.setPostPaging(20);
    preference.setProblemPaging(100);
    preference.setStatusPaging(20);
    preference.setThreadPaging(20);
    preference.setUserPaging(20);
    return preference;
}
Also used : UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference)

Example 10 with UserPreference

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

the class UserPersistenceImpl method getUserPreference.

/**
     * <p>
     * Gets the user preference with given id in persistence layer.
     * </p>
     * 
     * @param id
     *            the id of the user preference
     * @return the user preference with given id in persistence layer
     * @throws PersistenceException
     *             wrapping a persistence implementation specific exception
     */
public UserPreference getUserPreference(long id) throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(UserPersistenceImpl.GET_USER_PREFERENCE);
            ps.setLong(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                UserPreference preference = new UserPreference();
                preference.setId(rs.getLong(DatabaseConstants.USER_PREFERENCE_USER_PROFILE_ID));
                preference.setPlan(rs.getString(DatabaseConstants.USER_PREFERENCE_PLAN));
                preference.setPostPaging(rs.getInt(DatabaseConstants.USER_PREFERENCE_POST_PAGING));
                preference.setProblemPaging(rs.getInt(DatabaseConstants.USER_PREFERENCE_PROBLEM_PAGING));
                preference.setStatusPaging(rs.getInt(DatabaseConstants.USER_PREFERENCE_STATUS_PAGING));
                preference.setSubmissionPaging(rs.getInt(DatabaseConstants.USER_PREFERENCE_SUBMISSION_PAGING));
                preference.setThreadPaging(rs.getInt(DatabaseConstants.USER_PREFERENCE_THREAD_PAGING));
                preference.setUserPaging(rs.getInt(DatabaseConstants.USER_PREFERENCE_USER_PAGING));
                return preference;
            } else {
                return null;
            }
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the user preference with id " + id, e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference)

Aggregations

UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)10 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)5 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 ActionMessage (org.apache.struts.action.ActionMessage)3 ActionMessages (org.apache.struts.action.ActionMessages)3 ProfileForm (cn.edu.zju.acm.onlinejudge.form.ProfileForm)2 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)1 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 UserStatistics (cn.edu.zju.acm.onlinejudge.util.UserStatistics)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ServletException (javax.servlet.ServletException)1 Cookie (javax.servlet.http.Cookie)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1