Adapt $spaceManager.getAllSpaces() to get only active site/global spaces, excluding personal and archived using Velocity

Hi all, I’m new to the community, apologies if below question has been asked already and if so please can you point me in the right direction.

I am following Atlassian guidance here How to view a list of all space creators and administrators for all spaces | Confluence | Atlassian Documentation

I’m wondering if there is some way to modify this user macro code to get only the ‘active’ and ‘site/global’ spaces omitting personal and archived spaces from the list. This is for performance reasons and as mostly users are interested in ‘active’ and ‘site/global’ and not personal or archived spaces.

Any help would be greatly appreciated. Thanks

## Macro title: Space Administrators
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling (21/03/2012)
## Modified by: Foogie Sim (01/05/2013)
## Modified by: Mal Ninnes (19/03/2024)
## Installed by: <your name>
## Macro to display a list of space administrators for all spaces
## @noparams
#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($spaces = $spaceManager.getAllSpaces())
<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">Space</th><th class="confluenceTh">Space Administrator</th>
  </tr>

#foreach($spacer in $spaces)
<tr>
<td class="confluenceTd">$spacer.name</a></td>
<td class="confluenceTd">#set($admins=$spaceManager.getSpaceAdmins($spacer)) #foreach($admin in $admins) $admin.name, #end</td>
</tr>
#end

</table>

Hello Ivan,

I’m not a Macro expert, and I can’t say for sure if this is possible using only Velocity. For a case like that, we would develop a custom macro and then, using Java, we would call the function like this to get only active and global spaces:

SpacesQuery spacesQuery = SpacesQuery.newQuery()
                .withSpaceType(SpaceType.GLOBAL)
                .withSpaceStatus(SpaceStatus.CURRENT)
                .build();
spaceManager.getAllSpaces(spacesQuery);

However, please note that this function is deprecated and SpaceService should be used instead.

Regards,
Ansgar

1 Like

Thanks @AnsgarNell, I’m hoping to achieve this using only Velocity so if anyone know how I can do this using Velocity, that would be really helpful. I’m not familiar with how to set this up using the Java workaround, and also I would like to keep it simple. Given that the objective is simply fetching spaces from Confluence of a particular type and status, I feel like this should be possible using Velocity.