Structure (DC)

Find All Generators and Transformations in Instance

The following script returns a list of all configured generators and saved transformations across your instance.

When run, the script exports the results as a plain text (*.txt) in your jira_home directory.

Groovy
import com.almworks.integers.LongIterator
import com.almworks.jira.structure.api.forest.ForestSpec
import com.almworks.jira.structure.api.item.CoreIdentities
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.config.util.JiraHome
import org.apache.log4j.Level
import com.almworks.jira.structure.api.StructureComponents
import org.apache.log4j.Logger

@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureComponents structureComponents

// Set log level to INFO (default for REST endpoints is WARN)
def log = Logger.getLogger(getClass())
log.setLevel(Level.INFO)

def structureManager = structureComponents.structureManager
def forestService = structureComponents.forestService
def rowManager = structureComponents.rowManager
def generatorManager = structureComponents.generatorManager
def propertyService = structureComponents.structurePropertyService
def jiraHome = ComponentAccessor.getComponent(JiraHome)

def allStructures = structureManager.getAllStructures(null)

// Create the file in the Jira export directory
def exportFile = new File(jiraHome.exportDirectory, 'structure_generators_transformations_export.txt')
def printWriter = exportFile.newPrintWriter()

// Iterate over all structures to get the elements of each one
allStructures.each { structure ->
// Print structure name and id
printWriter.println("------- Structure (#${structure.id}): '${structure.name}'")

// Collect the generators ids in the structure
def forest = forestService.getForestSource(ForestSpec.structure(structure.id)).latest.forest
def generatorsIds = []
forest.rows.each { LongIterator li ->
def row = rowManager.getRow(li.value())
def itemId = row.itemId
if (CoreIdentities.isGenerator(itemId)) {
generatorsIds << itemId.getLongId()
}
}

// Print the info of each generator
printWriter.println('----- Generators')
generatorsIds.each { id ->
def generator = generatorManager.getGenerator(id)
printWriter.println("--- Row id: ${id}")
printWriter.println("--- Module key: ${generator.moduleKey}")
printWriter.println("--- Parameters: ${generator.parameters}")
printWriter.println()
}

// Print the info about the quick transforms
def quickTransforms = propertyService.getString(structure.id, 'quick-transforms', '')
printWriter.println('----- Quick transforms')
printWriter.println("--- JSON: ${quickTransforms}")
printWriter.println()
}
printWriter.close()

log.info("Export file generated at export directory, path: '${exportFile.absolutePath}'")