Search in sources :

Example 1 with User

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

the class UserAdapter method map.

/**
 * Maps user.
 *
 * @param apiUser
 *            user to map.
 * @return mapped user.
 */
public static User map(UserInfoResp apiUser) {
    if (apiUser == null) {
        return null;
    }
    final User user = new User(apiUser.getId(), apiUser.getAccountId(), apiUser.getGroups(), toStatus(apiUser.getStatus()), TranslationUtils.toBool(apiUser.isEmailVerified(), false), TranslationUtils.toDate(apiUser.getCreatedAt()), TranslationUtils.toTimeStamp(apiUser.getCreationTime()), TranslationUtils.toTimeStamp(apiUser.getPasswordChangedTime()), TranslationUtils.toTimeStamp(apiUser.getLastLoginTime()), TranslationUtils.toBool(apiUser.isIsTotpEnabled(), false), LoginHistoryAdapter.mapList(apiUser.getLoginHistory()));
    user.setFullName(apiUser.getFullName());
    user.setUsername(apiUser.getUsername());
    user.setPassword(apiUser.getPassword());
    user.setEmail(apiUser.getEmail());
    user.setPhoneNumber(apiUser.getPhoneNumber());
    user.setAddress(apiUser.getAddress());
    user.setTermsAccepted(TranslationUtils.toBool(apiUser.isIsGtcAccepted(), true));
    user.setMarketingAccepted(TranslationUtils.toBool(apiUser.isIsMarketingAccepted(), true));
    user.setCustomProperties(apiUser.getUserProperties());
    return user;
}
Also used : User(com.arm.mbed.cloud.sdk.accountmanagement.model.User)

Example 2 with User

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

the class AccountManagement method updateUser.

/**
 * Updates a user.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     User user = new User();
 *     String userId = "015f4ac587f500000000000100109294";
 *     user.setId(userId);
 *     user.setEmail("javaSDK@arm.com");
 *     user.setUsername("javaSDK");
 *     user.setFullName("New JavaSDK");
 *
 *     User newUser = accountManagementApi.updateUser(user);
 *     System.out.println("New User name: " + newUser.getFullName());
 *     assert userId == newUser.getId();
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param user
 *            User to update.
 * @return updated user.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public User updateUser(@NonNull User user) throws MbedCloudException {
    checkNotNull(user, TAG_USER);
    checkNotNull(user.getId(), TAG_USER_UUID);
    // checkModelValidity(user, TAG_USER);
    User updatedUser = null;
    if (user.hasEmailBeenUpdated()) {
        updatedUser = user;
    } else {
        updatedUser = user.clone();
        updatedUser.setEmail(null);
    }
    final User finalUser = updatedUser;
    return CloudCaller.call(this, "updateUser()", UserAdapter.getMapper(), new CloudCall<UserInfoResp>() {

        @Override
        public Call<UserInfoResp> call() {
            return endpoint.getAdmin().updateUser(finalUser.getId(), UserAdapter.reverseMapUpdate(finalUser));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.UserInfoResp) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 3 with User

use of com.arm.mbed.cloud.sdk.accountmanagement.model.User 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)

Example 4 with User

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

the class AccountManagement method addUser.

/**
 * Adds a user.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     User user = new User();
 *     user.setEmail("javaSDK@arm.com");
 *     user.setUsername("javaSDK");
 *     user.setFullName("Java SDK");
 *
 *     User newUser = accountManagementApi.addUser(user);
 *     System.out.println("User ID: " + newUser.getId());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param user
 *            User to add.
 * @return added user.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@NonNull
public User addUser(@NonNull User user) throws MbedCloudException {
    checkNotNull(user, TAG_USER);
    checkModelValidity(user, TAG_USER);
    final User finalUser = user;
    return CloudCaller.call(this, "addUser()", UserAdapter.getMapper(), new CloudCall<UserInfoResp>() {

        @Override
        public Call<UserInfoResp> call() {
            return endpoint.getAdmin().createUser(UserAdapter.reverseMapAdd(finalUser), "create");
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.UserInfoResp) NonNull(com.arm.mbed.cloud.sdk.annotations.NonNull) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 5 with User

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

the class AccountManagementExamples method listUsers.

/**
 * Lists the first 5 active users.
 */
@SuppressWarnings("boxing")
@Example
public void listUsers() {
    ConnectionOptions config = Configuration.get();
    AccountManagement api = new AccountManagement(config);
    try {
        // Defining query options
        UserListOptions options = new UserListOptions();
        options.setLimit(5);
        // Listing users.
        Paginator<User> users = api.listAllUsers(options);
        for (User user : users) {
            log("User", user);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Aggregations

User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)5 AccountManagement (com.arm.mbed.cloud.sdk.AccountManagement)2 API (com.arm.mbed.cloud.sdk.annotations.API)2 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)2 ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)2 UserInfoResp (com.arm.mbed.cloud.sdk.internal.iam.model.UserInfoResp)2 Call (retrofit2.Call)2 AbstractExample (utils.AbstractExample)2 Example (utils.Example)2 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 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)1 NonNull (com.arm.mbed.cloud.sdk.annotations.NonNull)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1