Skip to content

Commit

Permalink
[AZURE-12] fixes pagination, now last page is correctly returned (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-patricelli authored Aug 17, 2023
1 parent d0b4d5b commit 15d7098
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/main/java/net/tirasa/connid/bundles/azure/AzureConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.tirasa.connid.bundles.azure;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.graph.http.BaseCollectionRequestBuilder;
import com.microsoft.graph.models.AssignedLicense;
import com.microsoft.graph.models.AssignedPlan;
import com.microsoft.graph.models.DirectoryObject;
Expand Down Expand Up @@ -126,8 +127,7 @@ public void test() {
}

} else {
LOG.error("Error with establishing connection while testing. "
+ "No instance of the configuration class");
LOG.error("Error with establishing connection while testing. " + "No instance of the configuration class");
}
}

Expand Down Expand Up @@ -201,9 +201,7 @@ public void executeQuery(

UserCollectionRequestBuilder nextPageRequest =
client.getAuthenticated().getAllUsersNextPage(pagesSize, "").getNextPage();
cookie = nextPageRequest != null
&& nextPageRequest.buildRequest().get().getNextPage() != null
? getSkipToken(nextPageRequest) : null;
cookie = nextPageRequest != null ? getSkipToken(nextPageRequest) : null;
}
} else {
users = client.getAuthenticated().getAllUsers();
Expand Down Expand Up @@ -261,16 +259,13 @@ public void executeQuery(
GroupCollectionPage request =
client.getAuthenticated().getAllGroupsNextPage(pagesSize, cookie);
groups = request.getCurrentPage();
cookie = request != null && request.getNextPage() != null
? getGroupSkipToken(request.getNextPage()) : null;
cookie = request != null ? getSkipToken(request.getNextPage()) : null;
} else {
groups = client.getAuthenticated().getAllGroups(pagesSize);

GroupCollectionRequestBuilder nextPageRequest =
client.getAuthenticated().getAllGroupsNextPage(pagesSize, "").getNextPage();
cookie = nextPageRequest != null && nextPageRequest.buildRequest().get()
.getNextPage() != null
? getGroupSkipToken(nextPageRequest) : null;
cookie = nextPageRequest != null ? getSkipToken(nextPageRequest) : null;
}
} else {
groups = client.getAuthenticated().getAllGroups();
Expand Down Expand Up @@ -699,8 +694,7 @@ public Uid update(

returnUid = new Uid(group.id);
} catch (Exception e) {
AzureUtils.wrapGeneralError(
"Could not update Group " + uid.getUidValue() + " from attributes ", e);
AzureUtils.wrapGeneralError("Could not update Group " + uid.getUidValue() + " from attributes ", e);
}

return returnUid;
Expand Down Expand Up @@ -1076,16 +1070,14 @@ private ConnectorObject fromLicense(final SubscribedSku subscribedSku, final Set
return builder.build();
}

private String getSkipToken(final UserCollectionRequestBuilder request) {
String token = request.getRequestUrl().
substring(request.getRequestUrl().indexOf(SKIP_TOKEN_ID) + SKIP_TOKEN_ID.length());
return token.substring(0, token.indexOf("&"));
}

private String getGroupSkipToken(final GroupCollectionRequestBuilder request) {
String token = request.getRequestUrl().
substring(request.getRequestUrl().indexOf(SKIP_TOKEN_ID) + SKIP_TOKEN_ID.length());
return token.substring(0, token.indexOf("&"));
private String getSkipToken(final BaseCollectionRequestBuilder request) {
String token = null;
// set token only if the request is not null (not in the last page)
if (request != null) {
token = request.getRequestUrl()
.substring(request.getRequestUrl().indexOf(SKIP_TOKEN_ID) + SKIP_TOKEN_ID.length());
}
return StringUtil.isNotBlank(token) ? token.substring(0, token.indexOf("&")) : null;
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 15d7098

Please sign in to comment.