Iterate over all Spaces

Florian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2020

Hi,

I want to write a user macro to get a public list of all spaces, not only the spaces the current user has access to. The official documentation mentions the $spaceManager (https://developer.atlassian.com/server/confluence/confluence-objects-accessible-from-velocity/) but the requried method getAllSpaces() is marked as deprecated (https://docs.atlassian.com/ConfluenceServer/javadoc/7.4.0/com/atlassian/confluence/spaces/SpaceManager.html).

Is there another way to get a list of all spaces without running into trouble in near future? There is a hint in the documentation saying "since 7.3.0, use SpaceService.find(Expansion...) in plugins and SpaceManagerInternal in core where applicable". I tried but I can't get it up and running.

 

 

1 answer

0 votes
Liza January 6, 2022

Hi there, did you manage to find a way to work with the SpaceService.find() method in a user macro? I am running into the same problem...

Florian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2022

Hi @[deleted], unfortunately no. 

Ansgar Nell February 21, 2023
int start = 0;
PageResponse<Space> pageResponse;
do {
pageResponse = spaceService.find().fetchMany(new SimplePageRequest(start, start + MAX_RESULTS));
for (Space space : pageResponse.getResults()) {
// do stuff
}
start += MAX_RESULTS;
} while (pageResponse.hasMore());

MAX_RESULTS HAS TO be 500 because that's the limit for fetchMany. Where did I read that? Nowhere, it isn't documented and you have to guess it (fortunately I did it before production).

This method sucks, getAllSpaces() is much better, and to make it even worse, one method returns 1433 and the other 1423 for which should give the same results.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.4.0
TAGS
AUG Leaders

Atlassian Community Events