Class: MoveToGo::RootModel
- Inherits:
-
Object
- Object
- MoveToGo::RootModel
- Includes:
- SerializeHelper
- Defined in:
- lib/move-to-go/model/rootmodel.rb
Overview
The root model for Move To Go. This class is the container for everything else.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
The configuration is used to set run-time properties for move-to-go.
-
#coworkers ⇒ Object
Returns the value of attribute coworkers.
-
#deals ⇒ Object
Returns the value of attribute deals.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#histories ⇒ Object
Returns the value of attribute histories.
-
#meetings ⇒ Object
Returns the value of attribute meetings.
-
#migrator_coworker ⇒ Object
the migrator_coworker is a special coworker that is set as responsible for objects that requires a coworker, eg a history.
-
#organizations ⇒ Object
Returns the value of attribute organizations.
-
#persons ⇒ Object
readonly
Returns the value of attribute persons.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#todos ⇒ Object
Returns the value of attribute todos.
Instance Method Summary collapse
- #add_client_visit(client_visit) ⇒ Object
- #add_comment(comment) ⇒ Object
- #add_coworker(coworker) ⇒ Object
-
#add_deal(deal) ⇒ Object
Adds the specifed deal object to the model.
- #add_file(file) ⇒ Object
-
#add_history(history) ⇒ Object
Adds the specifed history object to the model.
- #add_link(link) ⇒ Object
- #add_meeting(meeting) ⇒ Object
-
#add_organization(organization) ⇒ Object
Adds the specifed organization object to the model.
- #add_sales_call(sales_call) ⇒ Object
- #add_talked_to(talked_to) ⇒ Object
- #add_todo(todo) ⇒ Object
- #add_tried_to_reach(tried_to_reach) ⇒ Object
- #configure ⇒ Object
- #create_zip(filename, xml, files) ⇒ Object
-
#find_coworker(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a coworker based on one of its property.
- #find_coworker_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#find_deal(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a deal based on one of its property.
- #find_deal_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#find_deals_for_organization(organization) ⇒ Object
find deals for organization using Organization#integration_id.
-
#find_document(type, report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a document based on one of its property.
-
#find_history(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a history based on one of its property.
- #find_history_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#find_meeting(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a meeting based on one of its property.
- #find_meeting_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#find_organization(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a organization based on one of its property.
- #find_organization_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#find_person(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a person based on one of its property.
- #find_person_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#find_todo(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a todo based on one of its property.
- #find_todo_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
-
#initialize ⇒ RootModel
constructor
A new instance of RootModel.
-
#map_organization_duplicates!(fields_to_check = [:name], &block) ⇒ Object
Maps organization duplicates from the rootmodel, only returned.
- #remove_organization(organization) ⇒ Object
- #report_rootmodel_status ⇒ Object
-
#sanity_check ⇒ Object
Returns a string describing problems with the data.
-
#select_coworkers(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds coworkers based on one of their property.
-
#select_deals(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds deals based on one of their property.
-
#select_documents(type, report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a document based on one of its property.
-
#select_histories(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a history based on one of its property.
-
#select_meetings(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a meeting based on one of its property.
-
#select_organizations(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds organizations based on one of their property.
-
#select_persons(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds persons based on one of their property.
-
#select_todos(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a todo based on one of its property.
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
- #validate(ignore_invalid_files = false, max_file_size) ⇒ Object
Methods included from SerializeHelper
#get_import_rows, #serialize, #serialize_to_file
Constructor Details
#initialize ⇒ RootModel
Returns a new instance of RootModel.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/move-to-go/model/rootmodel.rb', line 46 def initialize() @settings = Settings.new @organizations = Organizations.new self @coworkers = {} @migrator_coworker = Coworker.new @migrator_coworker.integration_id = "migrator" @migrator_coworker.first_name = "Migrator" @migrator_coworker.email = "[email protected]" @coworkers[@migrator_coworker.integration_id] = @migrator_coworker @deals = {} @histories = {} @todos = {} @meetings = {} @documents = Documents.new @configuration = {} configure end |
Instance Attribute Details
#configuration ⇒ Object
The configuration is used to set run-time properties for move-to-go. This should not be confused with the model’s settings. Sets the following properties:
ALLOW_DEALS_WITHOUT_RESPONSIBLE - if set to true, deals without a responsible will NOT have the import user set as default.
23 24 25 |
# File 'lib/move-to-go/model/rootmodel.rb', line 23 def configuration @configuration end |
#coworkers ⇒ Object
Returns the value of attribute coworkers.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def coworkers @coworkers end |
#deals ⇒ Object
Returns the value of attribute deals.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def deals @deals end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
25 26 27 |
# File 'lib/move-to-go/model/rootmodel.rb', line 25 def documents @documents end |
#histories ⇒ Object
Returns the value of attribute histories.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def histories @histories end |
#meetings ⇒ Object
Returns the value of attribute meetings.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def meetings @meetings end |
#migrator_coworker ⇒ Object
the migrator_coworker is a special coworker that is set as responsible for objects that requires a coworker, eg a history.
12 13 14 |
# File 'lib/move-to-go/model/rootmodel.rb', line 12 def migrator_coworker @migrator_coworker end |
#organizations ⇒ Object
Returns the value of attribute organizations.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def organizations @organizations end |
#persons ⇒ Object (readonly)
Returns the value of attribute persons.
25 26 27 |
# File 'lib/move-to-go/model/rootmodel.rb', line 25 def persons @persons end |
#settings ⇒ Object
Returns the value of attribute settings.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def settings @settings end |
#todos ⇒ Object
Returns the value of attribute todos.
14 15 16 |
# File 'lib/move-to-go/model/rootmodel.rb', line 14 def todos @todos end |
Instance Method Details
#add_client_visit(client_visit) ⇒ Object
261 262 263 264 265 266 267 268 269 |
# File 'lib/move-to-go/model/rootmodel.rb', line 261 def add_client_visit(client_visit) if client_visit.nil? return nil end if !client_visit.is_a?(ClientVisit) raise ArgumentError.new("Expected a ClientVisit") end add_history(client_visit) end |
#add_comment(comment) ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'lib/move-to-go/model/rootmodel.rb', line 231 def add_comment(comment) if comment.nil? return nil end if !comment.is_a?(Comment) raise ArgumentError.new("Expected a Comment") end add_history(comment) end |
#add_coworker(coworker) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/move-to-go/model/rootmodel.rb', line 78 def add_coworker(coworker) if coworker.nil? return nil end if !coworker.is_a?(Coworker) raise ArgumentError.new("Expected a coworker") end if coworker.integration_id.nil? || coworker.integration_id.length == 0 raise IntegrationIdIsRequiredError, "An integration id is required for a coworker." end if find_coworker_by_integration_id(coworker.integration_id, false) != nil raise AlreadyAddedError, "Already added a coworker with integration_id #{coworker.integration_id}" end @coworkers[coworker.integration_id] = coworker coworker.set_is_immutable return coworker end |
#add_deal(deal) ⇒ Object
Adds the specifed deal object to the model.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/move-to-go/model/rootmodel.rb', line 178 def add_deal(deal) if deal.nil? return nil end if !deal.is_a?(Deal) raise ArgumentError.new("Expected a deal") end if deal.integration_id.nil? || deal.integration_id.length == 0 raise IntegrationIdIsRequiredError, "An integration id is required for a deal." end if find_deal_by_integration_id(deal.integration_id, false) != nil raise AlreadyAddedError, "Already added a deal with integration_id #{deal.integration_id}" end if !configuration[:allow_deals_without_responsible] && deal.responsible_coworker.nil? deal.responsible_coworker = @migrator_coworker end @deals[deal.integration_id] = deal deal.set_is_immutable return deal end |
#add_file(file) ⇒ Object
368 369 370 371 372 |
# File 'lib/move-to-go/model/rootmodel.rb', line 368 def add_file(file) @documents = Documents.new if @documents == nil return @documents.add_file(file) end |
#add_history(history) ⇒ Object
Adds the specifed history object to the model.
If no integration_id has been specifed move-to-go generate one.
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/move-to-go/model/rootmodel.rb', line 281 def add_history(history) if history.nil? return nil end if !history.is_a?(History) raise ArgumentError.new("Expected a history") end if history.integration_id.nil? || history.integration_id.length == 0 history.integration_id = @histories.length.to_s end if find_history_by_integration_id(history.integration_id, false) != nil raise AlreadyAddedError, "Already added a history with integration_id #{history.integration_id}" end if history.created_by.nil? history.created_by = @migrator_coworker end @histories[history.integration_id] = history history.set_is_immutable return history end |
#add_link(link) ⇒ Object
362 363 364 365 366 |
# File 'lib/move-to-go/model/rootmodel.rb', line 362 def add_link(link) @documents = Documents.new if @documents == nil return @documents.add_link(link) end |
#add_meeting(meeting) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/move-to-go/model/rootmodel.rb', line 335 def add_meeting(meeting) if meeting.nil? return nil end if !meeting.is_a?(Meeting) raise ArgumentError.new("Expected an meeting") end if meeting.integration_id.nil? || meeting.integration_id.length == 0 meeting.integration_id = "meeting_#{@meetings.length}" end if find_meeting_by_integration_id(meeting.integration_id, false) != nil raise AlreadyAddedError, "Already added a meeting with integration_id #{meeting.integration_id}" end if meeting.created_by.nil? meeting.created_by = @migrator_coworker end @meetings[meeting.integration_id] = meeting meeting.set_is_immutable return meeting end |
#add_organization(organization) ⇒ Object
Adds the specifed organization object to the model.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/move-to-go/model/rootmodel.rb', line 107 def add_organization(organization) if organization.nil? return nil end if !organization.is_a?(Organization) raise ArgumentError.new("Expected an organization") end if organization.integration_id.nil? || organization.integration_id.length == 0 raise IntegrationIdIsRequiredError, "An integration id is required for an organization." end if find_organization_by_integration_id(organization.integration_id, false) != nil raise AlreadyAddedError, "Already added an organization with integration_id #{organization.integration_id}" end if !organization.source.nil? if !@organizations.find{|key,value| value.source.id == organization.source.id if !value.source.nil?}.nil? raise AlreadyAddedError, "Source id already exists, sourceId: #{organization.source.id}" end end @organizations[organization.integration_id] = organization organization.rootmodel = self organization.set_is_immutable return organization end |
#add_sales_call(sales_call) ⇒ Object
221 222 223 224 225 226 227 228 229 |
# File 'lib/move-to-go/model/rootmodel.rb', line 221 def add_sales_call(sales_call) if sales_call.nil? return nil end if !sales_call.is_a?(SalesCall) raise ArgumentError.new("Expected a SalesCall") end add_history(sales_call) end |
#add_talked_to(talked_to) ⇒ Object
241 242 243 244 245 246 247 248 249 |
# File 'lib/move-to-go/model/rootmodel.rb', line 241 def add_talked_to(talked_to) if talked_to.nil? return nil end if !talked_to.is_a?(TalkedTo) raise ArgumentError.new("Expected a TalkedTo") end add_history(talked_to) end |
#add_todo(todo) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/move-to-go/model/rootmodel.rb', line 308 def add_todo(todo) if todo.nil? return nil end if !todo.is_a?(Todo) raise ArgumentError.new("Expected an todo") end if todo.integration_id.nil? || todo.integration_id.length == 0 todo.integration_id = "todo_#{@todos.length}" end if find_todo_by_integration_id(todo.integration_id, false) != nil raise AlreadyAddedError, "Already added a todo with integration_id #{todo.integration_id}" end if todo.created_by.nil? todo.created_by = @migrator_coworker end @todos[todo.integration_id] = todo todo.set_is_immutable return todo end |
#add_tried_to_reach(tried_to_reach) ⇒ Object
251 252 253 254 255 256 257 258 259 |
# File 'lib/move-to-go/model/rootmodel.rb', line 251 def add_tried_to_reach(tried_to_reach) if tried_to_reach.nil? return nil end if !tried_to_reach.is_a?(TriedToReach) raise ArgumentError.new("Expected a TriedToReach") end add_history(tried_to_reach) end |
#configure ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/move-to-go/model/rootmodel.rb', line 205 def configure() if defined?(ALLOW_DEALS_WITHOUT_RESPONSIBLE) config_value = ALLOW_DEALS_WITHOUT_RESPONSIBLE.to_s configuration[:allow_deals_without_responsible] = config_value.downcase == "true" || config_value == "1" end if defined?(REPORT_RESULT) config_value = REPORT_RESULT.to_s configuration[:report_result] = config_value.downcase == "true" || config_value == "1" end end |
#create_zip(filename, xml, files) ⇒ Object
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'lib/move-to-go/model/rootmodel.rb', line 773 def create_zip(filename, xml, files) Zip::File.open("#{Dir.pwd}/#{filename}", Zip::File::CREATE) do |zip_file| puts "Add go.xml file to zip '#{filename}'..." zip_file.add('go.xml', xml) if files.length > 0 if defined?(FILES_FOLDER) && !FILES_FOLDER.empty?() puts "Files with relative path are imported from '#{FILES_FOLDER}'." root_folder = FILES_FOLDER else puts "Files with relative path are imported from the current folder (#{Dir.pwd})." root_folder = Dir.pwd end # If a file's path is absolute, then we probably dont # have the files in the same location here. For # example, the customer might have stored their files # at f:\lime-easy\documents. We must replace this part # of each file with the root_folder from above. if defined?(FILES_FOLDER_AT_CUSTOMER) && !FILES_FOLDER_AT_CUSTOMER.empty?() files_folder_at_customer = FILES_FOLDER_AT_CUSTOMER puts "Files with absolute paths will have the part '#{files_folder_at_customer}' replaced with '#{root_folder}'." else files_folder_at_customer = "" puts "Files with absolute paths will be imported from their origial location." end # 1) files/ - a folder with all files referenced from # the source. files.with_progress(" - Trying to add files to zip...").each do |file| # we dont need to check that the file exists since # we assume that rootmodel.validate has been # called before save_to_zip. file.add_to_zip_file(zip_file) end end puts "Compressing zip file ... " end end |
#find_coworker(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a coworker based on one of its property. Returns the first found matching coworker
515 516 517 518 519 |
# File 'lib/move-to-go/model/rootmodel.rb', line 515 def find_coworker(report_result=!!configuration[:report_result], &block) result = find(@coworkers.values.flatten, &block) report_failed_to_find_object("coworker") if result.nil? and report_result return result end |
#find_coworker_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
374 375 376 377 378 379 380 381 |
# File 'lib/move-to-go/model/rootmodel.rb', line 374 def find_coworker_by_integration_id(integration_id, report_result=!!configuration[:report_result]) if @coworkers.has_key?(integration_id) return @coworkers[integration_id] else report_failed_to_find_object("coworker", ":#{integration_id}") if report_result return nil end end |
#find_deal(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a deal based on one of its property. Returns the first found matching deal Method is much slower then using find_deal_by_integration_id
495 496 497 498 499 |
# File 'lib/move-to-go/model/rootmodel.rb', line 495 def find_deal(report_result=!!configuration[:report_result], &block) result = find(@deals.values.flatten, &block) report_failed_to_find_object("person") if result.nil? and report_result return result end |
#find_deal_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
440 441 442 443 444 445 446 447 |
# File 'lib/move-to-go/model/rootmodel.rb', line 440 def find_deal_by_integration_id(integration_id, report_result=!!configuration[:report_result]) if @deals.has_key?(integration_id) return @deals[integration_id] else report_failed_to_find_object("deal", ":#{integration_id}") if report_result return nil end end |
#find_deals_for_organization(organization) ⇒ Object
find deals for organization using Organization#integration_id
431 432 433 434 435 436 437 438 |
# File 'lib/move-to-go/model/rootmodel.rb', line 431 def find_deals_for_organization(organization) deals = [] deals = @deals.values.select do |deal| !deal.customer.nil? && deal.customer.integration_id == organization.integration_id end return deals end |
#find_document(type, report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a document based on one of its property. Returns the first found matching document
596 597 598 599 600 601 |
# File 'lib/move-to-go/model/rootmodel.rb', line 596 def find_document(type, report_result=!!configuration[:report_result], &block) result = find(@documents.files, &block) if type == :file result = find(@documents.links, &block) if type == :link report_failed_to_find_object("document") if result.nil? and report_result return result end |
#find_history(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a history based on one of its property. Returns the first found matching history
536 537 538 539 540 |
# File 'lib/move-to-go/model/rootmodel.rb', line 536 def find_history(report_result=!!configuration[:report_result], &block) result = find(@histories.values.flatten, &block) report_failed_to_find_object("history") if result.nil? and report_result return result end |
#find_history_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
403 404 405 406 407 408 409 410 |
# File 'lib/move-to-go/model/rootmodel.rb', line 403 def find_history_by_integration_id(integration_id, report_result=!!configuration[:report_result]) if @histories.has_key?(integration_id) return @histories[integration_id] else report_failed_to_find_object("history", ":#{integration_id}") if report_result return nil end end |
#find_meeting(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a meeting based on one of its property. Returns the first found matching meeting
576 577 578 579 580 |
# File 'lib/move-to-go/model/rootmodel.rb', line 576 def find_meeting(report_result=!!configuration[:report_result], &block) result = find(@meetings.values.flatten, &block) report_failed_to_find_object("meeting") if result.nil? and report_result return result end |
#find_meeting_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
421 422 423 424 425 426 427 428 |
# File 'lib/move-to-go/model/rootmodel.rb', line 421 def find_meeting_by_integration_id(integration_id, report_result=!!configuration[:report_result]) if @meetings.has_key?(integration_id) return @meetings[integration_id] else report_failed_to_find_object("meeting", ":#{integration_id}") if report_result return nil end end |
#find_organization(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a organization based on one of its property. Returns the first found matching organization Method is much slower then using find_organization_by_integration_id
454 455 456 457 458 |
# File 'lib/move-to-go/model/rootmodel.rb', line 454 def find_organization(report_result=!!configuration[:report_result], &block) result = find(@organizations.values.flatten, &block) report_failed_to_find_object("organization") if result.nil? and report_result return result end |
#find_organization_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
383 384 385 386 387 388 389 390 391 |
# File 'lib/move-to-go/model/rootmodel.rb', line 383 def find_organization_by_integration_id(integration_id, report_result=!!configuration[:report_result]) if @organizations.has_key?(integration_id) return @organizations[integration_id] else report_failed_to_find_object("organization", ":#{integration_id}") if report_result return nil end end |
#find_person(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a person based on one of its property. Returns the first found matching person
474 475 476 477 478 |
# File 'lib/move-to-go/model/rootmodel.rb', line 474 def find_person(report_result=!!configuration[:report_result], &block) result = find(persons, &block) report_failed_to_find_object("person") if result.nil? and report_result return result end |
#find_person_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
393 394 395 396 397 398 399 400 401 |
# File 'lib/move-to-go/model/rootmodel.rb', line 393 def find_person_by_integration_id(integration_id, report_result=!!configuration[:report_result]) return nil if @organizations.nil? @organizations.each do |key, organization| person = organization.find_employee_by_integration_id(integration_id) return person if person end report_failed_to_find_object("person", ":#{integration_id}") if report_result return nil end |
#find_todo(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a todo based on one of its property. Returns the first found matching todo
556 557 558 559 560 |
# File 'lib/move-to-go/model/rootmodel.rb', line 556 def find_todo(report_result=!!configuration[:report_result], &block) result = find(@todos.values.flatten, &block) report_failed_to_find_object("todo") if result.nil? and report_result return result end |
#find_todo_by_integration_id(integration_id, report_result = !!configuration[:report_result])) ⇒ Object
412 413 414 415 416 417 418 419 |
# File 'lib/move-to-go/model/rootmodel.rb', line 412 def find_todo_by_integration_id(integration_id, report_result=!!configuration[:report_result]) if @todos.has_key?(integration_id) return @todos[integration_id] else report_failed_to_find_object("todo", ":#{integration_id}") if report_result return nil end end |
#map_organization_duplicates!(fields_to_check = [:name], &block) ⇒ Object
Maps organization duplicates from the rootmodel, only returned
827 828 829 830 831 832 |
# File 'lib/move-to-go/model/rootmodel.rb', line 827 def map_organization_duplicates!(fields_to_check=[:name], &block) dc = MoveToGo::DuplicateChecker.new(fields_to_check, self) dc.map_organization_duplicates! do |duplicate_set| yield duplicate_set end end |
#remove_organization(organization) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/move-to-go/model/rootmodel.rb', line 137 def remove_organization(organization) if organization.nil? return nil end if !organization.is_a?(Organization) raise ArgumentError.new("Expected an organization") end if organization.integration_id.nil? || organization.integration_id.length == 0 raise IntegrationIdIsRequiredError, "An integration id is required to remove an organization" end find_deals_for_organization(organization) .each{|deal| @deals.delete(deal.integration_id)} select_histories{|history| history.organization == organization} .each{|history| @histories.delete(history.integration_id)} select_todos{|todo| todo.organization == organization} .each{|todo| @todo.delete(todo.integration_id)} select_meetings{|meeting| meeting.organization == organization} .each{|meeting| @meeting.delete(meeting.integration_id)} select_documents(:file){|file| file.organization == organization} .each{|file| @documents.files.delete(file.integration_id)} select_documents(:link){|doc| doc.organization == organization} .each{|doc| @documents.links.delete(doc.integration_id)} @organizations.delete(organization.integration_id) end |
#report_rootmodel_status ⇒ Object
813 814 815 816 817 818 819 820 821 822 823 824 |
# File 'lib/move-to-go/model/rootmodel.rb', line 813 def report_rootmodel_status #nbr_of_persons = @organizations.collect{|k, o| o.employees}.flatten.compact.length nbr_of_documents = @documents.files.length + @documents.links.length puts "Rootmodel contains:\n" \ " Organizations: #{@organizations.length}\n" \ " Persons: #{persons.length}\n" \ " Deals: #{@deals.length}\n" \ " History logs: #{@histories.length}\n" \ " Todos: #{@todos.length}\n" \ " Meetings: #{@meetings.length}\n" \ " Documents: #{nbr_of_documents}" end |
#sanity_check ⇒ Object
Returns a string describing problems with the data. For instance if integration_id for any entity is not unique.
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/move-to-go/model/rootmodel.rb', line 616 def sanity_check error = String.new # dups = get_integration_id_duplicates(with_non_empty_integration_id(@coworkers)) # dups_error_items = (dups.collect{|coworker| coworker.integration_id}).compact # if dups.length > 0 # error = "#{error}\nDuplicate coworker integration_id: #{dups_error_items.join(", ")}." # end # dups = get_integration_id_duplicates(with_non_empty_integration_id(@organizations)) # dups_error_items = (dups.collect{|org| org.integration_id}).compact # if dups.length > 0 # error = "#{error}\nDuplicate organization integration_id: #{dups_error_items.join(", ")}." # end # dups = get_integration_id_duplicates(with_non_empty_integration_id(@deals)) # dups_error_items = (dups.collect{|deal| deal.integration_id}).compact # if dups_error_items.length > 0 # error = "#{error}\nDuplicate deal integration_id: #{dups_error_items.join(", ")}." # end persons = @organizations.collect{|k, o| o.employees}.flatten.compact dups = get_integration_id_duplicates(with_non_empty_integration_id(persons)) dups_error_items = (dups.collect{|person| person.integration_id}).compact if dups_error_items.length > 0 error = "#{error}\nDuplicate person integration_id: #{dups_error_items.join(", ")}." end dups = get_integration_id_duplicates(with_non_empty_integration_id(@documents.links)) dups_error_items = (dups.collect{|l| l.integration_id}).compact if dups_error_items.length > 0 error = "#{error}\nDuplicate link integration_id: #{dups_error_items.join(", ")}." end return error.strip end |
#select_coworkers(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds coworkers based on one of their property. Returns all matching coworkers
525 526 527 528 529 |
# File 'lib/move-to-go/model/rootmodel.rb', line 525 def select_coworkers(report_result=!!configuration[:report_result], &block) result = select(@coworkers, &block) report_failed_to_find_object("coworker") if result.empty? and report_result return result end |
#select_deals(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds deals based on one of their property. Returns all matching deals
505 506 507 508 509 |
# File 'lib/move-to-go/model/rootmodel.rb', line 505 def select_deals(report_result=!!configuration[:report_result], &block) result = select(@deals.values.flatten, &block) report_failed_to_find_object("deal") if result.empty? and report_result return result end |
#select_documents(type, report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a document based on one of its property. Returns all found matching document
607 608 609 610 611 612 |
# File 'lib/move-to-go/model/rootmodel.rb', line 607 def select_documents(type, report_result=!!configuration[:report_result], &block) result = select(@documents.files, &block) if type == :file result = select(@documents.links, &block) if type == :link report_failed_to_find_object("document") if result.nil? and report_result return result end |
#select_histories(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a history based on one of its property. Returns all found matching history
546 547 548 549 550 |
# File 'lib/move-to-go/model/rootmodel.rb', line 546 def select_histories(report_result=!!configuration[:report_result], &block) result = select(@histories.values.flatten, &block) report_failed_to_find_object("history") if result.nil? and report_result return result end |
#select_meetings(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a meeting based on one of its property. Returns all found matching meeting
586 587 588 589 590 |
# File 'lib/move-to-go/model/rootmodel.rb', line 586 def select_meetings(report_result=!!configuration[:report_result], &block) result = select(@meetings.values.flatten, &block) report_failed_to_find_object("meeting") if result.nil? and report_result return result end |
#select_organizations(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds organizations based on one of their property. Returns all matching organizations
464 465 466 467 468 |
# File 'lib/move-to-go/model/rootmodel.rb', line 464 def select_organizations(report_result=!!configuration[:report_result], &block) result = select(@organizations.values.flatten, &block) report_failed_to_find_object("organization") if result.empty? and report_result return result end |
#select_persons(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds persons based on one of their property. Returns all matching persons
484 485 486 487 488 |
# File 'lib/move-to-go/model/rootmodel.rb', line 484 def select_persons(report_result=!!configuration[:report_result], &block) result = select(persons, &block) report_failed_to_find_object("person") if result.empty? and report_result return result end |
#select_todos(report_result = !!configuration[:report_result],, &block) ⇒ Object
Finds a todo based on one of its property. Returns all found matching todo
566 567 568 569 570 |
# File 'lib/move-to-go/model/rootmodel.rb', line 566 def select_todos(report_result=!!configuration[:report_result], &block) result = select(@todos.values.flatten, &block) report_failed_to_find_object("todo") if result.nil? and report_result return result end |
#serialize_name ⇒ Object
40 41 42 |
# File 'lib/move-to-go/model/rootmodel.rb', line 40 def serialize_name "GoImport" end |
#serialize_variables ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/move-to-go/model/rootmodel.rb', line 27 def serialize_variables [ {:id => :settings, :type => :settings}, {:id => :coworkers, :type => :coworkers}, {:id => :organizations, :type => :organizations}, {:id => :deals, :type => :deals}, {:id => :histories, :type => :histories}, {:id => :todos, :type => :todos}, {:id => :meetings, :type => :meetings}, {:id => :documents, :type => :documents} ] end |
#validate(ignore_invalid_files = false, max_file_size) ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
# File 'lib/move-to-go/model/rootmodel.rb', line 653 def validate(ignore_invalid_files = false, max_file_size) errors = String.new warnings = String.new @coworkers.each do |key, coworker| validation_mesage = coworker.validate if !validation_mesage.empty? errors = "#{errors}\n#{validation_mesage}" end end @organizations.each do |k, o| = o.validate() if !.empty? errors = "#{errors}\n#{}" end end converter_deal_statuses = @settings.deal.statuses.map {|status| status.label} if @settings.deal != nil @deals.each do |key, deal| error, warning = deal.validate converter_deal_statuses if !error.empty? errors = "#{errors}\n#{error}" end if !warning.empty? warnings = "#{warnings}\n#{warning}" end end @histories.each do |key, history| = history.validate if !.empty? errors = "#{errors}\n#{}" end end @todos.each do |key, todo| = todo.validate if !.empty? errors = "#{errors}\n#{}" end end @meetings.each do |key, meeting| = meeting.validate if !.empty? errors = "#{errors}\n#{}" end end @documents.links.each do |link| = link.validate if !.empty? errors = "#{errors}\n#{}" end end @documents.files.each do |file| = file.validate(ignore_invalid_files, max_file_size) if !.empty? errors = "#{errors}\n#{}" end end return [errors.strip, warnings.strip] end |