com.atlassian.jira.util
Class MantisImportBean

java.lang.Object
  extended by com.atlassian.jira.util.MantisImportBean
Direct Known Subclasses:
CustomMantisImportBean

public class MantisImportBean
extends Object

Mantis importer.


Nested Class Summary
static class MantisImportBean.DefaultMappingBean
          Class mapping Mantis ids (see lang/strings_english.txt in the Mantis source) to JIRA IDs
protected static interface MantisImportBean.MappingBean
           
static class MantisImportBean.UserRole
           
 
Field Summary
static Integer MANTIS_CF_TYPE_CHECKBOX
           
static Integer MANTIS_CF_TYPE_DATE
           
static Integer MANTIS_CF_TYPE_EMAIL
           
static Integer MANTIS_CF_TYPE_ENUM
           
static Integer MANTIS_CF_TYPE_FLOAT
           
static Integer MANTIS_CF_TYPE_LIST
           
static Integer MANTIS_CF_TYPE_MULTILIST
           
static Integer MANTIS_CF_TYPE_NUMERIC
           
static Integer MANTIS_CF_TYPE_STRING
           
static String MANTIS_ID_CF_NAME
           
static DecimalFormat MANTIS_ID_FORMAT
           
static String MANTIS_ID_TYPE
           
static Map MANTIS_TO_JIRA_CF_SEARCHER_MAPPINGS
          Mapping from Mantis custom field types (Integers) to JIRA custom field searchers (Strings).
static Map MANTIS_TO_JIRA_CF_TYPE_MAPPINGS
          Mapping from Mantis custom field types (Integers) to JIRA custom field types (Strings).
 
Constructor Summary
MantisImportBean(IssueIndexManager indexManager, org.ofbiz.core.entity.GenericDelegator genericDelegator, ProjectManager projectManager, PermissionSchemeManager permissionSchemeManager, CacheManager cacheManager, IssueManager issueManager, VersionManager versionManager, ProjectComponentManager projectComponentManager, CustomFieldManager customFieldManager, IssueTypeScreenSchemeManager issueTypeScreenSchemeManager, PermissionManager permissionManager, OptionsManager optionsManager, ExternalUtils externalUtils, CommentManager commentManager, IssueFactory issueFactory, ProjectService projectService, UserUtil userUtil)
           
 
Method Summary
 String cleanMantisFilename(String filename)
          Return a clean filename from Mantis - internal format.
protected static void closePS(PreparedStatement ps)
           
protected  void createChangeHistory(int bug_id, org.ofbiz.core.entity.GenericValue issue)
          Store the original mantis bug id in the change history.
protected  boolean createComponent(String projectName, String componentName, String description)
           
protected  void createMantisIdCustomFieldValue(int bug_id, org.ofbiz.core.entity.GenericValue issue)
           
protected  boolean createProject(String product, String description)
           
protected  User createUser(String mantisEmail, String mantisUsername, int mantisUserid, String fullName, String password)
           
protected  boolean createVersion(String project, String versionName)
           
 void doImport(MantisImportBean.MappingBean mappingBean, DatabaseConnectionBean connectionBean, boolean enableNotifications, boolean reuseExistingUsers, boolean addToDevelopersGroup, boolean reindex, String[] projectNames, User importer)
          Main method of this bean.
 String escapeMantisString(String str)
           
static Map getAllMantisProjects(DatabaseConnectionBean connectionBean)
          Get a map of available Mantis projects and their id's.
 String getFullNameFromEmail(String email, String username)
          Infers the user's full name from other information.
 String getImportLog()
           
protected  int getMantisFeaturePriority()
          In Mantis, 'features' are just 'bugs' with a priority of 'feature'.
 Integer getMantisIdFromString(String s)
          Return an integer prefix of a string, if any.
