/** * Generates a List of unique identifiers for campaigns based on the parameters. The List is based * on the 'campaignIds' parameter unless it is null in which case the List is based on all * campaigns visible to the user. All parameters except 'request' and 'username' are optional and * each will filter the resulting List of campaign identifiers.<br> * <br> * <br> * For example, if 'campaignIds' was null as were 'endDate' and 'privacyState', then what would be * returned would be the intersection of the following lists:<br> * - All of the campaigns to which the user was associated (because 'campaignIds' was null).<br> * - All of the campaigns that are associated with any of the classes whose unique identifier was * in the 'classIds' list.<br> * - All of the campaigns whose creation timestamp was equal to or after 'startDate'<br> * - All of the campaigns whose running state equaled 'runningState'.<br> * - All of the campaigns to which the user had the campaign role 'role'. <br> * <br> * Therefore, if a campaign was associated with a user only through a single class, but that class * wasn't in the 'classIds' list, then that campaign ID would not be returned even if all of the * other parameters matched. * * @param request The Request that is performing this service. * @param username The username of the user. * @param campaignIds An optional Collection of campaign identifiers from which to base the List. * If this is empty, the resulting List will be empty. If this is null, the base List will be * all campaigns to which the user is associated. * @param classIds A Collection of unique identifiers for classes where the resulting list will * only contain campaign identifiers for campaigns that are associated with any of these * classes. * @param startDate A Calendar where only campaigns whose creation timestamp is equal to or after * this date. * @param endDate A Calendar where only campaigns whose creation timestamp is equal to or before * this date. * @param privacyState A campaign privacy state that trims the resulting list of campaigns to only * those that have this privacy state. * @param runningState A campaign running state that trims the resulting list of campaigns to only * those that have this running state. * @param role A campaign role that trims the resulting list of campaigns to only those where the * user has that role in the campaign. * @return A List of campaign unique identifiers based on the 'campaignIds' parameter and trimmed * by the rest of the parameters. * @throws ServiceException Thrown if there is an error. */ public static List<String> getCampaignsForUser( Request request, String username, Collection<String> campaignIds, Collection<String> classIds, Calendar startDate, Calendar endDate, CampaignPrivacyStateCache.PrivacyState privacyState, CampaignRunningStateCache.RunningState runningState, CampaignRoleCache.Role role) throws ServiceException, DataAccessException { Set<String> desiredCampaignIds = new HashSet<String>(); if (campaignIds == null) { // Initializes the list with all of the campaign IDs for the // requesting user. desiredCampaignIds.addAll(UserCampaignDaos.getCampaignIdsAndNameForUser(username).keySet()); } else { // Initializes the list with the campaign IDs in the query. desiredCampaignIds.addAll(campaignIds); } if (classIds != null) { // Get all of the campaigns associated with all of the classes in // the list. for (String classId : classIds) { desiredCampaignIds.retainAll(CampaignClassDaos.getCampaignsAssociatedWithClass(classId)); } } if (startDate != null) { // Get all of the campaigns whose creation timestamp is greater // than or equal to the start date. desiredCampaignIds.retainAll(CampaignDaos.getCampaignsOnOrAfterDate(startDate)); } if (endDate != null) { // Get all of the campaigns whose creation timestamp is less than // or equal to the end date. desiredCampaignIds.retainAll(CampaignDaos.getCampaignsOnOrBeforeDate(endDate)); } if (privacyState != null) { // Get all of the campaigns with a privacy state of 'privacyState'. desiredCampaignIds.retainAll(CampaignDaos.getCampaignsWithPrivacyState(privacyState)); } if (runningState != null) { // Get all of the campaigns with a running state of 'runningState'. desiredCampaignIds.retainAll(CampaignDaos.getCampaignsWithRunningState(runningState)); } if (role != null) { // Get all of the campaigns where the user's role is 'role'. desiredCampaignIds.retainAll(UserCampaignDaos.getCampaignIdsForUserWithRole(username, role)); } return new ArrayList<String>(desiredCampaignIds); }