Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. import com.atlassian.sal.api.component.ComponentLocator
  2. import com.atlassian.confluence.pages.CommentManager
  3. import com.atlassian.confluence.pages.PageManager
  4. import com.atlassian.confluence.spaces.SpaceManager
  5. import com.atlassian.confluence.pages.Page
  6. import com.atlassian.confluence.user.UserAccessor
  7. import com.atlassian.sal.api.user.UserKey
  8. import com.atlassian.confluence.core.DefaultSaveContext
  9. import com.atlassian.confluence.core.SaveContext
  10. import com.atlassian.confluence.event.events.content.page.PageEvent
  11. import com.atlassian.applinks.api.ApplicationLinkService
  12. import com.atlassian.applinks.api.application.jira.JiraApplicationType
  13. import com.atlassian.sal.api.net.Response
  14. import com.atlassian.sal.api.net.ResponseException
  15. import com.atlassian.sal.api.net.ResponseHandler
  16. import com.onresolve.scriptrunner.runner.customisers.WithPlugin
  17. import groovy.json.JsonBuilder
  18. import groovy.json.JsonSlurper
  19. import org.apache.http.util.EntityUtils
  20. import org.jsoup.Jsoup
  21. import org.jsoup.nodes.Document
  22. import org.jsoup.nodes.Element
  23. import static com.atlassian.sal.api.net.Request.MethodType.POST
  24. import org.apache.log4j.Level
  25. import org.apache.log4j.Logger
  26.  
  27. log = Logger.getLogger("com.test.Page")
  28. log.setLevel(Level.DEBUG)
  29.  
  30. def pageManager = ComponentLocator.getComponent(PageManager)
  31. def entityUtils = ComponentLocator.getComponent(EntityUtils)
  32. def response = ComponentLocator.getComponent(Response)
  33. def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
  34. def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
  35. def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
  36.  
  37. def page = pageManager.getPage('OP','2019-10-09 Meeting notes')
  38. def text_page = page.getBodyAsString()
  39.  
  40. def doc = Jsoup.parse(text_page)
  41. def element = doc.select("td")
  42. def result = element.collect {it.text()}
  43.  
  44. for (int i = 0; i < result.size(); i = i + 6){
  45. def body = new JsonBuilder([
  46. fields: [
  47. project : [key: "QQ"],
  48. issuetype : [name: "Техническая консультация"],
  49. summary : result[ i+1],
  50. description: result[i+2],
  51. //assignee : [result[i+3]],
  52. //priority : [result[i+4]],
  53. //customfield_11801 : result[i+5],
  54. //remotelink: [globalId: "appId=5aac7244-e0d3-31df-a7f5-d93dce867807&pageId=10748184", application: {type: "com.atlassian.confluence"}, relationship:"Wiki Page", object:[url:"http://confluence-test-app.sands.local/pages/viewpage.action?pageId=10748184", title:"Wiki Page"]]
  55. ]
  56. ]).toString()
  57.  
  58.  
  59. def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/issue")
  60. .addHeader("Content-Type", "application/json")
  61. .setEntity(body)
  62. request.execute(new ResponseHandler<Response>() {
  63. @Override
  64. void handle(Response response) throws ResponseException {
  65. if (response.statusCode != 201) {
  66. log.error("Creating Jira issue failed: ${response.responseBodyAsString}")
  67. }
  68. }
  69. })
  70.  
  71. def value = responce.getResponseBodyAsString()
  72. def s = entityUtils.toString()
  73.  
  74. //def jsonSlurper = new JsonSlurper()
  75. //def issue = JsonSlurper.parseText(s)
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement