agoalofalife/bpm-online

Using the API BPM Terrasoft

2.2.1 2018-07-05 12:12 UTC

This package is auto-updated.

Last update: 2024-04-29 04:06:00 UTC


README

API BPM ONLINE

Build Status Twitter Scrutinizer Code Quality Code Coverage License

RU | EN

Что это такое?

Пакет предоставляет удобный интерфейс для работы с API Bpm’online через протокол OData.

Установка

Для установки необходимо выполнить команду из composer

composer require agoalofalife/bpm-online

Настройка конфигураций

Для установки ваших конфигурационных данных есть несколько способов :

  • Через class File
 //Инициализируем ядро
 $kernel = new KernelBpm();
 $file = new File();
 
 // указываем путь до файла с  конфигурациями
 $file->setSource(__DIR__ . '/config/apiBpm.php');
 // Загружаем их
 $kernel->loadConfiguration($file);

Файл должен возвращать массив с конфигурационными данными

return [
	// url для аутентификации
    'UrlLogin' => '',
    //ваш url для запросов по api       
    'UrlHome'  => '',
    'Login'    => '',
    'Password' => ''
    ]
  • Через метод setConfigManually в KernelBpm
$kernel = new KernelBpm();
// первым параметром передается префикс для конфигурации
$$kernel->setConfigManually('apiBpm', [
        'UrlLogin' => '',
        'Login'    => '',
        'Password' => '',
        'UrlHome'  => ''
]);

Аутенфикация

Для аутенфикация в BPM API необходимо получить cookie по URL https://ikratkoe.bpmonline.com/ServiceModel/AuthService.svc/Login Для этого необходимо вызвать метод authentication

$kernel->authentication();

Можно не вызывать его и пакет автоматически обновит куки сделав дополнительный запрос.

Установка коллекции

В BPM все таблицы из базы данных именуются как коллекции ( Collections ) Для взаимодействия необходимо установить коллекцию.

$kernel->setCollection('CaseCollection');

Данный подход имеет минус в дополнительном вызове метода setCollection , но позволяет переиспользывать установку коллекции. Имеется в виду что мы можем один раз установить коллекцию и производить операции по ней.

Select

Все методы принимают первым параметром строку типа операции и тип данных, вторым параметром callback внутрь которого передается тип операции, внутри callback происходит выполнение всех пред - настроек в конце вызывается метод get. Возращается обьект типа Handler который обрабатывает ответ от BPM.

$handler = $kernel->action('read:json', function ($read){
    $read->amount(1)->skip(100);

})->get();

Всего два типа данных xml и json. Четыре вида операции read, create, update, delete.

Методы Select

filterConstructor Позволяет фильтровать выборку с помощью функции $filter в запросе

filterConstructor('Id eq guid\'00000000-0000-0000-0000-000000000000\'');

orderBy Получать данные в отсортированном виде Первым параметром название поля, вторым параметром тип сортировки : по возрастанию (asc) по убыванию (desc)

->orderby('Number', 'desc')

skip Если необходимо пропустить заданное кол - во записей

->skip(10)

amount Задать максимальное кол - во записей

->amount(100)

Имейте в виду что вы можете комбинировать методы согласно документации Bpm’online

Create

Синтаксис для создания записи такой же как и Select. Внутри callback необходимо вызвать метод setData и передать ему массив параметров для создания записи в таблице BPM.

$handler = $kernel->action('create:xml', function ($creator){
    $creator->setData([
        // array key => value
    ]);
})->get();

Update

Для обновления данных в записи в BPM необходимо знать guid записи. Здесь устанавливается guid и новые параметры для обновления.

$handler = $kernel->action('update:json', function ($creator){
    $creator->guid('')->setData([
       'Number' => ''
    ]);
})->get();

Delete

Для удаление записи из бд достаточно знать guid

$handler = $kernel->action('delete:xml', function ($creator){
    $creator->guid('');
})->get();

Обработчики ответов

Вне зависимости от операции всегда возращается тип Handler, который иммеет несколько методов для преобразования данных.

toArray Преобразовывает данные в массив

toJson Преобразовывает данные в json

getData Получить данные как есть

Логирование

На данный момент пакет сохраняет внутри себя детализацию всех запросов с сортировкой по дате. Их можно найти в src/resource/logs/...

Интеграция с Laravel

Для интеграции с фреймворком Laravel необходимо скопировать конфигурации и заполнить их

 php artisan vendor:publish --tag=bpm --force

Вставить сервис провайдер в файл config/app.php

 \agoalofalife\bpm\ServiceProviders\BpmBaseServiceProvider::class

Далее можно пользоваться извлекая обьект из контейнера

$bpm =  app('bpm');
$bpm->setCollection('CaseCollection');

 $handler = $bpm->action('read:xml', function ($read){
    $read->amount(1);
})->get();

