Skip to content

Commit

Permalink
Merged PR 1193: [CC v2.1]remove default keyword and return empty list
Browse files Browse the repository at this point in the history
**Issue** : Expecting empty list and getting null(default) in return.

**Fix** : Replace default keyword with empty list.
  • Loading branch information
Priyank Saxena authored and aosolis committed Oct 16, 2020
1 parent d94ee82 commit df98105
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private async Task<IEnumerable<Group>> AddDistributionGroupAsync(string query, i
{
if (resultCount == 0)
{
return default;
return new List<Group>();
}

string filterforDL = $"mailEnabled eq true and (startsWith(mail,'{query}') or startsWith(displayName,'{query}'))";
Expand Down Expand Up @@ -151,7 +151,7 @@ private async Task<IEnumerable<Group>> AddSecurityGroupAsync(string query, int r
{
if (resultCount == 0)
{
return default;
return new List<Group>();
}

string filterforSG = $"mailEnabled eq false and securityEnabled eq true and startsWith(displayName,'{query}')";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.MicrosoftGrap
using System.Text;
using System.Threading.Tasks;
using Microsoft.Graph;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
Expand Down Expand Up @@ -38,27 +37,20 @@ public UsersService(IGraphServiceClient graphServiceClient)
/// <returns>list of users.</returns>
public async Task<IEnumerable<User>> FilterByUserIdsAsync(IEnumerable<string> userIds)
{
try
if (userIds.Count() < 1)
{
if (userIds.Count() < 1)
{
return default;
}

var filterUserIds = this.GetUserIdFilter(userIds);
var userList = new List<User>();
var usersStream = this.GetUsersAsync(filterUserIds.ToString());
await foreach (var users in usersStream)
{
userList.AddRange(users);
}

return userList;
return new List<User>();
}
catch

var filterUserIds = this.GetUserIdFilter(userIds);
var userList = new List<User>();
var usersStream = this.GetUsersAsync(filterUserIds.ToString());
await foreach (var users in usersStream)
{
return default;
userList.AddRange(users);
}

return userList;
}

/// <summary>
Expand All @@ -68,46 +60,34 @@ public async Task<IEnumerable<User>> FilterByUserIdsAsync(IEnumerable<string> us
/// <returns>list of users.</returns>
public async Task<IEnumerable<User>> GetBatchByUserIds(IEnumerable<IEnumerable<string>> userIdsByGroups)
{
if (userIdsByGroups.Count() < 1)
var users = new List<User>();
var batches = this.GetBatchRequest(userIdsByGroups);
foreach (var batchRequestContent in batches)
{
return default;
}

try
{
var users = new List<User>();
var batches = this.GetBatchRequest(userIdsByGroups);
foreach (var batchRequestContent in batches)
{
var response = await this.graphServiceClient
.Batch
.Request()
.WithMaxRetry(this.MaxRetry)
.PostAsync(batchRequestContent);
var response = await this.graphServiceClient
.Batch
.Request()
.WithMaxRetry(this.MaxRetry)
.PostAsync(batchRequestContent);

Dictionary<string, HttpResponseMessage> responses = await response.GetResponsesAsync();
Dictionary<string, HttpResponseMessage> responses = await response.GetResponsesAsync();

foreach (string key in responses.Keys)
{
HttpResponseMessage httpResponse = await response.GetResponseByIdAsync(key);
httpResponse.EnsureSuccessStatusCode();

var responseContent = await httpResponse.Content.ReadAsStringAsync();
JObject content = JObject.Parse(responseContent);
var userstemp = content["value"]
.Children()
.OfType<JObject>()
.Select(obj => obj.ToObject<User>());
users.AddRange(userstemp);
}
foreach (string key in responses.Keys)
{
HttpResponseMessage httpResponse = await response.GetResponseByIdAsync(key);
httpResponse.EnsureSuccessStatusCode();

var responseContent = await httpResponse.Content.ReadAsStringAsync();
JObject content = JObject.Parse(responseContent);
var userstemp = content["value"]
.Children()
.OfType<JObject>()
.Select(obj => obj.ToObject<User>());
users.AddRange(userstemp);
}

return users;
}
catch
{
return default;
}

return users;
}

/// <summary>
Expand Down Expand Up @@ -144,25 +124,18 @@ public async IAsyncEnumerable<IEnumerable<User>> GetUsersAsync(string filter = n
/// <returns>user data.</returns>
public async Task<User> GetUserAsync(string userId)
{
try
{
var graphResult = await this.graphServiceClient
.Users[userId]
.Request()
.WithMaxRetry(this.MaxRetry)
.Select(user => new
{
user.Id,
user.DisplayName,
user.UserPrincipalName,
})
.GetAsync();
return graphResult;
}
catch
{
return default;
}
var graphResult = await this.graphServiceClient
.Users[userId]
.Request()
.WithMaxRetry(this.MaxRetry)
.Select(user => new
{
user.Id,
user.DisplayName,
user.UserPrincipalName,
})
.GetAsync();
return graphResult;
}

private string GetUserIdFilter(IEnumerable<string> userIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Microsoft.Teams.Apps.CompanyCommunicator.Prep.Func.Export.Activities
{
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
using Microsoft.Graph;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Repositories.ExportData;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Repositories.NotificationData;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.MicrosoftGraph;
Expand Down Expand Up @@ -58,11 +60,22 @@ public async Task<MetaData> RunAsync(
/// <returns>instance of metadata.</returns>
[FunctionName(nameof(GetMetaDataActivityAsync))]
public async Task<MetaData> GetMetaDataActivityAsync(
[ActivityTrigger](
NotificationDataEntity notificationDataEntity,
[ActivityTrigger](NotificationDataEntity notificationDataEntity,
ExportDataEntity exportDataEntity) exportRequiredData)
{
var user = await this.usersService.GetUserAsync(exportRequiredData.exportDataEntity.PartitionKey);
User user = default;
try
{
user = await this.usersService.GetUserAsync(exportRequiredData.exportDataEntity.PartitionKey);
}
catch (ServiceException serviceException)
{
if (serviceException.StatusCode != HttpStatusCode.Forbidden)
{
throw serviceException;
}
}

var userPrincipalName = (user != null) ?
user.UserPrincipalName :
Common.Constants.AdminConsentError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Microsoft.Teams.Apps.CompanyCommunicator.Prep.Func.Export.Streams
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.Graph;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Repositories.SentNotificationData;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Repositories.TeamData;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.MicrosoftGraph;
Expand Down Expand Up @@ -48,14 +50,27 @@ public async IAsyncEnumerable<IEnumerable<UserData>> GetUserDataStreamAsync(stri
var sentNotificationDataEntitiesStream = this.sentNotificationDataRepository.GetStreamsAsync(notificationId);
await foreach (var sentNotifcations in sentNotificationDataEntitiesStream)
{
// filter the recipient not found users.
var users = await this.usersService.GetBatchByUserIds(
sentNotifcations
.Where(sentNotifcation => !sentNotifcation.DeliveryStatus.Equals(SentNotificationDataEntity.RecipientNotFound, StringComparison.CurrentCultureIgnoreCase))
.Select(notitification => notitification.RowKey)
.ToList()
.AsGroups());
yield return sentNotifcations.CreateUserData(users);
List<User> userList = new List<User>();
try
{
// filter the recipient not found users.
var users = await this.usersService.GetBatchByUserIds(
sentNotifcations
.Where(sentNotifcation => !sentNotifcation.DeliveryStatus.Equals(SentNotificationDataEntity.RecipientNotFound, StringComparison.CurrentCultureIgnoreCase))
.Select(notitification => notitification.RowKey)
.ToList()
.AsGroups());
userList = users.ToList();
}
catch (ServiceException serviceException)
{
if (serviceException.StatusCode != HttpStatusCode.Forbidden)
{
throw serviceException;
}
}

yield return sentNotifcations.CreateUserData(userList);
}
}

Expand Down

0 comments on commit df98105

Please sign in to comment.