diff --git a/app/controllers/madmp_codebase_controller.rb b/app/controllers/madmp_codebase_controller.rb index e65676a..8355984 100644 --- a/app/controllers/madmp_codebase_controller.rb +++ b/app/controllers/madmp_codebase_controller.rb @@ -13,7 +13,7 @@ # EXAMPLE DATA # file_path = Rails.root.join("config/madmp/schemas/codebase_example_data.json") # response = JSON.load(File.open(file_path)) - # fragment.save_codebase_fragment(response, fragment.madmp_schema) + # fragment.import_with_instructions(response, fragment.madmp_schema) # render json: { # "message" => d_("dmpopidor", 'New data have been added to your plan, please click on the "Reload" button.') # }, status: 200 @@ -27,7 +27,7 @@ "needs_reload" => false }, status: 200 else - fragment.save_codebase_fragment(response["data"], fragment.madmp_schema) + fragment.import_with_instructions(response["data"], fragment.madmp_schema) render json: { "message" => d_("dmpopidor", 'New data have been added to your plan, please click on the "Reload" button.'), "needs_reload" => true @@ -51,27 +51,23 @@ def anr_search anr_project_id = params[:project_id] fragment = MadmpFragment.find(params[:fragment_id]) + dmp_fragment = fragment.dmp script_id = params[:script_id] authorize fragment # EXAMPLE DATA # file_path = Rails.root.join("config/madmp/schemas/anr_example_data.json") # response = JSON.load(File.open(file_path)) - # fragment.save_api_fragment(response, fragment.madmp_schema) + # dmp_fragment.raw_import(response, dmp_fragment.madmp_schema) # render json: { # "message" => d_("dmpopidor", 'New data have been added to your plan, please click on the "Reload" button.') # }, status: 200 # return begin - response = ExternalApis::MadmpCodebaseService.run(script_id, body: - { - "data": anr_project_id, - "dmp_id": fragment.dmp_id - } - ) + response = fetch_run_data(nil, script_id, { "grantId": anr_project_id }) if response["return_code"]&.eql?(0) - fragment.save_codebase_fragment(response["data"], fragment.madmp_schema) + fragment.dmp.raw_import(response["data"], fragment.madmp_schema) render json: { "message" => d_("dmpopidor", 'New data have been added to your plan, please click on the "Reload" button.'), "needs_reload" => true @@ -93,15 +89,17 @@ private - def fetch_run_data(fragment, script_id) + def fetch_run_data(fragment, script_id, params = {}) return {} unless fragment.present? && script_id.present? ExternalApis::MadmpCodebaseService.run(script_id, body: { "data": fragment.data, "schema": {}, + "dmp_language": fragment.dmp.locale, "dmp_id": fragment.dmp_id, - "research_output_id": fragment.research_output_fragment&.id + "research_output_id": fragment.research_output_fragment&.id, + "params": params } ) end diff --git a/app/models/fragment/dmp.rb b/app/models/fragment/dmp.rb index 1f7c032..30c73a3 100755 --- a/app/models/fragment/dmp.rb +++ b/app/models/fragment/dmp.rb @@ -54,6 +54,14 @@ Fragment::Person.where(dmp_id: id) end + def locale + meta.data["dmpLanguage"] + end + + def dmp + self + end + def self.sti_name "dmp" end diff --git a/config/madmp/schemas/anr_example_data.json b/config/madmp/schemas/anr_example_data.json new file mode 100644 index 0000000..7f6df6e --- /dev/null +++ b/config/madmp/schemas/anr_example_data.json @@ -0,0 +1,49 @@ +{ + "project": { + "title": "Modélisation de l'impact climatique d\u2019une maladie émergente, le dépérissement de l'aulne induit par Phytophthora alni", + "acronym": "PHYTOCLIM", + "description": "A partir des années 1990, une nouvelle maladie est apparue sur les aulnes en bordure des cours d\u2019eau. Elle est causée par un microorganisme pathogène, Phytophthora alni, qui attaque les racines des arbres et provoque leur dépérissement. Ce pathogène est une espèce thermophile. Par ailleurs, l\u2019émergence du dépérissement de l\u2019aulne est concomitante avec les années particulièrement chaudes des deux dernières décennies. \nLes facteurs environnementaux, tels que la température moyenne du site et les caractéristiques du sol jouent un rôle important dans l'apparition de la maladie.\nL'objectif de ce projet est :\n\u2022 de modéliser et de prévoir l'effet de l'environnement sur la gravité des épidémies dues à Phytophthora alni et,\n\u2022 de déterminer si les récents changements climatiques pourraient expliquer l'émergence de la maladie.\n", + "funding": [ + { + "funder": { + "name": "Agence Nationale de la Recherche", + "dataPolicy": { + "title": "La politique science ouverte de l'ANR", + "docIdentifier": "https://anr.fr/fr/lanr-et-la-recherche/engagements-et-valeurs/la-science-ouverte/", + "idType": "URL" + }, + "funderId": "http://dx.doi.org/10.13039/501100001665", + "idType": "DOI" + }, + "grantId": "ANR-07-BDIV-0003", + "fundingStatus": "Approuvé" + } + ], + "startDate": null, + "partner": [ + { + "name": "Biodiversité, Gènes et Communautés ", + "rnsr": "200317684N" + }, + { + "name": "Walloon Agricultural Research Centre " + }, + { + "name": "Plant Protection Institute " + } + ], + "principalInvestigator": { + "person": { + "nameType": "Personne", + "lastName": "Marçais", + "firstName": "Benoît", + "affiliationName": "Interactions Arbres/Micro-organismes ", + "affiliationId": "200117307M", + "affiliationIdType": "RNSR" + } + } + }, + "meta": { + "title": "DMP du projet \"Modélisation de l'impact climatique d\u2019une maladie émergente, le dépérissement de l'aulne induit par Phytophthora alni\"" + } +} \ No newline at end of file diff --git a/config/madmp/schemas/codebase_example_data.json b/config/madmp/schemas/codebase_example_data.json index 234a5e9..4c0517d 100644 --- a/config/madmp/schemas/codebase_example_data.json +++ b/config/madmp/schemas/codebase_example_data.json @@ -60,5 +60,5 @@ } ], "acronym": "BioProtect", - "description": "" + "description": "Ma description est cool" } \ No newline at end of file