Hi All,
Appreciate your comments here.
Use case: get the users from aem group then send the mails..
This code is written in aem custom workflow.
Working fine : when click on asset and initiate custom workflow . I am getting group and able to get users.
Not working case : when adding asset to folder and using luncher/event handler initiate the custom workflow. In this case below group is coming null
JackrabbitSession jrSession=(JackrabbitSession) session;
UserManager userManager=jrSession.getUserManager();
Group group = (Group) userManager.getAuthorizable("GroupId");
log.info("group >>> "+group);
final Iterator<Authorizable> memberslist = group.getMembers();
while (memberslist.hasNext()) {
final Authorizable user = memberslist.next();
if (user != null && !user.isGroup() && user.getProperty("./profile/email") != null) {
//EMAIL ADDRESS FOR MEMBERS
Value[] usrEmail = user.getProperty("./profile/email");
for(Value emailGroup : usrEmail) {
log.info("emailGroup line 152>>> "+emailGroup);
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
@chetan001 : Are you using any system user for the workflow? If you are already using then you can provide the permission on that user for the folders which is required for the workflow. Please check this.
Thank You.
Keshav Chaurasiya
@chetan001 : Are you using any system user for the workflow? If you are already using then you can provide the permission on that user for the folders which is required for the workflow. Please check this.
Thank You.
Keshav Chaurasiya
Hi @chetan001,
From the code snippet you have shared, suggest to make below changes
UserManager :
ResourceResolver rescResolver = wfSession.adaptTo(ResourceResolver.class);
UserManager userManager = rescResolver.adaptTo(UserManager.class);
@Reference
private ResourceResolverFactory resFactory;
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "demoService");
ResourceResolver rescResolver = null;
try {
rescResolver = resFactory.getServiceResourceResolver(param);
} catch (LoginException e) {
LOG.error("Login Exception={}", e.getMessage());
}
Authorizable First: (Check if authorizable is a group or no)
String userOrGroupId = "admin";
try {
Authorizable authorizable = userManagerResc.getAuthorizable(userOrGroupId);
if (authorizable.isGroup()) {
LOG.info("Id is a group");
Group userGroup = (Group) authorizable;
Iterator<Authorizable> declaredMembers = userGroup.getDeclaredMembers();
while (declaredMembers.hasNext()) {
declaredMembers.next();
}
}
else{
LOG.info("It is a user !!");
}
} catch (RepositoryException e) {
e.printStackTrace();
}
Views
Likes
Replies
Views
Likes
Replies