From 560783f19024681944031348ea02a4e3d77bd8c4 Mon Sep 17 00:00:00 2001 From: Syphax Date: Fri, 30 Aug 2024 10:15:27 +0200 Subject: [PATCH] add the serialize_default for the portal config model --- config/config.rb.sample | 2 +- .../models/portal_config.rb | 26 +++++++++---------- test/models/test_portal_configuration.rb | 8 ++++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/config/config.rb.sample b/config/config.rb.sample index c233196b..d3e9f9e0 100644 --- a/config/config.rb.sample +++ b/config/config.rb.sample @@ -95,7 +95,7 @@ begin config.ui_name = 'Bioportal' config.title = 'NCBO BioPortal' - config.description = "The world's most comprehensive repository of biomedical ontologies " + config.description = "The world's most comprehensive repository of biomedical ontologies" config.color = '#234979' config.logo = '' config.fundedBy = [ diff --git a/lib/ontologies_linked_data/models/portal_config.rb b/lib/ontologies_linked_data/models/portal_config.rb index b3887e03..59e131ea 100644 --- a/lib/ontologies_linked_data/models/portal_config.rb +++ b/lib/ontologies_linked_data/models/portal_config.rb @@ -8,8 +8,10 @@ class PortalConfig < LinkedData::Models::Base attribute :description, namespace: :dcterms attribute :logo, namespace: :foaf, enforce: [:url] attribute :numberOfArtefacts, namespace: :mod, handler: :ontologies_count - attribute :federated_portals - attribute :fundedBy, enforce: [:list] + attribute :federated_portals, handler: :federated_portals_settings + attribute :fundedBy, namespace: :foaf, enforce: [:list] + + serialize_default :acronym, :title, :color, :description, :logo, :numberOfArtefacts, :federated_portals, :fundedBy def self.current_portal_config p = LinkedData::Models::PortalConfig.new @@ -20,29 +22,27 @@ def self.current_portal_config p.color = LinkedData.settings.color p.logo = LinkedData.settings.logo p.fundedBy = LinkedData.settings.fundedBy - p.federated_portals = LinkedData.settings.federated_portals p end + def federated_portals_settings + LinkedData.settings.federated_portals.symbolize_keys + end + def ontologies_count - if current_portal? - LinkedData::Models::Ontology.where(viewingRestriction: 'public').count - else - 0 - end + LinkedData::Models::Ontology.where(viewingRestriction: 'public').count end def self.valid_hash_code(inst, attr) inst.bring(attr) if inst.bring?(attr) str = inst.send(attr) - unless /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/ === str do - return [:valid_hash_code, "Invalid hex color code: '#{str}'. Please provide a valid hex code in the format '#FFF' or '#FFFFFF'."] - end - end - + return if (/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/ === str) + [:valid_hash_code, + "Invalid hex color code: '#{str}'. Please provide a valid hex code in the format '#FFF' or '#FFFFFF'."] end end end end + diff --git a/test/models/test_portal_configuration.rb b/test/models/test_portal_configuration.rb index 2194eebd..dcebbc93 100644 --- a/test/models/test_portal_configuration.rb +++ b/test/models/test_portal_configuration.rb @@ -10,8 +10,6 @@ def test_read_portal_config color: '#234979', description: "The world's most comprehensive repository of biomedical ontologies", logo: '', - federated_portals: { 'agroportal' => { api: 'http://data.agroportal.lirmm.fr', ui: 'http://agroportal.lirmm.fr', apikey: '1cfae05f-9e67-486f-820b-b393dec5764b', color: '#1e2251' }, - 'bioportal' => { api: 'http://data.bioontology.org', ui: 'http://bioportal.bioontology.org', apikey: '4a5011ea-75fa-4be6-8e89-f45c8c84844e', color: '#234979' } }, fundedBy: [{ img_src: 'https://identity.stanford.edu/wp-content/uploads/sites/3/2020/07/block-s-right.png', url: 'https://www.stanford.edu' }, { img_src: 'https://ontoportal.org/images/logo.png', url: 'https://ontoportal.org/' }], id: RDF::URI.new('http://data.bioontology.org/SemanticArtefactCatalogues/bioportal') } @@ -19,5 +17,11 @@ def test_read_portal_config assert config.valid? assert_equal expected, config.to_hash + + expected_federated_portals = { 'agroportal' => { api: 'http://data.agroportal.lirmm.fr', ui: 'http://agroportal.lirmm.fr', apikey: '1cfae05f-9e67-486f-820b-b393dec5764b', color: '#1e2251' }, + 'bioportal' => { api: 'http://data.bioontology.org', ui: 'http://bioportal.bioontology.org', apikey: '4a5011ea-75fa-4be6-8e89-f45c8c84844e', color: '#234979' } }.symbolize_keys + assert_equal expected_federated_portals, config.federated_portals + refute_nil config.numberOfArtefacts end end +