Change the status of a task - Best practice - java

I am creating an application that concern the activities to be carried out in a company.
These tasks can go through n states (e.g. new, in progress, completed, canceled).
The status step is determined by both the previous state and the user who is currently logged on.
What is the best way to handle all this in a spring boot application? A BPM engine?
Thanks

If its as simple as you suggested, list of rules, Drools should be fine.
If its more elaborate, please have a look at activiti
Both easily integrates with SpringBoot.

Related

Can activiti be used to develop a state machine?

The aim is to build a state machine in java which has
An initial state and which can make transition based on a given target state id.
It can output a set of possible transitions which can be reached from the target state id.
It can be achieved by simple coding but i want the workflow to be configurable.
This requires some work. I wanted to know if there is an existing library in java which does this. I came across activiti but i don't know how to use it for my scenario. If it can be used for the scenario, please mention exact steps needed to configure it for the same. Or if there is any other alternative for this.
Given your requirements, I'm not sure Activiti is a good fit, since it is a full blown workflow engine, with users/groups, a modeling application, and a set of existing processes.
I'd probably look at specialized state machine like: https://github.com/oxo42/stateless4j
Two more open-source state machine library you can use
1) SCXML(State Chart XML): http://commons.apache.org/proper/commons-scxml/guide.html
2) Spring state machine:http://docs.spring.io/spring-statemachine/docs/1.2.0.BUILD-SNAPSHOT/reference/htmlsingle

Customizable workflow/ State machine

I am trying to build a customizable workflow or kind of state transition which user should be able to update through UI.
Basically it should have all the states and user should be able to choose the transition from one state to another and also hook any predefined action to it. The predefined action could be anything like user task, email task or script task.
It should be flexible enough to add more states / actions to it.
I tried evaluating Activiti but it doesn't look like a good fit here. In fact Workflow engine doesn't look like a right candidate.
Can someone suggest any existing framework or library which I can use.
You can try using JBPM. I have used it in my earlier project.
http://www.jbpm.org/[Jbpm Home][1].
Drawback
JBPM 5 doesnt support clustering. (Not sure if It is fixed in JBPM 6)
I have chosen Squirrel foundation as my backend state transition machine. Decorated with my custom palates for denoting different kind of state (user intervention, service , email etc). And using Viz.js for visualizing and creating the workflow in JS.

architecture - should I combine many ad-hoc applications to a single application?

My main goal is providing a search application written in jquery that is based on solr. (For those who unfamiliar with solr, just assume its a rest api that can return search result.)
For this goal I wrote many small applications and servlets that each one does an ad-hoc task.
For example:
SearchApp - a jquery app in which an end user can perform searches.
SolrProxy - A java servlet that plays a proxy role between the SearchApp and solr. One of the things it does is logging the user request for later analysis.
StatsApp- a servlet that performs analysis of the user activity and returns a json with the data.
Indexer - a java application that indexes data to solr according to my requirements. in this process it also fetches an SQLServer DB, and then performs some update commands to the DB.
IndexerServlet - an asynchronous servlet that uses Indexer to provide an ability to execute index by http request.
Nutch - an open source project that indexes data to solr for other requirements that are not accomplished in Indexer(3).
(MAYBE) - some service that will perform scheduled Nutch running.
And more components might be added.
It seems a bit wrong to have multiple java projects that each one does a single task, instead of having one project that handles most of the components.
Any ideas and insights on this?
Should I combine all the java apps to a single project? should I use some kind of a fremework for this? or should I live it as it is now?
I don't think it's a bad idea that you have all these separate applications. They all seem to be doing one thing, and doing it well. What you can do, is expose them via a unified interface. So essentially you have a facade that sits in front of all these disparate services that presents an abstract and uniform interface. The consumers of this service will have no idea what sits behind that facade. This is just as well, because now you can discretely update and replace individual components without affecting others. If you had combined all of them into one, you would have to push a new release every time you modified one of the components.

Best approach to intercept task creation in Activiti for updating a parallel search index?

We are embedding Activiti in an application and have some specific requirements towards searching for tasks that go beyond the out of the box Task query capabilities of Activiti. I'm currently considering integrating ElasticSearch and maintaining a specialized index of tasks. For that to work I need to intercept task creation in Activiti.
I haven't found a "native" and transparent (in that I should not have to explicitly model this into my workflows) Activiti mechanism for this (like an interceptor mechanism). At the moment my best bet looks to be to write an myBatis intercepter plugin.
Before I commit to this I wanted to make sure I'm not missing a cleaner/easier method.
I have written a post about this. Check out http://developer4life.blogspot.com/2012/02/extending-task-service-in-activiti.html
If you are using CDI (Weld), have a look at the Activiti User Guide, section "Receiving Process Events": http://activiti.org/userguide/index.html#N12DA5

Usecase for Workflow Engine

We have an issue where a Database table has to be updated on the status for a particular entity. Presently, its all Java code with a lot of if conditions and an update to the status. I was thinking along lines of using a Workflow engine since there can be multiple flows in future. Is it an overkill to use a Workflow Engine here... where do you draw the line ?
It depends on the complexity of your use case.
In a simple use case, we have a database column updated by multiple consumers for each stage in an Order lifecycle. This is done by a web service calling into the database.
The simple lifecycle goes from ACKNOWLEDGED > ACCEPTED/REJECTED > FULFILLED > CLOSED. All of these are in the same table on the same column. This is executed in java classes with no workflow.
A workflow engine is suited in a more complex use case which involves actions on multiple data providers eg: database or Content Mgmt or Document Mgmt or search engine, multiple parallel processes, forking based on the success/failure of a previous step, sending an email at a certain step, offline error alerting.
You can look at Apache ODE to implement this.
We have an issue where a Database table has to be updated on the status for a particular entity. Presently, its all Java code with a lot of if conditions and an update to the status.
Sounds like something punctual, no need for orchestrating actions among workflow participants.
Maybe a rule engine is better suited for this. Drools could be a good candidate. When X then Y.
If you're using Spring, this is a good article on how to implement your requirement
http://www.javaworld.com/javaworld/jw-04-2005/jw-0411-spring.html
I think you should consider a workflow engine. Workflow should be separated from application logic.
Reasons:
Maintainable: Easier to modify, add new flows and even easier to replace by another workflow engine.
Business Process management: Workflows are mostly software representations of BPM. So it is usually designed by process designers (Non-tech people). So it is not a good idea to code inside the application. Instead BPM products such as ALBPM or JPBM should be used which support graphical workflow designs.
Monitoring business flows: They are often monitored by the Top level managers and used to make strategic decisions.
Easier for Data mining/Reports/Statistics.
ALBPM(Now Oracle BPM): is a commercial tool from Oracle suitable for large scope projects.
My recommendation is JBPM. Open source tool from JBOSS. Unlike ALBPM which requires separate DB and application server, it can be packaged with your application and runs as another module in your application. I think suitable for your project.

Categories