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);
}
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);
}
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");
}
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;
}
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);
}
}
Aggregations