use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImpl method populateUserProfile.
/**
* Populates a UserProfile instance with the given ResultSet.
*
* @param rs
* the ResultSet
* @return the UserProfile instance
* @throws SQLException
* if any error occurs
*/
private UserProfile populateUserProfile(ResultSet rs) throws SQLException {
UserProfile profile = new UserProfile();
profile.setId(rs.getLong(DatabaseConstants.USER_PROFILE_USER_PROFILE_ID));
profile.setHandle(rs.getString(DatabaseConstants.USER_PROFILE_HANDLE));
profile.setPassword(rs.getString(DatabaseConstants.USER_PROFILE_PASSWORD));
profile.setEmail(rs.getString(DatabaseConstants.USER_PROFILE_EMAIL_ADDRESS));
profile.setRegDate(rs.getTimestamp(DatabaseConstants.USER_PROFILE_REG_DATE));
profile.setFirstName(rs.getString(DatabaseConstants.USER_PROFILE_FIRST_NAME));
profile.setLastName(rs.getString(DatabaseConstants.USER_PROFILE_LAST_NAME));
profile.setAddressLine1(rs.getString(DatabaseConstants.USER_PROFILE_ADDRESS_LINE1));
profile.setAddressLine2(rs.getString(DatabaseConstants.USER_PROFILE_ADDRESS_LINE2));
profile.setCity(rs.getString(DatabaseConstants.USER_PROFILE_CITY));
profile.setState(rs.getString(DatabaseConstants.USER_PROFILE_STATE));
profile.setCountry(new Country(rs.getLong(DatabaseConstants.USER_PROFILE_COUNTRY_ID), "foo"));
profile.setZipCode(rs.getString(DatabaseConstants.USER_PROFILE_ZIP_CODE));
profile.setPhoneNumber(rs.getString(DatabaseConstants.USER_PROFILE_PHONE_NUMBER));
profile.setBirthDate(rs.getDate(DatabaseConstants.USER_PROFILE_BIRTH_DATE));
String gender = rs.getString(DatabaseConstants.USER_PROFILE_GENDER);
profile.setGender(gender == null || gender.length() == 0 ? ' ' : gender.charAt(0));
profile.setSchool(rs.getString(DatabaseConstants.USER_PROFILE_SCHOOL));
profile.setMajor(rs.getString(DatabaseConstants.USER_PROFILE_MAJOR));
profile.setGraduateStudent(rs.getBoolean(DatabaseConstants.USER_PROFILE_GRADUATE_STUDENT));
profile.setGraduationYear(rs.getInt(DatabaseConstants.USER_PROFILE_GRADUATION_YEAR));
profile.setStudentNumber(rs.getString(DatabaseConstants.USER_PROFILE_STUDENT_NUMBER));
profile.setConfirmed(rs.getBoolean(DatabaseConstants.USER_PROFILE_CONFIRMED));
profile.setActive(rs.getBoolean(DatabaseConstants.USER_PROFILE_ACTIVE));
profile.setNickName(rs.getString("nickname"));
profile.setOldEmail(rs.getString("old_email"));
return profile;
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImpl method searchUserProfiles.
/**
* <p>
* Searches all user profiles according with the given criteria in persistence layer.
* </p>
*
* @return a list of user profiles according with the given criteria
* @param criteria
* the user profile search criteria
* @param offset
* the offset of the start position to search
* @param count
* the maximum number of user profiles in returned list
* @throws NullPointerException
* if argument is null
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public List<UserProfile> searchUserProfiles(UserCriteria criteria, int offset, int count) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = this.getUserSearchSql(conn, criteria, false, offset, count);
ResultSet rs = ps.executeQuery();
List<UserProfile> users = new ArrayList<UserProfile>();
while (rs.next()) {
users.add(this.populateUserProfile(rs));
}
return users;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to search user.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class ShowJudgeCommentAction method execute.
/**
* ShowRankListAction.
*
* @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 {
HttpServletResponse response = context.getResponse();
UserProfile user = context.getUserProfile();
if (user == null) {
response.sendError(404);
return null;
}
long id = Utility.parseLong(context.getRequest().getParameter("submissionId"));
Submission submission = null;
if (id > 0) {
submission = PersistenceManager.getInstance().getSubmissionPersistence().getSubmission(id);
}
if (submission == null) {
response.sendError(404);
return null;
}
if (!context.isAdmin() && (submission.getUserProfileId() != user.getId() || !JudgeReply.COMPILATION_ERROR.equals(submission.getJudgeReply()))) {
response.sendError(404);
return null;
}
response.setContentType("text/plain");
response.getOutputStream().write((submission.getJudgeComment() == null ? "" : submission.getJudgeComment()).getBytes());
response.getOutputStream().close();
return null;
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class ShowUserStatusAction method execute.
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @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);
context.setAttribute("UserStatistics", statistics);
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class EditProfileAction method execute.
/**
* Edit Profile.
*
* @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.editProfile()) {
context.getResponse().sendError(404);
return null;
}
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());
UserPreference newPerference = profileForm.toUserPreference();
newPerference.setId(profile.getId());
userPersistence.updateUserPreference(newPerference, profile.getId());
context.setUserProfile(newProfile);
context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.editProfile.success"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", "");
return this.handleSuccess(mapping, context, "success");
}
Aggregations