CreateOwningObjSurElement() static private method

Given the guid, return a new 'objsur' XElement.
static private CreateOwningObjSurElement ( string guid ) : System.Xml.Linq.XElement
guid string
return System.Xml.Linq.XElement
Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change model for Data Notebook to combine the RnEvent and RnAnalysis classes
        /// into RnGenericRec
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of its work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000004);

            // 1. Change EventTypes field to RecTypes
            var nbkDto            = domainObjectDtoRepository.AllInstancesSansSubclasses("RnResearchNbk").First();
            var nbkElement        = XElement.Parse(nbkDto.Xml);
            var nbkClsElement     = nbkElement.Element("RnResearchNbk");
            var typesFieldElement = nbkClsElement.Element("EventTypes");
            var typesSurElement   = typesFieldElement.Element("objsur");

            nbkClsElement.Add(new XElement("RecTypes", typesSurElement));
            typesFieldElement.Remove();
            DataMigrationServices.UpdateDTO(domainObjectDtoRepository, nbkDto, nbkElement.ToString());

            // 2. Add Analysis possibility to Record Types list
            var typesGuid    = typesSurElement.Attribute("guid").Value;
            var typesDto     = domainObjectDtoRepository.GetDTO(typesGuid);
            var typesElement = XElement.Parse(typesDto.Xml);

            typesElement.XPathSelectElement("CmMajorObject/Name/AUni[@ws='en']").SetValue("Entry Types");
            var posElement = typesElement.XPathSelectElement("CmPossibilityList/Possibilities");

            posElement.Add(
                DataMigrationServices.CreateOwningObjSurElement("82290763-1633-4998-8317-0EC3F5027FBD"));
            DataMigrationServices.UpdateDTO(domainObjectDtoRepository, typesDto,
                                            typesElement.ToString());
            var ord = posElement.Elements().Count();

            var nowStr      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            var typeElement = new XElement("rt", new XAttribute("class", "CmPossibility"),
                                           new XAttribute("guid", "82290763-1633-4998-8317-0EC3F5027FBD"),
                                           new XAttribute("ownerguid", typesGuid),
                                           new XAttribute("owningflid", "8008"), new XAttribute("owningord", ord.ToString()),
                                           new XElement("CmObject"),
                                           new XElement("CmPossibility",
                                                        new XElement("Abbreviation",
                                                                     new XElement("AUni", new XAttribute("ws", "en"), "Ana")),
                                                        new XElement("BackColor", new XAttribute("val", "16711680")),
                                                        new XElement("DateCreated", new XAttribute("val", nowStr)),
                                                        new XElement("DateModified", new XAttribute("val", nowStr)),
                                                        new XElement("Description",
                                                                     new XElement("AStr", new XAttribute("ws", "en"),
                                                                                  new XElement("Run", new XAttribute("ws", "en"), "Reflection on events and other types of data, such as literature summaries or interviews. An analysis does not add data; it interprets and organizes data. An analysis entry may synthesize emerging themes. It may draw connections between observations. It is a place to speculate and hypothesize, or document moments of discovery and awareness. Analytic notes can be turned into articles. Or, they may just be steps on the stairway toward greater understanding."))),
                                                        new XElement("ForeColor", new XAttribute("val", "16777215")),
                                                        new XElement("Name",
                                                                     new XElement("AUni", new XAttribute("ws", "en"), "Analysis")),
                                                        new XElement("UnderColor", new XAttribute("val", "255")),
                                                        new XElement("UnderStyle", new XAttribute("val", "1"))));

            domainObjectDtoRepository.Add(new DomainObjectDTO("82290763-1633-4998-8317-0EC3F5027FBD",
                                                              "CmPossibility", typeElement.ToString()));

            // 3. Move the attributes that are in RnEvent and RnAnalysis into RnGenericRec.
            MigrateSubclassOfGenRec(domainObjectDtoRepository, "RnEvent");
            MigrateSubclassOfGenRec(domainObjectDtoRepository, "RnAnalysis");

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #2
0
        private void MoveFileToFolder(IDomainObjectDTORepository repoDto, DomainObjectDTO folder, DomainObjectDTO fileToMove)
        {
            // Create surogate for file and add it to the folder
            var surrogate     = DataMigrationServices.CreateOwningObjSurElement(fileToMove.Guid);
            var folderElement = XElement.Parse(folder.Xml);
            var filesElement  = folderElement.Element("Files");

            filesElement.Add(surrogate);
            DataMigrationServices.UpdateDTO(repoDto, folder, folderElement.ToString());

            // Change owner of file
            var fileElement = XElement.Parse(fileToMove.Xml);

            fileElement.Attribute("ownerguid").SetValue(folder.Guid);
            DataMigrationServices.UpdateDTO(repoDto, fileToMove, fileElement.ToString());
        }
