Using webwork1 with CreateIssueDetails

Elena Gridneva June 30, 2017

Hello. I want to add some functions on issue creating.

I have this webwork in my atlassian-plugin.xml:

<webwork1 key="unitera-create-issue-details" name="Unitera Create Issue Details"
class="com.atlassian.jira.web.action.issue.CreateIssueDetails">
<actions>
<action name="org.smedyou.tutorial.ComDescCreateIssueDetails"
alias="CreateIssueDetails"
roles-required="use">
<view name="error">/secure/views/createissue-details.jsp</view>
</action>
</actions>
</webwork1>

And this class, which extends CreateIssueDetails.class, as seen

 

package org.smedyou.tutorial;

import com.atlassian.gzipfilter.org.apache.commons.lang.exception.ExceptionUtils;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.comment.CommentService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.mau.MauEventService;
import com.atlassian.jira.issue.IssueFactory;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.TemporaryAttachmentsMonitorLocator;
import com.atlassian.jira.issue.comments.Comment;
import com.atlassian.jira.security.xsrf.RequiresXsrfCheck;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.util.JiraUrlCodec;
import com.atlassian.jira.web.action.issue.CreateIssueDetails;
import com.atlassian.jira.web.action.issue.IssueCreationHelperBean;


public class ComDescCreateIssueDetails extends CreateIssueDetails {

    private IssueService issueService;
    private CommentService commentService;

    public ComDescCreateIssueDetails(IssueFactory issueFactory, IssueCreationHelperBean issueCreationHelperBean, IssueService issueService, TemporaryAttachmentsMonitorLocator temporaryAttachmentsMonitorLocator) {
        super(issueFactory, issueCreationHelperBean, issueService, temporaryAttachmentsMonitorLocator);
        this.issueService = issueService;
    }

    @Override
    @RequiresXsrfCheck
    protected String doExecute() throws Exception {
        String var1;
        try {
            this.createIssue();
            if(this.hasAnyErrors()) {
                var1 = "error";
                return var1;
            }

            var1 = this.doPostCreationTasks();
        } catch (Exception var6) {
            this.log.error(var6, var6);
            this.addErrorMessage(var6.getMessage() != null?var6.getMessage(): ExceptionUtils.getFullStackTrace(var6));
            String var2 = "error";
            return var2;
        } finally {
            ((MauEventService)ComponentAccessor.getComponent(MauEventService.class)).setApplicationForThreadBasedOnProject(this.getProject());
        }

        return var1;
    }

    @Override
    protected String doPostCreationTasks() throws Exception{
        
        commentService = ComponentAccessor.getComponent(CommentService.class);
        Comment comment1 = addComment("First coment!");

        //from CreateIssueDetails.class
        String issueKey = JiraUrlCodec.encode(this.getKey());
        if(this.isIssueValid()) {
            return this.getRedirect("/browse/" + issueKey);
        } else {
            this.errorMessages.clear();
            return this.getRedirect("CantBrowseCreatedIssue.jspa?issueKey=" + issueKey);
        }
    }

    private Comment addComment(String commentString, MutableIssue issue, ApplicationUser user) {
        CommentService.CommentParameters commentParams = new CommentService.CommentParameters.CommentParametersBuilder()
                .issue(issue).body(commentString).build();
        CommentService.CommentCreateValidationResult commentResult = this.commentService.validateCommentCreate(user, commentParams);
        return this.commentService.create(user, commentResult, true);
    }
}

So, I tried to change this code, using java.lang.Object instead of 

class="com.atlassian.jira.web.action.issue.CreateIssueDetails"

in webwork and so on. But after filling the fields at http:/[jira]/secure/CreateIssue.jspa?pid=10000&issuetype=10000 and pressing Create, I am redirected to http:/[jira]/secure/CreateIssueDetails.jspa getting a code 404. I do not understand why it doesn't go to http:/[jira]/secure/browse/<issue_name>, but to http:/[jira]/secure/<alias>.jspa. Thanks for responses.

 

1 answer

0 votes
Nadir MEZIANI
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.
June 30, 2017

Hi,

I think the probem is in your XM plugin definition of your action

 

Try to see this link maybe it can give you some help

http://www.j-tricks.com/tutorials/extending-jira-actions

Suggest an answer

Log in or Sign up to answer