1 package com.atlassian.jira.service;
2
3 import org.apache.log4j.Category;
4 import org.apache.log4j.Logger;
5
6 import com.atlassian.configurable.ObjectConfiguration;
7 import com.atlassian.configurable.ObjectConfigurationException;
8 import com.atlassian.jira.ComponentManager;
9 import com.atlassian.jira.issue.MutableIssue;
10 import com.atlassian.jira.issue.search.SearchRequest;
11 import com.atlassian.jira.issue.search.parameters.lucene.CategoryParameter;
12 import com.atlassian.jira.issue.search.parameters.lucene.ProjectParameter;
13 import com.atlassian.jira.workflow.transition.AutoTransitionManager;
14 import com.atlassian.jira.workflow.transition.DefaultAutoTransitionManager;
15 import com.opensymphony.module.propertyset.PropertySet;
16
17
18
19
20
21
22
23
24
25
26
27 public class AutoTransitionService extends ARequestAwareService {
28
29 protected final static Category log = Logger.getInstance(AutoTransitionService.class);
30
31 protected AutoTransitionManager autoTransitionManager;
32
33
34
35 public static String PROJECT_KEY = "PROJECT";
36
37 public static String CATEGORY_KEY = "CATEGORY";
38
39
40
41 private String projectId;
42
43 private String categoryId;
44
45 public AutoTransitionService() {
46 super();
47 autoTransitionManager = (AutoTransitionManager) ComponentManager.getComponentInstanceOfType(DefaultAutoTransitionManager.class);
48 }
49
50 public void runServiceOnIssue(MutableIssue _issue) {
51 autoTransitionManager.performAutoTransition(_issue);
52 }
53
54
55
56
57 public void validate() throws ServiceException {
58
59 }
60
61
62
63
64 public ObjectConfiguration getObjectConfiguration() throws ObjectConfigurationException {
65 return getObjectConfiguration("AUTOTRANSITIONSERVICE", "services/com/atlassian/jira/service/autoTransition.xml", null);
66 }
67
68
69
70
71 public void destroy() {
72 log.debug("AutoTransitionService being destroyed");
73 }
74
75
76
77
78
79
80
81 public void init(final PropertySet _props) throws ObjectConfigurationException {
82 super.init(_props);
83 if (hasProperty(PROJECT_KEY)) {
84 projectId = getProperty(PROJECT_KEY);
85 }
86 if (hasProperty(CATEGORY_KEY)) {
87 categoryId = getProperty(CATEGORY_KEY);
88 }
89 }
90
91
92
93
94 public SearchRequest getSearchRequest() {
95 SearchRequest sr = super.getSearchRequest();
96 if (sr == null && projectId != null && !projectId.equals("-1") && !projectId.equals("")) {
97 sr = new SearchRequest(true);
98 sr.addParameter(new ProjectParameter(Long.valueOf(projectId)));
99 }
100 if (sr == null && categoryId != null && !categoryId.equals("-1") && !categoryId.equals("")) {
101 sr = new SearchRequest(true);
102 sr.addParameter(new CategoryParameter(Long.valueOf(categoryId)));
103 }
104 return sr;
105 }
106
107 }