From 7ff8741b5ced219e03f6afc524f00b6074d0927d Mon Sep 17 00:00:00 2001 From: Johannes Nickel Date: Mon, 16 Jul 2012 00:12:25 +0200 Subject: [PATCH 1/2] Revert "Created initial object link model" This reverts commit 7be711dc2616e9fb8c0f87b8e694ffa844370178. --- .gitignore | 4 + app/controllers/getting_started_controller.rb | 2 +- app/models/link.rb | 114 +----------------- db/migrate/20120101000010_create_ticket.rb | 12 +- 4 files changed, 15 insertions(+), 117 deletions(-) diff --git a/.gitignore b/.gitignore index 5c2c63764..e2a18853b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ # Ignore .project files /.project +<<<<<<< HEAD Gemfile.lock # Ignore mac stuff @@ -28,3 +29,6 @@ Gemfile.lock # Ignore local changes to schema.rb (e. g. through extentions) db/schema.rb +======= +db/schema.rb +>>>>>>> Revert "Created initial object link model" diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index b37624900..74a243140 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -5,7 +5,7 @@ class GettingStartedController < ApplicationController # check if first user already exists master_user = 0 count = User.all.count() - if count == 1 + if count >= 2 master_user = 1 end diff --git a/app/models/link.rb b/app/models/link.rb index 6386b35fd..44ae62d40 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,113 +1,7 @@ class Link < ActiveRecord::Base + class Object < ActiveRecord::Base + end - #before_create :check_object - #after_create :after_create, :cache_delete - #after_update :cache_delete - #after_destroy :cache_delete - -=begin - Link.add(:link_types_id=>12, - :link_object_source => 'Ticket', - :link_object_source_value => 1, - :link_object_target=> 'Ticket', - :link_object_target_value=> 1) - - Link.add(:link_types_id=>12, - :link_object_source_id => '1', - :link_object_source_value => 1, - :link_object_target_id=> '1', - :link_object_target_value=> 1) - - Link.get_links_for_source_object(:link_object => 'Ticket', - :link_object_value => 1) - - Link.get_links_for_target_object(:link_object => 'Ticket', - :link_object_value => 1) - - Link.delete_link_by_source(:source_value=>1) - - Link.delete_link_by_target(:target_value=>1) - - Link.delete_all_links_by_value(:object_value=>1) -=end - - has_many :link_types - - def self.get_links_for_source_object(data) - linkobject_id = self.get_linktype_by_name(:name=>data[:link_object]) - if linkobject_id - where(:link_object_source_id=>linkobject_id,:link_object_source_value=>data[:link_object_value]) - end - end - - def self.get_links_for_target_object(data) - linkobject_id = self.get_linktype_by_name(:name=>data[:link_object]) - if linkobject_id - where(:link_object_target_id=>linkobject_id,:link_object_target_value=>data[:link_object_value]) - end - end - - def self.add(data) - if data.has_key?(:link_object_source) - # it exists we have to delete it - linkobject_id = self.get_linktype_by_name(:name=>data[:link_object_source]) - data[:link_object_source_id] = linkobject_id - data.delete(:link_object_source) - end - - if data.has_key?(:link_object_target) - # it exists we have to delete it - linkobject_id = self.get_linktype_by_name(:name=>data[:link_object_target]) - data[:link_object_target_id] = linkobject_id - data.delete(:link_object_target) - end - - Link.create(data) - end - - def self.delete_link_by_source(data) - Link.where(:link_object_source_value=>data[:source_value]).destroy_all - end - - def self.delete_link_by_target(data) - Link.where(:link_object_target_value => data[:target_value]).destroy_all - end - - def self.delete_all_links_by_value(data) - Link.where(["link_object_source_value = ? or link_object_target_value = ?", data[:object_value],data[:object_value]]).destroy_all - end - - - private - def self.get_linktype_by_name(data) - - linkid = Link::Object.where(:name=>data[:name]).first - if linkid - return linkid.id - else - return nil - end - return linkid - end - - #checks for a valid link type - def check_valid_link_type - Rails.logger.info "Logger Test" - puts "pre check link type" - end - - def get_linkobject_by_key - puts "check for exisiting link" - end - - #checks for an exisiting ling - def check_existing_link - puts "check for exisiting link" - end + class Type < ActiveRecord::Base + end end - -class Link::Type < ActiveRecord::Base -end - -class Link::Object < ActiveRecord::Base -end \ No newline at end of file diff --git a/db/migrate/20120101000010_create_ticket.rb b/db/migrate/20120101000010_create_ticket.rb index 41f876a32..f2c56df5e 100644 --- a/db/migrate/20120101000010_create_ticket.rb +++ b/db/migrate/20120101000010_create_ticket.rb @@ -186,14 +186,14 @@ class CreateTicket < ActiveRecord::Migration add_index :link_objects, [:name], :unique => true create_table :links do |t| - t.references :link_types, :null => false - t.column :link_object_source_id, :integer, :null => false - t.column :link_object_source_value, :integer, :null => false - t.column :link_object_target_id, :integer, :null => false - t.column :link_object_target_value, :integer, :null => false + t.references :link_types, :null => false + t.column :source_object_id, :integer, :null => false + t.column :source_key, :string, :limit => 50, :null => false + t.column :target_object_id, :integer, :null => false + t.column :target_key, :string, :limit => 50, :null => false t.timestamps end - add_index :links, [:link_object_source_id, :link_object_source_value, :link_object_target_id, :link_object_target_value, :link_types_id], :unique => true, :name => 'links_uniq_total' + add_index :links, [:source_object_id, :source_key, :target_object_id, :target_key, :link_types_id], :unique => true, :name => 'links_uniq_total' end def self.down From 21b0b6957e6a8d6a02207c740192e4d60e9db942 Mon Sep 17 00:00:00 2001 From: Johannes Nickel Date: Mon, 23 Jul 2012 15:15:03 +0200 Subject: [PATCH 2/2] Revert "Revert "Created initial object link model"" This reverts commit 7ff8741b5ced219e03f6afc524f00b6074d0927d. --- .gitignore | 4 - app/controllers/getting_started_controller.rb | 2 +- app/models/link.rb | 114 +++++++++++++++++- db/migrate/20120101000010_create_ticket.rb | 12 +- 4 files changed, 117 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index e2a18853b..5c2c63764 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ # Ignore .project files /.project -<<<<<<< HEAD Gemfile.lock # Ignore mac stuff @@ -29,6 +28,3 @@ Gemfile.lock # Ignore local changes to schema.rb (e. g. through extentions) db/schema.rb -======= -db/schema.rb ->>>>>>> Revert "Created initial object link model" diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index 74a243140..b37624900 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -5,7 +5,7 @@ class GettingStartedController < ApplicationController # check if first user already exists master_user = 0 count = User.all.count() - if count >= 2 + if count == 1 master_user = 1 end diff --git a/app/models/link.rb b/app/models/link.rb index 44ae62d40..6386b35fd 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,7 +1,113 @@ class Link < ActiveRecord::Base - class Object < ActiveRecord::Base - end - class Type < ActiveRecord::Base - end + #before_create :check_object + #after_create :after_create, :cache_delete + #after_update :cache_delete + #after_destroy :cache_delete + +=begin + Link.add(:link_types_id=>12, + :link_object_source => 'Ticket', + :link_object_source_value => 1, + :link_object_target=> 'Ticket', + :link_object_target_value=> 1) + + Link.add(:link_types_id=>12, + :link_object_source_id => '1', + :link_object_source_value => 1, + :link_object_target_id=> '1', + :link_object_target_value=> 1) + + Link.get_links_for_source_object(:link_object => 'Ticket', + :link_object_value => 1) + + Link.get_links_for_target_object(:link_object => 'Ticket', + :link_object_value => 1) + + Link.delete_link_by_source(:source_value=>1) + + Link.delete_link_by_target(:target_value=>1) + + Link.delete_all_links_by_value(:object_value=>1) +=end + + has_many :link_types + + def self.get_links_for_source_object(data) + linkobject_id = self.get_linktype_by_name(:name=>data[:link_object]) + if linkobject_id + where(:link_object_source_id=>linkobject_id,:link_object_source_value=>data[:link_object_value]) + end + end + + def self.get_links_for_target_object(data) + linkobject_id = self.get_linktype_by_name(:name=>data[:link_object]) + if linkobject_id + where(:link_object_target_id=>linkobject_id,:link_object_target_value=>data[:link_object_value]) + end + end + + def self.add(data) + if data.has_key?(:link_object_source) + # it exists we have to delete it + linkobject_id = self.get_linktype_by_name(:name=>data[:link_object_source]) + data[:link_object_source_id] = linkobject_id + data.delete(:link_object_source) + end + + if data.has_key?(:link_object_target) + # it exists we have to delete it + linkobject_id = self.get_linktype_by_name(:name=>data[:link_object_target]) + data[:link_object_target_id] = linkobject_id + data.delete(:link_object_target) + end + + Link.create(data) + end + + def self.delete_link_by_source(data) + Link.where(:link_object_source_value=>data[:source_value]).destroy_all + end + + def self.delete_link_by_target(data) + Link.where(:link_object_target_value => data[:target_value]).destroy_all + end + + def self.delete_all_links_by_value(data) + Link.where(["link_object_source_value = ? or link_object_target_value = ?", data[:object_value],data[:object_value]]).destroy_all + end + + + private + def self.get_linktype_by_name(data) + + linkid = Link::Object.where(:name=>data[:name]).first + if linkid + return linkid.id + else + return nil + end + return linkid + end + + #checks for a valid link type + def check_valid_link_type + Rails.logger.info "Logger Test" + puts "pre check link type" + end + + def get_linkobject_by_key + puts "check for exisiting link" + end + + #checks for an exisiting ling + def check_existing_link + puts "check for exisiting link" + end end + +class Link::Type < ActiveRecord::Base +end + +class Link::Object < ActiveRecord::Base +end \ No newline at end of file diff --git a/db/migrate/20120101000010_create_ticket.rb b/db/migrate/20120101000010_create_ticket.rb index f2c56df5e..41f876a32 100644 --- a/db/migrate/20120101000010_create_ticket.rb +++ b/db/migrate/20120101000010_create_ticket.rb @@ -186,14 +186,14 @@ class CreateTicket < ActiveRecord::Migration add_index :link_objects, [:name], :unique => true create_table :links do |t| - t.references :link_types, :null => false - t.column :source_object_id, :integer, :null => false - t.column :source_key, :string, :limit => 50, :null => false - t.column :target_object_id, :integer, :null => false - t.column :target_key, :string, :limit => 50, :null => false + t.references :link_types, :null => false + t.column :link_object_source_id, :integer, :null => false + t.column :link_object_source_value, :integer, :null => false + t.column :link_object_target_id, :integer, :null => false + t.column :link_object_target_value, :integer, :null => false t.timestamps end - add_index :links, [:source_object_id, :source_key, :target_object_id, :target_key, :link_types_id], :unique => true, :name => 'links_uniq_total' + add_index :links, [:link_object_source_id, :link_object_source_value, :link_object_target_id, :link_object_target_value, :link_types_id], :unique => true, :name => 'links_uniq_total' end def self.down