diff --git a/app/models/research_output.rb b/app/models/research_output.rb index df0ffa5..770769b 100644 --- a/app/models/research_output.rb +++ b/app/models/research_output.rb @@ -90,64 +90,70 @@ end def create_json_fragments - fragment = json_fragment - dmp_fragment = plan.json_fragment - contact_person = dmp_fragment.persons.first - if fragment.nil? - # Fetch the first question linked with a ResearchOutputDescription schema - description_question = plan.questions.joins(:madmp_schema) - .find_by(madmp_schemas: { classname: "research_output_description" } ) + 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 + if fragment.nil? + # Fetch the first question linked with a ResearchOutputDescription schema + description_question = plan.questions.joins(:madmp_schema) + .find_by(madmp_schemas: { classname: "research_output_description" } ) - # Creates the main ResearchOutput fragment - fragment = Fragment::ResearchOutput.create( - data: { - "research_output_id" => id - }, - madmp_schema: MadmpSchema.find_by(classname: "research_output"), - dmp_id: dmp_fragment.id, - parent_id: dmp_fragment.id, - additional_info: { property_name: "researchOutput" } - ) - ro_contact = Fragment::Contributor.create( - data: { - "person" => { "dbid" => contact_person.id }, - "role" => d_("dmpopidor", "Data contact") - }, - dmp_id: dmp_fragment.id, - parent_id: nil, - madmp_schema: MadmpSchema.find_by(name: "ResearchOutputContact"), - additional_info: { property_name: "contact" } - ) - fragment_description = Fragment::ResearchOutputDescription.new( - data: { - "title" => fullname, - "contact" => { "dbid" => ro_contact.id } - }, - madmp_schema: MadmpSchema.find_by(name: "ResearchOutputDescriptionStandard"), - dmp_id: dmp_fragment.id, - parent_id: fragment.id, - additional_info: { property_name: "researchOutputDescription" } - ) - fragment_description.instantiate - - unless description_question.nil? - # Create a new answer for the ResearchOutputDescription Question - # This answer will be displayed in the Write Plan tab, pre filled with the ResearchOutputDescription info - fragment_description.answer = Answer.create( - question_id: description_question.id, - research_output_id: id, - plan_id: plan.id, - user_id: plan.users.first.id + # Creates the main ResearchOutput fragment + fragment = Fragment::ResearchOutput.create( + data: { + "research_output_id" => id + }, + madmp_schema: MadmpSchema.find_by(classname: "research_output"), + dmp_id: dmp_fragment.id, + parent_id: dmp_fragment.id, + additional_info: { property_name: "researchOutput" } ) - fragment_description.save! + ro_contact = Fragment::Contributor.create( + data: { + "person" => { "dbid" => contact_person.id }, + "role" => d_("dmpopidor", "Data contact") + }, + dmp_id: dmp_fragment.id, + parent_id: nil, + madmp_schema: MadmpSchema.find_by(name: "ResearchOutputContact"), + additional_info: { property_name: "contact" } + ) + fragment_description = Fragment::ResearchOutputDescription.new( + data: { + "title" => fullname, + "contact" => { "dbid" => ro_contact.id } + }, + madmp_schema: MadmpSchema.find_by(name: "ResearchOutputDescriptionStandard"), + dmp_id: dmp_fragment.id, + parent_id: fragment.id, + additional_info: { property_name: "researchOutputDescription" } + ) + fragment_description.instantiate + + unless description_question.nil? + # Create a new answer for the ResearchOutputDescription Question + # This answer will be displayed in the Write Plan tab, pre filled with the ResearchOutputDescription info + fragment_description.answer = Answer.create( + question_id: description_question.id, + research_output_id: id, + plan_id: plan.id, + user_id: plan.users.first.id + ) + fragment_description.save! + end + else + data = fragment.research_output_description.data.merge( + { + "title" => fullname + } + ) + fragment.research_output_description.update(data: data) end - else - data = fragment.research_output_description.data.merge( - { - "title" => fullname - } - ) - fragment.research_output_description.update(data: data) end end diff --git a/config/locale/en_GB/dmpopidor.po b/config/locale/en_GB/dmpopidor.po index dd31aea..1e265e9 100644 --- a/config/locale/en_GB/dmpopidor.po +++ b/config/locale/en_GB/dmpopidor.po @@ -486,7 +486,7 @@ msgstr "Project coordinator" msgid "Data contact" -msgstr "Personne contact pour les données" +msgstr "Data contact" msgid "Click here to add a new item" msgstr "Click here to add a new item" diff --git a/config/locale/fr_FR/dmpopidor.po b/config/locale/fr_FR/dmpopidor.po index 91f7117..42082c9 100644 --- a/config/locale/fr_FR/dmpopidor.po +++ b/config/locale/fr_FR/dmpopidor.po @@ -488,7 +488,7 @@ msgstr "Coordinateur du projet" msgid "Data contact" -msgstr "Data contact" +msgstr "Personne contact pour les données" msgid "Click here to add a new item" msgstr "Cliquez ici pour ajouter un nouvel élément" diff --git a/config/madmp/schemas/main/ResearchOutputContact-template.json b/config/madmp/schemas/main/ResearchOutputContact-template.json index 1582e69..52afb76 100644 --- a/config/madmp/schemas/main/ResearchOutputContact-template.json +++ b/config/madmp/schemas/main/ResearchOutputContact-template.json @@ -28,7 +28,7 @@ "description": "Rôle d'une personne dans la gestion et production des données", "label@fr_FR": "Rôle", "label@en_GB": "Role", - "const@fr_FR": " Personne contact pour les données", + "const@fr_FR": "Personne contact pour les données", "const@en_GB": "Data contact", "hidden": true } diff --git a/lib/dmpopidor/models/plan.rb b/lib/dmpopidor/models/plan.rb index 46a37f1..80e1602 100644 --- a/lib/dmpopidor/models/plan.rb +++ b/lib/dmpopidor/models/plan.rb @@ -134,87 +134,89 @@ end def create_plan_fragments - dmp_fragment = Fragment::Dmp.create( - data: { - "plan_id" => id - }, - madmp_schema: MadmpSchema.find_by(name: "DMPStandard"), - additional_info: {} - ) - - ################################# - # PERSON & COORDINATORS FRAGMENTS - ################################# - - person_data = { - "lastName" => owner.surname, - "firstName" => owner.firstname, - "mbox" => owner.email - } unless owner.nil? - - person = Fragment::Person.create( - data: person_data || {}, - dmp_id: dmp_fragment.id, - madmp_schema: MadmpSchema.find_by(name: "PersonStandard"), - additional_info: { property_name: "person" } - ) - - dmp_coordinator = Fragment::Contributor.create( - data: { - "person" => { "dbid" => person.id }, - "role" => d_("dmpopidor", "DMP manager") - }, - dmp_id: dmp_fragment.id, - parent_id: nil, - madmp_schema: MadmpSchema.find_by(name: "DMPCoordinator"), - additional_info: { property_name: "contact" } - ) - - project_coordinator = Fragment::Contributor.create( - data: { - "person" => { "dbid" => person.id }, - "role" => d_("dmpopidor", "Project coordinator") - }, - dmp_id: dmp_fragment.id, - parent_id: nil, - madmp_schema: MadmpSchema.find_by(name: "PrincipalInvestigator"), - additional_info: { property_name: "principalInvestigator" } - ) - - ################################# - # META & PROJECT FRAGMENTS - ################################# - - project = Fragment::Project.create( - data: { - "title" => title, - "principalInvestigator" => { "dbid" => project_coordinator.id } - }, - dmp_id: dmp_fragment.id, - parent_id: dmp_fragment.id, - madmp_schema: MadmpSchema.find_by(name: "ProjectStandard"), - additional_info: { property_name: "project" } - ) - project.instantiate - template_locale = template.locale.eql?("en_GB") ? "eng" : "fra" - meta = Fragment::Meta.create( - data: { - "title" => d_("dmpopidor", "\"%{project_title}\" project DMP") % { project_title: title }, - "creationDate" => created_at.strftime("%F"), - "lastModifiedDate" => updated_at.strftime("%F"), - "dmpLanguage" => template_locale, - "contact" => { "dbid" => dmp_coordinator.id } - }, - dmp_id: dmp_fragment.id, - parent_id: dmp_fragment.id, - madmp_schema: MadmpSchema.find_by(name: "MetaStandard"), - additional_info: { property_name: "meta" } - ) - meta.instantiate + FastGettext.with_locale template.locale do + dmp_fragment = Fragment::Dmp.create( + data: { + "plan_id" => id + }, + madmp_schema: MadmpSchema.find_by(name: "DMPStandard"), + additional_info: {} + ) - dmp_coordinator.update(parent_id: meta.id) - project_coordinator.update(parent_id: project.id) + ################################# + # PERSON & COORDINATORS FRAGMENTS + ################################# + + person_data = { + "lastName" => owner.surname, + "firstName" => owner.firstname, + "mbox" => owner.email + } unless owner.nil? + + person = Fragment::Person.create( + data: person_data || {}, + dmp_id: dmp_fragment.id, + madmp_schema: MadmpSchema.find_by(name: "PersonStandard"), + additional_info: { property_name: "person" } + ) + + dmp_coordinator = Fragment::Contributor.create( + data: { + "person" => { "dbid" => person.id }, + "role" => d_("dmpopidor", "DMP manager") + }, + dmp_id: dmp_fragment.id, + parent_id: nil, + madmp_schema: MadmpSchema.find_by(name: "DMPCoordinator"), + additional_info: { property_name: "contact" } + ) + + project_coordinator = Fragment::Contributor.create( + data: { + "person" => { "dbid" => person.id }, + "role" => d_("dmpopidor", "Project coordinator") + }, + dmp_id: dmp_fragment.id, + parent_id: nil, + madmp_schema: MadmpSchema.find_by(name: "PrincipalInvestigator"), + additional_info: { property_name: "principalInvestigator" } + ) + + ################################# + # META & PROJECT FRAGMENTS + ################################# + + project = Fragment::Project.create( + data: { + "title" => title, + "principalInvestigator" => { "dbid" => project_coordinator.id } + }, + dmp_id: dmp_fragment.id, + parent_id: dmp_fragment.id, + madmp_schema: MadmpSchema.find_by(name: "ProjectStandard"), + additional_info: { property_name: "project" } + ) + project.instantiate + + meta = Fragment::Meta.create( + data: { + "title" => d_("dmpopidor", "\"%{project_title}\" project DMP") % { project_title: title }, + "creationDate" => created_at.strftime("%F"), + "lastModifiedDate" => updated_at.strftime("%F"), + "dmpLanguage" => template_locale, + "contact" => { "dbid" => dmp_coordinator.id } + }, + dmp_id: dmp_fragment.id, + parent_id: dmp_fragment.id, + madmp_schema: MadmpSchema.find_by(name: "MetaStandard"), + additional_info: { property_name: "meta" } + ) + meta.instantiate + + dmp_coordinator.update(parent_id: meta.id) + project_coordinator.update(parent_id: project.id) + end end end