Commit 79ff2c52 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

remove old _lib files

parent f2dfead4
module DSpaceRest
module Repositories
class AbstractRepository
attr_reader :rest_client
def initialize(rest_client)
@rest_client = rest_client
end
protected
def build_expand_uri(expand = nil)
if expandable_properties.include? expand
"expand=#{expand}"
end
end
end
end
end
\ No newline at end of file
module DSpaceRest
module Repositories
class BitstreamRepository < AbstractRepository
# Bitstreams are files. They have a filename, size (in bytes), and a file format.
# Typically in DSpace, the Bitstream will the "full text" article, or some other media.
# Some files are the actual file that was uploaded (tagged with bundleName:ORIGINAL),
# others are DSpace-generated files that are derivatives or renditions, such as text-extraction, or thumbnails.
# You can download files/bitstreams.
# DSpace doesn't really limit the type of files that it takes in, so this could be PDF, JPG, audio, video, zip,
# or other.
# Also, the logo for a Collection or a Community, is also a Bitstream.
# √ GET /bitstreams - Return all bitstreams in DSpace.
# √ GET /bitstreams/{bitstream id} - Return bitstream.
# GET /bitstreams/{bitstream id}/policy - Return bitstream policies.
# √ GET /bitstreams/{bitstream id}/retrieve - Return data of bitstream.
# POST /bitstreams/{bitstream id}/policy - Add policy to item. You must post a ResourcePolicy
# PUT /bitstreams/{bitstream id}/data - Update data/file of bitstream. You must put the data
# √ PUT /bitstreams/{bitstream id} - Update metadata of bitstream. You must put a Bitstream, does not alter the file/data
# DELETE /bitstreams/{bitstream id} - Delete bitstream from DSpace.
# DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete bitstream policy.
def get_bitstream_by_id(id, expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/bitstreams/#{id}?#{expand_uri}"].get
DSpaceRest::Bitstream.new(JSON.parse(response))
end
def get_all_bitstreams(expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/bitstreams?#{expand_uri}"].get
bit_streams = []
JSON.parse(response).each do |bits|
bit_streams << DSpaceRest::Bitstream.new(bits)
end
bit_streams
end
def retrieve_data(bitstream)
response = rest_client["/bitstreams/#{bitstream.id}/retrieve"].get
end
def update(bitstream)
valid_keys=[:name, :description, :sequenceId]
form = JSON.generate(bitstream.to_h.select { |k, v| valid_keys.include? k })
response = rest_client["/bitstreams/#{bitstream.id}"].put form
end
private
def expandable_properties
["parent","policies","all"]
end
end
end
end
module DSpaceRest
module Repositories
class CollectionRepository < AbstractRepository
# Collections in DSpace are containers of Items
# √ GET /communities/{communityId}/collections - Returns array of collections of community.
# √ GET /collections - Return all collections of DSpace in array.
# √ GET /collections/{collectionId} - Return collection with id.
# √ GET /collections/{collectionId}/items - Return all items of collection.
# √ POST /communities/{communityId}/collections - Create new collections in community. You must post Collection.
# √ POST /collections/{collectionId}/items - Create posted item in collection. You must post an Item
# POST /collections/find-collection - Find collection by passed name.
# PUT /collections/{collectionId} - Update collection. You must put Collection.
# DELETE /collections/{collectionId} - Delete collection from DSpace.
# DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection.
# DELETE /communities/{communityId}/collections/{collectionId} - Delete collection in community.
def get_collection_items(collection)
response = rest_client["/collections/#{collection.id}/items"].get
items = []
JSON.parse(response).each do |item|
items << DSpaceRest::Item.new(item)
end
items
end
def get_collection_by_id(id, expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/collections/#{id}?#{expand_uri}"].get
DSpaceRest::Collection.new(JSON.parse(response))
end
def get_all_collections(expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/collections?#{expand_uri}"].get
collections = []
JSON.parse(response).each do |coll|
collections << DSpaceRest::Collection.new(coll)
end
collections
end
def get_collections_of(community, expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/communities/#{community.id}/collections?#{expand_uri}"].get
collections = []
JSON.parse(response).each do |coll|
collections << DSpaceRest::Collection.new(coll)
end
collections
end
def create_collection_for(community, collection)
form = JSON.generate(collection.to_h)
response = rest_client["/communities/#{community.id}/collections"].post form
DSpaceRest::Collection.new(JSON.parse(response))
end
def create_item_for(collection, item)
form = JSON.generate({"metadata" => item.to_h["metadata"]})
response = rest_client["/collections/#{collection.id}/items"].post form
DSpaceRest::Item.new(JSON.parse(response))
end
private
def expandable_properties
["parentCommunityList","parentCommunity","items","license","logo","all"]
end
end
end
end
\ No newline at end of file
module DSpaceRest
module Repositories
class CommunityRepository < AbstractRepository
# Communities in DSpace are used for organization and hierarchy, and are containers that hold sub-Communities and Collections.
# √ GET /communities - Returns array of all communities in DSpace.
# √ GET /communities/top-communities - Returns array of all top communities in DSpace
# √ GET /communities/{communityId} - Returns community
# √ GET /communities/{communityId}/communities - Returns array of subcommunities of community.
# √ POST /communities - Create new community at top level. You must post community.
# √ POST /communities/{communityId}/communities - Create new subcommunity in community. You must post Community.
# PUT /communities/{communityId} - Update community. You must put Community
# DELETE /communities/{communityId} - Delete community.
# DELETE /communities/{communityId}/communities/{communityId2} - Delete subcommunity in community.
def get_community_by_id(id, expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/communities/#{id}?#{expand_uri}"].get
DSpaceRest::Community.new(JSON.parse(response))
end
def get_all_communities(expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/communities?#{expand_uri}"].get
communities = []
JSON.parse(response).each do |comm|
communities << DSpaceRest::Community.new(comm)
end
communities
end
def get_top_communities(expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/communities/top-communities?#{expand_uri}"].get
communities = []
JSON.parse(response).each do |comm|
communities << DSpaceRest::Community.new(comm)
end
communities
end
def get_subcommunities_of(community, expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/communities/#{community.id}/communities?#{expand_uri}"].get
communities = []
JSON.parse(response).each do |comm|
communities << DSpaceRest::Community.new(comm)
end
communities
end
def create_community(community)
form = JSON.generate(community.to_h)
response = rest_client["/communities"].post form
end
def create_subcommunity_of(community, subcommunity)
form = JSON.generate(subcommunity.to_h)
response = rest_client["/communities/#{community.id}/communities"].post form
DSpaceRest::Community.new(JSON.parse(response))
end
private
def expandable_properties
["parentCommunity","collections","subCommunities","logo","all"]
end
end
end
end
\ No newline at end of file
module DSpaceRest
module Repositories
class DspaceRepository < AbstractRepository
def bitstream_repository
BitstreamRepository.new rest_client
end
def collection_repository
CollectionRepository.new rest_client
end
def community_repository
CommunityRepository.new rest_client
end
def item_repository
ItemRepository.new rest_client
end
def metadata_repository
MetadataRepository.new rest_client
end
end
end
end
\ No newline at end of file
module DSpaceRest
module Repositories
class ItemRepository < AbstractRepository
# Items in DSpace represent a "work" and combine metadata and files, known as Bitstreams
# √ GET /items - Return list of items.
# √ GET /items/{item id} - Return item.
# √ GET /items/{item id}/metadata - Return item metadata.
# √ GET /items/{item id}/bitstreams - Return item bitstreams.
# POST /items/find-by-metadata-field - Find items by metadata entry. You must post a MetadataEntry. DS-2501 - wrong SQL in REST /items/find-by-metadata-field CLOSED
# √ POST /items/{item id}/metadata - Add metadata to item. You must post an array of MetadataEntry
# √ POST /items/{item id}/bitstreams - Add bitstream to item. You must post a Bitstream
# √ PUT /items/{item id}/metadata - Update metadata in item. You must put a MetadataEntry
# √ DELETE /items/{item id} - Delete item.
# DELETE /items/{item id}/metadata - Clear item metadata.
# DELETE /items/{item id}/bitstreams/{bitstream id} - Delete item bitstream.
def get_all_items(expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/items?#{expand_uri}"].get
items = []
JSON.parse(response).each do |item|
items << DSpaceRest::Item.new(item)
end
items
end
def get_item_by_id(id, expand = nil)
expand_uri = build_expand_uri(expand)
response = rest_client["/items/#{id}?#{expand_uri}"].get
DSpaceRest::Item.new(JSON.parse(response))
end
def get_metadata_of(item)
response = rest_client["/items/#{item.id}/metadata"].get
metadata = []
JSON.parse(response).each do |m|
metadata << DSpaceRest::Metadata.new(m)
end
metadata
end
def get_bitstreams_of(item)
response = rest_client["/items/#{item.id}/bitstreams"].get
bitstreams = []
JSON.parse(response).each do |bits|
bitstreams << DSpaceRest::Bitstream.new(bits)
end
bitstreams
end
def create_metadata_for(item)
form = JSON.generate(self.to_h["metadata"])
response = rest_client["/items/#{item.id}/metadata"].put form
end
def create_bitstream_for(item, file, upload_strategy)
response = upload_strategy.upload("/items/#{item.id}/bitstreams", file)
DSpaceRest::Bitstream.new(JSON.parse(response))
end
def delete(item)
response = rest_client["/items/#{item.id}"].delete
end
private
def expandable_properties
["metadata","parentCollection","parentCollectionList","parentCommunityList","bitstreams","all"]
end
end
end
end
\ No newline at end of file
#require 'curl'
module DSpaceRest
module Strategies
module Uploads
class CurlStrategy
def initialize(host_url, token)
@host_url = host_url
@token = token
end
def upload(endpoint, file)
c = Curl::Easy.new(@host_url.concat(endpoint))
c.headers['Accept'] = 'application/json'
c.headers['rest-dspace-token'] = @token
c.multipart_form_post = true
c.ssl_verify_peer = false
c.http_post(Curl::PostField.file('file', file))
c.body_str
end
end
end
end
end
\ No newline at end of file
module DSpaceRest
module Strategies
module Uploads
class RestStrategy
def initialize(rest_client)
@rest_client = rest_client
end
def upload(endpoint, file)
@rest_client[endpoint].post File.read(file)
end
end
end
end
end
\ No newline at end of file
module Dspace
#the current dspace-rest-client version
VERSION = '2.0.0'
end
\ No newline at end of file
# More logical way to require 'dspace-rest-client'
require File.dirname(__FILE__) + '/dspace_client'
require File.dirname(__FILE__) + '/dspacerest/bitstream'
require File.dirname(__FILE__) + '/dspacerest/collection'
require File.dirname(__FILE__) + '/dspacerest/community'
require File.dirname(__FILE__) + '/dspacerest/item'
require File.dirname(__FILE__) + '/dspacerest/metadata'
require File.dirname(__FILE__) + '/dspacerest/repositories/abstract_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/bitstream_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/collection_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/community_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/dspace_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/item_repository'
require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/curl_strategy'
require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/rest_strategy'
require File.dirname(__FILE__) + '/dspacerest/builders/hash_builder'
require File.dirname(__FILE__) + '/dspacerest/builders/model_builder'
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