View Javadoc

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   * FQCN : com.atlassian.jira.service.AutoTransitionService
19   * 
20   * @author Kaamelot
21   * @since 3.10.1.30 
22   * @version 3.10.1.34
23   * Description : Provides an Auto Transition Service using  AutoTransitionManager 
24   * - Issues are scanned depending a RequestFilter 
25   * - Delegates Auto-Transition to AutoTransitionManager 
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  	// -- Service Parameters Key
34  
35  	public static String PROJECT_KEY = "PROJECT";
36  
37  	public static String CATEGORY_KEY = "CATEGORY";
38  
39  	// -- Service Parameters
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  	/** DO NOTHING
55  	 * @throws ServiceException
56  	 */
57  	public void validate() throws ServiceException {
58  		// TODO Auto-generated method stub
59  	}
60  
61  	/**
62  	 * @return Object Configuration descriptor for current Service
63  	 */
64  	public ObjectConfiguration getObjectConfiguration() throws ObjectConfigurationException {
65  		return getObjectConfiguration("AUTOTRANSITIONSERVICE", "services/com/atlassian/jira/service/autoTransition.xml", null);
66  	}
67  
68  	/**
69  	 * End of Service
70  	 */
71  	public void destroy() {
72  		log.debug("AutoTransitionService being destroyed");
73  	}
74  
75  	/**
76  	 * Service Initialisation
77  	 * 
78  	 * @param _props Properies to use for Initialisation
79  	 * @throws ObjectConfigurationException n/a
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  	 * @return A SearchRequest depending on Service Parameters
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 }