Hi, I was wondering if someone could assist with the conversion of this simplified directory code? That is, I'd like to convert the usage of 'findAllDirectories' it to use the new non-deprecated call, i.e., searchDirectories(EntityQuery) instead.
import com.atlassian.crowd.manager.directory.DirectoryManager
def directoryManager = ComponentAccessor.getComponent(DirectoryManager)
return directoryManager.findAllDirectories().find {
it.name.toString().toLowerCase() == 'jira internal directory'
}?.getId() ?: -1
Something like this works
import com.atlassian.crowd.manager.directory.DirectoryManager
import com.atlassian.crowd.search.query.entity.DirectoryQuery
import com.atlassian.crowd.search.query.entity.restriction.NullRestrictionImpl
import com.atlassian.jira.component.ComponentAccessor
DirectoryManager directoryManager = ComponentAccessor.getComponent(DirectoryManager)
directoryManager.searchDirectories(new DirectoryQuery(NullRestrictionImpl.INSTANCE, 0, 100)).stream().forEach(directory -> {
log.warn(directory.getName() + ":" + directory.getId())
})
However, there are many SearchRestriction implementations and unless you really, really care about the method being deprecated, I would say just use the deprecated method, until it's removed. Once you start digging this far you will start seeing magic numbers such as 0 and 100, which are start index and max results.
Seeing as you're just looking for internal directory you could just as easily hardcode
directoryManager.findDirectoryById(1L)
because internal dir in Jira is always 1
Or you could just search by name
directoryManager.findDirectoryByName("Jira Internal Directory")
internal directory is static, it never changes the id, it never changes the name. It beats me as to why anyone would decide to change it.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.