You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
The following is the code I am trying to implement in the Rest Endpoint for creating a Web fragment for rendering a pdf with the result of a jql
This code does not work and it is complaining about the Permissions library and some of the static methods (which usually only complains but allows you to create the script, not in this case)
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.user.UserProjectHistoryManager
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory
import com.atlassian.jira.web.bean.*
import com.atlassian.plugin.web.api.model.WebFragmentBuilder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import org.springframework.util.FileCopyUtils
@BaseScript CustomEndpointDelegate delegate
//identify the last project accessed by the User
def lastProjectAccessed = ComponentAccessor.getComponent(UserProjectHistoryManager.class)
def projectAcessed = lastProjectAccessed.getCurrentProject(Permissions.BROWSE, ComponentAccessor.jiraAuthenticationContext.loggedInUser)
def projectName = projectAcessed.name
// PDF configuration
def userName = "admin" // this user runs the search and generates the PDF
def jql = "XXXX"
def templateName = "issue-navigator-fo.vm"
def title = "XXXX"
// run the search
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def query = jqlQueryParser.parseQuery(jql)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.userUtil.getUser(userName)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
// render the PDF
def issues = results.issues
if (issues) {
def pdfApiClass = this.class.forName('com.midori.jira.plugin.pdfview.api.PdfApi', true, ComponentAccessor.pluginAccessor.classLoader)
def pdfApi = ComponentAccessor.getOSGiComponentInstanceOfType(pdfApiClass)
ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(user)
def pdfResult = pdfApi.getPdf(templateName, title.toString(), issues, [:])
// write the pdf to a file with a timestamped filename like "example-20170526-1304.pdf")
FileCopyUtils.copy(pdfResult.bytes, new File("c:\\tmp\\example-${new Date().format('yyyyMMdd-HHmm')}.pdf"))
}
def searchService = ComponentAccessor.getComponent(SearchService)
def jiraAuthenticationContext = ComponentAccessor.getComponent(JiraAuthenticationContext)
def velocityRequestContextFactory = ComponentAccessor.getComponent(VelocityRequestContextFactory)
def requestContext = velocityRequestContextFactory.getJiraVelocityRequestContext()
def baseUrl = requestContext.getBaseUrl()
results.issues.collect { issue ->
def issueLabel = "${issue.key} ${issue.summary}"
String iconUrl = issue.issueTypeObject.iconUrl
if (!iconUrl.startsWith("http://") && !iconUrl.startsWith("https://")) {
iconUrl = baseUrl + iconUrl;
}
new WebFragmentBuilder(50).
id("sample-web-item-${issue.key.toLowerCase()}").
label(issueLabel).
title(issueLabel).
styleClass("").
addParam("class", "issue-link").
addParam("data-issue-key", issue.getKey()).
addParam("iconUrl", iconUrl).
webItem("").
url(baseUrl + "/browse/" + issue.getKey()).
build()
}
Happy New Year! We hope you all had a safe and restful holiday season. 2020 was a unique year full of unforeseen events; however, as we enter the new year of 2021, we’re optimistic for the light at t...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events