src/org/ohmage/request/survey/SurveyResponseReadRequest.java
private void populatePrompts(
			final Map<Integer, SurveyItem> surveyItems,
			Map<String, JSONObject> prompts) 
			throws JSONException {
		
		for(SurveyItem surveyItem : surveyItems.values()) {
	
			if(surveyItem instanceof Prompt) {
				if((surveyItem instanceof ChoicePrompt) && 
						(OutputFormat.CSV.equals(outputFormat))) {
					
					ChoicePrompt prompt = (ChoicePrompt) surveyItem;

					JSONObject promptJsonKey = new JSONObject();
					promptJsonKey.put(JSON_KEY_CONTEXT, prompt.toJson());
					promptJsonKey.put(JSON_KEY_VALUES, new JSONArray());
					
					JSONObject promptJsonLabel = new JSONObject();
					promptJsonLabel.put(JSON_KEY_CONTEXT, prompt.toJson());
					promptJsonLabel.put(JSON_KEY_VALUES, new JSONArray());
					
					prompts.put(prompt.getId() + ":key", promptJsonKey);
					prompts.put(prompt.getId() + ":label", promptJsonLabel);
					
					if(prompt.hasValues()) {
						JSONObject promptJsonValue = new JSONObject();
						promptJsonValue.put(JSON_KEY_CONTEXT, prompt.toJson());
						promptJsonValue.put(JSON_KEY_VALUES, new JSONArray());

						prompts.put(prompt.getId() + ":value", promptJsonValue);
					}
				}
				else {
					Prompt prompt = (Prompt) surveyItem;
					
					JSONObject promptJson = new JSONObject();
					promptJson.put(JSON_KEY_CONTEXT, prompt.toJson());
					promptJson.put(JSON_KEY_VALUES, new JSONArray());
					
					prompts.put(prompt.getId(), promptJson);
				}
			}
			else if(surveyItem instanceof RepeatableSet) {
				RepeatableSet repeatableSet = (RepeatableSet) surveyItem;
				populatePrompts(repeatableSet.getSurveyItems(), prompts);
			}
		}
	}
/**
	 * Populates the prompts map with all of the prompts from all of the survey
	 * items. 
	 * 
	 * @param surveyItems The map of survey item indices to the survey item.
	 * 
	 * @param prompts The prompts to be populated with all of the prompts in
	 * 				  the survey item including all of the sub-prompts of 
	 * 				  repeatable sets.
	 * 
	 * @throws JSONException Thrown if there is an error building the JSON.
	 */
Populates the prompts map with all of the prompts from all of the survey
items.

@param surveyItems The map of survey item indices to the survey item.

@param prompts The prompts to be populated with all of the prompts in
the survey item including all of the sub-prompts of
repeatable sets.

@throws JSONException Thrown if there is an error building the JSON.
Populates the prompts map with all of the prompts from all of the survey items . @param surveyItems The map of survey item indices to the survey item . @param prompts The prompts to be populated with all of the prompts in the survey item including all of the sub - prompts of repeatable sets . @throws JSONException Thrown if there is an error building the JSON .
private void populatePrompts(
			final Map<Integer, SurveyItem> surveyItems,
			Map<String, JSONObject> prompts) 
			throws JSONException {
		for(SurveyItem surveyItem : surveyItems.values()) {
			if(surveyItem instanceof Prompt) {
				if((surveyItem instanceof ChoicePrompt) && 
						(OutputFormat.CSV.equals(outputFormat))) {
					ChoicePrompt prompt = (ChoicePrompt) surveyItem;
					JSONObject promptJsonKey = new JSONObject();
					promptJsonKey.put(JSON_KEY_CONTEXT, prompt.toJson());
					promptJsonKey.put(JSON_KEY_VALUES, new JSONArray());
					JSONObject promptJsonLabel = new JSONObject();
					promptJsonLabel.put(JSON_KEY_CONTEXT, prompt.toJson());
					promptJsonLabel.put(JSON_KEY_VALUES, new JSONArray());
					prompts.put(prompt.getId() + ":key", promptJsonKey);
					prompts.put(prompt.getId() + ":label", promptJsonLabel);
					if(prompt.hasValues()) {
						JSONObject promptJsonValue = new JSONObject();
						promptJsonValue.put(JSON_KEY_CONTEXT, prompt.toJson());
						promptJsonValue.put(JSON_KEY_VALUES, new JSONArray());
						prompts.put(prompt.getId() + ":value", promptJsonValue);
					}
				}
				else {
					Prompt prompt = (Prompt) surveyItem;
					JSONObject promptJson = new JSONObject();
					promptJson.put(JSON_KEY_CONTEXT, prompt.toJson());
					promptJson.put(JSON_KEY_VALUES, new JSONArray());
					prompts.put(prompt.getId(), promptJson);
				}
			}
			else if(surveyItem instanceof RepeatableSet) {
				RepeatableSet repeatableSet = (RepeatableSet) surveyItem;
				populatePrompts(repeatableSet.getSurveyItems(), prompts);
			}
		}
	}
private void populatePrompts ( final Map < Integer , SurveyItem > surveyItems , Map < String , JSONObject > prompts ) throws JSONException { for ( SurveyItem surveyItem : surveyItems . values ( ) ) { if ( surveyItem instanceof Prompt ) { if ( ( surveyItem instanceof ChoicePrompt ) && ( OutputFormat . CSV . equals ( outputFormat ) ) ) { ChoicePrompt prompt = ( ChoicePrompt ) surveyItem ; JSONObject promptJsonKey = new JSONObject ( ) ; promptJsonKey . put ( JSON_KEY_CONTEXT , prompt . toJson ( ) ) ; promptJsonKey . put ( JSON_KEY_VALUES , new JSONArray ( ) ) ; JSONObject promptJsonLabel = new JSONObject ( ) ; promptJsonLabel . put ( JSON_KEY_CONTEXT , prompt . toJson ( ) ) ; promptJsonLabel . put ( JSON_KEY_VALUES , new JSONArray ( ) ) ; prompts . put ( prompt . getId ( ) + ":key" , promptJsonKey ) ; prompts . put ( prompt . getId ( ) + ":label" , promptJsonLabel ) ; if ( prompt . hasValues ( ) ) { JSONObject promptJsonValue = new JSONObject ( ) ; promptJsonValue . put ( JSON_KEY_CONTEXT , prompt . toJson ( ) ) ; promptJsonValue . put ( JSON_KEY_VALUES , new JSONArray ( ) ) ; prompts . put ( prompt . getId ( ) + ":value" , promptJsonValue ) ; } } else { Prompt prompt = ( Prompt ) surveyItem ; JSONObject promptJson = new JSONObject ( ) ; promptJson . put ( JSON_KEY_CONTEXT , prompt . toJson ( ) ) ; promptJson . put ( JSON_KEY_VALUES , new JSONArray ( ) ) ; prompts . put ( prompt . getId ( ) , promptJson ) ; } } else if ( surveyItem instanceof RepeatableSet ) { RepeatableSet repeatableSet = ( RepeatableSet ) surveyItem ; populatePrompts ( repeatableSet . getSurveyItems ( ) , prompts ) ; } } }
Populates the prompts map with all of the prompts from all of the survey
 items.
Populates the prompts map with all of the prompts from all of the survey items .