Skip to end of metadata
Go to start of metadata

Introduction

Useful classes:

  • SubstitutionService - managing user substitutions
  • SubstitutionFinder - searching for substitutions
Access to services
		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.

Examples
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.

Example using filters
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.

Example using DetachedCriteria
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 );

  • No labels