/** {@inheritDoc} */
  @Transactional(rollbackFor = {Throwable.class})
  public void updateSavedSearch(Long savedSearchId, boolean weekly, boolean monthly) {
    SavedSearch savedSearch = hibernateTemplate.get(SavedSearch.class, savedSearchId);

    savedSearch.setMonthly(monthly);
    savedSearch.setWeekly(weekly);

    hibernateTemplate.update(savedSearch);
  }
  /** {@inheritDoc} */
  @Transactional(rollbackFor = {Throwable.class})
  public UserProfile setFilteredWeeklySearchAlert(
      Long userProfileId, String[] subjects, String journal) {
    SearchParameters searchParameters = new SearchParameters();

    searchParameters.setQuery("*:*");
    searchParameters.setFilterJournals(new String[] {journal});
    searchParameters.setFilterSubjectsDisjunction(subjects);

    // We store the saved search here as JSON instead of serializing the object cuz JSON rocks
    SavedSearchQuery query = saveSearchQuery(searchParameters);

    UserProfile user = getUser(userProfileId);
    SavedSearch newSearch = null;

    // See if a record exists already, we only allow one weekly alert of type JOURNAL_ALERT per
    // journal
    // We key off of the title as it is not user facing
    for (SavedSearch savedSearch : user.getSavedSearches()) {
      if (savedSearch.getSearchType() == SavedSearchType.JOURNAL_ALERT
          && savedSearch.getWeekly()
          && savedSearch.getSearchName().equals(journal)) {
        newSearch = savedSearch;
      }
    }

    if (newSearch == null) {
      newSearch = new SavedSearch(journal, query);
      newSearch.setSearchType(SavedSearchType.JOURNAL_ALERT);
      newSearch.setWeekly(true);
      newSearch.setMonthly(false);
      user.getSavedSearches().add(newSearch);
    } else {
      newSearch.setSearchQuery(query);
    }

    hibernateTemplate.save(user);

    return user;
  }
  /** {@inheritDoc} */
  @Transactional(rollbackFor = {Throwable.class})
  @SuppressWarnings("unchecked")
  public void saveSearch(
      Long userProfileId,
      SearchParameters searchParameters,
      String name,
      boolean weekly,
      boolean monthly) {

    UserProfile user = hibernateTemplate.get(UserProfile.class, userProfileId);

    SavedSearchQuery query = saveSearchQuery(searchParameters);

    SavedSearch savedSearch = new SavedSearch(name, query);
    savedSearch.setSearchType(SavedSearchType.USER_DEFINED);
    savedSearch.setWeekly(weekly);
    savedSearch.setMonthly(monthly);

    user.getSavedSearches().add(savedSearch);

    hibernateTemplate.save(user);
  }