View Javadoc

1   package com.atlassian.jira.plugin.issuetabpanel;
2   
3   import java.util.ArrayList;
4   import java.util.HashMap;
5   import java.util.List;
6   import java.util.Map;
7   
8   import javax.servlet.http.Cookie;
9   
10  import org.apache.log4j.Category;
11  import org.ofbiz.core.entity.GenericValue;
12  
13  import com.atlassian.jira.config.GradientColors;
14  import com.atlassian.jira.issue.Issue;
15  import com.atlassian.jira.issue.IssueFactory;
16  import com.atlassian.jira.issue.action.GenericAction;
17  import com.atlassian.jira.issue.worklog.WorklogHelper;
18  import com.atlassian.jira.plugin.report.provider.IReportDefinitionProvider;
19  import com.atlassian.jira.plugin.report.provider.ReportDefinition;
20  import com.atlassian.jira.plugin.report.workload.AWorkloadReport;
21  import com.atlassian.jira.plugin.report.workload.WorkloadHelper;
22  import com.atlassian.jira.plugin.report.workload.WorkloadProjectGroupData;
23  import com.atlassian.jira.plugin.report.workload.provider.IWorkloadReportDefinitionProvider;
24  import com.atlassian.jira.plugin.report.workload.provider.WorkloadIssuePanelReportDefinitionProvider;
25  import com.atlassian.jira.plugin.util.ModuleDescriptorUtils;
26  import com.atlassian.jira.security.JiraAuthenticationContext;
27  import com.atlassian.jira.util.ConglomerateCookieUtils;
28  import com.atlassian.jira.util.DateTools;
29  import com.atlassian.jira.util.EasyList;
30  import com.atlassian.jira.web.bean.I18nBean;
31  import com.atlassian.plugin.ModuleDescriptor;
32  import com.opensymphony.user.User;
33  
34  import fr.kaamelot.reporter.AGroupData;
35  
36  /**
37   * Provides the new Issue Worklog Panel
38   * 
39   * @author Kaamelot - 2006
40   * @history - 08 Nov. 2006 - Class Creation
41   * 
42   */
43  public class WorklogTabPanel extends AIssueTabPanel implements IssueTabPanel, IWorkloadReportDefinitionProvider {
44  
45  	public static final String RESOURCE_NAME_VIEW = "view";
46  	private static final Category log = Category.getInstance(WorklogTabPanel.class);
47  	
48  	protected WorklogHelper worklogHelper;
49  	protected WorkloadHelper workloadHelper;
50  	protected static List i18nLocations = new ArrayList();
51  	protected I18nBean i18nBean;
52  	
53  	protected static String WORKLOG_COOKIE_NAME = "jira.panel.worklogs";
54  	protected static String DEFAULT_REPORT_KEY = WKL_ASSIGNEE  + "," + WKL_WORKLOGTYPE + "," + WKL_WORKED_WEEK;
55  		
56  	public WorklogTabPanel(IssueFactory issueFactory, final JiraAuthenticationContext authenticationContext, WorklogHelper worklogHelper, WorkloadHelper workloadHelper) {
57  		super(issueFactory, authenticationContext);		
58  		this.worklogHelper = worklogHelper;
59  		this.workloadHelper = workloadHelper;
60  	}
61  
62  	public void init(IssueTabPanelModuleDescriptor descriptor) {
63  		super.init(descriptor);
64  	}
65  	
66  	protected Cookie[] getCookies() {
67  		return webwork.action.ActionContext.getRequest().getCookies();		
68  	}
69  	
70  	public String getReportKey() {
71  //		String value =	ConglomerateCookieUtils.readFromConglomerateCookie(WORKLOG_COOKIE_NAME, "reportId", DEFAULT_REPORT_KEY);
72  		String value = ConglomerateCookieUtils.getValueFromCookie("reportId", DEFAULT_REPORT_KEY);
73  		return value.replace('#',',');
74  	}
75  
76  	public Map getVelocityParameters(Issue issue) {
77  		Map velocityParams = new HashMap();
78  		Map reqParams = new HashMap();
79  		Map queryParams = new HashMap();
80  		AGroupData grpData = null;
81  		User remoteUser = getRemoteUser();
82  		int nbCriteria = 0;
83  
84  		try {
85  			String reportKey = getReportKey();
86  			ReportDefinition wrd = (ReportDefinition)getReportDefinitionProvider().getReportDefinition(reportKey);
87  			nbCriteria = wrd.getReportElements().size();			
88  			
89  			queryParams.put("reportKey",reportKey);
90  			queryParams.put("reportDefinition",wrd);
91  			queryParams.put("reportDefinitionProvider",getReportDefinitionProvider());
92  			
93  			reqParams.put("issue", issue.getId());
94  			List worklogs = workloadHelper.getIssueWorkLogs(remoteUser, wrd, reqParams, queryParams);
95  			
96  			grpData = getGroupData();
97  			workloadHelper.configureAgregation(wrd, grpData, queryParams);
98  			workloadHelper.performAgregation(grpData,worklogs);
99  		} catch (Exception e) {
100 			log.info("",e);
101 			velocityParams.put("error", e.getMessage());
102 		}
103 		
104 		velocityParams.putAll(queryParams);
105 		velocityParams.putAll(super.getVelocityParameters(issue));
106 		velocityParams.put("report", this);
107 		velocityParams.put("dateTools", new DateTools());		
108 		velocityParams.put("rootGrpData", grpData);
109 		velocityParams.put("unitType", "2");
110 		velocityParams.put("i18n", getI18nBean());
111 		velocityParams.put("gradientsColors", GradientColors.getGradientsColors(nbCriteria));
112 		velocityParams.put("velocityParams", velocityParams);
113 
114 		velocityParams.put("reportType", RESOURCE_NAME_VIEW);		
115 //		velocityParams.put("dateUnitType", new DateUnitTypeGenerator());
116 //		velocityParams.put("issueBean", IssueBeanHelper.getInstance());
117 
118 		return velocityParams;
119 	}
120 	
121 	public List getActions(GenericValue _gvIssue, User _user) {
122 		Map params = getVelocityParameters(_gvIssue);
123 		GenericAction action = new GenericAction(_user, getDescriptor(), params);
124 		return EasyList.build(action);
125 	}
126 	
127 	/** @return Dedicated Report Definition Provider 
128 	 */
129 	public IReportDefinitionProvider getReportDefinitionProvider() {
130 		return WorkloadIssuePanelReportDefinitionProvider.getInstance();
131 	}
132 	
133 	protected AGroupData getGroupData() {
134 		return new WorkloadProjectGroupData(null, null);
135 	}
136 
137 	public I18nBean getI18nBean() {
138 		return ModuleDescriptorUtils.getI18nBean(authenticationContext, getDescriptor(), getI18nLocations());
139 	}
140 	
141 	public List getI18nLocations() {
142 		if (i18nLocations.isEmpty()) {
143 			initI18nLocation();
144 		}
145 		return i18nLocations;
146 	}
147 	
148 	protected void initI18nLocation() {
149 		synchronized (i18nLocations) {
150 			i18nLocations.addAll(getDescriptor().getI18nBean().getI18nLocations());
151 			i18nLocations.add(AWorkloadReport.I18N_RESSOURCE);
152 		}
153 	}
154 
155 }