Beispiel #1
0
        private async Task VerifyRelationTypesExistsOnTarget(IValidationContext context)
        {
            var sourceRelationTypes = await WorkItemTrackingHelpers.GetRelationTypesAsync(context.SourceClient.WorkItemTrackingHttpClient);

            var targetRelationTypes = await WorkItemTrackingHelpers.GetRelationTypesAsync(context.TargetClient.WorkItemTrackingHttpClient);

            foreach (var relationType in sourceRelationTypes)
            {
                //retrieve relations which are of type workitemlink defined by attribute kvp {"usage", "workitemlink"}
                //exclude remote link types because they need to be converted into hyperlinks
                if (IsWorkItemLinkType(relationType))
                {
                    if (RelationHelpers.IsRemoteLinkType(relationType))
                    {
                        context.RemoteLinkRelationTypes.Add(relationType.ReferenceName);
                    }
                    else
                    {
                        if (TargetHasRelationType(relationType, targetRelationTypes))
                        {
                            context.ValidatedWorkItemLinkRelationTypes.Add(relationType.ReferenceName);
                        }
                        else
                        {
                            Logger.LogWarning(LogDestination.File, $"Target: Relation type {relationType.ReferenceName} does not exist");
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <JsonPatchOperation> > Process(IMigrationContext migrationContext, IBatchMigrationContext batchContext, WorkItem sourceWorkItem, WorkItem targetWorkItem)
        {
            IList <JsonPatchOperation>     jsonPatchOperations = new List <JsonPatchOperation>();
            IEnumerable <WorkItemRelation> sourceRemoteLinks   = sourceWorkItem.Relations?.Where(r => RelationHelpers.IsRemoteLinkType(migrationContext, r.Rel));

            if (sourceRemoteLinks != null && sourceRemoteLinks.Any())
            {
                foreach (WorkItemRelation sourceRemoteLink in sourceRemoteLinks)
                {
                    string           url = ConvertRemoteLinkToHyperlink(sourceRemoteLink.Url);
                    WorkItemRelation targetRemoteLinkHyperlinkRelation = GetHyperlinkIfExistsOnTarget(targetWorkItem, url);

                    if (targetRemoteLinkHyperlinkRelation != null) // is on target
                    {
                        JsonPatchOperation remoteLinkHyperlinkAddOperation = MigrationHelpers.GetRelationAddOperation(targetRemoteLinkHyperlinkRelation);
                        jsonPatchOperations.Add(remoteLinkHyperlinkAddOperation);
                    }
                    else // is not on target
                    {
                        string comment = string.Empty;
                        if (sourceRemoteLink.Attributes.ContainsKey(Constants.RelationAttributeComment))
                        {
                            comment = $"{sourceRemoteLink.Attributes[Constants.RelationAttributeComment]}";
                        }

                        WorkItemRelation newRemoteLinkHyperlinkRelation = new WorkItemRelation();
                        newRemoteLinkHyperlinkRelation.Rel        = Constants.Hyperlink;
                        newRemoteLinkHyperlinkRelation.Url        = url;
                        newRemoteLinkHyperlinkRelation.Attributes = new Dictionary <string, object>();
                        newRemoteLinkHyperlinkRelation.Attributes[Constants.RelationAttributeComment] = comment;

                        JsonPatchOperation remoteLinkHyperlinkAddOperation = MigrationHelpers.GetRelationAddOperation(newRemoteLinkHyperlinkRelation);
                        jsonPatchOperations.Add(remoteLinkHyperlinkAddOperation);
                    }
                }
            }

            return(jsonPatchOperations);
        }