Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Polish

Wstęp

Przydatne klasy:

  • SubstitutionService - zarządzanie zastępstwami użytkowników
  • SubstitutionFinder - wyszukiwanie zastępstw
Code Block
languagejava
titleDostęp do usług
linenumberstrue
		SubstitutionService substitutionService = ServiceFactory.getSubstitutionService();
        SubstitutionFinder substitutionFinder = FinderFactory.getSubstitutionFinder();

Zarządzanie zastępstwami

Do zarządzania zastępstwami należy używać usługi SubstitutionService. Umożliwia ona m. in. dodawanie, zmianę, usuwanie zastępstw.

Code Block
languagejava
titlePrzykłady
linenumberstrue
SubstitutionService ss = ServiceFactory.getSubstitutionService();		

//Utworzenie zastępstwa
Substitution substitution = new Substitution();
substitution.setProcessDefId( "test" );

RoleService rs = ServiceFactory.getRoleService();
ProcessService ps = ServiceFactory.getProcessService();
ProcessDefinition pd = ps.getProcessDefinition( substitutionForm.getProcessName() );
Role role = rs.getRole( pd.getPackageId(), pd.getProcessDefinitionId(), roleId );
substitution.setRole( role );

UserService us = ServiceFactory.getUserService();
substitution.setSubstituted( us.getUser("jkowalski") );
substitution.setSubstitute( us.getUser( "admin" ) );

substitution.setStartDate( new LocalDateTime( "2014-10-20") );
substitution.setFinishDate( new LocalDateTime( "2014-10-22" ) );

ss.createSubstitution( substitution );
 
//Pobieranie zastępstw
Substitution substitution  = ss.getSubstitution( 34L ); //pobieranie na podstawie id z bazy danych

...

List<Substitution> substitutions = ss.getSubstitutions( "admin" ); //pobieranie na podstawie loginu użytkownika (zastępstwa, w których podany użytkownik jest zastępcą lub zastępowanym)
 
//Modyfikacja zastępstwa
Substitution substitution  = ss.getSubstitution( 34L );
substitution.setProcessDefId( "test2" );
ss.updateSubstitution( substitution );
 
//Usuwanie zastępstwa
Substitution substitution  = ss.getSubstitution( 34L );
ss.deleteSubstitution( substitution ); //usuwanie na podstawie całego obiektu pobranego z bazy
ss.deleteSubstitution( 30L ); //usuwanie na podstawie id z bazy danych

Wyszukiwanie zastępstw

Usługa SubstitutionService udostępnia podstawowe i najczęściej wykorzystywane wyszukiwania zastępstw, np.: pobieranie zastępców dla danego użytkownika.

Do bardziej złożonego wyszukiwania służy usługa SubstitutionFinder, która pozwala na wyszukiwanie zastępstw w zależności od zdefiniowanych kryteriów.

Code Block
languagejava
titlePrzykład z wykorzystaniem filtrów
linenumberstrue
SubstitutionFinder sf = FinderFactory.getSubstitutionFinder();
 
//definiujemy filtry wyszukiwania
List<HibernateFilter> filters = new ArrayList<HibernateFilter>();
//Łączenie kryteriów za pomocą operatora logicznego OR
GroupHibernateFilter groupFilter = new GroupHibernateFilter();
groupFilter.setLogicOperator( LogicOperator.OR );
 
//Warunek - processDefId = "test"
SimpleHibernateFilter filter1 = new SimpleHibernateFilter( "processDefId", "test" );
groupFilter.addFilter( filter1 );
//Warunek - lStartDate (data rozpoczęcia) > obecna data
SimpleHibernateFilter filter2 = new SimpleHibernateFilter( "lStartDate", ( new Date() ).getTime() );
filter2.setOperator( FilterOperator.GT );
groupFilter.addFilter( filter2 );
 
filters.add( groupFilter );
 
//Sortowanie malejąco po id z bazy
Sorter sorter = new Sorter( "id", SortDirection.DESC );
int start = 0;
int limit = 10;
 
Pagination pagination = Pagination.create( sorter, start, limit );
 
CountedResult<Substitution> substitutions = sf.findByFilters( filters, pagination );

Zdefiniowane powyżej wyszukiwanie znajdzie zastępstwa, które zdefiniowane są dla procesu "test" lub ich data rozpoczęcia jest późniejsza niż aktualna data. Wyniki zostaną zawężone do 10 pozycji i posortowane malejąco po "id" z bazy danych.

Do utworzenia filtrów zastosowano zdefiniowane filtry HibernateFilter.

Powyższy przykład można również zaimplementować za pomocą DetachedCriteria.

Code Block
titlePrzykład z wykorzystaniem DetachedCriteria
linenumberstrue
SubstitutionFinder sf = FinderFactory.getSubstitutionFinder();

DetachedCriteria dc = DetachedCriteria.forClass( Substitution.class );

//Łączenie kryteriów za pomocą operatora logicznego OR
Disjunction or = Restrictions.disjunction();
or.add( Restrictions.eq( "processDefId", "test" ) );
or.add( Restrictions.gt( "lStartDate", ( new Date() ).getTime() ) );

dc.add( or );

int start = 0;
int limit = 10;

/*Można wybrac jeden z dwóch poniższych wariantów:*/
 
//Pobieranie listy zastępstw za pomocą metody findByCriteria (musimy dodać order do DetachedCriteria.
dc.addOrder( Order.desc( "id" ) );
List<Substitution> substitutions = sf.findByCriteria( dc, start, limit );

