diff --git a/PROMS/DataLoader/Transitions.cs b/PROMS/DataLoader/Transitions.cs index a81ccf02..3a646607 100644 --- a/PROMS/DataLoader/Transitions.cs +++ b/PROMS/DataLoader/Transitions.cs @@ -26,14 +26,25 @@ namespace DataLoader { public partial class Loader { - private string AddTrans(Content fromCon, DataRow dr, DataRow dr2) + Dictionary> _ContentMigrationErrors = new Dictionary>(); + List _TransitionMigrationErrors = null; + //private void AddContentMigrationError(Content fromCon,string errorMsg) + //{ + // if (!_ContentMigrationErrors.ContainsKey(fromCon.ContentID)) + // _ContentMigrationErrors.Add(fromCon.ContentID,new List()); + // _ContentMigrationErrors[fromCon.ContentID].Add(errorMsg); + //} + + private string AddTrans(OleDbConnection cn, Content fromCon, DataRow dr, DataRow dr2, string pth) { + List migrationErrors = new List(); //TODO: ZTransitions tr.Oldto = dr["OLDTO"].ToString(); string thekey = dr["TONUMBER"].ToString() + "|" + dr["TOSEQUENCE"].ToString(); string dti = dr["DTI"].ToString().PadRight(18, ' '); string userid = dti.Substring(13, 5).Trim(); int itype = 0; ConfigInfo ci = null; + //string otranskey = null; // The transition type was stored as a character & also, when read in thru // ado.net may have been converted into unicode. So in order to get the // correct type, first, use the TextConvert to eliminate the conversion done @@ -60,6 +71,16 @@ namespace DataLoader itype = -1; } DateTime dts = GetDTS(MakeDate(dti.Substring(0, 8).Trim()), dti.Substring(8, 5).Trim()); + + //// if this is an Outside Transition, then decode the ToTrans to the procedure set path and + // // procedure number. This will be saved in the tr.MyZTransition.Oldto for now. + // // Then, after all the set are processed, we'll grab these and find the proper ITEM for + // // the transition reference. + // if (itype == 6) // Outside Transition + // { + // = ProcessOutSideTrans(cn, thekey, pth); + // } + // if it's in the dictionary of structure elements already migrated, just use this // structure id, or if it's in the dictionary of structure elements that have // not been migrated but a record was created from this code, use it. Otherwise @@ -67,57 +88,77 @@ namespace DataLoader // a structure record. Item toItem = null; Item toItem2 = null; - if (dicTrans_ItemDone.ContainsKey(thekey)) - { - toItem = dicTrans_ItemDone[thekey]; - } - else - { - if (dicTrans_ItemIds.ContainsKey(thekey)) - { - toItem = dicTrans_ItemIds[thekey]; - } - else - { - // note that parent is null right now - it will be filled in later. - //toItem = Item.MakeItem(null, fromCon, DateTime.Now, "Migration"); + if (itype == 6) // Outside Transition + { + ItemInfo tmp = _OutTran.GetItem(thekey); + if (tmp != null) + toItem = tmp.Get(); + else + { toItem = Item.New(null, TransDummyCont, DateTime.Now, "Migration"); - dicTrans_ItemIds.Add(thekey, toItem); - } - } - - // if there is data in dr2, it means that it is a range transition. Get its item - // data too. - toItem2 = toItem; - if (dr2 != null) - { - string thekey2 = dr2["TONUMBER"].ToString() + "|" + dr2["TOSEQUENCE"].ToString(); - if (dicTrans_ItemDone.ContainsKey(thekey2)) - { - toItem2 = dicTrans_ItemDone[thekey2]; - } - else - { - if (dicTrans_ItemIds.ContainsKey(thekey2)) - { - toItem2 = dicTrans_ItemIds[thekey2]; - } - else - { - toItem2 = Item.MakeItem(null, TransDummyCont, DateTime.Now, "Migration"); - dicTrans_ItemIds.Add(thekey2, toItem2); - } - } - } + migrationErrors.Add("Transition Error: Missing Data - "+_OutTran.GetDescription(thekey)); + } + toItem2 = toItem; + } + else + { + if (dicTrans_ItemDone.ContainsKey(thekey)) + { + toItem = dicTrans_ItemDone[thekey]; + } + else + { + if (dicTrans_ItemIds.ContainsKey(thekey)) + { + toItem = dicTrans_ItemIds[thekey]; + } + else + { + // note that parent is null right now - it will be filled in later. + //toItem = Item.MakeItem(null, fromCon, DateTime.Now, "Migration"); + toItem = Item.New(null, TransDummyCont, DateTime.Now, "Migration"); + dicTrans_ItemIds.Add(thekey, toItem); + _TransitionMigrationErrors.Add(thekey); + } + } + // if there is data in dr2, it means that it is a range transition. Get its item + // data too. + toItem2 = toItem; + if (dr2 != null) + { + string thekey2 = dr2["TONUMBER"].ToString() + "|" + dr2["TOSEQUENCE"].ToString(); + if (dicTrans_ItemDone.ContainsKey(thekey2)) + { + toItem2 = dicTrans_ItemDone[thekey2]; + } + else + { + if (dicTrans_ItemIds.ContainsKey(thekey2)) + { + toItem2 = dicTrans_ItemIds[thekey2]; + } + else + { + toItem2 = Item.MakeItem(null, TransDummyCont, DateTime.Now, "Migration"); + dicTrans_ItemIds.Add(thekey2, toItem2); + } + } + } + } if (userid == null || userid == "") userid = "Migration"; Transition tr = null; try { tr = Transition.New(fromCon, toItem, toItem2, itype, ci!=null?ci.ToString():null, dts, userid); - tr.MyZTransition.Oldto = dr["OLDTO"].ToString(); + //if (otranskey != null) + // tr.MyZTransition.Oldto = otranskey; // info to finish outside transition processing later + //else + tr.MyZTransition.Oldto = dr["OLDTO"].ToString(); if (!tr.IsSavable) ErrorRpt.ErrorReport(tr); tr.Save(); + if (migrationErrors.Count > 0) + _ContentMigrationErrors.Add(fromCon.ContentID, migrationErrors); } catch (Exception ex) { @@ -160,7 +201,97 @@ namespace DataLoader return trtxt.ToString(); } - private string MigrateTrans(OleDbConnection cn, string textm, string seqcvt, Content content) + //private bool pathsAreEqual(string setpth, string pth) + //{ + // bool eql = false; + // string cpth = (pth.Substring(3)).ToUpper(); + // string spth = setpth.ToUpper(); + // eql = cpth.Equals(spth); + // if (!eql) // full path not equal, check for a partial path match + // { + // int idx = spth.LastIndexOf('\\'); + // idx = spth.LastIndexOf('\\', idx - 1); + // spth = spth.Substring(idx); + // idx = cpth.LastIndexOf('\\'); + // idx = cpth.LastIndexOf('\\', idx - 1); + // cpth = cpth.Substring(idx); + // eql = (cpth.Equals(spth)); + // } + // return eql; + //} + + //private string ProcessOutSideTrans(OleDbConnection cn, string thekey, string pth) + //{ + // string xtransstring = null; + // DataTable dt = null; + // DataSet ds = null; + // OleDbDataAdapter da = null; + + // DataTable dt2 = null; + // DataSet ds2 = null; + // OleDbDataAdapter da2 = null; + + // string tosetid = thekey.Substring(0, 8); + // string toprocid = thekey.Substring(8, 8); + + // /// Get the path to the procedure set from the SETID + // string xtsetcmd = "SELECT * FROM [xtsetid] WHERE [SETID]='" + tosetid +"'"; + // string xtproccmd = "SELECT * FROM [xtprocid] WHERE [SETID]='" + tosetid +"' AND [PROCID]='" + toprocid +"'"; + + // da = new OleDbDataAdapter(xtsetcmd, cn); + // da2 = new OleDbDataAdapter(xtproccmd, cn); + + // // get xtsetid records. + // ds = new DataSet(); + // try + // { + // da.Fill(ds); + // dt = ds.Tables[0]; + // dt.CaseSensitive = true; + // } + // catch (Exception ex) + // { + // log.Error("Error getting XTSETID"); + // log.ErrorFormat("to number = {0}", thekey); + // log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); + // //return textm; + // } + // DataRow dr = dt.Rows[0]; // there should be only one entry! + // string setpth = dr["Path"].ToString(); // this should be the path to the proc set! + + // // get xtprocid records + // ds2 = new DataSet(); + // try + // { + // da2.Fill(ds2); + // dt2 = ds2.Tables[0]; + // dt2.CaseSensitive = true; + // } + // catch (Exception ex) + // { + // log.Error("Error getting XTPROCID"); + // log.ErrorFormat("to number = {0}", thekey); + // log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); + // //return textm; + // } + // DataRow dr2 = dt2.Rows[0]; // there should be only one entry! + // string procnum = dr2["Procnum"].ToString(); // this should be the procedure number! + + // xtransstring = setpth + "\\" + procnum; // ex: VEHLP\PROCS\0POP05-EO00 + + // //if (pathsAreEqual(setpth, pth)) + // //{ + // // // Outside Transiton is to this procedure set (not really outsde) + // // // need to find the item id that references the proc number and title + // // // - find the setpth in the doc.version + // //} + // //else + // //return thekey; // is a true outside transition + + // return xtransstring; + //} + + private string MigrateTrans(OleDbConnection cn, string textm, string seqcvt, Content content, string pth) { StringBuilder trtxt = new StringBuilder(); int instance = 0; @@ -217,10 +348,10 @@ namespace DataLoader { instance++; DataRow dr2 = dt.Rows[instance]; - rectxt = AddTrans(content, dr, dr2); + rectxt = AddTrans(cn, content, dr, dr2, pth); } else - rectxt = AddTrans(content, dr, null); + rectxt = AddTrans(cn, content, dr, null, pth); trtxt.Append(textm[tok]); trtxt.Append(rectxt); } @@ -245,19 +376,48 @@ namespace DataLoader } private void ShowMissingTransitions() { - log.Info("Missing Transitions from Dictionary"); + if (dicTrans_ItemIds.Keys.Count > 0) + log.Warn("Missing Transitions from Dictionary"); foreach (string s in dicTrans_ItemIds.Keys) { - log.InfoFormat("{0} - {1}", s, dicTrans_ItemIds[s]); + log.WarnFormat("{0} - {1}", s, dicTrans_ItemIds[s]); + //AddItemAnnotation(dicTrans_ItemIds[s]); + } + foreach (string s in dicTrans_MigrationErrors.Keys) + { + foreach (Item itm in dicTrans_MigrationErrors[s]) + { + ItemAnnotation ia = itm.ItemAnnotations.Add(MigrationErrorType); + ia.SearchText = "Transition Error: Destination Missing - " + s; + ia.UserID = "Migration"; + itm.Save(); + } } - log.Info("Bad transitions to 'dummy' content"); + if (TransDummyCont.ContentItemCount > 0) + log.Warn("Bad transitions to 'dummy' content"); foreach (ContentItem itm in TransDummyCont.ContentItems) { - log.InfoFormat("ItemID = {0}", itm.ItemID); + log.WarnFormat("ItemID = {0}", itm.ItemID); + //AddItemAnnotation(itm.MyItem); } log.Info("End of Missing Transitions"); } + + private void AddItemAnnotation(Item itm) + { + foreach (ItemTransition_ToID tmp in itm.ItemTransitions_ToID) + { + foreach (ContentItem ci in tmp.MyContent.ContentItems) + { + ItemAnnotation ia = ci.MyItem.ItemAnnotations.Add(MigrationErrorType); + ia.SearchText = "Transition Error: Missing end point"; + ia.UserID = "Migration"; + ci.MyItem.Save(); + } + } + } + } } \ No newline at end of file