Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need review of the approach "Select all assignees for all issues in the particular project"

Arseny Kovalchuk December 26, 2011

Hi all. I'm writing a JIRA plugin with a gadget that uses JIRA REST services to retrieve different information using AJAX and displays this within UI blocks with visual effects. Don't ask me why :). The one point of the UI is the UI should display the projects that are currently avaliable for logged in user. That's not a problem. Than I need a faceted filter in UI that should display all executors (aka asignees) for selected project. In other words, I need to get all assignees from all issues in the current project. When the project is not selected, facet filter should display all different assignees for all issues avaliable to the logged in user. Each record in the faceted filter should display a count of issues. For example:

All Projects (3) <--- All projects is selected

Project One (1)

Project Two (2)

---------------

User One (1) <--- These links should display the count of issues of the Assignee in (All Projects)

User Two (1)

User Three (1)

I wrote following REST resource to get neccessary information. But it realy looks inefficient! Could you please review the source below. JIRA API 4.4.

So, the question: Is there more efficient way to get "all assignees for all issues in the particular project (all projects)"?

The list of usefull helpers, services, utils is very appriciated.

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.search.SearchException;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.jql.builder.JqlQueryBuilder;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.query.Query;
import com.atlassian.query.order.SortOrder;
import com.telesoftservice.jira.plugin.entity.UserEntity;
import com.telesoftservice.jira.plugin.entity.UserEntityFactory;

/**
 * TODO : docs
 * 
 * @author Arseny Kovalchuk
 */
@Path("/executors")
public class ExecutorFilterResource
{

    private static final Log logger = LogFactory.getLog(ExecutorFilterResource.class);
    
    private SearchService searchService;
    private JiraAuthenticationContext authenticationContext;

    @Context
    private UriInfo uriInfo;
    @Context
    private HttpServletRequest httpServletRequest; 

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/project/{projectKey}/{filter}")
    public Response getIssuesByExecutor(@DefaultValue("all") @PathParam("projectKey") String projectKey,
                                        @DefaultValue("all") @PathParam("filter") String filter)
    {
        User currentUser = authenticationContext.getLoggedInUser();
        
        if (null == currentUser)
            return Response.status(Status.UNAUTHORIZED).build();
        
        SearchResults results = null;
        JqlQueryBuilder jqlQueryBuilder = JqlQueryBuilder.newBuilder();
        Query query = null;
        if (!"all".equals(projectKey))
        {
            jqlQueryBuilder.orderBy().createdDate(SortOrder.DESC, true).issueKey(SortOrder.ASC);
            jqlQueryBuilder.where().project(projectKey);
            query = jqlQueryBuilder.buildQuery();
        }
        else
        {
            jqlQueryBuilder.orderBy().createdDate(SortOrder.DESC, true).issueKey(SortOrder.ASC);
            query = jqlQueryBuilder.buildQuery();
        }
        try
        {
            results = searchService.search(currentUser, query, PagerFilter.getUnlimitedFilter());
        }
        catch (SearchException e)
        {
            logger.error(e);
            return Response.serverError().build();
        }
        List&lt;Issue&gt; issues = results.getIssues();
        Map&lt;String, UserEntity&gt; users = new HashMap&lt;String, UserEntity&gt;();
        for(Issue issue : issues)
        {
            User assignee = issue.getAssigneeUser();
            if (null != assignee)
            {
                users.put(assignee.getName(), UserEntityFactory.buildUserEntity(assignee, uriInfo, httpServletRequest));
            }
        }
        // TODO : manage unassigned
        return Response.ok(users.values()).build();
    }
    
    public void setSearchService(SearchService searchService)
    {
        this.searchService = searchService;
    }

    public void setAuthenticationContext(JiraAuthenticationContext authenticationContext)
    {
        this.authenticationContext = authenticationContext;
    }


}

Thanks in advance.

PS. Unfortunately I don't have JIRA sources, so it is quite difficult to obtain neccessary information based only on weak java-docs and "hello world" samples on docs sites.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Pawel Zienkiewicz August 13, 2012

Hi,

As far as I tried use this feature I found that orderBy anw where clauses must have endWhere() and endOrderBy() methods:

jqlQueryBuilder.orderBy().createdDate(SortOrder.DESC, true).issueKey(SortOrder.ASC).endOrderBy();

jqlQueryBuilder.where().project(projectKey).endWhere();

TAGS
AUG Leaders

Atlassian Community Events