<commit_before>class NdlBooksController < ApplicationController
  before_filter :authenticate_user!
  before_filter :check_librarian

  def index
    if params[:page].to_i == 0
      page = 1
    else
      page = params[:page]
    end
    @query = params[:query].to_s.strip
    books = NdlBook.search(params[:query], page)
    @books = WillPaginate::Collection.create(page, NdlBook.per_page, books[:total_entries]) do |pager|
      pager.replace books[:items]
    end
  end

  def create
    if params[:book]
      @manifestation = NdlBook.import_from_sru_response(params[:book][:nbn])
      if @manifestation.try(:save)
        flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.manifestation'))
        flash[:porta_import] == true
        redirect_to manifestation_items_url(@manifestation)
      else
        flash[:notice] = t('enju_ndl.record_not_found')
        redirect_to ndl_books_url
      end
    end
  end

  private
  def check_librarian
    unless current_user.try(:has_role?, 'Librarian')
      access_denied
    end
  end
end<commit_msg>show error message<commit_after>class NdlBooksController < ApplicationController
  before_filter :authenticate_user!
  before_filter :check_librarian

  def index
    if params[:page].to_i == 0
      page = 1
    else
      page = params[:page]
    end
    @query = params[:query].to_s.strip
    books = NdlBook.search(params[:query], page)
    @books = WillPaginate::Collection.create(page, NdlBook.per_page, books[:total_entries]) do |pager|
      pager.replace books[:items]
    end
  end

  def create
    if params[:book]
      @manifestation = NdlBook.import_from_sru_response(params[:book][:nbn])
      respond_to do |format|
        if @manifestation.try(:save)
          flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.manifestation'))
          format.html { redirect_to manifestation_items_url(@manifestation) }
        else
          flash[:notice] = t('enju_ndl.record_not_found')
          format.html { redirect_to ndl_books_url }
        end
      end
    end
  rescue ActiveRecord::RecordInvalid => e
    respond_to do |format|
      flash[:notice] = e.message
      format.html { render :action => "index" }
    end
  end

  private
  def check_librarian
    unless current_user.try(:has_role?, 'Librarian')
      access_denied
    end
  end
end
{'fraction_non_alphanumeric': 0.10530714584203928, 'fraction_numerical': 0.001671541997492687, 'mean_word_length': 3.2597864768683276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3855153', 'n_tokens_mistral': 774, 'n_tokens_neox': 748, 'n_words': 152}