Example #3
0
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000040);

            // (WRONG) The ExcludeAsHeadword element only appears when @val="true" and
            // it is to be replaced by DoNotShowMainEntryIn with a list of all publications.
            // NB: The above statement is simply not true (RBR).
            // FW 7 writes out all primitive data properties.
            // The FW 6-FW7 migrator doesn't add them,
            // but FW 7 writes them the next time an object gets changed.

            // Make the list of publications once
            var newElt = new XElement("DoNotShowMainEntryIn");

            IEnumerable <XElement> dtoPubList = null;

            // XPATH: rt[Name/AUni='Publications']/Possibilities/objsur
            foreach (var a_list in domainObjectDtoRepository.AllInstancesSansSubclasses("CmPossibilityList"))
            {
                var xList = XElement.Parse(a_list.Xml);
                if (xList.XPathSelectElement("Name[AUni='Publications']") == null)
                {
                    continue;
                }
                dtoPubList = xList.XPathSelectElements("Possibilities/objsur");
                if (dtoPubList != null && dtoPubList.Count() > 0)
                {
                    break;
                }
            }

            if (dtoPubList == null || dtoPubList.Count() == 0) // add the Publications list to the project
            {                                                  // This list is owned by LexDb
                var ieDtoLexDb = domainObjectDtoRepository.AllInstancesSansSubclasses("LexDb");
                Debug.Assert(ieDtoLexDb != null && ieDtoLexDb.Count <DomainObjectDTO>() == 1, "Project has no LexDb Dto or more than one");
                var    dtoLexDb    = ieDtoLexDb.First <DomainObjectDTO>();
                var    xNode       = XElement.Parse(dtoLexDb.Xml);
                var    ksguidLexDb = xNode.Attribute("guid").Value;
                var    nowStr      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                string xmlStrPub   =
                    "<rt guid=\"" + ksguidPubList + "\" class=\"CmPossibilityList\" ownerguid=\"" + ksguidLexDb + "\"><Name><AUni ws=\"en\">Publications</AUni></Name><DateCreated val=\"" + nowStr + "\" /><DateModified val=\"" + nowStr + "\" /><Depth val=\"1\" /><PreventChoiceAboveLevel val=\"0\" /><IsSorted val=\"True\" /><IsClosed val=\"False\" /><PreventDuplicates val=\"False\" /><PreventNodeChoices val=\"False\" /><UseExtendedFields val=\"False\" /><DisplayOption val=\"0\" /><ItemClsid val=\"7\" /><IsVernacular val=\"False\" /><WsSelector val=\"0\" /><ListVersion val=\"00000000-0000-0000-0000-000000000000\" /><Possibilities><objsur guid=\"" + ksguidMainDictionary + "\" t=\"o\" /></Possibilities></rt>";
                var dtoPub = new DomainObjectDTO(ksguidPubList, "CmPossibilityList", xmlStrPub);

                string xmlStrMD = "<rt guid=\"" + ksguidMainDictionary + "\" class=\"CmPossibility\" ownerguid=\"" + ksguidPubList + "\"><Name><AUni ws=\"en\">Main Dictionary</AUni></Name><Abbreviation><AUni ws=\"en\">Main</AUni></Abbreviation><SortSpec val=\"0\" /><DateCreated val=\"" + nowStr + "\" /><DateModified val=\"" + nowStr + "\" /><ForeColor val=\"0\" /><BackColor val=\"0\" /><UnderColor val=\"0\" /><UnderStyle val=\"0\" /><Hidden val=\"False\" /><IsProtected val=\"True\" /></rt>";
                var    dtoMD    = new DomainObjectDTO(ksguidMainDictionary, "CmPossibility", xmlStrMD);

                domainObjectDtoRepository.Add(dtoMD);
                domainObjectDtoRepository.Add(dtoPub);

                // Make xLexDb own dtoPub
                var xPts = xNode.Element("PublicationTypes");
                if (xPts == null)
                {                   // add one to LexDb
                    xPts = new XElement("PublicationTypes");
                    xPts.Add(DataMigrationServices.CreateOwningObjSurElement(ksguidPubList));
                    xNode.Add(xPts);
                }
                Debug.Assert(xPts != null, "LexDb has no PublicatonTypes and won't accept new ones.");
                dtoLexDb.Xml = xNode.ToString();
                domainObjectDtoRepository.Update(dtoLexDb);
                newElt.Add(DataMigrationServices.CreateReferenceObjSurElement(ksguidMainDictionary));
            }
            else
            {               // already had a publications list - add all to DoNotShowMainEntryIn
                foreach (var xElt in dtoPubList)
                {           // change the t attr to "r" reference instead of "o" own.
                    var xPubRef = new XElement(xElt);
                    xPubRef.SetAttributeValue("t", "r");
                    newElt.Add(xPubRef);
                }
            }
            foreach (var dto in domainObjectDtoRepository.AllInstancesSansSubclasses("LexEntry"))
            {
                // (WRONG) The ExcludeAsHeadword element only appears when @val="true" unless played with in a text editor
                // NB: The above statement is simply not true (RBR).
                // FW 7 writes out all primitive data properties.
                // The FW 6-FW7 migrator doesn't add them,
                // but FW 7 writes them the next time an object gets changed.
                var xElt       = XElement.Parse(dto.Xml);
                var exHeadword = xElt.Element("ExcludeAsHeadword");
                if (exHeadword == null)
                {
                    continue;
                }
                XAttribute XAval = exHeadword.Attribute("val");
                // It must be upper-case, since that is what is output.
                if (XAval.Value == "True")
                {                       // Add all publications from the list to this property
                    xElt.Add(new XElement(newElt));
                }
                exHeadword.Remove();                 // exHeadword.Value may be True, False or invalid
                dto.Xml = xElt.ToString();
                domainObjectDtoRepository.Update(dto);
            }
            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #4
