Polish |
---|
WstępPrzydatne klasy: |
Operacje
...
Dostęp do usług | linenumbers | true |
---|
| ProcessService processService = ServiceFactory.getProcessService();
ActivityService activityService = ServiceFactory.getActivityService();
ProcessFinder processFinder =FinderFactory.getProcessFinder();
ActivityFinder activityFinder=FinderFactory.getActivityFinder(); |
Procesy Code Block |
---|
language | java |
---|
title | Operacje na procesach |
---|
linenumbers | true |
---|
| ProcessBuilderDefinition definition = new ProcessBuilderDefinition();
definition.setPackageId( "suncode" );
definition.setCreator( "admin" );
definition.setCreatorPassword( " |
|
...
xxxxxx" );
definition.setProcessDefId( "proces1" );
Map<String, Object> variables = new HashMap<String, Object>();
variables.put( "zmienna1", "abc" );
definition.setVariables( variables );
String processId = processService.createProcess( definition );
// Pobieranie informacji o procesie
Process process = processService.getProcess( processId );
process = processService.getProcess( processId, Process.JOIN_PROCESS_DEFINITION );// jeżeli chcemy mieć dostęp
// do definicji procesu
String name = process.getName();
String desc = process.getDescription();
// Definicja procesu
ProcessDefinition processDef = process.getProcessDefinition();
String packageId = processDef.getPackageId();// bez Process.JOIN_PROCESS_DEFINITION rzuci wyjątek
String processDefId = processDef.getProcessDefinitionId();
// Zmiana wartości zmiennych procesu
Map<String, Object> ctx = processService.getProcessContext( processId );
ctx.put( "zmienna", "abc" );
processService.setProcessContext( processId, ctx );
//Usunięcie procesu
processService.deleteProcess( processId ); |
Do wyszukiwania procesów należy używać klasy ProcessFinder |
...
Podstawowe wyszukiwanie dokumentów | linenumbers | true |
---|
| //definijemy |
|
...
wartości zmiennych procesu, który chcemy znaleźć
Map<String, Object> indexes = new HashMap<String, Object>();
indexes.put( "textcol", "text5" );
|
|
...
indexes.put( "datecol", DateUtils.parseDate( "2014-02-12", "yyyy-MM-dd" ) );
indexes.put( "doublecol", 4.3);
indexes.put( "intcol", 5 );
List<Process> processes = finder.findByIndexes( processDefId, indexes );
|
|
...
Process p = processes.get( 0 );//znaleziony proces
//odczyt indeksów
String textcol = (String) p.getIndexValue( "textcol" );
Date datecol = (Date) p.getIndexValue( "datecol" );
Double doublecol = (Double) p.getIndexValue( "doublecol" );
Integer intcol = (Integer) p.getIndexValue( "intcol" ); |
Przedstawiona wyżej metoda wyszukuje procesy o indeksach równych (operator '=' ) podanym wartościom i wszystkie warunki łączy operatorem logicznym AND. Jeżeli chcemy stworzyć bardziej zaawansowane warunki wyszukiwania możemy wykorzystać następującą metodę: Code Block |
---|
language | java |
---|
title | Zaawansowane wyszukiwanie |
---|
| List<IndexFilter> filters = new ArrayList<IndexFilter>();
|
|
...
filters.add( new SimpleIndexFilter( "datecol", date, FilterOperator.GT ) );// Greater then '>'
|
|
...
filters.add( new SimpleIndexFilter( "textcol", "%text%", FilterOperator.LIKE ) );
List<Process> result = finder.findByIndexes( processDefId, filters ); |
W powyższym przykładzie zdefiniowaliśmy operatory wyszukiwania, lecz warunki nadal są połączone logicznym operatorem AND. Aby to zmienić możemy wykorzystać grupowanie filtrów: Code Block |
---|
language | java |
---|
title | Grupowanie filtrów |
---|
linenumbers | true |
---|
| List<IndexFilter> filters = new ArrayList<IndexFilter>();
// tworzymy grupę warunków połączonych operatorem OR
GroupIndexFilter gif = new GroupIndexFilter( LogicOperator.OR );
// tworzymy pierwszą podgrupę warunków
GroupIndexFilter subGroup1 = new GroupIndexFilter( LogicOperator.AND );
subGroup1.addFilter( new SimpleIndexFilter( "datecol", date, FilterOperator.GT ) );
subGroup1.addFilter( new SimpleIndexFilter( "textcol", "%text%", FilterOperator.LIKE ) );
// tworzymy drugą grupę warunków
GroupIndexFilter subGroup2 = new GroupIndexFilter( LogicOperator.AND );// tworzymy kolejną grupę warunków
subGroup2.addFilter( new SimpleIndexFilter( "textcol", "text3" ) );
subGroup2.addFilter( new SimpleIndexFilter( "intcol", 3 ) );
gif.addFilter( subGroup1 );// do grupy warunków możmy dodać inną grupę tworząc drzewo warunków
gif.addFilter( subGroup2 );
filters.add( gif );
List<Process> result = finder.findByIndexes( processDefId, filters );
|
Powyższy przykład utworzy następujący warunek: ( ( datecol > '2014-02-11' and textcol like '%text%' ) or ( textcol = 'text3' and intcol = 3 ) ) Zadania |
...
Operacje na zadaniach | linenumbers | true |
---|
| |
|
...
...
// Pobieranie informacji o zadaniu
Activity activity=activityService.getActivity( processId, activityId );
String activityDefId=activity.getActivityDefinitionId();
String desc=activity.getDescription();
String name=activity.getName();
ActivityState state=activity.getState();//RUNNING, NOT_STARTED, SUSPENDED, COMPLETED, TERMINATED, ABORTED
Date created=activity.getCreatedTime();//data utworzenia zadani
Date started=activity.getStartedTime();//data uruchomienia
// Zmiana wartości zmiennych zadania
Map<String,Object> activityContext=activityService.getActivityContext( processId, activityId );
activityContext.put( "zmienna", "wartość" );
activityService.setActivityContext( processId, activityId, activityContext ); |
|
...
Powyższy kod zmienia mapę zmiennych zadania. Jeżeli w aktualnym wątku mamy otwartą transakcję, np. jesteśmy w zadaniu automatycznym to metody getActivityContext i setActivityContext automatycznie podłączą się do aktywnej transakcji. Jeżeli chcemy zmienić wartości zmiennych procesu, lecz nie chcemy zaakceptować zadania to należy ustawić ActivityContext, oraz ProcessContext:
//Otworzenie zadania przez podanego użytkownika. Jeżeli zadanie ma status 'Oczekujące na uruchomienie'
//i jest przypisane do podanego użytkownika to poniższa funkcja spowoduje przypisanie zadania
//do podanego użytkownia i zmieni status na 'Uruchomione'
activityService.openActivity( userName, userPassword, processId, activityId );
//Akceptacja zadania
String executor="jkowalski";//użytkownik akceptujący
String actionName="akceptacja";//nazwa akcji z mapy
Map<String,Object> map=new HashMap<String,Object>();
map.put( "zmienna", "wartosc" );//mapa nie zostanie całkowicie zastąpiona podaną
//zostaną nadpisane tylko podane wartości
AcceptationDefinition acceptation=new AcceptationDefinition( processId, activityId, executor, actionName );
acceptation.setContextMap( map );//opcjonalnie
acceptation.setIgnoreValidators( false ); //opcjonalne wymuszenie walidacji akceptacji
//Akceptacja zadania, na dowolnym użytkowniku (ownerLogin), jeśli jest on właścicielem zadania (tj.zostało przez niego otwarte w PWFL)
String ownerLogin = "jkowalski";
AcceptationDefinition acceptation = new AcceptationDefinition( procId, activId, ownerLogin, actionName );
activityService.acceptActivity( acceptation );
//Akceptacja zadania, na dowolnym użytkowniku (approverLogin), nawet jeśli nie jest on właścicielem zadania
String approverLogin = "test";
assignmentService.assignActivityToUser( procId, activId, approverLogin );
AcceptationDefinition acceptation = new AcceptationDefinition( procId, activId, approverLogin, actionName );
acceptation.setIgnoreOwnerShip( true );
activityService.acceptActivity( acceptation );
|
Warning |
---|
title | Uwaga dot. akceptacji zadania |
---|
| Powyżej wspomniana akceptacja zadania nie może być uruchamiana w tej samej transakcji co tworzenie procesu w którego dotyczy akceptowane zadanie. Wtedy co prawda akceptacja powiedzie się, ale w logach polecą wyjątki dot. powiadomień systemowych, które przez to nie zostaną poprawnie wykonane. Jeśli jest potrzeba, aby akceptacja zadania była wykonana zaraz po utworzeniu procesu tego zadania (np w jednym zadaniu automatycznym/zaplanowanym itp.), to trzeba wymusić stworzenie procesu w osobnej transakcji. Co można zrobić zgodnie z instrukcją Opis używania transakcji. |
Warning |
---|
title | Uwaga dot. walidacji akceptacji |
---|
| Przy walidacji zadania przez API brane są pod uwagę tylko walidatory komponentowe. |
Code Block |
---|
language | java |
---|
title | Wyszukiwanie zadań |
---|
linenumbers | true |
---|
| // Pobieranie otwartych zadań
List<Activity> activities = activityFinder.findOpenedActivities( processId );
for ( Activity activity : activities )
{
activityId = activity.getActivityId();
}
// Pobieranie zadań przypisanych do użytkownika
activities = activityFinder.findActivitiesAssignedToUser( userName, Activity.JOIN_PROCESS );
for ( Activity activity : activities )
{
activityId = activity.getActivityId();
Process process = activity.getProcess();// tylko gdy użyliśmy Activity.JOIN_PROCESS
}
// Pobieranie zadań z procesu
activities = activityFinder.findByProcessId( processId, Activity.JOIN_PROCESS );
for ( Activity activity : activities )
{
activityId = activity.getActivityId();
Process process = activity.getProcess();// tylko gdy użyliśmy Activity.JOIN_PROCESS
} |
|
English |
---|
IntroductionUseful classes: |
...
Access to services | linenumbers | true |
---|
| |
|
...
ProcessService processService = ServiceFactory.getProcessService();
ActivityService activityService = ServiceFactory.getActivityService();
|
|
...
ProcessFinder processFinder =FinderFactory.getProcessFinder();
ActivityFinder activityFinder=FinderFactory.getActivityFinder(); |
Processes Code Block |
---|
language | java |
---|
title | Operations on processes |
---|
linenumbers | true |
---|
| ProcessBuilderDefinition definition = new ProcessBuilderDefinition();
definition.setPackageId( "suncode" );
definition.setCreator( "admin" );
definition.setCreatorPassword( "xxxxxx" );
definition.setProcessDefId( "proces1" );
Map<String, Object> variables = new HashMap<String, Object>();
variables.put( "zmienna1", "abc" );
definition.setVariables( variables );
String processId = processService.createProcess( definition );
// Pobieranie informacji o procesie
Process process = processService.getProcess( processId );
process = processService.getProcess( processId, Process.JOIN_PROCESS_DEFINITION );// if we want to access
// to the process definition
String name = process.getName();
String desc = process.getDescription();
// Definicja procesu
ProcessDefinition processDef = process.getProcessDefinition();
String packageId = processDef.getPackageId();// without Process.JOIN_PROCESS_DEFINITION an exception will occur
String processDefId = processDef.getProcessDefinitionId();
// Zmiana wartości zmiennych procesu
Map<String, Object> |
|
...
ctx = processService.getProcessContext( processId );
ctx.put( "zmienna", "abc" );
processService.setProcessContext( processId, ctx );
//Usunięcie procesu
processService.deleteProcess( processId ); |
Use the ProcessFinder class to search for processes Code Block |
---|
language | java |
---|
title | Basic document search |
---|
linenumbers | true |
---|
| //define the values of the variables of the process we want to find
Map<String, Object> indexes = new HashMap<String, Object>();
indexes.put( "textcol", "text5" );
indexes.put( "datecol", DateUtils.parseDate( "2014-02-12", "yyyy-MM-dd" ) );
indexes.put( "doublecol", 4.3);
indexes.put( "intcol", 5 );
List<Process> processes = finder.findByIndexes( processDefId, indexes );
Process p = processes.get( 0 );//found process
//odczyt indeksów
String textcol = (String) p.getIndexValue( "textcol" );
Date datecol = (Date) p.getIndexValue( "datecol" );
Double doublecol = (Double) p.getIndexValue( "doublecol" );
Integer intcol = (Integer) p.getIndexValue( "intcol" ); |
The method presented above searches for processes with indices equal (operator '=' ) to the given values and combines all conditions with the logical operator AND. If we want to create more advanced search conditions, we can use the following method: Code Block |
---|
language | java |
---|
title | Advanced search |
---|
| List<IndexFilter> filters = new ArrayList<IndexFilter>();
filters.add( new SimpleIndexFilter( "datecol", date, FilterOperator.GT ) );// Greater then '>'
filters.add( new SimpleIndexFilter( "textcol", "%text%", FilterOperator.LIKE ) );
List<Process> result = finder.findByIndexes( processDefId, filters ); |
In the above example, we have defined search operators, but the conditions are still connected by a logical AND operator. To change this, we can use filter grouping: Code Block |
---|
language | java |
---|
title | Filter grouping |
---|
linenumbers | true |
---|
| List<IndexFilter> filters = new ArrayList<IndexFilter>();
// create a group of conditions connected by OR operator
GroupIndexFilter gif = new GroupIndexFilter( LogicOperator.OR );
// create the first subgroup of conditions
GroupIndexFilter subGroup1 = new GroupIndexFilter( LogicOperator.AND );
subGroup1.addFilter( new SimpleIndexFilter( "datecol", date, FilterOperator.GT ) );
subGroup1.addFilter( new SimpleIndexFilter( "textcol", "%text%", FilterOperator.LIKE ) );
// create a second group of conditions
GroupIndexFilter subGroup2 = new GroupIndexFilter( LogicOperator.AND );// create another group of conditions
subGroup2.addFilter( new SimpleIndexFilter( "textcol", "text3" ) );
subGroup2.addFilter( new SimpleIndexFilter( "intcol", 3 ) );
gif.addFilter( subGroup1 );// to a group of conditions we can add another group creating a tree of conditions
gif.addFilter( subGroup2 );
filters.add( gif );
List<Process> result = finder.findByIndexes( processDefId, filters );
|
The above example will create the following condition: ( ( datecol > '2014-02-11' and textcol like '%text%' ) or ( textcol = 'text3' and intcol = 3 ) ) Tasks
Code Block |
---|
language | java |
---|
title | Operations on tasks |
---|
linenumbers | true |
---|
| // Downloading task information
Activity activity=activityService.getActivity( processId, activityId );
String activityDefId=activity.getActivityDefinitionId();
String desc=activity.getDescription();
String name=activity.getName();
ActivityState state=activity.getState();//RUNNING, NOT_STARTED, SUSPENDED, COMPLETED, TERMINATED, ABORTED
Date created=activity.getCreatedTime();//task date creation
Date started=activity.getStartedTime();//date of running
// Changing the value of task variables
Map<String,Object> activityContext=activityService.getActivityContext( processId, activityId );
activityContext.put( "zmienna", "wartość" );
activityService.setActivityContext( processId, activityId, activityContext );
|
|
...
...
...
...
//Open task by the specified user. If the task has a status of 'Pending launch'
//and is assigned to the specified user then the following function will assign the task
//to the specified user and change the status to 'Running'.
activityService.openActivity( userName, userPassword, processId, activityId );
|
|
...
//Task acceptance
String executor="jkowalski";//user accepting
String actionName="akceptacja";//map action name
Map<String,Object> map=new HashMap<String,Object>();
map.put( "zmienna", " |
|
...
wartosc" );//map will not be completely replaced by the |
|
...
specified variable
//only the specified values will be overwritten
AcceptationDefinition acceptation=new AcceptationDefinition( processId, |
|
...
TODO Opisać możliwość utworzenie ręczenie transakcji SharkTransaction która będzie kompatybilna z serviceami API.
activityId, executor, actionName );
acceptation.setContextMap( map );//optional
acceptation.setIgnoreValidators( false ); //optional force acceptance validation
//Task acceptance, on any user (ownerLogin), if user is the owner of the task (i.e.it was opened by him/her in PWFL)
String ownerLogin = "jkowalski";
AcceptationDefinition acceptation = new AcceptationDefinition( procId, activId, ownerLogin, actionName );
activityService.acceptActivity( acceptation );
//Accept the task, on any user (approverLogin), even if he is not the owner of the task
String approverLogin = "test";
assignmentService.assignActivityToUser( procId, activId, approverLogin );
AcceptationDefinition acceptation = new AcceptationDefinition( procId, activId, approverLogin, actionName );
acceptation.setIgnoreOwnerShip( true );
activityService.acceptActivity( acceptation );
|
Warning |
---|
title | Note on acceptance task |
---|
| The above-mentioned task acceptance cannot be started in the same transaction as the creation of the process in which the accepted task is involved. Then the acceptance will be successful, but in the logs there will be exceptions concerning system notifications, which will not be executed correctly. If you want the acceptance of a task to be executed immediately after the creation of the process for this task (e.g. in one automatic/scheduled task, etc.), then you need to force the creation of the process in a separate transaction. Which can be done according to the instructions Description of using transactions. |
Warning |
---|
title | Note on acceptance validation |
---|
| Only component validators are considered when validating a task through the API. |
Code Block |
---|
language | java |
---|
title | Tasks searching |
---|
linenumbers | true |
---|
| // Downloading open tasks
List<Activity> activities = activityFinder.findOpenedActivities( processId );
for ( Activity activity : activities )
{
activityId = activity.getActivityId();
}
// Downloading tasks assigned to a user
activities = activityFinder.findActivitiesAssignedToUser( userName, Activity.JOIN_PROCESS );
for ( Activity activity : activities )
{
activityId = activity.getActivityId();
Process process = activity.getProcess();// tylko gdy użyliśmy Activity.JOIN_PROCESS
}
// Downloading tasks from the process
activities = activityFinder.findByProcessId( processId, Activity.JOIN_PROCESS );
for ( Activity activity : activities )
{
activityId = activity.getActivityId();
Process process = activity.getProcess();// tylko gdy użyliśmy Activity.JOIN_PROCESS
} |
|