File tree Expand file tree Collapse file tree
app/services/external_apis Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,19 +51,35 @@ def repository_path
5151 def fetch
5252 xml_list = query_re3data
5353 return [ ] unless xml_list . present?
54-
55- xml_list . xpath ( '/list/repository/id' ) . each do |node |
56- next unless node . present? && node . text . present?
57-
58- xml = query_re3data_repository ( repo_id : node . text )
59- next unless xml . present?
60-
61- process_repository ( id : node . text , node : xml . xpath ( '//r3d:re3data//r3d:repository' ) . first )
54+
55+ active_repo_ids = [ ]
56+ xml_list . xpath ( '/list/repository' ) . each do |repo_node |
57+
58+ repo_id = repo_node . xpath ( './id' ) . text . strip
59+ if repo_id . present?
60+ # Fetch additional data for the repository
61+ xml = query_re3data_repository ( repo_id : repo_id )
62+
63+ # Only process repositories that don't have an endDate node i.e. active
64+ if xml . xpath ( './/r3d:endDate' , 'r3d' => 'http://www.re3data.org/schema/2-2' ) . empty?
65+ process_repository ( id : repo_id , node : xml . xpath ( '//r3d:re3data//r3d:repository' ) . first )
66+
67+ # Add repository ID to list of active repositories
68+ active_repo_ids << repo_id
69+ end
70+ end
6271 end
72+
73+ clear_inactive_repositories ( active_repo_ids )
6374 end
64-
75+
6576 private
6677
78+ # Method to clear repositories that were not identified as active
79+ def clear_inactive_repositories ( active_ids )
80+ Repository . where . not ( uri : active_ids ) . destroy_all
81+ end
82+
6783 # Queries the re3data API for the full list of repositories
6884 def query_re3data
6985 # Call the ROR API and log any errors
You can’t perform that action at this time.
0 commit comments