⬆️ ⬇️

What threatens the business process engine programmer on the example of Apache Activiti

The phrase "business processes" has long and firmly agitated the brain to all business people and those who are faced with them. Among those interested, it is believed that work on business processes is “stylish, fashionable, youth.” True, there is no guarantee to see a clear understanding of what kind of a beast is in the eyes of the interlocutor, even if he is a real business person. And now I propose to imagine what a swamp about this topic croaked in the head of the average developer (by the example of the author), when it turned out that the next product would work on these very business processes ...



Inside it can be interesting to the same developers who do not yet have an idea of ​​how business processes will change their lives.



It is from this moment that the acquaintance with these poorly understood entities and how they influence product development began, why they might be needed and useful. I want to note that there will be no program code inside at all - something, but there are practically no technical difficulties. Normal industrial development. In my case, JavaEE and a little Spring.



What is the essence



So, business processes. All my life I was interested in the question “why?” And only then - “how”. Acquaintance with business processes was no exception. Therefore, the first item, let's see what the essence. In short, a business process is nothing more than a route between small pieces of work. As in any route, there are your own routes, crossroads, the conditions under which you can go, you need to stand or are allowed to turn only to the left and turn.

')

To be honest, here are a few of the following paragraphs (up to the standards for describing processes), I consider the most important. And here's why: in them I'm going to describe what could potentially give a software product the use of a business process engine. Due to a misunderstanding of this, expectations from the top management may be overestimated. And, most likely, you will have to pronounce it all your mouth out loud in the direction of the above-mentioned people, so that there will be no misunderstanding later.



Practical use


