Commit b1f98bbe authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette

Merge branch 'add-report-endpoints' into 'v.3.x.x'

Add report endpoints

See merge request !3
parents 4413946f a65546cf
......@@ -5,7 +5,7 @@ require 'dspace/version'
Gem::Specification.new do |spec|
spec.date = '2016-03-14'
spec.name = "dspace_rest_client"
spec.name = 'dspace_rest_client'
spec.version = Dspace::VERSION
spec.authors = ["Mauricio Giacomini Girardello", "Lucas Ernesto Kindinger", "Bruno Nocera Zanette", "Mateus Rambo Strey"]
spec.email = ["mauriciogiacomini4@gmail.com", "kindingerlek@hotmail.com", "brunonzanette@gmail.com"]
......@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.test_files = `git ls-files -z spec/`.split("\0")
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']
spec.add_runtime_dependency "json", '~> 1.8', '>= 1.8.3'
spec.add_runtime_dependency "resource_kit", "~> 0.1.4"
......@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "net-http-persistent", '~> 2.9', '>= 2.9.4'
spec.add_runtime_dependency "activesupport", '>= 4.2.0'
spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
end
end
\ No newline at end of file
......@@ -5,6 +5,7 @@ require "faraday"
require "active_support/all"
require_relative "dspace/version"
require_relative "dspace/resources/report_resource"
require_relative "dspace/resources/hierarchy_resource"
require_relative "dspace/resources/schema_registry_resource"
require_relative "dspace/resources/community_resource"
......@@ -25,6 +26,8 @@ require_relative "dspace/schema"
require_relative "dspace/metadata_field"
require_relative "dspace/bitstream"
require_relative "dspace/policy"
require_relative "dspace/item_filter"
require_relative "dspace/report"
require_relative "dspace/client"
module Dspace
......
......@@ -74,6 +74,24 @@ module Dspace
colls
end
def self.build_reports(reports=[])
return reports unless reports.is_a? Array
colls = []
reports.each do |c|
colls << Dspace::Report.new(c)
end
colls
end
def self.build_item_filters(item_filters=[])
return item_filters unless item_filters.is_a? Array
colls = []
item_filters.each do |c|
colls << Dspace::ItemFilter.new(c)
end
colls
end
def self.models2hash(list)
if list.is_a? Array
list.map do |m|
......
......@@ -29,7 +29,8 @@ module Dspace
status: ::Dspace::Resources::StatusResource,
authentication: ::Dspace::Resources::AuthenticationResource,
schema_registry: ::Dspace::Resources::SchemaRegistryResource,
hierarchy: ::Dspace::Resources::HierarchyResource
hierarchy: ::Dspace::Resources::HierarchyResource,
report: ::Dspace::Resources::ReportResource
}
end
......
module Dspace
class ItemFilter
attr_reader :category, :filter_name, :title
def initialize(args={})
@category = args['category']
@filter_name = args['filter-name']
@title = args['title']
end
def to_h
{category: @category, 'filter-name': @filter_name, title: @title}
end
end
end
module Dspace
class Report
attr_reader :nickname, :url
def initialize(args={})
@nickname = args['nickname']
@url = args['url']
end
def to_h
{nickname: @nickname, url: @url}
end
end
end
module Dspace
module Resources
class ReportResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
# GET /reports
# => Return a list of report tools built on the rest api
# TODO: Fix response error
action :reports,
'GET /rest/reports' do
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_reports(JSON.parse(response.body))
end
end
# GET /reports/{nickname}
# => Return a redirect to a specific report
# TODO: Fix response error
action :reports_by_nickname,
'GET /rest/reports/:nickname' do
handler(200) do |response|
response.body
end
end
# GET /filters
# => Return a list of use case filters available for quality control reporting
action :filters,
'GET /rest/filters' do
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_item_filters(JSON.parse(response.body))
end
end
# GET /filtered-collections
# => Return collections and item counts based on pre-defined filters
# TODO: Fix query keys
# TODO: Test it!
action :filtered_collections,
'GET /rest/filtered-collections' do
query_keys :limit, :offset, :expand, :filters, :collection
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_collections(JSON.parse(response.body))
end
end
# GET /filtered-collections/{collection_id}
# => Return items and item counts for a collection based on pre-defined filters
# TODO: Fix query keys
# TODO: Test it!
action :filtered_collections_by_id,
'GET /rest/filtered-collections/:collection_id' do
query_keys :limit, :offset, :expand, :filters, :collection
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body)['items'])
end
end
# GET /filtered-items
# => Retrieve a set of items based on a metadata query and a set of filters
action :filtered_items,
'GET /rest/filtered-items' do
query_keys :'collSel[]', :'query_field[]', :'query_op[]', :'query_val[]', :limit, :offset, :expand, :filters
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body)['items'])
end
end
end
end
end
end
module Dspace
VERSION = "3.0.0"
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment