Class: CPEE::Worklist::ActivityHappens
- Inherits:
-
Riddl::Implementation
- Object
- Riddl::Implementation
- CPEE::Worklist::ActivityHappens
- Defined in:
- lib/cpee-worklist/implementation.rb
Overview
}}}
Instance Method Summary collapse
-
#response ⇒ Object
{{{.
Instance Method Details
#response ⇒ Object
{{{
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 136 137 138 139 140 141 |
# File 'lib/cpee-worklist/implementation.rb', line 61 def response controller = @a[0] activity = {} activity['process'] = @h.keys.include?('CPEE_ATTR_INFO') ? "#{@h['CPEE_ATTR_INFO']} (#{@h['CPEE_INSTANCE'].split('/').last})" : "DUMMY PROCESS (#{@h['CPEE_INSTANCE'].split('/').last})" activity['label'] = @h.keys.include?('CPEE_INSTANCE') ? "#{@h['CPEE_LABEL']}" : 'DUMMY LABEL' activity['user'] = [] activity['url'] = @h['CPEE_CALLBACK'] activity['id'] = @h['CPEE_CALLBACK_ID'] activity['cpee_activity_id'] = @h['CPEE_ACTIVITY'] activity['cpee_base'] = @h['CPEE_BASE'] activity['cpee_instance'] = @h['CPEE_INSTANCE'] activity['uuid'] = @h['CPEE_ATTR_UUID'] omo = @p.shift.value activity['orgmodel'] = @h[ 'CPEE_ATTR_' + omo.upcase] || omo activity['form'] = @p.shift.value activity['unit'] = @p.first.name == 'unit' ? @p.shift.value : '*' activity['role'] = @p.first.name == 'role' ? @p.shift.value : '*' activity['priority'] = @p.first.name == 'priority' ? @p.shift.value.to_i : 1 activity['collect'] = @p.first.name == 'collect' ? @p.shift.value.to_i : nil activity['deadline'] = @p.first.name == 'deadline' ? ((Time.now + ChronicDuration.parse(@p.shift.value)) rescue nil): nil activity['restrictions'] = [] rests = JSON::parse(@p.shift.value) rescue nil activity['restrictions'] << rests unless rests.nil? activity['parameters'] = JSON::parse(@p.shift.value) rescue {} status, content, headers = Riddl::Client.new(activity['orgmodel']).get if status == 200 begin xml = content[0].value.read schema = XML::Smart.open(@a[0].opts[:ORG_SCHEMA]) org_xml = XML::Smart.string(xml) raise 'a fucked up xml (wink wink)' unless org_xml.validate_against(schema) org_xml.register_namespace 'o', 'http://cpee.org/ns/organisation/1.0' rescue => e puts e. puts e.backtrace @a[0].notify('task/invalid', :callback_id => activity['id'], :reason => 'orgmodel invalid', :instance_uuid => activity['uuid'], :cpee_callback => activity['url'], :cpee_instance => activity['cpee_instance'], :cpee_base => activity['cpee_base'], :cpee_label => activity['label'], :cpee_activity => activity['cpee_activity_id'], :orgmodel => activity['orgmodel'] ) @status = 404 return end attributes = "" if activity['role'] != '*' attributes += "@role='#{activity['role']}'" attributes += " and " if activity['unit'] != '*' end attributes += "@unit='#{activity['unit']}'" if activity['unit'] != '*' user = org_xml.find("/o:organisation/o:subjects/o:subject[o:relation[#{attributes}]]").map{ |e| e.attributes['uid'] } if activity['collect'] activity['collect_max'] = user.length activity['collected'] = 0 end if user.empty? @a[0].notify('task/invalid', :callback_id => activity['id'], :reason => 'no users found for this combination of unit/role',:instance_uuid => activity['uuid'], :cpee_callback => activity['url'], :cpee_instance => activity['cpee_instance'], :cpee_base => activity['cpee_base'], :cpee_label => activity['label'], :cpee_activity => activity['cpee_activity_id'], :orgmodel => activity['orgmodel'] ) @status = 404 return end @a[0].add_activity activity @a[0].add_orgmodel Riddl::Protocols::Utils::escape(activity['orgmodel']), xml Thread.new do # TODO immediate vote for adding by external subscribers # results = @a[0].vote('task/add', :user => user , :instance_uuid => activity['uuid'], :cpee_callback => activity['url'], :cpee_instance => activity['cpee_instance'], :cpee_base => activity['cpee_base'], :cpee_label => activity['label'], :cpee_activity => activity['cpee_activity_id'], :orgmodel => activity['orgmodel'] ) # if (results.length == 1) && (user.include? results[0]) # activity['user'] = results[0] # info = CPEE::Worklist::User::info(@a[0].opts,activity,activity['user']) # @a[0].notify('task/add', :user => user,:callback_id => activity['id'], :instance_uuid => activity['uuid'], :cpee_callback => activity['url'], :cpee_instance => activity['cpee_instance'], :cpee_base => activity['cpee_base'], :cpee_label => activity['label'], :cpee_activity => activity['cpee_activity_id'], :orgmodel => activity['orgmodel'], :wl_instance => activity['wl_instance'] ) # @a[0].notify('user/take', :user => results[0], :callback_id => activity['id'], :instance_uuid => activity['uuid'], :cpee_callback => activity['url'], :cpee_instance => activity['cpee_instance'], :cpee_base => activity['cpee_base'], :cpee_label => activity['label'], :cpee_activity => activity['cpee_activity_id'], :orgmodel => activity['orgmodel'], :organisation => info, :wl_instance => activity['wl_instance']) # else @a[0].notify('task/add', :user => user,:callback_id => activity['id'], :instance_uuid => activity['uuid'], :cpee_callback => activity['url'], :cpee_instance => activity['cpee_instance'], :cpee_base => activity['cpee_base'], :cpee_label => activity['label'], :cpee_activity => activity['cpee_activity_id'], :orgmodel => activity['orgmodel']) # end end @headers << Riddl::Header.new('CPEE_CALLBACK','true') else @status = 404 end end |