src/org/ohmage/service/SurveyResponseReadServices.java
public void performPrivacyFilter(
			final String username, 
			final String campaignId,
			final Collection<SurveyResponse> surveyResponseList) 
			throws ServiceException {
		
		// check for logical errors
		if(StringUtils.isEmptyOrWhitespaceOnly(username) || 
				StringUtils.isEmptyOrWhitespaceOnly(campaignId) || 
				surveyResponseList == null) {
			
			throw new IllegalArgumentException("user, campaignId, and surveyResponseList must all be non-null");
		}
		
		if(surveyResponseList.isEmpty()) {
			return;
		}
		
		try {
			List<Role> userRoles = userCampaignQueries.getUserCampaignRoles(username, campaignId);
			
			// Supervisors can read all data all the time
			if(! userRoles.contains(Campaign.Role.SUPERVISOR)) {
				Campaign.PrivacyState privacyState = 
					campaignQueries.getCampaignPrivacyState(campaignId);
				
				Collection<SurveyResponse> responsesToRemove = new LinkedList<SurveyResponse>();
				for(SurveyResponse currentResult : surveyResponseList) {
					// If they own it, it's ok.
					if(currentResult.getUsername().equals(username)) {
						continue;
					}
					
					// If the survey response is shared,
					if(SurveyResponse.PrivacyState.SHARED.equals(
							currentResult.getPrivacyState())) {
						
						// Authors can always view shared data
						// regardless of the state of the campaign
						if(userRoles.contains(Campaign.Role.AUTHOR)) {
							continue;
						}
						
						// If the campaign is shared and the user is an author
						// or an analyst, it's ok.
						if(Campaign.PrivacyState.SHARED.equals(privacyState) &&
								userRoles.contains(Campaign.Role.ANALYST))
							{
							
							continue;
						}
					}
					
					// If none of the above rules apply, it will fall to this and
					// remove the survey response.
					responsesToRemove.add(currentResult);
				}
				
				surveyResponseList.removeAll(responsesToRemove);
			}
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
/**
	 * <p>Filters the provided surveyResponseList according to our ACL rules for
	 * survey responses:</p>
	 * <ul>
	 * <li>Owners of responses can view their data anytime.</li>
	 * <li>Supervisors can view any user's data anytime.</li>
	 * <li>Authors can view shared responses.</li>
	 * <li>Analysts can view shared responses if the campaign is shared.</li> 
	 * </ul> 
	 * 
	 * <p>This method assumes that the user's role has already been checked
	 * 
	 * @param user The requester's username.
	 * 
	 * @param campaignId The campaign's unique identifier to which all of the
	 * 					 survey responses belong.
	 *  
	 * @param surveyResponseList The collection of survey responses to filter.
	 * 
	 * @return A filtered list of survey response results.
	 */
Filters the provided surveyResponseList according to our ACL rules for
survey responses:

Owners of responses can view their data anytime.
Supervisors can view any user's data anytime.
Authors can view shared responses.
Analysts can view shared responses if the campaign is shared.


This method assumes that the user's role has already been checked

@param user The requester's username.

@param campaignId The campaign's unique identifier to which all of the
survey responses belong.

@param surveyResponseList The collection of survey responses to filter.

@return A filtered list of survey response results.
Filters the provided surveyResponseList according to our ACL rules for survey responses : Owners of responses can view their data anytime . Supervisors can view any user ' s data anytime . Authors can view shared responses . Analysts can view shared responses if the campaign is shared . This method assumes that the user ' s role has already been checked @param user The requester ' s username . @param campaignId The campaign ' s unique identifier to which all of the survey responses belong . @param surveyResponseList The collection of survey responses to filter . @return A filtered list of survey response results .
public void performPrivacyFilter(
			final String username, 
			final String campaignId,
			final Collection<SurveyResponse> surveyResponseList) 
			throws ServiceException {
		if(StringUtils.isEmptyOrWhitespaceOnly(username) || 
				StringUtils.isEmptyOrWhitespaceOnly(campaignId) || 
				surveyResponseList == null) {
			throw new IllegalArgumentException("user, campaignId, and surveyResponseList must all be non-null");
		}
		if(surveyResponseList.isEmpty()) {
			return;
		}
		try {
			List<Role> userRoles = userCampaignQueries.getUserCampaignRoles(username, campaignId);
			if(! userRoles.contains(Campaign.Role.SUPERVISOR)) {
				Campaign.PrivacyState privacyState = 
					campaignQueries.getCampaignPrivacyState(campaignId);
				Collection<SurveyResponse> responsesToRemove = new LinkedList<SurveyResponse>();
				for(SurveyResponse currentResult : surveyResponseList) {
					if(currentResult.getUsername().equals(username)) {
						continue;
					}
					if(SurveyResponse.PrivacyState.SHARED.equals(
							currentResult.getPrivacyState())) {
						if(userRoles.contains(Campaign.Role.AUTHOR)) {
							continue;
						}
						if(Campaign.PrivacyState.SHARED.equals(privacyState) &&
								userRoles.contains(Campaign.Role.ANALYST))
							{
							continue;
						}
					}
					responsesToRemove.add(currentResult);
				}
				surveyResponseList.removeAll(responsesToRemove);
			}
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
public void performPrivacyFilter ( final String username , final String campaignId , final Collection < SurveyResponse > surveyResponseList ) throws ServiceException { if ( StringUtils . isEmptyOrWhitespaceOnly ( username ) || StringUtils . isEmptyOrWhitespaceOnly ( campaignId ) || surveyResponseList == null ) { throw new IllegalArgumentException ( "user, campaignId, and surveyResponseList must all be non-null" ) ; } if ( surveyResponseList . isEmpty ( ) ) { return ; } try { List < Role > userRoles = userCampaignQueries . getUserCampaignRoles ( username , campaignId ) ; if ( ! userRoles . contains ( Campaign . Role . SUPERVISOR ) ) { Campaign . PrivacyState privacyState = campaignQueries . getCampaignPrivacyState ( campaignId ) ; Collection < SurveyResponse > responsesToRemove = new LinkedList < SurveyResponse > ( ) ; for ( SurveyResponse currentResult : surveyResponseList ) { if ( currentResult . getUsername ( ) . equals ( username ) ) { continue ; } if ( SurveyResponse . PrivacyState . SHARED . equals ( currentResult . getPrivacyState ( ) ) ) { if ( userRoles . contains ( Campaign . Role . AUTHOR ) ) { continue ; } if ( Campaign . PrivacyState . SHARED . equals ( privacyState ) && userRoles . contains ( Campaign . Role . ANALYST ) ) { continue ; } } responsesToRemove . add ( currentResult ) ; } surveyResponseList . removeAll ( responsesToRemove ) ; } } catch ( DataAccessException e ) { throw new ServiceException ( e ) ; } }
<p>Filters the provided surveyResponseList according to our ACL rules for
 survey responses:</p>
 <ul>
 <li>Owners of responses can view their data anytime.</li>
 <li>Supervisors can view any user's data anytime.</li>
 <li>Authors can view shared responses.</li>
 <li>Analysts can view shared responses if the campaign is shared.</li>
 </ul>
<p > Filters the provided surveyResponseList according to our ACL rules for survey responses : < / p > <ul > <li > Owners of responses can view their data anytime . < / li > <li > Supervisors can view any user ' s data anytime . < / li > <li > Authors can view shared responses . < / li > <li > Analysts can view shared responses if the campaign is shared . < / li > < / ul >
// check for logical errors // Supervisors can read all data all the time // If they own it, it's ok. // If the survey response is shared, // Authors can always view shared data // regardless of the state of the campaign // If the campaign is shared and the user is an author // or an analyst, it's ok. // If none of the above rules apply, it will fall to this and // remove the survey response.