tags: Bonita BPM
先期知識
- 如何取得Organization中的成員:
http://spicyboyd.blogspot.tw/2017/12/bonita-bpm-organizationuser.html - 使用 identityAPI:
http://spicyboyd.blogspot.tw/2018/01/bonita-bpm-identityapi.html - 取出Group中所有成員的email:http://spicyboyd.blogspot.tw/2018/01/bonita-bpmgroupemail.html
Common 目的
- 在先前文章 <如何取得Organization中的成員> 使用的方式是:
- 透過 Group 或 Role 的 data (例如:id, name, path) 去取得該 Group 或 Role 的成員
- 但是這方法有一個缺點:只能一次找 1個 Group或者 1個 Role的成員
- 因此本篇文章,透過 Filter 的方式,去解決第1點的缺陷
- 可能會用到的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
import org.bonitasoft.engine.identity.UserSearchDescriptor
import org.bonitasoft.engine.search.SearchOptionsBuilder
import org.bonitasoft.engine.search.SearchResult
Code 程式碼
1. 建構子 SearchOptionsBuilder(int startIndex, int maxResults)
- 參數:
- startIndex - the first result to return
- maxResults - the maximum results to return. The actual number can be smaller, if the end of the list has been reached.
- 補充:maxResults 常用
Integer.MAX_VALUE
2. UserSearchDescriptor 常用屬性(field):
- GROUP_ID:filter search on User’s group id
- ROLE_ID:filter search on User’s role id
3. SearchOptionsBuilder的 filter(String field, Serializable value)
- Return Type:SearchOptionsBuilder
- 參數:
- field - the field name to filter,填入第2點的 屬性
- value - the single value to filter on that field name,填入 field 需要的資料
4. IdentityAPI的 searchUsers(SearchOptions options)
- Return Type:SearchResult
- 參數:
- options - The search criteria,常用第5點的方法
5. SearchOptionsBuilder的 done()
- the SearchOptions finally built using this builder.
- Return Type:SearchOptions
6. Example 範例
IdentityAPI identityAPI = apiAccessor.identityAPI
Group group = identityAPI.getGroupByPath('/exampleGroup')
Role role = identityAPI.getRoleByName('exampleRole')
SearchOptionsBuilder optionsBuilder = new SearchOptionsBuilder(0, Integer.MAX_VALUE);
optionsBuilder.filter(UserSearchDescriptor.GROUP_ID, group.getId());
optionsBuilder.filter(UserSearchDescriptor.ROLE_ID, role.getId());
SearchResult<User> resultList = identityAPI.searchUsers(optionsBuilder.done())
List<User> userList = resultList.getResult()
for(User user : userList){
//按照需求,取出user的各種資料(例如:firstName, lastName, userName)
}
7. 結果
- 假設Group
'/exampleGroup'
為'/BeiJing'
,其成員有- operator
- supervisor
- 假設Role
'exampleRole'
為'Supervisor'
,其成員有- executive
- finance
- management
- purchaser
- supervisor1
- supervisor2
- supervisor3
- supervisor
- test
- 以上面兩個假設使用filter,可得最後的成員有:
- supervisor
Reference 參考資料
- SearchOptionsBuilder:https://documentation.bonitasoft.com/javadoc/api/6.0/sp/common/org/bonitasoft/engine/search/SearchOptionsBuilder.html
- UserSearchDescriptor:https://documentation.bonitasoft.com/javadoc/api/7.3/org/bonitasoft/engine/identity/UserSearchDescriptor.html
- UserAPI:https://documentation.bonitasoft.com/javadoc/api/7.0/org/bonitasoft/engine/api/UserAPI.html
沒有留言:
張貼留言