diff --git a/app/models/fragment/project.rb b/app/models/fragment/project.rb index 350fb0d..58f50bb 100755 --- a/app/models/fragment/project.rb +++ b/app/models/fragment/project.rb @@ -33,7 +33,7 @@ end def principal_investigator - Fragment::Person.where(parent_id: id).first + Fragment::Contributor.where(parent_id: id).first end def properties diff --git a/app/models/research_output.rb b/app/models/research_output.rb index 770769b..721aabb 100644 --- a/app/models/research_output.rb +++ b/app/models/research_output.rb @@ -91,10 +91,6 @@ def create_json_fragments FastGettext.with_locale plan.template.locale do - p "######" - p plan.template.locale - p d_("dmpopidor", "Data contact") - p "######" fragment = json_fragment dmp_fragment = plan.json_fragment contact_person = dmp_fragment.persons.first @@ -126,6 +122,7 @@ fragment_description = Fragment::ResearchOutputDescription.new( data: { "title" => fullname, + "type" => other_type_label || type.label, "contact" => { "dbid" => ro_contact.id } }, madmp_schema: MadmpSchema.find_by(name: "ResearchOutputDescriptionStandard"), diff --git a/lib/dmpopidor/models/plan.rb b/lib/dmpopidor/models/plan.rb index 80e1602..060e957 100644 --- a/lib/dmpopidor/models/plan.rb +++ b/lib/dmpopidor/models/plan.rb @@ -145,7 +145,7 @@ ) ################################# - # PERSON & COORDINATORS FRAGMENTS + # PERSON & CONTRIBUTORS FRAGMENTS ################################# person_data = { @@ -190,6 +190,7 @@ project = Fragment::Project.create( data: { "title" => title, + "description" => description, "principalInvestigator" => { "dbid" => project_coordinator.id } }, dmp_id: dmp_fragment.id, @@ -205,6 +206,7 @@ "creationDate" => created_at.strftime("%F"), "lastModifiedDate" => updated_at.strftime("%F"), "dmpLanguage" => template_locale, + "dmpId" => identifier, "contact" => { "dbid" => dmp_coordinator.id } }, dmp_id: dmp_fragment.id, diff --git a/lib/tasks/madmpopidor.rake b/lib/tasks/madmpopidor.rake index f785fa4..524698b 100644 --- a/lib/tasks/madmpopidor.rake +++ b/lib/tasks/madmpopidor.rake @@ -17,6 +17,79 @@ Plan.all.each do |plan| plan.create_plan_fragments if plan.json_fragment.nil? + dmp_fragment = plan.json_fragment + project_fragment = dmp_fragment.project + meta_fragment = dmp_fragment.meta + + FastGettext.with_locale plan.template.locale do + ################################# + # PERSON & CONTRIBUTORS FRAGMENTS + ################################# + # Principal Investigator + pi_person_data = { + "lastName" => plan.principal_investigator, + "mbox" => plan.principal_investigator_email, + "personId" => plan.principal_investigator_identifier + } + pi_person = MadmpFragment.fragment_exists?( + pi_person_data, MadmpSchema.find_by(name: "PersonStandard"), dmp_fragment.id + ) + if pi_person.eql?(false) + principal_investigator = project_fragment.principal_investigator + pi_person = Fragment::Person.create( + data: pi_person_data, + dmp_id: dmp_fragment.id, + madmp_schema: MadmpSchema.find_by(name: "PersonStandard"), + additional_info: { property_name: "person" } + ) + principal_investigator.update( + data: principal_investigator.data.merge("person" => { "dbid" => pi_person.id }) + ) + end + + # Data Contact + dc_person_data = { + "lastName" => plan.data_contact, + "mbox" => plan.data_contact_email + } + data_contact = meta_fragment.contact + dc_person = MadmpFragment.fragment_exists?( + dc_person_data, MadmpSchema.find_by(name: "PersonStandard"), dmp_fragment.id + ) + + if dc_person.eql?(false) + dc_person = Fragment::Person.create( + data: dc_person_data, + dmp_id: dmp_fragment.id, + madmp_schema: MadmpSchema.find_by(name: "PersonStandard"), + additional_info: { property_name: "person" } + ) + end + data_contact.update( + data: data_contact.data.merge("person" => { "dbid" => dc_person.id }) + ) + ################################# + # PROJECT FUNDINGS + ################################# + if plan.grant_number.present? || plan.funder_name.present? + funding = Fragment::Funding.create( + data: { + "grantId" => plan.grant_number + }, + dmp_id: dmp_fragment.id, + parent_id: project_fragment.id, + madmp_schema: MadmpSchema.find_by(name: "FundingStandard"), + additional_info: { property_name: "funding" } + ) + funding.instantiate + funding.funder.update( + additional_info: funding.funder.additional_info.merge( + "custom_value" => plan.funder_name + ) + ) + end + end + plan.research_outputs.each do |research_output| next if research_output.nil? && research_output.json_fragment.present?