private ServerConnector.Entities.Workitem CreateNewWorkitem(Workitem item) { if (item == null) { throw new ArgumentNullException("item"); } var type = item.Type; logger.Log(LogMessage.SeverityType.Info, string.Format("Creating VersionOne {0} for item from {1} system with identifier {2}", type, item.ExternalSystemName, item.ExternalId)); var projectToken = FindProperProjectToken(item.ProjectId, item.Project); try { var newWorkitem = v1Processor.CreateWorkitem(type, item.Title, item.Description, projectToken, configuration.ExternalIdFieldName, item.ExternalId, item.ExternalSystemName, item.Priority, item.Owners); AddLinkToWorkitemToOriginalIssue(item, newWorkitem); logger.Log(LogMessage.SeverityType.Info, string.Format("VersionOne asset {0} succesfully created.", newWorkitem.Id)); return(newWorkitem); } catch (Exception ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Error during saving workitems: {0}", ex.Message)); return(null); } }
public WorkitemCreationResult CreateWorkitem(Workitem item, ServerConnector.Entities.Workitem closedDuplicate) { item.Description += string.Format("\n\n This is a copy of '{0}' {1}", closedDuplicate.Number, closedDuplicate.TypeName); var workitem = CreateNewWorkitem(item); var url = v1Processor.GetSummaryLink(closedDuplicate); var link = new Link(url, "Previous item"); v1Processor.AddLinkToEntity(workitem, link); return(GetWorkitemCreationResult(item, workitem)); }
private WorkitemCreationResult CreateWorkitem(Workitem toSendToV1, IList <ServerConnector.Entities.Workitem> duplicates) { if (duplicates.Count == 0) { return(workitemWriter.CreateWorkitem(toSendToV1)); } var lastDuplicate = FindLastDuplicate(duplicates); var result = workitemWriter.CreateWorkitem(toSendToV1, lastDuplicate); return(result); }
private void AddLinkToWorkitemToOriginalIssue(Workitem item, ServerConnector.Entities.Workitem newWorkitem) { if (item.ExternalLink == null) { return; } var url = item.ExternalLink.Url; var urlTitle = item.ExternalLink.Title; var title = !string.IsNullOrEmpty(urlTitle) ? urlTitle : url; var link = new Link(url, title, true); v1Processor.AddLinkToEntity(newWorkitem, link); }
private WorkitemCreationResult GetWorkitemCreationResult(Workitem item, ServerConnector.Entities.Workitem newWorkitem) { if (newWorkitem != null) { var result = ConvertToWorkitemCreationResult(item, newWorkitem); result.Messages.Add(string.Format("Created item \"{0}\" ({1}) in Project \"{2}\" URL: {3}", item.Title, result.Source.Number, item.Project, result.Permalink)); return(result); } return(null); }
private WorkitemCreationResult ConvertToWorkitemCreationResult(Workitem item, ServerConnector.Entities.Workitem newWorkitem) { var result = new WorkitemCreationResult(item) { Source = { Number = newWorkitem.Number, ExternalId = item.ExternalId, Description = newWorkitem.Description, ExternalSystemName = item.ExternalSystemName, ProjectId = newWorkitem.Project.Key, Project = newWorkitem.Project.Value, Title = newWorkitem.Name, Priority = newWorkitem.PriorityToken, }, WorkitemId = newWorkitem.Id, Permalink = v1Processor.GetWorkitemLink(newWorkitem), }; return(result); }
public IList<ServerConnector.Entities.Workitem> GetDuplicates(Workitem item) { var emptyDuplicateList = new List<ServerConnector.Entities.Workitem>(); if(string.IsNullOrEmpty(item.ExternalSystemName) || string.IsNullOrEmpty(configuration.ExternalIdFieldName)) { return emptyDuplicateList; } try { var filter = GroupFilter.And( Filter.Equal(Entity.SourceNameProperty, item.ExternalSystemName), Filter.Equal(configuration.ExternalIdFieldName, item.ExternalId), Filter.OfTypes(VersionOneProcessor.PrimaryWorkitemType) ); var duplicates = v1Processor.GetWorkitems(item.Type, filter); return duplicates; } catch (VersionOneException ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Can't get duplicates for {0} {1}. Cause:\n{2}", item.Number, item.Type, ex.Message)); } return emptyDuplicateList; }
public IList <ServerConnector.Entities.Workitem> GetDuplicates(Workitem item) { var emptyDuplicateList = new List <ServerConnector.Entities.Workitem>(); if (string.IsNullOrEmpty(item.ExternalSystemName) || string.IsNullOrEmpty(configuration.ExternalIdFieldName)) { return(emptyDuplicateList); } try { var filter = GroupFilter.And( Filter.Equal(Entity.SourceNameProperty, item.ExternalSystemName), Filter.Equal(configuration.ExternalIdFieldName, item.ExternalId), Filter.OfTypes(VersionOneProcessor.PrimaryWorkitemType) ); var duplicates = v1Processor.GetWorkitems(item.Type, filter); return(duplicates); } catch (VersionOneException ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Can't get duplicates for {0} {1}. Cause:\n{2}", item.Number, item.Type, ex.Message)); } return(emptyDuplicateList); }
public WorkitemCreationResult CreateWorkitem(Workitem item) { var workitem = CreateNewWorkitem(item); return(GetWorkitemCreationResult(item, workitem)); }
private WorkitemCreationResult CreateWorkitem(Workitem toSendToV1, IList<ServerConnector.Entities.Workitem> duplicates) { if(duplicates.Count == 0) { return workitemWriter.CreateWorkitem(toSendToV1); } var lastDuplicate = FindLastDuplicate(duplicates); var result = workitemWriter.CreateWorkitem(toSendToV1, lastDuplicate); return result; }