src/org/ohmage/domain/campaign/Campaign.java
private static Survey processSurvey(
			final Node survey) 
			throws DomainException {
		
		Nodes ids = survey.query(XML_SURVEY_ID);  // required
		if(ids.size() == 0) {  
			throw new DomainException("The survey ID is missing.");
		}
		else if(ids.size() > 1) {
			throw new DomainException(
					"Multiple survey IDs were found for the same survey.");
		}
		String id = validateSurveyId(ids.get(0).getValue());
		
		Nodes titles = survey.query(XML_SURVEY_TITLE);  // required
		if(titles.size() == 0) {  
			throw new DomainException("The survey title is missing: " + id);
		}
		else if(titles.size() > 1) {
			throw new DomainException(
					"Multiple survey titles were found for the same survey: " +
						id);
		}
		String title = titles.get(0).getValue().trim();
		if(title.length() == 0) {
			throw new DomainException(
					"The title cannot be only whitespace: " +
						id);
		}
		
		String description = null;
		Nodes descriptions = survey.query(XML_SURVEY_DESCRIPTION);  // optional
		if(descriptions.size() > 1) {
			throw new DomainException(
					"Multiple survey descriptions were found for the same survey: " + 
						id);
		}
		else if(descriptions.size() == 1) {
			description = descriptions.get(0).getValue().trim();
			
			if(description.length() == 0) {
				throw new DomainException(
						"The survey's description cannot be only whitespace: " +
							id);
			}
		}
		
		String introText = null;
		Nodes introTexts = survey.query(XML_SURVEY_INTRO_TEXT);  // optional
		if(introTexts.size() > 1) {
			throw new DomainException(
					"Multiple survey intro texts were found for the same survey: " + 
						id);
		}
		else if(introTexts.size() == 1) {
			introText = introTexts.get(0).getValue().trim();
			
			if(introText.length() == 0) {
				throw new DomainException(
						"The survey's intro text cannot be only whitespace: " +
							id);
			}
		}
		
		Nodes submitTexts = survey.query(XML_SURVEY_SUBMIT_TEXT);  // required
		if(submitTexts.size() == 0) {
			throw new DomainException("The survey submit text is missing.");
		}
		else if(submitTexts.size() > 1) {
			throw new DomainException(
					"Multiple survey submit texts were found for the same survey: " + 
						id);
		}
		String submitText = submitTexts.get(0).getValue().trim();
		if(submitText.length() == 0) {
			throw new DomainException(
					"The survey's submit text cannot be only whitespace: " +
						id);
		}
		
		Nodes anytimes = survey.query(XML_SURVEY_ANYTIME);  // required
		if(anytimes.size() == 0) {
			throw new DomainException(
					"The survey anytime value is missing: " + id);
		}
		else if(anytimes.size() > 1) {
			throw new DomainException(
					"Multiple survey anytime values were found for the same survey: " + 
						id);
		}
		Boolean anytime = StringUtils.decodeBoolean(anytimes.get(0).getValue().trim());
		if(anytime == null) {
			throw new DomainException(
					"The anytime value is not a valid boolean value: " + id);
		}
		
		Nodes contentLists = survey.query(XML_SURVEY_CONTENT_LIST);  // required
		if(contentLists.size() == 0) {
			throw new DomainException(
					"The survey content list is missing: " + id);
		}
		else if(contentLists.size() > 1) {
			throw new DomainException(
					"Multiple survey content lists were found: " + id);
		}
		Node contentList = contentLists.get(0);
		List<SurveyItem> promptsList = 
			processContentList(id, contentList.query(XML_CONTENT_LIST_ITEMS));
	
		// check for promptID uniqueness within each survey
		Map<Integer, SurveyItem> prompts = 
			new HashMap<Integer, SurveyItem>(promptsList.size());
		Set<String> promptIds = new HashSet<String>();
		for(SurveyItem prompt : promptsList) {
			if(promptIds.add(prompt.getId())) {
				prompts.put(prompt.getIndex(), prompt);
			}
			else {
				throw new DomainException(
						"Multiple prompts have the same unqiue identifier in a group of survey items: " + 
							prompt.getId());
			}
		}
		
		return
			new Survey(
				id, 
				title, 
				description, 
				introText, 
				submitText,
				anytime,
				prompts);
	}
/**
	 * Processes a survey Node and returns a Survey object.
	 * 
	 * @param survey A Node representing a survey.
	 * 
	 * @return A Survey object representing this survey Node from the XML.
	 * 
	 * @throws DomainException Thrown if the survey is invalid.
	 */
