[ruote:2272] ruote participant

11 views
Skip to first unread message

eric woo

unread,
May 13, 2010, 10:51:35 PM5/13/10
to ruote
ruote is a greate workflow engine,but i found the participant is not
Meet my needs.

i want to get the participant from the database table,not from the
programm.

and i want to says if the participant just like workflow role?

--
you received this message because you are subscribed to the "ruote users" group.
to post : send email to openwfe...@googlegroups.com
to unsubscribe : send email to openwferu-use...@googlegroups.com
more options : http://groups.google.com/group/openwferu-users?hl=en

John Mettraux

unread,
May 13, 2010, 11:11:06 PM5/13/10
to openwfe...@googlegroups.com

On Thu, May 13, 2010 at 07:51:35PM -0700, eric woo wrote:
>
> ruote is a great workflow engine, but i found the participant is not
> Meet my needs.
>
> i want to get the participant from the database table,not from the
> programm.

Hello Eric,

if you want to store workitems in a database, you should use "ruote-dm"

http://github.com/jmettraux/ruote-dm

Here is some code : (also at http://gist.github.com/400761)

---8<---
require 'rubygems'
require 'json' # gem install json
require 'ruote'
require 'ruote-dm' # gem install ruote-dm

#DataMapper.setup(:default, 'sqlite3::memory:')
#DataMapper.setup(:default, 'sqlite3:ruote_test.db')
DataMapper.setup(:default, 'postgres://localhost/ruote_test')

#Ruote::Dm::Document.all.destroy!
# cleans up the ruote database before running

engine = Ruote::Engine.new(
Ruote::Worker.new(
Ruote::Dm::DmStorage.new(:default)))

sp = engine.register_participant '.+', Ruote::StorageParticipant

pdef = Ruote::process_definition do
sequence do
eric
john
end
end

# launch a process instance

#engine.context.logger.noisy = true
engine.launch(pdef)

sleep 1

# display workitems

puts '-' * 80
sp.all.each do |wi|
p [ wi.participant_name, wi.fields ]
end

# manipulate one workitem

wi = sp.first
wi.fields['hello'] = 'world'

sp.reply(wi)

sleep 1

# display workitems

puts '-' * 80
sp.all.each do |wi|
p [ wi.participant_name, wi.fields ]
end

# ...
--->8---


> and i want to says if the participant just like workflow role?

Sorry I don't understand this question.

Maybe this chat extract could help :

---8<---
11:40 hansen_: how to build the relation between people and participant?
11:40 jmettraux: use a storage participant
11:41 jmettraux: then in your rails application use some logic to decide which user has the right to view which workitem
11:43 jmettraux: RuoteKit.storage_participant.by_participant('review')
11:43 jmettraux: will return all the workitems where participant name is "review"
11:43 jmettraux: these are just examples
11:46 jmettraux: another technique is to have participant names mapped to groups of people
11:46 jmettraux: and then have a workitem field named 'user'
11:46 jmettraux: when this field is empty it means that the workitem is not assigned to a user...
11:46 jmettraux: there are many techniques, your imagination is the limit
--->8---


Welcome in this mailing list and best regards,

--
John Mettraux - http://jmettraux.wordpress.com

Cappelaere Patrice

unread,
May 14, 2010, 1:26:53 PM5/14/10
to openwfe...@googlegroups.com
John,

I just noticed a few problems with latest ruote-fluo.

1.  as_xml link dies brutally with:

LoadError at /def

no such file to load -- builder

[but of course, will work fine within rails]

2.  I think that other worse problem is in FluoEditor.asJson routine.
If you look carefully at the code generated for ruby and json, the output does not seem correct when the parser encounters the "if ${f:success}" expression.

Here is the json outpout: 
["if",{"${f":"success}"}

and here is the ruby output:
if :${f => "success}"

I think that problem is likely to be in ruote-fluo-editor.js, asJson function...unless my system is screwed up...

Just want to make sure you confirm problem before I go to deep in there :)
I can try to look at it later unless, of course, you beat me to it.

Cheers,
Pat.


John Mettraux

unread,
May 14, 2010, 10:14:57 PM5/14/10
to openwfe...@googlegroups.com

On Fri, May 14, 2010 at 01:26:53PM -0400, Cappelaere Patrice wrote:
>
> I just noticed a few problems with latest ruote-fluo.
>
> 1. as_xml link dies brutally with:
> LoadError at /def
>
> no such file to load -- builder
>
> [but of course, will work fine within rails]

Hello,

ah, many thanks !

http://github.com/jmettraux/ruote-fluo/commit/cc434e4955b6ce1465539394b6ab3147ce556de5

> 2. I think that other worse problem is in FluoEditor.asJson routine.
> If you look carefully at the code generated for ruby and json, the output does not seem correct when the parser encounters the "if ${f:success}" expression.
>
> Here is the json outpout:
> ["if",{"${f":"success}"}
>
> and here is the ruby output:
> if :${f => "success}"
>
> I think that problem is likely to be in ruote-fluo-editor.js, asJson function...unless my system is screwed up...
>
> Just want to make sure you confirm problem before I go to deep in there :)
> I can try to look at it later unless, of course, you beat me to it.

I'm on it.


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
May 14, 2010, 10:32:06 PM5/14/10
to openwfe...@googlegroups.com

On Fri, May 14, 2010 at 01:26:53PM -0400, Cappelaere Patrice wrote:
> John,
>
> I just noticed a few problems with latest ruote-fluo.
>
> 1. as_xml link dies brutally with:
> LoadError at /def

Please do not hi-jack threads :

http://groups.google.com/group/openwferu-users/browse_thread/thread/7910ad398424403a


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
May 15, 2010, 9:14:32 AM5/15/10
to openwfe...@googlegroups.com


On Sat, May 15, 2010 at 11:14 AM, John Mettraux <jmet...@openwfe.org> wrote:
>
> On Fri, May 14, 2010 at 01:26:53PM -0400, Cappelaere Patrice wrote:
>
>> 2.  I think that other worse problem is in FluoEditor.asJson routine.
>> If you look carefully at the code generated for ruby and json, the output does not seem correct when the parser encounters the "if ${f:success}" expression.
>>
>> Here is the json outpout:
>>       ["if",{"${f":"success}"}
>>
>> and here is the ruby output:
>>       if :${f => "success}"
>>
>> I think that problem is likely to be in ruote-fluo-editor.js, asJson function...unless my system is screwed up...
>>
>> Just want to make sure you confirm problem before I go to deep in there :)
>> I can try to look at it later unless, of course, you beat me to it.
>
> I'm on it.

Hello again,

http://github.com/jmettraux/ruote-fluo/commit/0b312301e1e7748db5b4a287d5cc9e5cb2652b6a

and a side-commit for ruote itself :

http://github.com/jmettraux/ruote/commit/ef23a6d656bf270b140ee9333728b59283cae603


Many thanks !

eric

unread,
May 17, 2010, 4:01:46 AM5/17/10
to openwfe...@googlegroups.com
i just create a subclass of Ruote::StorageParticipant.
just like:

module TestWoo
  class WooTestParticipant < Ruote::StorageParticipant
#    include Ruote::LocalParticipant

    def consume (workitem)
     puts "1----------------------__>"
     wfid = workitem.h.fei
     puts "2----------------------__>"
     participant = workitem.participant_name
     puts "3----------------------__>"
#     puts  "4===>wfid = " + wfid
#     puts  "5===>participant = " + participant
    map_participant_user(wfid,participant)
    puts "4----------------------__>"
    reply_to_engine( workitem )
    end

    def map_participant_user(wfid,participant)
       ActiveRecord::Base.connection.insert("insert into wfwiparticitant(workitem_id,participant,parrticipant2,workitem_state,extend1)" +
                                            "select #{wfid},#{participant},csru.user_id,1,'' from" +
                                             "cloudsoft_security_role csr,cloudsoft_security_roleuser csru" +
                                              "where  csr.role_id = csru.role_id ");
    end
  end
end

i want to get the wfid and participant.but it doesn't work? 
john,can you help me.thank you very much
best regards.
Message has been deleted

John Mettraux

unread,
May 17, 2010, 5:54:28 AM5/17/10
to openwfe...@googlegroups.com
Hello,

what about something like :

---8<---
module TestWoo
class TestParticipant < Ruote::StorageParticipant
def consume (workitem)
workitem.fields['user'] = Crsu.find_by_role(workitem.participant_name)
super(workitem)
end
end
end
--->8---

So that the field 'user' is set before the workitem gets saved.

Remember that the StorageParticipant, like its name implies, stores the workitem in the storage.


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
May 17, 2010, 9:23:41 AM5/17/10
to openwfe...@googlegroups.com
Eric,

what about a classical approach where the processes look like

---8<---
Ruote.process_definition do
sequence do
role1
role2
role3
end
end
--->8---

and your Rails views look like

---8<---
class WorkController
def index
@roles = Roles.find_by_user(current_user)
@workitems = @roles.inject([]) do |a, role|
RuoteKit.storage_participant.by_participant(role)
end
end
end
--->8---

?

There are multiple advantages to this approach, for example, you can change the roles independently from the process definitions and of the already existing (waiting) workitems...

If you want me to help you, please try to explain what you are trying to do, else I'm just emitting useless pieces of advice.

John Mettraux

unread,
May 17, 2010, 9:31:55 AM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 10:23 PM, John Mettraux <jmet...@openwfe.org> wrote:
>
> and your Rails views look like
>
> ---8<---
>  class WorkController
>    def index
>      @roles = Roles.find_by_user(current_user)
>      @workitems = @roles.inject([]) do |a, role|
>        RuoteKit.storage_participant.by_participant(role)
>      end
>    end
>  end
> --->8---

Sorry,

---8<---
 class WorkController
   def index
     @roles = Roles.find_by_user(current_user)
     @workitems = @roles.inject([]) do |a, role|
       a += RuoteKit.storage_participant.by_participant(role)
     end
   end
 end
--->8---

is better.

Cappelaere Patrice

unread,
May 17, 2010, 10:04:47 AM5/17/10
to openwfe...@googlegroups.com
John,

Just curious but what was the reasoning behind writing your own ruby_dsl parser? and not use ParseTree and its s-expressions?

The reason I ask (if you really want to know)...I am trying to extend a participant to be a DSL for spectral image processing. So I really want to define an algorithm (aka a process) in a similar manner... and then use that within a workflow...

I was trying to visualize with ruote-fluo to quickly show the equivalence of representation... this would make it very seamless.

This would also allow full arithmetic operations...

b1 = band(23)
b2 = band(24)
c = b1 + b2
d = b1 > 0...

Thanks,
Pat.

eric

unread,
May 17, 2010, 11:10:43 AM5/17/10
to openwfe...@googlegroups.com
hi,john:
first,thank you very much!
 
i just want to create a todolist for a user.if workflow launch a process definition,engine will send workitem to participant.
so if i map the participant to the user.the user will have a todo task about workitem.
 
today,as your says,i implements the Ruote::StorageParticipant,after consume the participant,i will create a relationship bewteen
the user and the participant,at the same time,i will create a todo task for a user.
 
and then in the rails application,user will get todo task.
 
---8<---
module TestWoo
  class WooTestParticipant < Ruote::StorageParticipant
    def consume( workitem )
     super(workitem)
     puts "1----------------------__>" +workitem.nil?.to_s
     message = Rufus::Json.encode(workitem)
     wfid = workitem.h.fei['wfid']
     puts "2----------------------__>" + message.to_s
     participant = workitem.participant_name
     fields = workitem.to_h['fields']
     puts "3----------------------__>" + fields.to_s
     wfid_s = wfid.to_s
     participant_s = participant.to_s
     puts  "4===>wfid = " + wfid_s
     puts  "5===>participant = " + participant_s
     map_participant_user(wfid_s,participant_s)
     puts "6----------------------__>"
    end
    #just want to map the participant to user.
    #and the user will get from cloudsoft_security_roleuser.
    def map_participant_user(wfid_s,participant_s)
       ActiveRecord::Base.connection.insert("insert into wfwiparticipant(workitem_id,participant,participant2,workitem_state,extend1)" +
                                            "select '#{wfid_s}','#{participant_s}',csru.user_id,1,'' from" +
                                            " cloudsoft_security_role csr,cloudsoft_security_roleuser csru" +
                                            " where csr.role_id = csru.role_id " +
                                            " and csr.role_id = '#{participant_s}'");
    end
  end
end
--->8---
 
do you have any suggestion about this.
kind regards
 
eric

John Mettraux

unread,
May 17, 2010, 7:26:42 PM5/17/10
to openwfe...@googlegroups.com

On Mon, May 17, 2010 at 11:10:43PM +0800, eric wrote:
>
> i just want to create a todolist for a user.if workflow launch a process
> definition,engine will send workitem to participant.
> so if i map the participant to the user.the user will have a todo task about
> workitem.

Hello Eric,

why not simply think of the workitem as a task ?

It is much simpler.

> today,as your says,i implements the Ruote::StorageParticipant,after consume
> the participant,i will create a relationship bewteen
> the user and the participant,

What kind of relationship ?

> at the same time,i will create a todo task for
> a user.

As said, why not simply think of the "workitem" as a "task" ?
This code looks like PHP. It's not very readable.

Why are you using SQL statements directly ?

In Rails you have ActiveRecord, it's an ORM. ORM means "Object to Relational Mapper". You can do a lot of things in Ruby directly without writing SQL code.

Please teach yourself about ActiveRecord.

http://www.amazon.cn/mn/detailApp/ref=sr_1_1?_encoding=UTF8&s=books&qid=1274138540&asin=B0011C47ZA&sr=8-1


Kind regards,

--
John Mettraux - http://jmettraux.wordpress.com

eric

unread,
May 17, 2010, 8:36:15 PM5/17/10
to openwfe...@googlegroups.com
john,first thanks a lot.
 
i also think the workitem is better,but workitem store a lot of info.
in the enterprise application,users is lagre enough.
everytime,when you get the user's todotask,you should query all the workitem.
this increse the database I/O.the performence of the application will be weaker.
 
the todolist is just  focus on the user and the url(where is todotask).
so i create a todotask table to slove this I/O performence problem.
 
as you says ,i will study the ActiveRecord hard from now on.
thanks
 
kind regards.
eric

John Mettraux

unread,
May 17, 2010, 8:47:13 PM5/17/10
to openwfe...@googlegroups.com
On Tue, May 18, 2010 at 08:36:15AM +0800, eric wrote:
> john,first thanks a lot.
>
> i also think the workitem is better,but workitem store a lot of info.
> in the enterprise application,users is lagre enough.
> everytime,when you get the user's todotask,you should query all the
> workitem.
> this increse the database I/O.the performence of the application will be
> weaker.
>
> the todolist is just focus on the user and the url(where is todotask).
> so i create a todotask table to slove this I/O performence problem.

Hello Eric,

then you can have something like

---8<---
class TodoParticipant
include Ruote::LocalParticipant

def initialize (opts)
end

def consume (workitem)

Todo.new(
:user => workitem.participant_name,
:at => workitem.fields['todo_at'],
:description = workitem.fields['todo_description']
).save!
# creates Todo record

reply_to_engine(workitem)
# let the process instance resume immediately
end
end
--->8---

This participant creates a Todo and then lets the process instance resume immediately.

It assumes you have an ActiveRecord model named Todo with 3 columns 'user', 'at' and 'description'.


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

Reply all
Reply to author
Forward
0 new messages