1

issueKeyパラメーターを使用して渡す問題の「Assignee」を更新するjiraプラグインを作成しようとしています。

正しいissueIdとuserを取得するなど、すべて正しく実行されますが、問題を更新できず、ログに何も表示されず、エラーも出力されませんが、サーブレット内に配置した条件は失敗します。私はそれを機能させることができません、どんな提案も。また、この状況での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());
        }


    }
}
4

1 に答える 1

7

以下のコードを試してください

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(issueKey);
User loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
issue.setAssignee(loggedInUser);
issue.store();
于 2013-01-22T11:40:17.413 に答える