src/org/ohmage/domain/campaign/Survey.java
public JSONObject toJson(
			final boolean withId, 
			final boolean withTitle,
			final boolean withDescription, 
			final boolean withIntroText,
			final boolean withSubmitText, 
			final boolean withAnytime, 
			final boolean withSurveyItems,
			final Set<String> promptIds) 
			throws JSONException {
		
		JSONObject result = new JSONObject();
		
		if(withId) {
			result.put(JSON_KEY_ID, id);
		}

		if(withTitle) {
			result.put(JSON_KEY_TITLE, title);
		}

		if(withDescription) {
			result.put(JSON_KEY_DESCRIPTION, description);
		}

		if(withIntroText) {
			result.put(JSON_KEY_INTRO_TEXT, introText);
		}

		if(withSubmitText) {
			result.put(JSON_KEY_SUBMIT_TEXT, submitText);
		}

		if(withAnytime) {
			result.put(JSON_KEY_ANYTIME, anytime);
		}

		if(withSurveyItems) {
			JSONArray surveyItemsArray = new JSONArray();
			
			List<Integer> indices =
				new ArrayList<Integer>(surveyItems.keySet());
			Collections.sort(indices);
			
			for(Integer index : indices) {
				if(promptIds == null) {
					surveyItemsArray.put(surveyItems.get(index).toJson());
				}
				else {
					SurveyItem surveyItem = surveyItems.get(index);
					if(promptIds.contains(surveyItem.getId())) {
						surveyItemsArray.put(surveyItem.toJson());
					}
				}
			}
			
			result.put(JSON_KEY_PROMPTS, surveyItemsArray);
		}
		
		return result;
	}
/**
	 * Creates a JSONObject that represents this survey.
	 * 
	 * @param withId Whether or not to include the survey's unique identifier.
	 * 
	 * @param withTitle Whether or not to include the survey's title.
	 * 
	 * @param withDescription Whether or not to include the survey's 
	 * 						  description.
	 * 
	 * @param withIntroText Whether or not to include the survey's intro text.
	 * 
	 * @param withSubmitText Whether or not to include the survey's submit
	 * 						 text.
	 * 
	 * @param withAnytime Whether or not to include if the survey allows the 
	 * 					  user to take the survey anytime.
	 * 
	 * @param withSurveyItems Whether or not to include all of the prompts.
	 * 
	 * @return A JSONObject that represents this survey based on the 
	 * 		   parameters.
	 * 
	 * @throws JSONException There was a problem creating the JSONObject.
	 */
Creates a JSONObject that represents this survey.

@param withId Whether or not to include the survey's unique identifier.

@param withTitle Whether or not to include the survey's title.

@param withDescription Whether or not to include the survey's
description.

@param withIntroText Whether or not to include the survey's intro text.

@param withSubmitText Whether or not to include the survey's submit
text.

@param withAnytime Whether or not to include if the survey allows the
user to take the survey anytime.

@param withSurveyItems Whether or not to include all of the prompts.

@return A JSONObject that represents this survey based on the
parameters.

@throws JSONException There was a problem creating the JSONObject.
Creates a JSONObject that represents this survey . @param withId Whether or not to include the survey ' s unique identifier . @param withTitle Whether or not to include the survey ' s title . @param withDescription Whether or not to include the survey ' s description . @param withIntroText Whether or not to include the survey ' s intro text . @param withSubmitText Whether or not to include the survey ' s submit text . @param withAnytime Whether or not to include if the survey allows the user to take the survey anytime . @param withSurveyItems Whether or not to include all of the prompts . @return A JSONObject that represents this survey based on the parameters . @throws JSONException There was a problem creating the JSONObject .
public JSONObject toJson(
			final boolean withId, 
			final boolean withTitle,
			final boolean withDescription, 
			final boolean withIntroText,
			final boolean withSubmitText, 
			final boolean withAnytime, 
			final boolean withSurveyItems,
			final Set<String> promptIds) 
			throws JSONException {
		JSONObject result = new JSONObject();
		if(withId) {
			result.put(JSON_KEY_ID, id);
		}
		if(withTitle) {
			result.put(JSON_KEY_TITLE, title);
		}
		if(withDescription) {
			result.put(JSON_KEY_DESCRIPTION, description);
		}
		if(withIntroText) {
			result.put(JSON_KEY_INTRO_TEXT, introText);
		}
		if(withSubmitText) {
			result.put(JSON_KEY_SUBMIT_TEXT, submitText);
		}
		if(withAnytime) {
			result.put(JSON_KEY_ANYTIME, anytime);
		}
		if(withSurveyItems) {
			JSONArray surveyItemsArray = new JSONArray();
			List<Integer> indices =
				new ArrayList<Integer>(surveyItems.keySet());
			Collections.sort(indices);
			for(Integer index : indices) {
				if(promptIds == null) {
					surveyItemsArray.put(surveyItems.get(index).toJson());
				}
				else {
					SurveyItem surveyItem = surveyItems.get(index);
					if(promptIds.contains(surveyItem.getId())) {
						surveyItemsArray.put(surveyItem.toJson());
					}
				}
			}
			result.put(JSON_KEY_PROMPTS, surveyItemsArray);
		}
		return result;
	}
public JSONObject toJson ( final boolean withId , final boolean withTitle , final boolean withDescription , final boolean withIntroText , final boolean withSubmitText , final boolean withAnytime , final boolean withSurveyItems , final Set < String > promptIds ) throws JSONException { JSONObject result = new JSONObject ( ) ; if ( withId ) { result . put ( JSON_KEY_ID , id ) ; } if ( withTitle ) { result . put ( JSON_KEY_TITLE , title ) ; } if ( withDescription ) { result . put ( JSON_KEY_DESCRIPTION , description ) ; } if ( withIntroText ) { result . put ( JSON_KEY_INTRO_TEXT , introText ) ; } if ( withSubmitText ) { result . put ( JSON_KEY_SUBMIT_TEXT , submitText ) ; } if ( withAnytime ) { result . put ( JSON_KEY_ANYTIME , anytime ) ; } if ( withSurveyItems ) { JSONArray surveyItemsArray = new JSONArray ( ) ; List < Integer > indices = new ArrayList < Integer > ( surveyItems . keySet ( ) ) ; Collections . sort ( indices ) ; for ( Integer index : indices ) { if ( promptIds == null ) { surveyItemsArray . put ( surveyItems . get ( index ) . toJson ( ) ) ; } else { SurveyItem surveyItem = surveyItems . get ( index ) ; if ( promptIds . contains ( surveyItem . getId ( ) ) ) { surveyItemsArray . put ( surveyItem . toJson ( ) ) ; } } } result . put ( JSON_KEY_PROMPTS , surveyItemsArray ) ; } return result ; }
Creates a JSONObject that represents this survey.
Creates a JSONObject that represents this survey .