Welcome to Chris Johnsons' Portfolio

G'day. My name is Christopher Johnson and you've reached my humble portfolio which contains bits and pieces that I've created over the years. I've decided to post as much as I can in order to show where I've come from and in what ways I've improved. Thanks for stopping by. I hope you enjoy what you see. If you have any questions then feel free to contact me. Chris.

Twitter Update

Follow me on Twitter


My Websites

Most Recent Additions

Browse by Month

Content Syndication


TimeTrack Java Code Snippets

UserTools.java – clockInTask()

 * Populates the taskTime table with the current information
 * @author Christopher Johnson
 * @param task		The task which is being worked on
 * @param userID	The user that is working on the task
 * @param startTime	The time that the user started working on the task
public static boolean clockInTask(Task task, int userID, java.sql.Timestamp startTime) {
	java.util.Calendar rightNow = java.util.Calendar.getInstance();
	java.sql.Timestamp endTime = new java.sql.Timestamp(rightNow.getTimeInMillis());
	// grab the user_task_id
	SelectQuery sq = new SelectQuery("user_task_id",
					 "user_id = " + userID + " AND task_id = " + task.getID());
	DatabaseConnection dc = DatabaseConnection.getInstance();
	ResultSet rs = dc.executeQuery(sq);
	if ( rs == null ) return false; // The user has not been assigned to this task
	int user_task_id = 0;
	try {
		if (rs.next()) {
			user_task_id = rs.getInt("user_task_id");
	} catch (java.sql.SQLException e) {
		System.err.println("SQLException: " + e.getMessage());
		return false;
	// Submit to the database
	InsertQuery iq = new InsertQuery("taskTime");
	iq.addField("user_task_id", user_task_id);
	iq.addField("tasktime_start_date", startTime);
	iq.addField("tasktime_end_date", endTime);
	if ( !dc.executeQuery(iq) ) {
		return false; // adding to database failed
	// Report project deletion in log
	Event.submitEvent("Task: " + task.getName()  + 
                                      " Worked on by " + CurrentState.get().getUsername());
	return true;

TestManagerTools.java – testGetUserGroups()

 * Test Case for testGetUserGroups()
 * Tests to see if GetUserGroups gets the correct number of User Groups
 * @author Christopher Johnson
 * Note that this code can fail as you can have more than Integer.MAX_VALUE usergroups
 * Default Database Configuration sets row limit to be less than Integer.MAX_VALUE
public void testGetUserGroups() throws SQLException {
	byte[] pwd = {'p','a','s','s','w', 'o', 'r', 'd' };
	try {
		DatabaseConnection.getInstance().login("Nick", pwd);
	} catch (Exception e) {
		System.err.println("Login failed: " + e.getMessage());
	ArrayList<usergroup> currentUserGroups = ManagerTools.getUsersGroups(Integer.MAX_VALUE);
	SelectQuery query = new SelectQuery("count(usergroup_id) as usergroup_count",
	ResultSet rs = dc.executeQuery(query);
	assertTrue((currentUserGroups.size() == rs.getInt("usergroup_count")));