Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,334
Community Members
 
Community Events
184
Community Groups

Why if a user is referred to in an Insight comment, no notification is sent?

In an insight object, if a user refers to another jira user with @Name, one would expect an  email notification to be sent. I can't see anything in Insight or Jira settings that support or prevent this notification. I've looked at the automation, and it doesn't seem to be configurable there either. Any guidance or ideas? 

2 answers

1 accepted

0 votes
Answer accepted

I ended up writing a messy groovy script. Take this with a grain of salt. 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.util.UserManager
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.user.util.UserUtil
import java.util.regex.Pattern
import java.util.regex.Matcher
import com.atlassian.jira.mail.Email;
import com.atlassian.mail.queue.SingleMailQueueItem;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
/* Custom field for the organisation */
CustomField insightObjectCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10000);

if (insightObjectCF == null) {
return false;
}
MailServerManager mailServerManager = ComponentAccessor.getMailServerManager();

def currentUserEmail = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getEmailAddress();

/* The object facade class */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)
def objectKey = object.getObjectKey()
def insightObject = objectFacade.loadObjectBean(objectKey)
int objectId = insightObject.getId()

def commentList = objectFacade.findCommentBeans(objectId);
def commentLast = commentList.last();
def commentID = commentLast.getId();
def comment = commentLast.getComment();
/*def s1 = comment.substring(comment.indexOf("[")+1);
s1.trim();
def userName = s1.replaceAll("[^a-zA-Z0-9]", ""); */
UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService.class)

def subject = "New Insight Comment from Object " + objectId
def objectUrl = "https://services.virtamed.net/jira/secure/ShowObject.jspa?id="+objectId
def body = "New comment from issue \n <br>" + objectUrl + "\n <br> "+ comment

/* Log the Insight object */
log.info("Insight object of key: " + objectId);
log.info("Logged in user " + currentUserEmail);
//log.info("User " + user + " "+ emailAddr );
log.info("Comment " + body );

 

/* Pattern match to get email addresses*/
String myRegex=/(?<=\~)([\w.]+)/
String myInput = comment;

String ResultString
Pattern regex
Matcher regexMatcher

regex = Pattern.compile(myRegex, Pattern.DOTALL);

regexMatcher = regex.matcher(myInput);

List<String> matchList = new ArrayList<String>();
List<String> emails = new ArrayList<String>();

while (regexMatcher.find()) {
matchList.add(regexMatcher.group());
}

for(int i=0;i<matchList.size();i++)
{
myInput=myInput.replaceAll( matchList[i], '')
def user = ComponentAccessor.userManager.getUserByKey(matchList[i])
emails[i]= user.getEmailAddress();
log.info(matchList[i] +" " + emails[i])
}
//log.info(myInput)

/*Send email*/
def sendEmail(String emailAddr, String subject, String body, String currentUserEmail) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(emailAddr);
email.setCc(currentUserEmail);
email.setSubject(subject);
email.setMimeType("text/html");
email.setBody(body);
mailServer.send(email);
log.info("Mail sent " +emailAddr)
} else {
log.info("Problem getting the mail server from JIRA configuration, log this error")
}
}

for(int i=0;i<emails.size();i++)
{
sendEmail( emails[i], subject, body, currentUserEmail)
}

return true;

I can't see anything in Insight or Jira settings that support or prevent this notification. I've looked at the automation http://essaypapers.reviews/, and it doesn't seem to be configurable there either. Any guidance or ideas? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events