Changing UserSearchParams.Builder parameters on the fly

Quentin Mahé November 26, 2020

Hello everyone,

I'm trying to have as few REST Endpoints as I can, and to achieve that goal I'm writing a class that will be used to get users, depending if they're active, inactive, etc...

So far here's what I have :

UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.allowEmptyQuery(true)
.includeActive(true)
.includeInactive(true)
.maxResults(10000)

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
JiraServiceContextImpl jiraServiceContext = new JiraServiceContextImpl(loggedInUser)

ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, "", paramBuilder.build()).each { user ->
Return.add(Username: user.getUsername())
}

 The goal is to have GET parameters to choose if I want to include/exclude active/inactive users, kinda like this (considering they're at true by default) :

if (active == "false") {
paramBuilder.includeActive(false)
}
if (inactive == "false") {
paramBuilder.includeInactive(false)
}

It's just the first step, the final goal is to have a unique script that is really flexible (calling it in a python script that's called via Jenkins), instead of 1 script per kind of research.
The only informations I'm using are :
- Username
- Account creation date
- Last login date
- Full name (eventually)

...which are then send to other scripts (for reporting, disabling inactive users, etc...)

Unfortunately this doesn't seem to work (I guess you can only set the builder once), is there a way to make it work ? I'm okay at using basic objets and classes, but that kind of stuff is a bit advanced for me (I found the entire block of code for searching users here).

Also I'm guessing this above actually is the right way to search for users, I have some other scripts where I use this (only way I found to get the account's creation date) :

ComponentAccessor.getOfBizDelegator().findByField("User", "active", 1).each {
...
}

 Thanks !

0 answers

Suggest an answer

Log in or Sign up to answer