Diff
Added: branches/biocat/app/controllers/services_controller.rb (0 => 2354)
--- branches/biocat/app/controllers/services_controller.rb (rev 0)
+++ branches/biocat/app/controllers/services_controller.rb 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,81 @@
+# myExperiment: app/controllers/services_controller.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class ServicesController < ApplicationController
+
+ before_filter :find_service, : [:show]
+ before_filter :find_services, : [:all]
+
+ # GET /algorithms;search
+ def search
+# @query = params[:query] || ''
+# @query.strip!
+#
+# @contributables = (Conf.solr_enable && address@hidden) ? Algorithm.find_by_solr(@query, :limit => 100).results : []
+# @total_count = (Conf.solr_enable && address@hidden) ? Algorithm.count_by_solr(@query) : 0
+#
+# respond_to do |format|
+# format.html # search.rhtml
+# end
+ end
+
+ # GET /services
+ def index
+ respond_to do |format|
+ format.html # index.rhtml
+ end
+ end
+
+ # GET /services/all
+ def all
+ respond_to do |format|
+ format.html # all.rhtml
+ end
+ end
+
+ # GET /service/1
+ def show
+ end
+
+ protected
+
+ def find_services
+ @contributables = BioCatService.find(:all,
+ :order => "created_at DESC",
+ :page => { :size => 20,
+ :current => params[:page] })
+ end
+
+ def find_service
+ begin
+ service = BioCatService.find(params[:id])
+
+ @contributable = service
+
+ @contributable_entry_url = url_for : false,
+ :host => base_host,
+ :id => @contributable.id
+
+ @contributable_label = @contributable.name
+ @contributable_path = service_path(@contributable)
+
+ rescue ActiveRecord::RecordNotFound
+ error("Service not found", "is invalid")
+ return false
+ end
+ end
+
+ private
+
+ def error(notice, message, attr=:id)
+ flash[:error] = notice
+ (err = BioCatService.new.errors).add(attr, message)
+
+ respond_to do |format|
+ format.html { redirect_to services_url }
+ end
+ end
+end
+
Added: branches/biocat/app/models/bio_cat_service.rb (0 => 2354)
--- branches/biocat/app/models/bio_cat_service.rb (rev 0)
+++ branches/biocat/app/models/bio_cat_service.rb 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,14 @@
+# myExperiment: app/models/workflow.rb
+#
+# Copyright (c) 2007 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'lib/acts_as_site_entity'
+require 'lib/acts_as_contributable'
+
+class BioCatService < ActiveRecord::Base
+ acts_as_site_entity
+ acts_as_contributable
+ acts_as_structured_data
+end
+
Added: branches/biocat/app/views/bio_cat_services/_table.rhtml (0 => 2354)
--- branches/biocat/app/views/bio_cat_services/_table.rhtml (rev 0)
+++ branches/biocat/app/views/bio_cat_services/_table.rhtml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,61 @@
+<% query ||= false -%>
+<% odd_row = false -%>
+<% unless collection.empty? %>
+
+<table class="alt_table">
+ <% for contributable in collection %>
+ <tr class="<%= (odd_row = !odd_row) ? "odd_row" : "even_row" %>">
+ <% cache(:controller => 'services_cache', :action ="" 'listing', :id => contributable.id) do -%>
+ <td style="width: 100px;">
+ <p style="margin-top:0; padding-top:0; text-align: center;"><b>Submitter:</b></p>
+ <center><%=h contributable.submitter_label %></center>
+ </td>
+ <td style="text-align: left;">
+
+ <p class="title">
+ <%= icon contributable.class.to_s.underscore, nil, nil, nil, '' %>
+ <% title = contributable.name %>
+ <%= link_to(query ? highlight_all(title, query) : title, service_path(contributable)) %>
+ </p>
+
+ <p style="font-size: 85%; margin-top: 0; padding-top: 0;">
+ <b>Retrieved at:</b> <%= datetime(contributable.created_at, false) %>
+ </p>
+ <% if false %>
+
+ <p style="font-size:85%;"><b>License: </b><%= license_link contributable.license.to_s %></p>
+
+ <div class="desc" style="font-size: 85%;">
+ <% if contributable.description and contributable.description.length > 0 %>
+ <% desc = truncate(strip_html(contributable.description), 500) %>
+ <%= query ? highlight_all(desc, query) : desc %>
+ <% else -%>
+ <span class="none_text">No description</span>
+ <% end %>
+ </div>
+
+ <p style="font-size: 85%;">
+ <a href="" algorithm_path(contributable) + '#ratings' -%>"><b>Rating: </b><%= number_with_precision(contributable.rating, 1) %> / 5 (<%= pluralize contributable.ratings_count, 'rating' %>)</a> |
+ <a href="" algorithm_path(contributable) + '#comments' -%>"><b>Comments: </b><%= contributable.comments_count %></a> |
+ <b>Viewed internally:</b> <%= pluralize Viewing.total_site_viewings_count_for_contribution(contributable.contribution.id), "time" %>
+ </p>
+
+ <% unless (tags = contributable.tags).empty? %>
+ <a href="" algorithm_path(contributable) + '#tags' -%>"><p style="font-size: 85%;"><b>Tags:</b></p></a>
+ <div style="display:inline;" class="tags_onesize"><%= tag_cloud_from_collection tags, true %></div>
+ <% else %>
+ <p style="font-size: 85%;"><i>This Algorithm has no tags!</i></p>
+ <% end %>
+<% end %>
+ </td>
+ <% end %>
+
+ <td class="actions" style="width: 80px;">
+ <%= icon "show", service_path(contributable), nil, nil, "View" %>
+ </td>
+ </tr>
+ <% end %>
+</table>
+
+<% end %>
+
Added: branches/biocat/app/views/services/_breadcrumbs.rhtml ( => )
Added: branches/biocat/app/views/services/_subnav.rhtml
===================================================================
Added: branches/biocat/app/views/services/_table.rhtml (0 => 2354)
--- branches/biocat/app/views/services/_table.rhtml (rev 0)
+++ branches/biocat/app/views/services/_table.rhtml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,61 @@
+<% query ||= false -%>
+<% odd_row = false -%>
+<% unless collection.empty? %>
+
+<table class="alt_table">
+ <% for contributable in collection %>
+ <tr class="<%= (odd_row = !odd_row) ? "odd_row" : "even_row" %>">
+ <% cache(:controller => 'services_cache', :action ="" 'listing', :id => contributable.id) do -%>
+ <td style="width: 100px;">
+ <p style="margin-top:0; padding-top:0; text-align: center;"><b>Submitter:</b></p>
+ <center><%=h contributable.submitter_label %></center>
+ </td>
+ <td style="text-align: left;">
+
+ <p class="title">
+ <%= icon contributable.class.to_s.underscore, nil, nil, nil, '' %>
+ <% title = contributable.name %>
+ <%= link_to(query ? highlight_all(title, query) : title, service_path(contributable)) %>
+ </p>
+
+ <p style="font-size: 85%; margin-top: 0; padding-top: 0;">
+ <b>Retrieved at:</b> <%= datetime(contributable.created_at, false) %>
+ </p>
+ <% if false %>
+
+ <p style="font-size:85%;"><b>License: </b><%= license_link contributable.license.to_s %></p>
+
+ <div class="desc" style="font-size: 85%;">
+ <% if contributable.description and contributable.description.length > 0 %>
+ <% desc = truncate(strip_html(contributable.description), 500) %>
+ <%= query ? highlight_all(desc, query) : desc %>
+ <% else -%>
+ <span class="none_text">No description</span>
+ <% end %>
+ </div>
+
+ <p style="font-size: 85%;">
+ <a href="" algorithm_path(contributable) + '#ratings' -%>"><b>Rating: </b><%= number_with_precision(contributable.rating, 1) %> / 5 (<%= pluralize contributable.ratings_count, 'rating' %>)</a> |
+ <a href="" algorithm_path(contributable) + '#comments' -%>"><b>Comments: </b><%= contributable.comments_count %></a> |
+ <b>Viewed internally:</b> <%= pluralize Viewing.total_site_viewings_count_for_contribution(contributable.contribution.id), "time" %>
+ </p>
+
+ <% unless (tags = contributable.tags).empty? %>
+ <a href="" algorithm_path(contributable) + '#tags' -%>"><p style="font-size: 85%;"><b>Tags:</b></p></a>
+ <div style="display:inline;" class="tags_onesize"><%= tag_cloud_from_collection tags, true %></div>
+ <% else %>
+ <p style="font-size: 85%;"><i>This Algorithm has no tags!</i></p>
+ <% end %>
+<% end %>
+ </td>
+ <% end %>
+
+ <td class="actions" style="width: 80px;">
+ <%= icon "show", service_path(contributable), nil, nil, "View" %>
+ </td>
+ </tr>
+ <% end %>
+</table>
+
+<% end %>
+
Added: branches/biocat/app/views/services/all.rhtml (0 => 2354)
--- branches/biocat/app/views/services/all.rhtml (rev 0)
+++ branches/biocat/app/views/services/all.rhtml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,8 @@
+<h2>All Services</h2>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributables } %>
+
+<%= render :partial => "services/table", :locals => { :collection => @contributables } %>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributables } %>
+
Added: branches/biocat/app/views/services/index.rhtml (0 => 2354)
--- branches/biocat/app/views/services/index.rhtml (rev 0)
+++ branches/biocat/app/views/services/index.rhtml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,5 @@
+<ul class="sectionIcons">
+ <li><%= icon "view-all", all_services_path, nil, nil, "View All Services" %></li>
+</ul>
+
+<%= render :partial => "contributions/most_tabs", :locals => { :type => "BioCatService" } %>
Added: branches/biocat/app/views/services/show.rhtml (0 => 2354)
--- branches/biocat/app/views/services/show.rhtml (rev 0)
+++ branches/biocat/app/views/services/show.rhtml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,328 @@
+<h1>Service: <%=h @contributable.name %></h1>
+
+<h2>Service</h2>
+
+<table class="simple">
+
+ <tr>
+ <td>created_at</td>
+ <td><%=h @contributable.created_at -%></td>
+ </tr>
+
+ <tr>
+ <td>updated_at</td>
+ <td><%=h @contributable.updated_at -%></td>
+ </tr>
+
+ <tr>
+ <td>retrieved_at</td>
+ <td><%=h @contributable.retrieved_at -%></td>
+ </tr>
+
+ <tr>
+ <td>uri</td>
+ <td><%=h @contributable.uri -%></td>
+ </tr>
+
+ <tr>
+ <td>submitter_label</td>
+ <td><%=h @contributable.submitter_label -%></td>
+ </tr>
+
+ <tr>
+ <td>created</td>
+ <td><%=h @contributable.created -%></td>
+ </tr>
+
+ <tr>
+ <td>submitter_uri</td>
+ <td><%=h @contributable.submitter_uri -%></td>
+ </tr>
+
+ <tr>
+ <td>name</td>
+ <td><%=h @contributable.name -%></td>
+ </tr>
+
+ <tr>
+ <td>provider_uri</td>
+ <td><%=h @contributable.provider_uri -%></td>
+ </tr>
+
+ <tr>
+ <td>provider_label</td>
+ <td><%=h @contributable.provider_label -%></td>
+ </tr>
+
+ <tr>
+ <td>endpoint</td>
+ <td><%=h @contributable.endpoint -%></td>
+ </tr>
+
+ <tr>
+ <td>wsdl</td>
+ <td><%=h @contributable.wsdl -%></td>
+ </tr>
+
+ <tr>
+ <td>country</td>
+ <td><%=h @contributable.country -%></td>
+ </tr>
+
+ <tr>
+ <td>city</td>
+ <td><%=h @contributable.city -%></td>
+ </tr>
+
+ <tr>
+ <td>iso3166_country_code</td>
+ <td><%=h @contributable.iso3166_country_code -%></td>
+ </tr>
+
+ <tr>
+ <td>flag_url</td>
+ <td><%=h @contributable.flag_url -%></td>
+ </tr>
+
+ <tr>
+ <td>documentation_uri</td>
+ <td><%=h @contributable.documentation_uri -%></td>
+ </tr>
+
+ <tr>
+ <td>description</td>
+ <td><%=h @contributable.description -%></td>
+ </tr>
+
+ <tr>
+ <td>monitor_label</td>
+ <td><%=h @contributable.monitor_label -%></td>
+ </tr>
+
+ <tr>
+ <td>monitor_message</td>
+ <td><%=h @contributable.monitor_message -%></td>
+ </tr>
+
+ <tr>
+ <td>monitor_symbol_url</td>
+ <td><%=h @contributable.monitor_symbol_url -%></td>
+ </tr>
+
+ <tr>
+ <td>monitor_small_symbol_url</td>
+ <td><%=h @contributable.monitor_small_symbol_url -%></td>
+ </tr>
+
+ <tr>
+ <td>monitor_last_checked</td>
+ <td><%=h @contributable.monitor_last_checked -%></td>
+ </tr>
+
+</table>
+
+<h2>Service categories</h2>
+
+<% @contributable.bio_cat_service_categories.each do |category| %>
+
+ <table class="simple">
+
+ <tr>
+ <td>created_at</td>
+ <td><%=h category.created_at -%></td>
+ </tr>
+
+ <tr>
+ <td>updated_at</td>
+ <td><%=h category.updated_at -%></td>
+ </tr>
+
+ <tr>
+ <td>retrieved_at</td>
+ <td><%=h category.retrieved_at -%></td>
+ </tr>
+
+ <tr>
+ <td>uri</td>
+ <td><%=h category.uri -%></td>
+ </tr>
+
+ <tr>
+ <td>label</td>
+ <td><%=h category.label -%></td>
+ </tr>
+
+ </table>
+
+<% end %>
+
+<h2>Service types</h2>
+
+<% @contributable.bio_cat_service_types.each do |type| %>
+
+ <table class="simple">
+
+ <tr>
+ <td>created_at</td>
+ <td><%=h type.created_at -%></td>
+ </tr>
+
+ <tr>
+ <td>updated_at</td>
+ <td><%=h type.updated_at -%></td>
+ </tr>
+
+ <tr>
+ <td>retrieved_at</td>
+ <td><%=h type.retrieved_at -%></td>
+ </tr>
+
+ <tr>
+ <td>label</td>
+ <td><%=h type.label -%></td>
+ </tr>
+
+ </table>
+
+<% end %>
+
+<h2>Service tags</h2>
+
+<% @contributable.bio_cat_service_tags.each do |tag| %>
+
+ <table class="simple">
+
+ <tr>
+ <td>created_at</td>
+ <td><%=h tag.created_at -%></td>
+ </tr>
+
+ <tr>
+ <td>updated_at</td>
+ <td><%=h tag.updated_at -%></td>
+ </tr>
+
+ <tr>
+ <td>retrieved_at</td>
+ <td><%=h tag.retrieved_at -%></td>
+ </tr>
+
+ <tr>
+ <td>uri</td>
+ <td><%=h tag.uri -%></td>
+ </tr>
+
+ <tr>
+ <td>label</td>
+ <td><%=h tag.label -%></td>
+ </tr>
+
+ </table>
+
+<% end %>
+
+<h2>Service deployments</h2>
+
+<% @contributable.bio_cat_service_deployments.each do |deployment| %>
+
+ <table class="simple">
+
+ <tr>
+ <td>created_at</td>
+ <td><%=h deployment.created_at -%></td>
+ </tr>
+
+ <tr>
+ <td>updated_at</td>
+ <td><%=h deployment.updated_at -%></td>
+ </tr>
+
+ <tr>
+ <td>retrieved_at</td>
+ <td><%=h deployment.retrieved_at -%></td>
+ </tr>
+
+ <tr>
+ <td>uri</td>
+ <td><%=h deployment.uri -%></td>
+ </tr>
+
+ <tr>
+ <td>endpoint</td>
+ <td><%=h deployment.endpoint -%></td>
+ </tr>
+
+ <tr>
+ <td>city</td>
+ <td><%=h deployment.city -%></td>
+ </tr>
+
+ <tr>
+ <td>country</td>
+ <td><%=h deployment.country -%></td>
+ </tr>
+
+ <tr>
+ <td>iso3166_country_code</td>
+ <td><%=h deployment.iso3166_country_code -%></td>
+ </tr>
+
+ <tr>
+ <td>flag_url</td>
+ <td><%=h deployment.flag_url -%></td>
+ </tr>
+
+ <tr>
+ <td>submitter_label</td>
+ <td><%=h deployment.submitter_label -%></td>
+ </tr>
+
+ <tr>
+ <td>submitter_uri</td>
+ <td><%=h deployment.submitter_uri -%></td>
+ </tr>
+
+ <tr>
+ <td>created</td>
+ <td><%=h deployment.created -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider created_at</td>
+ <td><%=h deployment.bio_cat_service_provider.created_at -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider updated_at</td>
+ <td><%=h deployment.bio_cat_service_provider.updated_at -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider retrieved_at</td>
+ <td><%=h deployment.bio_cat_service_provider.retrieved_at -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider uri</td>
+ <td><%=h deployment.bio_cat_service_provider.uri -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider name</td>
+ <td><%=h deployment.bio_cat_service_provider.name -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider description</td>
+ <td><%=h deployment.bio_cat_service_provider.description -%></td>
+ </tr>
+
+ <tr>
+ <td>Provider created</td>
+ <td><%=h deployment.bio_cat_service_provider.created -%></td>
+ </tr>
+
+ </table>
+
+<% end %>
+
Modified: branches/biocat/config/default_settings.yml (2353 => 2354)
--- branches/biocat/config/default_settings.yml 2010-03-30 08:49:10 UTC (rev 2353)
+++ branches/biocat/config/default_settings.yml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -142,6 +142,10 @@
link: /workflows
controller: workflows
+ - label: Services
+ link: /services
+ controller: services
+
- label: Files
link: /files
controller: blobs
Modified: branches/biocat/config/routes.rb (2353 => 2354)
--- branches/biocat/config/routes.rb 2010-03-30 08:49:10 UTC (rev 2353)
+++ branches/biocat/config/routes.rb 2010-03-30 09:06:29 UTC (rev 2354)
@@ -118,6 +118,9 @@
# blogs have nested posts
blog.resources :blog_posts
end
+
+ # services
+ map.resources :services, :collection => { :all => :get, :search => :get }
# all downloads and viewings
map.resources :downloads, :viewings
Added: branches/biocat/config/schema.d/services.xml (0 => 2354)
--- branches/biocat/config/schema.d/services.xml (rev 0)
+++ branches/biocat/config/schema.d/services.xml 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,146 @@
+<?xml version="1.0"?>
+<schema>
+
+ <!-- BioCatalogue services -->
+
+ <table name="bio_cat_services">
+
+ <column type="integer" name="contributor_id"/>
+ <column type="string" name="contributor_type"/>
+
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+ <column type="datetime" name="retrieved_at"/>
+
+ <!-- from the service index listing -->
+
+ <column type="string" name="uri"/>
+ <column type="string" name="submitter_label"/>
+ <column type="datetime" name="created"/>
+ <column type="string" name="submitter_uri"/>
+
+ <!-- service summary -->
+
+ <column type="string" name="name"/>
+ <column type="string" name="provider_uri"/>
+ <column type="string" name="provider_label"/>
+ <column type="string" name="endpoint"/>
+ <column type="string" name="wsdl"/>
+ <column type="string" name="city"/>
+ <column type="string" name="country"/>
+ <column type="string" name="iso3166_country_code"/>
+ <column type="string" name="flag_url"/>
+ <column type="string" name="documentation_uri"/>
+ <column type="text" name="description"/>
+
+ <!-- service monitoring -->
+
+ <column type="string" name="monitor_label"/>
+ <column type="text" name="monitor_message"/>
+ <column type="string" name="monitor_symbol_url"/>
+ <column type="string" name="monitor_small_symbol_url"/>
+ <column type="datetime" name="monitor_last_checked"/>
+
+ <has-many target="bio_cat_service_categories"/>
+ <has-many target="bio_cat_service_types"/>
+ <has-many target="bio_cat_service_tags"/>
+ <has-many target="bio_cat_service_deployments"/>
+
+ </table>
+
+ <!-- BioCatalogue service categories -->
+
+ <table name="bio_cat_service_categories">
+
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+ <column type="datetime" name="retrieved_at"/>
+
+ <column type="integer" name="bio_cat_service_id"/>
+ <column type="string" name="uri"/>
+ <column type="string" name="label"/>
+
+ <belongs-to target="bio_cat_service"/>
+
+ </table>
+
+ <!-- BioCatalogue service types -->
+
+ <table name="bio_cat_service_types">
+
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+ <column type="datetime" name="retrieved_at"/>
+
+ <column type="integer" name="bio_cat_service_id"/>
+ <column type="string" name="label"/>
+
+ <belongs-to target="bio_cat_service"/>
+
+ </table>
+
+ <!-- BioCatalogue service tags -->
+
+ <table name="bio_cat_service_tags">
+
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+ <column type="datetime" name="retrieved_at"/>
+
+ <column type="integer" name="bio_cat_service_id"/>
+ <column type="string" name="uri"/>
+ <column type="string" name="label"/>
+
+ <belongs-to target="bio_cat_service"/>
+
+ </table>
+
+ <!-- BioCatalogue service deployments -->
+
+ <table name="bio_cat_service_deployments">
+
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+ <column type="datetime" name="retrieved_at"/>
+
+ <column type="string" name="uri"/>
+ <column type="string" name="endpoint"/>
+
+ <column type="string" name="city"/>
+ <column type="string" name="country"/>
+ <column type="string" name="iso3166_country_code"/>
+ <column type="string" name="flag_url"/>
+
+ <column type="string" name="submitter_label"/>
+ <column type="string" name="submitter_uri"/>
+
+ <column type="datetime" name="created"/>
+
+ <column type="integer" name="bio_cat_service_id"/>
+ <column type="integer" name="bio_cat_service_provider_id"/>
+
+ <belongs-to target="bio_cat_service_provider"/>
+ <belongs-to target="bio_cat_service"/>
+
+ </table>
+
+ <!-- BioCatalogue service providers -->
+
+ <table name="bio_cat_service_providers">
+
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+ <column type="datetime" name="retrieved_at"/>
+
+ <column type="string" name="uri"/>
+ <column type="string" name="name"/>
+ <column type="text" name="description"/>
+
+ <column type="datetime" name="created"/>
+
+ <has-many target="bio_cat_service_deployments" foreign_key="bio_cat_service_provider_id"/>
+
+ </table>
+
+</schema>
+
Added: branches/biocat/lib/bio_catalogue_import.rb (0 => 2354)
--- branches/biocat/lib/bio_catalogue_import.rb (rev 0)
+++ branches/biocat/lib/bio_catalogue_import.rb 2010-03-30 09:06:29 UTC (rev 2354)
@@ -0,0 +1,209 @@
+# myExperiment: lib/biocatalog_import.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class BioCatalogueImport
+
+ require 'xml/libxml'
+
+ @@biocat_base_uri = 'http://www.biocatalogue.org/'
+ @@biocat_ns = { "bc" => "http://www.biocatalogue.org/2009/xml/rest" }
+ @@biocat_document_cache = "tmp/biocatalogue.yml"
+ @@biocat_wait_in_seconds = 10
+
+ def self.fetch_uri(uri)
+
+ if @documents.nil?
+ if File.exists?(@@biocat_document_cache)
+ @documents = YAML::load_file(@@biocat_document_cache)
+ else
+ @documents = { :retrieved_at => { } }
+ end
+ end
+
+ return @documents[uri] if @documents[uri]
+
+ rest_uri = URI.parse(uri)
+ rest_uri.path = rest_uri.path + ".xml"
+
+ puts "Fetching URI: #{rest_uri}"
+
+ @documents[uri] = rest_uri.read.to_s
+ @documents[:retrieved_at][uri] = Time.now
+
+ puts "Got it."
+ Kernel.sleep(@@biocat_wait_in_seconds)
+
+ @documents[uri]
+ end
+
+ def self.uri_retrieved_at(uri)
+ @documents[:retrieved_at][uri]
+ end
+
+ def self.save_document_cache
+ file = File.open(@@biocat_document_cache, "w+") do |file|
+ file.rewind
+ file.puts(@documents.to_yaml)
+ end
+ end
+
+ def self.get_text(element, query)
+ response = element.find(query, @@biocat_ns)
+ response[0].to_s unless response.length.zero?
+ end
+
+ def self.get_attr(element, query)
+ response = element.find(query, @@biocat_ns)
+ response[0].value unless response.length.zero?
+ end
+
+ def self.get_link(element, query)
+ response = element.find(query, @@biocat_ns)
+ (URI.parse(@@biocat_base_uri) + response[0].value).to_s unless response.length.zero?
+ end
+
+ def self.import_service(service_uri)
+
+ service_element = LibXML::XML::Parser.string(fetch_uri(service_uri)).parse.root
+
+ summary_uri = get_attr(service_element, '/bc:service/bc:related/bc:summary/@xlink:href')
+ deployment_uri = get_attr(service_element, '/bc:service/bc:related/bc:deployments/@xlink:href')
+ variants_uri = get_attr(service_element, '/bc:service/bc:related/bc:variants/@xlink:href')
+ annotations_uri = get_attr(service_element, '/bc:service/bc:related/bc:annotations/@xlink:href')
+ monitoring_uri = get_attr(service_element, '/bc:service/bc:related/bc:monitoring/@xlink:href')
+
+ summary_element = LibXML::XML::Parser.string(fetch_uri(summary_uri)).parse.root
+ deployments_element = LibXML::XML::Parser.string(fetch_uri(deployment_uri)).parse.root
+ variants_element = LibXML::XML::Parser.string(fetch_uri(variants_uri)).parse.root
+ annotations_element = LibXML::XML::Parser.string(fetch_uri(annotations_uri)).parse.root
+ monitoring_element = LibXML::XML::Parser.string(fetch_uri(monitoring_uri)).parse.root
+
+ service = BioCatService.create(
+ :retrieved_at => uri_retrieved_at(service_uri),
+
+ :contributor => User.find(22),
+
+ :uri => get_link(service_element, '/bc:service/@xlink:href'),
+ :name => get_text(service_element, '/bc:service/bc:name/text()'),
+ :submitter_label => get_attr(service_element, '/bc:service/bc:originalSubmitter/@resourceName'),
+ :created => get_text(service_element, '/bc:service/dcterms:created/text()'),
+ :submitter_uri => get_attr(service_element, '/bc:service/bc:originalSubmitter/@xlink:href'),
+
+ :provider_uri => get_link(summary_element, '/bc:service/bc:summary/bc:provider/@xlink:href'),
+ :provider_label => get_text(summary_element, '/bc:service/bc:summary/bc:provider/bc:name/text()'),
+ :endpoint => get_text(summary_element, '/bc:service/bc:summary/bc:endpoint/text()'),
+ :wsdl => get_text(summary_element, '/bc:service/bc:summary/bc:wsdl/text()'),
+ :city => get_text(summary_element, '/bc:service/bc:summary/bc:location/bc:city/text()'),
+ :country => get_text(summary_element, '/bc:service/bc:summary/bc:location/bc:country/text()'),
+ :iso3166_country_code => get_text(summary_element, '/bc:service/bc:summary/bc:location/bc:iso3166CountryCode/text()'),
+ :flag_url => get_link(summary_element, '/bc:service/bc:summary/bc:location/bc:flag/@xlink:href'),
+ :documentation_uri => get_text(summary_element, '/bc:service/bc:summary/bc:documentationUrl/text()'),
+ :description => get_text(summary_element, '/bc:service/bc:summary/dc:description/text()'),
+
+ :monitor_label => get_text(summary_element, '/bc:service/bc:latestMonitoringStatus/bc:label/text()'),
+ :monitor_message => get_text(summary_element, '/bc:service/bc:latestMonitoringStatus/bc:message/text()'),
+ :monitor_symbol_url => get_link(summary_element, '/bc:service/bc:latestMonitoringStatus/bc:symbol/@xlink:href'),
+ :monitor_small_symbol_url => get_link(summary_element, '/bc:service/bc:latestMonitoringStatus/bc:smallSymbol/@xlink:href'),
+ :monitor_last_checked => get_text(summary_element, '/bc:service/bc:latestMonitoringStatus/bc:lastChecked/text()'))
+
+ service.contribution.policy = create_default_policy(User.find(22))
+ service.contribution.policy.share_mode = 0 # Make public
+ service.contribution.policy.save
+ service.contribution.save
+
+ summary_element.find('/bc:service/bc:summary/bc:category', @@biocat_ns).each do |category_element|
+ BioCatServiceCategory.create(
+ :bio_cat_service => service,
+ :retrieved_at => uri_retrieved_at(summary_uri),
+ :uri => get_link(category_element, '@xlink:href'),
+ :label => get_text(category_element, 'text()'))
+ end
+
+ summary_element.find('/bc:service/bc:summary/bc:serviceType', @@biocat_ns).each do |category_element|
+ BioCatServiceType.create(
+ :bio_cat_service => service,
+ :retrieved_at => uri_retrieved_at(summary_uri),
+ :label => get_text(category_element, 'text()'))
+ end
+
+ summary_element.find('/bc:service/bc:summary/bc:tag', @@biocat_ns).each do |tag_element|
+ BioCatServiceTag.create(
+ :bio_cat_service => service,
+ :retrieved_at => uri_retrieved_at(summary_uri),
+ :uri => get_link(tag_element, '@xlink:href'),
+ :label => get_text(tag_element, 'text()'))
+ end
+
+ # deployments and providers
+
+ service_element.find('/bc:service/bc:deployments/bc:serviceDeployment', @@biocat_ns).each do |deployment_element|
+
+ deployment_uri = get_link(deployment_element, '@xlink:href')
+ provider_uri = get_link(deployment_element, 'bc:serviceProvider/@xlink:href')
+
+ next if BioCatServiceDeployment.find_by_uri(deployment_uri)
+
+ if BioCatServiceProvider.find_by_uri(provider_uri).nil?
+ BioCatServiceProvider.create(
+ :uri => provider_uri,
+ :retrieved_at => uri_retrieved_at(service_uri),
+ :name => get_text(deployment_element, 'bc:serviceProvider/bc:name/text()'),
+ :description => get_text(deployment_element, 'bc:serviceProvider/dc:description/text()'),
+ :created => get_text(deployment_element, 'bc:serviceProvider/dcterms:created/text()'))
+ end
+
+ provider = BioCatServiceProvider.find_by_uri(provider_uri)
+
+ deployment = BioCatServiceDeployment.create(
+ :bio_cat_service => service,
+ :bio_cat_service_provider => provider,
+ :retrieved_at => uri_retrieved_at(service_uri),
+ :uri => get_link(deployment_element, '@xlink:href'),
+ :endpoint => get_text(deployment_element, 'bc:endpoint/text()'),
+ :city => get_text(deployment_element, 'bc:location/bc:city/text()'),
+ :country => get_text(deployment_element, 'bc:location/bc:country/text()'),
+ :iso3166_country_code => get_text(deployment_element, 'bc:location/bc:iso3166CountryCode/text()'),
+ :flag_url => get_link(deployment_element, 'bc:location/bc:flag/@xlink:href'),
+ :submitter_label => get_attr(deployment_element, 'bc:submitter/@resourceName'),
+ :submitter_uri => get_attr(deployment_element, 'bc:submitter/@xlink:href'),
+ :created => get_text(deployment_element, 'dcterms:created/text()'))
+
+ end
+ end
+
+ def self.import_biocatalogue_services(uri)
+
+ Contribution.delete_all("contributable_type = 'BioCatService'")
+ BioCatService.delete_all
+ BioCatServiceCategory.delete_all
+ BioCatServiceType.delete_all
+ BioCatServiceTag.delete_all
+ BioCatServiceDeployment.delete_all
+ BioCatServiceProvider.delete_all
+
+ while true
+
+ doc = LibXML::XML::Parser.string(fetch_uri(uri)).parse.root
+
+ doc.find("/bc:services/bc:results/bc:service", @@biocat_ns).each do |service_element|
+ import_service(get_link(service_element, '@xlink:href'))
+ end
+
+ next_doc = doc.find("/bc:services/bc:related/bc:next/@xlink:href", @@biocat_ns)
+
+ break if next_doc.length.zero?
+
+ uri = next_doc[0].value
+ end
+
+ save_document_cache
+
+ end
+
+ def self.import_biocatalogue
+ import_biocatalogue_services("http://www.biocatalogue.org/services")
+ end
+end
+