10-09-2017 04:51 PM
I have been researching and found out that this is the best way to current usr info from activiti DB. However, it comes out to be null.
This is my code..
First, I get userID
List<IdentityLink> identityLink = processEngine.getRuntimeService().getIdentityLinksForProcessInstance(processID);
Iterating through this I get userID
if (identityLink != null){
for (IdentityLink link : identityLink){
userID = link.getUserId();
logger.info("getProjectID: userID ==== is " + userID);
}
}else{
logger.info("getProjectID: userID is NULL ");
}
Now I try to get userinfo, this is null.. Can someone help?
User user = processEngine.getIdentityService().createUserQuery().userId(userID).singleResult();
if (user !=null){
logger.info("FirstName ======= " + user.getFirstName() );
logger.info("LastName ======= " + user.getLastName() );
logger.info("Email ======= " + user.getEmail() );
logger.info("Password ======= " + user.getPassword() );
}else{
logger.info("user is ......................... NULL ");
}
10-11-2017 08:09 PM
Yeah, now it makes sense. When you add an attach file option in the form, the next task will turn async. That means it is no longer executed under the logged in user context! Hence you get null. Try executing your logic from an execution listener attached to the start activity or on the sequence flow if you really need the user context. It is not a bug, it is working as designed.
10-11-2017 04:16 PM
That didn't work either.. Maybe I have to call it from service task..
10-11-2017 04:21 PM
I mean script task
10-11-2017 04:23 PM
It would help if you can post all the details such as bpmn file, service java code etc in one post when asking questions. From this post, it is difficult to understand whether you are doing it from a service/script task or even execution/task/event listeners etc. Also, if this is getting executed without a user context (ie, async) you won't have any user info where your bpmn definition will help!
10-11-2017 06:59 PM
of course thanks Ciju.
I think I found a bug in the system.
I am now able to get userinfo through SecurityUtils.getCurrentUserObject(); Only if the form in previous activity (not activiti) does not have a file upload option with Alfresco repo enabled.
So i have a form on start event which has attach file option and after that i have service task which calls javadelegate and it prints the user info if I don't enable alfresco repo files to be attached.
10-11-2017 07:22 PM
Steps:
1. Create a form with attach file and configure it accept local files and alfresco files.
2. Create a java api or bean .. add code to capture userinfo .. see attachment for example.
3. Create a process with start event -> service task -> end
4. attach form to start event and configure service task to call your java api
5. check the log and you will see that userinfo in null.
Now remove the alfresco option and republish the app and run it again. UserInfo is now available
10-11-2017 08:09 PM
Yeah, now it makes sense. When you add an attach file option in the form, the next task will turn async. That means it is no longer executed under the logged in user context! Hence you get null. Try executing your logic from an execution listener attached to the start activity or on the sequence flow if you really need the user context. It is not a bug, it is working as designed.
Explore our Alfresco products with the links below. Use labels to filter content by product module.