src/org/ohmage/domain/campaign/Campaign.java
private static String validateCondition(
			final String condition,
			final String surveyItemId,
			final String surveyItemContainerId,
			final List<SurveyItem> alreadyProcessedItemsInSurveyItemGroup) 
			throws DomainException {
		
		Map<String, List<ConditionValuePair>> promptIdAndConditionValues;
		try {
			parserLock.lock();
			promptIdAndConditionValues = 
					ConditionValidator.validate(condition);
		}
		catch(ConditionParseException e) {
			throw new DomainException(e.getMessage(), e);
		}
		finally {
			parserLock.unlock();
		}
		
		for(String promptId : promptIdAndConditionValues.keySet()) {
			// Validate that the prompt/message exists and comes before this prompt/message. 
			// This can only, and must, be true if we have already validated 
			// it.
			SurveyItem conditionSurveyItem = null;
			for(SurveyItem surveyItem : alreadyProcessedItemsInSurveyItemGroup) {
				if(surveyItem.getId().equals(promptId)) {
					// allow both prompt and message to be in the condition
					if( (surveyItem instanceof Prompt) ||
						(surveyItem instanceof Message)) {
						conditionSurveyItem = surveyItem;
						break;
					}
					else {
						throw new DomainException(
							"Only prompts or messages may be part of a condition. The offending ID is " 
							    + promptId + " and the parent id is " + surveyItemContainerId);
					}
				}
			}
			if(conditionSurveyItem == null) {
				throw new DomainException(
						"The survey item is unknown: " + promptId);
			}
			
			// Validate all of the condition-valid pairs for the prompt.
			for(ConditionValuePair pair : promptIdAndConditionValues.get(promptId)) {
				try {
					conditionSurveyItem.validateCondition(pair);
				}
				catch(DomainException e) {
					throw new DomainException(
							"The condition was invalid for the survey item '" +
								surveyItemId +
								"' in the prompt group '" +
								surveyItemContainerId +
								"': " +
								e.getMessage(),
							e);
				}
			}
		}
		
		return condition;
	}
/**
	 * Validates a condition string to ensure that it is well formed, that each
	 * of the prompts in the condition exist before this prompt and in this
	 * survey item container and are allowed to be referenced in a condition,
	 * and that the value associated with that prompt is both applicable and
	 * within the bounds of that instance of that prompt.
	 * 
	 * @param condition The condition string to be validated.
	 * 
	 * @param surveyItemId The ID of the survey item that owns this condition.
	 * 
	 * @param surveyItemContainerId The ID of the survey item that owns the
	 * 								survey item that owns this condition.
	 * 
	 * @param alreadyProcessedItemsInSurveyItemGroup The list of prompts that
	 * 												 have already been 
	 * 												 processed in the order 
	 * 												 that they were processed.
	 * 
	 * @return The condition, validated.
	 * 
	 * @throws DomainException Thrown if the condition is invalid for any 
	 * 						   reason.
	 */
Validates a condition string to ensure that it is well formed, that each
of the prompts in the condition exist before this prompt and in this
survey item container and are allowed to be referenced in a condition,
and that the value associated with that prompt is both applicable and
within the bounds of that instance of that prompt.

@param condition The condition string to be validated.

@param surveyItemId The ID of the survey item that owns this condition.

@param surveyItemContainerId The ID of the survey item that owns the
survey item that owns this condition.

@param alreadyProcessedItemsInSurveyItemGroup The list of prompts that
have already been
processed in the order
that they were processed.

@return The condition, validated.

