Sha256: 60e237bd14a3525a3f5342a9b3b537c6778859d2ba550c85fc4c65f6ee79d527

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require_dependency "publish_my_data/application_controller"

module PublishMyData
  class SparqlController < ApplicationController

    rescue_from PublishMyData::SparqlQueryResultTooLargeException, :with => :show_response_too_large_message
    rescue_from PublishMyData::SparqlQueryExecutionException, :with => :show_sparql_execution_message

    respond_to :html, :csv, :text, :nt, :ttl, :xml, :rdf, :json

    def endpoint
      @query_text = params[:query]

      unless @query_text.blank?
        @sparql_query = PublishMyData::SparqlQuery.new(@query_text, request.format.to_sym)

        if @sparql_query.allow_pagination?
          get_pagination_params
          @sparql_query_result = @sparql_query.paginate(@page, @per_page)
          @more_pages = @sparql_query.as_pagination_query(@page, @per_page, 1).count > @per_page if request.format.html?
        else
          @sparql_query_result = @sparql_query.execute
        end

        respond_with(@sparql_query_result)
      end

    end

    private

    def respond_with_error
      respond_to do |format|
        format.html { render 'endpoint' }
        format.any { head :status => 400 }
      end
    end

    def show_response_too_large_message(e)
      @error_message = "The results for this query are too large to return."
      respond_with_error
    end

    def show_sparql_execution_message(e)
      @error_message = "There was a syntax error in your query: #{e.message}"
      respond_with_error
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
publish_my_data-0.0.3 app/controllers/publish_my_data/sparql_controller.rb
publish_my_data-0.0.2 app/controllers/publish_my_data/sparql_controller.rb
publish_my_data-0.0.1 app/controllers/publish_my_data/sparql_controller.rb