示例#1
0
        public Resource ConvertToResource(Jira3.Issue jiraIssue)
        {
            Resource result = null;

            Key classKey = new Key("RC-Requirement", "1.1");

            result = SpecIfDataFactory.CreateResource(classKey, _metadataReader);

            if (jiraIssue.Fields.IssueType.Name == "Requirement")
            {
                classKey = new Key("RC-Requirement", "1.1");
                result.SetPropertyValue("SpecIF:Perspective", "V-perspective-2", _metadataReader);
            }
            else if (jiraIssue.Fields.IssueType.Name == "Customer Requirement")
            {
                classKey = new Key("RC-Requirement", "1.1");
                result.SetPropertyValue("SpecIF:Perspective", "V-perspective-1", _metadataReader);
            }

            // EA GUID
            string eaGuidFieldName = GetEaGuidFieldName(jiraIssue);

            string eaGuid = (string)jiraIssue.FieldDictionary[eaGuidFieldName];

            if (!string.IsNullOrEmpty(eaGuid))
            {
                AlternativeId alternativeId = new AlternativeId()
                {
                    ID      = eaGuid,
                    Project = "Enterprise Architect"
                };

                result.AlternativeIDs.Add(alternativeId);
            }

            string specIfGuid = JiraGuidConverter.ConvertToSpecIfGuid(jiraIssue.Self, jiraIssue.ID);

            result.ID = specIfGuid;

            result.Revision = SpecIfGuidGenerator.ConvertDateToRevision(jiraIssue.Fields.Updated.Value);

            result.ChangedAt = jiraIssue.Fields.Updated.Value;

            if (jiraIssue.ChangeLog.Total == 0)
            {
                result.ChangedBy = jiraIssue.Fields.Creator.DisplayName;
            }
            else
            {
                result.ChangedBy = jiraIssue.ChangeLog.Histories[0].Author.DisplayName;
            }

            //result.Title = jiraIssue.Fields.Summary;

            if (jiraIssue.ChangeLog.Total > 1)
            {
                Jira3.History predecessor = jiraIssue.ChangeLog.Histories[1];

                string preRevision = SpecIfGuidGenerator.ConvertDateToRevision(predecessor.Created);

                result.Replaces.Add(preRevision);
            }

            result.SetPropertyValue("dcterms:identifier", jiraIssue.Key, _metadataReader);



            AdfToXhtmlConverter adfToXhtmlConverter = new AdfToXhtmlConverter();

            string descriptionHtml = adfToXhtmlConverter.ConvertAdfToXhtml(jiraIssue.Fields.Description);



            string mainLanguage = "en";

            string languageFieldID = GetCustomFieldName(jiraIssue, "Language");

            if (!string.IsNullOrEmpty(languageFieldID))
            {
                JObject language = jiraIssue.FieldDictionary[languageFieldID] as JObject;

                if (language != null)
                {
                    string languageValue = (string)language["value"];

                    if (!string.IsNullOrEmpty(languageValue))
                    {
                        if (languageValue.ToLower().StartsWith("de"))
                        {
                            mainLanguage = "de";
                        }
                        else if (languageValue.ToLower().StartsWith("en"))
                        {
                            mainLanguage = "en";
                        }
                        else if (languageValue.ToLower().StartsWith("zh"))
                        {
                            mainLanguage = "zh";
                        }
                    }
                }
            }

            string secondLanguage = "de";

            string foreignLanguageFieldID = GetCustomFieldName(jiraIssue, "Foreign Language");

            if (!string.IsNullOrEmpty(foreignLanguageFieldID))
            {
                JObject foreignLanguage = jiraIssue.FieldDictionary[foreignLanguageFieldID] as JObject;
                if (foreignLanguage != null)
                {
                    string foreignLanguageValue = (string)foreignLanguage["value"];

                    if (!string.IsNullOrEmpty(foreignLanguageValue))
                    {
                        if (foreignLanguageValue.ToLower().StartsWith("en"))
                        {
                            secondLanguage = "en";
                        }
                        else if (foreignLanguageValue.ToLower().StartsWith("de"))
                        {
                            secondLanguage = "de";
                        }
                        else if (foreignLanguageValue.ToLower().StartsWith("zh"))
                        {
                            secondLanguage = "zh";
                        }
                    }
                }
            }

            if (mainLanguage == secondLanguage)
            {
                if (mainLanguage == "en")
                {
                    secondLanguage = "de";
                }
                else if (mainLanguage == "de")
                {
                    secondLanguage = "en";
                }
                else
                {
                    mainLanguage = "en";
                }
            }

            string mainTitleContent       = jiraIssue.Fields.Summary;
            string mainDescriptionContent = descriptionHtml;

            string secondTitleFieldID = GetCustomFieldName(jiraIssue, "Foreign Title");
            string secondTitleContent = "";

            if (!string.IsNullOrEmpty(secondTitleFieldID))
            {
                secondTitleContent = (string)jiraIssue.FieldDictionary[secondTitleFieldID];
            }

            string secondDescriptionFieldID = GetCustomFieldName(jiraIssue, "Foreign Description");
            string secondDescriptionContent = "";

            if (!string.IsNullOrEmpty(secondDescriptionFieldID))
            {
                JObject secondDescriptionJobject = jiraIssue.FieldDictionary[secondDescriptionFieldID] as JObject;

                if (secondDescriptionJobject != null)
                {
                    Jira3.ADF.AtlassianDocumentFormat secondDescriptionADF = secondDescriptionJobject.ToObject <Jira3.ADF.AtlassianDocumentFormat>();

                    secondDescriptionContent = adfToXhtmlConverter.ConvertAdfToXhtml(secondDescriptionADF);
                }
            }

            Value titleValue       = new Value();
            Value descriptionValue = new Value();

            if (mainLanguage == "en")
            {
                MultilanguageText firstTitle = new MultilanguageText
                {
                    Text     = mainTitleContent,
                    Language = mainLanguage,
                    Format   = TextFormat.Plain
                };

                titleValue.MultilanguageText.Add(firstTitle);

                MultilanguageText secondTitle = new MultilanguageText
                {
                    Text     = secondTitleContent,
                    Language = secondLanguage,
                    Format   = TextFormat.Plain
                };

                titleValue.MultilanguageText.Add(secondTitle);

                MultilanguageText firstDescription = new MultilanguageText
                {
                    Text     = mainDescriptionContent,
                    Language = mainLanguage,
                    Format   = TextFormat.XHTML
                };

                descriptionValue.MultilanguageText.Add(firstDescription);

                MultilanguageText secondDescription = new MultilanguageText
                {
                    Text     = secondDescriptionContent,
                    Language = secondLanguage,
                    Format   = TextFormat.XHTML
                };

                descriptionValue.MultilanguageText.Add(secondDescription);
            }
            else if (secondLanguage == "en")
            {
                MultilanguageText firstTitle = new MultilanguageText
                {
                    Text     = secondTitleContent,
                    Language = secondLanguage,
                    Format   = TextFormat.Plain
                };

                titleValue.MultilanguageText.Add(firstTitle);

                MultilanguageText secondTitle = new MultilanguageText
                {
                    Text     = mainTitleContent,
                    Language = mainLanguage,
                    Format   = TextFormat.Plain
                };

                titleValue.MultilanguageText.Add(secondTitle);

                MultilanguageText firstDescription = new MultilanguageText
                {
                    Text     = secondDescriptionContent,
                    Language = "en",
                    Format   = TextFormat.XHTML
                };

                descriptionValue.MultilanguageText.Add(firstDescription);

                MultilanguageText secondDescription = new MultilanguageText
                {
                    Text     = mainDescriptionContent,
                    Language = mainLanguage,
                    Format   = TextFormat.XHTML
                };

                descriptionValue.MultilanguageText.Add(secondDescription);
            }

            result.SetPropertyValue("dcterms:title", titleValue, _metadataReader);

            //jiraIssue.FieldDictionary[""];

            result.SetPropertyValue("dcterms:description", descriptionValue, _metadataReader);

            string lifecycleStatus = ConvertJiraStatusToSpecIfLifeCycleStatus(jiraIssue);

            result.SetPropertyValue("SpecIF:LifeCycleStatus", lifecycleStatus, _metadataReader);

            return(result);
        }
