forked from ontoportal/ontologies_linked_data
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/parse-diff-files
- Loading branch information
Showing
5 changed files
with
155 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module LinkedData | ||
module Models | ||
class PortalConfig < LinkedData::Models::Base | ||
model :SemanticArtefactCatalogue, namespace: :mod, name_with: :acronym | ||
attribute :acronym, enforce: [:unique, :existence] | ||
attribute :title, namespace: :dcterms, enforce: [:existence] | ||
attribute :color, enforce: [:existence, :valid_hash_code] | ||
attribute :description, namespace: :dcterms | ||
attribute :logo, namespace: :foaf, enforce: [:url] | ||
attribute :numberOfArtefacts, namespace: :mod, handler: :ontologies_count | ||
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 | ||
|
||
p.acronym = LinkedData.settings.ui_name.downcase | ||
p.title = LinkedData.settings.title | ||
p.description = LinkedData.settings.description | ||
p.color = LinkedData.settings.color | ||
p.logo = LinkedData.settings.logo | ||
p.fundedBy = LinkedData.settings.fundedBy | ||
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 | ||
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) | ||
|
||
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require_relative '../test_case' | ||
|
||
class TestPortalConfiguration < LinkedData::TestCase | ||
|
||
def test_read_portal_config | ||
config = LinkedData::Models::PortalConfig.current_portal_config | ||
|
||
expected = { acronym: 'bioportal', | ||
title: 'NCBO BioPortal', | ||
color: '#234979', | ||
description: "The world's most comprehensive repository of biomedical ontologies", | ||
logo: '', | ||
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 | ||
|