src/org/ohmage/domain/campaign/Campaign.java
public JSONObject toJson(
			final boolean withId, 
			final boolean withClasses,
			final boolean withRoles, 
			final boolean withParticipants,
			final boolean withAnalysts, 
			final boolean withAuthors,
			final boolean withSupervisors, 
			final boolean withXml,
			final boolean withSurveys,
			final boolean withResponseCounts) 
			throws JSONException, DomainException{
		
		JSONObject result = new JSONObject();
		
		if(withId) {
			result.put(JSON_KEY_ID, id);
		}
		result.put(JSON_KEY_NAME, name);
		result.put(JSON_KEY_DESCRIPTION, (description == null) ? "" : description);
		result.put(JSON_KEY_ICON_URL, iconUrl);
		result.put(JSON_KEY_AUTHORED_BY, authoredBy);
		result.put(JSON_KEY_RUNNING_STATE, runningState.name().toLowerCase());
		result.put(JSON_KEY_PRIVACY_STATE, privacyState.name().toLowerCase());
		result.put(JSON_KEY_EDITABLE, editable);
		result.put(JSON_KEY_AUTHOR_LIST, authorList);
		// add request's user roles
		
		// If there is no mask, report the actual campaign creation timestamp.
		if(masks.size() == 0) {
			result
				.put(
					JSON_KEY_CREATION_TIMESTAMP,
					DateTimeUtils
						.getIso8601DateString(creationTimestamp, true));
		}
		// Otherwise, get the latest mask and use its creation timestamp as
		// this campaign's timestamp.
		else {
			result
				.put(
					JSON_KEY_CREATION_TIMESTAMP,
					DateTimeUtils
						.getIso8601DateString(
							masks.get(masks.size() - 1).getCreationTime(),
							true));
		}
		
		if(withClasses) {
			result.put(JSON_KEY_CLASSES, classes);
		}
		
		if(withRoles) {
			JSONObject roles = new JSONObject();
			
			if(withParticipants) {
				roles.put(JSON_KEY_PARTICIPANT, getParticipants());
			}
			if(withAnalysts) {
				roles.put(JSON_KEY_ANALYST, getAnalysts());
			}
			if(withAuthors) {
				roles.put(JSON_KEY_AUTHOR, getAuthors());
			}
			if(withSupervisors) {
				roles.put(JSON_KEY_SUPERVISOR, getSupervisors());
			}
			
			result.put(JSON_KEY_ROLES, roles);
		}
		
		if (withResponseCounts){
		    JSONObject counts = new JSONObject();
		    for (SurveyResponse.PrivacyState ps : SurveyResponse.PrivacyState.values()){
			Integer count = surveyResponseCounts.get(ps);
			if (count != null)
			    counts.put(ps.toString(), surveyResponseCounts.get(ps));
			else counts.put(ps.toString(), 0);
		    }
		    result.put(JSON_KEY_SURVEY_RESPONSE_COUNT, counts);
		}
		
		if(withXml) {
			// Returned the masked XML.
			result.put(JSON_KEY_XML, getXml());
		}
		
		if(withSurveys) {
			// If any masks exist, get the most recent one's survey list.
			Map<String, Set<String>> surveyPromptMap = null;
			if(masks.size() > 0) {
				surveyPromptMap = masks.get(masks.size() - 1).getSurveyPromptMap();
			}
			
			JSONArray surveysArray = new JSONArray();
			for(Survey survey : surveyMap.values()) {
				// If the campaign is being masked and this survey isn't part
				// of the mask, skip it.
				if(
					(surveyPromptMap != null) && 
					(! surveyPromptMap.containsKey(survey.getId()))) {
						
					continue;
				}
				
				surveysArray.put( 
					survey.toJson(
						true,	// ID
						true,	// Title
						true,	// Description
						true,	// Intro Text
						true,	// Submit Text
						true,	// Anytime
						true,	// Prompts
						surveyPromptMap.get(survey.getId())
					)
				);
			}
			
			result.put(JSON_KEY_SURVEYS, surveysArray);
		}
		
		return result;
	}
/**
	 * Creates a JSONObject from this campaign.
	 * 
	 * @param withId Whether or not to include the ID.
	 * 
	 * @param withClasses Whether or not to include the list of classes.
	 * 
	 * @param withRoles Whether or not to include the list of roles for all of
	 * 					the users.
	 * 
	 * @param withParticipants If 'withRoles' is true, whether or not to 
	 * 						   include the list of participants.
	 * 
	 * @param withAnalysts If 'withRoles' is true, whether or not to include 
	 * 					   the list of analysts.
	 * 
	 * @param withAuthors If 'withRoles' is true, whether or not to include the
	 * 					  list of authors.
	 * 
	 * @param withSupervisors If 'withRoles' is true, whether or not to include
	 * 						  the list of supervisors.
	 * 
	 * @param withXml Whether or not to include the XML.
	 * 
	 * @return A JSONObject that represents this campaign.
	 * 
	 * @throws JSONException Thrown if there is an error creating the 
	 * 						 JSONObject.
	 */
