Hello,
My JIRA plugin creating new IssueType, Workflow and adding it to existing WorkflowScheme via:
GenericValue workflowScheme = workflowSchemeManager.getWorkflowScheme(project); workflowSchemeManager.addWorkflowToScheme(workflowScheme, jiraWorkflow.getName(), issueType.getId());
Unfortunately I cannot find any method to remove workflow from workflow scheme.
I would be grateful for any hint how to do it.
Community moderators have prevented the ability to post new answers.
Thanks to Nic Brough [Adaptavist] I found solution. As Nic said it's needed to create draft workflow scheme.
Note that below solution missing migration of issues = can broke all issues that using workflow that we removing.
package com.mycompany.plugin.service; import org.springframework.stereotype.Component; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.workflow.AssignableWorkflowScheme; import com.atlassian.jira.workflow.DraftWorkflowScheme; import com.atlassian.jira.workflow.JiraWorkflow; import com.atlassian.jira.workflow.WorkflowScheme; import com.atlassian.jira.workflow.WorkflowSchemeManager; import com.google.common.collect.Iterables; import lombok.extern.slf4j.Slf4j; @Slf4j @Component public class MyWorkflowSchemeService { private WorkflowSchemeManager workflowSchemeManager = ComponentAccessor.getComponent(WorkflowSchemeManager.class); public void unlinkFromWorkflowSchemes(JiraWorkflow jiraWorkflow) { Iterable<WorkflowScheme> workflowSchemes = workflowSchemeManager.getSchemesForWorkflowIncludingDrafts(jiraWorkflow); log.debug("Found {} workflow schemes for \"{}\"", Iterables.size(workflowSchemes), jiraWorkflow.getName()); for (WorkflowScheme workflowScheme : workflowSchemes) { log.debug("Unlinking workflow \"{}\" from workflowScheme \"{}\"", jiraWorkflow.getName(), workflowScheme.getName()); if (workflowScheme instanceof AssignableWorkflowScheme) { this.unlinkFromWorkflowSchemes((AssignableWorkflowScheme) workflowScheme, jiraWorkflow); } else { log.debug("WorkflowScheme \"{}\" is not instance of AssignableWorkflowScheme - cannot unlink", workflowScheme.getName()); } } } private void unlinkFromWorkflowSchemes(AssignableWorkflowScheme assignableWorkflowScheme, JiraWorkflow jiraWorkflow) { DraftWorkflowScheme draftWorkflowScheme = getDraft(assignableWorkflowScheme); draftWorkflowScheme = draftWorkflowScheme.builder().removeWorkflow(jiraWorkflow.getName()).build(); workflowSchemeManager.replaceSchemeWithDraft(draftWorkflowScheme); workflowSchemeManager.clearWorkflowCache(); } private DraftWorkflowScheme getDraft(AssignableWorkflowScheme assignableWorklflowScheme) { if (workflowSchemeManager.hasDraft(assignableWorklflowScheme)) { log.debug("Draft for \"{}\" already exists. Using existing draft.", assignableWorklflowScheme.getName()); return workflowSchemeManager.getDraftForParent(assignableWorklflowScheme); } return workflowSchemeManager.createDraftOf(null, assignableWorklflowScheme); } }
I think you have to create a draft workflow scheme with the new list of workflows (i.e. the same as the existing one, minus the one you want to delete) and then make the draft live.
I'm not sure how you're going to pass it all the data about what to migrate existing issues to though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.