/// <summary>
        /// Create an <see cref="AlternativeId"/> for the <see cref="Identifiable"/>
        /// </summary>
        /// <param name="identifiable">
        /// The <see cref="Identifiable"/> for which an <see cref="AlternativeId"/> needs to be created
        /// </param>
        private void CreateAlternativeId(Identifiable identifiable)
        {
            var alternativeId = new AlternativeId();

            alternativeId.Identifier = identifiable.Identifier + "_alternative";

            alternativeId.Ident        = identifiable;
            identifiable.AlternativeId = alternativeId;
        }
Beispiel #2
0
        public void Verify_that_constructor_works_as_expected()
        {
            var specObject = new SpecObject();

            var alternativeId = new AlternativeId(specObject);

            Assert.That(specObject.AlternativeId, Is.EqualTo(alternativeId));

            Assert.That(alternativeId.Ident, Is.EqualTo(specObject));
        }
Beispiel #3
0
        public void Verify_That_WriteXmlAsync_throws_exception_when_cancelled()
        {
            using var memoryStream = new MemoryStream();
            using var writer       = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true });

            var alternativeId = new AlternativeId();

            var cts = new CancellationTokenSource();

            cts.Cancel();

            Assert.That(
                async() => await alternativeId.WriteXmlAsync(writer, cts.Token),
                Throws.Exception.TypeOf <OperationCanceledException>());
        }
Beispiel #4
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);
        }