- Created by svitlana (Deactivated), last modified on Mar 05, 2020
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 14 Next »
JAVA API for the Table Grid Next Generation
Check the javadoc for TGNG JAVA API.
JAVA API Examples
readRows usage example Expand source
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;
addRows usage example Expand source
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;
updateRows usage example Expand source
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"); //grid named 'Grid One' with the default configuration, in issue 'TEST-3' // 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(); StringBuilder columnResult = new StringBuilder(); for (column in columns.keySet()) { columnResult.append("column ID: " + column + ", value: " + columns.get(column) + ", " + System.lineSeparator()) } result.append("Grid ID=" + tgeCustomFieldId + ", row ID: " + rowId + ", columns " + columnResult + "<br>") } return result;
- No labels