Versions Compared

Key

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

...

Excerpt

JAVA API for the Table Grid Next Generation


Table Grid Next Generation javadoc for JAVA APIĀ 

JAVA API Examples

...

Code Block
languagejava
themeEclipse
firstline1
titlereadRows method script example usage
linenumberstrue
collapsetrue
import com.atlassian.crowd.embedded.api.User;
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.jira.security.JiraAuthenticationContext;
import com.atlassian.plugin.PluginAccessor;
import com.atlassian.jira.user.ApplicationUser;
import org.apache.log4j.Logger;

// set up logger
Logger log=Logger.getLogger("com.idalko.scripts");

// get an issue
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("TEST-3");
Long issueId = issue.getId().toLong();

// get TGE custom field
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class);
CustomField tgeCustomField = customFieldManager.getCustomFieldObjectsByName("Grid One").get(0);
Long tgeCustomFieldId = tgeCustomField.getIdAsLong();

ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// read grid data
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService");
def gridFieldData = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass);

StringBuilder result = new StringBuilder();
def callResult = null;

try {
    callResult = gridFieldData.readFieldData(issueId, tgeCustomFieldId, applicationUser, null);
} catch (Exception e) {
    log.error(e.getMessage())
}
    def gridRows = callResult.getRows()

for (row in gridRows) {
    def columns = row.getColumns();
    def rowId = row.getRowId();
    //log.error(columns.toString())
    StringBuilder tempResult = new StringBuilder();
    
    for (column in columns.keySet()) {
        tempResult.append("column ID: " + column + ", value: " + columns.get(column) + ", " + System.lineSeparator())        
    }
    
    result.append("Grid ID=" + tgeCustomFieldId + ", row ID: " + rowId + ", columns " + tempResult + "<br>")
}


return result;

...

Code Block
languagejava
themeEclipse
firstline1
titleaddRows method script example usage
linenumberstrue
collapsetrue
import com.atlassian.crowd.embedded.api.User;
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.jira.security.JiraAuthenticationContext;
import com.atlassian.plugin.PluginAccessor;
import com.atlassian.jira.user.ApplicationUser;
import org.apache.log4j.Logger;

// set up logger
Logger log=Logger.getLogger("com.idalko.scripts");

// get an issue
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("TEST-3");
Long issueId = issue.getId().toLong();

// get TGE custom field
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class);
CustomField tgeCustomField = customFieldManager.getCustomFieldObjectsByName("Grid One").get(0);
Long tgeCustomFieldId = tgeCustomField.getIdAsLong();

ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// read grid data
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService");
def gridFieldData = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass);

StringBuilder result = new StringBuilder();
def callResult = null;

try {
    callResult = gridFieldData.readFieldData(issueId, tgeCustomFieldId, applicationUser, null);
} catch (Exception e) {
    log.error(e.getMessage())
}

// let's add some rows
Map<String, Object> row = new HashMap<String, Object>();
row.put("jseq", callResult.getRows().get(callResult.getRows().size() - 1).getColumns().get("jseq") + 1);
row.put("jsummary", "Some summary");
row.put("jstatus", "Done");

//Script Runner can show validation errors here as well. Ignore them.
try {
    List<Long> rowIds = gridFieldData.addRows(issue.getId(), tgeCustomFieldId, applicationUser, [row]);
    result.append("Grid ID=" + tgeCustomFieldId + " data was successfully added. IDs of added rows: " + rowIds + "\n");
} catch (Exception e) {
    log.error(e.getMessage())
}

return result;

...