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.