...
JAVA API Examples
readRows
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
Read data of the grid. @param issueId - id of the issue where rows should be added @param customFieldId - id of the grid custom field where data should be read from @param user - Jira user which will be used to control permissions @param columnIds - set of columns' ids to filter columns for the returned result @return object of Grid meta data and rows GridFieldData readFieldData(Long issueId, CustomFieldId customFieldId, ApplicationUser user, Set<String> columnIds); |
...
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
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
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
Add rows to the grid. @param issueId - id of the issue where rows should be added @param customFieldId - id of the grid custom field where data should be added @param rows - list of maps with columns' ids and values @param user - Jira user which will be used to control permissions @return list of rows' ids List<String> addRows(Long issueId, CustomFieldId customFieldId, List<Map<String, Object>> rows, ApplicationUser user); |
...
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
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
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
Update rows of the grid. @param issueId - id of the issue where rows should be added @param customFieldId - id of the grid custom field where data should be added @param changes - list object that represent changes for specific rows @param user - Jira user which will be used to control permissions void updateRows(Long issueId, CustomFieldId customFieldId, List<GridRow> changes, ApplicationUser user); |
...
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
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; |
GridRows class
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
public class GridRow { private String rowId; private Map<String, Object> columns; private Long order; public GridRow() {} public GridRow(String rowId, Map<String, Object> columns) { this.rowId = rowId; this.columns = columns; } public GridRow(String rowId, Map<String, Object> columns, Long order) { this.rowId = rowId; this.columns = columns; this.order = order; } ... } |
GridFieldDate class
Code Block | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
public class GridFieldData { private String customFieldId; private String description; private List<GridRow> rows; public GridFieldData() {} ... } |
...