Versions Compared

Key

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

Spis treści

Table of Contents
exclude.*Spis treści.*

Tip
titleJavadoc

http://javadoc.plusworkflow.pl/javadoc/plusworkflow/latest

 

Polish

Wstęp

API Systemu PlusWorkflow udostępnia zbiór interfejsów i klas umożliwiających wykonywanie operacji systemowych. Najważniejszymi elementami API są usługi (Service) i klasy wyszukujące (Finder). Dostęp do tych elementów uzyskujemy poprzez klasy ServiceFactory oraz FinderFactory. Przykłady:

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

Gdy mamy stworzoną instancję klasy Service możemy wykonywać dowolne operacje. Lista dostępnych serwisów jest dostępna tutaj: Lista dostępnych serwisów

Przykłady użycia usług

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

 

Code Block
languagejava
titlePobranie użytkownika (UserService)
UserService us=ServiceFactory.getUserService(); 
User user = us.getUser("jkowalski");

Pobieranie powiązanych obiektów

Większość obiektów w systemie ma powiązania z innymi obiektami. Powiązania te obrazują schemat bazy danych. W większości przypadków obiekt podstawowy np. User, Position itd., znajduje się w osobnej tabeli bazy danych dlatego obiekty powiązane nie są domyślnie pobierane, aby zminimalizować czas wykonywania zapytania. Aby umożliwić pobieranie obiektów powiązanych metody służące do pobierania danych tj. get(), getAll(),getBy,,,() są wyposażone w parametr 'joins', określający które elementy mają zostać dołączone do pobieranego obiektu. Każda klasa podstawowa ma zdefiniowane stałe statyczne, których możemy użyć jako wartości parametru 'joins'. Argument  'joins' możemy ustawiać przekazując do funkcji tablicę lub listę wartości oddzielonych przecinkiem (parametr jest typu String). Przykłady:

 

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


Warning
titleUwaga

Gdyby w funkcji getUser nie przekazano parametru 'joins' to podczas odwołania do pola 'groups' klasy User wystąpiłby wyjątek LazyInitializationException(chyba, ze w momencie odwołania do pola 'groups' istnieje otwarta transakcja).

 

Code Block
languagejava
titlePobranie 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() );
}
 

Jak widać na powyższym przykładzie możemy pobierać obiekty powiązane pośrednio. W przykładzie pobieramy stanowiska użytkownika i dla każdego stanowiska pobieramy również jednostkę organizacyjną.

 

Info
titleZaawansowane dołączanie obiektów

Tak naprawdę w celu dołączenia obiektów powiązanych nie musimy korzystać z pól statycznych tj. User.JOIN_GROUPS, ponieważ pod nimi kryje się zwykły ciąg znaków zawierający pola klasy, które mają zostać dołączone podczas pobierania. Musimy pamiętać, aby dołączyć również wszystkie pola pośrednie. Spójrzmy na przykład:

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

Powyższe zapytanie pobierze użytkownika o loginie 'jkowalski', dołączy stanowiska, do stanowiska dołączy jednostkę, do jednostki dołączy stanowisko kierownicze i dla tego stanowiska dołączy również role. Dzięki temu możemy wykonać np. następujący kod:

Code Block
languagejava
  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() );
                        }
                    }
                }
            }

Oczywiście tak złożone zapytanie poza tym, że raczej nie ma większego sensu, nie jest zalecane z uwagi na stosunkowo długi czas wykonywania.

Używanie pól statycznych do dołączania obiektów jest zalecane, ponieważ eliminuje możliwość popełnienia błędu (literówki).

 

 
English

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:

 

Code Block
languagejava
titlePobieranie usług
UserService us=ServiceFactory.getUserService();
ActivityService as=ServiceFactory.getActivityService();
Code Block
titlePobieranie 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

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

 

Code Block
languagejava
titlePobranie 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:

 

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


Warning
titleUwaga

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

 

Code Block
languagejava
titlePobranie 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.

 

Info
titleZaawansowane 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:

Code Block
languagejava
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:

Code Block
languagejava
  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).