public void Delete(int jamaProjectId, int jamaItemId) { RequirementMappingData.RequirementMappingRow dataRow = GetFromJamaId(jamaProjectId, jamaItemId); if (dataRow != null) { dataRow.Delete(); dataRow.AcceptChanges(); } }
/// <summary> /// Adds a new mapping entry /// </summary> /// <param name="spiraProjectId">The id of the spira project</param> /// <param name="spiraReqId">The id of the spira requirement</param> /// <param name="jamaProjectId">The id of the jama project</param> /// <param name="jamaItemId">The id of the jama item</param> public void Add(int spiraProjectId, int spiraReqId, int jamaProjectId, int jamaItemId) { //Create a new data row if (this.requirementMappingData != null) { RequirementMappingData.RequirementMappingRow dataRow = this.requirementMappingData.RequirementMapping.AddRequirementMappingRow( spiraProjectId, spiraReqId, jamaProjectId, jamaItemId ); dataRow.AcceptChanges(); } }
/// <summary>Searches the Tagged Values for the mapping ID.</summary> /// <param name="element">The element to search in.</param> /// <returns>Integer indicating the SpiraTeam Requirement ID, NULL if no mapping.</returns> private int?GetLinkedNumber(JamaItem jamaItem) { if (this._requirementDataMapping == null) { return(null); } RequirementMappingData.RequirementMappingRow dataRow = this._requirementDataMapping.GetFromJamaId(jamaItem.ProjectId, jamaItem.Id); if (dataRow == null) { return(null); } else { return(dataRow.SpiraRequirementId); } }
/// <summary> /// Deletes a specific spira requirement and its associated mapping row /// </summary> /// <param name="mappingRow">The mapping row to be deleted</param> private void DeleteSpiraRequirement(StreamWriter streamWriter, RequirementMappingData.RequirementMappingRow mappingRow) { //First delete the item in SpiraTeam try { this._spiraClient.Requirement_Delete(mappingRow.SpiraRequirementId); //Finally delete the mapping row mappingRow.Delete(); } catch (Exception exception) { //Log error but continue streamWriter.WriteLine(String.Format("Unable to delete requirement RQ{0} in SpiraTeam.", mappingRow.SpiraRequirementId) + ": " + exception.Message); } }
/// <summary>Sets a mapping value on the specified item.</summary> /// <param name="jamaItem">The Jama item to set the mapping on.</param> /// <param name="spiraProjectid">The Spira project ID</param> /// <param name="spiraReqId">The Spira requirement ID to map to, NULL to delete the mapping.</param> private void SetLinkedNumber(JamaItem jamaItem, int spiraProjectid, int?spiraReqId) { //See if we have the add or remove case if (spiraReqId.HasValue) { //See if we have an existing item RequirementMappingData.RequirementMappingRow dataRow = this._requirementDataMapping.GetFromJamaId(jamaItem.ProjectId, jamaItem.Id); if (dataRow == null) { this._requirementDataMapping.Add(spiraProjectid, spiraReqId.Value, jamaItem.ProjectId, jamaItem.Id); } else { dataRow.SpiraProjectId = spiraProjectid; dataRow.SpiraRequirementId = spiraReqId.Value; dataRow.AcceptChanges(); } } else { //Delete the item this._requirementDataMapping.Delete(jamaItem.ProjectId, jamaItem.Id); } }
/// <summary>Gets the Spira Mapped ID for the parent item of the specified item.</summary> /// <param name="jamaItem">The Jama item</param> /// <returns>The Spira Mapping ID of the parent. -1 if the parent is a root item, NULL if mapping was deleted.</returns> private int?GetParentLinkedNumber(JamaItem jamaItem) { if (this._requirementDataMapping == null) { return(null); } //See if we have a parent item or not if (jamaItem.ParentId.HasValue) { RequirementMappingData.RequirementMappingRow dataRow = this._requirementDataMapping.GetFromJamaId(jamaItem.ProjectId, jamaItem.ParentId.Value); if (dataRow == null) { //If not, create a new requirement for this folder, if the parent exists. JamaItem jamaParentItem = this._jamaClient.GetItem(jamaItem.ParentId.Value); if (jamaParentItem == null) { //If the parent item no longer exists, just return -1 return(null); } SpiraSoapService.RemoteRequirement parReq = this.GenerateOrUpdateRequirement(jamaParentItem, null); //Get mapping for this item's parent. int?itemParentParentMappedID = GetParentLinkedNumber(jamaParentItem); //If the value is null, it was deleted, so do not create this and return NULL. if (!itemParentParentMappedID.HasValue) { return(null); } else { int?sentParentID = null; if (itemParentParentMappedID > 0) { sentParentID = itemParentParentMappedID; } //Create requirement. if (itemParentParentMappedID.Value < 0) { //HACK: Force it to root. parReq = this._spiraClient.Requirement_Create1(parReq, -100); } else { parReq = this._spiraClient.Requirement_Create2(parReq, sentParentID); } //Create mapping. this.SetLinkedNumber(jamaParentItem, this._SpiraProject.ProjectNum, parReq.RequirementId.Value); //Return requirement ID. (It's the parent.) return(parReq.RequirementId); } } else { //Make sure the requirement still exists, otherwise return null SpiraSoapService.RemoteRequirement checkReq = this._spiraClient.Requirement_RetrieveById(dataRow.SpiraRequirementId); if (checkReq == null) { return(null); } else { return(dataRow.SpiraRequirementId); } } } else { if (this._SpiraProject.RootReq > 0) { return(this._SpiraProject.RootReq); } else { return(-1); } } }
/// <summary>The main processing function.</summary> /// <param name="ErrorMsg">Error message in case an error happens.</param> /// <returns>Boolean on status of import.</returns> private bool ProcessImport(StreamWriter streamWriter, out FinalStatusEnum Status) { Status = FinalStatusEnum.OK; this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 2 }); streamWriter.WriteLine("Starting Import..."); try { //Load the mapping data this._requirementDataMapping = new RequirementDataMapping(); this._releaseDataMapping = new ReleaseDataMapping(); //See if we've been asked to clear the saved mapping data if (this._SpiraProject.RootReq == -1) { this._requirementDataMapping.Clear(); this._releaseDataMapping.Clear(); } else { //Get the list of Releases in the Jama project JamaProject jamaProject = this._jamaClient.GetProject(this._JamaProject.ProjectNum); if (jamaProject != null) { //Store the project short name this._projectShortName = jamaProject.ProjectKey; List <JamaRelease> jamaReleases = this._jamaClient.GetReleases(jamaProject.Id); //Import the releases into SpiraTeam if (jamaReleases != null) { foreach (JamaRelease jamaRelease in jamaReleases) { if (ProcessThread.WantCancel) { break; } FinalStatusEnum thisRun = this.ProcessRelease(streamWriter, jamaRelease); if (Status != FinalStatusEnum.Error && thisRun == FinalStatusEnum.Error) { Status = thisRun; } if (Status == FinalStatusEnum.OK && thisRun == FinalStatusEnum.Warning) { Status = thisRun; } } } } //Get the list of items in the Jama project in batches of 25 int startItem = 1; List <JamaItem> jamaItems = null; //Store the list of jama project ids and item ids so that we can track deletes later List <JamaProjectItemEntry> jamaEntries = new List <JamaProjectItemEntry>(); do { jamaItems = this._jamaClient.GetItemsForProject(this._JamaProject.ProjectNum, startItem, REQUEST_PAGE_SIZE); //Import the items into SpiraTeam if (jamaItems != null) { foreach (JamaItem jamaItem in jamaItems) { if (ProcessThread.WantCancel) { break; } FinalStatusEnum thisRun = this.ProcessItem(streamWriter, jamaItem); if (Status != FinalStatusEnum.Error && thisRun == FinalStatusEnum.Error) { Status = thisRun; } if (Status == FinalStatusEnum.OK && thisRun == FinalStatusEnum.Warning) { Status = thisRun; } //Also add to the list so that we can check for deletes afterwards jamaEntries.Add(new JamaProjectItemEntry(jamaItem.ProjectId, jamaItem.Id)); } } startItem += REQUEST_PAGE_SIZE; }while (jamaItems != null && jamaItems.Count > 0 && !ProcessThread.WantCancel); //See if we want to delete items in Spira that are not in Jama if (Properties.Settings.Default.DeleteItemInSpiraIfMissing) { //See if we have at least v3.1 of SpiraTest, since only that supports deletes RemoteVersion remoteVersion = this._spiraClient.System_GetProductVersion(); if (remoteVersion != null) { string versionNumber = remoteVersion.Version; string[] versionComponents = versionNumber.Split('.'); int majorVersion = 0; if (!Int32.TryParse(versionComponents[0], out majorVersion)) { majorVersion = 0; } int minorVersion = 0; if (versionComponents.Length > 1) { if (!Int32.TryParse(versionComponents[1], out minorVersion)) { minorVersion = 0; } } //We need at least v3.1 if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 1)) { //Now see if we have any mapped requirements that are no longer in Jama if (this._requirementDataMapping.Rows != null) { for (int i = 0; i < this._requirementDataMapping.Rows.Count; i++) { RequirementMappingData.RequirementMappingRow mappingRow = this._requirementDataMapping.Rows[i]; //See that entry exists in the list of items, if not, delete from Spira and mappings if (!jamaEntries.Any(je => je.ItemId == mappingRow.JamaItemId && je.ProjectId == mappingRow.JamaProjectId)) { DeleteSpiraRequirement(streamWriter, mappingRow); } } } } } } } //Save the mapping data this._requirementDataMapping.Save(); this._releaseDataMapping.Save(); if (Status == FinalStatusEnum.Error) { string ErrorMsg = ""; if (ProcessThread.WantCancel) { ErrorMsg = App.CANCELSTRING; } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 2 }); return(false); } else { this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 2 }); return(true); } } catch (Exception exception) { //Handle all exceptions streamWriter.WriteLine("Error: " + exception.Message); this.ProgressUpdate(this, new ProgressArgs() { ErrorText = exception.Message, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 2 }); return(false); } }