Processes a survey Node and returns a Survey object.

@param survey A Node representing a survey.

@return A Survey object representing this survey Node from the XML.

@throws DomainException Thrown if the survey is invalid.
Processes a survey Node and returns a Survey object . @param survey A Node representing a survey . @return A Survey object representing this survey Node from the XML . @throws DomainException Thrown if the survey is invalid .
private static Survey processSurvey(
			final Node survey) 
			throws DomainException {
		Nodes ids = survey.query(XML_SURVEY_ID);  
		if(ids.size() == 0) {  
			throw new DomainException("The survey ID is missing.");
		}
		else if(ids.size() > 1) {
			throw new DomainException(
					"Multiple survey IDs were found for the same survey.");
		}
		String id = validateSurveyId(ids.get(0).getValue());
		Nodes titles = survey.query(XML_SURVEY_TITLE);  
		if(titles.size() == 0) {  
			throw new DomainException("The survey title is missing: " + id);
		}
		else if(titles.size() > 1) {
			throw new DomainException(
					"Multiple survey titles were found for the same survey: " +
						id);
		}
		String title = titles.get(0).getValue().trim();
		if(title.length() == 0) {
			throw new DomainException(
					"The title cannot be only whitespace: " +
						id);
		}
		String description = null;
		Nodes descriptions = survey.query(XML_SURVEY_DESCRIPTION);  
		if(descriptions.size() > 1) {
			throw new DomainException(
					"Multiple survey descriptions were found for the same survey: " + 
						id);
		}
		else if(descriptions.size() == 1) {
			description = descriptions.get(0).getValue().trim();
			if(description.length() == 0) {
				throw new DomainException(
						"The survey's description cannot be only whitespace: " +
							id);
			}
		}
		String introText = null;
		Nodes introTexts = survey.query(XML_SURVEY_INTRO_TEXT);  
		if(introTexts.size() > 1) {
			throw new DomainException(
					"Multiple survey intro texts were found for the same survey: " + 
						id);
		}
		else if(introTexts.size() == 1) {
			introText = introTexts.get(0).getValue().trim();
			if(introText.length() == 0) {
				throw new DomainException(
						"The survey's intro text cannot be only whitespace: " +
							id);
			}
		}
		Nodes submitTexts = survey.query(XML_SURVEY_SUBMIT_TEXT);  
		if(submitTexts.size() == 0) {
			throw new DomainException("The survey submit text is missing.");
		}
		else if(submitTexts.size() > 1) {
			throw new DomainException(
					"Multiple survey submit texts were found for the same survey: " + 
						id);
		}
		String submitText = submitTexts.get(0).getValue().trim();
		if(submitText.length() == 0) {
			throw new DomainException(
					"The survey's submit text cannot be only whitespace: " +
						id);
		}
		Nodes anytimes = survey.query(XML_SURVEY_ANYTIME);  
		if(anytimes.size() == 0) {
			throw new DomainException(
					"The survey anytime value is missing: " + id);
		}
		else if(anytimes.size() > 1) {
			throw new DomainException(
					"Multiple survey anytime values were found for the same survey: " + 
						id);
		}
		Boolean anytime = StringUtils.decodeBoolean(anytimes.get(0).getValue().trim());
		if(anytime == null) {
			throw new DomainException(
					"The anytime value is not a valid boolean value: " + id);
		}
		Nodes contentLists = survey.query(XML_SURVEY_CONTENT_LIST);  
		if(contentLists.size() == 0) {
			throw new DomainException(
					"The survey content list is missing: " + id);
		}
		else if(contentLists.size() > 1) {
			throw new DomainException(
					"Multiple survey content lists were found: " + id);
		}
		Node contentList = contentLists.get(0);
		List<SurveyItem> promptsList = 
			processContentList(id, contentList.query(XML_CONTENT_LIST_ITEMS));
		Map<Integer, SurveyItem> prompts = 
			new HashMap<Integer, SurveyItem>(promptsList.size());
		Set<String> promptIds = new HashSet<String>();
		for(SurveyItem prompt : promptsList) {
			if(promptIds.add(prompt.getId())) {
				prompts.put(prompt.getIndex(), prompt);
			}
			else {
				throw new DomainException(
						"Multiple prompts have the same unqiue identifier in a group of survey items: " + 
							prompt.getId());
			}
		}
		return
			new Survey(
				id, 
				title, 
				description, 
				introText, 
				submitText,
				anytime,
				prompts);
	}
