cern.jira.emailhandler
Class AdvancedCreateIssueHandler

java.lang.Object
  extended by AbstractMessageHandler
      extended by cern.jira.emailhandler.AdvancedCreateIssueHandler

public class AdvancedCreateIssueHandler
extends AbstractMessageHandler

A message handler to create a new issue from an incoming message. Note: requires public noarg constructor as this class is instantiated by reflection.

Version:
3.0 (19-3-2009)
Author:
Daniele Raffo on the basis of the CreateIssueHandler class, copyright (c) 2002-2006 Atlassian

Field Summary
private static java.lang.String CC_ASSIGNEE
           
 boolean ccAssignee
           
 java.lang.String defaultIssueType
           
 java.lang.String defaultProjectKey
           
private  IssueDescriptor issueDescriptor
           
 java.lang.String issueType
           
private static java.lang.String KEY_ISSUETYPE
           
private static java.lang.String KEY_PROJECT
           
private static Category log
           
private  java.util.Collection priorities
           
 java.lang.String projectKey
           
 
Constructor Summary
AdvancedCreateIssueHandler()
           
 
Method Summary
protected  boolean attachHtmlParts(Part part)
          Attaches HTML parts.
protected  boolean attachPlainTextParts(Part part)
          Attaches plaintext parts.
private  java.lang.String getDefaultSystemPriority()
           
private  java.lang.String getDescription(User reporter, Message message)
          Extracts the description of the issue from the message.
static User getFirstValidAssignee(Address[] addresses, GenericValue project)
          Given an array of addresses, returns the first valid assignee for the appropriate project.
private  java.lang.String getPriority()
          Get the issue's priority.
protected  GenericValue getProject()
           
protected  ProjectManager getProjectManager()
           
static User getUserByName(java.lang.String userName)
          Returns an User given its userName.
 boolean handleMessage(Message message)
           
protected  boolean hasValidIssueType()
           
 void init(java.util.Map params)
           
private  boolean isEnterprise()
           
private static boolean isValidAssignee(GenericValue project, User user)
          Tells if user is a valid assignee for project.
private  java.lang.String recordFromAddressForAnon(User reporter, Message message, java.lang.String description)
          Adds the senders' From: addresses to the end of the issue's details (if they could be extracted), if the e-mail has been received from an unknown e-mail address and the mapping to an "anonymous" user has been enabled.
private  void setDefaultSecurityLevel(MutableIssue issue)
           
(package private)  void setIssueDescriptor(IssueDescriptor issueDescriptor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Category log

issueDescriptor

private IssueDescriptor issueDescriptor

priorities

private java.util.Collection priorities

projectKey

public java.lang.String projectKey

issueType

public java.lang.String issueType

defaultProjectKey

public java.lang.String defaultProjectKey

defaultIssueType

public java.lang.String defaultIssueType

ccAssignee

public boolean ccAssignee

KEY_PROJECT

private static final java.lang.String KEY_PROJECT
See Also:
Constant Field Values

KEY_ISSUETYPE

private static final java.lang.String KEY_ISSUETYPE
See Also:
Constant Field Values

CC_ASSIGNEE

private static final java.lang.String CC_ASSIGNEE
See Also:
Constant Field Values
Constructor Detail

AdvancedCreateIssueHandler

public AdvancedCreateIssueHandler()
Method Detail

init

public void init(java.util.Map params)

handleMessage

public boolean handleMessage(Message message)
                      throws MessagingException
Throws:
MessagingException

getProject

protected GenericValue getProject()

hasValidIssueType

protected boolean hasValidIssueType()

getProjectManager

protected ProjectManager getProjectManager()

getDescription

private java.lang.String getDescription(User reporter,
                                        Message message)
                                 throws MessagingException
Extracts the description of the issue from the message.

Parameters:
reporter - the established reporter of the issue
message - the message from which the issue is created
Returns:
the description of the issue
Throws:
MessagingException

recordFromAddressForAnon

private java.lang.String recordFromAddressForAnon(User reporter,
                                                  Message message,
                                                  java.lang.String description)
                                           throws MessagingException
Adds the senders' From: addresses to the end of the issue's details (if they could be extracted), if the e-mail has been received from an unknown e-mail address and the mapping to an "anonymous" user has been enabled.

Parameters:
reporter - the established reporter of the issue (after one has been established)
message - the message that is used to create issue
description - the issues extracted description
Returns:
the modified description if the e-mail is from anonymous user, unmodified description otherwise
Throws:
MessagingException

getPriority

private java.lang.String getPriority()
Get the issue's priority.


getDefaultSystemPriority

private java.lang.String getDefaultSystemPriority()

getFirstValidAssignee

public static User getFirstValidAssignee(Address[] addresses,
                                         GenericValue project)
Given an array of addresses, returns the first valid assignee for the appropriate project.

Parameters:
addresses - the addresses
project - the project
Returns:
the first valid assignee for project

isValidAssignee

private static boolean isValidAssignee(GenericValue project,
                                       User user)
Tells if user is a valid assignee for project.

Parameters:
project - a project
user - an user
Returns:
whether user is a valid assignee for project

getUserByName

public static User getUserByName(java.lang.String userName)
Returns an User given its userName.

Parameters:
userName - the name of the user
Returns:
the user, or null if there was no user with name userName

setDefaultSecurityLevel

private void setDefaultSecurityLevel(MutableIssue issue)
                              throws java.lang.Exception
Throws:
java.lang.Exception

isEnterprise

private boolean isEnterprise()

setIssueDescriptor

final void setIssueDescriptor(IssueDescriptor issueDescriptor)

attachPlainTextParts

protected boolean attachPlainTextParts(Part part)
                                throws MessagingException,
                                       java.io.IOException
Attaches plaintext parts. Text parts are not attached but rather potentially form the source of issue text. However text part attachments are kept providing they are not empty.

Parameters:
part - the part which will have a content type of text/plain to be tested
Returns:
true if the part is an attachment and not empty
Throws:
MessagingException
java.io.IOException

attachHtmlParts

protected boolean attachHtmlParts(Part part)
                           throws MessagingException,
                                  java.io.IOException
Attaches HTML parts. HTML parts are not attached but rather potentially form the source of issue text. However html part attachments are kept providing they are not empty.

Parameters:
part - the part which will have a content type of text/html to be tested
Returns:
true if the part is an attachment and not empty
Throws:
MessagingException
java.io.IOException