class Orvos::V1::MetadataController < ApplicationController
def index
- if params[:target_kind] and params[:target_uuid]
- @objects = Metadatum.where('target_kind=? and target_uuid=?',
- params[:target_kind], params[:target_uuid])
+ if params[:tail_kind] and params[:tail]
+ @objects = Metadatum.where('tail_kind=? and tail=?',
+ params[:tail_kind], params[:tail])
end
super
end
type: col.type }
end
end
- if k.respond_to? :add_schema_columns
- classes[k].concat k.add_schema_columns
- end
end
render json: classes
end
include KindAndEtag
include CommonApiTemplate
serialize :info, Hash
- before_validation :populate_native_target
-
- def self.add_schema_columns
- [ { name: :head_kind, type: :string },
- { name: :head_uuid, type: :string } ]
- end
api_accessible :superuser, :extend => :common do |t|
- t.add :target_kind
- t.add :target_uuid
+ t.add :tail_kind
+ t.add :tail
t.add :metadata_class
- t.add :key
- t.add :value
- t.add :info
+ t.add :name
t.add :head_kind
- t.add :head_uuid
+ t.add :head
+ t.add :info
end
def info
@info ||= Hash.new
super
end
-
- def head_kind
- @head_kind if populate_head_object
- end
-
- def head_uuid
- @head_uuid if populate_head_object
- end
-
- protected
-
- def populate_head_object
- @head_object ||= begin
- @head_kind = self.value.
- sub(/^(.*)#.*/,'\1')
- logger.debug @head_kind
- class_name = @head_kind.
- sub(/^orvos#/,'').
- pluralize.
- classify
- logger.debug "class_name is #{class_name}"
- @head_uuid = self.value.split('#').last
- logger.debug "uuid is @head_uuid"
- @head_object = class_name.
- constantize.
- where('uuid = ?', @head_uuid).
- first
- @head_object
- rescue
- @head_kind = nil
- @head_uuid = nil
- false
- end || false unless @head_object == false
- end
-
- def populate_native_target
- begin
- class_name = target_kind.
- sub(/^orvos#/,'').
- pluralize.
- classify
- self.native_target_type = class_name
- self.native_target_id = class_name.
- constantize.
- where('uuid = ?', target_uuid).
- first.
- id
- rescue
- self.native_target_type = nil
- self.native_target_id = nil
- end
- end
end
resources :projects
match '/schema' => 'schema#show'
match '/nodes/:uuid/ping' => 'nodes#ping', :as => :ping_node
- match '/metadata/:target_kind/:target_uuid' => 'metadata#index'
+ match '/metadata/:tail_kind/:tail' => 'metadata#index'
end
end
--- /dev/null
+class RenameMetadataAttributes < ActiveRecord::Migration
+ def up
+ rename_column :metadata, :target_kind, :tail_kind
+ rename_column :metadata, :target_uuid, :tail
+ rename_column :metadata, :value, :head
+ rename_column :metadata, :key, :name
+ add_column :metadata, :head_kind, :string
+ add_index :metadata, :head
+ add_index :metadata, :head_kind
+ add_index :metadata, :tail
+ add_index :metadata, :tail_kind
+ Metadatum.where('head like ?', 'orvos#%').each do |m|
+ kind_uuid = m.head.match /^(orvos\#.*)\#([-0-9a-z]+)$/
+ if kind_uuid
+ m.update_attributes(head_kind: kind_uuid[1],
+ head: kind_uuid[2])
+ end
+ end
+ end
+
+ def down
+ Metadatum.where('head_kind is not null and head_kind <> ? and head is not null', '').each do |m|
+ m.update_attributes(head: m.head_kind + '#' + m.head)
+ end
+ remove_index :metadata, :tail_kind
+ remove_index :metadata, :tail
+ remove_index :metadata, :head_kind
+ remove_index :metadata, :head
+ rename_column :metadata, :name, :key
+ remove_column :metadata, :head_kind
+ rename_column :metadata, :head, :value
+ rename_column :metadata, :tail, :target_uuid
+ rename_column :metadata, :tail_kind, :target_kind
+ end
+end
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130116215213) do
+ActiveRecord::Schema.define(:version => 20130118002239) do
create_table "collections", :force => true do |t|
t.string "locator"
t.string "modified_by_client"
t.string "modified_by_user"
t.datetime "modified_at"
- t.string "target_uuid"
- t.string "target_kind"
+ t.string "tail"
+ t.string "tail_kind"
t.integer "native_target_id"
t.string "native_target_type"
t.string "metadata_class"
- t.string "key"
- t.string "value"
+ t.string "name"
+ t.string "head"
t.text "info"
t.datetime "updated_at"
+ t.string "head_kind"
end
+ add_index "metadata", ["head"], :name => "index_metadata_on_head"
+ add_index "metadata", ["head_kind"], :name => "index_metadata_on_head_kind"
+ add_index "metadata", ["tail"], :name => "index_metadata_on_tail"
+ add_index "metadata", ["tail_kind"], :name => "index_metadata_on_tail_kind"
add_index "metadata", ["uuid"], :name => "index_metadata_on_uuid", :unique => true
create_table "nodes", :force => true do |t|