//LUB
 
//pobieranie zastępstw wraz z całkowitą liczbą za pomocą getCountedResult (musimy utworzyć obiekt Sorter do sortowania)
Sorter sorter = new Sorter( "id", SortDirection.DESC );
Pagination pagination = Pagination.create( sorter, start, limit );
CountedResult<Substitution> substitutions = sf.getCountedResult( dc, pagination );
English

Introduction

Useful classes:

  • SubstitutionService - managing user substitutions
  • SubstitutionFinder - searching for substitutions
Code Block
languagejava
titleAccess to services
linenumberstrue
		SubstitutionService substitutionService = ServiceFactory.getSubstitutionService();
        SubstitutionFinder substitutionFinder = FinderFactory.getSubstitutionFinder();

Substitution management

Use SubstitutionService to manage substitutions. It allows you to add, change, delete substitutions, among other things.

Code Block
languagejava
titleExamples
linenumberstrue
SubstitutionService ss = ServiceFactory.getSubstitutionService();		

//Create Substitution
Substitution substitution = new Substitution();
substitution.setProcessDefId( "test" );

RoleService rs = ServiceFactory.getRoleService();
ProcessService ps = ServiceFactory.getProcessService();
ProcessDefinition pd = ps.getProcessDefinition( substitutionForm.getProcessName() );
Role role = rs.getRole( pd.getPackageId(), pd.getProcessDefinitionId(), roleId );
substitution.setRole( role );

UserService us = ServiceFactory.getUserService();
substitution.setSubstituted( us.getUser("jkowalski") );
substitution.setSubstitute( us.getUser( "admin" ) );

substitution.setStartDate( new LocalDateTime( "2014-10-20") );
substitution.setFinishDate( new LocalDateTime( "2014-10-22" ) );

ss.createSubstitution( substitution );
 
//Pobieranie zastępstw
Substitution substitution  = ss.getSubstitution( 34L ); //retrieve based on id from database
List<Substitution> substitutions = ss.getSubstitutions( "admin" ); //retrieval based on the user's login (substitutions in which the specified user is the substitute or substituted)
 
//Modyfikacja zastępstwa
Substitution substitution  = ss.getSubstitution( 34L );
substitution.setProcessDefId( "test2" );
ss.updateSubstitution( substitution );
 
//Usuwanie zastępstwa
Substitution substitution  = ss.getSubstitution( 34L );
ss.deleteSubstitution( substitution ); //removal on the basis of the entire object downloaded from the database
ss.deleteSubstitution( 30L ); //removal based on id from database

Substitution search

The SubstitutionService provides basic and most commonly used substitution searches, for example: retrieving substitutes for a given user.

For more complex searches, there is the SubstitutionFinder service, which allows you to search for substitutions depending on defined criteria.

Code Block
languagejava
titleExample using filters
linenumberstrue
SubstitutionFinder sf = FinderFactory.getSubstitutionFinder();
 
//define search filters
List<HibernateFilter> filters = new ArrayList<HibernateFilter>();
//Combining criteria using the OR logical operator
GroupHibernateFilter groupFilter = new GroupHibernateFilter();
groupFilter.setLogicOperator( LogicOperator.OR );
 
//Condition - processDefId = "test"
SimpleHibernateFilter filter1 = new SimpleHibernateFilter( "processDefId", "test" );
groupFilter.addFilter( filter1 );
//Warunek - lStartDate (data rozpoczęcia) > obecna data
SimpleHibernateFilter filter2 = new SimpleHibernateFilter( "lStartDate", ( new Date() ).getTime() );
filter2.setOperator( FilterOperator.GT );
groupFilter.addFilter( filter2 );
 
filters.add( groupFilter );
 
//Sort descending by Id from Sort base
Sorter sorter = new Sorter( "id", SortDirection.DESC );
int start = 0;
int limit = 10;
 
Pagination pagination = Pagination.create( sorter, start, limit );
 
CountedResult<Substitution> substitutions = sf.findByFilters( filters, pagination );

The search defined above will find substitutions that are defined for the process "test" or their start date is later than the current date. The results will be narrowed down to 10 items and sorted in descending order by "id" from the database.

The defined HibernateFilter was used to create the filters.

The above example can also be implemented using DetachedCriteria.

Code Block
titleExample using DetachedCriteria
linenumberstrue
SubstitutionFinder sf = FinderFactory.getSubstitutionFinder();

DetachedCriteria dc = DetachedCriteria.forClass( Substitution.class );

//Combining criteria using the OR logical operator
Disjunction or = Restrictions.disjunction();
or.add( Restrictions.eq( "processDefId", "test" ) );
or.add( Restrictions.gt( "lStartDate", ( new Date() ).getTime() ) );

dc.add( or );

int start = 0;
int limit = 10;

/*You can choose one of the following two options:*/
 
//Retrieving a list of substitutions using the findByCriteria method (we need to add an order to DetachedCriteria).
dc.addOrder( Order.desc( "id" ) );
List<Substitution> substitutions = sf.findByCriteria( dc, start, limit );

//OR
 
//get substitutions along with the total number using getCountedResult (we need to create a Sorter object for sorting)
Sorter sorter = new Sorter( "id", SortDirection.DESC );
Pagination pagination = Pagination.create( sorter, start, limit );
CountedResult<Substitution> substitutions = sf.getCountedResult( dc, pagination );