protected  String getMantisUsername(ResultSet resultSet)
          Return a JIRA username from a row in the Mantis user table.
 Set getNonExistentAssociatedUsers(DatabaseConnectionBean connectionBean, String[] projectNames)
          This method will determine all the users that will need to exist in JIRA to successfully import the specified projects and will return the users that do not yet exist.
 String getProjectKey(String name)
           
 String getProjectList(String[] selectList)
          Generate SQL-friendly quoted comma-separated list of projects.
protected  void importAttachments(Connection conn, PreparedStatement attachPrepStatement, int bug_id, org.ofbiz.core.entity.GenericValue issue)
           
protected  void importComments(Connection conn, int bug_id, org.ofbiz.core.entity.GenericValue issue)
           
protected  void importComponents(Connection conn, String projectName, int projectId)
           
protected  org.ofbiz.core.entity.GenericValue importIssue(ResultSet resultSet, Connection conn, ResultSet textResultSet, String projectName)
          Import an issue from Mantis
protected  void importIssues(Connection conn, String projectName, int projectId)
           
protected  void importProjects(Connection conn, String[] selectedProjects, String selectedProjectsDisplay)
           
protected  void importUser(Connection conn, int mantisId)
           
protected  void importVersions(Connection conn, String projectName, int projectId)
           
protected  void log(String s)
           
protected  void logAttachmentLocation(String diskfile, File jiraAttachFile)
          Hook for recording which Mantis attachment filename maps to which JIRA attachment filename.
