src/org/ohmage/request/clazz/ClassReadRequest.java
@Override
	public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
		LOGGER.info("Writing the result to the user.");
		
		// Populate our result JSONObject with class information.
		LOGGER.info("Creating the result JSONObject with the information about the classes.");
		JSONObject jsonResult = new JSONObject();
		try {
			for(Clazz clazz : result.keySet()) {
				// Create the JSON for the class.
				JSONObject jsonClass = clazz.toJson(false);
				
				// Retrieve the username to class role map.
				Map<String, Clazz.Role> userRole = result.get(clazz);
				
				if(userRole != null) {
					// Generate the user to class role JSON and add it to the 
					// class JSON.
					JSONObject users = new JSONObject();
					for(String username : userRole.keySet()) {
						Clazz.Role role = userRole.get(username);
						
						users.put(username, ((role == null) ? "" : role));
					}
					jsonClass.put(JSON_KEY_USERS, users);
				}
				
				// Add the class JSON to the result JSON with an index of the
				// class' ID.
				jsonResult.put(clazz.getId(), jsonClass);
			}
		}
		catch(JSONException e) {
			LOGGER.error("Error adding a class' information to the result object.", e);
			setFailed();
		}
		
		respond(httpRequest, httpResponse, jsonResult);
	}
/**
	 * Writes the response to the HTTP response object.
	 */
Writes the response to the HTTP response object.
Writes the response to the HTTP response object .
@Override
	public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
		LOGGER.info("Writing the result to the user.");
		LOGGER.info("Creating the result JSONObject with the information about the classes.");
		JSONObject jsonResult = new JSONObject();
		try {
			for(Clazz clazz : result.keySet()) {
				JSONObject jsonClass = clazz.toJson(false);
				Map<String, Clazz.Role> userRole = result.get(clazz);
				if(userRole != null) {
					JSONObject users = new JSONObject();
					for(String username : userRole.keySet()) {
						Clazz.Role role = userRole.get(username);
						users.put(username, ((role == null) ? "" : role));
					}
					jsonClass.put(JSON_KEY_USERS, users);
				}
				jsonResult.put(clazz.getId(), jsonClass);
			}
		}
		catch(JSONException e) {
			LOGGER.error("Error adding a class' information to the result object.", e);
			setFailed();
		}
		respond(httpRequest, httpResponse, jsonResult);
	}
@ Override public void respond ( HttpServletRequest httpRequest , HttpServletResponse httpResponse ) { LOGGER . info ( "Writing the result to the user." ) ; LOGGER . info ( "Creating the result JSONObject with the information about the classes." ) ; JSONObject jsonResult = new JSONObject ( ) ; try { for ( Clazz clazz : result . keySet ( ) ) { JSONObject jsonClass = clazz . toJson ( false ) ; Map < String , Clazz . Role > userRole = result . get ( clazz ) ; if ( userRole != null ) { JSONObject users = new JSONObject ( ) ; for ( String username : userRole . keySet ( ) ) { Clazz . Role role = userRole . get ( username ) ; users . put ( username , ( ( role == null ) ? "" : role ) ) ; } jsonClass . put ( JSON_KEY_USERS , users ) ; } jsonResult . put ( clazz . getId ( ) , jsonClass ) ; } } catch ( JSONException e ) { LOGGER . error ( "Error adding a class' information to the result object." , e ) ; setFailed ( ) ; } respond ( httpRequest , httpResponse , jsonResult ) ; }
Writes the response to the HTTP response object.
Writes the response to the HTTP response object .
// Populate our result JSONObject with class information. // Create the JSON for the class. // Retrieve the username to class role map. // Generate the user to class role JSON and add it to the  // class JSON. // Add the class JSON to the result JSON with an index of the // class' ID.