Skip to content
Snippets Groups Projects
Commit febb0bcc authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'issue/359' into 'master'

Create Tags and Subjects relation when imported from DSpaceIssue/359

See merge request !519
parents 557de992 dc4dfd38
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
# along with portalmec. If not, see <http://www.gnu.org/licenses/>. # along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class LearningObjectBuilder class LearningObjectBuilder
I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG = nil
def self.build_from_dspace(item, publisher) def self.build_from_dspace(item, publisher)
lo = LearningObject.new( lo = LearningObject.new(
name: item.name, name: item.name,
...@@ -34,7 +37,34 @@ class LearningObjectBuilder ...@@ -34,7 +37,34 @@ class LearningObjectBuilder
object_type = lo.get_metadata_value_of('dc.type') object_type = lo.get_metadata_value_of('dc.type')
object_type = 'Desconhecido' if object_type.blank? 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') # date = lo.get_metadata_value_of('dc.date.issued')
# lo.published_at = Time.iso8601(date) unless date.nil? # lo.published_at = Time.iso8601(date) unless date.nil?
...@@ -49,6 +79,8 @@ class LearningObjectBuilder ...@@ -49,6 +79,8 @@ class LearningObjectBuilder
lo.author = lo.get_metadata_values_of('dc.contributor.author').join(', ') lo.author = lo.get_metadata_values_of('dc.contributor.author').join(', ')
lo.author = publisher.name if lo.author.blank? lo.author = publisher.name if lo.author.blank?
lo.description = lo.get_metadata_value_of('dc.description') lo.description = lo.get_metadata_value_of('dc.description')
lo.link = lo.get_metadata_value_of('dc.relation.uri')
lo.state = LearningObject.states[:published] lo.state = LearningObject.states[:published]
......
...@@ -31,7 +31,7 @@ namespace :import do ...@@ -31,7 +31,7 @@ namespace :import do
# TODO: Deal with already existing item/LO # TODO: Deal with already existing item/LO
# TODO: Deal with deleted items # TODO: Deal with deleted items
params = { 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]", fq: "dc.date.accessioned_dt:[NOW-1DAY TO NOW]",
wt: "json", wt: "json",
indent: "true" indent: "true"
...@@ -41,7 +41,7 @@ namespace :import do ...@@ -41,7 +41,7 @@ namespace :import do
users = User.joins(:roles).where(roles: {name: "partner"}).where.not(dspace_url: [nil, ""], dspace_handle: [nil, ""]) users = User.joins(:roles).where(roles: {name: "partner"}).where.not(dspace_url: [nil, ""], dspace_handle: [nil, ""])
users.each do |user| users.each do |user|
user_params = params 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) uri.query = URI.encode_www_form(user_params)
response = JSON.parse(Net::HTTP.get(uri)) response = JSON.parse(Net::HTTP.get(uri))
...@@ -55,9 +55,12 @@ namespace :import do ...@@ -55,9 +55,12 @@ namespace :import do
logger.warn "Received a string instead of item: #{item}" logger.warn "Received a string instead of item: #{item}"
next next
end end
items << item items << item
end end
importer = Dspace::LearningObjectImporter.new(items, user)
importer = Dspace::LearningObjectImporter.new(items, user)
importer.import importer.import
end end
end end
......
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