diff --git a/app/builders/learning_object_builder.rb b/app/builders/learning_object_builder.rb index cad1fcb5c31e978a9bb27c942b706a2e67539c0b..8203ff0c1873ae46f4dfb8f47c61a81467b43e4d 100644 --- a/app/builders/learning_object_builder.rb +++ b/app/builders/learning_object_builder.rb @@ -18,6 +18,9 @@ # along with portalmec. If not, see <http://www.gnu.org/licenses/>. class LearningObjectBuilder + + I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG = nil + def self.build_from_dspace(item, publisher) lo = LearningObject.new( name: item.name, @@ -34,7 +37,34 @@ class LearningObjectBuilder object_type = lo.get_metadata_value_of('dc.type') object_type = 'Desconhecido' if object_type.blank? - lo.object_type = ObjectType.where(name: object_type).first_or_create + + subjects = lo.get_metadata_values_of('dc.subject') + subjects = ['Outros'] if subjects.blank? + + subjects.each do |subject| + s = Subject.where(name: subject) + if s.blank? + lo.tags << Tag.where(name: subject).first_or_create + else + lo.subjects << s + end + end + + tags = lo.get_metadata_value_of('dc.subject.keyword') + tags = ['Outros'] if tags.blank? + + tags.each do |tg| + tag = Tag.where(name: tg).first_or_create + tagging = Tagging.new(tag: tag, tagger: publisher, taggable: lo) + lo.taggings << tagging + end + + ot = ObjectType.where(name: object_type) + if ot.blank? + lo.object_type = ObjectType.where(name: 'Outros').first + else + lo.object_type = ot.first + end # date = lo.get_metadata_value_of('dc.date.issued') # lo.published_at = Time.iso8601(date) unless date.nil? @@ -49,6 +79,8 @@ class LearningObjectBuilder lo.author = lo.get_metadata_values_of('dc.contributor.author').join(', ') lo.author = publisher.name if lo.author.blank? lo.description = lo.get_metadata_value_of('dc.description') + + lo.link = lo.get_metadata_value_of('dc.relation.uri') lo.state = LearningObject.states[:published] diff --git a/lib/tasks/import/learning_objects.rake b/lib/tasks/import/learning_objects.rake index 9b0947086efb3161a02f3fa00143c4f6951f7b46..7f758426e31f37fe727b229bf0782b72f3497c07 100644 --- a/lib/tasks/import/learning_objects.rake +++ b/lib/tasks/import/learning_objects.rake @@ -31,7 +31,7 @@ namespace :import do # TODO: Deal with already existing item/LO # TODO: Deal with deleted items params = { - q: "search.resourcetype:2", # AND location.coll:4 + # q: "search.resourcetype:2", # AND location.coll:4 fq: "dc.date.accessioned_dt:[NOW-1DAY TO NOW]", wt: "json", indent: "true" @@ -41,7 +41,7 @@ namespace :import do users = User.joins(:roles).where(roles: {name: "partner"}).where.not(dspace_url: [nil, ""], dspace_handle: [nil, ""]) users.each do |user| user_params = params - user_params[:q] += " AND handle: #{user.dspace_handle}/*" + user_params[:q] = "search.resourcetype:2 AND handle: #{user.dspace_handle}" uri.query = URI.encode_www_form(user_params) response = JSON.parse(Net::HTTP.get(uri)) @@ -55,9 +55,12 @@ namespace :import do logger.warn "Received a string instead of item: #{item}" next end + items << item + end - importer = Dspace::LearningObjectImporter.new(items, user) + + importer = Dspace::LearningObjectImporter.new(items, user) importer.import end end