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;
}
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));
}
});
}
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());
}
}
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");
}
});
}
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());
}
}
Aggregations