Why public void issueReopened(IssueEvent event){} Doesn't wants to works?

Hi!!

I've done a listener for my JIRA 4.1.2 to control some actions, as for example "issueCreated(IssueEvent event)" or "issueReopened(IssueEvent event)". In both methods i call my own function named "sendNotification(event)". The question is. why sendNotification works when i create an issue, but doesn't do anything when i reopen my issue?

Te same happens with my UserEvents, noone works :(

That's my code:

****************************CODE STARTS HERE*************************

package gfi.es;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult;
import com.atlassian.jira.bc.issue.IssueService.IssueResult;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.issue.IssueEventListener;
import com.atlassian.jira.event.user.UserEvent;
import com.atlassian.jira.event.user.UserEventListener;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.opensymphony.user.User;

public class Reopen extends AbstractIssueEventListener implements IssueEventListener, UserEventListener{

User user = null;

public void GenericEvent(UserEvent ue, IssueEvent ie){
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("IssueEvent -> " + ie.getEventTypeId() + ", userEvent -> " + ue.getUser().getName() + ".\n\t");
out.close();
}
catch (IOException e){}
}

public void issueCreated(IssueEvent event)
{
sendNotification(event);
}

public void issueAssigned(IssueEvent event)
{
sendNotification(event);
}

public void issueClosed(IssueEvent event)
{
sendNotification(event);
}

public void issueResolved(IssueEvent event)
{
sendNotification(event);
}

public void issueReopened(IssueEvent event)
{
sendNotificationR(event);
}

public void issueUpdated(IssueEvent event)
{
sendNotification(event);
}

public void issueCommented(IssueEvent event)
{
sendNotification(event);
}

public void issueCommentEdited(IssueEvent event)
{
sendNotification(event);
}

public void issueWorkLogged(IssueEvent event)
{
sendNotification(event);
}

public void issueWorklogUpdated(IssueEvent event)
{
sendNotification(event);
}

public void issueWorklogDeleted(IssueEvent event)
{
sendNotification(event);
}

public void issueDeleted(IssueEvent event, UserEvent uevent)
{
sendNotification(event);
sendNotificationIU(event,uevent);
reopening(event,user);
}

public void issueMoved(IssueEvent event)
{
sendNotification(event);
}

public void issueStarted(IssueEvent event)
{
sendNotification(event);
}

public void issueStopped(IssueEvent event)
{
sendNotification(event);
}

public void issueGenericEvent(IssueEvent event)
{
sendNotification(event);
}

public void customEvent(IssueEvent event)
{
sendNotification(event);
}

public void workflowEvent(IssueEvent event)
{
sendNotification(event);
}

protected void reopening(IssueEvent event, User user)
{
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
issueInputParameters.setProjectId(event.getIssue().getProjectObject().getId());
issueInputParameters.setIssueTypeId("2");
issueInputParameters.setSummary("This is a summary");
issueInputParameters.setReporterId("joeuser");
issueInputParameters.setAssigneeId("otheruser");
issueInputParameters.setDescription("I am a description");
issueInputParameters.setEnvironment("I am an environment");
issueInputParameters.setStatusId("2");
issueInputParameters.setPriorityId("2");
issueInputParameters.setResolutionId("2");
issueInputParameters.setSecurityLevelId(10000L);
issueInputParameters.setFixVersionIds(10000L, 10001L);

IssueService issueService = ComponentManager.getInstance().getIssueService();

CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters);

if (createValidationResult.isValid())
{
IssueResult createResult = issueService.create(user, createValidationResult);
if (!createResult.isValid())
{
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("No se pudo crear la nueva issue.\n\t");
out.close();
}
catch (IOException e){}
}
}
}

protected void sendNotification(IssueEvent event)
{

String error = "si";

try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("IssueEvent tipo: " + event.getEventTypeId() + "\n\t");
out.write("IssueEvent descripcion: " + event.getIssue().getString("summary") + "\n\t");
out.close();
error = "no";
}
catch (IOException e){}

if(error == "si"){
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("Error recibiendo el tipo de IssueEvent\n\t");
out.close();
}
catch (IOException e){}
}

}

protected void sendNotificationR(IssueEvent event)
{

String error = "si";

try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("IssueEvent tipo reopen: " + event.getEventTypeId() + "\n\t");
out.write("IssueEvent descripcion: " + event.getIssue().getString("summary") + "\n\t");
out.close();
error = "no";
}
catch (IOException e){}

if(error == "si"){
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("Error recibiendo el tipo de IssueEvent reopen.\n\t");
out.close();
}
catch (IOException e){}
}

}

protected void sendNotificationIU(IssueEvent event, UserEvent Uevent)
{

String error = "si";

try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("IssueEvent tipo: " + event.getEventTypeId() + "\n\t");
out.write("IssueEvent descripcion: " + event.getIssue().getString("summary") + "\n\t");
out.write("IssueEvent username: " + Uevent.getUser().getName() + "\n\t");
out.close();
error = "no";
}
catch (IOException e){}

if(error == "si"){
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("Error recibiendo el tipo de IssueEvent\n\t");
out.close();
}
catch (IOException e){}
}

}

