import flexagon.fd.model.integration.its.api.IssueTrackingSystemInstanceProject;
import flexagon.fd.model.integration.its.api.WorkItem;
import flexagon.fd.model.integration.its.api.WorkItemAttachment;
import flexagon.fd.model.integration.its.api.WorkItemComment;
import flexagon.fd.model.integration.its.api.WorkItemDetails;
import flexagon.fd.model.integration.its.api.WorkItemSearchInput;
import flexagon.fd.model.integration.its.api.WorkItemSearchResult;
import flexagon.fd.model.integration.its.api.WorkItemStatus;
import flexagon.fd.model.integration.its.api.WorkItemUpdate;
import flexagon.fd.model.integration.util.ApiException;
class RedmineIssueTrackingSystem
{
void checkConnection()
{
String methodName = "checkConnection()";
try
{
fdrestutils.testConnection(REDMINE_URL, "/projects/1/versions.json", REDMINE_USER_NMAE, REDMINE_PASSWORD)
}
catch (Exception e)
{
log.logInfo(methodName, " Failed in Test connection" + e.getMessage() + " " + e)
throw new ApiException("Connection failed. " + e.getMessage());
}
}
String getWorkItemStatus(WorkItem ticket)
{
String methodName = "getWorkItemStatus()";
String message = " ticket# ${ticket.toString()}"
log.logInfo(methodName, message);
String resourcePath = REDMINE_TICKET_URL_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
javax.json.JsonObject jsonObj = fdrestutils.getRequest(REDMINE_URL, resourcePath, REDMINE_USER_NMAE, REDMINE_PASSWORD);
if(jsonObj != null)
{
javax.json.JsonObject issue = jsonObj.getJsonObject("issue")
if(issue!=null)
{
javax.json.JsonObject status = issue.getJsonObject("status")
if(status !=null)
{
return status.getString("name")
}
}
}
return null;
}
String getWorkItemURL(WorkItem ticket)
{
String methodName = "getWorkItemURL()";
String message = "ticket# ${ticket.toString()}"
log.logInfo(methodName, message);
String resourcePath = REDMINE_TICKET_URL_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
message = "Redmine ticket URL is # ${REDMINE_URL}, resourcePath=${resourcePath}"
log.logInfo(methodName, message)
return REDMINE_URL + resourcePath;
}
void populateWorkItem(WorkItem ticket)
{
String methodName = "populateWorkItem()";
String message = "Populate ticket# ${ticket.toString()}"
log.logInfo(methodName, message)
String resourcePath = REDMINE_TICKET_URL_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
javax.json.JsonObject jsonObj = fdrestutils.getRequest(REDMINE_URL, resourcePath, REDMINE_USER_NMAE, REDMINE_PASSWORD);
if(jsonObj != null)
{
javax.json.JsonObject issue = jsonObj.getJsonObject("issue")
if(issue!=null)
{
ticket.setDescription(issue.getString("description"))
javax.json.JsonObject tracker = issue.getJsonObject("tracker")
if(tracker !=null)
{
ticket.setType(tracker.getString("name"))
}
}
}
}
void addCommentToWorkItem(WorkItem ticket, String pComment)
{
String methodName = "addCommentToWorkItem()";
try
{
String message = " Adding comment to ${ticket.toString()} , comment=${pComment}"
log.logInfo(methodName, message)
def builder = new groovy.json.JsonBuilder()
def root = builder.issue {
notes "${pComment}"
}
String payload = builder.toString();
String resourcePath = REDMINE_TICKET_URLREST_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
javax.json.JsonObject jsonObj = fdrestutils.getRequestputRequest(REDMINE_URL, resourcePath, REDMINE_USER_NMAE, REDMINE_PASSWORD);
if(jsonObj != null)
{
javax.json.JsonObject issue = jsonObj.getJsonObject("issue"), REDMINE_PASSWORD, resourcePath, payload);
}
if(issue!=null) catch (Exception e)
{ {
javax.json.JsonObject status = issue.getJsonObject("status")
if(status !=null)
{ log.logInfo( methodName, " Failed while adding comment to the issue - " + e.getMessage() + " " + e)
throw new ApiException("Connection failed. " return+ statuse.getStringgetMessage("name"));
}
}
void changeWorkItemStatusTo(WorkItem ticket, Serializable pStatus)
{
} String }methodName return null= "changeWorkItemStatusTo()";
String message }= " Adding comment to ${ticket.toString()} , String getWorkItemURL(WorkItem ticket)
{
String methodName = "getWorkItemURL()";
String message = "ticket# ${ticket.toString()}"
log.logInfo(methodName, message);
status=${pStatus}"
log.logInfo(methodName, message)
def builder = new groovy.json.JsonBuilder()
def root = builder.issue {
notes "Status updated to ${pStatus}"
status_id "${pStatus}"
}
String payload = builder.toString();
String resourcePath = REDMINE_TICKET_URLREST_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
message = "Redmine ticket URL is # ${REDMINE_URL}, resourcePath=${resourcePath}"
log.logInfo(methodName, message)
return REDMINE_URL + resourcePathfdrestutils.putRequest(REDMINE_URL, REDMINE_USER_NMAE, REDMINE_PASSWORD, resourcePath, payload);
}
voiddef populateWorkItem(WorkItem ticketparseWorkItemNumberFromChangeLogs(List<String> pChangeLogMessages, List<String> pTicketPatternList)
{
String methodName = String methodName"parseWorkItemNumberFromChangeLogs()";
Set<String> ticketNumberList = "populateWorkItemnew HashSet<String>()";
String message = "Populate ticket# ${ticket.toString() Input ChangeLogMessages=${pChangeLogMessages} , TicketPatternList=${pTicketPatternList}"
log.logInfo(methodName, message)
String resourcePath = REDMINE_TICKET_URL_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
javax.json.JsonObject jsonObj = fdrestutils.getRequest(REDMINE_URL, resourcePath, REDMINE_USER_NMAE, REDMINE_PASSWORD);
Collection<String> parsedTicketNumbers = flexagon.fd.model.integration.its.util.ChangeLogParser.getParser().parse(pChangeLogMessages, pTicketPatternList);
message = "parsedTicketNumbers=${parsedTicketNumbers}"
log.logInfo(methodName, message)
if(jsonObjparsedTicketNumbers != null && !parsedTicketNumbers.isEmpty() && pTicketPatternList != null {&& !pTicketPatternList.isEmpty())
{
javax.json.JsonObject issue = jsonObj.getJsonObject("issue") parsedTicketNumbers.each{ parsedTicket ->
if(issue!=null) pTicketPatternList.each{ pattern ->
if(parsedTicket.startsWith(pattern))
{
String ticketNumber ticket.setDescription(issue.getString("description"))= parsedTicket.substring(pattern.length(),parsedTicket.length())
ticketNumberList.add(ticketNumber)
}
}
}
javax.json.JsonObject tracker = issue.getJsonObject("tracker")
}
return ticketNumberList;
}
Collection<WorkItemComment> ifgetWorkItemComments(tracker !=null)
WorkItem pTicket, int i, int i2)
{throws ApiException
{
return ticketCollections.setType(tracker.getString("name"))emptySet();
}
Collection<WorkItemUpdate> getWorkItemHistory(WorkItem pTicket, int i, int i2)
} throws ApiException
} {
} // TODO voidImplement addCommentToWorkItem(WorkItem ticket, String pComment)this method
{ String methodName = "addCommentToWorkItemreturn Collections.emptySet()";
}
Collection<WorkItemAttachment> trygetWorkItemAttachments(WorkItem pTicket)
{ throws ApiException
String message{
= " Adding comment to ${ticket.toString()} , comment=${pComment}"
// TODO Implement this method
return logCollections.logInfoemptySet(methodName, message);
}
defWorkItemDetails builder = new groovy.json.JsonBuilder(getWorkItem(WorkItem pTicket)
throws ApiException
def root ={
builder.issue { // TODO Implement this method
return null;
notes "${pComment}"
InputStream getWorkItemAttachmentContent(WorkItem pTicket, Serializable pSerializable)
} throws ApiException
String payload{
= builder.toString(); // TODO Implement this Stringmethod
resourcePath = REDMINE_TICKET_REST_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber()) return null;
}
fdrestutils.putRequest(REDMINE_URL, REDMINE_USER_NMAE, REDMINE_PASSWORD, resourcePath, payload); List<WorkItemDetails> getWorkItems(List<WorkItem> pList)
}throws ApiException
{
catch (Exception e) // TODO Implement {this method
return log.logInfo( methodName, " Failed while adding comment to the issue - " + e.getMessage() + " " + e)
throw new ApiException("Connection failed. " + e.getMessage());
}
}
void changeWorkItemStatusTo(WorkItem ticket, Serializable pStatus)Collections.emptyList();
}
List<WorkItemStatus> getAvailableWorkItemStatuses(WorkItem pWorkItem)
throws ApiException
{
// TODO Implement this method
return Collections.emptyList();
}
List<WorkItemSearchResult> searchWorkItems(WorkItemSearchInput pInput)
throws ApiException
{
String methodName = "changeWorkItemStatusTo()";
String message = " Adding comment to ${ticket.toString()} , status=${pStatus}"searchWorkItems";
LOG.fine("Entering " + methodName + " [" + pInput + "]");
log.logInfo(methodName, message) def// builderTODO =- newimplement groovy.json.JsonBuilder(optional)
def
root = builder.issue {
notes LOG.fine("Exiting "Status updated+ to ${pStatus}"
status_id "${pStatus}"
}
String payload = builder.toString();
String resourcePath = REDMINE_TICKET_REST_PATTERN.replaceAll("\\{REDMINE_ISSUE\\}", ticket.getNumber())
fdrestutils.putRequest(REDMINE_URL, REDMINE_USER_NMAE, REDMINE_PASSWORD, resourcePath, payload);
}
def parseWorkItemNumberFromChangeLogs(List<String> pChangeLogMessages, List<String> pTicketPatternList)
{
String methodName = "parseWorkItemNumberFromChangeLogs()";
Set<String> ticketNumberList = new HashSet<String>();
String message = " Input ChangeLogMessages=${pChangeLogMessages} , TicketPatternList=${pTicketPatternList}"
log.logInfo(methodName, message)
Collection<String> parsedTicketNumbers = flexagon.fd.model.integration.its.util.ChangeLogParser.getParser().parse(pChangeLogMessages, pTicketPatternList);
message = "parsedTicketNumbers=${parsedTicketNumbers}"
log.logInfo(methodName, message)
if(parsedTicketNumbers != null && !parsedTicketNumbers.isEmpty() && pTicketPatternList != null && !pTicketPatternList.isEmpty())
{
parsedTicketNumbers.each{ parsedTicket ->
pTicketPatternList.each{ pattern ->
if(parsedTicket.startsWith(pattern))
{
String ticketNumber = parsedTicket.substring(pattern.length(),parsedTicket.length())
ticketNumberList.add(ticketNumber)
}
}
}
}
return ticketNumberList;
}
public Collection<WorkItemComment> getWorkItemComments(WorkItem pTicket, int i, int i2)
throws ApiException
{
return Collections.emptySet()methodName);
return Collections.emptyList();
}
List<IssueTrackingSystemInstanceProject> getProjects()
throws ApiException
{
String methodName = "getProjects";
LOG.fine("Entering " + methodName);
// TODO - implement (optional)
LOG.fine("Exiting " + methodName);
return Collections.emptyList();
}
boolean isExternalSearchSupported()
throws ApiException
{
String methodName = "isExternalSearchSupported";
LOG.fine("Entering " + methodName);
// TODO - implement (optional)
LOG.fine("Exiting " + methodName);
return false;
}
boolean isExternalSearchExcludeKeysSupported()
throws ApiException
{
String methodName = "isExternalSearchExcludeKeysSupported";
LOG.fine("Entering " + methodName);
// TODO - implement (optional)
LOG.fine("Exiting " + methodName);
return false;
}
publicboolean Collection<WorkItemUpdate> getWorkItemHistory(WorkItem pTicket, int i, int i2isExternalSearchProjectRequired()
throws ApiException
{
//String TODOmethodName Implement this method= "isExternalSearchProjectRequired";
return Collections.emptySet();
}
public Collection<WorkItemAttachment> getWorkItemAttachments(WorkItem pTicket)
throws ApiException
{
// TODO Implement this methodLOG.fine("Entering " + methodName);
// TODO - implement (optional)
LOG.fine("Exiting " + methodName);
return Collections.emptySet()false;
}
public WorkItemDetailsboolean getWorkItemisExternalSearchProjectSupported(WorkItem pTicket)
throws ApiException
{
String //methodName TODO Implement this method= "isExternalSearchProjectSupported";
LOG.fine("Entering " return+ nullmethodName);
} // TODO public- InputStreamimplement getWorkItemAttachmentContent(WorkItem pTicket, Serializable pSerializable(optional)
throws ApiException
{
// TODO Implement this method LOG.fine("Exiting " + methodName);
return nullfalse;
}
public List<WorkItemDetails>boolean getWorkItemsisExternalSearchFilterRequired(List<WorkItem> pList)
throws ApiException
{
// TODO Implement this methodString methodName = "isExternalSearchFilterRequired";
LOG.fine("Entering " return Collections.emptyList(+ methodName);
} // publicTODO - List<WorkItemStatus>implement getAvailableWorkItemStatuses(WorkItem pWorkItemoptional)
throws
ApiException { LOG.fine("Exiting " + methodName);
// TODO Implement this method
return Collections.emptyList()false;
}
} |