Class: GoImport::Organization

Inherits:
CanBecomeImmutable show all
Includes:
ModelHasCustomFields, ModelHasTags, SerializeHelper
Defined in:
lib/go_import/model/organization.rb

Instance Attribute Summary collapse

Attributes included from ModelHasTags

#tags

Instance Method Summary collapse

Methods included from SerializeHelper

#get_import_rows, #serialize, #serialize_to_file

Methods included from ModelHasCustomFields

#set_custom_value

Methods included from ModelHasTags

#set_tag

Methods inherited from CanBecomeImmutable

immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable

Constructor Details

#initialize(opt = nil) ⇒ Organization

Returns a new instance of Organization.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/go_import/model/organization.rb', line 63

def initialize(opt = nil)
    if !opt.nil?
        serialize_variables.each do |myattr|
            val = opt[myattr[:id]]
            instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
        end
    end

    @relation = Relation::NoRelation if @relation.nil?
    set_tag 'Import'
end

Instance Attribute Details

#custom_valuesObject (readonly)

you add custom values by using ModelHasCustomFields#set_custom_value



61
62
63
# File 'lib/go_import/model/organization.rb', line 61

def custom_values
  @custom_values
end

#employeesObject (readonly)

Returns the value of attribute employees.



59
60
61
# File 'lib/go_import/model/organization.rb', line 59

def employees
  @employees
end

#relationObject

Returns the value of attribute relation.



59
60
61
# File 'lib/go_import/model/organization.rb', line 59

def relation
  @relation
end

#relation_last_modifiedObject

Sets/gets the date when this organization’s relation was changed. Default is Now.



57
58
59
# File 'lib/go_import/model/organization.rb', line 57

def relation_last_modified
  @relation_last_modified
end

#responsible_coworkerObject

Returns the value of attribute responsible_coworker.



59
60
61
# File 'lib/go_import/model/organization.rb', line 59

def responsible_coworker
  @responsible_coworker
end

Instance Method Details

#==(that) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/go_import/model/organization.rb', line 83

def ==(that)
    if that.nil?
        return false
    end

    if that.is_a? Organization
        return @integration_id == that.integration_id
    end

    return false
end

#add_employee(val) ⇒ Object

Examples:

Add an employee and then add additional info to that employee

employee = o.add_employee({
    :integration_id => "79654",
    :first_name => "Peter",
    :last_name => "Wilhelmsson"
})
employee.direct_phone_number = '+234234234'
employee.currently_employed = true

See Also:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/go_import/model/organization.rb', line 134

def add_employee(val)
    @employees = [] if @employees == nil
    person = if val.is_a? Person then val else Person.new(val) end
    @employees.push(person)

    # *** TODO:
    #
    # The person should be immutable after it has been added
    # to the organization. However most sources (LIME Easy,
    # LIME Pro, Excel, SalesForce, etc) are updating the
    # person after is has been added to the organization. We
    # must update the sources before we can set the person
    # immutable here.
    
    #person.set_is_immutable
    
    return person
end

#find_employee_by_integration_id(integration_id) ⇒ Object



188
189
190
191
192
193
# File 'lib/go_import/model/organization.rb', line 188

def find_employee_by_integration_id(integration_id)
    return nil if @employees.nil?
    return @employees.find do |e|
        e.integration_id == integration_id
    end
end

#serialize_nameObject



216
217
218
# File 'lib/go_import/model/organization.rb', line 216

def serialize_name
    "Organization"
end

#serialize_variablesObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/go_import/model/organization.rb', line 195

def serialize_variables
    [
     { :id => :id, :type => :string },
     { :id => :integration_id, :type => :string },
     { :id => :source, :type => :source_ref },
     { :id => :name, :type => :string },
     { :id => :organization_number, :type => :string },
     { :id => :postal_address, :type => :address },
     { :id => :visit_address, :type => :address },
     { :id => :central_phone_number, :type => :string },
     { :id => :email, :type => :string },
     { :id => :web_site, :type => :string },
     { :id => :employees, :type => :persons },
     { :id => :custom_values, :type => :custom_values },
     { :id => :tags, :type => :tags },
     { :id => :responsible_coworker_reference, :type => :coworker_reference, :element_name => :responsible_coworker},
     { :id => :relation, :type => :string },
     { :id => :relation_last_modified, :type => :string }
    ]
end

#to_referenceObject



75
76
77
78
79
80
81
# File 'lib/go_import/model/organization.rb', line 75

def to_reference()
    reference = OrganizationReference.new
    reference.id = @id
    reference.integration_id = @integration_id
    reference.heading = @name
    return reference
end

#to_sObject



220
221
222
# File 'lib/go_import/model/organization.rb', line 220

def to_s
    return "#{name}"
end

#validateObject



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/go_import/model/organization.rb', line 224

def validate
    error = String.new

    if @name.nil? || @name.empty?
        error = "A name is required for organization.\n#{serialize()}"
    end

    if !@source.nil?
        if @source.id.nil? || @source.id == ""
            error = "#{error}\nReference to source must have an id"
        end
    end

    if @employees != nil
        @employees.each do |person|
            validation_message = person.validate()
            if !validation_message.empty?
                error = "#{error}\n#{validation_message}"
            end
        end
    end

    return error
end

#with_postal_address {|@postal_address| ... } ⇒ Object

Examples:

Set city of postal address to ‘Lund’

o.with_postal_address do |addr|
    addr.city = "Lund"
end

Yields:

  • (@postal_address)

See Also:



100
101
102
103
# File 'lib/go_import/model/organization.rb', line 100

def with_postal_address
    @postal_address = Address.new if @postal_address == nil
    yield @postal_address
end

#with_source {|@source| ... } ⇒ Object

Examples:

Set the source to par id 4653

o.with_source do |source|
     source.par_se('4653')
end

Yields:

  • (@source)

See Also:



120
121
122
123
# File 'lib/go_import/model/organization.rb', line 120

def with_source
    @source = ReferenceToSource.new if @source == nil
    yield @source
end

#with_visit_address {|@visit_address| ... } ⇒ Object

Examples:

Set city of visit address to ‘Lund’

o.with_visit_address do |addr|
    addr.city = "Lund"
end

Yields:

  • (@visit_address)

See Also:



110
111
112
113
# File 'lib/go_import/model/organization.rb', line 110

def with_visit_address
    @visit_address = Address.new if @visit_address == nil
    yield @visit_address
end