From b234199d0a1133b44fa54ca92250abcad603ecd6 Mon Sep 17 00:00:00 2001 From: Johannes Nickel Date: Mon, 16 Jul 2012 00:08:02 +0200 Subject: [PATCH 1/2] Created initial object link model - add link(s) - remove links - get links todo: - exception handling - checks - unit tests --- Gemfile.lock | 179 --------------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 817ab49ca..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,179 +0,0 @@ -GEM - remote: http://rubygems.org/ - specs: - actionmailer (3.2.3) - actionpack (= 3.2.3) - mail (~> 2.4.4) - actionpack (3.2.3) - activemodel (= 3.2.3) - activesupport (= 3.2.3) - builder (~> 3.0.0) - erubis (~> 2.7.0) - journey (~> 1.0.1) - rack (~> 1.4.0) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.1.2) - activemodel (3.2.3) - activesupport (= 3.2.3) - builder (~> 3.0.0) - activerecord (3.2.3) - activemodel (= 3.2.3) - activesupport (= 3.2.3) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.3) - activemodel (= 3.2.3) - activesupport (= 3.2.3) - activesupport (3.2.3) - i18n (~> 0.6) - multi_json (~> 1.0) - arel (3.0.2) - builder (3.0.0) - coffee-rails (3.2.2) - coffee-script (>= 2.2.0) - railties (~> 3.2.0) - coffee-script (2.2.0) - coffee-script-source - execjs - coffee-script-source (1.3.3) - daemons (1.1.8) - delayed_job (3.0.2) - activesupport (~> 3.0) - delayed_job_active_record (0.3.2) - activerecord (> 2.1.0) - delayed_job (~> 3.0.0) - eco (1.0.0) - coffee-script - eco-source - execjs - eco-source (1.1.0.rc.1) - erubis (2.7.0) - execjs (1.4.0) - multi_json (~> 1.0) - faraday (0.8.0) - multipart-post (~> 1.1) - hashie (1.2.0) - hike (1.2.1) - httpauth (0.1) - i18n (0.6.0) - journey (1.0.3) - jquery-rails (2.0.2) - railties (>= 3.2.0, < 5.0) - thor (~> 0.14) - json (1.7.3) - json (1.7.3-java) - koala (1.1.0) - multi_json (~> 1.0) - multipart-post (~> 1.0) - mail (2.4.4) - i18n (>= 0.4.0) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.18) - multi_json (1.3.5) - multipart-post (1.1.5) - mysql2 (0.3.11) - oauth (0.4.6) - oauth2 (0.6.1) - faraday (~> 0.7) - httpauth (~> 0.1) - multi_json (~> 1.3) - omniauth (1.1.0) - hashie (~> 1.2) - rack - omniauth-facebook (1.3.0) - omniauth-oauth2 (~> 1.0.2) - omniauth-google-oauth2 (0.1.9) - omniauth (~> 1.0) - omniauth-oauth2 - omniauth-linkedin (0.0.6) - omniauth-oauth (~> 1.0.0) - omniauth-oauth (1.0.1) - oauth - omniauth (~> 1.0) - omniauth-oauth2 (1.0.2) - oauth2 (~> 0.6.0) - omniauth (~> 1.0) - omniauth-twitter (0.0.11) - multi_json (~> 1.3) - omniauth-oauth (~> 1.0) - polyglot (0.3.3) - rack (1.4.1) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.2) - rack - rack-test (0.6.1) - rack (>= 1.0) - rails (3.2.3) - actionmailer (= 3.2.3) - actionpack (= 3.2.3) - activerecord (= 3.2.3) - activeresource (= 3.2.3) - activesupport (= 3.2.3) - bundler (~> 1.0) - railties (= 3.2.3) - railties (3.2.3) - actionpack (= 3.2.3) - activesupport (= 3.2.3) - rack-ssl (~> 1.3.2) - rake (>= 0.8.7) - rdoc (~> 3.4) - thor (~> 0.14.6) - rake (0.9.2.2) - rdoc (3.12) - json (~> 1.4) - sass (3.1.18) - sass-rails (3.2.5) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - simple-rss (1.2.3) - simple_oauth (0.1.8) - sprockets (2.1.3) - hike (~> 1.2) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.6) - thor (0.14.6) - tilt (1.3.3) - treetop (1.4.10) - polyglot - polyglot (>= 0.3.1) - twitter (2.4.0) - activesupport (>= 2.3.9, < 4) - faraday (~> 0.8) - multi_json (~> 1.3) - simple_oauth (~> 0.1.6) - tzinfo (0.3.33) - uglifier (1.2.4) - execjs (>= 0.3.0) - multi_json (>= 1.0.2) - -PLATFORMS - java - ruby - -DEPENDENCIES - coffee-rails (~> 3.2.2) - daemons - delayed_job_active_record - eco - jquery-rails - json - koala - mail - mime-types - mysql2 - omniauth - omniauth-facebook - omniauth-google-oauth2 - omniauth-linkedin - omniauth-twitter - rails (= 3.2.3) - sass-rails (~> 3.2.4) - simple-rss - sqlite3 - twitter - uglifier (>= 1.2.3) From 7be711dc2616e9fb8c0f87b8e694ffa844370178 Mon Sep 17 00:00:00 2001 From: Johannes Nickel Date: Mon, 16 Jul 2012 00:12:06 +0200 Subject: [PATCH 2/2] Created initial object link model - add link(s) - remove links - get links todo: - exception handling - checks - unit tests --- .gitignore | 5 +- app/controllers/getting_started_controller.rb | 2 +- app/models/link.rb | 114 +++++++++++++++++- db/migrate/20120101000010_create_ticket.rb | 12 +- 4 files changed, 121 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 74c27890c..69ea0ede8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,7 @@ # Ignore .project files /.project -db/schema.rb \ No newline at end of file +db/schema.rb +Gemfile.lock + +.DS_Store 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