Skip to main content
Mitratech Success Center

Client Support Center

Need help? Click a product group below to select your application and get access to knowledge articles, webinars, training content, and release notes or to contact our support team.

Authorized users - log in to create a ticket, view tickets status and check your success plan details.

 

User Accounts

The following .JAVA code samples show how you can use TeamConnect® Enterprise Web Services for functions related to user records.

Creating user accounts

The following sample creates a user account record. Prerequisite to working with user records, a corresponding contact (type person) record must already exist in TeamConnect  In addition, you need to get the following information before writing an application using Web Services: the unique key of the related contact record.

Code Snippet

// this sample assumes a contact record (type person) already exists with the 
unique key (String) value equal to contactUniqueKey
protected UserAccountRepository userAccountRepository; 
private String insertUserAccount() throws Exception {
    String userAccountName = "John_Doe";
    UserAccountCreate userAccount = new UserAccountCreate();
    //username is a required field userAccount.setUsername(userAccountName);
    //password is a required field userAccount.setPassword("p@ssw0rd");
    //contactUniqueKey is a required field userAccount.setContactUniqueKey(contactUniqueKey);
    userAccount.setShortDescription("new user hired 10/01/2008, business administrator");
    userAccount.setUserType(UserType.NORMAL); 
    userAccount.setActive(true);
    String uniqueKey = userAccountRepository.insertUserAccount(userAccount); 
    return uniqueKey;
}

Updating user accounts

The following sample updates an existing user account record by changing the password, changing the user type, and inactivating the user account.

Note: In actual business usage, if you are inactivating a user account, it is unlikely you would need to change other properties but the samples are provided for you to use as necessary.

Code Snippet

// this sample assumes a user record already exists with the unique key 
(String) value equal to uniqueKey
protected UserAccountRepository userAccountRepository; 
public void test_updateUserAccount() throws Exception {
    UserAccountUpdate userUpdate = new UserAccountUpdate();
    //set the uniqueKey with the String value of the target user record 
    to identify which record you are updating
    userUpdate.setUniqueKey(uniqueKey);
    //update the existing password userUpdate.setPassword("newP@ssw0rd");
    //update the existing userType userUpdate.setUserType(UserType.LIMITED);
    //inactive the user account userUpdate.setActive(false); 
    userAccountRepository.updateUserAccount(userUpdate);
}

Reading user accounts

The following sample reads the specified properties of a user account record.

Code Snippet

//define the list of user record properties to return with the readUserAccount results
protected UserAccountRepository userAccountRepository;
private List<String> getProperties() { 
    List<String> properties = new List<String>(); 
    properties.add("username"); 
    properties.add("active"); 
    properties.add("password"); 
    properties.add("contact"); 
    properties.add("shortDescription"); 
    properties.add("uniqueKey"); 
    properties.add("userType");
    return properties;
}
    public UserAccount test_readUserAccount() throws Exception {
    //it is assumed that a user record exists with the unique key equal to String, uniqueKey
    UserAccount searchedUser = userAccountRepository.readUserAccount(uniqueKey, getProperties());
    return searchedUser;
}

Searching user accounts

The following sample searches users by given search criteria and returns the specified properties of the resulting user account records.

Code Snippet

protected UserAccountRepository userAccountRepository;
private List<UserAccount> test_readUserAccountsByCriteria() throws Exception {
    // Criterion for user account searching
    StringFieldCriterion fieldCriterion = new StringFieldCriterion(); 
    fieldCriterion.setComparator(StringComparator.EQUALS_ENFORCE_CASE);
    LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression();
    fieldPathExpression.setSearchKeyPath("username"); 
    fieldCriterion.setFieldPath(fieldPathExpression); 
    fieldCriterion.getValue().add("JohnDoe");
    FieldSearchClause searchCriteria = new FieldSearchClause(); 
    searchCriteria.setOperator(LogicOperator.AND); 
    searchCriteria.getCriteria().add(fieldCriterion);
    users = userAccountRepository.readUserAccountsByCriteria(searchCriteria, 100, 
    getPropertiesToRead());
}
private List<String> getProperties() { 
    List<String> properties = new List<String>(); 
    properties.add("username"); 
    properties.add("active");
    properties.add("password");
    properties.add("contact"); 
    properties.add("shortDescription"); 
    properties.add("uniqueKey"); 
    properties.add("userType");
    return properties;
}

Deleting user accounts

The following sample deletes a user account record with a given unique key.

Code Snippet

//for this sample it is assumed that a user record exists with a unique key String equal to uniqueKey
protected UserAccountRepository userAccountRepository; 
public void test_deleteUserAccount() throws Exception {
    userAccountRepository.deleteUserAccount(uniqueKey);
}
  • Was this article helpful?