jira-plugin-intellij /src/test/resources/examples/CreateJob.groovy

Language Groovy Lines 201
MD5 Hash 8c8634dc8dcee058d73e1278ccf0614f
Repository https://bitbucket.org/sorin/jira-plugin-intellij View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package examples

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import org.apache.log4j.Level
import com.atlassian.jira.web.bean.MoveIssueBean
import com.atlassian.jira.web.action.issue.MoveIssueUpdateFields
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.bc.issue.comment.CommentService
import com.atlassian.jira.issue.security.IssueSecurityHelper
import webwork.action.ActionContext
import com.atlassian.jira.web.SessionKeys
import com.atlassian.jira.web.action.issue.MoveIssueConfirm
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.IssueManager
import com.atlassian.core.ofbiz.util.CoreTransactionUtil
import com.atlassian.jira.ManagerFactory
import org.quartz.Scheduler
import org.quartz.helpers.TriggerUtils
import org.quartz.SimpleTrigger
import org.quartz.JobDetail
import com.onresolve.jira.groovy.TestJob
import org.quartz.Trigger
import org.quartz.JobDataMap
import com.atlassian.jira.issue.Issue
import com.opensymphony.user.UserManager
import com.opensymphony.user.User

// CoreTransactionUtil.commit(true)

// boolean began = CoreTransactionUtil.begin()

public final String JOB_NAME = "SomeTestJob"
public final String TRIGGER_NAME = "SomeTestTrigger"

System.setProperty("atlassian.mail.senddisabled", "false")

Issue issue
ComponentManager componentManager = ComponentManager.getInstance()

User currentUser

currentUser.getGroups().contains("a b") && ! issue.repo

String cat = componentManager.getProjectManager().getProjectCategoryFromProject(issue.getProject()).get("name")
issue.getProjectObject()


Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)

Scheduler scheduler = ManagerFactory.getScheduler()
(scheduler.getJobGroupNames() as List).each {String group ->
    (scheduler.getJobNames(group) as List).each {String jobName ->
        log.debug scheduler.getJobDetail(jobName, group)
        // log.debug scheduler.getJobDetail(jobName, group).getJobDataMap().toMapString()
    }
}

(scheduler.getTriggerGroupNames() as List).each {String group ->
    (scheduler.getTriggerNames(group) as List).each {String t ->
        Trigger trigger = scheduler.getTrigger(t, group)
        log.debug trigger
        if (trigger.getJobName() == JOB_NAME || trigger.getName() == TRIGGER_NAME) {
            log.debug("Unscheduling $t")
            scheduler.unscheduleJob(t, Scheduler.DEFAULT_GROUP)
        }
        // scheduler.unscheduleJob()
    }
}


scheduler.deleteJob(JOB_NAME, Scheduler.DEFAULT_GROUP)
if (!scheduler.getJobDetail(JOB_NAME, Scheduler.DEFAULT_GROUP)) {
    JobDetail jobDetail = new JobDetail(JOB_NAME,
            Scheduler.DEFAULT_GROUP,
            TestJob.class,
    );
    jobDetail.setDurability(true)
    jobDetail.setJobDataMap(new JobDataMap([issue: 10001]))

    scheduler.addJob(jobDetail, true)

}


scheduler.unscheduleJob(TRIGGER_NAME, Scheduler.DEFAULT_GROUP)
SimpleTrigger trigger = new SimpleTrigger(TRIGGER_NAME, Scheduler.DEFAULT_GROUP)


// Trigger trigger = scheduler.getTrigger("ztesxt", Scheduler.DEFAULT_GROUP)

trigger.setStartTime(new Date(System.currentTimeMillis() + 1000))
trigger.setJobGroup(Scheduler.DEFAULT_GROUP)
trigger.setJobName(JOB_NAME)

scheduler.scheduleJob(trigger)

return


// scheduler.deleteJob("xmyJob", Scheduler.DEFAULT_GROUP)

