Repository: ontoportal-lirmm/ontologies_api
Pull request #142: Feature: use catalog links
Author: login: imadbourouche
Labels: name: enhancement
name: MOD-API
Created: 2025-03-13T14:09:53Z | Merged: 2025-03-19T14:49:24Z

- Fix for : https://github.com/agroportal/project-management/issues/689
- require: https://github.com/ontoportal-lirmm/ontologies_linked_data/pull/200

### What's change
- Remove the links generation logic in the home controller and use the links defined in the SemanticArtefactCatalog model
- result
![image](https://github.com/user-attachments/assets/ad60616a-cf7d-4a66-a5b0-622eb7239aa7)



Diff:
diff --git a/Gemfile.lock b/Gemfile.lock
index 8398ea56a..3e6009e24 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -57,7 +57,7 @@ GIT
 
 GIT
   remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
-  revision: b321d73a28b4f60fc5969da7a071b3c19c1a84f3
+  revision: 11bf507999651a030cb5550423ce67fb301667f4
   branch: development
   specs:
     ontologies_linked_data (0.0.1)
@@ -103,7 +103,7 @@ GIT
 
 GIT
   remote: https://github.com/sinatra/sinatra.git
-  revision: c235249abaafa2780b540aca1813dfcf3d17c2dd
+  revision: cfcc70dee1133690207b5a3dc6000426ec04e250
   specs:
     rack-protection (4.1.1)
       base64 (>= 0.1.0)
@@ -221,23 +221,24 @@ GEM
       mutex_m
       representable (~> 3.0)
       retriable (>= 2.0, < 4.a)
-    google-cloud-core (1.7.1)
+    google-cloud-core (1.8.0)
       google-cloud-env (>= 1.0, < 3.a)
       google-cloud-errors (~> 1.0)
-    google-cloud-env (2.2.1)
+    google-cloud-env (2.2.2)
+      base64 (~> 0.2)
       faraday (>= 1.0, < 3.a)
-    google-cloud-errors (1.4.0)
+    google-cloud-errors (1.5.0)
     google-logging-utils (0.1.0)
-    google-protobuf (4.29.3)
+    google-protobuf (4.30.1)
       bigdecimal
       rake (>= 13)
-    google-protobuf (4.29.3-arm64-darwin)
+    google-protobuf (4.30.1-arm64-darwin)
       bigdecimal
       rake (>= 13)
-    google-protobuf (4.29.3-x86_64-darwin)
+    google-protobuf (4.30.1-x86_64-darwin)
       bigdecimal
       rake (>= 13)
-    google-protobuf (4.29.3-x86_64-linux)
+    google-protobuf (4.30.1-x86_64-linux)
       bigdecimal
       rake (>= 13)
     googleapis-common-protos (1.6.0)
@@ -246,7 +247,7 @@ GEM
       grpc (~> 1.41)
     googleapis-common-protos-types (1.18.0)
       google-protobuf (>= 3.18, < 5.a)
-    googleauth (1.13.1)
+    googleauth (1.14.0)
       faraday (>= 1.0, < 3.a)
       google-cloud-env (~> 2.2)
       google-logging-utils (~> 0.1)
@@ -254,16 +255,16 @@ GEM
       multi_json (~> 1.11)
       os (>= 0.9, < 2.0)
       signet (>= 0.16, < 2.a)
-    grpc (1.70.1)
+    grpc (1.71.0)
       google-protobuf (>= 3.25, < 5.0)
       googleapis-common-protos-types (~> 1.0)
-    grpc (1.70.1-arm64-darwin)
+    grpc (1.71.0-arm64-darwin)
       google-protobuf (>= 3.25, < 5.0)
       googleapis-common-protos-types (~> 1.0)
-    grpc (1.70.1-x86_64-darwin)
+    grpc (1.71.0-x86_64-darwin)
       google-protobuf (>= 3.25, < 5.0)
       googleapis-common-protos-types (~> 1.0)
-    grpc (1.70.1-x86_64-linux)
+    grpc (1.71.0-x86_64-linux)
       google-protobuf (>= 3.25, < 5.0)
       googleapis-common-protos-types (~> 1.0)
     haml (5.2.2)
@@ -278,7 +279,7 @@ GEM
       mutex_m
     i18n (1.14.7)
       concurrent-ruby (~> 1.0)
-    json (2.10.1)
+    json (2.10.2)
     json-canonicalization (0.4.0)
     json-ld (3.2.5)
       htmlentities (~> 4.3)
@@ -306,12 +307,12 @@ GEM
       net-pop
       net-smtp
     method_source (1.1.0)
-    mime-types (3.6.0)
+    mime-types (3.6.1)
       logger
       mime-types-data (~> 3.2015)
-    mime-types-data (3.2025.0220)
+    mime-types-data (3.2025.0318)
     mini_mime (1.1.5)
-    minitest (5.25.4)
+    minitest (5.25.5)
     minitest-fail-fast (0.1.0)
       minitest (~> 5)
     minitest-hooks (1.5.2)
@@ -351,7 +352,7 @@ GEM
     net-ssh (7.3.0)
     netrc (0.11.0)
     newrelic_rpm (9.17.0)
-    oj (3.16.9)
+    oj (3.16.10)
       bigdecimal (>= 3.0)
       ostruct (>= 0.2)
     omni_logger (0.1.4)
@@ -372,7 +373,7 @@ GEM
     public_suffix (6.0.1)
     raabro (1.4.0)
     racc (1.8.1)
-    rack (3.1.10)
+    rack (3.1.12)
     rack-accept (0.4.5)
       rack (>= 0.4)
     rack-attack (6.7.0)
@@ -412,7 +413,7 @@ GEM
       rexml (~> 3.2)
     redis (5.4.0)
       redis-client (>= 0.22.0)
-    redis-client (0.23.2)
+    redis-client (0.24.0)
       connection_pool
     redis-rack-cache (2.2.1)
       rack-cache (>= 1.10, < 2)
@@ -436,7 +437,7 @@ GEM
     rsolr (2.6.0)
       builder (>= 2.1.2)
       faraday (>= 0.9, < 3, != 2.0.0)
-    rubocop (1.72.2)
+    rubocop (1.74.0)
       json (~> 2.3)
       language_server-protocol (~> 3.17.0.2)
       lint_roller (~> 1.1.0)
@@ -447,7 +448,7 @@ GEM
       rubocop-ast (>= 1.38.0, < 2.0)
       ruby-progressbar (~> 1.7)
       unicode-display_width (>= 2.4.0, < 4.0)
-    rubocop-ast (1.38.0)
+    rubocop-ast (1.40.0)
       parser (>= 3.3.1.0)
     ruby-progressbar (1.13.0)
     ruby-xxHash (0.4.0.2)
@@ -503,10 +504,10 @@ GEM
     unicorn-worker-killer (0.4.5)
       get_process_mem (~> 0)
       unicorn (>= 4, < 7)
-    uri (1.0.2)
+    uri (1.0.3)
     uuid (2.3.9)
       macaddr (~> 1.0)
-    webmock (3.25.0)
+    webmock (3.25.1)
       addressable (>= 2.8.0)
       crack (>= 0.3.2)
       hashdiff (>= 0.4.0, < 2.0.0)
diff --git a/controllers/home_controller.rb b/controllers/home_controller.rb
index 7f3280795..5cc1ace68 100644
--- a/controllers/home_controller.rb
+++ b/controllers/home_controller.rb
@@ -11,25 +11,6 @@ class HomeController < ApplicationController
     get do
       expires 3600, :public
       last_modified @@root_last_modified ||= Time.now.httpdate
-      routes = routes_list
-
-      # TODO: delete when ccv will be on production
-      routes.delete('/ccv')
-
-      routes.delete('/resource_index') if LinkedData.settings.enable_resource_index == false
-
-      routes.delete('/Agents')
-
-      routes_hash = {}
-      context = {}
-
-      routes.each do |route|
-        next unless  routes_by_class.key?(route)
-
-        route_no_slash = route.gsub('/', '')
-        context[route_no_slash] = routes_by_class[route].type_uri.to_s if routes_by_class[route].respond_to?(:type_uri)
-        routes_hash[route_no_slash] = LinkedData.settings.rest_url_prefix + route_no_slash
-      end
 
       catalog_class = LinkedData::Models::SemanticArtefactCatalog
       catalog = catalog_class.all.first || create_catalog
@@ -42,8 +23,6 @@ class HomeController < ApplicationController
       if catalog.loaded_attributes.include?(:fundedBy)
         catalog.fundedBy = catalog.fundedBy.map { |item| JSON.parse(item.gsub('=>', ':').gsub('\"', '"')) } 
       end
-      catalog.class.link_to *routes_hash.map { |key, url| LinkedData::Hypermedia::Link.new(key, url, context[key]) }
-      
       reply catalog
     end
 
diff --git a/helpers/home_helper.rb b/helpers/home_helper.rb
index c794dc281..7862c750d 100644
--- a/helpers/home_helper.rb
+++ b/helpers/home_helper.rb
@@ -5,47 +5,6 @@ module Helpers
 
     module HomeHelper
 
-      def routes_list
-        return @navigable_routes if @navigable_routes
-
-        routes = Sinatra::Application.routes['GET']
-        navigable_routes = []
-        routes.each do |route|
-          navigable_routes << route[0].to_s.split('?').first
-        end
-        @navigable_routes = navigable_routes
-        navigable_routes
-      end
-
-      def routes_by_class
-        {
-          '/agents' => LinkedData::Models::Agent,
-          '/annotator' => nil,
-          '/categories' => LinkedData::Models::Category,
-          '/groups' => LinkedData::Models::Group,
-          '/documentation' => nil,
-          '/mappings' => LinkedData::Models::Mapping,
-          '/metrics' => LinkedData::Models::Metric,
-          '/notes' => LinkedData::Models::Note,
-          '/ontologies' => LinkedData::Models::Ontology,
-          '/ontologies_full' => LinkedData::Models::Ontology,
-          '/analytics' => nil,
-          '/submissions' => LinkedData::Models::OntologySubmission,
-          '/projects' => LinkedData::Models::Project,
-          '/property_search' => nil,
-          '/provisional_classes' => LinkedData::Models::ProvisionalClass,
-          '/provisional_relations' => LinkedData::Models::ProvisionalRelation,
-          '/recommender' => nil,
-          '/replies' => LinkedData::Models::Notes::Reply,
-          '/reviews' => LinkedData::Models::Review,
-          '/search' => nil,
-          '/slices' => LinkedData::Models::Slice,
-          '/submission_metadata' => nil,
-          '/ontology_metadata' => nil,
-          '/users' => LinkedData::Models::User
-        }
-      end
-
       def resource_collection_link(cls)
         resource = @metadata[:cls].name.split("::").last
         return "" if resource.nil?
@@ -71,8 +30,6 @@ def resource_collection_link(cls)
           "Example: "\
             "<a href='/ontologies/NCIT/submissions?display=submissionId,version'>"\
             "/ontologies/NCIT/submissions?display=submissionId,version</a>"
-        when (routes_list().include? resource_path) == false
-          "Example: coming soon"
         else
           "Resource collection: <a href='#{resource_path}'>#{resource_path}</a>"
         end
@@ -96,13 +53,25 @@ def hypermedia_links(cls)
 
       def get_metadata_all
         return @metadata_all_info if @metadata_all_info
-
-        ld_classes = ObjectSpace.each_object(Class).select { |klass| klass < LinkedData::Hypermedia::Resource }
         info = {}
-
-        ld_classes.each do |cls|
-          next unless routes_by_class.value?(cls)
-
+        routes_cls = [
+          LinkedData::Models::Agent,
+          LinkedData::Models::Category,
+          LinkedData::Models::Group,
+          LinkedData::Models::Mapping,
+          LinkedData::Models::Metric,
+          LinkedData::Models::Note,
+          LinkedData::Models::Ontology,
+          LinkedData::Models::OntologySubmission,
+          LinkedData::Models::Project,
+          LinkedData::Models::ProvisionalClass,
+          LinkedData::Models::ProvisionalRelation,
+          LinkedData::Models::Notes::Reply,
+          LinkedData::Models::Review,
+          LinkedData::Models::Slice,
+          LinkedData::Models::User
+        ]
+        routes_cls.each do |cls|
           attributes = if cls.respond_to?(:attributes)
                          (cls.attributes(:all) + cls.hypermedia_settings[:serialize_methods]).uniq
                        else
diff --git a/views/documentation/metadata.haml b/views/documentation/metadata.haml
index 841ac492b..5952da305 100644
--- a/views/documentation/metadata.haml
+++ b/views/documentation/metadata.haml
@@ -1,4 +1,3 @@
-- return "" unless routes_by_class.value?(@metadata[:cls])
 %h3.text-success{id: @metadata[:cls].name.split("::").last}= @metadata[:uri]
 %div.resource
   %div.collection_link


Reviews:
user: login: syphax-bouazzouni
body: Here we need to be sure that it is at least we have the same links as before, the links is used in UI, so can be risky to double check in your side. 
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-03-14T10:12:29Z
user: login: syphax-bouazzouni
state: APPROVED
author_association: NONE
submitted_at: 2025-03-19T14:49:17Z

Review comments:
diff_hunk: @@ -11,25 +11,6 @@ class HomeController < ApplicationController
     get do
       expires 3600, :public
       last_modified @@root_last_modified ||= Time.now.httpdate
-      routes = routes_list
path: controllers/home_controller.rb
user: login: syphax-bouazzouni
body: here you don't use anymore theses functions: `routes_list` , `routes_by_class`, so need to be removed also
created_at: 2025-03-14T10:10:32Z
author_association: NONE

PR comments:
user: login: syphax-bouazzouni
created_at: 2025-03-14T11:34:30Z
body: Yes
On Mar 14, 2025 at 11:16 +0100, Imad Bourouche ***@***.***>, wrote:
> @imadbourouche commented on this pull request.
> In controllers/home_controller.rb:
> > @@ -11,25 +11,6 @@ class HomeController < ApplicationController
>     get do
>       expires 3600, :public
>       last_modified @@root_last_modified ||= Time.now.httpdate
> -      routes = routes_list
> you mean remove them from home_helper.rb ?
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> You are receiving this because your review was requested.Message ID: ***@***.***>

author_association: NONE
user: login: imadbourouche
created_at: 2025-03-19T14:26:05Z
body: > Here we need to be sure that it is at least we have the same links as before, the links is used in UI, so can be risky to double check in your side.

I checked the links, i added mod-api links and change the `documentation:` to `doc/legacy-api`. You can merge it :white_check_mark: 
author_association: COLLABORATOR