Skip to content
Snippets Groups Projects
Commit bcd7951c authored by Matheus Agio Nerone's avatar Matheus Agio Nerone
Browse files

basic upload, todo: metadata

parent 29274a4f
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,6 @@ class LearningObjectsController < ApplicationController
after_action :increment_learning_object_views, only: [:show]
before_action :authenticate_user!, except: [:index, :show]
before_action :set_complaint_messages, only: :show
before_action :login_on_dspace, only: :create
# GET /learning_objects
# GET /learning_objects.json
......@@ -14,7 +13,7 @@ class LearningObjectsController < ApplicationController
# GET /learning_objects/1
# GET /learning_objects/1.json
def show
@liked = learning_object_repository.liked?(current_user, @learning_object) if user_signed_in?
@liked = learning_object_repository.liked?(current_user, @learning_object) if user_signed_in?
end
# GET /learning_objects/new
......@@ -44,7 +43,7 @@ class LearningObjectsController < ApplicationController
# trata o form do learning object
lo = DSpaceRest::Item.new(args)
dspace_keys = get_dspace_metadata_names("invert")
learning_object_params.each do |k,v|
params[:learning_object].each do |k,v|
unless dspace_keys[k].nil?
if v.kind_of?(Array)
v.each do |item|
......@@ -56,25 +55,25 @@ class LearningObjectsController < ApplicationController
end
end
response = repo.create_item_for(collection, lo)
subjects = []
learning_object_params[:subjects].each do |subject|
subjects << subject_repository.find_by_name(subject)
end
file = learning_object_params[:file]
learning_object_params[:file] = nil
file = params[:learning_object][:file]
repo = Dspace::Client.instance.repository.item_repository
bitstream_response = repo.create_bitstream_for(response, file.tempfile.path, strategy)
subjects = []
params[:learning_object][:subjects].each do |subject|
subjects << subject_repository.find_by_name(subject)
end
@learning_object = LearningObject.new(learning_object_params)
@learning_object.type = get_file_type file
@learning_object.id_dspace = response.id
@learning_object.subjects = subjects
@learning_object.created_at = Time.now
@learning_object.last_modified = Time.now
@learning_object.publisher = current_user
@learning_object.metadata = lo.to_h[:metadata]
@learning_object.bitstreams = []
@learning_object.bitstreams << bitstream_response.as_json
@learning_object.metadata = lo.to_h[:metadata].as_json.to_s.gsub! '=>', ':'
@learning_object.bitstreams = [bitstream_response.as_json]
respond_to do |format|
if learning_object_repository.create @learning_object
......@@ -145,6 +144,20 @@ class LearningObjectsController < ApplicationController
private
def get_file_type(file)
type = file.content_type.split('/').first
case type
when 'video'
"Vídeo"
when 'image'
"Imagem"
when 'audio'
"Áudio"
else
"Outros"
end
end
def get_dspace_metadata_names(invert=nil)
h = {
"dc.title" => "name",
......@@ -173,10 +186,6 @@ class LearningObjectsController < ApplicationController
h
end
def login_on_dspace
Dspace::Client.instance.login 'admin@mecdb3.c3sl.ufpr.br', 'admin'
end
# Use callbacks to share common setup or constraints between actions.
def set_learning_object
@learning_object = learning_object_repository.find params[:id]
......@@ -184,7 +193,7 @@ class LearningObjectsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def learning_object_params
params[:learning_object]
params[:learning_object].permit(:author, :name, :type, :description, :subjects, :school_level)
end
def increment_learning_object_views
......
......@@ -9,9 +9,13 @@ module OrientDb
protected
def execute
create_edge("PublishedBy", @learning_object.id, @learning_object.publisher.id)
if @learning_object.publisher.class.name == "User"
create_edge("PublishedBy", @learning_object.id, @learning_object.publisher.rid)
else
create_edge("PublishedBy", @learning_object.id, @learning_object.publisher.id)
end
end
end
end
end
\ No newline at end of file
end
......@@ -28,8 +28,8 @@
<%= f.text_field :language %><br>
<%= f.label :source, "Fonte" %>
<%= f.text_field :source %><br>
<%= f.label :type, "Tipo de objeto" %>
<%= f.text_field :type %><br>
<!-- <%= f.label :type, "Tipo de objeto" %>
<%= f.text_field :type %><br> -->
<%= f.label :license, "Licença"%>
<%= f.text_field :license %><br>
<%= f.label :copyright, "Detentor dos direitos autorais" %>
......
......@@ -15,4 +15,6 @@ else
config = dspace_configs.fetch(Rails.env)
set_dspace_config config['host'], config['port'], config['rest_webapp_name'], config['solr_webapp_name']
end
\ No newline at end of file
end
Dspace::Client.instance.login 'admin@mecdb3.c3sl.ufpr.br', 'admin'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment