AnsweredAssumed Answered

re-opening closed process and setting to praticular task

Question asked by danielporter1 on Sep 1, 2016
Latest reply on Dec 13, 2016 by thuynh
Hi there,

I'm working on re-opening a process and setting it to the last task in the workflow by directly modifying the database. Right now I'm changing information in 8 tables - adding an execution, adding an act_ru_task, adding a new act_hi_actinst, adding a new act_hi_taskinst, modifying the act_hi_procinst to stop saying the task is closed, adding candidate groups to act_ru_identitylink, copying the vars from act_hi_varinst to act_ru_variable, and incrementing the application's id counter in act_ge_property.

This seems to work sometimes, but not all of the time, and can't tell why that is. In the times it fails, I get the error pasted at the bottom. It's a null pointer exception that seems to get thrown when finish task gets called.

I've also pasted the postgresql stored procedure and the method invocation I'm using the re-open the task. It can be trivially modified to work on another activiti process.

Does anyone have any ideas why this would happen? I've tried to be thorough but apparently I'm missing something. Wondering if I need to give in and figure out how to run the engine code with intellij. Hoping to avoid that.

Thanks so much!

05:25:00,420 [http-nio-8080-exec-10] ERROR org.activiti.rest.exception.ExceptionHandlerAdvice  - Unhandled exception
java.lang.NullPointerException
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.signal(ExecutionEntity.java:406)
        at org.activiti.engine.impl.persistence.entity.TaskEntity.complete(TaskEntity.java:203)
        at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:52)
        at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:24)
        at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:59)
        at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
        at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
        at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
        at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:179)
        at org.activiti.rest.service.api.runtime.task.TaskResource.completeTask(TaskResource.java:126)
        at org.activiti.rest.service.api.runtime.task.TaskResource.executeTaskAction(TaskResource.java:78)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:201)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
        at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

create or replace function setClosedProcessToManagerReview(proc_inst_id character varying (64), proc_def_id character varying(64))
returns BOOLEAN  LANGUAGE plpgsql AS
$$
BEGIN

INSERT INTO act_ru_execution select id_, 1, proc_inst_id_, business_key_, null, proc_def_id_, null, 'a5managerreview', true, false, true, false, 1, 2, '', null, null
FROM act_hi_procinst
WHERE proc_inst_id_ = proc_inst_id;

INSERT INTO act_ru_task
SELECT (SELECT cast(max(cast(id_ as int)) + 3 as character varying (64)) FROM act_ru_task) as id_,
2,
proc_inst_id,
proc_inst_id,
proc_def_id, 'Manager Review', null , null, 'a5managerreview', null, null, null, 50, now(), null, null, 1, '', '/app/viewdocument/review/'
–FROM act_ru_task
–WHERE id_= (select cast(max(cast(id_ as int)) as character varying (64)) from act_ru_task);

INSERT INTO act_hi_actinst
SELECT (select cast(max(cast(id_ as int)) + 3 as character varying (64)) from act_hi_actinst), proc_def_id, proc_inst_id, proc_inst_id, 'a5managerreview',
(SELECT id_ FROM act_ru_task WHERE proc_inst_id_ = proc_inst_id), null, 'Manager Review', 'userTask', null, now(), null, null, '';

INSERT INTO act_hi_taskinst
select id_, proc_def_id_, task_def_key_, proc_inst_id_, execution_id_, name_,
null, null, null, assignee_, create_time_, null, null, null, null, 50, null, form_key_, category_, tenant_id_ FROM act_ru_task WHERE proc_inst_id_ = proc_inst_id;

UPDATE act_hi_procinst
SET end_time_ = null, duration_=null, end_act_id_ = null
WHERE proc_inst_id_ =  proc_inst_id;

INSERT INTO act_ru_variable
SELECT id_, rev_, var_type_, name_, execution_id_, proc_inst_id_, task_id_, bytearray_id_, double_, long_, text_, text2_
FROM act_hi_varinst
WHERE proc_inst_id_ = proc_inst_id;

INSERT INTO act_ru_identitylink
SELECT (SELECT cast(max(cast(id_ as int)) + 3 as character varying (64)) FROM act_ru_identitylink),
1, 'ProjectLeader', 'candidate', null, (SELECT id_ FROM act_ru_task WHERE proc_inst_id_ = proc_inst_id), null, null;
return true;
END;
$$;
select setClosedProcessToManagerReview(proc_inst_id_, 'documentupload:3:220008') from act_hi_procinst
WHERE end_time_ is not null AND end_act_id_ = 'a6goodocrfinish' AND delete_reason_ is null;

Outcomes