JobDetail jobDetail = new JobDetail(JOB_NAME,
        Scheduler.DEFAULT_GROUP,
        TestJob.class,
);
jobDetail.setDurability(true)

scheduler.addJob(jobDetail, true)
return

// JobDetail jobDetail = scheduler.getJobDetail("sxmyJob", Scheduler.DEFAULT_GROUP)
log.debug("jobDetail: $jobDetail")
// scheduler.scheduleJob(jobDetail, trigger)


// scheduler.rescheduleJob("tesxtxx", Scheduler.DEFAULT_GROUP, trigger)

// scheduler.unscheduleJob()
scheduler.scheduleJob(jobDetail, trigger)

return

ProjectManager projectManager = componentManager.getProjectManager()
Project targetProject = projectManager.getProjectObjByKey("JRA")
IssueManager issueManager = componentManager.getIssueManager()

MutableIssue targetIssue = issueManager.getIssueObject('GRV-100')
// MutableIssue targetIssue = issue


MoveIssueBean moveIssueBean = new MoveIssueBean(componentManager.getConstantsManager(), projectManager);
moveIssueBean.getFieldValuesHolder().put(IssueFieldConstants.PROJECT, targetProject.id)
moveIssueBean.getFieldValuesHolder().put(IssueFieldConstants.ISSUE_TYPE, "1")
moveIssueBean.setIssueId(targetIssue.id)
moveIssueBean.setTargetStatusId("1")


log.debug(moveIssueBean)
//MoveIssueUpdateFields moveIssueUpdateFields = ComponentManager.getComponentInstanceOfType(MoveIssueUpdateFields.class)
//log.debug moveIssueUpdateFields

ActionContext.getSession().put(SessionKeys.MOVEISSUEBEAN, moveIssueBean)
MoveIssueUpdateFields moveIssueUpdateFields = new MoveIssueUpdateFields(
        componentManager.getIssueLinkManager(),
        componentManager.getSubTaskManager(),
        componentManager.getConstantsManager(),
        componentManager.getWorkflowManager(),
        componentManager.getFieldManager(),
        componentManager.getFieldLayoutManager(),
        componentManager.getIssueFactory(),
        componentManager.getFieldScreenRendererFactory(),
        ComponentManager.getComponentInstanceOfType(CommentService),
        ComponentManager.getComponentInstanceOfType(IssueSecurityHelper.class)
)

MoveIssueConfirm moveIssueConfirm = new MoveIssueConfirm(
        componentManager.getIssueLinkManager(),
        componentManager.getSubTaskManager(),
        ComponentManager.getComponentInstanceOfType(AttachmentManager.class),
        componentManager.getConstantsManager(),
        componentManager.getWorkflowManager(),
        componentManager.getFieldManager(),
        componentManager.getFieldLayoutManager(),
        componentManager.getIssueFactory(),
        componentManager.getFieldScreenRendererFactory(),
        ComponentManager.getComponentInstanceOfType(CommentService),
        ComponentManager.getComponentInstanceOfType(IssueSecurityHelper.class),
        issueManager,
        componentManager.getAttachmentPathManager())


log.debug(moveIssueConfirm)
moveIssueUpdateFields.setId(targetIssue.id)
moveIssueUpdateFields.setIssue(issueManager.getIssue(targetIssue.id))
moveIssueUpdateFields.doExecute()


moveIssueConfirm.setId(targetIssue.id)
moveIssueConfirm.setIssue(issueManager.getIssue(targetIssue.id))
String execute = moveIssueConfirm.doExecute()
log.debug(moveIssueConfirm.errors)

// CoreTransactionUtil.commit(began)
return

/*
log.debug(moveIssueUpdateFields)
moveIssueUpdateFields.setId(targetIssue.id)
execute = moveIssueUpdateFields.doValidation()
log.debug moveIssueUpdateFields.getErrors()
log.debug("execute: $execute")
*/
Back to Top