Creates a JSONObject from this campaign.

@param withId Whether or not to include the ID.

@param withClasses Whether or not to include the list of classes.

@param withRoles Whether or not to include the list of roles for all of
the users.

@param withParticipants If 'withRoles' is true, whether or not to
include the list of participants.

@param withAnalysts If 'withRoles' is true, whether or not to include
the list of analysts.

@param withAuthors If 'withRoles' is true, whether or not to include the
list of authors.

@param withSupervisors If 'withRoles' is true, whether or not to include
the list of supervisors.

@param withXml Whether or not to include the XML.

@return A JSONObject that represents this campaign.

@throws JSONException Thrown if there is an error creating the
JSONObject.
Creates a JSONObject from this campaign . @param withId Whether or not to include the ID . @param withClasses Whether or not to include the list of classes . @param withRoles Whether or not to include the list of roles for all of the users . @param withParticipants If ' withRoles ' is true whether or not to include the list of participants . @param withAnalysts If ' withRoles ' is true whether or not to include the list of analysts . @param withAuthors If ' withRoles ' is true whether or not to include the list of authors . @param withSupervisors If ' withRoles ' is true whether or not to include the list of supervisors . @param withXml Whether or not to include the XML . @return A JSONObject that represents this campaign . @throws JSONException Thrown if there is an error creating the JSONObject .
public JSONObject toJson(
			final boolean withId, 
			final boolean withClasses,
			final boolean withRoles, 
			final boolean withParticipants,
			final boolean withAnalysts, 
			final boolean withAuthors,
			final boolean withSupervisors, 
			final boolean withXml,
			final boolean withSurveys,
			final boolean withResponseCounts) 
			throws JSONException, DomainException{
		JSONObject result = new JSONObject();
		if(withId) {
			result.put(JSON_KEY_ID, id);
		}
		result.put(JSON_KEY_NAME, name);
		result.put(JSON_KEY_DESCRIPTION, (description == null) ? "" : description);
		result.put(JSON_KEY_ICON_URL, iconUrl);
		result.put(JSON_KEY_AUTHORED_BY, authoredBy);
		result.put(JSON_KEY_RUNNING_STATE, runningState.name().toLowerCase());
		result.put(JSON_KEY_PRIVACY_STATE, privacyState.name().toLowerCase());
		result.put(JSON_KEY_EDITABLE, editable);
		result.put(JSON_KEY_AUTHOR_LIST, authorList);
		if(masks.size() == 0) {
			result
				.put(
					JSON_KEY_CREATION_TIMESTAMP,
					DateTimeUtils
						.getIso8601DateString(creationTimestamp, true));
		}
		else {
			result
				.put(
					JSON_KEY_CREATION_TIMESTAMP,
					DateTimeUtils
						.getIso8601DateString(
							masks.get(masks.size() - 1).getCreationTime(),
							true));
		}
		if(withClasses) {
			result.put(JSON_KEY_CLASSES, classes);
		}
		if(withRoles) {
			JSONObject roles = new JSONObject();
			if(withParticipants) {
				roles.put(JSON_KEY_PARTICIPANT, getParticipants());
			}
			if(withAnalysts) {
				roles.put(JSON_KEY_ANALYST, getAnalysts());
			}
			if(withAuthors) {
				roles.put(JSON_KEY_AUTHOR, getAuthors());
			}
			if(withSupervisors) {
				roles.put(JSON_KEY_SUPERVISOR, getSupervisors());
			}
			result.put(JSON_KEY_ROLES, roles);
		}
		if (withResponseCounts){
		    JSONObject counts = new JSONObject();
		    for (SurveyResponse.PrivacyState ps : SurveyResponse.PrivacyState.values()){
			Integer count = surveyResponseCounts.get(ps);
			if (count != null)
			    counts.put(ps.toString(), surveyResponseCounts.get(ps));
			else counts.put(ps.toString(), 0);
		    }
		    result.put(JSON_KEY_SURVEY_RESPONSE_COUNT, counts);
		}
		if(withXml) {
			result.put(JSON_KEY_XML, getXml());
		}
		if(withSurveys) {
			Map<String, Set<String>> surveyPromptMap = null;
			if(masks.size() > 0) {
				surveyPromptMap = masks.get(masks.size() - 1).getSurveyPromptMap();
			}
			JSONArray surveysArray = new JSONArray();
			for(Survey survey : surveyMap.values()) {
				if(
					(surveyPromptMap != null) && 
					(! surveyPromptMap.containsKey(survey.getId()))) {
					continue;
				}
				surveysArray.put( 
					survey.toJson(
						true,	
						true,	
						true,	
						true,	
						true,	
						true,	
						true,	
						surveyPromptMap.get(survey.getId())
					)
				);
			}
			result.put(JSON_KEY_SURVEYS, surveysArray);
		}
		return result;
	}
