diff --git a/Gemfile b/Gemfile index 39f9bf6780f8841328e72b71fc9f030dad331d24..5e839910a5d477820fdb20069e40a3cf6fe35935 100644 --- a/Gemfile +++ b/Gemfile @@ -69,6 +69,9 @@ gem "rsolr", "~> 1.0.12" #Dspace REST API Integration gem 'dspace_rest_client', '~> 1.1.0' +# pretty logs +gem 'rainbow' + #Chart js gem 'chart-js-rails' @@ -131,4 +134,4 @@ gem 'curb', '~> 0.8.8' # libArchive (Zip, Rar, ...) # C extension is required # For Mac OSX: brew install libarchive && bundle config build.libarchive "--with-opt-dir=/usr/local/opt/libarchive" -gem 'libarchive', '~> 0.1.2' +gem 'libarchive', '~> 0.1.2' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index b8cf4c66f90c51b899e0a92ec74f8b5dd5ce6c15..d4f31c191c7456f76edf08d87c65cc386d2d70f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,8 +164,6 @@ GEM sexp_processor (~> 4.4) globalid (0.3.6) activesupport (>= 4.1.0) - gruff (0.6.0) - rmagick (>= 2.13.4) hitimes (1.2.3) http-cookie (1.0.2) domain_name (~> 0.5) @@ -187,6 +185,7 @@ GEM kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) + libarchive (0.1.2) libv8 (3.16.14.11) locastyle (0.0.1) loofah (2.0.3) @@ -390,12 +389,12 @@ DEPENDENCIES dspace_rest_client (~> 1.1.0) execjs flamegraph - gruff jbuilder (~> 2.0) jquery-rails jquery-turbolinks jquery-ui-rails kaminari + libarchive (~> 0.1.2) locastyle mina orientdb4r @@ -405,6 +404,7 @@ DEPENDENCIES rack-cors rack-mini-profiler rails (= 4.2.0) + rainbow rdoc rmagick rsolr (~> 1.0.12) @@ -426,3 +426,6 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (~> 2.0) whenever + +BUNDLED WITH + 1.10.6 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 4d15ff7a789ec8f8ecaf08165f69a2ae93c40feb..008395584214f4a17d81668aff467b9e033d5d55 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -589,6 +589,16 @@ input.chk { position: relative; overflow: hidden; } + +.add-picture{ + color:#1676bc; +} + + .btn-file { + position: relative; + overflow: hidden; +} + .btn-file input[type=file] { position: absolute; top: 0; @@ -604,3 +614,8 @@ input.chk { cursor: inherit; display: block; } + +.style-cadastro{ + font-color: #343D3E; + font: Arial; +} diff --git a/app/assets/stylesheets/application/users.scss b/app/assets/stylesheets/application/users.scss index 18506d84d196843390c7653887aa399156ea9764..662334523081ba53307701437a3378a5e83ac3ac 100644 --- a/app/assets/stylesheets/application/users.scss +++ b/app/assets/stylesheets/application/users.scss @@ -78,3 +78,7 @@ $background-grey: #e7e7e8; margin-top: 20px; padding: 20px; } + +.avatar_input { + display: none; +} diff --git a/app/models/institution.rb b/app/models/institution.rb index 64a83bf6c51a54af1677755f120a8b44b6a44150..5d73701d480e0174206156871b2a300f01c4fad0 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -1,4 +1,4 @@ class Institution include ActiveModel::Model - attr_accessor :id, :title, :description + attr_accessor :id, :name, :created_at, :last_modified, :country, :city, :description, :thumbnail end diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index bdbe6b2ce2a405fb288a0d1dc59a5825259a5056..da48bf42e04e35545cf6256bfdbaa3931cfae668 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -5,7 +5,7 @@ class LearningObject attr_accessor :id, :id_dspace, :rid, :name, :author, :description, :published_at, :thumbnail, :created_at, :last_modified, :type, :grade_level, :bitstreams, :metadata, :likes, :views, - :downloads, :subjects, :attributes, :score + :downloads, :subjects, :attributes, :score, :publisher validates_presence_of :name, :created_at, :type, :likes, :views, :downloads validates_numericality_of :likes, greater_than_or_equal_to: 0 @@ -20,6 +20,10 @@ class LearningObject collection_repository.find_by_learning_object self end + def publisher + @publisher ||= learning_object_repository.get_publisher(self) + end + def like(user) learning_object_repository.like user, self end diff --git a/app/repositories/orient_db/institution_repository.rb b/app/repositories/orient_db/institution_repository.rb index 028e13b96f04e1747c3e2825ad6e2638be70bb41..ba74fbc5ab7db112eca3dd42230378617b2e3749 100644 --- a/app/repositories/orient_db/institution_repository.rb +++ b/app/repositories/orient_db/institution_repository.rb @@ -2,9 +2,9 @@ module OrientDb class InstitutionRepository < Base include OrientDb::Methods::EdgeMethods - def create(name, url) - connection.command sprintf("INSERT INTO Institution (name) VALUES ('%s')", name) - end + # def create(name) + # connection.command sprintf("INSERT INTO Institution (name) VALUES ('%s')", name) + # end # Usage: # repository.for(:institutions).destroy institution @@ -13,10 +13,19 @@ module OrientDb connection.command sprintf("DELETE VERTEX %s", institution.id) end + def get_by_name(name) + result = select_by_property(odb_class, "name", name) + build_object result.first + end + def build_object(args={}) + if args.nil? + return nil + end + return Institution.new( :id => args["@rid"], - :title => args["title"], + :name => args["name"] ) end diff --git a/app/repositories/orient_db/learning_object_repository.rb b/app/repositories/orient_db/learning_object_repository.rb index 718302ec11b2a69f336b0bf794e144a3d0af9c52..4c2ebfa26262b71faa62a357a7bb89a045ce65d7 100644 --- a/app/repositories/orient_db/learning_object_repository.rb +++ b/app/repositories/orient_db/learning_object_repository.rb @@ -74,12 +74,12 @@ module OrientDb end #it could perhaps be in the GenericMethods, if we'd like to extend to User counting. - def get_number_of_non_visualised() + def get_number_of_non_visualised (connection.query("SELECT COUNT(*) FROM LearningObject WHERE in('Views').size() = 0"))[0]["COUNT"] end #get the ten most visualised. It's probably making too many useless accesses to orientDB... - def get_most_visualised() + def get_most_visualised result = connection.query("SELECT FROM (SELECT @rid,in('Views').size() AS views FROM LearningObject) ORDER BY views DESC LIMIT 10") @most_visualised = [] result.each do |result| @@ -88,6 +88,22 @@ module OrientDb build_objects @most_visualised end + def get_publisher(learning_object) + result = get_edges_end("PublishedBy", "out", learning_object.id) + result = result.first + + unless result.empty? + if result["@class"] == "Institution" + institution_repository.build_object(result) + else + user_repository.build_object(result) + end + end + end + + # Usage: + # learning_object = repository.for(:learning_objects).get_by_dspace_id 123 + # def get_by_dspace_id(id_dspace) result = select_by_property(odb_class, "id_dspace", id_dspace) build_object result.first @@ -123,6 +139,10 @@ module OrientDb unless learning_object.attributes.empty? edges << create_edges_from_array("HasAttr", learning_object.id, learning_object.attributes, true) end + + if !learning_object.publisher.nil? && !edge_exists?("PublishedBy",learning_object.id,learning_object.publisher.id) + edges << create_edge("PublishedBy", learning_object.id, learning_object.publisher.id) + end edges.flatten end @@ -270,4 +290,4 @@ module OrientDb end end -end +end \ No newline at end of file diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index b8d0ffa2d461da4acc4c18de564796f7cd2a1263..d1b073acf4338c592bc62c9e773bc322d7bbd62d 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,34 +1,65 @@ -<h2>Cadastrar</h2> - <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> - - <div class="field"> - <%= f.label :name %><br/> - <%= f.text_field :name, autofocus: true, required: true %> - </div> - - <div class="field"> - <%= f.label :email %><br/> - <%= f.email_field :email, :value => params[:email], required: true %> - </div> - - <div class="field"> - <%= f.label :password %> - <% if @minimum_password_length %> - <em>(<%= @minimum_password_length %> caracteres mÃnimos)</em> - <% end %><br/> - <%= f.password_field :password, autocomplete: "off" %> - </div> - - <div class="field"> - <%= f.label :password_confirmation %><br/> - <%= f.password_field :password_confirmation, autocomplete: "off" %> - </div> - - <div class="actions"> - <%= f.submit "Cadastrar" %> - </div> +<div class="container"> + <div class="row"> + <div class="col-md-12"> + <div class="grey-panel"> + <div class="center_data"> + <div class="style-cadastro"> + <h2> + <font>Cadastre-se</font> + </h2><br/> + </div> + <font> + <%= image_tag image_path("user-anon.png")%><br/> + <div class="btn-file"> + <%=link_to 'adicionar foto', '#', { :class=>"add-picture"}%> + <%= f.file_field :avatar%> + </div> + </font><br/></br> + <div class="col-md-10"> + <p style="line-height: 170%"> + <div class="col-md-10"> + <span class="pull-right">Nome: + <%= f.text_field :name, autofocus: true, required: true , style:"width:335px;"%></span><br/> + </p> + <p style="line-height: 15%"><br/></p> + <p style="line-height: 170%"> + <span class="pull-right">Email: + <%= f.email_field :email, :value => params[:email], required: true, style:"width:335px;" %></span><br/> + </p> + <p style="line-height: 15%"><br/></p> + <p style="line-height: 170%"> + <span class="pull-right">Senha: + <%= f.password_field :password, autocomplete: "off", style:"width:335px;" %><br/> + <% if @minimum_password_length %> + <em>(<%= @minimum_password_length %> caracteres mÃnimos)</em> + <% end %><br/> + </span> + <br/></p></div> + <p style="line-height: 15%"><br/></p> + <p style="line-height: 170%"> + <div class="col-md-10"> + <span class="pull-right">Confirmar senha: + <%= f.password_field :password_confirmation, autocomplete: "off", style:"width:335px;" %> + </span> + </div><br/><br/></p> + </div> + <div class="container-fluid"> + <div class="col-md-offset-3 col-md-5"> + <div class="center_data"> + <div class="col-md-6"> + <br/><span class="pull-right">Já possui conta?</span><br/> + <span class="pull-right"><%= render "devise/shared/links"%></span> + </div> + <div class=" col-md-5"> + <br/><span class="pull-right"><%= f.submit "Cadastrar", :class=> "but but-shadow but-rc" %></span><br/> + </div> + </div> + </div> + </div> + </div> + </div> + </div> +</div> <% end %> - -<%= render "devise/shared/links" %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index cd4f77afa2407f6c35a51cae7d503d7feaeaf245..cbc179c84ad016e18170e998c6dec8907626ab74 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -1,5 +1,5 @@ <%- if controller_name != 'sessions' %> - <%= link_to "Entrar", new_session_path(resource_name) %><br /> + <%= link_to "Entre Aqui", new_session_path(resource_name) , {:class=>'add-picture'} %><br /> <% end -%> <%- if devise_mapping.registerable? && controller_name != 'registrations' %> diff --git a/lib/tasks/dspace.rake b/lib/tasks/dspace.rake index 68b4c1170048d162f922f9a969b1044d015e960b..5d60c8a6afc37ae55c5d87197d04978d3ed9470b 100644 --- a/lib/tasks/dspace.rake +++ b/lib/tasks/dspace.rake @@ -1,10 +1,11 @@ require 'dspace_rest_client' +require 'rainbow' namespace :dspace do desc "Dspace tasks" - task import: :environment do - desc "Import DSpace items to LearningObject Repositoy" + task import_item: :environment do + desc "Import DSpace items to LearningObject Repository" include RepositoriesProxy @@ -16,7 +17,7 @@ namespace :dspace do loop do - puts " --> importing items from #{offset} to #{offset+limit}" + puts Rainbow(" --> importing items from #{offset} to #{offset+limit}").blue begin # Get items from dspace (from offset to offset+limit) @@ -43,26 +44,104 @@ namespace :dspace do learning_object = initialize_learning_object item learning_object_repository.create learning_object end + + # Comment the line below if you don't want print the itens + puts "\t[" + Rainbow(item.id).green.bright + "] " + Rainbow(item.name).yellow.bright end end - end + end + + task import_collection: :environment do + desc "Import DSpace Collections to Institutions Repository" + + include RepositoriesProxy + + # Quantity of items fetched on each iteration + limit = 500 + + # Start point from where items will be fetched + offset = 0 + + loop do + + puts Rainbow(" --> importing Collections from #{offset} to #{offset+limit}").blue + begin + # Get items from dspace (from offset to offset+limit) + dspace_items = get_items_from_dspace(limit,offset) + rescue + # Sleeps for a while to wait database's recovery + sleep(10.seconds) + # Goes to next iteration to retry + next + else + # Terminate loop if there are no more items to import + break if dspace_items.empty? + + # Increment offset, to get new items on next iteration + offset = offset + limit + + dspace_items.each do |item| + + # Checking if Item from DSpace exist in repository + learning_object = learning_object_repository.get_by_dspace_id item.id + + unless learning_object.nil? + + if learning_object.publisher.nil? && !item.parent_collection.nil? + + # Get from repository the institution + institution = institution_repository.get_by_name item.parent_collection.name + + if institution.nil? + institution = initialize_institution item.parent_collection + institution_repository.create institution + end + + # Uncomment the line below if you want print the properties of itens + # puts "\t[" + Rainbow(item.id).green.bright + "] " + Rainbow(item.name).yellow.bright + "[" + Rainbow(item.parent_collection.name).red +"]" + + # Setting publisher of learning_object as institution + learning_object.publisher = institution + learning_object_repository.create_relations(learning_object); + + end + end + end + end + end end private def dspace_repository @dspace_repository ||= Dspace::Client.instance.repository.item_repository + end def get_items_from_dspace(limit, offset) dspace_repository.get_all_items( - expand: ['metadata','bitstreams'], + expand: ['metadata', 'parentCollection','bitstreams'], limit: limit, offset: offset ) end + def initialize_institution item + + current_date = Time.now + + inst = Institution.new( + :name => item.name, + :last_modified => current_date, + :created_at => current_date, + :country => "", + :city => "", + :description => item.short_description + ) + + end + def initialize_learning_object item metadata = build_array_of(item.metadata) bitstreams = build_array_of(item.bit_streams)