Skip to content

Conversation

@momo3404
Copy link
Collaborator

Changes proposed in this PR:

  • Add the question_and_answer flag to the V2 API to enable accessing all questions and answers belonging to a plan in the API response.
  • Per the V2 API Documentation: "The idea is to have a flag titled something like questions_and_answers=true, which
    defaults to false and thereby is compliant with the RDA metadata standard, but can be
    passed in with a value of true to include the questions and answers of the plan."
  • The flag is optional and works with the api/v2/plans and api/v2/plans/[plan_id] endpoints. For example: api/v2/plans/12345?question_and_answer=true.
  • The schema the flag returns is as follows:
  •       "questions_and_answers": {
            "15476": [
              {
                "title": "Question 1",
                "question": "<p>What considerations will you take into account with respect to ethical, legal, or commercial issues?</p>\r\n<p><br>Describe any applicable ethical, legal, or commercial considerations related to your project and data. This includes research involving Indigenous communities and knowledges, human subjects, legal and commercial considerations/agreements, partnerships or data with a high level of risk associated with it.</p>",
                "answer": "<p>test</p>"
              },
              {
                "title": "Question 2",
                "question": "<p>What data will you collect or otherwise bring into your project under this plan?</p>\r\n<p><br>Describe the data that will be collected, generated, and/or acquired.</p>",
                "answer": "<p>test</p>"
              },
            ]
          }
    
  • Questions with no answers are not included in the response.
  • The following file includes an example response to the call api/v2/plans/15476?question_and_answer=true response.json

- This optional parameter is added to the plans endpoints in the V2 API
- This function fetches all questions and answers belonging to a plan.
@github-actions
Copy link

</tr>
1 Error
🚫

Please include a CHANGELOG entry.

You can find it at [CHANGELOG.md](https://github.com/DMPRoadmap/roadmap/blob/main/CHANGELOG.md).

Generated by 🚫 Danger

Comment on lines +60 to +76
if @question_and_answer
json.questions_and_answers do
outputs.each do |output|
presenter = Api::V2::ResearchOutputPresenter.new(output: output)
q_and_a = presenter.send(:fetch_all_q_and_a, plan: plan)
next if q_and_a.blank?

json.set! output.id.to_s do
json.array! q_and_a do |item|
json.title item[:title]
json.question item[:question]
json.answer item[:answer]
end
end
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at the comment at the top of this file:

# Note the symbol of the dmproadmap json object
# nested in extensions which is the container for the json template object, etc.
# A JSON representation of a Data Management Plan in the
# RDA Common Standard format

With the exception of json.extension, I think all of the keys here map onto the RDA-DMP-Common-Standard structure. Maybe this additional data should also be placed inside of json.extension?

if @question_and_answer
json.questions_and_answers do
outputs.each do |output|
presenter = Api::V2::ResearchOutputPresenter.new(output: output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you did this because app/presenters/api/v2/research_output_presenter.rb already has some other q_and_a methods, but I'm not sure about this approach.

It looks like Api::V2::ResearchOutputPresenter is currently only instantiated in app/views/api/v2/datasets/_show.json.jbuilder, which is responsible for the dataset section of the RDA DMP Common Standard structure. Because fetch_all_q_and_a(plan:) isn't being used for that section, I don't think we should define it there.

I worry about directly calling the private fetch_all_q_and_a method from here as well.

Since this view is already instantiating Api::V2::PlanPresenter, maybe defining fetch_all_q_and_a there might better fit the existing architecture?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants