2013-01-22 65 views
1

我想創建一個jira插件,它會更新我使用issueKey參數傳遞它的任何問題的'Assignee'。自定義Jira插件:不能更新問題

它做的一切正確,就像我得到正確的issueId和用戶,但它無法更新問題,它不會顯示任何日誌或打印出任何錯誤,但我放在servlet內的條件失敗。 我不能得到它的工作,任何建議。在這種情況下,讓我知道doGet和doPost方法。謝謝。 下面是代碼:

package com.elixir.plugins.servlet; 

import com.atlassian.crowd.embedded.api.User; 
import com.atlassian.jira.bc.issue.IssueService; 
import com.atlassian.jira.bc.issue.search.SearchService; 
import com.atlassian.jira.bc.project.ProjectService; 
import com.atlassian.jira.security.PermissionManager; 
import com.atlassian.jira.security.Permissions; 

//import com.atlassian.jira.bc.issue;//added 
import com.atlassian.jira.bc.ServiceResultImpl;//added 
import com.atlassian.jira.bc.issue.IssueService.IssueResult;//added 
import com.atlassian.jira.bc.issue.IssueService.IssueValidationResult;//added 
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult;//added 
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult;//added 

//import com.atlassian.jira.rest.v2.issue; //added 
//import com.atlassian.jira.rest.api.util.*; //added 
import com.atlassian.jira.util.ErrorCollection; //added 

//import com.atlassian.jira.issue; //added 
import com.atlassian.jira.issue.*; //added 
import com.atlassian.jira.issue.Issue; 
import com.atlassian.jira.issue.IssueInputParameters; 
import com.atlassian.jira.issue.IssueInputParametersImpl;//added 
import com.atlassian.jira.issue.worklog.Worklog;  //added 
import com.atlassian.jira.issue.worklog.WorklogManager;//added 
import com.atlassian.jira.workflow.*;//added 
import com.atlassian.jira.ComponentManager;//added 
import com.atlassian.jira.ManagerFactory;//added 
import com.atlassian.jira.component.ComponentAccessor; 
import com.atlassian.jira.security.JiraAuthenticationContext; 
import com.atlassian.jira.config.properties.APKeys; 
import com.atlassian.jira.event.issue.IssueEvent; 
import com.atlassian.jira.event.issue.IssueEventManager; 
import com.atlassian.jira.issue.MutableIssue; 
import com.atlassian.jira.issue.search.SearchException; 
import com.atlassian.jira.jql.builder.JqlClauseBuilder; 
import com.atlassian.jira.jql.builder.JqlQueryBuilder; 
import com.atlassian.jira.project.Project; 
import com.atlassian.jira.web.bean.PagerFilter; 
import com.atlassian.sal.api.user.UserManager; 
import com.atlassian.templaterenderer.TemplateRenderer; 
import com.google.common.collect.Maps; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

import com.atlassian.jira.config.properties.ApplicationProperties; //added 
import com.atlassian.jira.config.properties.ApplicationPropertiesImpl;//added 
import com.atlassian.jira.util.ImportUtils;       //added 
import com.atlassian.jira.util.JiraUtils;        //added 
import com.atlassian.jira.workflow.WorkflowTransitionUtil;   //added 
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;  //added 

import com.atlassian.core.user.*;//added 

/*import com.opensymphony.user.User; 
import com.opensymphony.user.UserManager;*/ 
import com.opensymphony.workflow.*; 
import com.opensymphony.workflow.InvalidActionException; 
import com.opensymphony.workflow.WorkflowContext; 
import com.opensymphony.workflow.loader.ActionDescriptor; 
import com.opensymphony.workflow.loader.StepDescriptor; 
import com.opensymphony.workflow.loader.AbstractDescriptor; //added 
import com.opensymphony.workflow.loader.WorkflowDescriptor; //added 
import com.atlassian.jira.workflow.ImmutableWorkflowDescriptor;//added 
import com.opensymphony.module.propertyset.PropertySet;  //added 
//import com.opensymphony.user.EntityNotFoundException;   //added 
import com.opensymphony.util.TextUtils;      //added 
import com.opensymphony.workflow.loader.ValidatorDescriptor; //added 
import com.opensymphony.workflow.loader.DescriptorFactory;  //added 
import com.opensymphony.workflow.spi.WorkflowEntry;   //added 

import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import java.io.IOException; 
import java.util.*; //added 
import java.util.HashMap; 
import java.util.HashSet; 
import java.util.List; 
import java.util.Map; 

import org.ofbiz.core.entity.GenericEntityException;//added 
import org.ofbiz.core.entity.GenericValue;   //added 

public class Unassigner extends HttpServlet { 
    private static final Logger log = LoggerFactory.getLogger(Unassigner.class); 
    private IssueService issueService; 
    private ProjectService projectService; 
    private SearchService searchService; 
    private UserManager userManager; 
    private TemplateRenderer templaterenderer; 
    private com.atlassian.jira.user.util.UserManager jiraUserManager; 

    public Unassigner(IssueService issueService, ProjectService projectService, SearchService searchService, 
        UserManager userManager, TemplateRenderer templateRenderer, 
        com.atlassian.jira.user.util.UserManager jiraUserManager) { 
     this.issueService = issueService; 
     this.projectService = projectService; 
     this.searchService = searchService; 
     this.userManager = userManager; 
     this.templaterenderer = templateRenderer; 
     this.jiraUserManager = jiraUserManager; 
    } 
    @Override 
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 
     resp.setContentType("text/html"); 
     String issueKey = req.getParameter("issue"); 
     Issue issue = ComponentAccessor.getIssueManager().getIssueObject(issueKey); 
     User loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); 
     IssueInputParameters issueInputParameters = new IssueInputParametersImpl(); 
     issueInputParameters.setAssigneeId("Unassigned"); 

     issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(false); 

     resp.getWriter().write(loggedInUser +"<br>"); 
     resp.getWriter().write(issue.getId() +"<br>"); 
     resp.getWriter().write(issueInputParameters +"<br>"); 

     IssueService issueService = ComponentManager.getInstance().getIssueService(); 
     Long issueId = issue.getId(); 
     UpdateValidationResult updateValidationResult = issueService.validateUpdate(loggedInUser, issueId, issueInputParameters); 

     resp.getWriter().write(updateValidationResult.getErrorCollection().getErrorMessages() +"<br>"); 

     if (updateValidationResult.isValid()) { 
      IssueResult updateResult = issueService.update(loggedInUser, updateValidationResult); 
      MutableIssue updatedIssue = updateResult.getIssue(); 
      resp.getWriter().write("<p style='background:LightYellow; font-family:Arial,Helvetica,sans-serif;font-size:small;'>Issue Updated "+ updatedIssue +"</p>"); 
     } 
     if (!updateValidationResult.isValid()) { 
      //final Collection<String> errorMessages = updateValidationResult.getErrorCollection().getErrorMessages(); 
      resp.getWriter().write("<p style='background:Pink; font-family:Arial,Helvetica,sans-serif;font-size:small;'>Issue Updated Failed</p><br>"+ updateValidationResult.getErrorCollection().getErrorMessages()); 
     } 


    } 
} 

回答

7

試試下面的代碼

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(issueKey); 
User loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); 
issue.setAssignee(loggedInUser); 
issue.store(); 
+0

它給我的錯誤在這條線 'issue.setAssignee(與loggedInUser);' 錯誤:無法找到符號 – user1788171

+0

好吧,我的工作它所有你需要做的是,在你的code.1行中將'Issue'改爲'MutableIssue'。再次感謝。 – user1788171

+0

保存我的一天男人。謝謝 – Marcel