Group Accounts
Creating group accounts
The following sample creates a group account record. Also see the section about User Accounts.
Code Snippet
// this sample assumes at least one user account record already exists with the unique key (String) value equal to userUniqueKey protected GroupAccountRepository groupAccountRepository; private String insertGroupAccount() throws Exception { String groupAccountName = "administrators"; GroupAccountCreate groupAccount = new GroupAccountCreate(); //uniqueName is a required field groupAccount.setUniqueName(groupAccountName); //displayName is a required field groupAccount.setDisplayName(groupAccountName); //add users to the group groupAccount.getUserAccountUniqueKeys().add(userUniqueKeys); String uniqueKey = groupAccountRepository.insertGroupAccount(groupAccount); return uniqueKey; } private List<String> userAccountUniqueKeys() { List<String> userUniqueKeys = new List<String>(); userUniqueKeys.add("USER_1005"); userUniqueKeys.add("USER_1009"); userUniqueKeys.add("USER_1041"); return userUniqueKeys; }
Updating group accounts
The following sample updates an existing group account record by changing the display name, changing the description, and removing an existing group member (user account).
Code Snippet
// this sample assumes a group account record already exists with the unique key (String) value equal to uniqueKey protected GroupAccountRepository groupAccountRepository; public void test_updateGroupAccount() throws Exception { GroupAccountUpdate groupUpdate = new GroupAccountUpdate(); //set the uniqueKey with the String value of the target group record to identify which record you are updating groupUpdate.setUniqueKey(uniqueKey); //update the existing display name groupUpdate.setDisplayName("BusinessAdministrators"); //update the existing group description groupUpdate.setDescription("Administrators who manage Admin Settings and TeamConnect user/group accounts"); //remove a user from the group groupUpdate.getUserAccountDeleteUniqueKeys().add(userUniqueKeys); groupAccountRepository.updateGroupAccount(groupUpdate); } private List<String> userAccountUniqueKeys() { List<String> userUniqueKeys = new List<String>(); userUniqueKeys.add("USER_1005"); return userUniqueKeys; }
Reading group accounts
The following sample reads the specified properties of a group account record. All available properties of a group account are listed but you can comment out or remove unnecessary properties in your application to improve performance.
Code Snippet
//define the list of group account record properties to return with the readGroupAccount results protected GroupAccountRepository groupAccountRepository; private List<String> getProperties() { List<String> properties = new List<String>(); properties.add("uniqueName"); properties.add("displayName"); properties.add("description"); properties.add("createdBy"); properties.add("createdOn"); properties.add("modifiedBy"); properties.add("modifiedOn"); properties.add("users"); return properties; } public GroupAccount test_readGroupAccount() throws Exception { //it is assumed that a group account record exists with the unique key equal to String, uniqueKey GroupAccount searchedGroup = groupAccountRepository.readGroupAccount(uniqueKey, getProperties()); return searchedGroup; }
Searching group accounts
The following sample searches groups by given search criteria and returns the specified properties of the resulting group account records.
Code Snippet
protected GroupAccountRepository groupAccountRepository; private List<GroupAccount> test_readGroupAccountsByCriteria() throws Exception { // Criterion for group account searching UserFieldCriterion fieldCriterion = new UserFieldCriterion(); fieldCriterion.setComparator(UserComparator.ONE_OF); LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression(); fieldPathExpression.setSearchKeyPath("createdBy"); fieldCriterion.setFieldPath(fieldPathExpression); fieldCriterion.getValues().add("JohnDoe"); FieldSearchClause searchCriteria = new FieldSearchClause(); searchCriteria.setOperator(LogicOperator.AND); searchCriteria.getCriteria().add(fieldCriterion); groups = groupAccountRepository.readGroupAccountsByCriteria(searchCriteria, 100, getPropertiesToRead()); } private List<String> getProperties() { List<String> properties = new List<String>(); properties.add("uniqueName"); properties.add("displayName"); properties.add("description"); properties.add("createdBy"); properties.add("createdOn"); properties.add("modifiedBy"); properties.add("modifiedOn"); properties.add("users"); return properties; }
Deleting group accounts
The following sample deletes a group account record with a given unique key.
Note: Deleting a group removes users from the group; however the user accounts are not deleted from the system. Also see the Administrator help, Deleting a Group, topic for Scenarios that Prevent Deletion.
Code Snippet
//for this sample it is assumed that a group record exists with a unique key String equal to uniqueKey protected GroupAccountRepository groupAccountRepository; public void test_deleteGroupAccount() throws Exception { groupAccountRepository.deleteGroupAccount(uniqueKey); }