def query (criteria)
cr = criteria.inject({}) { |h, (k, v)| h[k.to_s] = v; h }
return @context.storage.query_workitems(cr).collect { |h|
Ruote::Workitem.new(h)
} if @context.storage.respond_to?(:query_workitems)
offset = cr.delete('offset')
limit = cr.delete('limit')
wfid = cr.delete('wfid')
pname = cr.delete('participant_name') || cr.delete('participant')
hwis = if wfid
@context.storage.get_many('workitems', /!#{wfid}$/)
else
fetch_all
end
hwis = hwis.select { |hwi|
Ruote::StorageParticipant.matches?(hwi, pname, cr)
}.collect { |hwi|
Ruote::Workitem.new(hwi)
}
offset = offset || 0
limit = limit || hwis.length
hwis[offset, limit]
end