tags: Bonita BPM
Common 基礎知識
- Organization的架構:organization - groups - roles - users
- 參考下圖,可以發現每個user都有自己的group和role
- 可能會用到的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
- example code的Group為複數
- 若只有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
- 從 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
- 從 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
- 補充:不取 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
-
使用狀況:當Actors需要設定Actor filter為Single user
-
我們可以稍微修改上面的code,來達到我們需求
-
於for迴圈中,加入if判斷式去比對資料 userName
-
承3,也可以用while寫寫看
-
同理,也可以從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
沒有留言:
張貼留言