0
        /// <summary>
        /// Add a few items to the Notebook Record Type list, and rearrange the list a bit.  The original
        /// list should look something like:
        ///		Conversation
        ///		Interview
        ///			Structured
        ///			Unstructured
        ///		Literature Summary
        ///		Observation
        ///			Performance
        ///		Analysis
        ///	After the migration, the list should look something like:
        ///		Event
        ///			Observation
        ///			Conversation
        ///			Interview
        ///				Structured
        ///				Unstructured
        ///			Performance
        ///		Literature Summary
        ///		Analysis
        ///		Methodology
        ///		Weather
        /// </summary>
        /// <remarks>
        /// This implements FWR-643.  Note that users can edit this list, so any of the expected
        /// items could have been deleted or moved around in the list.  :-(
        /// </remarks>
        public void PerformMigration(IDomainObjectDTORepository repoDTO)
        {
            DataMigrationServices.CheckVersionNumber(repoDTO, 7000015);

            DomainObjectDTO dtoList             = repoDTO.GetDTO(ksguidRecTypesList);
            XElement        xeList              = XElement.Parse(dtoList.Xml);
            XElement        xeListPossibilities = xeList.XPathSelectElement("Possibilities");

            if (xeListPossibilities == null)
            {
                xeListPossibilities = new XElement("Possibilities");
                xeList.Add(xeListPossibilities);
            }
            // The user can edit the list, so these might possibly have been deleted (or moved).  :-(
            DomainObjectDTO dtoObservation  = GetDTOIfItExists(repoDTO, ksguidObservation);
            DomainObjectDTO dtoConversation = GetDTOIfItExists(repoDTO, ksguidConversation);
            DomainObjectDTO dtoInterview    = GetDTOIfItExists(repoDTO, ksguidInterview);
            DomainObjectDTO dtoPerformance  = GetDTOIfItExists(repoDTO, ksguidPerformance);

            // Create the new Event, Methodology, and Weather record types.
            var nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("<rt class=\"CmPossibility\" guid=\"{0}\" ownerguid=\"{1}\">",
                            ksguidEvent, ksguidRecTypesList);
            sb.Append("<Abbreviation><AUni ws=\"en\">Evnt</AUni></Abbreviation>");
            sb.Append("<Name><AUni ws=\"en\">Event</AUni></Name>");
            sb.AppendFormat("<DateCreated val=\"{0}\"/>", nowStr);
            sb.AppendFormat("<DateModified val=\"{0}\"/>", nowStr);
            sb.Append("</rt>");
            XElement xeEvent  = XElement.Parse(sb.ToString());
            var      dtoEvent = new DomainObjectDTO(ksguidEvent, "CmPossibility", xeEvent.ToString());

            repoDTO.Add(dtoEvent);
            xeListPossibilities.AddFirst(DataMigrationServices.CreateOwningObjSurElement(ksguidEvent));

            sb = new StringBuilder();
            sb.AppendFormat("<rt class=\"CmPossibility\" guid=\"{0}\" ownerguid=\"{1}\">",
                            ksguidMethodology, ksguidRecTypesList);
            sb.Append("<Abbreviation><AUni ws=\"en\">Method</AUni></Abbreviation>");
            sb.Append("<Name><AUni ws=\"en\">Methodology</AUni></Name>");
            sb.AppendFormat("<DateCreated val=\"{0}\"/>", nowStr);
            sb.AppendFormat("<DateModified val=\"{0}\"/>", nowStr);
            sb.Append("</rt>");
            var dtoMethod = new DomainObjectDTO(ksguidMethodology, "CmPossibility", sb.ToString());

            repoDTO.Add(dtoMethod);
            xeListPossibilities.LastNode.AddAfterSelf(DataMigrationServices.CreateOwningObjSurElement(ksguidMethodology));

            sb = new StringBuilder();
            sb.AppendFormat("<rt class=\"CmPossibility\" guid=\"{0}\" ownerguid=\"{1}\">",
                            ksguidWeather, ksguidRecTypesList);
            sb.Append("<Abbreviation><AUni ws=\"en\">Wthr</AUni></Abbreviation>");
            sb.Append("<Name><AUni ws=\"en\">Weather</AUni></Name>");
            sb.AppendFormat("<DateCreated val=\"{0}\"/>", nowStr);
            sb.AppendFormat("<DateModified val=\"{0}\"/>", nowStr);
            sb.Append("</rt>");
            var dtoWeather = new DomainObjectDTO(ksguidWeather, "CmPossibility", sb.ToString());

            repoDTO.Add(dtoWeather);
            xeListPossibilities.LastNode.AddAfterSelf(DataMigrationServices.CreateOwningObjSurElement(ksguidWeather));

            DataMigrationServices.UpdateDTO(repoDTO, dtoList, xeList.ToString());

            // Change the ownership links for the moved items.
            if (dtoObservation != null)
            {
                ChangeOwner(repoDTO, dtoObservation, ksguidEvent, "SubPossibilities");
            }
            if (dtoConversation != null)
            {
                ChangeOwner(repoDTO, dtoConversation, ksguidEvent, "SubPossibilities");
            }
            if (dtoInterview != null)
            {
                ChangeOwner(repoDTO, dtoInterview, ksguidEvent, "SubPossibilities");
            }
            if (dtoPerformance != null)
            {
                ChangeOwner(repoDTO, dtoPerformance, ksguidEvent, "SubPossibilities");
            }

            DataMigrationServices.IncrementVersionNumber(repoDTO);
        }
