From d3909d50612cce3d7bd9ac98e36731d2cac325c7 Mon Sep 17 00:00:00 2001
From: Matheus Agio Nerone <man13@inf.ufpr.br>
Date: Mon, 14 Sep 2015 14:18:57 -0300
Subject: [PATCH] fix typo at edge_methods, fix merge modifications

Signed-off-by: Matheus Agio Nerone <man13@inf.ufpr.br>
---
 app/controllers/welcome_controller.rb         | 17 ++++++------
 .../orient_db/learning_object_repository.rb   | 26 +------------------
 app/views/welcome/index.html.erb              | 22 +++++++++++-----
 lib/orient_db/methods/edge_methods.rb         |  4 +--
 lib/tasks/mainPage.rake                       | 21 +++++----------
 5 files changed, 34 insertions(+), 56 deletions(-)

diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index 2e7f45d27..3039b8696 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -10,19 +10,18 @@ class WelcomeController < ApplicationController
     end
 
     @General = mainPage[0]["highlights"].collect do |id|
-      repository.for(:learning_object).find_by_id(id)[0]
+      repository.for(:learning_object).find(id)
     end
 
     @Subjects = repository.for(:subject).find_all.take(8)
+    @Subjects.delete_if do |subject|
+      if subject['highlights'].nil? || subject['highlights'].empty?
+        true
+      end
+    end
     @Subjects.each do |subject|
-      puts subject['highlights'].first
-      puts '@@@@'
-      object = repository.for(:learning_object).find_by_id(subject['highlights'].first)
-      puts object
-      puts '@@@@'
-      subject['first_highlight'] = object[0]
-      puts subject
-      puts '------------------'
+      object = repository.for(:learning_object).find(subject['highlights'].first)
+      subject['first_highlight'] = object
     end
 
   end
diff --git a/app/repositories/orient_db/learning_object_repository.rb b/app/repositories/orient_db/learning_object_repository.rb
index c3ffb3227..5f625e966 100644
--- a/app/repositories/orient_db/learning_object_repository.rb
+++ b/app/repositories/orient_db/learning_object_repository.rb
@@ -37,7 +37,7 @@ module OrientDb
     #   learning_object = repository.for(:learning_objects).get_by_dspace_id 123
     #
     def find(id)
-      result = connection.query "SELECT FROM '#{id}'"
+      result = connection.query "SELECT FROM #{id}"
       build_learning_object result.first
     end
 
@@ -65,29 +65,6 @@ module OrientDb
     #  likes[0]["outE"]
     #end
 
-    def has(rid)
-      connection.query "SELECT expand(in) FROM (SELECT expand(out_has) FROM User WHERE @rid=#{rid})"
-    end
-
-    def find_all
-      connection.query("SELECT FROM LearningObject",{:limit=>-1} )
-    end
-
-    def find_by_id(id)
-      connection.query "SELECT FROM LearningObject where @rid = '#{id}'"
-    end
-
-    def insert_data (name, url)
-      connection.command "INSERT INTO LearningObject (name,URL) VALUES ('#{name}','#{url}')"
-    end
-
-
-    def destroy_data(id)
-      return @connection.command "DELETE VERTEX LearningObject where @rid = '#{id}'"
-    rescue
-      return nil
-    end
-
     private
 
     def count_likes(learning_object)
@@ -113,7 +90,6 @@ module OrientDb
       hash.each do |h|
         learning_objects << build_learning_object(h)
       end
-
       learning_objects
     end
 
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb
index 4dee39f87..0eccf9226 100644
--- a/app/views/welcome/index.html.erb
+++ b/app/views/welcome/index.html.erb
@@ -59,11 +59,15 @@
                   </a>
                 </div>
                 <div class="media-body">
-                  <h4 class="media-heading"><%= highlight['name'] %></h4>
+                  <% if highlight.title.nil? %>
+                  <h4 class="media-heading">Sem Título</h4>
+                  <% else %>
+                  <h4 class="media-heading"><%= highlight.title %></h4>
+                  <% end %>
                   <span>Por <a>Usuário&nbsp</a></span>
-                  <span class="glyphicon glyphicon-eye-open"><%= highlight['views'] %>&nbsp </span>
-                  <span class="glyphicon glyphicon-star"><%= highlight['likes'] %>&nbsp</span><br>
-                  <%= highlight['description']%><br>
+                  <span class="glyphicon glyphicon-eye-open"><%= highlight.views.count %>&nbsp </span>
+                  <span class="glyphicon glyphicon-star"><%= highlight.likes.count %>&nbsp</span><br>
+                  <%= highlight.description%><br>
                   Em<b> Biologia</b>, <b>Biologia Marinha</b>
                 </div>
               </div>
