Grid Datasource Info



Grid Datasource Info
import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.security.JiraAuthenticationContext import com.atlassian.plugin.PluginAccessor import com.atlassian.jira.user.ApplicationUser // find TGE custom fields PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); Class tgeConfigManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.config.grid.TGEGridConfigManager"); def tgeConfigManager = ComponentAccessor.getOSGiComponentInstanceOfType(tgeConfigManagerClass); List<Long> tgeCustomFieldIds = tgeConfigManager.getGridCustomFieldIds(); // get current user JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getOSGiComponentInstanceOfType(JiraAuthenticationContext.class); Object userObject = jiraAuthenticationContext.getLoggedInUser(); User user = userObject instanceof ApplicationUser ? ((ApplicationUser) userObject).getDirectoryUser() : (User) userObject; // read datasource info of the first grid Class configManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.config.grid.TGEGridConfigManager"); def configManager = ComponentAccessor.getOSGiComponentInstanceOfType(configManagerClass); StringBuilder result = new StringBuilder(); result.append(tgeCustomFieldIds.size() + " TGE field(s) found. Configurations:\n"); for (Long tgeFieldId : tgeCustomFieldIds) { def datasourceInfo = configManager.getDataSourceInfo(tgeCustomFieldIds.get(0), user); result.append("ID=" + tgeFieldId + "\n"); result.append("Configuration table name: " + datasourceInfo.getConfigurationTableName() + "\n"); result.append("Database table name: " + datasourceInfo.getDatabaseTableName() + "\n"); result.append("JDBC connection url: " + datasourceInfo.getConnectionUrl() + "\n\n"); } println(result.toString()); return result.toString();