protected  Map retrieveImportedIssues()
          Return a map of mantisKey (Integer) -> Jira Issues Id (Integer).
 String rewriteMantisBuglinksInText(String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANTIS_CF_TYPE_STRING

public static final Integer MANTIS_CF_TYPE_STRING

MANTIS_CF_TYPE_NUMERIC

public static final Integer MANTIS_CF_TYPE_NUMERIC

MANTIS_CF_TYPE_FLOAT

public static final Integer MANTIS_CF_TYPE_FLOAT

MANTIS_CF_TYPE_ENUM

public static final Integer MANTIS_CF_TYPE_ENUM

MANTIS_CF_TYPE_EMAIL

public static final Integer MANTIS_CF_TYPE_EMAIL

MANTIS_CF_TYPE_CHECKBOX

public static final Integer MANTIS_CF_TYPE_CHECKBOX

MANTIS_CF_TYPE_LIST

public static final Integer MANTIS_CF_TYPE_LIST

MANTIS_CF_TYPE_MULTILIST

public static final Integer MANTIS_CF_TYPE_MULTILIST

MANTIS_CF_TYPE_DATE

public static final Integer MANTIS_CF_TYPE_DATE

MANTIS_TO_JIRA_CF_TYPE_MAPPINGS

public static final Map MANTIS_TO_JIRA_CF_TYPE_MAPPINGS
Mapping from Mantis custom field types (Integers) to JIRA custom field types (Strings). Populated statically below.


MANTIS_TO_JIRA_CF_SEARCHER_MAPPINGS

public static final Map MANTIS_TO_JIRA_CF_SEARCHER_MAPPINGS
Mapping from Mantis custom field types (Integers) to JIRA custom field searchers (Strings). Populated statically below.


MANTIS_ID_CF_NAME

public static final String MANTIS_ID_CF_NAME
See Also:
Constant Field Values

MANTIS_ID_FORMAT

public static final DecimalFormat MANTIS_ID_FORMAT

MANTIS_ID_TYPE

public static final String MANTIS_ID_TYPE
See Also:
Constant Field Values
Constructor Detail

MantisImportBean

public MantisImportBean(IssueIndexManager indexManager,
                        org.ofbiz.core.entity.GenericDelegator genericDelegator,
                        ProjectManager projectManager,
                        PermissionSchemeManager permissionSchemeManager,
                        CacheManager cacheManager,
                        IssueManager issueManager,
                        VersionManager versionManager,
                        ProjectComponentManager projectComponentManager,
                        CustomFieldManager customFieldManager,
                        IssueTypeScreenSchemeManager issueTypeScreenSchemeManager,
                        PermissionManager permissionManager,
                        OptionsManager optionsManager,
                        ExternalUtils externalUtils,
                        CommentManager commentManager,
                        IssueFactory issueFactory,
                        ProjectService projectService,
                        UserUtil userUtil)
Method Detail

getAllMantisProjects

public static Map getAllMantisProjects(DatabaseConnectionBean connectionBean)
                                throws SQLException
Get a map of available Mantis projects and their id's.

Parameters:
connectionBean - connection bean
Returns:
map of product names to product IDs, never null
Throws:
SQLException - if database problem occurs

doImport

public void doImport(MantisImportBean.MappingBean mappingBean,
                     DatabaseConnectionBean connectionBean,
                     boolean enableNotifications,
                     boolean reuseExistingUsers,
                     boolean addToDevelopersGroup,
                     boolean reindex,
                     String[] projectNames,
                     User importer)
              throws Exception,
                     IndexException,
                     org.ofbiz.core.entity.GenericEntityException
Main method of this bean. Creates JIRA projects mirroring those found in a Mantis database.

Parameters:
mappingBean - Mappings from Mantis to JIRA, including project key, statuses, etc
enableNotifications - Whether to send email notifications for newly created issues
reuseExistingUsers - Do we try to reuse existing users, or doImport a unique user for every Mantis user?
addToDevelopersGroup - Whether to add new users to the 'jira-developers' group
reindex - Whether to reindex after the import
projectNames - Array of Mantis project names to import
importer - User doing the import
Throws:
Exception
IndexException
org.ofbiz.core.entity.GenericEntityException

getNonExistentAssociatedUsers

public Set getNonExistentAssociatedUsers(DatabaseConnectionBean connectionBean,
                                         String[] projectNames)
This method will determine all the users that will need to exist in JIRA to successfully import the specified projects and will return the users that do not yet exist.

Parameters:
connectionBean - initialized connection bean
projectNames - the projects, by bugzilla project name, that you want to import.
Returns:
Set all the users that will need to exist in JIRA but do not yet.

getProjectList

public String getProjectList(String[] selectList)
Generate SQL-friendly quoted comma-separated list of projects.


importIssues

protected void importIssues(Connection conn,
                            String projectName,
                            int projectId)
                     throws Exception,
                            com.opensymphony.workflow.InvalidRoleException,
                            com.opensymphony.workflow.InvalidInputException,
                            CreateException,
                            SQLException
Throws:
Exception
com.opensymphony.workflow.InvalidRoleException
com.opensymphony.workflow.InvalidInputException
CreateException
SQLException

importIssue

protected org.ofbiz.core.entity.GenericValue importIssue(ResultSet resultSet,
                                                         Connection conn,
                                                         ResultSet textResultSet,
                                                         String projectName)
                                                  throws Exception,
                                                         com.opensymphony.workflow.InvalidRoleException,
                                                         com.opensymphony.workflow.InvalidInputException,
                                                         CreateException,
                                                         SQLException
Import an issue from Mantis

Parameters:
resultSet - mantis_bug_table row
conn - JDBC Connection
textResultSet - mantis_bug_text_table row
projectName - Name of issue's project
Returns:
Imported Issue
Throws:
Exception
com.opensymphony.workflow.InvalidRoleException
com.opensymphony.workflow.InvalidInputException
CreateException
SQLException

getMantisFeaturePriority

protected int getMantisFeaturePriority()
In Mantis, 'features' are just 'bugs' with a priority of 'feature'. In JIRA we have a separate 'Feature' entity, which needs to be assigned a priority. This method chooses that default priority.


escapeMantisString

public String escapeMantisString(String str)

rewriteMantisBuglinksInText

public String rewriteMantisBuglinksInText(String str)

getMantisIdFromString

public Integer getMantisIdFromString(String s)
Return an integer prefix of a string, if any.


importComments

protected void importComments(Connection conn,
                              int bug_id,
                              org.ofbiz.core.entity.GenericValue issue)
                       throws Exception,
                              org.ofbiz.core.entity.GenericEntityException
Throws:
Exception
org.ofbiz.core.entity.GenericEntityException

createChangeHistory

protected void createChangeHistory(int bug_id,
                                   org.ofbiz.core.entity.GenericValue issue)
                            throws Exception
Store the original mantis bug id in the change history.

Throws:
Exception

createMantisIdCustomFieldValue

protected void createMantisIdCustomFieldValue(int bug_id,
                                              org.ofbiz.core.entity.GenericValue issue)
                                       throws Exception
Throws:
Exception

retrieveImportedIssues

protected Map retrieveImportedIssues()
                              throws org.ofbiz.core.entity.GenericEntityException
Return a map of mantisKey (Integer) -> Jira Issues Id (Integer).

It does this by looking through the change items for the mantis import key.

Throws:
org.ofbiz.core.entity.GenericEntityException

importComponents

protected void importComponents(Connection conn,
                                String projectName,
                                int projectId)
                         throws SQLException,
                                org.ofbiz.core.entity.GenericEntityException
Throws:
SQLException
org.ofbiz.core.entity.GenericEntityException

createComponent

protected boolean createComponent(String projectName,
                                  String componentName,
                                  String description)
                           throws org.ofbiz.core.entity.GenericEntityException
Throws:
org.ofbiz.core.entity.GenericEntityException

importVersions

protected void importVersions(Connection conn,
                              String projectName,
                              int projectId)
                       throws SQLException,
                              org.ofbiz.core.entity.GenericEntityException
Throws:
SQLException
org.ofbiz.core.entity.GenericEntityException

createVersion

protected boolean createVersion(String project,
                                String versionName)
                         throws org.ofbiz.core.entity.GenericEntityException
Throws:
org.ofbiz.core.entity.GenericEntityException

importProjects

protected void importProjects(Connection conn,
                              String[] selectedProjects,
                              String selectedProjectsDisplay)
                       throws Exception,
                              org.ofbiz.core.entity.GenericEntityException,
                              com.opensymphony.workflow.InvalidInputException
Throws:
Exception
org.ofbiz.core.entity.GenericEntityException
com.opensymphony.workflow.InvalidInputException

createProject

protected boolean createProject(String product,
                                String description)
                         throws org.ofbiz.core.entity.GenericEntityException
Throws:
org.ofbiz.core.entity.GenericEntityException

importUser

protected void importUser(Connection conn,
                          int mantisId)
                   throws SQLException
Throws:
SQLException

getMantisUsername

protected String getMantisUsername(ResultSet resultSet)
                            throws SQLException
Return a JIRA username from a row in the Mantis user table. This can be overridden to map usernames from Mantis to JIRA (see CustomMantisImportBean for an example.

Throws:
SQLException

createUser

protected User createUser(String mantisEmail,
                          String mantisUsername,
                          int mantisUserid,
                          String fullName,
                          String password)

importAttachments

protected void importAttachments(Connection conn,
                                 PreparedStatement attachPrepStatement,
                                 int bug_id,
                                 org.ofbiz.core.entity.GenericValue issue)
                          throws Exception
Throws:
Exception

cleanMantisFilename

public String cleanMantisFilename(String filename)
Return a clean filename from Mantis - internal format.


logAttachmentLocation

protected void logAttachmentLocation(String diskfile,
                                     File jiraAttachFile)
                              throws IOException
Hook for recording which Mantis attachment filename maps to which JIRA attachment filename.

Throws:
IOException

getProjectKey

public String getProjectKey(String name)

getFullNameFromEmail

public String getFullNameFromEmail(String email,
                                   String username)
Infers the user's full name from other information. This default implementation returns 'John Smith' for john.smith@example.com, and otherwise defaults to the Mantis username.


log

protected void log(String s)

closePS

protected static void closePS(PreparedStatement ps)

getImportLog

public String getImportLog()


Copyright © 2002-2009 Atlassian. All Rights Reserved.