JIRA project template - How to link to existing workflow?

Andreas Merkle _AME_ PF-26 March 25, 2014

I created a project template plugin, according to the tutorial here:

https://developer.atlassian.com/display/JIRADEV/Creating+a+Project+Template

It works fine.

But I try to avoid creating always a new workflow scheme, new issue type scheme and etc.
How to use existing ones? Removing <add-project> in <project-blueprint> is not the solution, because I don't any other element, which I can use to link to existing stuff.

Any hint would be appreciated.

And where to find the API description of: com.atlassian.jira.blueprint.api ??

2 answers

1 accepted

1 vote
Answer accepted
Andreas Merkle _AME_ PF-26 April 1, 2014

I got the following information from an atlassian member:

unfortunately Project Templates is designed to create new issue type and workflow schemes on each project creation and it is not possible through the JSON file to reuse an existing one. You can however use existing issue types by using the same name in the JSON configuration file. For example, if 'Bug' exists and you specify an issue type with name 'Bug' it will use the existing one in the system.

If there would really be a need to reuse existing schemes, you might try doing this through the AddProjectHook: don't specify a JSON configuration file and just do the creation/reusing of the schemes in that hook programatically.

Fred Hauschel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2014

Nice Idea, a hint to a code snipped would be nice ,-)

Andreas Merkle _AME_ PF-26 October 8, 2014

Hi Fred, the only chance is to change it programatically, see here: https://answers.atlassian.com/questions/279944/change-issue-type-scheme-programatically I hope Atlassian will update the blueprint interface, because right now it is not usable.

1 vote
IBL Software Engineering February 15, 2018

Here is a snippet of code that gives you a start:

@Override
public ConfigureResponse configure(final ConfigureData configureData) {
ConfigureResponse configureResponse = ConfigureResponse.create();

// Obviously you need to change the logic and add some null pointer protection. but it gives you an idea
WorkflowSchemeManager workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager();
Project project = configureData.project();
AssignableWorkflowScheme workflowScheme = workflowSchemeManager.getWorkflowSchemeObj(10100l);

MigrationHelperFactory migrationHelperFactory = ComponentAccessor.getComponent(DefaultMigrationHelperFactory.class);

try {
AssignableWorkflowSchemeMigrationHelper workflowSchemeMigrationHelper = migrationHelperFactory.createMigrationHelper(project,workflowScheme);
workflowSchemeMigrationHelper.doQuickMigrate();
} catch (GenericEntityException e) {
e.printStackTrace();
}

return configureResponse;
}
Chandan Gupta September 5, 2018

Code is not able to understand 

MigrationHelperFactory 

Can you provide me the import statement?

Thanks,

Chandan 

IBL Software Engineering September 5, 2018

Here is a link of API documentation:
https://docs.atlassian.com/software/jira/docs/api/7.2.3/com/atlassian/jira/workflow/migration/MigrationHelperFactory.html

You need to import it like this:

import com.atlassian.jira.workflow.migration.MigrationHelperFactory;

 I highly recommend IDE that does this more or less for you (I use IntelliJ Idea)

Chandan Gupta September 5, 2018

Thanks Peter. But I am using Jira-api-7.7.1.jar which do not contain this package. 

I am wondering why they have skipped it?

Chandan Gupta September 5, 2018

I think issue is not with version, but I am not able to see this package in any of the version i downloaded.

This is what I have in pom.xml

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>

Do I need to add something more.

IBL Software Engineering September 5, 2018

You need also:

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>

 

Note the jira-core artifactId.

Zuber Chataiwala September 21, 2018

Hello @IBL Software Engineering,

Your suggested code still creates new Workflow scheme and new Workflow for newly created project.

You have hardcode an id in the following code:

AssignableWorkflowScheme workflowScheme = workflowSchemeManager.getWorkflowSchemeObj(10100l);

 Is this id of existing scheme?

 

I tried the following but didnt work:

ConfigureResponse configureResponse = ConfigureResponse.create();
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
Collection<JiraWorkflow> workflows = workflowManager.getWorkflows();
JiraWorkflow myWorkflow = null;
for (JiraWorkflow workflow : workflows) {
    if (workflow.getName().indexOf("My Workflow") != -1) {
        myWorkflow = workflow;
        break;
    }
}
if (myWorkflow != null) {

    WorkflowSchemeManager workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager();

    Project project = configureData.project();
    AssignableWorkflowScheme workflowScheme;
    try {
        workflowScheme = (AssignableWorkflowScheme) workflowSchemeManager
                .getWorkflowScheme(workflowSchemeManager.getSchemesForWorkflow(myWorkflow).iterator().next());

        MigrationHelperFactory migrationHelperFactory = ComponentAccessor.getComponent(DefaultMigrationHelperFactory.class);

        AssignableWorkflowSchemeMigrationHelper workflowSchemeMigrationHelper = migrationHelperFactory
                .createMigrationHelper(project, workflowScheme);
        workflowSchemeMigrationHelper.doQuickMigrate();
    } catch (GenericEntityException e) {
        e.printStackTrace();
    }
}
IBL Software Engineering September 21, 2018

Yes, 10100l is hardcoded workflow scheme object id (that is why I said that the code needs to be adjusted in the code comments). Add logs to figure out what is missing/wrong.

Did it find the workflow? Did it find the workflow scheme?
 Are there any null pointers?  Where any exceptions caught?

Add following to add logging functionality:

Logger log = LoggerFactory.getLogger(YouClass.class);

log.info("Workflow Scheme found : " + String.valueOf(workflowScheme));

Suggest an answer

Log in or Sign up to answer