Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. import com.atlassian.jira.component.ComponentAccessor
  2. import com.atlassian.jira.user.ApplicationUser
  3. import com.atlassian.jira.issue.fields.config.FieldConfig
  4. import com.atlassian.jira.issue.fields.CustomField
  5. import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
  6. import com.atlassian.jira.issue.customfields.option.OptionsImpl
  7. import java.text.SimpleDateFormat
  8. import java.util.Date
  9. import org.joda.time.DateTime
  10. import org.apache.log4j.Level
  11. import org.apache.log4j.Logger
  12. log = Logger.getLogger("com.tvpro.CreateIssue")
  13. log.setLevel(Level.DEBUG)
  14.  
  15. def locale = ComponentAccessor.applicationProperties.defaultLocale
  16. def simpleDateFormat = new SimpleDateFormat("dd/MMM/yy HH:mm", locale)
  17. def newSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX")
  18.  
  19. def linkMgr = ComponentAccessor.getIssueLinkManager()
  20. def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("PP1-18842")
  21. def customField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11601")
  22. def dataVihodaEfira = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11504") //Дата выхода рубрики в эфир
  23. def dataVihodaEfiraValueOld = issue.getCustomFieldValue(dataVihodaEfira)
  24. def dataVihodaEfiraValueNew = simpleDateFormat.format(dataVihodaEfira.getValue(issue))
  25. def Deadline = simpleDateFormat.format(new DateTime(dataVihodaEfiraValueOld).minusDays(1).toDate()) // Заполняем поле Deadline
  26. log.debug("Дата выхода рубрики в эфир в задаче Промо: " + dataVihodaEfiraValueOld)
  27. log.debug("Дата выхода рубрики в эфир для задачи Оперативная графика: " + dataVihodaEfiraValueNew)
  28. log.debug("Дата делайна для Оперативной графики: " + Deadline)
  29.  
  30.  
  31. def rubrika = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10501") //Рубрика
  32. String rubrikaValueId = rubrika.getValue(issue)?.optionId
  33. def rubrikaValue = rubrika.getValue(issue)
  34. log.debug("Рубрика: " + rubrikaValue)
  35.  
  36. def znachimost = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11508") //Значимость
  37. String znachimostValueId = znachimost.getValue(issue)?.optionId
  38. def znachimostValue = znachimost.getValue(issue)
  39. log.debug("Значимость: " + znachimostValue)
  40.  
  41. def graficaDescription = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11502") // Графика - описание идеи/расписание
  42. def graficaDescriptionValue = graficaDescription.getValue(issue)
  43. log.debug("Графика - описание идеи/расписание: " + graficaDescriptionValue)
  44.  
  45. def valueCF = customField.getValue(issue)*.value
  46. if ("Моушен" in valueCF) {
  47.  
  48. def issueTypeName = "Оперативная графика"
  49. def issueService = ComponentAccessor.issueService
  50. def constantsManager = ComponentAccessor.constantsManager
  51. def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
  52. def projectId = ComponentAccessor.projectManager.getProjectByCurrentKey("SDTEST")
  53. log.debug(projectId.getId())
  54. def issueType = constantsManager.allIssueTypeObjects.findByName(issueTypeName)
  55. log.debug(issueType.id)
  56. def reporter = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
  57. log.debug(reporter.getKey())
  58. def priority = constantsManager.priorities.findByName("Major") ?: constantsManager.defaultPriority
  59. log.debug(priority.id)
  60. def issueInputParameters = issueService.newIssueInputParameters().with {
  61. setProjectId(projectId.getId())
  62. setIssueTypeId(issueType.id)
  63. setReporterId(reporter.getKey())
  64. setSummary(issue.summary)
  65. setPriorityId(priority.id)
  66. setDescription(graficaDescriptionValue)
  67. addCustomFieldValue("customfield_11504", dataVihodaEfiraValueNew)
  68. addCustomFieldValue("customfield_10501", rubrikaValueId)
  69. addCustomFieldValue("customfield_11508", znachimostValueId)
  70. //addCustomFieldValue("customfield_13503", [12345, 12345]) // Шаблоны
  71. addCustomFieldValue("customfield_12500", Deadline) // Deadline
  72.  
  73. }
  74. def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
  75. log.debug(validationResult.errorCollection)
  76. def result = issueService.create(loggedInUser, validationResult)
  77. log.debug(result.issue.id)
  78. linkMgr.createIssueLink(issue.id, result.issue.id, 10000, 1, loggedInUser)
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement