diff --git a/app/models/fragment/person.rb b/app/models/fragment/person.rb index e0ff50d..f6cd1c7 100755 --- a/app/models/fragment/person.rb +++ b/app/models/fragment/person.rb @@ -19,10 +19,14 @@ class Fragment::Person < MadmpFragment - def roles - contributors = Fragment::Contributor.where("(data->'person'->>'dbid')::int = ?", id) - - contributors.pluck("data->>'role'") + def roles(selected_research_outputs) + Fragment::Contributor.where("(data->'person'->>'dbid')::int = ?", id) + .map do |c| + if c.research_output_id.nil? || selected_research_outputs.include?(c.research_output_id) + c.data["role"] + end + end + .compact end def self.sti_name diff --git a/app/models/madmp_fragment.rb b/app/models/madmp_fragment.rb index 9ce5671..696c76c 100644 --- a/app/models/madmp_fragment.rb +++ b/app/models/madmp_fragment.rb @@ -370,6 +370,12 @@ parent.research_output_fragment end + + def research_output_id + return nil if research_output_fragment.nil? + + research_output_fragment.data["research_output_id"] + end # ================= # = Class methods = # ================= diff --git a/app/views/branded/shared/export/madmp_export_templates/rda/plan.jbuilder b/app/views/branded/shared/export/madmp_export_templates/rda/plan.jbuilder index 2ed8dc3..9ac5d3d 100644 --- a/app/views/branded/shared/export/madmp_export_templates/rda/plan.jbuilder +++ b/app/views/branded/shared/export/madmp_export_templates/rda/plan.jbuilder @@ -27,12 +27,13 @@ json.name contact.person.to_s end json.contributor dmp.persons do |person| - next if person.roles.empty? + roles = person.roles(selected_research_outputs) + next if roles.empty? json.name person.to_s json.mbox person.data["mbox"] - json.role person.roles.uniq - json.contributor_id do + json.role roles.uniq + json.contributor_id do json.identifier person.data["personId"] json.type person.data["idType"] end