Recipient Generators

This page lists recipient generator scripts to be used in conjunction with notification schemes. These scripts were taken straight from the public JIRA site. Please note that some scripts may be snippets and probably WILL need modification to work properly for your situation. Treat these as templates that you can modify from.

Uses Committers But Need to Modify Repository Username

You could have repository users that are close to Anthill user names and their is a easy operation to map the two and it is painful to add repository aliases for every user.

Script Notes:

  • This script strips off everything before the first '\'

AHPSCRIPTS-68

import com.urbancode.anthill3.domain.security.*;

org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("Committer Notification");

userSet = new java.util.HashSet();
changelogs = ChangeLogHelper.getChangeLogArray(workflow);
repoId = workflow.getBuildLife().getProfile().getSourceConfig().getRepository().getId();

for (int i = 0; i < changelogs.length; i++){
    changesets = changelogs[i].getChangeSetArray();
    for (int j = 0; j < changesets.length; j++){
        username = changesets[j].getUser();
        // remove the domain name from the repo user name
        username = username.substring(username.indexOf("\\") + 1);
        tempUsers = UserFactory.getInstance().restoreAllForChangelogNameAndRepository(username, repoId);
        if (tempUsers.length == 0) {
            log.warn("Did not find a user matching developer name '" + username + "'");
        }
        
com.urbancode.commons.util.CollectionUtil.addAll(userSet, tempUsers);
    }
}

result = new User[userSet.size()];
userSet.toArray(result);

activeUsers = new java.util.ArrayList();
for ( int i = 0; i < result.length; i++ ) {
if ( !result[i].isDeleted() && !result[i].isInactive()) {
activeUsers.add(result[i]);
}
}
return (User[]) activeUsers.toArray(new User[activeUsers.size()]);

Selects Person Who Started Build

  • User Generator script, that selects the person who started a build. If the build was not a manual request, it does not notify anyone.

AHPSCRIPTS-81

import com.urbancode.anthill3.domain.buildrequest.RequestSourceEnum; 
 import com.urbancode.anthill3.domain.security.User; 
 if (RequestSourceEnum.MANUAL.equals(request.getRequestSource())) { 
   return new User[] { request.getRequester() }; 
 } 
 return null;

Uses Project Property to Identify Users to Notify

  • This script looks up a property named project.managers on the Project. The property value should be the name of project management users in comma-separated form.

NOTE: The e-mails returned must match a User in the Anthill authentication realm!

AHPSCRIPTS-105

if (workflow.getProject().hasProperty("project.managers")) { 
   return UserLookup.getUsersForNames(workflow.getProject().getProperty("project.managers").getValue().split(",")); 
 }