Class: PublishMyData::ResourcesController

Inherits:
ApplicationController show all
Includes:
ResourceRendering
Defined in:
app/controllers/publish_my_data/resources_controller.rb

Instance Method Summary collapse

Instance Method Details

#attempt_local_dereferenceObject

Make a last ditch attempt to dereference the requested url as the resource uri. If it’s not found we 404 with ResourceNotFound.

routes.rb maps this as the final catch-all route.



68
69
70
# File 'app/controllers/publish_my_data/resources_controller.rb', line 68

def attempt_local_dereference
  find_and_render_resource(request.original_url, local: true)
end

#docObject



59
60
61
62
# File 'app/controllers/publish_my_data/resources_controller.rb', line 59

def doc
  uri = Resource.uri_from_host_and_doc_path(request.host, params[:path], params[:format])
  find_and_render_resource(uri, local: true)
end

#idObject

 linked data dereferencing: for id’s just redirect to the doc.  example.com/id/blah



50
51
52
53
54
55
56
# File 'app/controllers/publish_my_data/resources_controller.rb', line 50

def id
  respond_to do |format|
    format.any(:html, :rdf, :ttl, :nt, :json) do
      redirect_to "/doc/#{params[:path]}", :status=> 303
    end
  end
end

#indexObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/publish_my_data/resources_controller.rb', line 13

def index
  resource_criteria = Resource.all

  # TODO: when we get more complicated fitlers, move this out somewhere else.
  resource_criteria = add_type_filter(resource_criteria)
  resource_criteria = add_dataset_filter(resource_criteria)

  @pagination_params = ResourcePaginationParams.from_request(request)
  @resources = Paginator.new(resource_criteria, @pagination_params).paginate

  respond_with(@resources)
end

#showObject

/resource?uri=foo.bar



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/publish_my_data/resources_controller.rb', line 27

def show
  # RubyProf.start
  uri = params[:uri]

  if uri.present?
    begin
      find_and_render_resource(uri, local: uri.starts_with?('http://' + PublishMyData.local_domain))
    rescue Tripod::Errors::ResourceNotFound
      # if it's not there
      respond_to do |format|
        format.html { redirect_to uri }
        # This is meant for UI browsing only, really. Just 404 for other mimes.
        format.any { render :nothing => true, :status => 404, :content_type => 'text/plain' }
      end
    end
  else
    raise Tripod::Errors::ResourceNotFound.new
  end
end