Ejemplo n.º 1
0
        private Requirement CreateOrUpdateRequirement(RequirementSet rs, JiraConfig config, JiraService.Issue.Issue issue)
        {
            Requirement req = FindRequirementForIssue(rs, issue.key);

            if (req == null)
            {
                req = rs.CreateRequirement();
            }
            //Move requirement to parent
            string parentKey = (issue.fields.parent == null ? null : issue.fields.parent.key);

            if (config.parentLocatorPropertyOverride != null)
            {
                string parentKeyOverride = issue.GetValueByPath(config.parentLocatorPropertyOverride);
                if (parentKeyOverride != null)
                {
                    parentKey = parentKeyOverride;
                }
            }
            if (parentKey != null)
            {
                Requirement parent = FindRequirementForIssue(rs, parentKey);
                if (parent != null)
                {
                    parent.Move(req);
                }
            }
            try
            {
                req.SetAttibuteValue(Global.JiraTicket, issue.key);
            }
            catch (Exception)
            {
                throw new Exception("Please prepare project for integration (available from context menu at project level) and then try again");
            }
            //req.SetAttibuteValue(Global.JiraDefectID, issue.id);
            foreach (var fieldMap in config.fieldMaps)
            {
                string jiraValue = issue.GetValueByPath(fieldMap.jiraJsonPath);
                try
                {
                    req.SetAttibuteValue(fieldMap.toscaField, jiraValue);
                }
                catch (Exception)
                {
                    //NOM NOM NOM: Tasty tasty exceptions
                }
            }
            return(req);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides the kind of issue
        /// </summary>
        /// <param name="issue"></param>
        /// <returns></returns>
        public static IssueKind?GetKind(Paragraph issue)
        {
            IssueKind?retVal = null;

            foreach (RequirementSetReference reference in issue.RequirementSetReferences)
            {
                RequirementSet requirementSet = reference.Ref;
                while (requirementSet != null && retVal == null)
                {
                    if (requirementSet.Name.Equals(Blocking))
                    {
                        retVal = IssueKind.Blocking;
                    }
                    else if (requirementSet.Name.Equals(Issue))
                    {
                        retVal = IssueKind.Issue;
                    }
                    else if (requirementSet.Name.Equals(Comment))
                    {
                        retVal = IssueKind.Comment;
                    }
                    else if (requirementSet.Name.Equals(Question))
                    {
                        retVal = IssueKind.Question;
                    }

                    requirementSet = requirementSet.Enclosing as RequirementSet;
                }

                if (retVal != null)
                {
                    break;
                }
            }

            return(retVal);
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="requirementSet"></param>
 /// <param name="paragraphs"></param>
 public ParagraphForRequirementSet(RequirementSet requirementSet, List<Paragraph> paragraphs)
 {
     RequirementSet = requirementSet;
     Paragraphs = paragraphs;
 }
 /// <summary>
 ///     Adds a new requirement set to this list of requirement sets
 /// </summary>
 /// <param name="requirementSet"></param>
 public void AddRequirementSet(RequirementSet requirementSet)
 {
     appendSubSets(requirementSet);
 }
Ejemplo n.º 5
0
        public override TCObject Execute(TCObject requirementSet, TCAddOnTaskContext taskContext)
        {
            RequirementSet rs     = (RequirementSet)requirementSet;
            JiraConfig     config = rs.GetJiraConfig();

            #region Setup
            if (config == null)
            {
                string url      = taskContext.GetStringValue("Jira Instance URL: ", false);
                string jqlValue = taskContext.GetStringValue("JQL Filter for requirements: ", false);
                config = new JiraConfig
                {
                    baseURL   = url,
                    jqlFilter = jqlValue,
                    fieldMaps = new List <FieldMap>()
                    {
                        new FieldMap {
                            direction = JiraService.Configuration.Direction.jira_to_tosca, jiraJsonPath = "$.fields.summary", toscaField = "Name"
                        }
                    }
                };
                rs.SaveConfig(config);
            }
            string username, password;
            if (CredentialManager.Instance.Credentials.Any(x => x.BaseURL == config.baseURL))
            {
                Credential credential = CredentialManager.Instance.Credentials.First(x => x.BaseURL == config.baseURL);
                username = credential.Username;
                password = credential.Password;
            }
            else
            {
                username = taskContext.GetStringValue("Jira Username", false);
                password = taskContext.GetStringValue("Jira Password", true);
                CredentialManager.Instance.StoreOrUpdateCredential(new Credential
                {
                    BaseURL     = config.baseURL,
                    Description = "Created by Jira Config",
                    Username    = username,
                    Password    = password
                });
            }
            #endregion

            var    jira         = new JiraService.Jira(config.baseURL, username, password);
            var    issueService = jira.GetIssueService();
            String startTime    = DateTime.Now.ToString("yyyyMMddHHmmss");
            string jql          = config.jqlFilter;
            JiraService.Issue.Issue[]        issues    = null;
            Task <JiraService.Issue.Issue[]> issueTask = null;
            try
            {
                issueTask = issueService.SearchAsync(jql);
                while (!issueTask.IsCompleted)
                {
                    taskContext.ShowStatusInfo($"Gettign issues for JQL: {jql}");
                    System.Threading.Thread.Sleep(100);
                }
                //order the issues so that subtasks are not created before parent tasks
                issues = issueTask.Result.OrderBy(x => x.fields.project.name).ThenBy(x => x.id).ToArray();
                taskContext.ShowStatusInfo("Creating Requirements");
            }
            catch (Exception e)
            {
                string err = e.Message;
                if (e.InnerException != null)
                {
                    err += "\r\n" + e.InnerException.Message;
                }
                taskContext.ShowErrorMessage($"Error synchronising", err);
                taskContext.ShowStatusInfo($"Error synchronising: {err}");
                return(requirementSet);
            }
            HashSet <string> updatedItems = new HashSet <string>();
            if (issues != null)
            {
                foreach (var issue in issues)
                {
                    var req = CreateOrUpdateRequirement(rs, config, issue);
                    updatedItems.Add(req.UniqueId);
                }

                // Prompt status
                taskContext.ShowMessageBox("Jira Sync", issues.Length.ToString() + " requirements have been synchronised.");
            }
            return(null);
        }
Ejemplo n.º 6
0
        private Requirement FindRequirementForIssue(RequirementSet rs, string issueKey)
        {
            Requirement req = rs.Search($"=>SUBPARTS:Requirement[{Global.JiraTicket}==\"{issueKey}\"]").FirstOrDefault() as Requirement;

            return(req);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Adds a requirement set to a capp report for a user
        /// </summary>
        /// <param name="username">UserName of user to add requirement set for</param>
        /// <param name="cappReportName">Name of capp report to add requirement set to</param>
        /// <param name="requirementSetName">Name of requirement set to add to capp report</param>
        /// <param name="depthRequirement">Bool indicating whether or not there is a depth requirement in this requirement set</param>
        /// <param name="creditsNeeded">Credits needed to fulfill the requirement set</param>
        /// <param name="maxPnc">Maximum number of Pass No Credit credits allowed in this requirement set</param>
        /// <returns>RequirementSetModel of requirement set added or null if user or capp report could not be found</returns>
        public static RequirementSetModel CreateRequirementSet(string username, string cappReportName,
            string requirementSetName,
            bool depthRequirement, int creditsNeeded, int maxPnc)
        {
            using (var entities = GetEntityModel())
            {
                var user = entities.ApplicationUsers.FirstOrDefault(appuser => appuser.Username == username);
                if (user == null) return null;

                var cappreport = user.CAPPReports.FirstOrDefault(capp => capp.Name == cappReportName);
                if (cappreport == null) return null;

                var reqset = new RequirementSet
                {
                    Credits = creditsNeeded,
                    DepthRSR = depthRequirement,
                    Name = requirementSetName,
                    PassNCCredits = maxPnc,
                    Description = string.Empty
                };
                cappreport.RequirementSets.Add(reqset);
                entities.SaveChanges();

                return reqset.ToRequirementSetModel();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Indicates whether this paragraphs belongs to the functionam block whose name is provided as parameter
        /// </summary>
        /// <param name="requirementSet"></param>
        public bool BelongsToRequirementSet(RequirementSet requirementSet)
        {
            bool retVal = false;

            if (requirementSet != null)
            {
                // Try to find a reference to this requirement set
                foreach (RequirementSetReference reference in RequirementSetReferences)
                {
                    if (reference.Ref == requirementSet)
                    {
                        retVal = true;
                        break;
                    }
                }

                // Maybe a parent paragraph references this requirement set
                // (only if the requirement set specifies that selection is recursive)
                if (!retVal && requirementSet.getRecursiveSelection())
                {
                    Paragraph enclosing = EnclosingParagraph;
                    if (enclosing != null)
                    {
                        retVal = enclosing.BelongsToRequirementSet(requirementSet);
                    }
                }

                // Try if the requirement belong to a sub requirement set
                if (!retVal)
                {
                    foreach (RequirementSet subSet in requirementSet.SubSets)
                    {
                        if (BelongsToRequirementSet(subSet))
                        {
                            retVal = true;
                            break;
                        }
                    }
                }
            }

            return retVal;
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Appends this paragraph to the requirement set if it does not belong to it already
        /// </summary>
        /// <param name="requirementSet"></param>
        public bool AppendToRequirementSet(RequirementSet requirementSet)
        {
            bool retVal = false;

            if (!BelongsToRequirementSet(requirementSet))
            {
                retVal = true;
                RequirementSetReference reference =
                    (RequirementSetReference) acceptor.getFactory().createRequirementSetReference();
                reference.setTarget(requirementSet.Guid);
                appendRequirementSets(reference);
            }

            return retVal;
        }
Ejemplo n.º 10
0
        public bool SubParagraphBelongsToRequirementSet(RequirementSet requirementSet)
        {
            bool retVal = false;

            foreach (Paragraph p in SubParagraphs)
            {
                retVal = p.BelongsToRequirementSet(requirementSet) ||
                         p.SubParagraphBelongsToRequirementSet(requirementSet);
                if (retVal)
                {
                    break;
                }
            }

            return retVal;
        }