This article is for Data Center. Visit Cloud
Creating Generators
Below are a series of scripts that run through the creation of an Insert, Extend, Sort and Filter Generator.
JQL Inserter
package examples.docs.structure
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.almworks.jira.structure.api.structure.Structure
import com.almworks.jira.structure.api.forest.action.ForestAction
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.item.CoreIdentities
import com.almworks.jira.structure.api.generator.CoreGeneratorParameters
import java.util.Map
@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureComponents structureComponents
def structureName = "test" // name of the structure you want to add this generator to
def jql = 'project = stmb and type = story' // this is the JQL query you want the generator to executre
def structureManager = structureComponents.getStructureManager()
def forestService = structureComponents.getForestService()
def generatorManager = structureComponents.getGeneratorManager()
def permission = PermissionLevel.valueOf("ADMIN")
def structureId = structureManager.getStructuresByName(structureName, permission)[0].getId()
// inserter
def params = new java.util.HashMap()
params.put(CoreGeneratorParameters.JQL, jql)
def jqlinserterId = generatorManager.createGenerator("com.almworks.jira.structure:inserter-jql", params, structureId)
def generatorItem = CoreIdentities.generator(jqlinserterId); // item to add to forest
def forestSource = forestService.getForestSource(ForestSpec.structure(structureId)) //resolving forest source for structure
forestSource.apply(new ForestAction.Add(generatorItem, 0, 0, 0))
Extend stories under epics and extend by blocking link
package examples.docs.structure
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.almworks.jira.structure.api.structure.Structure
import com.almworks.jira.structure.api.forest.action.ForestAction
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.forest.item.ItemForestBuilderImpl;
import com.almworks.jira.structure.api.item.CoreIdentities
import com.almworks.jira.structure.api.generator.CoreStructureGenerators
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.almworks.jira.structure.api.generator.CoreStructureGenerators
import java.util.Map
@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureComponents structureComponents
def structureManager = structureComponents.getStructureManager()
def permission = PermissionLevel.valueOf("ADMIN")
def structureName = "test"
def structureId = structureManager.getStructuresByName(structureName, permission)[0].getId()
def forestBuilder = new ItemForestBuilderImpl()
def generatorManager = structureComponents.getGeneratorManager()
def epicsExtenderItem = generatorManager.createGenerator(CoreStructureGenerators.EXTENDER_AGILE, [:], null)
forestBuilder.nextRow(CoreIdentities.generator(epicsExtenderItem))
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def blocksLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName('Blocks')
def blocksLinkTypeId = blocksLinkTypes[0].id
def params = [
'linkTypeId': blocksLinkTypeId, // id of the Blocks issue link type
'direction': 'outward', // direction of the link type, could be either 'inward' or 'outward'
'disableActions': false, // enable structure actions, i.e. issues DnD
'from': 2,
'to': 2 // number of levels to extend issue at
]
def blocksExtenderItem = generatorManager.createGenerator(CoreStructureGenerators.EXTENDER_LINKS, params, structureId)
forestBuilder.nextRow(CoreIdentities.generator(blocksExtenderItem))
def forestService = structureComponents.getForestService()
def forestSource = forestService.getForestSource(ForestSpec.structure(structureId))
def forestToAdd = forestBuilder.build()
forestSource.apply(new ForestAction.Add(forestToAdd, 0, 0, 0))
Sorting by a formula result and manual sorter
package examples.docs.structure
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.almworks.jira.structure.api.structure.Structure
import com.almworks.jira.structure.api.forest.action.ForestAction
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.forest.item.ItemForestBuilderImpl;
import com.almworks.jira.structure.api.item.CoreIdentities
import com.almworks.jira.structure.api.generator.CoreStructureGenerators
@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureComponents structureComponents
def structureManager = structureComponents.getStructureManager()
def permission = PermissionLevel.valueOf("ADMIN")
def structureName = "test"
def structureId = structureManager.getStructuresByName(structureName, permission)[0].getId()
def forestBuilder = new ItemForestBuilderImpl()
def generatorManager = structureComponents.getGeneratorManager()
def manualSorterItem = generatorManager.createGenerator(CoreStructureGenerators.SORTER_MANUAL, [:], null)
forestBuilder.nextRow(CoreIdentities.generator(manualSorterItem))
/* adding formula-based sorter
*/
def formulaSorterParams = [
attribute: [
id : "expr",
format: "order",
params : [
formula: "assignee + key",
variables: [
assignee: [ id: "Assignee", format: "text"],
key: [ id: "Key", format: "text"]
]
]
]
]
def formulaSorterItem = generatorManager.createGenerator(CoreStructureGenerators.SORTER_ATTRIBUTE, formulaSorterParams as Map, null)
forestBuilder.nextRow(CoreIdentities.generator(formulaSorterItem))
def forestService = structureComponents.getForestService()
def forestSource = forestService.getForestSource(ForestSpec.structure(structureId))
def forestToAdd = forestBuilder.build()
forestSource.apply(new ForestAction.Add(forestToAdd, 0, 0, 0))