How to restrict custom report visibility?

hunsen lu January 5, 2013

hi, here's the thing.

We have a couple of projects created in JIRA. Let's say they are proj1 and proj2.

Now we developed a plugin with a couple of report modules in it. Let's say they are rpt1 and rpt2.

After installed the plugin to JIRA, both rpt1 and rpt2 show in the report menu of proj1 and proj2.

But what we want is that only rpt1 appears in the report menu of proj1 and only rpt2 appears in the report menu in proj2.

For now I already know that there's a method showReport() in AbstractReport class returing true or false to control report to show or not. My idea is to get the current projectId to determine whether the report should show or not. The problem is that I don't know how to get the current project id in my extended report class.

Is there anyone can help? Thanks in advance.

Here's my custom report code:

public class TurnaroundTimeReport extends AbstractReport {
 
    @Override
    public String generateReportHtml(ProjectActionSupport projectActionSupport, Map map) throws Exception {
        return descriptor.getHtml("view", getVelocityParams(projectActionSupport, map));
    }
 
    private Map<String, ?> getVelocityParams(ProjectActionSupport action, Map map) {
        ...
        ...
        final List<Map> turnaroud = getTurnaroundTimeFromProject(yearmonth, customer);
        final Map<String, Object> velocityParams = new HashMap<String, Object>();
        velocityParams.put("report", this);
        velocityParams.put("action", action);       
        velocityParams.put("turnaround", turnaroud);        
        return velocityParams;
    }
 
    @Override
    public boolean showReport() {
    // I want to get the current project id here to determine whether the report should show or not.    
    return true
    }
    
    @Override
    public boolean isExcelViewSupported() {
        return true;
    }
 
    @Override
    public String generateReportExcel(ProjectActionSupport action, Map params) {
        final StringBuilder builder = new StringBuilder(50);
        builder.append("attachment;filename=\"");
        builder.append(getDescriptor().getName());
        builder.append(".xls\";");
        HttpServletResponse response = ActionContext.getResponse();
        response.addHeader("content-disposition", builder.toString());
        return descriptor.getHtml("excel", getVelocityParams(action, params));
    }
  
    private List<Map> getTurnaroundTimeFromProject(int yearmonth, String customer) {
        ...
        ...
        return turnaround;
    }
}


					
				
			
			
			
				
			
			
			
			
			
			
		

2 answers

1 accepted

2 votes
Answer accepted
ConradR
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 27, 2013

You can get the current project with UserProjectHistoryManager:

UserProjectHistoryManager userProjectHistoryManager =  ComponentAccessor.getOSGiComponentInstanceOfType(UserProjectHistoryManager.class);

Project project = userProjectHistoryManager.getCurrentProject(Permissions.BROWSE, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser());

hunsen lu January 29, 2013

Thank you very much, Conrad Rolack. It works.

But i'm using atlassian-plugin-sdk-3.7.2, so i made a little change.

UserProjectHistoryManager userProjectHistoryManager =
ComponentManager.getComponentInstanceOfType(UserProjectHistoryManager.class);

0 votes
dleng
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2013

Hello, can you at least show abit of code so that we will know what are the classes that you actually need to use? Its hard to provide help without seeing some code.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events