[jboss-user] [jBPM] - [jBPM4.4] custom activity has an end time before this activity is leaveds the activity

saig0 do-not-reply at jboss.com
Thu Apr 14 07:24:24 EDT 2011


saig0 [http://community.jboss.org/people/saig0] created the discussion

"[jBPM4.4] custom activity has an end time before this activity is leaveds the activity"

To view the discussion, visit: http://community.jboss.org/message/600020#600020

--------------------------------------------------------------
Hi,

I note that a custom activity has an end time before this activity is leaved. 

process:

<?xml version="1.0" encoding="UTF-8"?>


<process name="HistoryServiceTest" xmlns="http://jbpm.org/4.4/jpdl">
          <start name="start" g="77,144,48,48">
                    <transition to="custom-state" />
          </start>
          <custom name="custom-state" g="175,140,105,52" class="processes.classes.SimpleCustomState">
                    <transition to="end" />
          </custom>
          <end name="end" g="324,144,48,48" />
</process>



SimpleCustomState.java:

package processes.classes; 
 
import java.util.Map; 
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.activity.ExternalActivityBehaviour; 
 
public class SimpleCustomState implements ExternalActivityBehaviour
{
    private static final long serialVersionUID = 1L;
 
    public void execute(ActivityExecution execution) throws Exception    {
        execution.waitForSignal();
    }
 
    public void signal(ActivityExecution execution, String signalName, Map<String, ?> parameters)
            throws Exception    {
        execution.takeDefaultTransition();
    }
 
}
 


test:

package services; 
 
import org.junit.Assert.*;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipInputStream;  
import org.jbpm.api.*;
import org.junit.*; 
 
public class HistoryServiceTest
{ 
    private HistoryService    historyService;
    private ExecutionService  executionService;
    private RepositoryService repositoryService;
 
    @Before
    public void setup()    {
        initEngine();
        deployProcess();
    }
 
    public void initEngine()    {
        ProcessEngine processEngine = new Configuration().setResource("default.jbpm.cfg.xml")
                .buildProcessEngine();
        executionService = processEngine.getExecutionService();
        historyService = processEngine.getHistoryService();
        repositoryService = processEngine.getRepositoryService();
    }
 
    public void deployProcess()    {
        ZipInputStream zipInputStream = new ZipInputStream(getClass().getResourceAsStream("/jbpm.zip"));
        repositoryService.createDeployment().addResourcesFromZipInputStream(zipInputStream).setName("test")
                .setTimestamp(new Date().getTime()).deploy();
    }
 
    public String startProcess()    {
        ProcessInstance processInstance = executionService.startProcessInstanceByKey("HistoryServiceTest");
        return processInstance.getId();
    }
 
    private boolean isRunning(String processInstanceId)    {
        ProcessInstance pi = executionService.findProcessInstanceById(processInstanceId);
        return pi != null ? pi.isEnded() : false;
    }
 
    @Test
    public void testHasEndDateForEndedCustomActivity()    {
        String processInstanceId = startProcess();
        String activityName = "custom-state";
        assertTrue(executionService.findProcessInstanceById(processInstanceId).isActive(activityName));
 
 
        executionService.signalExecutionById(processInstanceId, "");
        assertFalse(isRunning(processInstanceId));
 
 
        HistoryActivityInstance historyActivityInstance = historyService.createHistoryActivityInstanceQuery()
                .processInstanceId(processInstanceId).activityName(activityName).uniqueResult();
        assertNotNull(historyActivityInstance.getEndTime());
    }
 
    @Test
    public void testHasNoEndDateForActiveCustomActivity()    {
        String processInstanceId = startProcess();
        String activityName = "custom-state";
        assertTrue(executionService.findProcessInstanceById(processInstanceId).isActive(activityName));
 
 
        List<HistoryActivityInstance> historyActivityInstances = historyService
                .createHistoryActivityInstanceQuery().processInstanceId(processInstanceId)
                .activityName(activityName).list();
        if (!historyActivityInstances.isEmpty())
        {
            for (HistoryActivityInstance historyActivityInstance : historyActivityInstances)
                assertNull(historyActivityInstance.getEndTime()); // this fail!
        }
    }
}


After I looking for a reason, I found something in class UserCodeActivityBehaviour:

public void execute(ActivityExecution execution) throws Exception {
    ActivityBehaviour activityBehaviour = (ActivityBehaviour) customActivityReference.getObject(execution);
    activityBehaviour.execute(execution);
    ((ExecutionImpl)execution).historyAutomatic();
  }


This methode create a object of class HistoryActivityInstanceImpl and call:

public HistoryAutomaticInstanceImpl(HistoryProcessInstance historyProcessInstanceImpl, ExecutionImpl execution) {
    super(historyProcessInstanceImpl, execution);
    setEndTime(Clock.getTime());
  }


Now I want to ask why this was not implemented like in class StateActivity?
And how to fix this bug?
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/600020#600020]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110414/ae83dee4/attachment.html 


More information about the jboss-user mailing list