So: what is the average business process engine that it can? His first duty is to understand the pictures drawn by business analysts (or by the developers themselves, depending on how lucky they are) in a certain annotation (let's talk a little later) and carry out the sequence of actions in a strictly defined order, taking into account all the specified conditions and ... everything. No, really everything.



Here we will begin to trample the vulnerable soul of the manager with a kersey boot: no, the engine will not draw the necessary forms itself. No, he will not do the necessary work for the user, if you need data entry. No, he will not even write the business logic itself and he really does not know where our base lies and how to address it and call our business logic that has already been written. All this, the business process engines out of the box do not know how . All this needs to be written. All that is guaranteed to you is that some framework will take some resources and go from one class you implement to another class again implemented by you according to the scheme you draw again. This may seem obvious, but it is always better to voice it. It will not be worse.



And we really need it?


Next you need to answer the question - and we need it? It would seem - why learn another book in English, if a simple routing can be assembled on the knee in a week or two. The reason for this is still there (now I will talk about the capabilities of Apache Activiti including, but other representatives are basically not worse).



First of all, you need to decide whether you have fairly pronounced "cubes" in the product — works that can be repeatedly used and combined with each other. If the workflows are defined once and for all with small variations, completely covered by infrequent modifications - perhaps all this is superfluous. In the same case, when there are pronounced pieces of work that constantly have to be tied up and the main thing that you have to write - these are the call posts of previously written logic - perhaps you should pay attention to something like that.



Another reason to think about business processes is when several different people are included in the tasks modeled by the program. Well, something like someone created a document, someone endorsed, someone else wrapped the very first one for revision, and the fourth one received a notification that today he will not receive his document under any sauce. This is quite a normal scenario for creating a business process model and its subsequent execution by some Activiti.



It is necessary!


Suppose we decided that we need it. And the question arose - if you almost need to write everything yourself - do you need to bother with another component of the system with questionable utility? In fact, to fully replicate everything that the same Apache Activiti does (hereinafter - simply Activiti) is difficult and time consuming. The points: the main work of what makes Activiti:



Why am I marked with an asterisk about user roles and history? Yes, this is infinitely interesting information for business people! It is possible to watch in real time how processes go, who slows down, where the process may need to be parallelized, how much time is spent on each phase, etc. This information is just a gold mine for process optimization! And on the basis of this information it will be possible to restructure the processes of the enterprise’s work, almost on the fly.



Underwater rock


Almost - because all the same business logic needs to be written to programmers . If you just need to throw a piece of work out of a certain sequence of actions or change the condition of passing from one point to the second - there are no problems, such a refinement with a file can actually be done by poking the process diagram with the mouse. But if you need a new activity - you need to attract the developer. And it is very important that the customer understands this point as clearly as possible - the expectation of miracles in our cruel world ends mostly in disappointment and mutual insults. Therefore, the main goal is to convey what the business process engine really can for free, simply because it is and what is not. Well, it's not bad to explain that without it the matter most likely would not have been done by writing a single method in an EJB bin and its call in the process, but by full-fledged and more expensive refactoring (after all, everyone knows that explaining the benefits without reference to real money) that can be saved, you can not even voice, because it is not interesting to anyone).



Those. ultimately, when developers have come to terms with writing actually stateless operations oriented to work in the environment created by the business process engine - changes to customer needs will most likely be performed faster and easier than without relying on the capabilities of some Activiti (with provided that the application is well split into atomic work, of course).



BPMN Description Standard 2



Let's now go over the standard description of business processes. If there is an understanding that an application built under the business process engine will bring success and a bunch of goodies, and not anger and aggression on the part of the customer, the standard of description is the ability to manage the workflow that is given from above and that you need to know. You can say - this is the second programming language of the project and increased attention to it is strictly necessary. I will make a reservation - it says only about the description of the functional sequence of work.



In fact, the standard for describing business processes is not one. Not even one. There is BPEL, BPMN1.2, BPMN2, and beyond the functional description there are all kinds of IDEF0 and EPC. But here we will talk about BPMN2. What are its advantages? It is sufficiently developed to describe well-spreading processes, it is both descriptive and executable (information not only about the works and their relationships, but also the position of these elements in space is stored in one file, if someone wants to see a live process diagram) . Well, this is real XML in the end, which allows you to use it as you please and edit where you want.



Technically, here it would be worthwhile to tell about the elements used in BPMN 2.0. But ... the amount of information there is such that under it you have to write a whole bunch of articles. Moreover, right in the documentation of the same Activiti there is a brief description of all the elements, in addition there is a standard entirely translated into Russian. The translation was carried out by EleWis, for which she thanks a lot from colleagues who dislike languages ​​other than Russian, it is completely calmly searched and downloaded.



In short, there are jobs, events, logical operators in the standard. The control flow can branch under conditions, can be parallelized and then converge into one point. In addition to processes, there is the possibility of calling a subprocess. Supported business rules. There are such concepts as compensators (which work in case of an error and the task of which is to respond to this error in a certain way). In a couple of compensators, there are error generators. Even timers are. And cycles. And the ability to run scripts on process variables. Another process can be started not only explicitly, but also by a signal, including from another process. In short, there are really a lot of things and, perhaps, there was no situation when there was not enough set of actions for conducting the works presented by the standard. Even if at first it seemed that he was a dead end, later it turned out that everything was working out and the problem could be solved by building a scheme in a slightly different way.



Business Process Diagram Editor (s)



Yes, the scheme. They need to be drawn somewhere - not everyone likes to write XML by hand in vim. If we talk about Activiti - for it (it is because the engine, mr.) Right in the delivery is a web application that works quite well on Tomkat and provides a rather comfortable interface for viewing and editing processes. In addition, there is a plugin for Eclipse. Viewer to IDEA. And in general - the BPMN 2 standard is the same standard and should be supported by a whole bunch of relevant drawing artists. The last sentence is my naive thoughts that did not stand the test of reality.



Firstly, there are practically no free tools that form a normal document in the BPMN 2 annotation and allow you to save it in the correct XML according to the standard (* .bpmn or .bpmn20.xml) - Aris Express has disappeared. Yaoqiang is not bad (I won’t even try to say it), but it’s not completely free either. All I wanted was an offline, in the form of a separate application, the BPMN editor, which would be convenient and would not lose the values ​​from the fields from time to time, as the plugin for Eclipse likes to do. But decent tools were available not only for serious money, so it was almost impossible to see them either. Only after payment. And some supported BPMN. But very, very old.



It was endlessly fun to read business analyst forums on editors' choice. A lot of reading was reduced to the fact that they do not need XML output, but they need a picture. Those. Visio was among the leaders. But the difficulties of the programmers did not interest them.



So it happened that the complete Activiti web application was the best choice. The main thing is to find a free server for it and, in addition, you can get quite a working version for collaborative and remote work on process diagrams.



BUT! There is also a “second”: all business process engines have their own tags, plus to the standard, so it’s better to use the editor created for it. Or add tags then manually - XSD is usually not a problem.



Translation difficulties



So, we have come a long way, decided to get involved in business processes, and here, until we went over to the particulars of a particular engine, I consider it my duty to warn about one slippery nuance. The fact is that it is not written anywhere in the specification how small it is to split up the process so that the result obtained has the right to be called Optimal. If processes are created by business analysts, everything will become even more fun, since their task is to accurately reflect the flow of execution from the point of view of a normal person, and no one will take into account that the “Save” operation in two different processes for a programmer differs radically and not the same. Developers need to be prepared for what will have to be explained with living examples of how the process should be properly (from their point of view) in order for it to be well-placed on the business logic of the application.



And where to see how to? I'm afraid that without the accumulation of some experience by the developers themselves - nowhere. You can view a number of examples of processes, make your own by analogy, and understand that fragmentation was insufficient or, conversely, redundant.



Examples:

image



Now imagine: right and left - the same process (drawn in DIA hastily for purely illustrative purposes). And which of them is more correct? .. And here it is already decided in a particular case. If, for general process control, it doesn’t matter why a save fails, the left option can also go. And if everything is important - and the right will not be enough. The main thing is not to reach the limit of fragmentation and not to create tasks containing a line of the simplest code each. Usually, this is a bust. But not always, yes ...



Difficulties of choice



Now let's dive into the choice of a specific implementation. We once stopped at Apache Activiti. I do not even know if it makes sense to give a complete set of reasons. Most likely - no, because some of them were dictated precisely in the meantime and place, when and in what conditions the selection was carried out. But, if briefly - a free, responsive forum, development is moving, you can connect almost everything that starts with the word Apache (and this is quite a lot: Camel, Karaf, CXF, ...) by simply editing the pom-file. Good CDI support, easily configurable.



In addition to Activiti, there are a number of good solutions. This is also Intalio (their paid product is widely known in narrow circles, but there is also a free kernel), there is a solution from JBoss - BPMSuite, there are also paid implementations. If I had to choose a specific implementation again, there is no certainty that it would again be Activiti. Perhaps a BPM from JBoss would be chosen. But not a fact. Both products are developing quite dynamically, and both provide an unplowed field of opportunity. It can be noted that now there is no regret that Activiti was chosen, and not something else. But if someone is going to choose right now - I would strongly recommend not to dwell only on Activiti, but at least to compare the functionality of these three implementations.



Paid engines


What is different in all senses paid from the implementation of free? The main difference (except for support 24/7, etc.) can be called the following: they realize what you need to write in free hands. For example, connectors to web services. Developed monitors, showing statistics in a convenient person, not DBA, form. Settings with handy tools.



As mentioned above, the statistics are maintained by the free Activiti, and the logging level is configured. But, in order to show the customer important information for optimizing the processes and searching for applicants for the Slowest Brake Enterprise Award, you need to plant the developer to write a beautiful wrapper to an existing candy. In paid implementations, something like this is usually already there.



Also, some customers directly require only commercial implementations of products. If this is important - you need to look at the paid version. As an example, you can go to the Intalio website in order to feel the difference.



Internal implementation difficulties with JSF navigation as an example



Then we move a little further from general information and get into the jungle of particulars. There will be no code here anyway - I believe that there are no serious technical difficulties in this area; rather, there are difficulties in understanding what is happening and how to live with it further.



What is Activiti from a technical point of view? This is a jar set, i.e. no more than a library that you can use as you wish: you can connect directly to the web application, you can take it to the model level, and at least to a separate server (it has a REST interface, yes). What does this mean in the applied sense: you can divert the load associated with the work of the business process engine to at least another physical server. Activiti out of the box supports clustering well, so there should be no problems.



In addition, activit works on its own database schema - and here again we have a choice: you can roll out the table creation scripts directly into your workbase, and you can again make a separate database on a separate physical server and get independence from the workload of Activiti and applications. This can be very useful if you need to keep a "thick" history of the processes with a heavy load on the main base of the application. In general, as you like - do it. We can say that this is the philosophy of most Apache products. You have to pay for this, as always, by reading the configuration documentation. But in the case of Activiti there is not much documentation. And half of it is generally the standard BPMN2.



Well, a separate song - the user interface. We used JSF2, which, like any UI, has its own navigation model. And here again, you need to write an application with an eye on business processes. The reason is that tasks in BPMN2 can basically be divided into two groups: tasks that are performed without user input (for example, ServiceTask) and tasks that require user input (UserTask). The first is simple: you have a piece of somehow styled code - right up to JavaScript or Groovy in the case of ScriptTasks, in which you can manipulate the variables of the active process. For ServiceTasks, this means the implementation of an ordinary interface containing one method in which an object will be placed, from which you can get access to the current instance of the process and in which you can hook any CDI bins. Any objects can be placed in the process, so long as they know how to serialize. Those. normal operation while maintaining state if necessary. Nothing complicated.



But with the second type of tasks all the more difficult. When the process runs across UserTask, it ... just stops and does nothing. A user task is assigned to a specific user or their group. Next, you need to write your own engine, which will look at whether there is a task assigned to the user and in some way will draw the form. This is where the ugly dog ​​rummaged: you need to decide how the UI navigation will work, in other words, or we replace the JSF navigation model, shifting this care to Activiti or ... And “or” probably won't, because without the possibility redirect the process to the input form, business process management capabilities will be seriously curtailed. There will be only small pieces of work that can be performed blindly, without user intervention. But the main benefits of business processes can be extracted when several people are involved in the process. Therefore, we at one time decided to give the navigation between the forms included in the process, to the side of Activiti, leaving the JSF navigation models to work with forms that are not part of the business processes. And I think that was the right decision.



The rest - Activiti is quite friendly and obvious in the use of the engine of business processes, which allows you to most clearly conduct the interaction of work within the process.



In conclusion



Hopefully, everything written above will bring a little more clarity into what business processes are from the developer’s point of view. Well, to quote a certain B. Gates, who previously worked at MicroSoft:

The first rule of any technology is that automating efficiently operations improves efficiency.



The second rule: automating an inefficient operation increases inefficiency.

Source: https://habr.com/ru/post/235997/



All Articles