Class: CPEE::Worklist::ShowUserTasks

Inherits:
Riddl:: Implementation
  • Object
show all
Defined in:
lib/cpee-worklist/implementation.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/cpee-worklist/implementation.rb', line 246

def response
  out = XML::Smart.string('<tasks/>')
  tasks = {}
  @a[0].orgmodels.each do |e|
    XML::Smart.open(File.join(@a[0].opts[:top],'orgmodels',e)) do |doc|
      doc.register_namespace 'o', 'http://cpee.org/ns/organisation/1.0'
      doc.find("/o:organisation/o:subjects/o:subject[@uid='#{@r[-2]}']/o:relation").each do |rel|
        @a[0].activities.each do |activity|
          restrict = false
          activity['restrictions'].each do |restriction|
            restriction = restriction[0] if  restriction.is_a? Array
            restrict = true if restriction['mode'] == 'prohibit' && restriction['id'] == @r[-2]
          end
          if (
               activity['role']=='*' ||
               activity['role'].casecmp(rel.attributes['role']) == 0
             ) && (
               activity['unit'] == '*' ||
               activity['unit'].casecmp(rel.attributes['unit']) == 0
             ) && (
               activity['handling'] == 'collect' ||
               activity['handling'] == 'always' ||
               activity['user'].empty? ||
               activity['user'].include?(@r[-2])
             )
             !restrict
            tasks["#{activity['id']}"] = { :always => activity['handling'] == 'always', :all => activity.has_key?('collect') && !activity['collect'].nil?, :uid => @r[-2], :priority => activity['priority'], :label => activity['process'] + ': ' + activity['label'] }
            tasks["#{activity['id']}"][:own] = activity['user'].include?(@r[-2])
            tasks["#{activity['id']}"][:deadline] = activity['deadline'] if activity['deadline']
            tasks["#{activity['id']}"][:prioritization] = activity['prioritization']&.join(', ') || ''
            tasks["#{activity['id']}"][:label_extension] = activity['label_extension'] if activity['label_extension']
            tasks["#{activity['id']}"][:label_extension_details] = activity['label_extension_details'] if activity['label_extension_details']
          end
        end
      end
    end
  end
  tasks.sort_by{ |k,e| e[:priority] }.each{|k,v| out.root.add("task", v.merge(:id => k))}
  x = Riddl::Parameter::Complex.new("return","text/xml") do
    out.to_s
  end
  x
end