Author Topic: Access to baseline creation date  (Read 1148 times)

blaisephilip

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Access to baseline creation date
« on: May 13, 2024, 11:52:23 pm »
I'm developing an add-in and need to access the creation dates of a package's baselines and use these as part of a generated document's release history.
The following snippet retrieves the baseline information's basic elements (version, name, notes) correctly as raw XML.

Code: [Select]
Project projInterface = currentRepository.GetProjectInterface();
        string baselineInfo = projInterface.GetBaselines(pkg.PackageGUID, "");

So, baselineInfo can be post-processed to become part of the document. However, it does not contain any information about the baseline's creation date. In our case, I could ask users to use a manually entered date entry in the baseline notes but that could be falsified, so I don't want to go with that option.
The EA Menu's Design --> Package -> Manage -> Find Baselines feature provides a Baseline_Date column for all baselines of a package, with help of the Find in Project feature. So in the DB there is at least a table that stores the baseline creation date values.

Is there any way to reach the Baseline_Date values with help of the object model in a C# add-in?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +395/-301
  • I'm no guru at all
    • View Profile
Re: Access to baseline creation date
« Reply #1 on: May 14, 2024, 02:50:18 am »
Try a
Code: [Select]
SELECT DocDate FROM t_document
q.

philchudley

  • EA User
  • **
  • Posts: 732
  • Karma: +19/-0
  • UML/EA Principal Consultant / Trainer
    • View Profile
Re: Access to baseline creation date
« Reply #2 on: May 14, 2024, 10:45:52 pm »
Wot qwerty said plus you may find the following fields useful as well to filter out baselines for other documents stored within the t_document table

t_document.DocID       : which despite its name is actually a GUID (the guid of the actual document entry?)
t_document.ElementID : which despite its name is actually a GUID (the GUID of the baseline?)
t_document.DocName  : the name of the baseline
t_document.DocType    : this has the value Baseline for a Baseline in the t_document table

Phil
follow me on Twitter

@SparxEAGuru

blaisephilip

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Access to baseline creation date
« Reply #3 on: May 15, 2024, 07:48:54 pm »
Thanks for the hints about t_document content! I've implemented the solution by assembling the date of creation and the rest to a single XML output.
The GUID of the baseline (available as attribute in a baseline node within the raw XML) is actually the t_document table's DocID column.

Code: [Select]
        private void GetPackageBaselineInfo(Package pkg)
        {
            if (cfgHandling.bBaselineInfoSupport)
            {
                log("Available package baselines are collected for release history...");

                Project projInterface = currentRepository.GetProjectInterface();
                XmlDocument baselineInfo = new XmlDocument();
                // this retrieves only GUID, version, name and notes for the baseline
                string sBaselineInfoRaw = projInterface.GetBaselines(pkg.PackageGUID, "");
                sBaselineInfoRaw = sBaselineInfoRaw.Replace("><Baseline ", ">\r\n<Baseline ");
                baselineInfo.LoadXml(sBaselineInfoRaw);
                XmlNode blCollection = baselineInfo.SelectSingleNode("EA.BaseLines");

                if ((baselineInfo != null) && (blCollection != null))
                {
                    XmlDocument baselineInfoExt = (XmlDocument)baselineInfo.Clone(); // extended baseline info, to be exported
                    XmlAttribute cDate = baselineInfoExt.CreateAttribute("creationdate");
                    if (cDate == null)
                    {
                        log("Creation date could not be added as new attribute. No baseline info will be extracted.");
                        return;
                    }
                    if (baselineInfoExt == null)
                    {
                        log("Output baseline info XML creation failed.");
                        return;
                    }
                    else
                    {
                        log("Count of available baselines: " + blCollection.ChildNodes.Count.ToString());
                        // take each baseline to get the date of creation too
                        foreach (XmlNode node in blCollection.ChildNodes)
                        {
                            string guid = GetAttributeValue(node, "guid");
                            if (guid != null)
                            {
                                string sQuery = "SELECT `DocDate` FROM `t_document` WHERE `DocID` LIKE \"" + guid + "\"";
                                string date = currentRepository.SQLQuery(sQuery); // date is still raw XML, as date+time
                                XmlDocument DateXML = new XmlDocument();
                                DateXML.LoadXml(date);
                                DateTime dtDate = DateTime.Parse(DateXML.SelectSingleNode("//DocDate").InnerText);
                                // insert the date of creation to the baseline XML
                                XmlNode targetNode = baselineInfoExt.SelectSingleNode("//Baseline[@guid='" + guid + "']");
                                if (targetNode != null)
                                {
                                    cDate.Value = dtDate.Date.ToString("yyyy-MM-dd");
                                    targetNode.Attributes.SetNamedItem(cDate);
                                }
                                else
                                {
                                    log("Target node not found by baseline GUID.");
                                    return;
                                }
                            }
                            else
                            {
                                log("Package baseline with empty GUID found. This shall be an error. The process ends now.");
                                return;
                            }
                        }
                        log("Baseline content collected, writing to XML...");
                        baselineInfoExt.Save(Path.Combine(cfgHandling.sAddInPath, "temp_baselines.xml"));
                        log("Baseline information saved to XML.");
                    }
                }
                else
                {
                    log("Node collection not found.");
                }
            }
        }
« Last Edit: May 15, 2024, 10:25:21 pm by blaisephilip »