cancel
Showing results for 
Search instead for 
Did you mean: 

ProcessDefinition identitylink roles aside from candidate

nhmarsh
Champ in-the-making
Champ in-the-making
Hi all,

We're developing a workflow project with Activiti as our backbone, and one of the requirements we've received on the side of Process Definitions is to ensure we know which user deployed a process definition. Natively, activiti does not seem to support this, so it seemed reasonable to create an IdentityLink entry linking that processdefinition ID to the user, with the TYPE_ field equal to"owner". Once again, this does not seem to be supported natively in the API, so I wrote some simple test code:


      IdentityLinkEntity newEntity = new IdentityLinkEntity();
      
      newEntity.setProcessDefId(processDef.getId());
      newEntity.setType(OWNER);
      newEntity.setUserId(user.getUserId());
      newEntity.setId(UUID.randomUUID().toString());
      newEntity.insert();



Our process engine is set up using spring:

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="processEngineName" value="processEngine"/>  
      <property name="dataSource" ref="dataSource1" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="false" />
      <property name="jobExecutorActivate" value="false" />
      <property name="databaseSchema" value="WORKFLOW_POC1" />
   </bean>

However, the call to newEntity.insert() yields a nullpointer exception for this line of code within IdentityLinkEntity.java:


    Context
      .getCommandContext()
      .getDbSqlSession()
      .insert(this);


Specifically, the first line, Context.getCommandContext(). Upon further investigation, Context is indeed null.

So my question is - is there specific setup I'll need to do to get this call to work? Or is there an alternative approach that anybody can suggest, either for this method of creating an audit trail that can be traced to users, or any other method?

Thanks!
4 REPLIES 4

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Command context can be obtained from command. You can create create your own command. Good example could be

org.activiti.engine.impl.cmd.AddIdentityLinkForProcessDefinitionCmd
Regards
Martin
e.g

nhmarsh
Champ in-the-making
Champ in-the-making
This did not seem to work. Here is the code I used:

where "configuration" is our spring-specified ProcessEngineConfigurationImpl

<java>
 
  IdentityLinkEntity newEntity = new IdentityLinkEntity();

  newEntity.setProcessDefId(processDef.getId());
  newEntity.setType("owner");
  newEntity.setUserId("ownerUser");
  AddIdentityLinkForProcessDefinitionCmd newCmd = new AddIdentityLinkForProcessDefinitionCmd(processDef.getId(), "ownerUser", null);

  CommandContext context = new CommandContext(newCmd, (ProcessEngineConfigurationImpl) processEngineConfiguration);
  Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration);
  Context.setCommandContext(context);
  newEntity.insert();
</java>


Does not create the expected entity. Is there something else I need to set up, or check? I'm using the same processConfigurationEngine that we use to generate our service.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

try:

processEngineConfigurationImpl.getCommandExecutor().execute(new Command<Void>() {

      @Override
      public Void execute(CommandContext commandContext) {
        IdentityLinkEntity newEntity = new IdentityLinkEntity();

        newEntity.setProcessDefId(pi.getProcessDefinitionId());
        newEntity.setType(OWNER);
        newEntity.setUserId(user.getUserId());       
        newEntity.setId(UUID.randomUUID().toString());
        newEntity.insert();
        return null;
      }
    });

Regards
Martin

nhmarsh
Champ in-the-making
Champ in-the-making
That worked! Thanks much!