In the previous module, we looked at creating a database. But for the full operation of the application, it is not enough just to store data. It needs to be somehow processed, modified, used in calculations, transferred. The most important stage in the development of most applications is the process of creating the logic of their work.
Business process editor
Business process basics
On the AppMaster platform, a business process editor is designed to build the work logic. This module is dedicated to getting to know it.
Each business process (BP) is a separate part of the application logic, some specific function. At the same time, the BP itself consists of a set of blocks and links between them.
A block is usually some kind of elementary action. For example, multiplying two numbers, writing a variable to a database table, concatenating strings, or adding an element to an array. However, more complex operations can be performed in a separate block, such as searching for elements in the database, with filtering and sorting.
Moreover, any created business process can also be represented as a separate block, as part of another business process. It is reasonable to use this in situations where the BP function can be reused in other business processes, and also if the BP becomes too large and its individual parts can be represented as independent blocks.
Communication lines are created between the blocks, which determine the order of the blocks, the sequence of their execution. Often this will not be a normal linear sequence. In certain situations, branching can occur when the data obtained at one stage of the BP can influence the further choice of options for action. It is also possible to work in cycles, when the sequence of actions will be performed again and again, until the condition for terminating the cycle is met.
At the same time, there are two blocks that are mandatory for any business process. Blocks of the beginning (Start) and end (End) of the work of the BP. These blocks are created automatically and cannot be deleted. By themselves, they do not perform any operations, but are the entry and exit points of the business process. In addition, variables can be set in these blocks, which are the input and output data of the BP.
Building business processes
It's time to put it to the test. Let's move on to the section on working with business processes. Let's create the first business process and set up the internal logic of its work.
By clicking on “+ Create business process”, a modal window will open with parameters for creating a new business process:
- Process name. The only required field.
- Folder. If there are a lot of business processes, then it is more convenient to break them into groups and place them in the appropriate folders.
- Description One name may not be enough to fully convey the purpose of the BP and reveal the details of its work. The description field is intended for such information.
- Transaction mode. If the switch is activated, the BP acquires the property of atomicity. This means that the BP is either fully executed, or none of its individual blocks are executed. If an error occurs in any block, then all changes caused by previous blocks will be rolled back.
Let's create a business process that receives the values of two numbers as input. Let's perform mathematical operations with these numbers. Let's calculate the results of:
The result of the division we’ll also additionally round up to the first decimal place.
As a result, we will have to get 5 numbers, which we will combine into an array. It is this array that will become the result of the business process.
It all starts with input. It is necessary to determine the numbers with which we will carry out mathematical operations. It is important to understand that we are not asking numbers as such. We create variables that take on the required values. This can be compared to solving school equations. X + Y = Z. So we will not set specific 2 numbers, but abstract X and Y. In the future, their exact value can be set by anyone.
To set the input values, select the Start block. A section for setting variables will appear in the right pane. It is necessary to set their names (we have already decided that they will be X and Y) and select the type of variables. In the second module, we discussed that there are two options available for writing numbers. Integer (for integer data) and Float (for floating point numbers). In this case, we are not going to be limited to integer values, so it will be correct to choose the Float type.
The next step is to add blocks of mathematical operations. They are located on the left panel and divided into sections. You just need to select the necessary ones and drag them to the workspace. First of all, we are interested in mathematical operations, respectively, we need the Sum, Subtract, Multiply and Divide blocks.
You can make sure that each block is a business process in miniature. It necessarily has a beginning (In) and an end (Out), as well as input and output data (most often they are there, but this is not mandatory, there are BPs without them).
The operations will be performed sequentially, one after the other. It is necessary to establish their connection (determine the order of their execution) and submit the necessary input data).
The next step is to round the division result. We use the Round block (Round Up or Round Down options are possible for rounding up and down, respectively), we feed the result from the division block as input and set the accuracy. We are interested in 1 decimal place, so we set the Precision parameter to 1.
The intermediate result should be something like this:
It is worth noting that the arrangement of blocks itself can be any. You can line them up in a row, you can place one block under another. This affects only the convenience of perception, but not the result of the business process. The main thing is that the communication lines themselves are set in the correct order, and the necessary data is received at the input of the blocks.
The next step is to create an array with the received data. The Append array block is ideal for this. Its task is precisely to add a new element to the array. The input is an array and the required element, the output is an array with 1 more element.
Note that there is no need to manually set the data type. The block will automatically adjust to the required type, depending on what data it receives as input. If you apply Float to the input, then the output will automatically be an array of Float, it will not be possible to accidentally connect it to an incompatible data type.
We are adding 5 values to the array, so the Append Array block must be used 5 times. In the first case, it is sufficient to supply only the element to be added as input. The array will be created automatically. In subsequent cases, both the element and the array itself, to which we add the element, must get to the input.
By the way, in the left panel, next to Append Array, you can see functions with similar names. Prepend Array makes the new element the very first, and this is different from Append, which adds an element to the end of the array. The Concat Array block is used to concatenate two arrays.
AppMaster uses many different blocks. Do not be afraid to experiment and use them all, even if there was no information about a specific block within the course.
To transfer the final result, it remains only to add the corresponding variable to the End block. In our case, this is a Float Array.
The creation of the first business process is finished! In the next module, we will understand how to use it in practice, supply input data and receive a result.
Create a business process that handles 3 numbers. One of them is constant, the other two are variable.
- The sum of these numbers
- The result of dividing 2) by 1) rounded up to an integer value
- The result of dividing 1) by 2) rounded up to the second decimal place.
The result of the business process should be two arrays. In one, the data is arranged in the order in which it was calculated. In the second, the same data, but in reverse order.