Diff
Modified: trunk/Rakefile (2558 => 2559)
--- trunk/Rakefile 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/Rakefile 2011-02-12 15:34:49 UTC (rev 2559)
@@ -56,3 +56,9 @@
Maintenance::Backup.restore
end
+desc 'Load a controlled vocabulary file'
+task "myexp:vocab:load" do
+ require File.dirname(__FILE__) + '/config/environment'
+ LoadVocabulary::load_vocabulary
+end
+
Copied: trunk/app/controllers/relationships_controller.rb (from rev 2558, branches/neiss/app/controllers/relationships_controller.rb) (0 => 2559)
--- trunk/app/controllers/relationships_controller.rb (rev 0)
+++ trunk/app/controllers/relationships_controller.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -0,0 +1,88 @@
+# myExperiment: app/controllers/relationships_controller.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class RelationshipsController < ApplicationController
+
+ helper PacksHelper
+
+ before_filter :find_resource_context
+ before_filter :find_resource, :except => [ :edit_relationships, :create ]
+
+ # GET /:context_type/:context_id/edit_relationships
+ def edit_relationships
+
+ @relationships = Relationship.find(:all, :conditions => ['pack_id = ?', @context.id])
+
+ @concepts = Vocabulary.find(:all).map do |v| v.concepts end.flatten
+
+ @pack_entries = @context.contributable_entries + @context.remote_entries
+
+ @pack_entry_select_options = @pack_entries.map do |pe|
+ if pe.class == PackContributableEntry
+ [pe.contributable.label, "contributable:#{pe.id}"]
+ else
+ [pe.title, "remote:#{pe.id}"]
+ end
+ end
+ end
+
+ # POST /:context_type/:context_id/relationships
+ def create
+
+ subject = @context.find_pack_item(params[:subject])
+ objekt = @context.find_pack_item(params[:objekt])
+
+ prefix, term = params[:predicate].split(":")
+
+ label = Label.find(:first, :conditions =>
+ ['label_type = ? AND vocabulary_id = ? AND text = ?',
+ 'preferred',
+ Vocabulary.find_by_prefix(prefix).id,
+ term])
+
+ raise("Invalid form data") if subject.nil? || objekt.nil? || label.nil?
+
+ @relationship = Relationship.new(:pack => @context, :concept => label.concept, :user => current_user)
+
+ @relationship.subject = subject
+ @relationship.objekt = objekt
+
+ @relationship.save
+
+ redirect_to(:action ="" :edit_relationships)
+ end
+
+ # DELETE /:context_type/:context_id/relationships/:id
+ def destroy
+
+ if Authorization.is_authorized?('destroy', nil, @relationship, current_user)
+ @relationship.destroy
+ end
+
+ render :partial => "relationships/relationships",
+ :locals => { :relationships => @context.relationships }
+ end
+
+ private
+
+ def find_resource
+
+ @context = extract_resource_context(params)
+ @relationship = Relationship.find_by_id(params[:id])
+
+ return false if @relationship.nil? || @context.nil? || @relationship.pack != @context
+ return false if Authorization.is_authorized?('view', nil, @context, current_user) == false
+ end
+
+ def find_resource_context
+
+ @context = extract_resource_context(params)
+
+ return false if @context.nil?
+ return false if Authorization.is_authorized?('view', nil, @context, current_user) == false
+ end
+
+end
+
Modified: trunk/app/helpers/packs_helper.rb (2558 => 2559)
--- trunk/app/helpers/packs_helper.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/app/helpers/packs_helper.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -78,4 +78,18 @@
return tags
end
+
+ def pack_entry_link(entry)
+
+ case entry.class.name
+ when "PackContributableEntry"
+ text = entry.contributable.label
+ href = ""
+ when "PackRemoteEntry"
+ text = entry.title
+ href = ""
+ end
+
+ link_to(text, href)
+ end
end
Copied: trunk/app/models/concept.rb (from rev 2558, branches/neiss/app/models/concept.rb) (0 => 2559)
--- trunk/app/models/concept.rb (rev 0)
+++ trunk/app/models/concept.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -0,0 +1,17 @@
+# myExperiment: app/models/concept.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class Concept < ActiveRecord::Base
+
+ acts_as_structured_data
+
+ format_attribute :description
+
+ def preferred_label
+ preferred_labels.first
+ end
+
+end
+
Modified: trunk/app/models/pack.rb (2558 => 2559)
--- trunk/app/models/pack.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/app/models/pack.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -22,6 +22,8 @@
acts_as_rateable
acts_as_taggable
+ acts_as_structured_data
+
validates_presence_of :title
format_attribute :description
@@ -608,6 +610,36 @@
contributable_entries.map do |e| e.contributable end
end
+ # This function takes a string, such as 'contributable:4' (which would return
+ # a PackContributableEntry with the id of 4) or 'remote:8' (which would
+ # return a PackRemoteEntry with an id of 8) and returns the appropriate pack
+ # item if this pack contains that item.
+
+ def find_pack_item(str)
+
+ thing_type, thing_id = str.split(":")
+
+ case thing_type
+ when 'contributable'
+ ob = PackContributableEntry.find(:first,
+ :conditions => ['id = ? AND pack_id = ?', thing_id, id])
+
+ when 'remote'
+ ob = PackRemoteEntry.find(:first,
+ :conditions => ['id = ? AND pack_id = ?', thing_id, id])
+ end
+ end
+
+ # This method determines which pack relationships refer to contributables
+ # that are not included as pack entries in this pack. Such relationships
+ # might occur when deleting entries from a pack.
+
+ def dangling_relationships
+ relationships.select do |relationship|
+ relationship.subject.nil? || relationship.objekt.nil?
+ end
+ end
+
protected
# produces html string containing the required messaged, enclosed within left-padded P tag, belonging to 'none_text' class
Copied: trunk/app/models/relationship.rb (from rev 2558, branches/neiss/app/models/relationship.rb) (0 => 2559)
--- trunk/app/models/relationship.rb (rev 0)
+++ trunk/app/models/relationship.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -0,0 +1,13 @@
+# myExperiment: app/models/relationship.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class Relationship < ActiveRecord::Base
+
+ acts_as_structured_data
+
+ validates_uniqueness_of :concept_id, :scope => [:subject_id, :objekt_id]
+
+end
+
Modified: trunk/app/models/vocabulary.rb (2558 => 2559)
--- trunk/app/models/vocabulary.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/app/models/vocabulary.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -5,12 +5,15 @@
class Vocabulary < ActiveRecord::Base
+ acts_as_structured_data
+
belongs_to :user
- has_many :tags, :dependent => :destroy
-
validates_presence_of :title
+ validates_presence_of :prefix
+ validates_uniqueness_of :prefix
+
format_attribute :description
end
Modified: trunk/app/views/packs/show.rhtml (2558 => 2559)
--- trunk/app/views/packs/show.rhtml 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/app/views/packs/show.rhtml 2011-02-12 15:34:49 UTC (rev 2559)
@@ -81,8 +81,24 @@
</h4>
<%= render :partial => "items", :locals => { :pack => @pack, :authorised_to_edit => @authorised_to_edit } -%>
+
+ <br/><br/>
+ <h4>
+ <%= info_icon_with_tooltip("This section shows all the relationships between the items in this pack.") -%>
+ Relationships <span class="count_text">(<%= @pack.relationships.length -%>)</span>
+ </h4>
+
+ <%= render :partial => "relationships/relationships", :locals => { :relationships => @pack.relationships } -%>
+ <% if @authorised_to_edit %>
+ <br />
+ <ul class="sectionIcons">
+ <li><%= icon('manage', edit_relationships_pack_relationships_path(@pack), nil, nil, 'Edit Relationships') -%></li>
+ </ul>
+ <% end %>
+
<br/><br/>
+
<h3>
<%= info_icon_with_tooltip("This section provides a link to download all items in this pack as a single .zip archive") %>
Download
Modified: trunk/config/routes.rb (2558 => 2559)
--- trunk/config/routes.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/config/routes.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -94,9 +94,9 @@
:resolve_link => :post,
:items => :get } do |pack|
pack.resources :comments, :collection => { :timeline => :get }
+ pack.resources :relationships, :collection => { :edit_relationships => :get }
end
-
# workflows (downloadable)
map.resources :workflows,
:collection => { :search => :get },
Copied: trunk/config/schema.d/packs.xml (from rev 2558, branches/neiss/config/schema.d/packs.xml) (0 => 2559)
--- trunk/config/schema.d/packs.xml (rev 0)
+++ trunk/config/schema.d/packs.xml 2011-02-12 15:34:49 UTC (rev 2559)
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<schema>
+
+ <table name="packs">
+
+ <column type="integer" name="contributor_id"/>
+ <column type="string" name="contributor_type"/>
+ <column type="string" name="title"/>
+ <column type="text" name="description"/>
+ <column type="text" name="description_html"/>
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+
+ <has-many target="relationships" dependent="destroy"/>
+
+ </table>
+
+ <table name="pack_contributable_entries">
+
+ <column type="integer" name="pack_id"/>
+ <column type="integer" name="contributable_id"/>
+ <column type="integer" name="contributable_version"/>
+ <column type="string" name="contributable_type"/>
+ <column type="text" name="comment"/>
+ <column type="integer" name="user_id"/>
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+
+ </table>
+
+ <table name="pack_remote_entries">
+
+ <column type="integer" name="pack_id"/>
+ <column type="string" name="title"/>
+ <column type="string" name="uri"/>
+ <column type="string" name="alternate_uri"/>
+ <column type="text" name="comment"/>
+ <column type="integer" name="user_id"/>
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+
+ </table>
+
+ <table name="relationships">
+
+ <column type="integer" name="pack_id"/>
+ <column type="integer" name="user_id"/>
+ <column type="integer" name="concept_id"/>
+ <column type="string" name="subject_type"/>
+ <column type="integer" name="subject_id"/>
+ <column type="string" name="objekt_type"/>
+ <column type="integer" name="objekt_id"/>
+ <column type="datetime" name="created_at"/>
+
+ <belongs-to target="subjects" polymorphic="true"/>
+ <belongs-to target="objekts" polymorphic="true"/>
+
+ <belongs-to target="packs"/>
+ <belongs-to target="users"/>
+ <belongs-to target="concepts"/>
+
+ </table>
+
+</schema>
+
Copied: trunk/config/schema.d/skos.xml (from rev 2558, branches/neiss/config/schema.d/skos.xml) (0 => 2559)
--- trunk/config/schema.d/skos.xml (rev 0)
+++ trunk/config/schema.d/skos.xml 2011-02-12 15:34:49 UTC (rev 2559)
@@ -0,0 +1,120 @@
+<?xml version="1.0"?>
+<schema>
+
+ <table name="vocabularies">
+
+ <column type="integer" name="user_id"/>
+ <column type="string" name="uri"/>
+ <column type="string" name="title"/>
+ <column type="string" name="prefix"/>
+ <column type="text" name="description"/>
+ <column type="text" name="description_html"/>
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+
+ <has-many target="concepts" dependent="destroy"/>
+
+ </table>
+
+ <table name="concepts">
+
+ <column type="integer" name="vocabulary_id"/>
+ <column type="string" name="title"/>
+ <column type="text" name="description"/>
+ <column type="text" name="description_html"/>
+ <column type="datetime" name="created_at"/>
+ <column type="datetime" name="updated_at"/>
+
+ <belongs-to target="vocabularies"/>
+
+ <!-- Broader relations -->
+
+ <has-many target = "broader_relations"
+ foreign_key = "object_concept_id"
+ class_name = "ConceptRelation"
+ conditions = "relation_type = 'broader'"/>
+
+ <has-many target = "broader_concepts"
+ class_name = "Concept"
+ through = "broader_relations"
+ source = "object_concept"/>
+
+ <!-- Narrower relations -->
+
+ <has-many target = "narrower_relations"
+ foreign_key = "subject_concept_id"
+ class_name = "ConceptRelation"
+ conditions = "relation_type = 'broader'"/>
+
+ <has-many target = "narrower_concepts"
+ class_name = "Concept"
+ through = "narrower_relations"
+ source = "subject_concept"/>
+
+ <!-- Related relations -->
+
+ <has-many target = "related_relations"
+ foreign_key = "subject_concept_id"
+ class_name = "ConceptRelation"
+ conditions = "relation_type = 'related'"/>
+
+ <has-many target = "related_concepts"
+ class_name = "Concept"
+ through = "related_relations"
+ source = "object_concept"/>
+
+ <!-- Labels -->
+
+ <has-many target="labels" dependent="destroy"/>
+
+ <has-many target = "preferred_labels"
+ dependent = "destroy"
+ class_name = "Label"
+ foreign_key = "concept_id"
+ conditions = "label_type = 'preferred'"/>
+
+ <has-many target = "alternate_labels"
+ dependent = "destroy"
+ class_name = "Label"
+ foreign_key = "concept_id"
+ conditions = "label_type = 'alternate'"/>
+
+ <has-many target = "hidden_labels"
+ dependent = "destroy"
+ class_name = "Label"
+ foreign_key = "concept_id"
+ conditions = "label_type = 'hidden'"/>
+
+ </table>
+
+ <table name="concept_relations">
+
+ <column type="integer" name="subject_concept_id"/>
+ <column type="integer" name="object_concept_id"/>
+ <column type="string" name="relation_type"/>
+
+ <belongs-to target = "subject_concepts"
+ class_name = "Concept"
+ foreign_key = "subject_concept_id"/>
+
+ <belongs-to target = "object_concepts"
+ class_name = "Concept"
+ foreign_key = "object_concept_id"/>
+
+ </table>
+
+ <table name="labels">
+
+ <column type="string" name="text"/>
+ <column type="string" name="label_type"/>
+ <column type="string" name="language"/>
+ <column type="integer" name="concept_id"/>
+ <column type="integer" name="vocabulary_id"/>
+
+ <belongs-to target="vocabularies"/>
+ <belongs-to target="concepts"/>
+
+ </table>
+
+</schema>
+
Modified: trunk/lib/authorization.rb (2558 => 2559)
--- trunk/lib/authorization.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/lib/authorization.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -490,7 +490,7 @@
case action_name
when 'show', 'index', 'view', 'search', 'favourite', 'favourite_delete', 'comment', 'comment_delete', 'comments', 'comments_timeline', 'rate', 'tag', 'items', 'statistics', 'curation', 'tag_suggestions', 'extra_metadata', 'read', 'verify'
action = ''
- when 'edit', 'new', 'create', 'update', 'new_version', 'create_version', 'destroy_version', 'edit_version', 'update_version', 'new_item', 'create_item', 'edit_item', 'update_item', 'quick_add', 'resolve_link', 'process_tag_suggestions', 'process_extra_metadata'
+ when 'edit', 'new', 'create', 'update', 'new_version', 'create_version', 'destroy_version', 'edit_version', 'update_version', 'new_item', 'create_item', 'edit_item', 'update_item', 'quick_add', 'resolve_link', 'process_tag_suggestions', 'process_extra_metadata', 'edit_relationships'
action = ''
when 'download', 'named_download', 'launch', 'submit_job', 'save_inputs', 'refresh_status', 'rerun', 'refresh_outputs', 'render_output', 'outputs_xml', 'outputs_package'
action = ''
Copied: trunk/lib/load_vocabulary.rb (from rev 2558, branches/neiss/lib/load_vocabulary.rb) (0 => 2559)
--- trunk/lib/load_vocabulary.rb (rev 0)
+++ trunk/lib/load_vocabulary.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -0,0 +1,68 @@
+# myExperiment: lib/load_vocabulary.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+module LoadVocabulary
+
+ def self.load_vocabulary
+
+ file_name = ENV['FILE']
+
+ if file_name.nil?
+ puts "Missing file name."
+ return
+ end
+
+ data = ""
+
+ exising_vocabulary = Vocabulary.find_by_uri(data["uri"])
+ exising_vocabulary.destroy if exising_vocabulary
+
+ vocabulary = Vocabulary.create(
+ :uri => data["uri"],
+ :title => data["title"],
+ :prefix => data["prefix"],
+ :description => data["description"])
+
+ data["concepts"].each do |concept|
+
+ c = Concept.create(
+ :title => concept["title"],
+ :description => concept["description"])
+
+ c.labels << Label.create(
+ :vocabulary => vocabulary,
+ :text => concept["label"],
+ :label_type => 'preferred',
+ :language => 'en')
+
+ if concept["alternate"]
+ concept["alternate"].each do |alternate|
+
+ c.labels << Label.create(
+ :vocabulary => vocabulary,
+ :text => alternate,
+ :label_type => 'alternate',
+ :language => 'en')
+ end
+ end
+
+ if concept["hidden"]
+ concept["hidden"].each do |hidden|
+
+ c.labels << Label.create(
+ :vocabulary => vocabulary,
+ :text => hidden,
+ :label_type => 'hidden',
+ :language => 'en')
+ end
+ end
+
+ vocabulary.concepts << c
+
+ end
+ end
+
+end
+
Modified: trunk/vendor/plugins/structured_data/lib/auto_migrate.rb (2558 => 2559)
--- trunk/vendor/plugins/structured_data/lib/auto_migrate.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/vendor/plugins/structured_data/lib/auto_migrate.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -11,8 +11,8 @@
SCHEMA = "config/base_schema.xml"
SCHEMA_D = "config/schema.d"
COLUMN_ATTRIBUTES = ['name', 'type', 'default']
- BELONGS_TO_ATTRIBUTES = ['polymorphic']
- HAS_MANY_ATTRIBUTES = ['target', 'through', 'foreign_key']
+ BELONGS_TO_ATTRIBUTES = ['polymorphic', 'class_name', 'foreign_key']
+ HAS_MANY_ATTRIBUTES = ['target', 'through', 'foreign_key', 'source', 'dependent', 'conditions', 'class_name']
def self.schema
@@ -255,7 +255,7 @@
get_model(class_name)
rescue NameError
- logger.info("Structured data: instantiating #{class_name}")
+ # logger.info("Structured data: instantiating #{class_name}")
# model object not defined. create it
Modified: trunk/vendor/plugins/structured_data/lib/structured_data.rb (2558 => 2559)
--- trunk/vendor/plugins/structured_data/lib/structured_data.rb 2011-02-10 16:03:28 UTC (rev 2558)
+++ trunk/vendor/plugins/structured_data/lib/structured_data.rb 2011-02-12 15:34:49 UTC (rev 2559)
@@ -24,6 +24,10 @@
bits.push(":through => :#{association[:through]}") if association[:through]
bits.push(":foreign_key => :#{association[:foreign_key]}") if association[:foreign_key]
+ bits.push(":source => :#{association[:source]}") if association[:source]
+ bits.push(":dependent => :#{association[:dependent]}") if association[:dependent]
+ bits.push(":conditions => \"#{association[:conditions]}\"") if association[:conditions]
+ bits.push(":class_name => \"#{association[:class_name]}\"") if association[:class_name]
line = "has_many #{bits.join(', ')}"
self.class_eval(line)
@@ -32,6 +36,8 @@
bits = [":#{association[:target].singularize}"]
bits.push(":polymorphic => #{association[:polymorphic]}") if association[:polymorphic]
+ bits.push(":class_name => \"#{association[:class_name]}\"") if association[:class_name]
+ bits.push(":foreign_key => :#{association[:foreign_key]}") if association[:foreign_key]
line = "belongs_to #{bits.join(', ')}"
self.class_eval(line)