站長留言

  • ✅ 本站維護及更新歷史紀錄,詳情請參考公告
  • ✅ 有任何意見、想法,歡迎留言給Spicy知道喔
  • ✅ 固定於每周一至周五更新Blogger文章,周末不定期
程式Bonita BPM

【Bonita BPM】如何取得Organization中的成員

tags: Bonita BPM

Common 基礎知識

  1. Organization的架構:organization - groups - roles - users
  2. 參考下圖,可以發現每個user都有自己的grouprole
    Imgur Image
  3. 可能會用到的import
import org.bonitasoft.engine.api.IdentityAPI
import org.bonitasoft.engine.identity.Group
import org.bonitasoft.engine.identity.Role
import org.bonitasoft.engine.identity.User
import org.bonitasoft.engine.identity.UserCriterion    

取得GroupName List

  1. example code的Group為複數
  2. 若只有1個Group可自行精簡code
def list = []
def groupPathList = ['/ServiceDepartment', '/SystemDepartment']
IdentityAPI identityAPI = apiAccessor.identityAPI
Group group = null

for(String groupPath : groupPathList) {
    group = identityAPI.getGroupByPath(groupPath)
    list.add('{"display":"' + group.getDisplayName() + '","id":' + group.getId() + '}')
}

return list

取得UserName List

  1. Group 取得 userList (example code為複數)
def list = []
def groupPathList = ['/ServiceDepartment', '/SystemDepartment']
IdentityAPI identityAPI = apiAccessor.identityAPI
List<User> userList = null
Group group = null

for(String groupPath : groupPathList) {
    group = identityAPI.getGroupByPath(groupPath)
    userList = identityAPI.getUsersInGroup(group.getId(), 0, Integer.MAX_VALUE, UserCriterion.USER_NAME_ASC)
    for(User user : userList) {		
        list.add('{"display":"' + user.getUserName() + '","department_id":' + group.getId() + '}')
    }
}

return list
  1. Role 取得 userList (example code為1個)
    同理,將group的部分改成role和role的method即可
def list = []
IdentityAPI identityAPI = apiAccessor.identityAPI
List<User> userList = null
Role role = null

role = identityAPI.getRoleByName('Director')
userList = identityAPI.getUsersInRole(role.getId(), 0, Integer.MAX_VALUE, UserCriterion.USER_NAME_ASC)
for(User user : userList) {	
    list.add('{"display":"' + user.getUserName() + '","department_id":' + role.getId() + '}')
}

return list
  1. 補充:不取 UserName,改取 LastName + FirstName
StringBuilder userNameBuilder = new StringBuilder()
if(user.getLastName() != null) {
    userNameBuilder.append(user.getLastName())
}
if(user.getFirstName() != null) {
    userNameBuilder.append(user.getFirstName())
}
list.add('{"display":"' + userNameBuilder.toString() + '}')

取得SingleUser Id

  1. 使用狀況:當Actors需要設定Actor filter為Single user

  2. 我們可以稍微修改上面的code,來達到我們需求

  3. for迴圈中,加入if判斷式去比對資料 userName

  4. 承3,也可以用while寫寫看

  5. 同理,也可以從role中篩選出Single user

long id

IdentityAPI identityAPI = apiAccessor.identityAPI
List<User> userList = null
Group group = null

group = identityAPI.getGroupByPath('/ServiceDepartment')
userList = identityAPI.getUsersInGroup(group.getId(), 0, Integer.MAX_VALUE, UserCriterion.USER_NAME_ASC)
for(User user : userList) {
    if(user.getUserName().equals("example")) {
        id = user.getId()
    }
}

return id

連結:【Bonita BPM】使用 identityAPI

沒有留言:

張貼留言

本網站建議使用電腦或平板瀏覽