@@ -80,17 +84,22 @@
 
   <div class="row">
     <div class="col-md-11 col-sm-offset-1 padding-left-0">
+      <% unless @Subjects.nil? || @Subjects.empty?%>
       <h2>Em Destaque</h2>
         <ul class="list-unstyled">
           <% @Subjects.each do |subject|%>
           <li class="col-sm-3 padding-left-0">
             <div class="media">
-              <h4><b><%= subject['name']%></b></h4>
+              <h4><b><%= subject['name'].truncate(20)%></b></h4>
               <div>
                 <img src="http://dummyimage.com/250x150/363336/fff" alt='dummy image' class="img-responsive">
               </div>
               <div class="media-body">
-                <h4 class="media-heading"><%= subject['first_highlight']['name'] %></h4>
+                <% if subject['first_highlight'].title.nil? %>
+                  <h4 class="media-heading">Sem Título</h4>
+                <% else %>
+                  <h4 class="media-heading"><%= subject['first_highlight'].title %></h4>
+                <% end %>
                 <span>Por <a>Usuário&nbsp</a></span>
                 <span class="glyphicon glyphicon-eye-open">200&nbsp </span>
                 <span class="glyphicon glyphicon-star">4,5&nbsp</span>
@@ -102,6 +111,7 @@
           </li>
           <% end %>
         </ul>
+      <% end %>
     </div>
   </div>
 </div>
diff --git a/lib/orient_db/methods/edge_methods.rb b/lib/orient_db/methods/edge_methods.rb
index 379a62385..fdca19f5f 100644
--- a/lib/orient_db/methods/edge_methods.rb
+++ b/lib/orient_db/methods/edge_methods.rb
@@ -3,7 +3,7 @@ module OrientDb
     module EdgeMethods
 
       def get_in_edges_count(edge_class, id)
-        connection.query sprintf("SELECT COUNT(@rid) FROM %s WHERE in = %d", edge_class, id)
+        connection.query sprintf("SELECT COUNT(@rid) FROM %s WHERE in = %s", edge_class, id)
       end
 
       def create_edge(edge_class, from_id, to_id)
@@ -12,4 +12,4 @@ module OrientDb
 
     end
   end
-end
\ No newline at end of file
+end
diff --git a/lib/tasks/mainPage.rake b/lib/tasks/mainPage.rake
index d5155cf5a..94e506cc4 100644
--- a/lib/tasks/mainPage.rake
+++ b/lib/tasks/mainPage.rake
@@ -3,12 +3,10 @@ namespace :mainPage do
   task :highlights => :environment do
     repository = Portalmec::Application.repository
     puts 'Generating the main page highlights'
-    objects = repository.for(:learning_object).find_all
+    objects = repository.for(:learning_object).all
     objects = objects.collect do |object|
-      likes = repository.for(:learning_object).get_likes(object['@rid']).size()
-      views = repository.for(:learning_object).get_views(object['@rid']).size()
-      downloads = repository.for(:learning_object).get_downloads(object['@rid']).size()
-      Ranking::Item.new(object['@rid'],views,downloads,likes)
+      downloads = 0
+      Ranking::Item.new(object.id,object.views.count,downloads,object.likes.count)
     end
     rater = Ranking::Rater.new(Ranking::Strategies::BasicRater.new(1000,1,100))
     objects = rater.sortByRate(objects).take(5)
@@ -22,24 +20,19 @@ namespace :mainPage do
 
     puts 'Generate the main page subject highlights'
     subjects = repository.for(:subject).find_all
-    puts 'Found the subjects'
     subjects.each do |subject|
-      puts subject
       #pego os objetos sobre aquele subject
       objects = repository.for(:subject).get_objects(subject['@rid'])
-      puts objects
-      puts '-----------------------------------------------'
       #para todos os objetos eu transformo eles em items para rankear
       objects = objects.collect do |object|
-        likes = repository.for(:learning_object).get_likes(object['@rid']).size()
-        views = repository.for(:learning_object).get_views(object['@rid']).size()
-        downloads = repository.for(:learning_object).get_downloads(object['@rid']).size()
-        Ranking::Item.new(object['@rid'],views,downloads,likes)
+        downloads = 0
+        object = repository.for(:learning_object).find(object['@rid'])
+        Ranking::Item.new(object.id,object.views.count,downloads,object.likes.count)
       end
       #rankeio eles
-      rater = Ranking::Rater.new(Ranking::Strategies::BasicRater.new(1000,1,100))
       objects = rater.sortByRate(objects)
       #adciono no highlights do subject
+      puts subject['name']
       repository.for(:subject).update(subject['@rid'],'set','highlights','[]')
       objects.each do |object|
         repository.for(:subject).update(subject['@rid'],'add','highlights',object.name)
-- 
GitLab