From c5d6107101a46b7187da824cad11380840aa0b94 Mon Sep 17 00:00:00 2001 From: Marc Oller Date: Fri, 20 Sep 2024 11:52:36 +0200 Subject: [PATCH] =?UTF-8?q?Correcci=C3=B3=20"Number=20of=20requests=20insi?= =?UTF-8?q?de=20batch=20exceed=20the=20limit"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/MicrosoftCommonServiceImpl.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java b/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java index c6c27663b73..24cf451bdd0 100644 --- a/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java +++ b/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java @@ -1067,6 +1067,7 @@ public boolean addOwnerToTeam(String userId, String teamId) throws MicrosoftCred public SynchronizationStatus addUsersToTeamOrGroup(String teamId, List members, SynchronizationStatus status, LinkedList roles) throws MicrosoftCredentialsException { boolean res = false; String dataKey = roles.contains(MicrosoftUser.OWNER) ? "ownerId" : "memberId"; + boolean generalError = false; ConversationMemberCollectionRequest postMembers = graphClient.teams(teamId).members() .buildRequest(); @@ -1078,12 +1079,13 @@ public SynchronizationStatus addUsersToTeamOrGroup(String teamId, List pendingMembers = members.subList(i * MAX_PER_REQUEST, Math.min(MAX_PER_REQUEST * (i +1 ), members.size())); List successMembers = new LinkedList<>(); + generalError = false; int retryCount = 0; while (!pendingMembers.isEmpty() && retryCount < MAX_RETRY) { BatchRequestContent batchRequestContent = new BatchRequestContent(); - members.forEach(member -> { + pendingMembers.forEach(member -> { ConversationMember memberToAdd = new ConversationMember(); memberToAdd.oDataType = "#microsoft.graph.aadUserConversationMember"; @@ -1093,16 +1095,28 @@ public SynchronizationStatus addUsersToTeamOrGroup(String teamId, List membersResponse = parseBatchResponse(responseContent, members); + BatchResponseContent responseContent; - successMembers.addAll((List) membersResponse.get("success")); - pendingMembers = (List) membersResponse.get("failed"); - List> errors = (List>) membersResponse.get("errors"); - handleMicrosoftExceptions(errors); - retryCount++; + try { + responseContent = getGraphClient().batch().buildRequest().post(batchRequestContent); + HashMap membersResponse = parseBatchResponse(responseContent, pendingMembers); + + successMembers.addAll((List) membersResponse.get("success")); + pendingMembers = (List) membersResponse.get("failed"); + List> errors = (List>) membersResponse.get("errors"); + handleMicrosoftExceptions(errors); + } catch (GraphServiceException e) { + log.debug("Microsoft General error adding members ", e); + generalError = true; + break; + } finally { + retryCount++; + } } + if(generalError) + continue; + for (MicrosoftUser pendingMember : pendingMembers) { if (!res && status != SynchronizationStatus.ERROR) { //once ERROR status is set, do not check it again