Search in sources :

Example 1 with GroupListOptions

use of com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagementExamples method listGroups.

/**
 * Lists the last 5 groups and their contents.
 */
@SuppressWarnings("boxing")
@Example
public void listGroups() {
    ConnectionOptions config = Configuration.get();
    AccountManagement api = new AccountManagement(config);
    try {
        // Defining query options
        GroupListOptions options = new GroupListOptions();
        options.setLimit(5);
        options.setOrder(Order.DESC);
        // Listing groups.
        ListResponse<Group> groups = api.listGroups(options);
        for (Group group : groups.getData()) {
            log("Group", group);
            Paginator<ApiKey> apiKeyIterator = api.listAllGroupApiKeys(group.getId(), null);
            while (apiKeyIterator.hasNext()) {
                log("API key of group [" + group.getId() + "]", apiKeyIterator.next());
            }
            Paginator<User> userIterator = api.listAllGroupUsers(group.getId(), null);
            while (userIterator.hasNext()) {
                log("User of group [" + group.getId() + "]", userIterator.next());
            }
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : Group(com.arm.mbed.cloud.sdk.accountmanagement.model.Group) ApiKey(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey) User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) GroupListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Aggregations

AccountManagement (com.arm.mbed.cloud.sdk.AccountManagement)1 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)1 Group (com.arm.mbed.cloud.sdk.accountmanagement.model.Group)1 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)1 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)1 ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)1 AbstractExample (utils.AbstractExample)1 Example (utils.Example)1