Skip to content

Instantly share code, notes, and snippets.

@neilherbertuk
Created December 16, 2022 13:46
Show Gist options
  • Select an option

  • Save neilherbertuk/043d58c10316d8e7851a582f875cddd4 to your computer and use it in GitHub Desktop.

Select an option

Save neilherbertuk/043d58c10316d8e7851a582f875cddd4 to your computer and use it in GitHub Desktop.
Find users by their last (end) date within OpenIAM
import java.util.List
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.openiam.idm.searchbeans.UserSearchBean
import org.openiam.idm.srvc.user.dto.User
import org.openiam.srvc.user.UserDataWebService
import org.springframework.context.ApplicationContext
// Dependencies
Log log = LogFactory.getLog("findUserTest") // Logging
ApplicationContext appContext = (ApplicationContext) context // IoC Container
UserDataWebService userDataWebService = appContext.getBean("userWS") as UserDataWebService
// Date to Search from (Today)
Calendar from = Calendar.getInstance()
from.set(Calendar.HOUR_OF_DAY, 0)
from.set(Calendar.MINUTE, 0)
from.set(Calendar.SECOND, 0)
from.set(Calendar.MILLISECOND, 000)
// Date to search until (3 Days from now)
Calendar to = Calendar.getInstance()
to.add(Calendar.DAY_OF_MONTH, 3) // Add 3 days to today's date
to.set(Calendar.HOUR_OF_DAY, 23)
to.set(Calendar.MINUTE, 59)
to.set(Calendar.SECOND, 59)
to.set(Calendar.MILLISECOND, 999)
log.info("Searching for users with Last Date from: ${from.getTime()} to: ${to.getTime()}")
List<User> users = userDataWebService.getUserBetweenLastDate(from.getTime(), to.getTime())
if (users.size() > 0) {
log.info("Found ${users.size()} users")
for (User user : users) {
log.info("${user.getId()} - Name: ${user.getFirstName()} ${user.getLastName()}")
log.info("${user.getId()} - Last Date: ${user.getLastDate()}")
}
} else {
log.info("Returned no users")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment