/src/main/java/com/atlassian/jira/collector/plugin/web/admin/ViewCollectors.java
Java | 102 lines | 85 code | 12 blank | 5 comment | 3 complexity | 673e9fb52b40f49e3c5afa710a4dcbf4 MD5 | raw file
- package com.atlassian.jira.collector.plugin.web.admin;
- import com.atlassian.jira.bc.ServiceOutcome;
- import com.atlassian.jira.bc.project.ProjectService;
- import com.atlassian.jira.collector.plugin.components.Collector;
- import com.atlassian.jira.config.ConstantsManager;
- import com.atlassian.jira.issue.issuetype.IssueType;
- import com.atlassian.jira.plugin.profile.UserFormatManager;
- import com.atlassian.jira.project.Project;
- import com.atlassian.jira.web.action.JiraWebActionSupport;
- import com.atlassian.jira.collector.plugin.components.CollectorActivityHelper;
- import com.atlassian.jira.collector.plugin.components.CollectorService;
- import com.atlassian.sal.api.websudo.WebSudoRequired;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * Lists all the collectors currently defined
- *
- * @since v1.0
- */
- @WebSudoRequired
- public class ViewCollectors extends JiraWebActionSupport
- {
- private final CollectorService collectorService;
- private final ProjectService projectService;
- private final ConstantsManager constantsManager;
- private final UserFormatManager userFormatManager;
- private final CollectorActivityHelper collectorActivityHelper;
- private List<Collector> collectors;
- private Map<String, List<Integer>> collectorActivty = new HashMap<String, List<Integer>>();
- public ViewCollectors(final CollectorService collectorService, final ProjectService projectService,
- final ConstantsManager constantsManager, final UserFormatManager userFormatManager,
- final CollectorActivityHelper collectorActivityHelper)
- {
- this.collectorService = collectorService;
- this.projectService = projectService;
- this.constantsManager = constantsManager;
- this.userFormatManager = userFormatManager;
- this.collectorActivityHelper = collectorActivityHelper;
- }
- @Override
- public String doDefault() throws Exception
- {
- ServiceOutcome<List<Collector>> result = collectorService.getCollectors(getLoggedInUser());
- if (!result.isValid())
- {
- return ERROR;
- }
- collectors = result.getReturnedValue();
- return SUCCESS;
- }
- public List<Collector> getCollectors()
- {
- return collectors;
- }
- public Project getProject(Long projectId)
- {
- return projectService.getProjectById(getLoggedInUser(), projectId).getProject();
- }
- public IssueType getIssueType(Long issueTypeId)
- {
- return constantsManager.getIssueTypeObject(issueTypeId.toString());
- }
- public String getFormattedUser(String username)
- {
- return userFormatManager.getUserFormat("profileLinkActionHeader").format(username, "collector-reporter");
- }
- public List<Integer> getActivityForCollector(final Collector collector)
- {
- if (!collectorActivty.containsKey(collector.getId()))
- {
- collectorActivty.put(collector.getId(), collectorActivityHelper.getIssuesCreatedPerDay(getLoggedInUser(), collector, 30));
- }
- return collectorActivty.get(collector.getId());
- }
- public int getTotalNumberOfIssuesForCollector(final Collector collector)
- {
- final List<Integer> activityForCollector = getActivityForCollector(collector);
- int sum = 0;
- for (Integer issuesCreated : activityForCollector)
- {
- sum += issuesCreated;
- }
- return sum;
- }
- public String getActivityUrl(final Collector collector)
- {
- return collectorActivityHelper.getIssueNavigatorUrl(getLoggedInUser(), collector);
- }
- }