src/org/ohmage/service/UserAnnotationServices.java
public void userCanAccessSurveyResponseAnnotation(final String username, final Collection<String> campaignIds, final UUID surveyResponseId)
		throws ServiceException {
		
		if(StringUtils.isEmptyOrWhitespaceOnly(username)) {
			throw new IllegalArgumentException("A username is required.");
		}
		if(campaignIds == null || campaignIds.isEmpty()) {
			throw new IllegalArgumentException("A non-null, non-empty list of campaign ids is required.");
		}
		if(surveyResponseId == null) {
			throw new IllegalArgumentException("A survey id is required.");
		}
		
		// Get the campaign that the survey id belongs to
		String campaignUrn = SurveyResponseServices.instance().getCampaignForSurveyResponseId(surveyResponseId);
		
		if(campaignUrn == null) {
			throw new ServiceException("Could not find a campaign URN for the survey id " + surveyResponseId);
		}
		
		if(! campaignIds.contains(campaignUrn)) {
			throw new ServiceException(ErrorCode.ANNOTATION_INSUFFICIENT_PERMISSIONS, "A user attempted to update a survey response for a campaign he or she is not a member of.");
		}
		
		// Create a temporary single-item list in order to use
		// UserCampaignServices.getCampaignAndUserRolesForCampaigns()
		LinkedList<String> ll = new LinkedList<String>();
		ll.add(campaignUrn);
		
		// Get the roles for this user in the campaign
		Map<Campaign, List<Campaign.Role>> campaignRoleMap = UserCampaignServices.instance().getCampaignAndUserRolesForCampaigns(username, ll, false);
		
		// Bad! Somehow this user exists in a campaign without a role
		if(campaignRoleMap.isEmpty()) {
			LOGGER.warn("A user is attempting to create a survey response annotation for campaign " + campaignUrn + ", but the user has no role in the campaign.");
			throw new ServiceException(
					ErrorCode.ANNOTATION_INSUFFICIENT_PERMISSIONS, 
					"The logged-in user does not have the permissions to create a survey response annotation.");
		}
		
		// Just grab the only List in the Map
		List<Campaign.Role> roleList = campaignRoleMap.get(campaignRoleMap.keySet().iterator().next());
		
		if(! roleList.contains(Campaign.Role.SUPERVISOR)) {
			throw new ServiceException(
					ErrorCode.ANNOTATION_INSUFFICIENT_PERMISSIONS, 
					"The logged-in user does not have the permissions to create a survey response annotation.");
		}
	}
/**
	 * Determines whether the provided user has the correct role to annotate
	 * the survey response. Only supervisors in campaigns can annotate 
	 * survey responses. 
	 * 
	 * @param username the user attempting to create an annotation
	 * @param campaignIds the campaigns the user belongs to
	 * @param surveyResponseId the survey response id to annotate
	 * @return true if the user can create the annotation; false otherwise.
	 * @throws ServiceException if there was a problem dispatching to the data
	 *                          layer
	 * @throws IllegalArgumentException if the input parameters are malformed  
	 */
Determines whether the provided user has the correct role to annotate
the survey response. Only supervisors in campaigns can annotate
survey responses.

