Smith Workflow

download Smith Workflow

of 15

Transcript of Smith Workflow

  • 8/13/2019 Smith Workflow

    1/15

    Transaction Workflow with jBPMDoug Smith, CIS 764, Fall Semester 2007

    PurposeThe purpose of this tutorial is introduce j !", and sho# its use for transaction #or$flo#,using the session fa%ade pattern to demonstrate ho# j !" can fit into &2'' applications(

    jBPM & oss j !" is a #or$flo# engine that can )e used in settings from standalone &a*a

    programs coordinating tas$s to full large scale application ser*er deplo+ments in*ol*ing )usiness process implementations in*ol*ing long running processes, s+stem orchestrationand human interaction(

    j !" pro*ides a graphical process designer, an e ecution engine, an administrati*econsole application, and components for identit+ management, email integration, anddata)ase integration, among others(

    -t its core, j !" pro*ides a facilit+ for a graph oriented programming a)straction( "an+computing pro)lems can )e modeled as the e ecution of a directed graph, such as

    )usiness process management, #e) page flo#, ser*ice orchestration, and so on(

    For an in.depth treatment of graph oriented programming #ith j !", refer to the /raphriented !rogramming section of the j !" user guide1

    http1 docs(j)oss(com j)pm *3 userguide graphorientedprogramming(html

    An Example ScenarioFor the purposes of this tutorial, #e #ill use a simplified *ersion of enrolling in auni*ersit+ course as an e ample( Figure sho#s a !"5 diagram of the process(

    asicall+, #hen a student re uests enrollment for a course, if the course is not full, thestudent is added to the course, and an entr+ is made to their transcript(

    http://docs.jboss.com/jbpm/v3/userguide/graphorientedprogramming.htmlhttp://docs.jboss.com/jbpm/v3/userguide/graphorientedprogramming.html
  • 8/13/2019 Smith Workflow

    2/15

    Figure 1 Enrollment Process

    This is a *er+ simplified *ie# of the process, )ut it should suffice for the purposes of thistutorial(

    The Session Faade Patternne of the patterns #e *e seen in CIS 764 is the session fa%ade pattern( The t+pical use

    of the session fa%ade pattern in &2'' applications is to pro*ide a transaction orientedinterface to clients, scripting the necessar+ interactions )et#een '& s needed to pro*ide aser*ice( It is also used to reduce round.trips )et#een the client and ser*er re uired for atransaction, as #ell as to shield the client from the comple it+ and )aggage associated#ith using '& s(

    ne of the most important components of the session fa%ade pattern, ho#e*er, is to notma$e the client responsi)le for implementing the )usiness logic associated #ith thetransaction( - session fa%ade pro*ides a ser*ice.oriented *ie# of a transaction1 the clientcan consume the ser*ice #ithout needing to understand ho# it is implemented(

    ased on the a)o*e scenario, the follo#ing diagram sho#s the classes that can )e used toimplement the enrollment process(

  • 8/13/2019 Smith Workflow

    3/15

    Figure 2 Class model for Enrollment service

    The follo#ing se uence diagram sho#s ho# the session fa%ade can coordinate theinteractions #ith the entit+ classes to implement the enrollment process(

  • 8/13/2019 Smith Workflow

    4/15

  • 8/13/2019 Smith Workflow

    5/15

    This pattern has #or$ed #ell in practice, )ut in some cases an alternati*e approach ma+ )e #arranted1

    If the #or$flo# in the session fa%ade represents a )usiness process, as opposed todomain logic in an application, class and se uence diagrams are not a goodcommunication *ehicle #hen interacting #ith )usiness anal+sts and other

    sta$eholders from the )usiness communit+(If the process is su)ject to fre uent change, implementation in a session fa%adema+ not pro*ide the right le*el of agilit+ to deal #ith change(!rocesses that are long duration and com)ine tas$s performed )+ humans #ithtas$s performed )+ s+stems re uire a different solution paradigm, and in theinterest of consistenc+ it ma+ ma$e sense to use the same technolog+ for all

    process e ecution, )oth short li*ed straight through processing and longerduration processes(

    Using jBPM in the Session Faade j !" pro*ides a #a+ to implement the #or$flo# sho#n in the scenario a)o*e, using atechnolog+ that promotes agilit+ )+ putting the )usiness logic in an 8"9 file, e ecuted

    )+ infrastructure that can also host long duration processes that in*ol*e humans, too( Thisdemonstration #ill implement the enrollment process using j !"( -s the focus is on theuse of j !", plain old &a*a o)jects #ith stu))ed methods #ill )e used as pro ies foractual entities(

    ToolsTo complete this tutorial, +ou #ill need1

    The j !" j!D9 suite, a*aila)le from http1 la)s(j)oss(com do#nloading : projectId;j)ossj)pm

  • 8/13/2019 Smith Workflow

    6/15

    eclipse(local(path;(

    emo*e or comment out an+ other definitions for elipse(local(path( Sa*e the file, then runant, this #ill install eclipse( 5ote the installation process is )ac$#ards from most eclipse

    plugins and en*ironments1 j !" pro*ides an eclipse director+ #ith onl+ their add ons,then ha*e +ou un=ip eclipse into their director+( If +ou delete their eclipse director+, +ou#ill lose the j !" functionalit+(

    -fter the ant script finishes, install the -spect& de*elopment tools as an eclipse plugin1simpl+ un=ip the -&DT =ip file into the root eclipse director+ in the designer folder( 5otethat -spect& is used to print entr+ into the &a*a stu)s pro*ided for the tutorial1 if +ou dli$e to a*oid installing -spect&, simpl+ added the appropriate logging orS+stem(out(println statements to the stu)s to *ie# e ecution, and adjust the instructions

    )elo#(

    Create the Projectnce the tools are installed, start the j !" designer )+ dou)le clic$ing designer()at( This

    #ill launch eclipse( nce eclipse is launched, create a ne# j !" !roject(( Select File E 5e# !roject

    2( In the 5e# !roject dialog, e pand & oss j !" and select !rocess !roject(3( 5ame the project Tutorial, the select Finish(

    This #ill create a project configured #ith e*er+thing needed to e ecute a j !" process,including a sample process and &Gnit test( For this tutorial, #e #ill simpl+ add someadditional files to the project(

    Add the Sample Code/ra) the sample code from the lin$ in the references section, and un=ip it in a temporar+location on +our hard dri*e(

    efore adding the code to the project, con*ert the project to an -spect& project1( Select the project in the pac$age e plorer(

    2( ight clic$, and select Con*ert to -spect& !roject from the -spect& Tools conte tmenu(

    5e t, create folders for the e ample code1( Select src main ja*a in the pac$age e plorer(

    2( ight clic$ and select 5e# E Folder(3( Create a folder named aspects(4( epeat this process, creating folders named enroll and run(

    Finall+, drag and drop the source files from the aspects, enroll, and run folders on +ourhard dri*e into the corresponding folders in the eclipse pac$age e plorer(

  • 8/13/2019 Smith Workflow

    7/15

    Implement the Sample Process-t this point, it is time to outline the process sho#n in Figure (

    ( In the pac$age e plorer, select the src main jpdl folder(2( ight clic$ and select 5e# E ther3( ' pand & oss j !" and select !rocess Definition(

    4( Clic$ ne t, and name the process enrollment (@( Clic$ the Finish )utton(

    This #ill create a folder named enrollment , and #ill open the processdefinition( ml filein Diagram mode( -t this point, +ou can dra# the process diagram( It should loo$something li$e this1

    5ote this diagram is much closer to something +ou could sho# to a )usiness anal+st thana se uence diagram B the essential pieces of the process are sho#n, #ith the details

  • 8/13/2019 Smith Workflow

    8/15

    needed to implement the process to )e em)edded in its 8"9 representation ?soon to )esho#n )elo#A(

    -fter dra#ing the diagram, clic$ the source ta)( The 8"9 representation of the processshould loo$ li$e the follo#ing( 5ote that +ou ma+ ha*e to update the namespace for the

    document to )e Hurn1j)pm(org1jpdl.3(2 1

    J: ml *ersion;K (0K encoding;KGTF.LK:EJ process.definition mlns ;Kurn1j)pm(org1jpdl.3(2 K name ;Kenrollment KE

    J start.state name ;Kinitiate enrollment KEJ transition to;Kchec$ current enrollment KEJ transition E

    J start.state EJ state name ;Kchec$ current enrollment KE

    J transition to;KIs space a*aila)le: KEJ transition E

    J state EJ decision name ;KIs space a*aila)le: KEJ transition to;Kend K name ;K 5o KEJ transition EJ transition to;Kadd student to course K name ;K+esKEJ transition E

    J decision EJ state name ;Kadd student to course KE

    J transition to;Kadd course to transcript KEJ transition E

    J state EJ state name ;Kadd course to transcript KE

    J transition to;Kend KEJ transition E

    J state EJ end.state name ;Kend K E

    J process.definition E

    -t this point the states and transitions ha*e )een esta)lished, )ut the associated &a*ainteractions and decision logic needs to )e added(

    To add calls to &a*a o)jects in the process definition, j !" uses the )eanshell scriptinglanguage and engine to add &a*a calls to the process e ecution( For decision logic,according to the &!D9 part of the user guide, j !" uses a H&S! &SF '9 li$e e pressionlanguage for e pressing transition guards( I ha*e not found a reference to the e actlanguage, )ut it seems to align #ith &S! &SF '9, through it is em)edded slightl+differentl+, e(g( using MNO

    The follo#ing 8"9 adds the o)ject scripting and condition e pressions needed tocomplete the process(

  • 8/13/2019 Smith Workflow

    9/15

    < process-definition xmlns ="urn ! pm.org !pdl-#.$" n%me ="enrollment1" >< st%rt-st%te n%me ="initi%te enrollment" >

    < tr%nsition to ="c&ec' current enrollment" >< script >

    import enroll.+,*ourse*%t%log c%t%log = ne

    *ourse*%t%log /,t&e*ourse = c%t%log.get*ourse course)d

    semester/,

    < tr%nsition to =")s sp%ce %v%il% le?" >

    < script >

    sp%ce v%il% le =t&e*ourse.sp%ce v%il% le /,

    < tr%nsition to ="end" n%me = "2o" >< condition expression ="34sp%ce v%il% le == f%lse5" (>< tr%nsition to ="%dd student to course" n%me = "6es" >

    < condition expression ="34sp%ce v%il% le == true5" (>

    < tr%nsition to ="%dd course to tr%nscript" >< script >

    import enroll.+,egistr%r registr%r = ne egistr%r /,

    t&e7tudent =registr%r.get7tudent student)d/,

    t&e*ourse.%dd7tudent t&e7tudent/,

  • 8/13/2019 Smith Workflow

    10/15

    < tr%nsition to ="end" >

    < script >

    import enroll.+,Tr%nscript tr%nscript =

    t&e7tudent.getTr%nscript /,tr%nscript.%dd*ourse course)d semester/,

    5ote that *aria)les are introduced into scripts using the *aria)le tag( Paria)les can either

    )e *aria)les alread+ present in the process conte t, or ne# *aria)les to )e introduced inthe process conte t(

    5e t, e amine the un'nrollment class1

    p%c'%ge run,

    import org.! pm.context.exe.*ontext)nst%nce,import org.! pm.gr%p&.def.9rocess:efinition,import org.! pm.gr%p&.exe.9rocess)nst%nce,

    pu lic cl%ss un;nrollment1 4pu lic st%tic void m%in 7tring %rgs/ 4

    tr6 4(()nst%nti%te % process inst%nce.9rocess:efinition process:efinition =

    9rocess:efinition.p%rse ml esource "enrollment1(processdefinition.xml"/,9rocess)nst%nce inst%nce = ne

    9rocess)nst%nce process:efinition/,

    ((7et t&e process d%t%*ontext)nst%nce ctx = inst%nce.get*ontext)nst%nce /,ctx.set %ri% le "student)d" "1$#"/,ctx.set %ri% le "course)d" "*)7@AB"/,ctx.set %ri% le "semester" "F%ll $00@"/,

    ((;xecute t&e process&ile Cinst%nce.&%s;nded // 4

    inst%nce.sign%l /,5

    5 c%tc& T&ro % le t/ 4t.print7t%c'Tr%ce /,

    OO

    O

  • 8/13/2019 Smith Workflow

    11/15

    Some things to note a)out the process1( The process *aria)les are pro*ided to the process instance *ia the Conte tInstance

    class(2( The instance is signaled to mo*e it )et#een states(

    3( )*iousl+ a real implementation #ould ha*e to chec$ the process state,distinguish a full+ completed process from an a)orted process, and handle errorsand e ceptions(

    This is a simple program that e ecutes the process #e just defined( To see the processrun1

    ( 'dit log4j(properties in src main config, setting the j !" root logger le*el toI5F 1 change log4j(logger(org(j)pm;D' G/ to log4j(logger(org(j)pm;I5F (

    2( Select un'nrollment ?in the src main ja*a run folderA in the pac$age e plorer(3( ight clic$, then select un -s E &a*a -pplication

    Qour output should loo$ li$e1

    ;ntering run. un;nrollment1.m%in11 $$ $8 DA8 m%in )2FE pm*onfigur%tion using ! pm configur%tionresource G! pm.cfg.xmlG11 $$ $D 0@8 m%in )2FE 7t%leE !ectHog*onfigurer st%le o !ectexceptions ill e &idden from logging;ntering enroll.*ourse*%t%log.get*ourse;ntering enroll.*ourse.sp%ce v%il% le;ntering enroll. egistr%r.get7tudent;ntering enroll.7tudent.set7tudent)d;ntering enroll.*ourse.%dd7tudent;ntering enroll.7tudent.getTr%nscript;ntering enroll.Tr%nscript.%dd*ourse

    -t this point #e *e sho#n ho# o)ject interactions to pro*ide a client transaction can )ee ecuted using a j !" process and some simple o)ject scripting(

    Modifying the ProcessTo demonstrate ho# eas+ it is to modif+ a j !" process, consider the follo#ing updateto the enrollment process(

  • 8/13/2019 Smith Workflow

    12/15

    Figure 3 Updated Enrollment Process

    e #ill start )+ creating an enrollment2 process B follo# the same procedure used tocreate enrollment , e cept name it enrollment2( Cop+ the 8"9 from enrollment s

    processdefinition( ml file into enrollment2 s processdefinition( ml file, then change the process name to enrollment2 in the enrollment2 file(

    In modif+ing enrollment ?#ith the modified process captured in enrollment2A, note that1- chec$ of the student s standing #ith the )ursar has )een added, along #ith adecision to continue or end the process )ased on the student s standing(- chec$ of the student s transcript against the prere uisites of the course the+enrolling in ha*e )een added, along #ith a decision to continue or end the process

    )ased on the student s standing(

    e #ill ma$e the modifications directl+ to the 8"9(

    First, add the ne# states and decisions1

  • 8/13/2019 Smith Workflow

    13/15

    Gpdate the Rne tR state in the start.state, and remo*e the transition script 1

    -dd code to get )ursar status1

    import enroll.+,Kurs%r urs%r = ne Kurs%r /,

    urs%r7t%tus =urs%r.inLood7t%nding student)d/,

    -dd conditions to decision transitions1

    Similarl+, add scripts and conditions for the prere chec$1

  • 8/13/2019 Smith Workflow

    14/15

    import enroll.+,egistr%r registr%r = ne egistr%r /,

    t&e7tudent =registr%r.get7tudent student)d/,

    Tr%nscript tr%nscript =t&e7tudent.getTr%nscript /,

    *ourse*%t%log c%t%log = ne*ourse*%t%log /,

    prereIuisitesE' =c%t%log.s%tisfied9rereIuisites course)d tr%nscript/,

    Finall+, modif+ the chec$ current enrollment transition script1

    import enroll.+,*ourse*%t%log c%t%log = ne

    *ourse*%t%log /,t&e*ourse = c%t%log.get*ourse course)d

    semester/,sp%ce v%il% le =

    t&e*ourse.sp%ce v%il% le /,

    Qou can run the process as sho#n a)o*e, using un!rocess2 in the run pac$age( Qouroutput should loo$ li$e1

    ;ntering run. un;nrollment$.m%in1$ 0@ $D @M1 m%in )2FE pm*onfigur%tion using ! pm configur%tionresource G! pm.cfg.xmlG

  • 8/13/2019 Smith Workflow

    15/15

    1$ 0@ $D 8M1 m%in )2FE 7t%leE !ectHog*onfigurer st%le o !ectexceptions ill e &idden from logging;ntering enroll.Kurs%r.inLood7t%nding;ntering enroll. egistr%r.get7tudent;ntering enroll.7tudent.set7tudent)d;ntering enroll.7tudent.getTr%nscript;ntering enroll.*ourse*%t%log.s%tisfied9rereIuisites;ntering enroll.*ourse*%t%log.get*ourse;ntering enroll.*ourse.sp%ce v%il% le;ntering enroll. egistr%r.get7tudent;ntering enroll.7tudent.set7tudent)d;ntering enroll.*ourse.%dd7tudent;ntering enroll.7tudent.getTr%nscript;ntering enroll.Tr%nscript.%dd*ourse

    Conclusions j !" pro*ides a nice mechanism for implementing process logic and transaction#or$flo#s in &2'' applications( It s com)ination of graphical process representation and8"9 scripting pro*ide a nice separation of concerns for colla)oration )et#een )usinessanal+sts and de*elopers(

    Resources j !" Communit+ e) Site1 http1 la)s(j)oss(com j)ossj)pm

    j !" Gser /uide1 http1 docs(j)oss(com j)pm *3 userguide

    Session Fa%ade !attern1http1 ja*a(sun(com )lueprints corej2eepatterns !atterns SessionFacade(html

    TI C usiness Studio ?free !"5 modeling and simulation toolA1http1 ###(ti)co(com de*net )usiness studio default(jsp

    eanshell Scripting 9anguage1 http1 ###()eanshell(org

    ' ample project e port ?#ith source codeA1http1 people(cis($su(edu dougs cis764home#or$ j)pm tutorial srcs(=ip

    http://labs.jboss.com/jbossjbpm/http://docs.jboss.com/jbpm/v3/userguide/http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.htmlhttp://www.tibco.com/devnet/business_studio/default.jsphttp://www.beanshell.org/http://people.cis.ksu.edu/~dougs/cis764homework/jbpm_tutorial_srcs.ziphttp://labs.jboss.com/jbossjbpm/http://docs.jboss.com/jbpm/v3/userguide/http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.htmlhttp://www.tibco.com/devnet/business_studio/default.jsphttp://www.beanshell.org/http://people.cis.ksu.edu/~dougs/cis764homework/jbpm_tutorial_srcs.zip