Example #5
0
        private void ChangeOwner(IDomainObjectDTORepository repoDTO, DomainObjectDTO dto, string sGuidNew,
                                 string xpathNew)
        {
            XElement   xe       = XElement.Parse(dto.Xml);
            XAttribute xaOwner  = xe.Attribute("ownerguid");
            string     sGuidOld = null;

            if (xaOwner != null)
            {
                sGuidOld = xe.Attribute("ownerguid").Value;
                xe.Attribute("ownerguid").Value = sGuidNew;
            }
            else
            {
                xe.AddAnnotation(new XAttribute("ownerguid", sGuidNew));
            }
            DataMigrationServices.UpdateDTO(repoDTO, dto, xe.ToString());
            if (sGuidOld != null)
            {
                DomainObjectDTO dtoOldOwner = repoDTO.GetDTO(sGuidOld);
                XElement        xeOldOwner  = XElement.Parse(dtoOldOwner.Xml);
#if !__MonoCS__
                string   xpathOld = String.Format(".//objsur[@t='o' and @guid='{0}']", dto.Guid);
                XElement xeOldRef = xeOldOwner.XPathSelectElement(xpathOld);
                if (xeOldRef == null)
                {
                    xpathOld = String.Format(".//objsur[@t='o' and @guid='{0}']", dto.Guid.ToLowerInvariant());
                    xeOldRef = xeOldOwner.XPathSelectElement(xpathOld);
                }
                if (xeOldRef == null)
                {
                    xpathOld = String.Format(".//objsur[@t='o' and @guid='{0}']", dto.Guid.ToUpperInvariant());
                    xeOldRef = xeOldOwner.XPathSelectElement(xpathOld);
                }
                if (xeOldRef == null)
                {
                    foreach (XElement x in xeOldOwner.XPathSelectElements(".//objsur[@t='0']"))
                    {
                        var guidDst = x.Attribute("guid");
                        if (guidDst != null && guidDst.Value.ToLowerInvariant() == dto.Guid.ToLowerInvariant())
                        {
                            xeOldRef = x;
                            break;
                        }
                    }
                }
#else // TODO-Linux: work around mono bug https://bugzilla.novell.com/show_bug.cgi?id=594877
                XElement xeOldRef = null;
                xeOldRef = LocateObjsurElement(xeOldOwner, "o", dto.Guid);
                if (xeOldRef == null)
                {
                    xeOldRef = LocateObjsurElement(xeOldOwner, "0", dto.Guid);
                }
#endif
                if (xeOldRef != null)
                {
                    xeOldRef.Remove();
                    DataMigrationServices.UpdateDTO(repoDTO, dtoOldOwner, xeOldOwner.ToString());
                }
            }
            DomainObjectDTO dtoNewOwner = repoDTO.GetDTO(sGuidNew);
            XElement        xeNewOwner  = XElement.Parse(dtoNewOwner.Xml);
            XElement        xeNewField  = xeNewOwner.XPathSelectElement(xpathNew);
            if (xeNewField == null)
            {
                xeNewField = CreateXPathElementsAsNeeded(xpathNew, xeNewOwner);
            }
            if (xeNewField == null)
            {
                throw new ArgumentException("invalid XPath expression for storing owning objsur element");
            }
            XElement xeObjSur = DataMigrationServices.CreateOwningObjSurElement(dto.Guid);
            if (xeNewField.HasElements)
            {
                xeNewField.LastNode.AddAfterSelf(xeObjSur);
            }
            else
            {
                xeNewField.AddFirst(xeObjSur);
            }
            DataMigrationServices.UpdateDTO(repoDTO, dtoNewOwner, xeNewOwner.ToString());
        }