@param username the user attempting to create an annotation
@param campaignIds the campaigns the user belongs to
@param surveyResponseId the survey response id to annotate
@return true if the user can create the annotation; false otherwise.
@throws ServiceException if there was a problem dispatching to the data
layer
@throws IllegalArgumentException if the input parameters are malformed
Determines whether the provided user has the correct role to annotate the survey response . Only supervisors in campaigns can annotate survey responses . @param username the user attempting to create an annotation @param campaignIds the campaigns the user belongs to @param surveyResponseId the survey response id to annotate @return true if the user can create the annotation ; false otherwise . @throws ServiceException if there was a problem dispatching to the data layer @throws IllegalArgumentException if the input parameters are malformed
public void userCanAccessSurveyResponseAnnotation(final String username, final Collection<String> campaignIds, final UUID surveyResponseId)
		throws ServiceException {
		if(StringUtils.isEmptyOrWhitespaceOnly(username)) {
			throw new IllegalArgumentException("A username is required.");
		}
		if(campaignIds == null || campaignIds.isEmpty()) {
			throw new IllegalArgumentException("A non-null, non-empty list of campaign ids is required.");
		}
		if(surveyResponseId == null) {
			throw new IllegalArgumentException("A survey id is required.");
		}
		String campaignUrn = SurveyResponseServices.instance().getCampaignForSurveyResponseId(surveyResponseId);
		if(campaignUrn == null) {
			throw new ServiceException("Could not find a campaign URN for the survey id " + surveyResponseId);
		}
		if(! campaignIds.contains(campaignUrn)) {
			throw new ServiceException(ErrorCode.ANNOTATION_INSUFFICIENT_PERMISSIONS, "A user attempted to update a survey response for a campaign he or she is not a member of.");
		}
		LinkedList<String> ll = new LinkedList<String>();
		ll.add(campaignUrn);
		Map<Campaign, List<Campaign.Role>> campaignRoleMap = UserCampaignServices.instance().getCampaignAndUserRolesForCampaigns(username, ll, false);
		if(campaignRoleMap.isEmpty()) {
			LOGGER.warn("A user is attempting to create a survey response annotation for campaign " + campaignUrn + ", but the user has no role in the campaign.");
			throw new ServiceException(
					ErrorCode.ANNOTATION_INSUFFICIENT_PERMISSIONS, 
					"The logged-in user does not have the permissions to create a survey response annotation.");
		}
		List<Campaign.Role> roleList = campaignRoleMap.get(campaignRoleMap.keySet().iterator().next());
		if(! roleList.contains(Campaign.Role.SUPERVISOR)) {
			throw new ServiceException(
					ErrorCode.ANNOTATION_INSUFFICIENT_PERMISSIONS, 
					"The logged-in user does not have the permissions to create a survey response annotation.");
		}
	}
public void userCanAccessSurveyResponseAnnotation ( final String username , final Collection < String > campaignIds , final UUID surveyResponseId ) throws ServiceException { if ( StringUtils . isEmptyOrWhitespaceOnly ( username ) ) { throw new IllegalArgumentException ( "A username is required." ) ; } if ( campaignIds == null || campaignIds . isEmpty ( ) ) { throw new IllegalArgumentException ( "A non-null, non-empty list of campaign ids is required." ) ; } if ( surveyResponseId == null ) { throw new IllegalArgumentException ( "A survey id is required." ) ; } String campaignUrn = SurveyResponseServices . instance ( ) . getCampaignForSurveyResponseId ( surveyResponseId ) ; if ( campaignUrn == null ) { throw new ServiceException ( "Could not find a campaign URN for the survey id " + surveyResponseId ) ; } if ( ! campaignIds . contains ( campaignUrn ) ) { throw new ServiceException ( ErrorCode . ANNOTATION_INSUFFICIENT_PERMISSIONS , "A user attempted to update a survey response for a campaign he or she is not a member of." ) ; } LinkedList < String > ll = new LinkedList < String > ( ) ; ll . add ( campaignUrn ) ; Map < Campaign , List < Campaign . Role > > campaignRoleMap = UserCampaignServices . instance ( ) . getCampaignAndUserRolesForCampaigns ( username , ll , false ) ; if ( campaignRoleMap . isEmpty ( ) ) { LOGGER . warn ( "A user is attempting to create a survey response annotation for campaign " + campaignUrn + ", but the user has no role in the campaign." ) ; throw new ServiceException ( ErrorCode . ANNOTATION_INSUFFICIENT_PERMISSIONS , "The logged-in user does not have the permissions to create a survey response annotation." ) ; } List < Campaign . Role > roleList = campaignRoleMap . get ( campaignRoleMap . keySet ( ) . iterator ( ) . next ( ) ) ; if ( ! roleList . contains ( Campaign . Role . SUPERVISOR ) ) { throw new ServiceException ( ErrorCode . ANNOTATION_INSUFFICIENT_PERMISSIONS , "The logged-in user does not have the permissions to create a survey response annotation." ) ; } }
Determines whether the provided user has the correct role to annotate
 the survey response.
Determines whether the provided user has the correct role to annotate the survey response .
// Get the campaign that the survey id belongs to // Create a temporary single-item list in order to use // UserCampaignServices.getCampaignAndUserRolesForCampaigns() // Get the roles for this user in the campaign // Bad! Somehow this user exists in a campaign without a role // Just grab the only List in the Map