Search in sources :

Example 6 with UserProfile

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);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 7 with UserProfile

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

Example 8 with UserProfile

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

Example 9 with UserProfile

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);
    }
}
Also used : RankListEntry(cn.edu.zju.acm.onlinejudge.util.RankListEntry) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 10 with UserProfile

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);
    }
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

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