use of com.microsoft.graph.concurrency.ICallback in project android-java-snippets-sample by microsoftgraph.
the class UsersSnippets method getUsersSnippets.
static UsersSnippets[] getUsersSnippets() {
return new UsersSnippets[] { // Marker element
new UsersSnippets(null) {
@Override
public void request(ICallback callback) {
// Not implemented
}
}, /*
* Gets all of the users in your tenant\'s directory.
* HTTP GET https://graph.microsoft.com/{version}/myOrganization/users
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_list
*/
new UsersSnippets<JsonObject>(get_organization_users) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient.getUsers().buildRequest().get(new ICallback<IUserCollectionPage>() {
@Override
public void success(IUserCollectionPage iUserCollectionPage) {
callback.success(iUserCollectionPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /*
* Gets all of the users in your tenant's directory who are from the United States, using $filter.
* HTTP GET https://graph.microsoft.com/{version}/myOrganization/users?$filter=country eq \'United States\'
* @see http://graph.microsoft.io/docs/overview/query_parameters
*/
new UsersSnippets<JsonObject>(get_organization_filtered_users) {
@Override
public void request(final ICallback<JsonObject> callback) {
final List<Option> options = new LinkedList<>();
options.add(new QueryOption("$filter", "country eq 'United States'"));
mGraphServiceClient.getUsers().buildRequest(options).get(new ICallback<IUserCollectionPage>() {
@Override
public void success(IUserCollectionPage iUserCollectionPage) {
callback.success(iUserCollectionPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /*
* Adds a new user to the tenant's directory
* HTTP POST https://graph.microsoft.com/{version}/myOrganization/users
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_users
*/
new UsersSnippets<JsonObject>(insert_organization_user) {
@Override
public void request(final ICallback<JsonObject> callback) {
// Use a random UUID for the user name
String randomUserName = UUID.randomUUID().toString();
// create the user
User user = new User();
user.accountEnabled = true;
user.displayName = "SAMPLE " + randomUserName;
user.mailNickname = randomUserName;
// get the tenant from preferences
SharedPreferences prefs = SharedPrefsUtil.getSharedPreferences();
String tenant = prefs.getString(PREF_USER_TENANT, "");
user.userPrincipalName = randomUserName + "@" + tenant;
// initialize a password & say whether or not the user must change it
PasswordProfile password = new PasswordProfile();
password.password = UUID.randomUUID().toString().substring(0, 16);
password.forceChangePasswordNextSignIn = false;
user.passwordProfile = password;
mGraphServiceClient.getUsers().buildRequest().post(user, new ICallback<User>() {
@Override
public void success(User user) {
callback.success(user.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
} };
}
Aggregations