@throws DomainException Thrown if the condition is invalid for any
reason.
Validates a condition string to ensure that it is well formed that each of the prompts in the condition exist before this prompt and in this survey item container and are allowed to be referenced in a condition and that the value associated with that prompt is both applicable and within the bounds of that instance of that prompt . @param condition The condition string to be validated . @param surveyItemId The ID of the survey item that owns this condition . @param surveyItemContainerId The ID of the survey item that owns the survey item that owns this condition . @param alreadyProcessedItemsInSurveyItemGroup The list of prompts that have already been processed in the order that they were processed . @return The condition validated . @throws DomainException Thrown if the condition is invalid for any reason .
private static String validateCondition(
			final String condition,
			final String surveyItemId,
			final String surveyItemContainerId,
			final List<SurveyItem> alreadyProcessedItemsInSurveyItemGroup) 
			throws DomainException {
		Map<String, List<ConditionValuePair>> promptIdAndConditionValues;
		try {
			parserLock.lock();
			promptIdAndConditionValues = 
					ConditionValidator.validate(condition);
		}
		catch(ConditionParseException e) {
			throw new DomainException(e.getMessage(), e);
		}
		finally {
			parserLock.unlock();
		}
		for(String promptId : promptIdAndConditionValues.keySet()) {
			SurveyItem conditionSurveyItem = null;
			for(SurveyItem surveyItem : alreadyProcessedItemsInSurveyItemGroup) {
				if(surveyItem.getId().equals(promptId)) {
					if( (surveyItem instanceof Prompt) ||
						(surveyItem instanceof Message)) {
						conditionSurveyItem = surveyItem;
						break;
					}
					else {
						throw new DomainException(
							"Only prompts or messages may be part of a condition. The offending ID is " 
							    + promptId + " and the parent id is " + surveyItemContainerId);
					}
				}
			}
			if(conditionSurveyItem == null) {
				throw new DomainException(
						"The survey item is unknown: " + promptId);
			}
			for(ConditionValuePair pair : promptIdAndConditionValues.get(promptId)) {
				try {
					conditionSurveyItem.validateCondition(pair);
				}
				catch(DomainException e) {
					throw new DomainException(
							"The condition was invalid for the survey item '" +
								surveyItemId +
								"' in the prompt group '" +
								surveyItemContainerId +
								"': " +
								e.getMessage(),
							e);
				}
			}
		}
		return condition;
	}
private static String validateCondition ( final String condition , final String surveyItemId , final String surveyItemContainerId , final List < SurveyItem > alreadyProcessedItemsInSurveyItemGroup ) throws DomainException { Map < String , List < ConditionValuePair > > promptIdAndConditionValues ; try { parserLock . lock ( ) ; promptIdAndConditionValues = ConditionValidator . validate ( condition ) ; } catch ( ConditionParseException e ) { throw new DomainException ( e . getMessage ( ) , e ) ; } finally { parserLock . unlock ( ) ; } for ( String promptId : promptIdAndConditionValues . keySet ( ) ) { SurveyItem conditionSurveyItem = null ; for ( SurveyItem surveyItem : alreadyProcessedItemsInSurveyItemGroup ) { if ( surveyItem . getId ( ) . equals ( promptId ) ) { if ( ( surveyItem instanceof Prompt ) || ( surveyItem instanceof Message ) ) { conditionSurveyItem = surveyItem ; break ; } else { throw new DomainException ( "Only prompts or messages may be part of a condition. The offending ID is " + promptId + " and the parent id is " + surveyItemContainerId ) ; } } } if ( conditionSurveyItem == null ) { throw new DomainException ( "The survey item is unknown: " + promptId ) ; } for ( ConditionValuePair pair : promptIdAndConditionValues . get ( promptId ) ) { try { conditionSurveyItem . validateCondition ( pair ) ; } catch ( DomainException e ) { throw new DomainException ( "The condition was invalid for the survey item '" + surveyItemId + "' in the prompt group '" + surveyItemContainerId + "': " + e . getMessage ( ) , e ) ; } } } return condition ; }
Validates a condition string to ensure that it is well formed, that each
 of the prompts in the condition exist before this prompt and in this
 survey item container and are allowed to be referenced in a condition,
 and that the value associated with that prompt is both applicable and
 within the bounds of that instance of that prompt.
Validates a condition string to ensure that it is well formed that each of the prompts in the condition exist before this prompt and in this survey item container and are allowed to be referenced in a condition and that the value associated with that prompt is both applicable and within the bounds of that instance of that prompt .
// Validate that the prompt/message exists and comes before this prompt/message.  // This can only, and must, be true if we have already validated  // it. // allow both prompt and message to be in the condition // Validate all of the condition-valid pairs for the prompt.