diff --git a/app/helpers/madmp_export_helper.rb b/app/helpers/madmp_export_helper.rb index 2250fca..346755f 100644 --- a/app/helpers/madmp_export_helper.rb +++ b/app/helpers/madmp_export_helper.rb @@ -20,6 +20,18 @@ contributors end + def exportable_description(description) + exportable = Loofah.fragment(description).text(encode_special_chars: false).tr("\n\r", " ") + return nil if exportable.eql?("") + + exportable + end + + def extract_keywords(madmp_fragment) + keywords = madmp_fragment.data["uncontrolledKeywords"] || [] + keywords.concat(madmp_fragment.controlled_keyword.pluck("data->>'keyword'")) + keywords + end # def madmp_transform(madmp, export_template, dmp_id) # export_document = {} # variable_array = {} diff --git a/app/models/fragment/person.rb b/app/models/fragment/person.rb index a84bfaf..e0ff50d 100755 --- a/app/models/fragment/person.rb +++ b/app/models/fragment/person.rb @@ -20,8 +20,9 @@ class Fragment::Person < MadmpFragment def roles - Fragment::Contributor.where("(data->'person'->>'dbid')::int = ?", id) - .pluck("data->>'role'") + contributors = Fragment::Contributor.where("(data->'person'->>'dbid')::int = ?", id) + + contributors.pluck("data->>'role'") end def self.sti_name diff --git a/app/views/branded/shared/export/madmp_export_templates/rda/_datasets.jbuilder b/app/views/branded/shared/export/madmp_export_templates/rda/_datasets.jbuilder index cab2603..0873623 100644 --- a/app/views/branded/shared/export/madmp_export_templates/rda/_datasets.jbuilder +++ b/app/views/branded/shared/export/madmp_export_templates/rda/_datasets.jbuilder @@ -10,15 +10,15 @@ dataset_title = dataset.research_output_description.data["title"] json.dataset_id do - json.identifier dataset.data["research_output_id"] - json.type "Internal identifier" + json.identifier dataset.research_output_description.data["datasetId"] || dataset.data["research_output_id"] + json.type dataset.research_output_description.data["datasetId"].present? ? dataset.research_output_description.data["idType"] : d_("dmpopidor", "Local identifier") end - json.description strip_tags(dataset.research_output_description.data["description"]) - json.keyword dataset.research_output_description.data["uncontrolledKeywords"] + json.description exportable_description(dataset.research_output_description.data["description"]) + json.keyword extract_keywords(dataset.research_output_description) json.language dataset.research_output_description.data["language"] json.personal_data dataset.research_output_description.data["containsPersonalData"] if dataset.preservation_issues.present? - json.preservation_statement strip_tags(dataset.preservation_issues.data["description"]) + json.preservation_statement exportable_description(dataset.preservation_issues.data["description"]) else json.preservation_statement "" end @@ -29,13 +29,13 @@ # json.issued dataset.sharing.distribution.data["releaseDate"] json.issued "" json.distribution dataset.sharing.distribution do |distribution| - start_date = distribution.data["licenseStartDate"] ? DateTime.iso8601(distribution.data["licenseStartDate"]).strftime("%FT%T") : nil + start_date = distribution.data["licenseStartDate"] || nil json.access_url distribution.data["accessUrl"] json.available_until distribution.data["availableUntil"] json.byte_size distribution.data["fileVolume"] json.data_access distribution.data["dataAccess"] - json.description strip_tags(distribution.data["description"]) + json.description exportable_description(distribution.data["description"]) json.download_url distribution.data["downloadUrl"] json.format distribution.data["fileFormat"] json.title distribution.data["fileName"] @@ -45,7 +45,7 @@ json.backup_frequency "" json.backup_type "" json.storage_type "" - json.description strip_tags(host.data["description"]) + json.description exportable_description(host.data["description"]) json.availability host.data["availability"] json.certified_with host.data["certification"] json.geo_location host.data["geoLocation"] @@ -67,9 +67,9 @@ end if dataset.documentation_quality.present? - json.data_quality_assurance strip_tags(dataset.documentation_quality.data["description"]) + json.data_quality_assurance exportable_description(dataset.documentation_quality.data["description"]) json.metadata dataset.documentation_quality.metadata_standard do |metadata_standard| - json.description strip_tags("#{metadata_standard.data['name']} - #{metadata_standard.data['description']}") + json.description exportable_description("#{metadata_standard.data['name']} - #{metadata_standard.data['description']}") json.language metadata_standard.data["metadataLanguage"] json.metadata_standard_id do json.identifier metadata_standard.data["metadataStandardId"] @@ -82,20 +82,20 @@ if dataset.data_storage.present? json.security_and_privacy do - json.description strip_tags(dataset.data_storage.data["securityMeasures"]) + json.description exportable_description(dataset.data_storage.data["securityMeasures"]) json.title "Security measures" end else json.security_and_privacy {} end json.technical_resource dataset.technical_resources do |technical_resource| - json.description strip_tags(technical_resource.data["description"]) + json.description exportable_description(technical_resource.data["description"]) json.title technical_resource.data["title"] end ethical_issues_exist.push("#{dataset_title} : #{dataset.research_output_description.data['hasEthicalIssues']}") if dataset.ethical_issues.present? - ethical_issues_description.push(strip_tags("#{dataset_title} : #{dataset.ethical_issues.data['description']}")) + ethical_issues_description.push(exportable_description("#{dataset_title} : #{dataset.ethical_issues.data['description']}")) ethical_issues_report.push( "#{dataset_title} : #{dataset.ethical_issues.resource_reference.pluck("data->'docIdentifier'").join(', ')}" ) 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 bf1acdf..2ed8dc3 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 @@ -6,16 +6,15 @@ json.prettify! -json.dmp do - - json.created DateTime.iso8601(meta.data["creationDate"]).strftime("%FT%T") - json.description strip_tags(meta.data["description"]) +json.dmp do + json.created meta.data["creationDate"] + json.description exportable_description(meta.data["description"]) json.dmp_id do - json.identifier meta.data["dmpId"] || dmp.data["plan_id"] - json.type meta.data["dmpId"] ? meta.data["idType"] : "Internal identifier" + json.identifier meta.data["dmpId"] || plan_url(id: dmp.data["plan_id"]) + json.type meta.data["dmpId"] ? meta.data["idType"] : "URL" end json.language meta.data["dmpLanguage"] - json.modified DateTime.iso8601(meta.data["lastModifiedDate"]).strftime("%FT%T") + json.modified meta.data["lastModifiedDate"] json.title meta.data["title"] contact = meta.contact @@ -27,26 +26,27 @@ json.mbox contact.person.data["mbox"] json.name contact.person.to_s end - json.contributor dmp.persons do |person| + json.contributor dmp.persons do |person| + next if person.roles.empty? + json.name person.to_s json.mbox person.data["mbox"] - json.role person.roles + json.role person.roles.uniq json.contributor_id do json.identifier person.data["personId"] json.type person.data["idType"] end end - json.cost dmp.costs do |cost| + json.cost dmp.costs do |cost| json.currency_code cost.data["currency"] - json.description strip_tags(cost.data["description"]) + json.description exportable_description(cost.data["description"]) || cost.data["costType"] json.title cost.data["title"] json.value cost.data["amount"] end json.project do - start_date = project.data["startDate"] ? DateTime.iso8601(project.data["startDate"]).strftime("%FT%T") : nil - end_date = project.data["endDate"] ? DateTime.iso8601(project.data["endDate"]).strftime("%FT%T") : nil - - json.description strip_tags(project.data["description"]) + start_date = project.data["startDate"] || nil + end_date = project.data["endDate"] || nil + json.description exportable_description(project.data["description"]) json.title project.data["title"] json.start start_date json.end end_date @@ -58,10 +58,10 @@ json.funding_status funding.data["fundingStatus"] json.grant_id do json.identifier funding.data["grantId"] - json.type _("Other") + json.type "Code" end end end json.partial! "shared/export/madmp_export_templates/rda/datasets", datasets: research_outputs, selected_datasets: selected_research_outputs -end \ No newline at end of file +end diff --git a/config/locale/dmpopidor.pot b/config/locale/dmpopidor.pot index faebfba..54efd70 100644 --- a/config/locale/dmpopidor.pot +++ b/config/locale/dmpopidor.pot @@ -581,4 +581,11 @@ ### API ################ msgid "Fragment with id %{id} doesn't exist." +msgstr "" + + +################ +### EXPORT +################ +msgid "Local indentifier" msgstr "" \ No newline at end of file diff --git a/config/locale/en_GB/dmpopidor.po b/config/locale/en_GB/dmpopidor.po index 1e265e9..a2d759b 100644 --- a/config/locale/en_GB/dmpopidor.po +++ b/config/locale/en_GB/dmpopidor.po @@ -577,4 +577,11 @@ ### API ################ msgid "Fragment with id %{id} doesn't exist." -msgstr "Fragment with id %{id} doesn't exist." \ No newline at end of file +msgstr "Fragment with id %{id} doesn't exist." + + +################ +### EXPORT +################ +msgid "Local indentifier" +msgstr "Local indentifier" \ No newline at end of file diff --git a/config/locale/fr_FR/dmpopidor.po b/config/locale/fr_FR/dmpopidor.po index 42082c9..7f74a5b 100644 --- a/config/locale/fr_FR/dmpopidor.po +++ b/config/locale/fr_FR/dmpopidor.po @@ -579,4 +579,11 @@ ### API ################ msgid "Fragment with id %{id} doesn't exist." -msgstr "Le fragment avec l'identifiant %{id} n'existe pas." \ No newline at end of file +msgstr "Le fragment avec l'identifiant %{id} n'existe pas." + + +################ +### EXPORT +################ +msgid "Local indentifier" +msgstr "Identifiant local" \ No newline at end of file