Skip to end of metadata
Go to start of metadata

Spis treści


  

Introduction

The API of the PlusWorkflow System provides a set of interfaces and classes for performing system operations. The most important elements of the API are services (Service) and finder classes (Finder). These elements are accessed through the ServiceFactory and FinderFactory classes. Examples:

 

Pobieranie usług
UserService us=ServiceFactory.getUserService();
ActivityService as=ServiceFactory.getActivityService();
Pobieranie klas wyszukujących
UserFinder uf=FinderFactory.getUserFinder();
PositionFinder pf=FinderFactory.getPositionFinder();

When we have an instance of the Service class created, we can perform any operations. The list of available services is available here: List of available services

Examples of use

Dodanie użytkownika (UserService)
 		UserService us=ServiceFactory.getUserService(); 
        User user = new User("jkowalski","haslo");
        user.setFirstName("Jan");
        user.setLastName("Kowalski");
        us.createUser( user , "Pracownicy");

 

Pobranie użytkownika (UserService)
UserService us=ServiceFactory.getUserService(); 
User user = us.getUser("jkowalski");

Download related objects

Most objects in the system have links to other objects. These relationships illustrate the database schema. In most cases, the primary object, e.g. User, Position, etc., is in a separate database table, so related objects are not fetched by default to minimize query execution time. To enable retrieval of related objects the methods used to retrieve data i.e. get(), getAll(), getBy,,,,() are provided with a parameter 'joins', specifying which elements are to be attached to the retrieved object. Each base class has defined static constants that we can use as values for the 'joins' parameter. We can set the 'joins' argument by passing an array or a comma-separated list of values to the function (the parameter is of type String). Examples:

 

Pobranie użytkownika i jego grup (UserService)
User user = service.getUser( "jkowalski", User.JOIN_GROUPS );
for ( UserGroup ug : user.getGroups() )
{
   log.debug( ug.getName() );
}


Uwaga

If the getUser function did not pass the 'joins' parameter then a "LazyInitializationException" exception would occur when referring to the 'groups' field of the User class(unless there is an open operation when referring to the 'groups' field).

 

Pobranie wielu obiektów powiązanych (UserService)
User user = service.getUser( "jkowalski", User.JOIN_GROUPS, User.JOIN_POSITIONS, User.JOIN_OU );
Set<UserGroup> groups=user.getGroups();
Set<Position> positions=user.getPositions();
for ( Position position : positions )
{
   log.debug( position.getOrganizationalUnit().getName() );
}
 

As you can see from the example above, we can retrieve indirectly related objects. In the example, we retrieve user positions and for each position we also retrieve the organizational unit.

 

Zaawansowane dołączanie obiektów

In fact, in order to include related objects, we don't need to use static fields i.e. User.JOIN_GROUPS, because underneath them is a simple string containing the class fields to be included during retrieval. We need to remember to include all intermediate fields as well. take a look at an example:

User user = service.getByUserId( "jkowalski", "positions", "positions.organizationalUnit", "positions.organizationalUnit.directorPosition","positions.organizationalUnit.directorPosition.roles" );

The above query will take a user with the login 'jkowalski', attach the positions, attach the unit to the position, attach the management position to the unit and for this position attach the roles as well. With this, we can execute, for example, the following code:

  for ( Position p : user.getPositions() )
            {
                if ( p.getOrganizationalUnit() != null )
                {
                    if ( p.getOrganizationalUnit().getDirectorPosition() != null )
                    {
                        for ( PositionRole pr : p.getOrganizationalUnit().getDirectorPosition().getRoles() )
                        {
                            log.debug( pr.getRoleId() );
                        }
                    }
                }
            }

Of course, such a complex query, in addition to the fact that it is unlikely to make much sense, is not recommended due to the relatively long execution time.

Using static fields for attaching objects is recommended because it eliminates the possibility of errors (typos).

 



  • No labels