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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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? 

1 answer

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;

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

280 views 3 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you