Либо используя фасад , предварительно зарегистрировав его в файле config/app.php:

   'aliases' => [
 Illuminate\Support\Facades\Facade\Bpm
  ... 
  ]

Клиентский код


    Bpm::setCollection('CaseCollection');
     $handler = Bpm::action('read:xml', function ($read){
        $read->amount(1);
    })->get();

Инструмент

Вам необходимо запустить сервер выполнив команду

vendor/bin/panel-server

Когда перейдете по адресу то увидите перед собой , статистику продолжительности ваших запросов в Bpm. Это программа парсит ваш лог файл который находиться по адресу src/resource/logs

alt text

What is it ?

The package provides a convenient interface to work with API Bpm’online through the Protocol

Install

For installation, you must run the command from composer

composer require agoalofalife/bpm-online

Configurations

To install your configuration data there are several ways :

  • class File
 //Init  kernel
 $kernel = new KernelBpm();
 $file = new File();
 
 // specify the path to the file with the configurations
 $file->setSource(__DIR__ . '/config/apiBpm.php');
 // loading...
 $kernel->loadConfiguration($file);

The file must return an array with the data

return [
	// url for auth
    'UrlLogin' => '',
    //our url for request api       
    'UrlHome'  => '',
    'Login'    => '',
    'Password' => ''
    ]
  • through method setConfigManually in KernelBpm
$kernel = new KernelBpm();
// the first parameter is passed a prefix for configuration
$kernel->setConfigManually('apiBpm', [
        'UrlLogin' => '',
        'Login'    => '',
        'Password' => '',
        'UrlHome'  => ''
]);

Authentication

For authentication in BPM API , it is necessary to get cookie in URL

https://ikratkoe.bpmonline.com/ServiceModel/AuthService.svc/Login It is necessary to call the method authentication

$kernel->authentication();

You can not call it and the package will automatically update the cookies by making an additional query.

Set Collection

In BPM all tables of the database are referred to as collections ( Collections ) To communicate, you must install the collection.

$kernel->setCollection('CaseCollection');

This approach has an additional disadvantage in the method call setCollection, but reuse installation of the collection. Meaning that we can install a collection and perform operations on it.

Select

All methods take the first parameter of the string type and the data type, the second parameter callback inside of which is passed the type of operation, inside callback executed all pre - settings at the end method is called get.

Returns the object type Handler which handler response from BPM.

$handler = $kernel->action('read:json', function ($read){
    $read->amount(1)->skip(100);

})->get();

Only two types of data xml and json. Four types of operations read, create, update, delete.

Methods Select

filterConstructor

Allows you to filter the selection using the function $filter in request

filterConstructor('Id eq guid\'00000000-0000-0000-0000-000000000000\'');

orderBy To retrieve data in sorted form The first parameter the field name, the second argument to sort : ascending (asc) descending (desc)

->orderby('Number', 'desc')

skip

If you want to skip the specified number of records

->skip(10)

amount To set the maximum number of records

->amount(100)

Keep in mind that you can combine the methods according to the documentation Bpm’online

Create

The syntax for creating a record is the same as Select. Inside callback you must call setData and pass his array parameters for creating record in table BPM.

$handler = $kernel->action('create:xml', function ($creator){
    $creator->setData([
        // array key => value
    ]);
})->get();

Update

To update the data in the record BPM you need to know guid record. This set guid and new parameters for updates.

$handler = $kernel->action('update:json', function ($creator){
    $creator->guid('')->setData([
       'Number' => ''
    ]);
})->get();

Delete

For deleting a record from DB enough to know guid and only guid

$handler = $kernel->action('delete:xml', function ($creator){
    $creator->guid('');
})->get();

Handler Response

Regardless of the operation always returns a typeп Handler, which has several methods to convert the data.

toArray Converts the data into an array

toJson Converts the data to json

getData Just Return the data

Log

At the moment, the package keeps a detail of all queries sorted by date. You can find them in src/resource/logs/...

Integration with Laravel

For integration with the framework Laravel you must copy the configuration and fill them

 php artisan vendor:publish --tag=bpm --force

Insert the service provider to a file config/app.php

 \agoalofalife\bpm\ServiceProviders\BpmBaseServiceProvider::class,

Then you can use extract the object from the container.

    $bpm =  app('bpm');
    $bpm->setCollection('CaseCollection');

     $handler = $bpm->action('read:xml', function ($read){
        $read->amount(1);
    })->get();

Or by using the Facade , registering it in a fileconfig/app.php:

   'aliases' => [
 Illuminate\Support\Facades\Facade\Bpm
  ... 
  ]

Client code

    Bpm::setCollection('CaseCollection');
     $handler = Bpm::action('read:xml', function ($read){
        $read->amount(1);
    })->get();

Tool

You need to start the server by running the command :

vendor/bin/panel-server

When you click on the address you will see a statistics of the duration of your queries in Bpm. This program parses your log file which is located at the address src/resource/logs

alt text