public JSONObject toJson ( final boolean withId , final boolean withClasses , final boolean withRoles , final boolean withParticipants , final boolean withAnalysts , final boolean withAuthors , final boolean withSupervisors , final boolean withXml , final boolean withSurveys , final boolean withResponseCounts ) throws JSONException , DomainException { JSONObject result = new JSONObject ( ) ; if ( withId ) { result . put ( JSON_KEY_ID , id ) ; } result . put ( JSON_KEY_NAME , name ) ; result . put ( JSON_KEY_DESCRIPTION , ( description == null ) ? "" : description ) ; result . put ( JSON_KEY_ICON_URL , iconUrl ) ; result . put ( JSON_KEY_AUTHORED_BY , authoredBy ) ; result . put ( JSON_KEY_RUNNING_STATE , runningState . name ( ) . toLowerCase ( ) ) ; result . put ( JSON_KEY_PRIVACY_STATE , privacyState . name ( ) . toLowerCase ( ) ) ; result . put ( JSON_KEY_EDITABLE , editable ) ; result . put ( JSON_KEY_AUTHOR_LIST , authorList ) ; if ( masks . size ( ) == 0 ) { result . put ( JSON_KEY_CREATION_TIMESTAMP , DateTimeUtils . getIso8601DateString ( creationTimestamp , true ) ) ; } else { result . put ( JSON_KEY_CREATION_TIMESTAMP , DateTimeUtils . getIso8601DateString ( masks . get ( masks . size ( ) - 1 ) . getCreationTime ( ) , true ) ) ; } if ( withClasses ) { result . put ( JSON_KEY_CLASSES , classes ) ; } if ( withRoles ) { JSONObject roles = new JSONObject ( ) ; if ( withParticipants ) { roles . put ( JSON_KEY_PARTICIPANT , getParticipants ( ) ) ; } if ( withAnalysts ) { roles . put ( JSON_KEY_ANALYST , getAnalysts ( ) ) ; } if ( withAuthors ) { roles . put ( JSON_KEY_AUTHOR , getAuthors ( ) ) ; } if ( withSupervisors ) { roles . put ( JSON_KEY_SUPERVISOR , getSupervisors ( ) ) ; } result . put ( JSON_KEY_ROLES , roles ) ; } if ( withResponseCounts ) { JSONObject counts = new JSONObject ( ) ; for ( SurveyResponse . PrivacyState ps : SurveyResponse . PrivacyState . values ( ) ) { Integer count = surveyResponseCounts . get ( ps ) ; if ( count != null ) counts . put ( ps . toString ( ) , surveyResponseCounts . get ( ps ) ) ; else counts . put ( ps . toString ( ) , 0 ) ; } result . put ( JSON_KEY_SURVEY_RESPONSE_COUNT , counts ) ; } if ( withXml ) { result . put ( JSON_KEY_XML , getXml ( ) ) ; } if ( withSurveys ) { Map < String , Set < String > > surveyPromptMap = null ; if ( masks . size ( ) > 0 ) { surveyPromptMap = masks . get ( masks . size ( ) - 1 ) . getSurveyPromptMap ( ) ; } JSONArray surveysArray = new JSONArray ( ) ; for ( Survey survey : surveyMap . values ( ) ) { if ( ( surveyPromptMap != null ) && ( ! surveyPromptMap . containsKey ( survey . getId ( ) ) ) ) { continue ; } surveysArray . put ( survey . toJson ( true , true , true , true , true , true , true , surveyPromptMap . get ( survey . getId ( ) ) ) ) ; } result . put ( JSON_KEY_SURVEYS , surveysArray ) ; } return result ; }
Creates a JSONObject from this campaign.
Creates a JSONObject from this campaign .
// add request's user roles // If there is no mask, report the actual campaign creation timestamp. // Otherwise, get the latest mask and use its creation timestamp as // this campaign's timestamp. // Returned the masked XML. // If any masks exist, get the most recent one's survey list. // If the campaign is being masked and this survey isn't part // of the mask, skip it. // ID // Title // Description // Intro Text // Submit Text // Anytime // Prompts