Hi Felix,
You shouldn't put business logic into process engine. You could handle business logic in your class, then invoke the process engine to continue the process. Also you should handle the state of document in your class, not process engine. The only job of process engine is running through the graphic, when it arrived a TaskActivity, it will create a task, then you could do some related operation. Show these tasks to end users, when end users complete a task, you could do some business logic, like save data into database, then invoke the api of process engine, let process engine which next step we will take.