Question
How do we supply a parameter to the userApi.findUsers API, with it being optional. For example, the loginAllowed or external parameters. Is the way we are doing it with True or False the way to do it? If we don't provide anything, it does not work, and we would like it to return internal and external users.
Would the recommendation be then to use the REST API, and not the built-in APIs?
We have the following code, which is able to find a single user but does not allow any sort of wildcard search. * or %.
Even though the documentation says the fields are optional, we are not sure how to specify an optional date or string. When we leave it out, it complains.
Code:
from java.util import Calendar, Date, TimeZone, Locale;
yearAgo = Calendar.getInstance()
yearAgo.add(Calendar.DAY_OF_MONTH, -365)
users = userApi.findUsers( "Russell.Liss@brambles.com", "Liss, Russell", True or False, True or
False, yearAgo.getTime(), Date(), 0, 100 )
print( users )
for user in users:
print( user.fullName + " (" + user.email + ") " + str( user.lastActive ) )
Answer
If you are actually putting this True or False in a boolean parameter in the API they are sending True because True or False is a Jython condition that evaluates to True in Java. It is Boolean so likely needs to be None in Jython to translate to null in Java.
Also, you will only be going to find users with email = Russell.Liss@brambles.com and fullName = Liss, Russell which we believe will only match one result. The suggestion from our team would be to send None for those fields too assuming that want all users.
Steps to Follow
Use the following updated code to get the Users:
# List<UserAccount> findUsers(String email, String fullName, Boolean loginAllowed, Boolean external,
Date lastActiveAfter, Date lastActiveBefore, Long page, Long resultsPerPage)
from java.util import Calendar, Date, TimeZone, Locale;
yearAgo = Calendar.getInstance()
print yearAgo.getTime()
yearAgo.add(Calendar.DAY_OF_MONTH, -365)
print yearAgo.getTime()
allUsers = userApi.findUsers(None, None, None, None, None, None, None, None)
print "Found {0} total users".format(len(allUsers))
usersActiveAfterYearAgo = userApi.findUsers(None, None, None, None, yearAgo.getTime(), None,
None, None)
print "Found {0} users active after a year ago".format(len(usersActiveAfterYearAgo))
Related Information
- https://docs.xebialabs.com/jython-docs/#!/xl-release/9.7.x//service/com.xebialabs.xlrelease.api.v1.UserApi#UserApi-findUsers-String-String-Boolean-Boolean-Date-Date-Long-Long
- https://docs.xebialabs.com/jython-docs/#!/xl-release/9.7.x//service/com.xebialabs.xlrelease.api.v1.forms.UserAccount
Comments
Please sign in to leave a comment.