示例#2
0
        private async Task <List <Node> > CreateProjectHierarchiesAsync(bool rootNodesOnly, string projectFilter = null)
        {
            List <Node> result = new List <Node>();

            try
            {
                ProjectRootResources = new List <Resource>();

                ProjectSearchResponse projectSearchResponse = await _jiraClient.GetJiraProjectsAsync();



                foreach (Project project in projectSearchResponse.Values)
                {
                    string projectID = JiraGuidConverter.ConvertToSpecIfGuid(project.Self, project.ID);


                    if (projectFilter == null || (projectFilter != null && projectID == projectFilter))
                    {
                        string projectResourceID = "_" + SpecIfGuidGenerator.CalculateSha1Hash(project.Key);

                        Key resourceClass = new Key("RC-Hierarchy", "1.1");

                        Resource projectHierarchyResource = SpecIfDataFactory.CreateResource(resourceClass, _metadataReader);

                        projectHierarchyResource.ID       = projectResourceID;
                        projectHierarchyResource.Revision = "1";

                        projectHierarchyResource.SetPropertyValue("dcterms:title", "Jira Project " + project.Key, _metadataReader);

                        projectHierarchyResource.SetPropertyValue("dcterms:description", project.Name, _metadataReader);


                        ProjectRootResources.Add(projectHierarchyResource);


                        Node projectNode = new Node
                        {
                            ID              = projectResourceID + "_Node",
                            Revision        = "1",
                            IsHierarchyRoot = true,
                            ProjectID       = project.Key,
                            ResourceObject  = new Key(projectHierarchyResource.ID, projectHierarchyResource.Revision)
                        };

                        result.Add(projectNode);

                        if (!rootNodesOnly)
                        {
                            IssueSearchResponse issueSearchResponse = await GetProjectIssuesAsync(project.Key);

                            if (issueSearchResponse != null)
                            {
                                foreach (Issue issue in issueSearchResponse.Issues)
                                {
                                    string issueResourceID = JiraGuidConverter.ConvertToSpecIfGuid(issue.Self, issue.ID);

                                    string issueRevision = SpecIfGuidGenerator.ConvertDateToRevision(issue.Fields.Updated.Value);

                                    Node requirementNode = new Node
                                    {
                                        ID              = issueResourceID + "_Node",
                                        Revision        = "1",
                                        IsHierarchyRoot = false,
                                        ProjectID       = project.Key,
                                        ResourceObject  = new Key(issueResourceID, issueRevision)
                                    };

                                    projectNode.Nodes.Add(requirementNode);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }

            return(result);
        }