public void userSignup(UserEvent event)
{
this.user = event.getUser();
sendNotificationU(event);
}

public void userCreated(UserEvent event)
{
sendNotificationU(event);
}

public void userCannotChangePassword(UserEvent event)
{
sendNotificationU(event);
}

public void userForgotPassword(UserEvent event)
{
sendNotificationU(event);
}

public void userForgotUsername(UserEvent event)
{
sendNotificationU(event);
}

protected void sendNotificationU(UserEvent event)
{

String error = "si";

try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("UserEvent tipo: " + event.getEventType() + "\n\t");
out.close();
error = "no";
}
catch (IOException e){}

if(error == "si"){
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("Error reciviendo el tipo de UserEvent\n\t");
out.close();
}
catch (IOException e){}
}
}

public boolean isInternal()
{
return false;
}

public boolean isUnique()
{
return false;
}

public String getDescription()
{
return "Este es mi listener.";
}

}

********************************END OF CODE******************************

Never mind about the spanish text, isn't important what i put on mi log.txt.

I need some help. Thanks for your time!!

Alberto.

2 answers

0 vote

Are you firing the correct event in the issue Reopened transition in your workflow? Are you firing an event at all?

Hi Jobin,

Yes, the reopen event is fired but the listener doesn't do anything :(

Alberto.

***************CODE*****************

protected void reopening(IssueEvent event, User user)
{
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
issueInputParameters.setProjectId(event.getIssue().getProjectObject().getId());
//issueInputParameters.setIssueTypeId("2");//We don't know the id my new issue will take...
issueInputParameters.setSummary("This is a summary");
issueInputParameters.setReporterId("joeuser");
issueInputParameters.setAssigneeId("otheruser");
issueInputParameters.setDescription("I am a description");
issueInputParameters.setEnvironment("I am an environment");
issueInputParameters.setStatusId("2");
issueInputParameters.setPriorityId("2");
issueInputParameters.setResolutionId("2");
issueInputParameters.setSecurityLevelId(10000L);
issueInputParameters.setFixVersionIds(10000L, 10001L);

IssueService issueService = ComponentManager.getInstance().getIssueService();

CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters);

if (createValidationResult.isValid())
{
IssueResult createResult = issueService.create(user, createValidationResult);
if (!createResult.isValid())
{
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("No se pudo crear la nueva issue.\n\t");
out.close();
}
catch (IOException e){}
}
}
}

*************END OF CODE**************

The reopening method code is based on a JIRA 4.1.2 documentation example find on -> https://developer.atlassian.com/display/JIRADEV/Performing+Issue+Operations .

Hi again!

I finally could listen my reopen event, but not with the issueReopen method (i've seen in the API the method was deprecated). Using the workflowEvent i can listen this event, and i can identify it as a reopen event with this code:

*******************CODE***************

public void workflowEvent(IssueEvent event){

sendNotification(event);

if(event.getIssue().getProjectObject().getId() == 7){

reopening(event,user);

}

}

**************END OF CODE*************

Now the problem is i can't create my new issue when any issue has been reopened :S

That's my code for the reopening method:

****I'll add in the next comment beacouse i can pass the characters limit***

Alberto.

***********CODE UPDATE***********

public void workflowEvent(IssueEvent event)
{
sendNotification(event,"workflowEvent");
if(EVENT_REOPEN.equals(event.getEventTypeId())){
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("Intentando crear la issue...\n\t");
out.close();
}
catch (IOException e){}
reopening(event);
}
}

*******************************

protected void reopening(IssueEvent event)
{
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
issueInputParameters.setProjectId(event.getIssue().getProjectObject().getId());
issueInputParameters.setIssueTypeId("2");
issueInputParameters.setSummary("This is a summary");
issueInputParameters.setReporterId(event.getIssue().getProjectObject().getLeadUserName());
issueInputParameters.setAssigneeId(event.getIssue().getProjectObject().getLeadUserName());
issueInputParameters.setDescription("I am a description");

issueInputParameters.setEnvironment("I am an environment");
issueInputParameters.setStatusId("2");
issueInputParameters.setPriorityId("2");
issueInputParameters.setResolutionId("2");
issueInputParameters.setSecurityLevelId(event.getIssue().getSecurityLevelId());
issueInputParameters.setFixVersionIds(null,null);

IssueService issueService = ComponentManager.getInstance().getIssueService();

CreateValidationResult createValidationResult = issueService.validateCreate(event.getRemoteUser(), issueInputParameters);

if (createValidationResult.isValid())
{
IssueResult createResult = issueService.create(event.getRemoteUser(), createValidationResult);
if (!createResult.isValid())
{
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\log.txt",true));
out.write("No se pudo crear la nueva issue.\n\t");
out.close();
}
catch (IOException e){}
}
}
}

**********END OF CODE**********

The problem of the issueReopened event was beacouse is deprecated on JIRA 4.1.2, i need to use the wrokflowEvent to capture the event and use the following code to evaluate if the event comes from an reopenEvent:

****

public void workflowEvent(IssueEvent event){

private final static Long EVENT_REOPEN = 7L;

if(EVENT_REOPEN.equals(event.getEventTypeId())){

//This is fired when a reopen action has occured;

}

}

****

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

131 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you