use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImplTest method testUpdateUserProfile.
/**
* Tests updateUserProfile method
* @throws Exception to JUnit
*/
public void testUpdateUserProfile() throws Exception {
persistence.createUserProfile(profile, 1);
profile.setHandle("myNewHandle");
profile.setPassword("myNewPassword");
profile.setEmail("myNewEmail");
profile.setRegDate(new Date());
profile.setFirstName("myNewFirstName");
profile.setLastName("myNewLastName");
profile.setAddressLine1("myNewAddressLine1");
profile.setAddressLine2("myNewAddressLine2");
profile.setCity("myNewCity");
profile.setState("myNewState");
profile.setCountry(new Country(2, "foo"));
profile.setZipCode("myNewZipCode");
profile.setPhoneNumber("myNewPhoneNumber");
profile.setBirthDate(DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse("1/1/1980"));
profile.setGender('F');
profile.setSchool("myNewSchool");
profile.setMajor("myNewMajor");
profile.setGraduateStudent(false);
profile.setGraduationYear(2006);
profile.setStudentNumber("myNewStudentNumber");
profile.setConfirmed(false);
persistence.updateUserProfile(profile, 1);
UserProfile profile1 = persistence.getUserProfile(profile.getId());
checkUserProfile(profile, profile1);
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImplTest method testGetUserProfileByEmail.
/**
* 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);
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImplTest method testDeleteUserProfile.
/**
* Tests deleteUserProfile method
* @throws Exception to JUnit
*/
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());
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class SubmissionPersistenceImpl method getRankList.
public List<RankListEntry> getRankList(List<Problem> problems, long contestStartDate, long roleId) throws PersistenceException {
Connection conn = null;
if (problems.size() == 0) {
return new ArrayList<RankListEntry>();
}
try {
conn = Database.createConnection();
PreparedStatement ps = null;
List<Long> problemIds = new ArrayList<Long>();
Map<Long, Integer> problemIndexes = new HashMap<Long, Integer>();
int index = 0;
for (Problem problem2 : problems) {
Problem problem = (Problem) problem2;
problemIds.add(new Long(problem.getId()));
problemIndexes.put(new Long(problem.getId()), new Integer(index));
index++;
}
String userIdsCon = "";
if (roleId >= 0) {
// TODO performance issue!!
List<Long> ids = new ArrayList<Long>();
try {
ps = conn.prepareStatement("SELECT user_profile_id FROM user_role WHERE role_id=?");
ps.setLong(1, roleId);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
ids.add(rs.getLong(1));
}
if (ids.size() == 0) {
return new ArrayList<RankListEntry>();
}
} finally {
Database.dispose(ps);
}
userIdsCon = " AND user_profile_id IN " + Database.createNumberValues(ids);
}
String inProblemIds = Database.createNumberValues(problemIds);
Map<Long, RankListEntry> entries = new HashMap<Long, RankListEntry>();
try {
ps = conn.prepareStatement("SELECT user_profile_id, problem_id, judge_reply_id, submission_date FROM submission " + "WHERE problem_id IN " + inProblemIds + userIdsCon + " ORDER BY submission_date");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
long userId = rs.getLong(1);
RankListEntry entry = (RankListEntry) entries.get(new Long(userId));
if (entry == null) {
entry = new RankListEntry(problems.size());
entries.put(new Long(userId), entry);
UserProfile profile = new UserProfile();
profile.setId(userId);
entry.setUserProfile(profile);
}
long problemId = rs.getLong(2);
long judgeReplyId = rs.getLong(3);
int time = (int) ((rs.getTimestamp(4).getTime() - contestStartDate) / 1000 / 60);
entry.update(((Integer) problemIndexes.get(new Long(problemId))).intValue(), time, judgeReplyId == JudgeReply.ACCEPTED.getId());
}
} finally {
Database.dispose(ps);
}
List<RankListEntry> entryList = new ArrayList<RankListEntry>(entries.values());
Collections.sort(entryList);
return entryList;
} catch (SQLException e) {
throw new PersistenceException("Failed to get the rank list", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.UserProfile in project zoj by licheng.
the class UserPersistenceImpl method getStudents.
public List getStudents(long userId) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.GET_USER_BY_CREATE_USER);
ps.setLong(1, userId);
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 get the user profile with create user " + userId, e);
} finally {
Database.dispose(conn);
}
}
Aggregations