Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel4


Info

Check theĀ javadoc Javadoc for TGNG JAVA Java API.

...


Java API Examples


Code Block
languagegroovy
themeEclipse
firstline1
titlereadFieldData usage example
linenumberstrue
collapsetrue
// This script reads all data from a Grid custom field with default
// configuration named "API sampleSample" in issue TEST-1

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser

// Get issue id
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
Issue issue = issueManager.getIssueObject("TEST-1")
Long issueId = issue.getId()

// Get TGNG custom field id
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class)
CustomField tgngCustomField = customFieldManager.getCustomFieldObjectsByName("API sampleSample").get(0)
Long tgngCustomFieldId = tgngCustomField.getIdAsLong()

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get GridService
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService")
def gridService = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass)

// Read field data
def fieldData = gridService.readFieldData(issueId, tgngCustomFieldId, user, null)
def gridRows = fieldData.getRows()

StringBuilder result = new StringBuilder()
for (row in gridRows) {
    def columns = row.getColumns()
    result.append("Order: ${columns.get("jseq")}, ")
    result.append("Summary: ${columns.get("jsummary")}, ")
    def assignee = columns.get("jassignee")
    result.append("Assignee: ${assignee == null ? "null" : assignee.get("username")}, ")
    result.append("Status: ${columns.get("jstatus")};<br>")
}

return result

...

Code Block
languagegroovy
themeEclipse
firstline1
title addRows usage example
linenumberstrue
collapsetrue
// This script adds two rows to Grid custom field with default configuration
// named "API sampleSample" in issue TEST-1

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser

// Get issue id
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
Issue issue = issueManager.getIssueObject("TEST-1")
Long issueId = issue.getId()

// Get TGNG custom field id
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class)
CustomField tgngCustomField = customFieldManager.getCustomFieldObjectsByName("API sampleSample").get(0)
Long tgngCustomFieldId = tgngCustomField.getIdAsLong()

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get GridService
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService")
def gridService = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass)

// Add a row
// Only "key" is required for userlist columns
gridService.addRows(issueId, tgngCustomFieldId, user, [
    ["jsummary": "Buy groceries", "jassignee": ["key": user.getKey()], "jstatus": "Open"],
    ["jsummary": "Plan vacation", "jassignee": ["key": user.getKey()], "jstatus": "In Progress"]
])

...

Code Block
languagegroovy
themeEclipse
firstline1
titleupdateRows usage example
linenumberstrue
collapsetrue
// This script moves all rows assigned to a current user in status "In Review"
// to status "Closed" in a Grid custom field with default configuration named
// "API sampleSample" in issue TEST-1

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser

// Get issue id
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
Issue issue = issueManager.getIssueObject("TEST-1")
Long issueId = issue.getId()

// Get TGNG custom field id
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class)
CustomField tgngCustomField = customFieldManager.getCustomFieldObjectsByName("API sampleSample").get(0)
Long tgngCustomFieldId = tgngCustomField.getIdAsLong()

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get GridService
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService")
def gridService = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass)

// Get GridRow class
Class gridRowClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridRow")

// Read field data
def fieldData = gridService.readFieldData(issueId, tgngCustomFieldId, user, null)
def gridRows = fieldData.getRows()

// Update rows
def updates = new ArrayList()
for (row in gridRows) {
    def columns = row.getColumns()
    def assignee = columns.get("jassignee")
    if (assignee != null && assignee.get("key") == user.getKey() && columns.get("jstatus") == "In Review") {
        def update = gridRowClass.newInstance()
        update.setRowId(row.getRowId())
        // We need to specify only the columns which are being updated
        update.setColumns(["jstatus": "Closed"])
        updates.add(update)
    }
}

gridService.updateRows(issueId, tgngCustomFieldId, user, updates)

...

Code Block
languagegroovy
themeEclipse
firstline1
titledeleteRows usage example
linenumberstrue
collapsetrue
// This script deletes all rows assigned to a current user in status "Closed" in
// a Grid custom field with default configuration named "API sampleSample" in issue TEST-1

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser

// Get issue id
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
Issue issue = issueManager.getIssueObject("TEST-1")
Long issueId = issue.getId()

// Get TGNG custom field id
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class)
CustomField tgngCustomField = customFieldManager.getCustomFieldObjectsByName("API sampleSample").get(0)
Long tgngCustomFieldId = tgngCustomField.getIdAsLong()

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get GridService
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService")
def gridService = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass)

// Read field data
def fieldData = gridService.readFieldData(issueId, tgngCustomFieldId, user, null)
def gridRows = fieldData.getRows()

// Ids of rows to delete
def toDelete = new ArrayList()
for (row in gridRows) {
    def columns = row.getColumns()
    def assignee = columns.get("jassignee")
    if (assignee != null && assignee.get("key") == user.getKey() && columns.get("jstatus") == "Closed") {
        toDelete.add(row.getRowId())
    }
}

gridService.deleteRows(issueId, tgngCustomFieldId, user, toDelete)

...