Skip to content

Commit

Permalink
add the serialize_default for the portal config model
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Aug 30, 2024
1 parent 3218f02 commit d893c08
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/config.rb.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
35 changes: 22 additions & 13 deletions lib/ontologies_linked_data/models/portal_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ 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 initialize(*args)
super
init_federated_portals_settings
end

def self.current_portal_config
p = LinkedData::Models::PortalConfig.new
Expand All @@ -20,29 +27,31 @@ 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 init_federated_portals_settings(federated_portals = nil)
@federated_portals = federated_portals || LinkedData.settings.federated_portals.symbolize_keys
end

def federated_portals_settings
@federated_portals
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


8 changes: 6 additions & 2 deletions test/models/test_portal_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ 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') }

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

0 comments on commit d893c08

Please sign in to comment.