Groovy script to inactive users who are not logged in to Jira for past 90 days

I have code to inactive users who are not logged in to Jira for past 90 days. It is working fine in Jira 6.4 version.

Now, we upgraded our Jira to 7.2.9 version. The script what we have now is not compatible with 7 version.

Can someone provide me the resepective classes and method which can be replaced in the below code.

import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;

Logger log = log

int numOfDays = 90 // Number of days the user was not logged in
Date dateLimit = (new Date())- numOfDays

UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService.UpdateUserValidationResult updateUserValidationResult

// Important:
// Most of this code will just run in the ScriptRunner Console as-is
// but will not work when done as a Service or as a post-function.
// The reason is that in the case of the former, the currently logged
// on User provides the AuthenticationContext. In the case of the latter
// there is no ‘User’ per se who is running the code, and so we cannot
// deactivate anybody because there is no privilege that the Script
// has to do so. So we explicitly set the AuthenticationContext.

def authenticationContextUser = userUtil.getUserByName(“V116406”);

long count = 0
def sb = new StringBuffer();

sb.append(“Logon cutoff time stamp: " + dateLimit + “\n”);

userUtil.getUsers().findAll{it.isActive()}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
String lastLoginMillis = user.getValue(‘login.lastLoginMillis’)
if (lastLoginMillis?.isNumber()) {
Date d = new Date(Long.parseLong(lastLoginMillis))
if (d.before(dateLimit)) {
sb.append(“Found a candidate: " + user.getName()+”\t " + d.toString()+"\t " + user.getDisplayName().trim()+"\t " + user.getEmailAddress()+"\n");
updateUser = ImmutableUser.newUser(user).active(false).toUser()
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
sb.append("=====> Deactivated: "+ user.getName() + “\n”);
} else {
sb.append(“Could not deactivate :frowning: " + user.getName() + “. Errors: " + updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(’,’)+”\n”);

sb.append("${count} users were deactivated.\n");

// Set up Mail Server
MailServerManager mailServerManager = ComponentAccessor.getMailServerManager();
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer();

    // If the mail server configuration is valid, send an email.
    if (mailServer) {
        Email email = new Email(""); 
        email.setSubject("User Deactivation ["+ numOfDays +" day threshold] Summary (" + new Date().toString()+")"); // Set the SUBJECT
        email.setFrom("No-Reply DevOps User Deactivation <>"); // Set the FROM address
		// Just put the vzids of folks to cc here
        String content = """\


Below is the information for the deactivation service run for today.

Thank You for your support.

DevOps Engineering Team

content += sb.toString();

    else {
        log.error "No SMTP mail server defined.";

log.debug “User Deactivation Service finished running.”

Is this script compatible with JIRA in Cloud ?