Ability to extract all options hierarchy programmatically

Issue #49 resolved
Sergei Kniazhentcev created an issue

Hi Yury,

Is there a way (either using SQL or using JAVA API ) to extract whole tree of components?

For integration with some other plugins (Structure for), I need to have a map with Option and its parent option, if it exists.

I failed to find SQL table in jira DB, and the Groovy script I wrote

```

#!java

import com.atlassian.jira.component.ComponentAccessor

import groovy.json.JsonSlurper

import groovy.json.JsonBuilder

import groovy.json.JsonOutput    

import com.atlassian.jira.event.type.EventDispatchOption;

import com.onresolve.scriptrunner.runner.customisers.WithPlugin

import com.onresolve.scriptrunner.runner.customisers.PluginModule

import ru.slie.jira.tree.manager.TreeSchemaManager

@WithPlugin("ru.slie.jira.tree-customfield")

@PluginModule

TreeSchemaManager tsm    

def issueManager = ComponentAccessor.getIssueManager()

def issue = issueManager.getIssueObject("VER-2234")

def user = ComponentAccessor.getUserManager().getUserByName("jira_role");

def customFieldManager = ComponentAccessor.customFieldManager

def treeField = customFieldManager.getCustomFieldObject("customfield_17212")

def options = tsm.findOptionByName(treeField, "*", 0) 

log.debug(options)

def schema = tsm.getSchema(treeField.getRelevantConfig(issue))

if (!schema) {

log.debug "no assign schema for field"

} else {

log.debug(schema.getOptions())

}

```

seem to return only a subset of values

Comments (3)

  1. Yury Oboz repo owner

    Hi!

    Tables names for sql:

    • AO_AA9326_CONTEXT
    • AO_AA9326_OPTION
    • AO_AA9326_SCHEMA

    Java API:

    TreeSchema schema = tsm.getSchema(schemaId); // or FieldConfigScheme // or FieldConfig, ex.: customField.getRelevantConfig(issue)
    
    List<TreeOption> rootOptions = schema.getOptions();
    
    for (TreeOption option1: rootOptions) {
       List<TreeOption> children1 = option1.getChildren();
       for (TreeOption option2: children1) {
          List<TreeOption> children2 = option2.getChildren();
          ........
       }
    }
    
    /*  simple list  */
    
    List<TreeOption> allOptions = tsm.getOptions(schema, 10000) // 10000 - limit for return values
    
    /* option's methods */
    
    TreeOption parent = option.getParent(); // or (int) getParentId()
    
    List<TreeOption> parents = option.getParents();
    

    If you have any questions write them in comment

  2. Log in to comment