/// <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>Generates a remote requirement from the specified item.</summary> /// <param name="jamaItem">The Jama item to create the requirement from.</param> /// <param name="existingReq">Pass an existing requirement to update, leave null to create new</param> /// <returns>RemoteRequirement</returns> private SpiraSoapService.RemoteRequirement GenerateOrUpdateRequirement(JamaItem jamaItem, SpiraSoapService.RemoteRequirement existingReq) { SpiraSoapService.RemoteRequirement newReq; if (existingReq == null) { newReq = new SpiraSoapService.RemoteRequirement(); newReq.CustomProperties = new List <RemoteArtifactCustomProperty>(); } else { newReq = existingReq; } if (String.IsNullOrEmpty(jamaItem.Name)) { newReq.Name = "Unknown (Null)"; } else { newReq.Name = jamaItem.Name; } newReq.Description = jamaItem.Description; newReq.RequirementTypeId = (int)SpiraProject.RequirementType.Feature; if (jamaItem.CreatedDate.HasValue) { newReq.CreationDate = jamaItem.CreatedDate.Value; } if (jamaItem.ModifiedDate.HasValue) { newReq.LastUpdateDate = jamaItem.ModifiedDate.Value; } if (existingReq == null) { //Set the concurrent Date for new items newReq.ConcurrencyDate = DateTime.UtcNow; } //Get the other fields bool documentKeyFound = false; foreach (KeyValuePair <string, object> field in jamaItem.Fields) { //Handle the known fields //Priority if (field.Key == "priority") { if (field.Value != null && field.Value is Int32) { int jamaPriorityId = (int)field.Value; switch ((JamaProjectInfo.Priority)jamaPriorityId) { case JamaProjectInfo.Priority.High: newReq.ImportanceId = (int)SpiraProject.Importance.High; break; case JamaProjectInfo.Priority.Medium: newReq.ImportanceId = (int)SpiraProject.Importance.Medium; break; case JamaProjectInfo.Priority.Low: newReq.ImportanceId = (int)SpiraProject.Importance.Low; break; } } } //Status if (field.Key == "status") { if (field.Value != null && field.Value is Int32) { int jamaStatusId = (int)field.Value; switch ((JamaProjectInfo.Status)jamaStatusId) { case JamaProjectInfo.Status.Draft: newReq.StatusId = (int)SpiraProject.Status.Requested; break; case JamaProjectInfo.Status.Approved: newReq.StatusId = (int)SpiraProject.Status.Accepted; break; case JamaProjectInfo.Status.Completed: newReq.StatusId = (int)SpiraProject.Status.Completed; break; case JamaProjectInfo.Status.Rejected: newReq.StatusId = (int)SpiraProject.Status.Rejected; break; } } } //Document Key if (field.Key == "documentKey") { if (field.Value != null && field.Value is String) { string documentKey = (string)field.Value; if (!String.IsNullOrWhiteSpace(documentKey)) { string jamaItemKey = jamaItem.Id.ToString(); RemoteArtifactCustomProperty customProp = new RemoteArtifactCustomProperty(); customProp.PropertyNumber = 2; customProp.StringValue = documentKey; newReq.CustomProperties.Add(customProp); documentKeyFound = true; } } } //Release if (field.Key == "release") { if (field.Value != null && field.Value is Int32) { int jamaReleaseId = (int)field.Value; //See if we have a mapping for this release ReleaseMappingData.ReleaseMappingRow dataRow = this._releaseDataMapping.GetFromJamaId(this._JamaProject.ProjectNum, jamaReleaseId); if (dataRow == null) { newReq.ReleaseId = null; } else { newReq.ReleaseId = dataRow.SpiraReleaseId; } } } } //Now get the item document type and item document type category and store in text custom properties if (jamaItem.ItemTypeId.HasValue) { int itemTypeId = jamaItem.ItemTypeId.Value; JamaItemType itemType = this._jamaClient.GetItemType(itemTypeId); if (itemType != null) { { RemoteArtifactCustomProperty customProp = new RemoteArtifactCustomProperty(); customProp.PropertyNumber = 1; customProp.StringValue = itemType.Display; newReq.CustomProperties.Add(customProp); } //Also map to the nearest equivalent requirement type switch ((JamaProjectInfo.Type)itemTypeId) { case JamaProjectInfo.Type.Feature: newReq.RequirementTypeId = (int)SpiraProject.RequirementType.Feature; break; case JamaProjectInfo.Type.Requirement: case JamaProjectInfo.Type.Epic: newReq.RequirementTypeId = (int)SpiraProject.RequirementType.Need; break; case JamaProjectInfo.Type.UseCase: case JamaProjectInfo.Type.UsageScenario: newReq.RequirementTypeId = (int)SpiraProject.RequirementType.UseCase; break; case JamaProjectInfo.Type.UserStory: newReq.RequirementTypeId = (int)SpiraProject.RequirementType.UserStory; break; default: newReq.RequirementTypeId = (int)SpiraProject.RequirementType.Feature; break; } //Also we need to add the jama ID as the Custom 02 custom property //using format: <project-short-name>-<Jama item type key>-<number> if (!documentKeyFound) { if (!String.IsNullOrWhiteSpace(this._projectShortName)) { string jamaItemKey = jamaItem.Id.ToString(); RemoteArtifactCustomProperty customProp = new RemoteArtifactCustomProperty(); customProp.PropertyNumber = 2; customProp.StringValue = this._projectShortName + "-" + itemType.TypeKey + "-" + jamaItemKey; newReq.CustomProperties.Add(customProp); } } if (!String.IsNullOrEmpty(itemType.Category)) { RemoteArtifactCustomProperty customProp = new RemoteArtifactCustomProperty(); customProp.PropertyNumber = 3; customProp.StringValue = itemType.Category; newReq.CustomProperties.Add(customProp); } } } return(newReq); }
/// <summary> /// Processes a Jama item, taking care of the associated attachments, comments, etc. /// </summary> /// <param name="jamaItem">The item to process.</param> private FinalStatusEnum ProcessItem(StreamWriter streamWriter, JamaItem jamaItem) { FinalStatusEnum retStatus = FinalStatusEnum.OK; try { //We ignore the Defects, Issue, Task, Risk and Change Request items if (jamaItem.ItemTypeId.HasValue) { if (jamaItem.ItemTypeId == 14 || (jamaItem.ItemTypeId >= 16 && jamaItem.ItemTypeId <= 19 || jamaItem.ItemTypeId == (int)JamaProjectInfo.Type.Bug || jamaItem.ItemTypeId == (int)JamaProjectInfo.Type.ChangeRequest)) { return(FinalStatusEnum.OK); } } int?ExistingMapped = GetLinkedNumber(jamaItem); //See if we have a mapping entry if (ExistingMapped.HasValue) { //Get the mapped requirement. SpiraSoapService.RemoteRequirement existingReq = this._spiraClient.Requirement_RetrieveById(ExistingMapped.Value); //If it no longer exists, just ignore (user needs to clear the mappings if they want to reimport) if (existingReq != null) { //Update the requirement from the Jama item SpiraSoapService.RemoteRequirement newReq = this.GenerateOrUpdateRequirement(jamaItem, existingReq); //Update the requirement this._spiraClient.Requirement_Update(newReq); } else { //Could not find requirement and it was mapped. retStatus = FinalStatusEnum.Warning; } } else { //Create the requirement. SpiraSoapService.RemoteRequirement newReq = this.GenerateOrUpdateRequirement(jamaItem, null); //Get parent's ID. If it is null, ignore this requirement because the parent // folder was deleted. (We should always have a root, because of the RootReq // or the root folder.) int?ParentID = GetParentLinkedNumber(jamaItem); if (ParentID.HasValue) { //Insert new Requirement. if (ParentID == -1) { //HACK: Force it to root. newReq = this._spiraClient.Requirement_Create1(newReq, -100); } else { newReq = this._spiraClient.Requirement_Create2(newReq, ParentID); } this.SetLinkedNumber(jamaItem, this._SpiraProject.ProjectNum, newReq.RequirementId.Value); } else { //Could not find requirement's parent, and it was mapped. retStatus = FinalStatusEnum.Warning; } } if (ProcessThread.WantCancel) { return(FinalStatusEnum.Error); } } catch (Exception ex) { streamWriter.WriteLine("Unable to complete import: " + ex.Message); retStatus = FinalStatusEnum.Error; } return(retStatus); }