Class ArsModels::Form
In: lib/ars_models/form.rb
Parent: BaseWithContext

Ruby wrapper class for the java com.kd.ars.models.structure.ArsForm object Instances of Form represent a single AR server schema / form.

Methods

Constants

DEFAULT_FIELDS = { 1 => {:datatype => "CHAR", :entrymode => "SYSTEM", :id => 1, :label => 'Request ID', :name => 'Request ID'}, 2 => {:datatype => "CHAR", :entrymode => "REQUIRED", :id => 2, :label => 'Submitter', :name => 'Submitter'}, 3 => {:datatype => "CHAR", :entrymode => "SYSTEM", :id => 3, :label => 'Create Date', :name => 'Create Date'}, 4 => {:datatype => "CHAR", :entrymode => "OPTIONAL", :id => 4, :label => 'Assigned To', :name => 'Assigned To'}, 5 => {:datatype => "CHAR", :entrymode => "SYSTEM", :id => 5, :label => 'Last Modified By', :name => 'Last Modified By'}, 6 => {:datatype => "CHAR", :entrymode => "SYSTEM", :id => 6, :label => 'Modified Date', :name => 'Modified Date'}, 7 => { :datatype => "CHAR", :entrymode => "REQUIRED", :id => 7, :label => 'Status', :name => 'Status', :options => [ {:id => 0, :name => 'New', :label => 'New'}, {:id => 1, :name => 'Assigned', :label => 'Assigned'}, {:id => 2, :name => 'Fixed', :label => 'Fixed'}, {:id => 3, :name => 'Rejected', :label => 'Rejected'}, {:id => 4, :name => 'Closed', :label => 'Closed'}
DEFAULT_FIELD_NAMES = { 'Request ID' => 1, 'Submitter' => 2, 'Create Date' => 3, 'Assigned To' => 4, 'Last Modified By' => 5, 'Modified Date' => 6, 'Status' => 7, 'Short Description' => 8

Attributes

ars_form  [R]  Internal JAPI representation of the com.kd.ars.models.structure.ArsForm object
fields  [RW]  Array of ArsModels::Field objects that represent the fields of the form.
indexes  [RW]  Array of indexes, which are represented as arrays of ArsModels::Field objects included in the composite index.
name  [RW]  The name of the Form
permissions  [RW]  Hash of AR server group names to the permission type ("HIDDEN" or "VISIBLE") granted to that group.
sort_fields  [RW]  Array of fields that comprise the default sorting of the form

Public Class methods

TODO: Document ArsModels::Form.create

[Source]

    # File lib/ars_models/form.rb, line 30
30:     def self.create(options={})
31:       # Default the context if there is a class instance context set via context_instance

32:       options[:context] ||= context if context
33:       # Validate the options

34:       validate_options(
35:         options,
36:         :required => [:name, :context],
37:         :optional => [:fields, :indexes, :permissions, :sort_fields]
38:       )
39:       # Save the record

40:       save(options)
41:     end

TODO: Document ArsModels::Form.delete!

[Source]

    # File lib/ars_models/form.rb, line 44
44:     def self.delete(*args)
45:       # Pop the last argument if it is an options hash

46:       options = args.last.is_a?(::Hash) ? args.pop : {}
47:       options[:context] ||= context if context
48: 
49:       # Validate Options

50:       validate_options(options, :required => [:context])
51: 
52:       case args[0]
53:         when nil then return
54:         when :all then
55:           # TODO: Feature Completion - Implement delete all

56:           raise 'Not Implemented'
57:         else
58:           forms = args.flatten
59: 
60:           if forms.length == 1
61:             form_name = forms[0].is_a?(::String) ? forms[0] : forms[0].name
62:             begin
63:               new(ArsForm.delete(options[:context].ars_context, form_name, true))
64:             rescue StandardError => error
65:               raise Exceptions::InternalError.process(error)
66:             end
67:           else
68:             results, successes, failures = [], {}, {}
69:             forms.each do |form|
70:               form_name = form.is_a?(::String) ? form : form.name
71:               begin
72:                 form = new(ArsForm.delete(options[:context].ars_context, form_name, true), :context => options[:context])
73:                 successes[results.length] = form
74:                 results << form
75:               rescue StandardError => error
76:                 exception = Exceptions::InternalError.process(error)
77:                 failures[results.length] = exception
78:                 results << exception
79:               end
80:             end
81:             results_metaclass = class << results; self; end
82:             results_metaclass.instance_eval do
83:               define_method(:successes) {successes}
84:               define_method(:failures) {failures}
85:             end
86:             results
87:           end
88:       end
89:     end

TODO: Document ArsModels::Form.find

[Source]

     # File lib/ars_models/form.rb, line 92
 92:     def self.find(*args)
 93:       # Pop the last argument if it is an options hash

 94:       options = args.last.is_a?(::Hash) ? args.pop : {}
 95:       options[:context] ||= context if context
 96: 
 97:       # Validate that the options are valid

 98:       validate_options(options, :required => [:context], :optional=> [:name, :fields])
 99: 
100:       options[:fields] = options[:fields].to_java(:long) if options[:fields]
101: 
102:       case args.first
103:         when :all then
104:           name = options[:name] || args[1]
105:           begin
106:             ArsForm.find_all(options[:context].ars_context, name, options[:fields]).collect do |form|
107:               new(form, :context => options[:context])
108:             end
109:           rescue StandardError => error
110:             raise Exceptions::InternalError.process(error)
111:           end
112:         else
113:           args = args[0] if args.length == 1 && args[0].is_a?(::Array)
114:           results = args.collect do |arg|
115:             name = arg.is_a?(::String) ? arg : arg.name
116:             begin
117:               form = ArsForm.find(options[:context].ars_context, name, options[:fields])
118:               form ? new(form, :context => options[:context]) : nil
119:             rescue StandardError => error
120:               raise Exceptions::InternalError.process(error)
121:             end
122:           end
123:           case results.length
124:             when 0 then nil
125:             when 1 then results.first
126:             else results
127:           end
128:       end
129:     end

TODO: Document ArsModels::Form.initialize

[Source]

    # File lib/ars_models/form.rb, line 24
24:     def initialize(*args)
25:       # Call the ArsModels::Base initializer and delegate to the build or generate method

26:       super(*args)
27:     end

TODO: Document ArsModels::Form.save

[Source]

     # File lib/ars_models/form.rb, line 200
200:     def self.save(options={})
201:       options[:context] ||= context if context
202:       
203:       # Validate the options

204:       validate_options(
205:         options,
206:         :required => [:name, :context],
207:         :optional => [:fields, :indexes, :permissions, :sort_fields]
208:       )
209: 
210:       # Remove the context from the options hash

211:       context = options.delete(:context)
212: 
213:       # Attempt to save the form

214:       begin
215:         form = new(options)
216:         result = new(form.ars_form.save(context.ars_context), :context => options[:context])
217:       rescue StandardError => exception
218:         raise Exceptions::InternalError.process(exception)
219:       end
220: 
221:       # Return the result of the save

222:       return result
223:     end

TODO: Document ArsModels::Form.update

[Source]

     # File lib/ars_models/form.rb, line 132
132:     def self.update(options={})
133:       raise 'Not Implemented'
134:     end

Public Instance methods

'[]'(field_identifier)

Alias for field_for

TODO: Document ArsModels::Form#create

[Source]

     # File lib/ars_models/form.rb, line 137
137:     def create
138:       raise 'Not Implemented'
139:     end

TODO: Document ArsModels::Form#create_entry

[Source]

     # File lib/ars_models/form.rb, line 161
161:     def create_entry!(*args)
162:       delegate_to_entry('create!', args)
163:     end

TODO: Document ArsModels::Form#delete

[Source]

     # File lib/ars_models/form.rb, line 142
142:     def delete(options={})
143:       # Default the context to the context used to find this form

144:       options[:context] ||= self.context if self.context
145:       # Validate the options

146:       validate_options(options, :required => [:context])
147:       # Delete the form

148:       self.class.delete(self, options)
149:     end

TODO: Document ArsModels::Form#delete_entries

[Source]

     # File lib/ars_models/form.rb, line 166
166:     def delete_entries!(*args)
167:       delegate_to_entry('delete!', args)
168:     end

TODO: Document ArsModels::Form#delete_entry!

[Source]

     # File lib/ars_models/form.rb, line 171
171:     def delete_entry!(id, options={})
172:       delegate_to_entry('delete!', [id, options])
173:     end

TODO: Document ArsModels::Form#field_for

[Source]

     # File lib/ars_models/form.rb, line 231
231:     def field_for(field_identifier)
232:       ars_field = case field_identifier
233:         when Field then @ars_form.get_field_by_id(field_identifier.id)
234:         when ::Fixnum then @ars_form.get_field_by_id(field_identifier)
235:         when ::NilClass then nil
236:         when ::String then @ars_form.get_field_by_name(field_identifier)
237:         when ::Symbol then @ars_form.get_field_by_label(field_identifier.to_s)
238:         else raise 'Unknown field identifier type.'
239:       end
240:       Field.new(ars_field) if ars_field
241:     end

TODO: Document ArsModels::Form#field_id_for

[Source]

     # File lib/ars_models/form.rb, line 245
245:     def field_id_for(field_identifier)
246:       # TODO: Abstraction - Clean this up

247:       field = field_for(field_identifier)
248:       field.id if field
249:     end

[Source]

     # File lib/ars_models/form.rb, line 251
251:     def field_ids
252:       fields.collect{|field| field.id}
253:     end

TODO: Document ArsModels::Form#find_entries

[Source]

     # File lib/ars_models/form.rb, line 176
176:     def find_entries(*args)
177:       delegate_to_entry('find', args)
178:     end

TODO: Document ArsModels::Form#find_entry

[Source]

     # File lib/ars_models/form.rb, line 181
181:     def find_entry(id, options={})
182:       delegate_to_entry('find', [id, options])
183:     end

TODO: Document ArsModels::Form#save

[Source]

     # File lib/ars_models/form.rb, line 226
226:     def save
227:       raise 'Not Implemented'
228:     end

TODO: Document ArsModels::Form#to_xml

[Source]

     # File lib/ars_models/form.rb, line 303
303:     def to_xml
304:       @ars_form.to_xml_string
305:     end

TODO: Document ArsModels::Form#update

[Source]

     # File lib/ars_models/form.rb, line 152
152:     def update
153:       raise 'Not Implemented'
154:     end

TODO: Document ArsModels::Form#update_entries!

[Source]

     # File lib/ars_models/form.rb, line 186
186:     def update_entries!(*args)
187:       delegate_to_entry('update!', args)
188:     end

TODO: Document ArsModels::Form#update_entry!

[Source]

     # File lib/ars_models/form.rb, line 191
191:     def update_entry!(id, options={})
192:       delegate_to_entry('update!', [id, options])
193:     end

[Validate]