protected override void UpdateWorkItemMigrationStatus(IBatchMigrationContext batchContext, int sourceId, WorkItem targetWorkItem) { WorkItemMigrationState state = batchContext.WorkItemMigrationState.First(w => w.SourceId == sourceId); state.MigrationCompleted |= WorkItemMigrationState.MigrationCompletionStatus.Phase1; state.TargetId = targetWorkItem.Id.Value; }
private void StoreTargetRelationPhaseStatusHyperlinkDataFromWorkItem(WorkItemMigrationState workItemMigrationState, WorkItemRelation hyperlinkToSourceRelation) { var targetAttributes = hyperlinkToSourceRelation.Attributes; targetAttributes.TryGetValue(Constants.RelationAttributeComment, out string targetRelationPhaseStatus); workItemMigrationState.RevAndPhaseStatus = new RevAndPhaseStatus(targetRelationPhaseStatus); }
private async Task <IList <(int SourceId, WitBatchRequest WitBatchRequest)> > GenerateWitBatchRequestsForPhase2Batch(IBatchMigrationContext batchContext, int batchId, IList <WorkItemMigrationState> workItemMigrationState, IList <WorkItem> sourceWorkItems, IList <WorkItem> targetWorkItems) { IList <(int SourceId, WitBatchRequest WitBatchRequest)> result = new List <(int SourceId, WitBatchRequest WitBatchRequest)>(); IEnumerable <IPhase2Processor> phase2Processors = ClientHelpers.GetProcessorInstances <IPhase2Processor>(context.Config); foreach (IPhase2Processor processor in phase2Processors) { Logger.LogInformation(LogDestination.File, $"Starting preprocessing of phase 2 step {processor.Name} for batch {batchId}"); await processor.Preprocess(context, batchContext, sourceWorkItems, targetWorkItems); Logger.LogInformation(LogDestination.File, $"Completed preprocessing of phase 2 step {processor.Name} for batch {batchId}"); } foreach (var sourceToTarget in batchContext.SourceWorkItemIdToTargetWorkItemIdMapping) { int sourceId = sourceToTarget.Key; int targetId = sourceToTarget.Value; WorkItem sourceWorkItem = sourceWorkItems.First(a => a.Id == sourceId); WorkItem targetWorkItem = targetWorkItems.First(a => a.Id == targetId); IList <JsonPatchOperation> jsonPatchOperations = new List <JsonPatchOperation>(); WorkItemMigrationState state = workItemMigrationState.First(a => a.SourceId == sourceId); state.RevAndPhaseStatus = GetRevAndPhaseStatus(targetWorkItem, sourceId); ISet <string> enabledPhaseStatuses = System.Linq.Enumerable.ToHashSet(phase2Processors.Where(a => a.IsEnabled(context.Config)).Select(b => b.Name)); enabledPhaseStatuses.Remove(Constants.RelationPhaseClearAllRelations); foreach (IPhase2Processor processor in phase2Processors) { IEnumerable <JsonPatchOperation> processorJsonPatchOperations = await processor.Process(context, batchContext, sourceWorkItem, targetWorkItem); jsonPatchOperations.AddRange(processorJsonPatchOperations); } jsonPatchOperations.Add(GetAddHyperlinkWithCommentOperation(targetWorkItems, state, sourceId, targetId, sourceWorkItem, enabledPhaseStatuses)); if (this.context.Config.IncludeWebLink) { var link = (ReferenceLink)sourceWorkItem.Links.Links["html"]; var addWebLinkOperation = MigrationHelpers.GetHyperlinkAddOperation(link.Href); jsonPatchOperations.Add(addWebLinkOperation); } if (jsonPatchOperations.Any()) { WitBatchRequest witBatchRequest = GenerateWitBatchRequestFromJsonPatchOperations(jsonPatchOperations, targetId); result.Add((sourceId, witBatchRequest)); } } return(result); }
private bool IsPhase2UpdateRequired(WorkItemMigrationState workItemMigrationState, WorkItem targetWorkItem) { IEnumerable <IPhase2Processor> phase2Processors = ClientHelpers.GetProcessorInstances <IPhase2Processor>(ValidationContext.Config); workItemMigrationState.RevAndPhaseStatus = GetRevAndPhaseStatus(targetWorkItem, workItemMigrationState.SourceId); // find out if Enabled, see if matches comment from target ISet <string> enabledPhaseStatuses = System.Linq.Enumerable.ToHashSet(phase2Processors.Where(a => a.IsEnabled(ValidationContext.Config)).Select(b => b.Name)); enabledPhaseStatuses.Remove(Constants.RelationPhaseClearAllRelations); if (enabledPhaseStatuses.IsSubsetOf(workItemMigrationState.RevAndPhaseStatus.PhaseStatus)) // enabled relation phases are already complete for current work item { return(false); } return(true); }
public void GetNotMigratedWorkItemsFromWorkItemsMigrationState_ReturnsCorrectResult() { WorkItemMigrationState notMigratedState = new WorkItemMigrationState(); notMigratedState.SourceId = 1; notMigratedState.FailureReason |= FailureReason.UnsupportedWorkItemType; WorkItemMigrationState migratedState = new WorkItemMigrationState(); migratedState.SourceId = 2; ConcurrentBag <WorkItemMigrationState> workItemsMigrationState = new ConcurrentBag <WorkItemMigrationState>(); workItemsMigrationState.Add(notMigratedState); workItemsMigrationState.Add(migratedState); Dictionary <int, FailureReason> result = ClientHelpers.GetNotMigratedWorkItemsFromWorkItemsMigrationState(workItemsMigrationState); Assert.AreEqual(1, result.Count); Assert.AreEqual(1, result.First().Key); }
private void ProcessUpdatedSourceWorkItem(WorkItem targetWorkItem, WorkItemMigrationState workItemMigrationState, WorkItemRelation hyperlinkToSourceRelation) { //get the source rev from the revision dictionary - populated by PostValidateWorkitems int sourceId = workItemMigrationState.SourceId; int sourceRev = ValidationContext.SourceWorkItemRevision[sourceId]; string sourceUrl = ValidationContext.WorkItemIdsUris[sourceId]; int targetRev = GetRev(this.ValidationContext, targetWorkItem, sourceId, hyperlinkToSourceRelation); if (IsDifferenceInRevNumbers(sourceId, targetWorkItem, hyperlinkToSourceRelation, targetRev)) { Logger.LogInformation(LogDestination.File, $"Source workItem {sourceId} Rev {sourceRev} Target workitem {targetWorkItem.Id} Rev {targetRev}"); this.sourceWorkItemIdsThatHaveBeenUpdated.Add(sourceId); workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdatePhase1; workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdatePhase2; } else if (IsPhase2UpdateRequired(workItemMigrationState, targetWorkItem)) { workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdatePhase2; } else { workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.None; } }
private JsonPatchOperation GetAddHyperlinkWithCommentOperation(IList <WorkItem> targetWorkItems, WorkItemMigrationState state, int sourceId, int targetId, WorkItem sourceWorkItem, ISet <string> enabledPhaseStatuses) { IList <WorkItemRelation> targetRelations = targetWorkItems.First(a => a.Id == targetId).Relations; foreach (WorkItemRelation targetRelation in targetRelations) { if (RelationHelpers.IsRelationHyperlinkToSourceWorkItem(context, targetRelation, sourceId)) { string hyperlink = context.WorkItemIdsUris[sourceId]; // only store the enabled phase statuses RevAndPhaseStatus newRevAndPhaseStatus = new RevAndPhaseStatus(); newRevAndPhaseStatus.Rev = sourceWorkItem.Rev.Value; newRevAndPhaseStatus.PhaseStatus = enabledPhaseStatuses; state.RevAndPhaseStatus = newRevAndPhaseStatus; // get the key even if its letter case is different but it matches otherwise string idKeyFromFields = targetRelation.Attributes.GetKeyIgnoringCase(Constants.RelationAttributeId); object attributeId = targetRelation.Attributes[idKeyFromFields]; JsonPatchOperation addHyperlinkWithCommentOperation = MigrationHelpers.GetHyperlinkAddOperation(hyperlink, newRevAndPhaseStatus.GetCommentRepresentation(), attributeId); return(addHyperlinkWithCommentOperation); } } throw new Exception($"Could not find hyperlink to source work item on target work item with id: {targetId}. Expected source work item id: {sourceId}"); }
private bool WorkItemHasBeenUpdatedOnSource(WorkItem targetWorkItem, WorkItemMigrationState workItemMigrationState) { int correspondingSource = workItemMigrationState.SourceId; return(this.sourceWorkItemIdsThatHaveBeenUpdated.Contains(correspondingSource)); }