View Javadoc

1   package com.atlassian.jira.workflow;
2   
3   import java.util.Iterator;
4   import java.util.Map;
5   
6   import org.apache.log4j.Category;
7   
8   import com.atlassian.jira.bc.issue.comment.CommentService;
9   import com.atlassian.jira.issue.MutableIssue;
10  import com.atlassian.jira.issue.customfields.view.CustomFieldParams;
11  import com.atlassian.jira.issue.fields.OrderableField;
12  import com.atlassian.jira.issue.fields.screen.FieldScreenRenderLayoutItem;
13  import com.atlassian.jira.issue.fields.screen.FieldScreenRenderTab;
14  import com.atlassian.jira.issue.fields.screen.FieldScreenRendererFactory;
15  import com.atlassian.jira.security.JiraAuthenticationContext;
16  import com.atlassian.jira.security.PermissionManager;
17  import com.atlassian.jira.util.ErrorCollection;
18  import com.opensymphony.user.UserManager;
19  
20  /**
21   * FQCN : com.atlassian.jira.workflow.WorkflowTransitionUtilAddOnImpl
22   * @author Kaamelot
23   * @since 2005
24   * Description : Provides capacity to perform a Transition assuming Previous Field values as unchanged when Field is present in Transition Screen.
25   * Required for Transition Jelly Tag and Auto Transition Service.
26   *
27   */
28  public class WorkflowTransitionUtilAddOnImpl extends WorkflowTransitionUtilImpl {
29  	
30  	protected final static Category log = Category.getInstance(WorkflowTransitionUtilAddOnImpl.class);
31  	
32  	public static String UNCHANGED_VALUE_FIELD = "--unchanged--"; 
33  
34  	protected WorkflowManager workflowManager;
35  	protected UserManager userManager;
36  	protected Map params;
37  
38  	/**
39  	 * @param authenticationContext
40  	 * @param projectManager
41  	 * @param workflowManager
42  	 * @param permissionManager
43  	 * @param applicationProperties
44  	 * @param versionManager
45  	 * @param constantsManager
46  	 */
47  
48      public WorkflowTransitionUtilAddOnImpl(final JiraAuthenticationContext _authenticationContext, final WorkflowManager _workflowManager, 
49      		final PermissionManager _permissionManager, final FieldScreenRendererFactory _fieldScreenRendererFactory, final CommentService _commentService) {
50  		super(_authenticationContext, _workflowManager, _permissionManager, _fieldScreenRendererFactory, _commentService);
51  		workflowManager = _workflowManager;
52  		userManager = UserManager.getInstance();
53  	}
54  
55     /**
56      * Hack required, because there is no accessor on WorkflowTransitionUtilImpl.param !!!
57      */
58  	public void setParams(Map params) {
59  		super.setParams(params);
60  		this.params = params;
61  	}
62  
63  	/**
64  	 * Performs a pre-Validation in order to intiate Field with Default Values
65  	 */
66  	public ErrorCollection validate() {
67  		for (Iterator iterator = getFieldScreenRenderer().getFieldScreenRenderTabs().iterator(); iterator.hasNext();) {
68  			FieldScreenRenderTab fieldScreenRenderTab = (FieldScreenRenderTab) iterator.next();
69  			for (Iterator iterator1 = fieldScreenRenderTab.getFieldScreenRenderLayoutItemsForProcessing().iterator(); iterator1.hasNext();) {
70  				FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem = (FieldScreenRenderLayoutItem) iterator1.next();
71  				if (fieldScreenRenderLayoutItem.isShow(getIssue())) {
72  					OrderableField orderableField = fieldScreenRenderLayoutItem.getOrderableField();
73  					setDefaultValue(orderableField, getIssue());
74  				}
75  			}
76  		}
77  
78  		return super.validate();
79  	}
80  
81  	/**
82  	 * @param _orderableField Field to valuate with a Default Value (Previous value) if it is mark as UNCHANGED  
83  	 * @param _issue Conecrned Issue
84  	 */
85  	protected void setDefaultValue(OrderableField _orderableField, MutableIssue _issue) {
86  		String fieldId = _orderableField.getId();
87  		Object param = this.params.get(fieldId);
88  		if (param != null) {
89  			if (param instanceof String) {
90  				if (param.equals(UNCHANGED_VALUE_FIELD)) {
91  					_orderableField.populateFromIssue(params, _issue); 
92  				}
93  			} else if (param instanceof CustomFieldParams) {
94  				Object customFieldValue = ((CustomFieldParams)param).getValuesForNullKey().toArray()[0];
95  				if (customFieldValue instanceof String) {
96  					if (customFieldValue.equals(UNCHANGED_VALUE_FIELD) ) {
97  						_orderableField.populateFromIssue(params, _issue); 
98  					}
99  				}
100 			}
101 		}
102 	}
103 
104 }