private static Survey processSurvey ( final Node survey ) throws DomainException { Nodes ids = survey . query ( XML_SURVEY_ID ) ; if ( ids . size ( ) == 0 ) { throw new DomainException ( "The survey ID is missing." ) ; } else if ( ids . size ( ) > 1 ) { throw new DomainException ( "Multiple survey IDs were found for the same survey." ) ; } String id = validateSurveyId ( ids . get ( 0 ) . getValue ( ) ) ; Nodes titles = survey . query ( XML_SURVEY_TITLE ) ; if ( titles . size ( ) == 0 ) { throw new DomainException ( "The survey title is missing: " + id ) ; } else if ( titles . size ( ) > 1 ) { throw new DomainException ( "Multiple survey titles were found for the same survey: " + id ) ; } String title = titles . get ( 0 ) . getValue ( ) . trim ( ) ; if ( title . length ( ) == 0 ) { throw new DomainException ( "The title cannot be only whitespace: " + id ) ; } String description = null ; Nodes descriptions = survey . query ( XML_SURVEY_DESCRIPTION ) ; if ( descriptions . size ( ) > 1 ) { throw new DomainException ( "Multiple survey descriptions were found for the same survey: " + id ) ; } else if ( descriptions . size ( ) == 1 ) { description = descriptions . get ( 0 ) . getValue ( ) . trim ( ) ; if ( description . length ( ) == 0 ) { throw new DomainException ( "The survey's description cannot be only whitespace: " + id ) ; } } String introText = null ; Nodes introTexts = survey . query ( XML_SURVEY_INTRO_TEXT ) ; if ( introTexts . size ( ) > 1 ) { throw new DomainException ( "Multiple survey intro texts were found for the same survey: " + id ) ; } else if ( introTexts . size ( ) == 1 ) { introText = introTexts . get ( 0 ) . getValue ( ) . trim ( ) ; if ( introText . length ( ) == 0 ) { throw new DomainException ( "The survey's intro text cannot be only whitespace: " + id ) ; } } Nodes submitTexts = survey . query ( XML_SURVEY_SUBMIT_TEXT ) ; if ( submitTexts . size ( ) == 0 ) { throw new DomainException ( "The survey submit text is missing." ) ; } else if ( submitTexts . size ( ) > 1 ) { throw new DomainException ( "Multiple survey submit texts were found for the same survey: " + id ) ; } String submitText = submitTexts . get ( 0 ) . getValue ( ) . trim ( ) ; if ( submitText . length ( ) == 0 ) { throw new DomainException ( "The survey's submit text cannot be only whitespace: " + id ) ; } Nodes anytimes = survey . query ( XML_SURVEY_ANYTIME ) ; if ( anytimes . size ( ) == 0 ) { throw new DomainException ( "The survey anytime value is missing: " + id ) ; } else if ( anytimes . size ( ) > 1 ) { throw new DomainException ( "Multiple survey anytime values were found for the same survey: " + id ) ; } Boolean anytime = StringUtils . decodeBoolean ( anytimes . get ( 0 ) . getValue ( ) . trim ( ) ) ; if ( anytime == null ) { throw new DomainException ( "The anytime value is not a valid boolean value: " + id ) ; } Nodes contentLists = survey . query ( XML_SURVEY_CONTENT_LIST ) ; if ( contentLists . size ( ) == 0 ) { throw new DomainException ( "The survey content list is missing: " + id ) ; } else if ( contentLists . size ( ) > 1 ) { throw new DomainException ( "Multiple survey content lists were found: " + id ) ; } Node contentList = contentLists . get ( 0 ) ; List < SurveyItem > promptsList = processContentList ( id , contentList . query ( XML_CONTENT_LIST_ITEMS ) ) ; Map < Integer , SurveyItem > prompts = new HashMap < Integer , SurveyItem > ( promptsList . size ( ) ) ; Set < String > promptIds = new HashSet < String > ( ) ; for ( SurveyItem prompt : promptsList ) { if ( promptIds . add ( prompt . getId ( ) ) ) { prompts . put ( prompt . getIndex ( ) , prompt ) ; } else { throw new DomainException ( "Multiple prompts have the same unqiue identifier in a group of survey items: " + prompt . getId ( ) ) ; } } return new Survey ( id , title , description , introText , submitText , anytime , prompts ) ; }
Processes a survey Node and returns a Survey object.
Processes a survey Node and returns a Survey object .
// required // required // optional // optional // required // required // required // check for promptID uniqueness within each survey