Subversion Repositories DevTools

Rev

Rev 2161 | Rev 2169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2161 Rev 2167
Line 15... Line 15...
15
   /// packages, selecting just the requirements found in the ReqPro database for storage into EA,
15
   /// packages, selecting just the requirements found in the ReqPro database for storage into EA,
16
   /// where they will be used for design traceability purposes.
16
   /// where they will be used for design traceability purposes.
17
	/// </summary>
17
	/// </summary>
18
   public class ImportReqProDatabase : CopyReqProDatabaseToMemory
18
   public class ImportReqProDatabase : CopyReqProDatabaseToMemory
19
   {
19
   {
-
 
20
      private struct req_lists_t
-
 
21
      {
-
 
22
         public ArrayList ea_reqs;
-
 
23
         public ArrayList ea_GUIDs;
-
 
24
         public ArrayList new_ea_reqs;
-
 
25
         public ArrayList new_ea_GUIDs;
-
 
26
      };
-
 
27
 
-
 
28
      private req_lists_t req_lists = new req_lists_t();
-
 
29
 
20
      private int totalRequirements = 0;
30
      private int totalRequirements = 0;
21
 
31
 
-
 
32
      private EA.Package gCurrentPackage = null;
-
 
33
      private EA.Package gNewReqProDBPackage = null;
-
 
34
      private EA.Package gChangeHistoryPackage = null;
-
 
35
      private EA.Package gOrphansPackage = null;
-
 
36
 
-
 
37
 
22
      /// <summary>
38
      /// <summary>
23
      /// Constructor logic
39
      /// Constructor logic
24
      /// </summary>
40
      /// </summary>
25
      /// <param name="ea_repository"></param>
41
      /// <param name="ea_repository"></param>
26
      public ImportReqProDatabase(): base()
42
      public ImportReqProDatabase(): base()
Line 69... Line 85...
69
         }      
85
         }      
70
 
86
 
71
         return false;
87
         return false;
72
      }
88
      }
73
 
89
 
-
 
90
 
74
      /// <summary>
91
      /// <summary>
75
      /// Displays the content of the change log element to the output trace display. This method must
92
      /// Displays the content of the change log element to the output trace display. This method must
76
      /// be kept in sync with the ImportFromReqPro method, obviously.
93
      /// be kept in sync with the ImportFromReqPro method, obviously.
77
      /// </summary>
94
      /// </summary>
78
      /// <param name="ea_repository"></param>
95
      /// <param name="ea_repository"></param>
79
      /// <param name="changeLog"></param>
96
      /// <param name="changeLog"></param>
80
      public void displayChangeLog(EA.Element changeLog)
97
      public void displayChangeLog(EA.Element changeLog)
81
      {
98
      {
82
         // The change log element contains all the log in its notes section. Break it up into
-
 
83
         // lines, because each line is a single log entry, so that we can process them one at
-
 
84
         // a time.
-
 
85
         string delimStr = "\n";
-
 
86
         char [] delim = delimStr.ToCharArray();
-
 
87
         string[] log_strings = changeLog.Notes.Split(delim,2000);
-
 
88
 
-
 
89
         // Prepare a string to form an updated change log (needed to support the activity of orphaned 
-
 
90
         // requirement deletion).
-
 
91
         string newList = "";
-
 
92
 
-
 
93
         // modify delimiters to : character so that we can extract the parameters for each log entry
-
 
94
         delimStr = ":";
-
 
95
         delim = delimStr.ToCharArray();
-
 
96
 
-
 
97
         Main.WriteOutput("Displaying Import Change Log", -1);
99
         Main.WriteOutput("Displaying Import Change Log", -1);
98
 
100
 
99
         foreach(string s in log_strings)
101
         if (changeLog.Notes == null || changeLog.Notes.Length == 0 || changeLog.Notes.Trim().Length == 0)
100
         {
102
         {
-
 
103
            Main.WriteOutput("  No changes", -1);
-
 
104
         }
-
 
105
         else
-
 
106
         {
-
 
107
            // The change log element contains all the log in its notes section. Break it up into
-
 
108
            // lines, because each line is a single log entry, so that we can process them one at
-
 
109
            // a time.
-
 
110
            string delimStr = "\n";
-
 
111
            char [] delim = delimStr.ToCharArray();
-
 
112
            string[] log_strings = changeLog.Notes.Split(delim,2000);
-
 
113
 
-
 
114
            // Prepare a string to form an updated change log (needed to support the activity of orphaned 
-
 
115
            // requirement deletion).
101
            if (Main.mustAbort)
116
            string newList = "";
-
 
117
 
-
 
118
            // modify delimiters to : character so that we can extract the parameters for each log entry
102
               break;
119
            delimStr = ":";
-
 
120
            delim = delimStr.ToCharArray();
103
 
121
 
104
            // over time, users may delete the orphaned requirements from the EA database, but their
-
 
105
            // GUIDs will still exist in the change log. Use of such a GUID will cause 
-
 
106
            // an exception in the GetElementByGuid() function. What should we do? We can attempt
-
 
107
            // to remove those GUIDs from the list. We can do this by accumulating a new list of GUIDs
-
 
108
            // that is formed from the old list, where only good items from the old list find their 
-
 
109
            // way into the new list. Gradually, the list is wittled away as EA users delete orphaned
-
 
110
            // requirements having first dealt with the design change impacts that resulted from their
-
 
111
            // orphanage.
122
            foreach(string s in log_strings)
112
            try
-
 
113
            {
123
            {
114
               if (s.StartsWith("{"))
124
               if (Main.mustAbort)
115
               {
125
                  break;
116
                  string trimmed_s = s.Trim();
-
 
117
 
126
 
-
 
127
               // over time, users may delete the orphaned requirements from the EA database, but their
-
 
128
               // GUIDs will still exist in the change log. Use of such a GUID will cause 
-
 
129
               // an exception in the GetElementByGuid() function. What should we do? We can attempt
-
 
130
               // to remove those GUIDs from the list. We can do this by accumulating a new list of GUIDs
-
 
131
               // that is formed from the old list, where only good items from the old list find their 
-
 
132
               // way into the new list. Gradually, the list is wittled away as EA users delete orphaned
-
 
133
               // requirements having first dealt with the design change impacts that resulted from their
-
 
134
               // orphanage.
-
 
135
               try
-
 
136
               {
118
                  // Get log entry;s parameters.
137
                  if (s.StartsWith("{"))
-
 
138
                  {
119
                  string[] parameters = trimmed_s.Split(delim, 10);
139
                     string trimmed_s = s.Trim();
120
 
140
 
121
                  // The first parameter is the GUID so use it to get the requirement element
141
                     // Get log entry;s parameters.
122
                  EA.Element ea_req = Main.EA_Repository.GetElementByGuid(parameters[0]);
142
                     string[] parameters = trimmed_s.Split(delim, 10);
123
 
143
 
124
                  // Now discriminate actions based on the second parameter
144
                     // The first parameter is the GUID so use it to get the requirement element
-
 
145
                     EA.Element ea_req = Main.EA_Repository.GetElementByGuid(parameters[0]);
125
 
146
 
126
                  if (parameters[1].StartsWith("Created"))
-
 
127
                  {
-
 
128
                     Main.WriteOutput("  Created : " + ea_req.Name, ea_req.ElementID );
-
 
129
                  }
-
 
130
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
 
131
                  else if (parameters[1].StartsWith("Orphaned"))
-
 
132
                  {
-
 
133
                     Main.WriteOutput("  Orphaned : " + ea_req.Name, ea_req.ElementID );
147
                     // Now discriminate actions based on the second parameter
134
 
148
 
135
                     foreach (EA.Connector theConnector in ea_req.Connectors)
149
                     if (parameters[1].StartsWith("Created"))
136
                     {
150
                     {
137
                        int destId = -1;
-
 
138
 
-
 
139
                        // we dont care about direction of relationship, so test for both
-
 
140
                        if (theConnector.ClientID == ea_req.ElementID)
151
                        Main.WriteOutput("  Created : " + ea_req.Name, ea_req.ElementID );
141
                           destId = theConnector.SupplierID;
152
                     }
142
                        else if (theConnector.SupplierID == ea_req.ElementID)
153
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
143
                           destId = theConnector.ClientID;
154
                     else if (parameters[1].StartsWith("Orphaned"))
144
                        else 
155
                     {
145
                           destId = theConnector.SupplierID;
156
                        Main.WriteOutput("  Orphaned : " + ea_req.Name, ea_req.ElementID );
146
 
157
 
147
                        // and make sure we filter out self-referential connectors
158
                        foreach (EA.Connector theConnector in ea_req.Connectors)
148
                        if (destId != ea_req.ElementID)
-
 
149
                        {
159
                        {
-
 
160
                           int destId = -1;
-
 
161
 
150
                           EA.Package tgt_pkg = (EA.Package)Main.EA_Repository.GetPackageByID( destId );
162
                           // we dont care about direction of relationship, so test for both
151
                           if (tgt_pkg != null)
163
                           if (theConnector.ClientID == ea_req.ElementID)
152
                           {
164
                              destId = theConnector.SupplierID;
153
                              Main.WriteOutput("     --> " + tgt_pkg.Name, tgt_pkg.PackageID);
165
                           else if (theConnector.SupplierID == ea_req.ElementID)
-
 
166
                              destId = theConnector.ClientID;
154
                           }
167
                           else 
-
 
168
                              destId = theConnector.SupplierID;
-
 
169
 
-
 
170
                           // and make sure we filter out self-referential connectors
155
                           else
171
                           if (destId != ea_req.ElementID)
156
                           {
172
                           {
157
                              EA.Element tgt_ele = (EA.Element)Main.EA_Repository.GetElementByID( destId );
173
                              EA.Package tgt_pkg = (EA.Package)Main.EA_Repository.GetPackageByID( destId );
158
                              if (tgt_ele != null)
174
                              if (tgt_pkg != null)
-
 
175
                              {
-
 
176
                                 Main.WriteOutput("     --> " + tgt_pkg.Name, tgt_pkg.PackageID);
-
 
177
                              }
-
 
178
                              else
159
                              {
179
                              {
-
 
180
                                 EA.Element tgt_ele = (EA.Element)Main.EA_Repository.GetElementByID( destId );
-
 
181
                                 if (tgt_ele != null)
-
 
182
                                 {
160
                                 //if (!tgt_ele.Type.StartsWith("Requirement"))
183
                                    //if (!tgt_ele.Type.StartsWith("Requirement"))
161
                                 Main.WriteOutput("     --> " + tgt_ele.Name, tgt_ele.ElementID);
184
                                    Main.WriteOutput("     --> " + tgt_ele.Name, tgt_ele.ElementID);
-
 
185
                                 }
162
                              }
186
                              }
163
                           }
187
                           }
164
                        }
188
                        }
165
                     }
189
                     }
166
                  }
-
 
167
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
190
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
168
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_NAME))
191
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_NAME))
169
                  {
192
                     {
170
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_NAME, ea_req.Name), ea_req.ElementID );
193
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_NAME, ea_req.Name), ea_req.ElementID );
171
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
194
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
172
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
195
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
173
                  }
196
                     }
174
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
197
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
175
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_NOTES)) // aka Description of the requirement
198
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_NOTES)) // aka Description of the requirement
176
                  {
199
                     {
177
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", "Description", ea_req.Name), ea_req.ElementID );
200
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", "Description", ea_req.Name), ea_req.ElementID );
178
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
201
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
179
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
202
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
180
                  }
203
                     }
181
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
204
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
182
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_DIFFICULTY))
205
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_DIFFICULTY))
183
                  {
206
                     {
184
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_DIFFICULTY, ea_req.Name), ea_req.ElementID );
207
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_DIFFICULTY, ea_req.Name), ea_req.ElementID );
185
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
208
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
186
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
209
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
187
                  }
210
                     }
188
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
211
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
189
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_PRIORITY))
212
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_PRIORITY))
190
                  {
213
                     {
191
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_PRIORITY, ea_req.Name), ea_req.ElementID );
214
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_PRIORITY, ea_req.Name), ea_req.ElementID );
192
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
215
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
193
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
216
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
194
                  }
217
                     }
195
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
218
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
196
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_VERSION))
219
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_VERSION))
197
                  {
220
                     {
198
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_VERSION, ea_req.Name), ea_req.ElementID );
221
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_VERSION, ea_req.Name), ea_req.ElementID );
199
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
222
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
200
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
223
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
201
                  }
224
                     }
202
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
225
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
203
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_STATUS))
226
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_STATUS))
204
                  {
227
                     {
205
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_STATUS, ea_req.Name), ea_req.ElementID );
228
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_STATUS, ea_req.Name), ea_req.ElementID );
206
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
229
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
207
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
230
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
208
                  }
231
                     }
209
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
232
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
210
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_SUBSYSTEM_TYPE))
233
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SUBSYSTEM_TYPE))
211
                  {
234
                     {
212
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SUBSYSTEM_TYPE, ea_req.Name), ea_req.ElementID );
235
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SUBSYSTEM_TYPE, ea_req.Name), ea_req.ElementID );
213
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
236
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
214
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
237
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
215
                  }
238
                     }
216
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
239
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
217
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_STABILITY))
240
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_STABILITY))
218
                  {
241
                     {
219
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_STABILITY, ea_req.Name), ea_req.ElementID );
242
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_STABILITY, ea_req.Name), ea_req.ElementID );
220
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
243
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
221
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
244
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
222
                  }
245
                     }
223
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
246
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
224
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_REQ_TYPE))
247
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_REQ_TYPE))
225
                  {
248
                     {
226
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_REQ_TYPE, ea_req.Name), ea_req.ElementID );
249
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_REQ_TYPE, ea_req.Name), ea_req.ElementID );
227
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
250
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
228
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
251
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
229
                  }
252
                     }
230
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
253
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
231
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE_VERSION))
254
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE_VERSION))
232
                  {
255
                     {
233
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE_VERSION, ea_req.Name), ea_req.ElementID );
256
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE_VERSION, ea_req.Name), ea_req.ElementID );
234
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
257
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
235
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
258
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
236
                  }
259
                     }
237
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
260
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
238
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE_SECTION))
261
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE_SECTION))
239
                  {
262
                     {
240
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE_SECTION, ea_req.Name), ea_req.ElementID );
263
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE_SECTION, ea_req.Name), ea_req.ElementID );
241
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
264
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
242
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
265
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
243
                  }
266
                     }
244
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
267
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
245
                  else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE))
268
                     else if (parameters[1].StartsWith(Constants.CHG_LOG_SOURCE))
246
                  {
269
                     {
247
                     Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE, ea_req.Name), ea_req.ElementID );
270
                        Main.WriteOutput(string.Format("  Modified {0}: {1}", Constants.CHG_LOG_SOURCE, ea_req.Name), ea_req.ElementID );
248
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
271
                        Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
249
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
272
                        Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
250
                  }
273
                     }
251
 
274
 
252
                  // accumulate good item into the newList
275
                     // accumulate good item into the newList
253
                  newList += trimmed_s + "\r\n";
276
                     newList += trimmed_s + "\r\n";
-
 
277
                  }
-
 
278
               }
-
 
279
               catch
-
 
280
               {
-
 
281
                  // do nothing - the newList accumulator will not have the GUID that caused the exception
-
 
282
                  // so the next time a display operation is attempted, the exception wont happen.
254
               }
283
               }
255
            }
284
            }
256
            catch
-
 
257
            {
-
 
258
               // do nothing - the newList accumulator will not have the GUID that caused the exception
-
 
259
               // so the next time a display operation is attempted, the exception wont happen.
-
 
260
            }
-
 
261
         }
-
 
262
 
285
 
263
         // Update the change log
286
            // Update the change log
264
         changeLog.Notes = newList;
287
            changeLog.Notes = newList;
265
         changeLog.Update();
288
            changeLog.Update();
-
 
289
         }
266
      }
290
      }
267
 
291
 
268
 
292
 
269
      /// <summary>
293
      /// <summary>
270
      /// Rid a string of any : char because we use that as a delimiter in the change log and so we 
294
      /// Rid a string of any : char because we use that as a delimiter in the change log and so we 
Line 279... Line 303...
279
         sc = sc.Replace('\n' , ' ');
303
         sc = sc.Replace('\n' , ' ');
280
         
304
         
281
         return sc;
305
         return sc;
282
      }
306
      }
283
 
307
 
284
      /// <summary>
-
 
285
      /// Get a new import package in which to store change log and new requirements from the import.
-
 
286
      /// </summary>
-
 
287
      /// <param name="parentPackage"></param>
-
 
288
      /// <param name="importDateTime"></param>
-
 
289
      /// <returns></returns>
-
 
290
      private EA.Package createImportPackage(EA.Package parentPackage, string importDateTime)
-
 
291
      {
-
 
292
         EA.Package importPackage = null;
-
 
293
         string importSubDir = EA_TaggedValues.Read(base.RQ_Element, Constants.TAG_IMPORT_SUB_DIR, "");
-
 
294
         if (importSubDir != null && importSubDir.Length > 0)
-
 
295
         {
-
 
296
            importPackage = (EA.Package)parentPackage.Packages.GetByName(importSubDir);
-
 
297
            if (importPackage != null)
-
 
298
            {
-
 
299
               parentPackage = importPackage;
-
 
300
            }
-
 
301
            else
-
 
302
            {
-
 
303
               // create a subdir and use it as the parent
-
 
304
               parentPackage = (EA.Package )parentPackage.Packages.AddNew( importSubDir, "Package");
-
 
305
               parentPackage.Update();
-
 
306
            }
-
 
307
         }
-
 
308
 
-
 
309
         // create the import dir in the parent
-
 
310
         importPackage = (EA.Package )parentPackage.Packages.AddNew( "import " + importDateTime, "Package");
-
 
311
         importPackage.Update();
-
 
312
 
-
 
313
         return importPackage;
-
 
314
      }
-
 
315
 
308
 
316
 
309
 
317
 
310
 
318
      /// <summary>
311
      /// <summary>
319
      /// A method that imports requirements from a ReqPro database into EA for the purpose
312
      /// A method that imports requirements from a ReqPro database into EA for the purpose
Line 322... Line 315...
322
      /// <param name="repository"></param>
315
      /// <param name="repository"></param>
323
      private void ImportFromReqPro(string importDateTime)
316
      private void ImportFromReqPro(string importDateTime)
324
      {
317
      {
325
         try
318
         try
326
         {
319
         {
-
 
320
            DialogResult dlgres;
-
 
321
 
327
            // Get a list of EA requirements and their associated ReqPro GUIDs
322
            // begin to initialise some of our element lists
328
            ArrayList ea_reqs;
323
            req_lists.new_ea_reqs = new ArrayList();
-
 
324
            req_lists.new_ea_GUIDs = new ArrayList();
329
            ArrayList ea_GUIDs = new ArrayList();
325
            req_lists.ea_GUIDs = new ArrayList();
-
 
326
 
330
            ArrayList ea_req_matched = new ArrayList();
327
            ArrayList ea_req_matched = new ArrayList();
331
 
328
 
332
            // Obtain the EA parent package so that we can create under it an import package
329
            // Obtain the EA parent package so that we can create under it our ReqProDB structure and change history packages
333
            // if need be, and scan for existing requirement elements.
-
 
334
            EA.Package parentPackage = Main.EA_Repository.GetPackageByID( base.RQ_Element.PackageID );
330
            EA.Package parentPackage = Main.EA_Repository.GetPackageByID( base.RQ_Element.PackageID );
335
 
331
 
-
 
332
            // Find or create the change history package in which to store change logs
-
 
333
            gChangeHistoryPackage = find_or_create_change_history_package(parentPackage);
-
 
334
 
-
 
335
            // create the ReqProDB structure package in the parent container package, and attach it to its counterpart
-
 
336
            // in the ReqPro_object tree structure (ie. attach it to the root node therein).
-
 
337
            gNewReqProDBPackage = (EA.Package)parentPackage.Packages.AddNew( "ReqProDB " + importDateTime, "Package");
-
 
338
            gNewReqProDBPackage.Update();
-
 
339
            rq_root_package.ea_element_ID = gNewReqProDBPackage.PackageID;
-
 
340
 
-
 
341
            // Migrate the older form of import directory and change log, into the newer format
-
 
342
            migrate_old_import_packages_to_change_history_package(parentPackage);
-
 
343
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
-
 
344
 
-
 
345
            if (Main.mustAbort)
-
 
346
               return;
-
 
347
 
-
 
348
            // Create a package to hold orphans. This will be removed later on if it ends up empty.
-
 
349
            gOrphansPackage = find_or_create_orphans_package(parentPackage);
-
 
350
 
-
 
351
            // Get a list of EA requirements that already exist under the overall ReqProDB container package
336
            ArrayList allowedElementTypes = new ArrayList();
352
            ArrayList allowedElementTypes = new ArrayList();
337
            allowedElementTypes.Add("Requirement");
353
            allowedElementTypes.Add("Requirement");
338
            allowedElementTypes.Add("UseCase");
354
            allowedElementTypes.Add("UseCase");
339
 
355
 
340
            Main.WriteOutput("Acquiring list of elements already in EA", -1);
356
            Main.WriteOutput("Acquiring list of elements already in EA", -1);
341
            ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
357
            ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
342
            EA_Utilities.findAndProcessPackageElements( parentPackage, reqLister, true );
358
            EA_Utilities.findAndProcessPackageElements( parentPackage, reqLister, true );
343
 
359
 
-
 
360
            req_lists.ea_reqs = reqLister.Elements; 
-
 
361
 
344
            if (Main.mustAbort)
362
            if (Main.mustAbort)
345
               return;
363
               return;
346
 
364
 
-
 
365
            // For the lsit we just found, get an adjacent list of the associated ReqPro GUIDs.
347
            ea_reqs = reqLister.Elements; 
366
            // The two lists will be indexable by the same index.
348
            foreach (EA.Element ea_req in ea_reqs)
367
            foreach (EA.Element ea_req in req_lists.ea_reqs)
349
            {
368
            {
350
               string GUID = EA_TaggedValues.Read(ea_req, Constants.TAG_GUID);
369
               string GUID = EA_TaggedValues.Read(ea_req, Constants.TAG_GUID);
351
               ea_GUIDs.Add(GUID);
370
               req_lists.ea_GUIDs.Add(GUID);
352
               ea_req_matched.Add(false);
371
               ea_req_matched.Add(false);
353
            }
372
            }
354
 
373
 
355
            if (Main.mustAbort)
374
            if (Main.mustAbort)
356
               return;
375
               return;
357
 
376
 
358
            // Create an import package to store new requirements and the change log
-
 
359
            EA.Package importPackage = createImportPackage(parentPackage, importDateTime);
-
 
360
 
377
 
361
            // Create the change log element in the import package
378
            // Create the change log element in the change history package
362
            EA.Element changeLog = (EA.Element)importPackage.Elements.AddNew("Change Log","InformationItem");
379
            EA.Element changeLog = (EA.Element)gChangeHistoryPackage.Elements.AddNew("Change Log" + " - import " + importDateTime, "InformationItem");
-
 
380
            changeLog.TreePos = gChangeHistoryPackage.Elements.Count - 1;
363
            changeLog.Update();
381
            changeLog.Update();
364
 
382
 
365
            // Get a flattened list of requirements from the hierarchical data the user has filtered
383
            // Get a flattened list of requirements from the hierarchical data the user has filtered
366
            ArrayList rq_req_collection = new ArrayList();
384
            ArrayList rq_req_collection = new ArrayList();
367
            get_rq_req_collection(ref rq_req_collection);
385
            get_rq_req_collection(ref rq_req_collection);
368
 
386
 
-
 
387
            // initialise some statistical vars
369
            int newRequirementCount = 0;
388
            int newRequirementCount = 0;
370
            int modifiedRequirementCount = 0;
389
            int modifiedRequirementCount = 0;
371
            int statusUpdatedRequirementCount = 0;
390
            int statusUpdatedRequirementCount = 0;
372
            int orphanedCount = 0;
391
            int orphanedCount = 0;
373
 
392
 
374
 
393
 
375
            Main.WriteOutput("Merging ReqPro content to EA", -1);
394
            Main.WriteOutput("Merging ReqPro content to EA", -1);
-
 
395
 
376
            // loop through all of the ReqPro requirements
396
            // loop through all of the ReqPro requirements we have captured from the ReqPro database
377
            foreach(ReqPro_object rq_obj in rq_req_collection)
397
            foreach(ReqPro_object rq_obj in rq_req_collection)
378
            {
398
            {
379
               if (Main.mustAbort)
399
               if (Main.mustAbort)
380
                  break;
400
                  break;
381
 
401
 
382
               try
402
               try
383
               {
403
               {
384
                  // Find which EA requirement element refers to the current ReqPro GUID
404
                  // Find which EA requirement element refers to the current ReqPro GUID
385
                  int i_ea_req;
405
                  int i_ea_req;
386
                  i_ea_req = ea_GUIDs.IndexOf( rq_obj.guid );
406
                  i_ea_req = req_lists.ea_GUIDs.IndexOf( rq_obj.guid );
387
 
407
 
388
                  // If EA element was found
408
                  // If EA element was found
389
                  if (0 <= i_ea_req)
409
                  if (0 <= i_ea_req)
390
                  {
410
                  {
391
                     ea_req_matched[i_ea_req] = true;
411
                     ea_req_matched[i_ea_req] = true;
392
 
412
 
393
                     EA.Element ea_req = ((EA.Element)ea_reqs[i_ea_req]);
413
                     EA.Element ea_req = ((EA.Element)req_lists.ea_reqs[i_ea_req]);
394
 
414
 
395
                     rq_obj.ea_element_ID = ea_req.ElementID;
415
                     rq_obj.ea_element_ID = ea_req.ElementID;
396
 
416
 
397
                     // Only update the requirement if it was not mastered in EA, or
417
                     // Only update the requirement if it was not mastered in EA, or
398
                     // unrestricted imports have been enabled
418
                     // unrestricted imports have been enabled
Line 431... Line 451...
431
 
451
 
432
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_STABILITY, Constants.CHG_LOG_STABILITY, rq_obj.stability, ref statusMayHaveChanged);
452
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_STABILITY, Constants.CHG_LOG_STABILITY, rq_obj.stability, ref statusMayHaveChanged);
433
 
453
 
434
                        // Requirement Types are actually implemented using ordinary EA element stereotypes.
454
                        // Requirement Types are actually implemented using ordinary EA element stereotypes.
435
                        string[] sar = ea_req.StereotypeEx.Split(",".ToCharArray());
455
                        string[] sar = ea_req.StereotypeEx.Split(",".ToCharArray());
-
 
456
 
-
 
457
                        // if we didnt get a requirement type from the ReqPro database, set it to an empty string so that it can
-
 
458
                        // be compared to the EA stereotype strings.
-
 
459
                        if (rq_obj.type == null)
-
 
460
                           rq_obj.type = "";
-
 
461
 
436
                        if (sar.Length > 0)
462
                        if (sar.Length > 0)
437
                        {
463
                        {
438
                           // The first item in the stereotype list is the one on display in the EA element properties and so is the one the user
464
                           // The first item in the stereotype list is the one on display in the EA element properties and so is the one the user
439
                           // thinks is assigned to the requirement element, so check against that for changes
465
                           // thinks is assigned to the requirement element, so check against that for changes
440
                           string sar0 = sar[0].Trim();
466
                           string sar0 = sar[0].Trim();
Line 480... Line 506...
480
                     // This ReqPro requirement does not have a counterpart in EA, so we must create
506
                     // This ReqPro requirement does not have a counterpart in EA, so we must create
481
                     // a new one.
507
                     // a new one.
482
                     newRequirementCount++;
508
                     newRequirementCount++;
483
 
509
 
484
                     // create the new EA requirement in the import package
510
                     // create the new EA requirement in the import package
485
                     EA.Element ea_req = (EA.Element)importPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");
511
                     EA.Element ea_req = (EA.Element)gChangeHistoryPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");
486
 
512
 
487
                     rq_obj.ea_element_ID = ea_req.ElementID;
513
                     rq_obj.ea_element_ID = ea_req.ElementID;
488
 
514
 
489
                     CopyReqProDatabase.copyReq(ea_req, rq_obj);
515
                     CopyReqProDatabase.copyReq(ea_req, rq_obj);
490
 
516
 
491
                     ea_req.Notes = rq_obj.text;
517
                     ea_req.Notes = rq_obj.text;
492
 
518
 
493
                     ea_req.Update();
519
                     ea_req.Update();
494
 
520
 
-
 
521
                     // add the new requirement to our list for later processing
-
 
522
                     req_lists.new_ea_reqs.Add(ea_req);
-
 
523
                     req_lists.new_ea_GUIDs.Add(rq_obj.guid);
-
 
524
 
495
                     changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";
525
                     changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";
496
                     changeLog.Update();
526
                     changeLog.Update();
497
 
527
 
498
                     Main.WriteOutput("Created: " + ea_req.Name, ea_req.ElementID);
528
                     Main.WriteOutput("Created: " + ea_req.Name, ea_req.ElementID);
499
                  }
529
                  }
Line 507... Line 537...
507
 
537
 
508
            if (Main.mustAbort)
538
            if (Main.mustAbort)
509
               return;
539
               return;
510
 
540
 
511
            Main.WriteOutput("Checking for orphaned requirements", -1);
541
            Main.WriteOutput("Checking for orphaned requirements", -1);
-
 
542
 
512
            // Now check for orphaned EA requirements
543
            // Now check for orphaned EA requirements
513
            for (int i = 0; i < ea_GUIDs.Count; i++)
544
            for (int i = 0; i < req_lists.ea_GUIDs.Count; i++)
514
            {
545
            {
515
               if (Main.mustAbort)
546
               if (Main.mustAbort)
516
                  break;
547
                  break;
517
 
548
 
518
               string rq_GUID = (string)ea_GUIDs[i];
549
               string rq_GUID = (string)req_lists.ea_GUIDs[i];
519
               if (rq_GUID != "")
550
               if (rq_GUID != "")
520
               {
551
               {
521
                  if ((bool)ea_req_matched[i] == false)
552
                  if ((bool)ea_req_matched[i] == false)
522
                  {
553
                  {
523
                     EA.Element ea_req = (EA.Element)ea_reqs[i];
554
                     EA.Element ea_req = (EA.Element)req_lists.ea_reqs[i];
524
       
555
       
525
                     orphanedCount++;
556
                     orphanedCount++;
526
 
557
 
527
                     changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";
558
                     changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";
528
                     changeLog.Update();
559
                     changeLog.Update();
529
                  }
560
                  }
530
               }
561
               }
531
            }
562
            }
532
 
563
 
533
            bool changeLogDeleted = false;
564
            // If there is any change to report, ask user if they want to see it now, and if so, display it
534
            if (changeLog.Notes != null && changeLog.Notes.Length > 0)
565
            if (changeLog.Notes != null && changeLog.Notes.Length > 0)
535
            {
566
            {
536
               DialogResult dlgres = MessageBoxEx.Show("Display Change Log?", "Change Log", MessageBoxButtons.YesNo);
567
               dlgres = MessageBoxEx.Show("Display Change Log?", "Change Log", MessageBoxButtons.YesNo);
537
               if (dlgres == DialogResult.Yes)
568
               if (dlgres == DialogResult.Yes)
538
                  displayChangeLog(changeLog);
569
                  displayChangeLog(changeLog);
539
            }
570
            }
540
            else
-
 
541
            {
-
 
542
               importPackage.Elements.Refresh();
-
 
543
               if (importPackage.Elements.Count == 1)
-
 
544
               {
-
 
545
                  EA_Utilities.deletePackage(importPackage);
-
 
546
                  changeLogDeleted = true;
-
 
547
               }
-
 
548
            }
-
 
549
 
571
 
-
 
572
            if (Main.mustAbort)
-
 
573
               return;
-
 
574
 
-
 
575
            // Now we import the ReqPro database package structure and migrate all of our existing or 
-
 
576
            // new requirements into it. We only create the structure we need, ie. empty package structure
-
 
577
            // will not be created unecessarily.
-
 
578
            Main.WriteOutput("Importing latest ReqPro database package structure", -1);
-
 
579
            populate_latest_reqprodb_structure_package(rq_root_package);
-
 
580
            gNewReqProDBPackage.Packages.Refresh();
-
 
581
            gNewReqProDBPackage.Elements.Refresh();
-
 
582
            gNewReqProDBPackage.Diagrams.Refresh();
-
 
583
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
-
 
584
 
-
 
585
            if (Main.mustAbort)
-
 
586
               return;
-
 
587
 
-
 
588
            // Remove the old superseded facsimile of the ReqPro database package structure. At this point,
-
 
589
            // orphaned requirements left in these will be moved to the Orphaned package, before the old
-
 
590
            // structure package is removed.
-
 
591
            Main.WriteOutput("Removing old ReqPro database package structures", -1);
-
 
592
 
-
 
593
            remove_old_empty_structures(parentPackage, gNewReqProDBPackage);
-
 
594
 
-
 
595
            if (Main.mustAbort)
-
 
596
               return;
-
 
597
 
-
 
598
            // Remove other empty packages - this tidies up the ReqPro import area so that at the top level
-
 
599
            // all a user should see is the Change History package, ReqProDB package, and possibly an Orphans package.
-
 
600
            Main.WriteOutput("Pruning empty packages", -1);
-
 
601
 
-
 
602
            prune_empty_packages(parentPackage);
-
 
603
 
-
 
604
            // Refresh the project browser
550
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
605
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
551
 
606
 
552
            // Setup the internal requirement to requirement connectivity. This is seperate from the browser
607
            // Setup the internal requirement to requirement connectivity. This is seperate from the browser
553
            // organisation of elements in EA, but since in ReqPro, that organisation tells part of the story
608
            // organisation of elements in EA, but since in ReqPro, that organisation tells part of the story
554
            // of requirement to requirement connectivity, it is mirrored in the internal connectivity, along
609
            // of requirement to requirement connectivity, it is mirrored in the internal connectivity, along
Line 560... Line 615...
560
            write_traces(totalRequirements);
615
            write_traces(totalRequirements);
561
 
616
 
562
            if (Main.mustAbort)
617
            if (Main.mustAbort)
563
               return;
618
               return;
564
 
619
 
-
 
620
            // Output any messages the underlying parser may have collected as a result of observations it has made
-
 
621
            // regarding the data it has read from the ReqPro database.
565
            writeDelayedMessages();
622
            writeDelayedMessages();
566
            
623
            
567
            // display summary stats
624
            // display summary stats
568
            Main.WriteOutput(newRequirementCount.ToString() + " new requirements", -1);
625
            Main.WriteOutput(newRequirementCount.ToString() + " new requirements", -1);
569
            Main.WriteOutput(modifiedRequirementCount.ToString() + " requirements modified", -1);
626
            Main.WriteOutput(modifiedRequirementCount.ToString() + " requirements modified", -1);
570
            Main.WriteOutput(statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);
627
            Main.WriteOutput(statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);
571
            Main.WriteOutput(orphanedCount.ToString() + " requirements were orphaned", -1);
628
            Main.WriteOutput(orphanedCount.ToString() + " requirements were orphaned", -1);
572
 
629
 
573
            if (changeLogDeleted)
-
 
574
            {
-
 
575
               Main.WriteOutput("NOTE: import package and change log deleted, since nothing changed in this import", -1);
-
 
576
            }
-
 
577
 
-
 
578
            Main.WriteOutput("Import Completed", -1);
630
            Main.WriteOutput("Import Completed", -1);
579
            MessageBoxEx.Show("Import Completed");
631
            MessageBoxEx.Show("Import Completed");
580
         }
632
         }
581
         catch (Exception ex)
633
         catch (Exception ex)
582
         {
634
         {
Line 599... Line 651...
599
            return source_value;
651
            return source_value;
600
         }
652
         }
601
         return dest_value;
653
         return dest_value;
602
      }
654
      }
603
 
655
 
-
 
656
 
604
      private void if_tagged_value_changed_update_it(EA.Element changeLog, 
657
      private void if_tagged_value_changed_update_it(EA.Element changeLog, 
605
         EA.Element ea_req, 
658
         EA.Element ea_req, 
606
         string tagname, 
659
         string tagname, 
607
         string changeLogName, 
660
         string changeLogName, 
608
         string source_value,
661
         string source_value,
Line 618... Line 671...
618
         }
671
         }
619
      }
672
      }
620
 
673
 
621
 
674
 
622
 
675
 
623
 
-
 
624
      /// <summary>
676
      /// <summary>
625
      /// This method (along with its sibling overload) obtains a flattened view of the 
677
      /// This method (along with its sibling overload) obtains a flattened view of the 
626
      /// hierarchical requirements obtained from the ReqPro database. This accumulation
678
      /// hierarchical requirements obtained from the ReqPro database. This accumulation
627
      /// takes account of the users filtering requests.
679
      /// takes account of the users filtering requests.
628
      /// </summary>
680
      /// </summary>
Line 633... Line 685...
633
         {
685
         {
634
            get_rq_req_collection(ref rq_req_collection, sub_obj);
686
            get_rq_req_collection(ref rq_req_collection, sub_obj);
635
         }
687
         }
636
      }
688
      }
637
 
689
 
-
 
690
 
638
      private void get_rq_req_collection(ref ArrayList rq_req_collection,
691
      private void get_rq_req_collection(ref ArrayList rq_req_collection,
639
                                         ReqPro_object rq_obj )
692
                                         ReqPro_object rq_obj )
640
      {
693
      {
641
         if (rq_obj.isPackage)
694
         if (rq_obj.isPackage)
642
         {
695
         {
Line 698... Line 751...
698
            }
751
            }
699
         }
752
         }
700
      }
753
      }
701
 
754
 
702
 
755
 
-
 
756
 
-
 
757
 
-
 
758
 
-
 
759
 
-
 
760
      /// <summary>
-
 
761
      /// Populates a ReqProDB structure package to be used as a home for the requirements within the 
-
 
762
      /// overall import container, and re-locate requirements into it from wherever they may be elsewhere
-
 
763
      /// within and under the import container.
-
 
764
      /// </summary>
-
 
765
      /// <param name="rq_obj"></param>
-
 
766
      private void populate_latest_reqprodb_structure_package(ReqPro_object rq_obj)
-
 
767
      {
-
 
768
         foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
-
 
769
         {
-
 
770
            if (Main.mustAbort)
-
 
771
               return;
-
 
772
 
-
 
773
            if (sub_obj.isPackage)
-
 
774
            {
-
 
775
               populate_latest_reqprodb_structure_package(sub_obj);   // recurse
-
 
776
            }
-
 
777
            else if (sub_obj.isRequirement)
-
 
778
            {
-
 
779
               EA.Element ea_req = null;
-
 
780
 
-
 
781
               // Examine all of our requirement lists to try and re-locate the requirements from
-
 
782
               // the old structure(s) to the new one.
-
 
783
 
-
 
784
               // re-locate existing requirements updated during this import
-
 
785
               int i_ea_req;
-
 
786
               i_ea_req = req_lists.ea_GUIDs.IndexOf( sub_obj.guid );
-
 
787
               if (0 <= i_ea_req)
-
 
788
               {
-
 
789
                  ea_req = ((EA.Element)req_lists.ea_reqs[i_ea_req]);
-
 
790
 
-
 
791
                  EA.Package pkg = get_or_create_latest_structure(sub_obj);
-
 
792
 
-
 
793
                  ea_req.PackageID = pkg.PackageID;   // re-locate
-
 
794
                  ea_req.TreePos = sub_obj.treePos;
-
 
795
                  ea_req.Update();
-
 
796
               }
-
 
797
               else
-
 
798
               {
-
 
799
                  // re-locate new requirements that have come in for the first time on this import.
-
 
800
                  i_ea_req = req_lists.new_ea_GUIDs.IndexOf( sub_obj.guid );
-
 
801
                  if (0 <= i_ea_req)
-
 
802
                  {
-
 
803
                     ea_req = ((EA.Element)req_lists.new_ea_reqs[i_ea_req]);
-
 
804
 
-
 
805
                     EA.Package pkg = get_or_create_latest_structure(sub_obj);
-
 
806
                     
-
 
807
                     ea_req.PackageID = pkg.PackageID;   // re-locate
-
 
808
                     ea_req.TreePos = sub_obj.treePos;
-
 
809
                     ea_req.Update();
-
 
810
                  }
-
 
811
               }
-
 
812
 
-
 
813
               // Re-locate requirement under its parent requirement, if such a relationship exists.
-
 
814
               if (ea_req != null && sub_obj.parent.isRequirement)
-
 
815
               {
-
 
816
                  EA.Element parent_ea_req = Main.EA_Repository.GetElementByID(sub_obj.parent.ea_element_ID);
-
 
817
                  if (parent_ea_req != null)
-
 
818
                  {
-
 
819
                     ea_req.ParentID = parent_ea_req.ElementID;   // re-locate
-
 
820
                     ea_req.TreePos = sub_obj.treePos;
-
 
821
                     ea_req.Update();
-
 
822
                  }
-
 
823
               }
-
 
824
 
-
 
825
               populate_latest_reqprodb_structure_package(sub_obj);   // recurse
-
 
826
            }
-
 
827
         }
-
 
828
      }
-
 
829
 
-
 
830
 
-
 
831
      /// <summary>
-
 
832
      /// This is a helper for the populate_latest_reqprodb_structure_package() function. It allows on-the-fly
-
 
833
      /// EA package path construction, triggered whenever we find we have a requirement to 
-
 
834
      /// re-locate into the latest facsimile of the ReqPro database structure.
-
 
835
      /// </summary>
-
 
836
      /// <param name="rq_obj"></param>
-
 
837
      /// <returns></returns>
-
 
838
      private EA.Package get_or_create_latest_structure(ReqPro_object rq_obj)
-
 
839
      {
-
 
840
         // go up the tree to find the immediate enclosing package of the requirement represented
-
 
841
         // by the input parameter. We do this because it is certain that this function will be called
-
 
842
         // initially passing a ReqPro_object that has "isRequirement" set to true. The requirement object
-
 
843
         // may also be nested within another requirement object, as a result of its parent-child hierarchy
-
 
844
         // in ReqPro.
-
 
845
         while(rq_obj.isRequirement && rq_obj.parent != null)
-
 
846
         {
-
 
847
            rq_obj = rq_obj.parent;
-
 
848
         }
-
 
849
 
-
 
850
         // Now that we have reached a package, we can figure out if we need to create its facsimile in EA
-
 
851
         // or detect if that has already been done on a previous invocation.
-
 
852
         if (rq_obj.isPackage)
-
 
853
         {
-
 
854
            // if this package has already been related to an EA package, then simply return it. The EA package
-
 
855
            // must have been created ona  previous invocation of this function.
-
 
856
            if (rq_obj.ea_element_ID != -1)
-
 
857
            {
-
 
858
               return Main.EA_Repository.GetPackageByID(rq_obj.ea_element_ID);
-
 
859
            }
-
 
860
            else // need to create this package, and if necessary, its parental line right up to the root package
-
 
861
            {
-
 
862
               // use recursion to work our way up the package ancestral line until we hit a point where
-
 
863
               // we find an EA package, then unwind, creating the sub-packages down to where our requirement
-
 
864
               // is to be held.
-
 
865
               EA.Package pkg = get_or_create_latest_structure(rq_obj.parent);   // recurse
-
 
866
               if (pkg != null)
-
 
867
               {
-
 
868
                  if (rq_obj.filtered)
-
 
869
                  {
-
 
870
                     return pkg;
-
 
871
                  }
-
 
872
                  else
-
 
873
                  {
-
 
874
                     EA.Package sub_pkg = EA_Utilities.createPackage(pkg, rq_obj.name, rq_obj.treePos);
-
 
875
 
-
 
876
                     // attach the EA package to the ReqPro_object so that we do not attempt to create this
-
 
877
                     // package again on another call into this function.
-
 
878
                     rq_obj.ea_element_ID = sub_pkg.PackageID;
-
 
879
 
-
 
880
                     return sub_pkg;
-
 
881
                  }
-
 
882
               }
-
 
883
            }
-
 
884
         }
-
 
885
 
-
 
886
         // default to returning the root level package in EA where the requirement structure begins.
-
 
887
         // This will always be valid and available, but hopefully, the execution path wont drop down
-
 
888
         // to here.
-
 
889
         return Main.EA_Repository.GetPackageByID(rq_root_package.ea_element_ID);
-
 
890
      }
-
 
891
 
-
 
892
      /// <summary>
-
 
893
      /// Remove the old ReqProDB structure packages if they are now empty of requirements. IF some 
-
 
894
      /// requirements remain in them, they are moved to the orphaned package so that the old ReqProDB
-
 
895
      /// packages can be removed.
-
 
896
      /// </summary>
-
 
897
      /// <param name="parentPackage"></param>
-
 
898
      /// <param name="new_structure_pkg"></param>
-
 
899
      private void remove_old_empty_structures(EA.Package parentPackage, EA.Package new_structure_pkg)
-
 
900
      {
-
 
901
         // NOTE: The parentPackage is the container of the ReqProDB element
-
 
902
         short i;
-
 
903
         for(i=0; i<parentPackage.Packages.Count; i++)
-
 
904
         {
-
 
905
            gCurrentPackage = (EA.Package)parentPackage.Packages.GetAt(i);
-
 
906
 
-
 
907
            // dont do anything to the new structure package that has been created on the current import cycle.
-
 
908
            if (new_structure_pkg != null && gCurrentPackage.PackageID == new_structure_pkg.PackageID)
-
 
909
            {
-
 
910
               continue;
-
 
911
            }
-
 
912
 
-
 
913
            // skip any packages that are not ReqProDB structure packages
-
 
914
            if (!gCurrentPackage.Name.StartsWith("ReqProDB"))
-
 
915
            {
-
 
916
               continue;
-
 
917
            }
-
 
918
 
-
 
919
            // re-locate all elements to the orphans package
-
 
920
            relocate_elements_to_orphans_package(gCurrentPackage);
-
 
921
 
-
 
922
            // Now delete the old ReqProDB structure package
-
 
923
            parentPackage.Packages.DeleteAt(i, false);
-
 
924
         }
-
 
925
         
-
 
926
         parentPackage.Packages.Refresh();
-
 
927
         Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
-
 
928
      }
-
 
929
 
-
 
930
 
-
 
931
      /// <summary>
-
 
932
      /// Re-locate all requirements that remain under a ReqProDB structure package, to its 
-
 
933
      /// top level, so that later on, the package hierarchy within it can be removed.
-
 
934
      /// </summary>
-
 
935
      /// <param name="parentPackage"></param>
-
 
936
      private void relocate_elements_to_orphans_package(EA.Package parentPackage)
-
 
937
      {
-
 
938
         if (parentPackage.PackageID != gOrphansPackage.PackageID)
-
 
939
         {
-
 
940
            // relocate elements and diagrams to the top level of the orphans package
-
 
941
            foreach(EA.Element ele in parentPackage.Elements)
-
 
942
            {
-
 
943
               ele.PackageID = gOrphansPackage.PackageID;
-
 
944
               ele.Update();
-
 
945
            }
-
 
946
            foreach(EA.Diagram diag in parentPackage.Diagrams)
-
 
947
            {
-
 
948
               diag.PackageID = gOrphansPackage.PackageID;
-
 
949
               diag.Update();
-
 
950
            }
-
 
951
 
-
 
952
            // now parse lower level packages in the tree
-
 
953
            foreach(EA.Package sub_pkg in parentPackage.Packages)
-
 
954
            {
-
 
955
               relocate_elements_to_orphans_package(sub_pkg);  // recurse
-
 
956
            }
-
 
957
         }
-
 
958
      }
-
 
959
 
-
 
960
 
-
 
961
      /// <summary>
-
 
962
      /// This function migrates the older form of import package and its change log file into the newer
-
 
963
      /// Change History package, and deletes the old import package. In doing this, it will move any
-
 
964
      /// requirements still remaining in the import package to the top level of the new ReqProDB structure
-
 
965
      /// package.
-
 
966
      /// </summary>
-
 
967
      /// <param name="parentPackage"></param>
-
 
968
      private void migrate_old_import_packages_to_change_history_package(EA.Package parentPackage)
-
 
969
      {
-
 
970
         if (gNewReqProDBPackage != null && gChangeHistoryPackage != null)
-
 
971
         {
-
 
972
            bool found = false;
-
 
973
            short i;
-
 
974
            for(i=0; i<parentPackage.Packages.Count; i++)
-
 
975
            {
-
 
976
               EA.Package sub_pkg = (EA.Package)parentPackage.Packages.GetAt(i);
-
 
977
 
-
 
978
               if (sub_pkg.Name.StartsWith("import"))
-
 
979
               {
-
 
980
                  if (!found)
-
 
981
                  {
-
 
982
                     found = true;
-
 
983
                     Main.WriteOutput("Migrating old import package contents to Change History and ReqProDB packages", -1);
-
 
984
                  }
-
 
985
 
-
 
986
                  // re-locate all elements from the old import package to the new ReqProDB structure package.
-
 
987
                  migrate_old_import_packages_to_change_history_package_recurser(sub_pkg);
-
 
988
 
-
 
989
                  // delete the old import package
-
 
990
                  parentPackage.Packages.DeleteAt(i, false);
-
 
991
               }
-
 
992
            }
-
 
993
            parentPackage.Packages.Refresh();
-
 
994
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
-
 
995
         }
-
 
996
      }
-
 
997
 
-
 
998
      /// <summary>
-
 
999
      /// Moves all elements out of an old-style import package, and into the new ReqProDB structure package.
-
 
1000
      /// Change Log elements are handled in a special way such that they are renamed from plain "Change Log" 
-
 
1001
      /// to the new style "Change Log - import <date> <time>" format, and are moved into the new "Change History"
-
 
1002
      /// package.
-
 
1003
      /// </summary>
-
 
1004
      /// <param name="parentPackage"></param>
-
 
1005
      private void migrate_old_import_packages_to_change_history_package_recurser(EA.Package parentPackage)
-
 
1006
      {
-
 
1007
         foreach(EA.Element ele in parentPackage.Elements)
-
 
1008
         {
-
 
1009
            if (ele.Name.StartsWith("Change Log"))
-
 
1010
            {
-
 
1011
               ele.Name = ele.Name + " - " + parentPackage.Name;
-
 
1012
               ele.PackageID = gChangeHistoryPackage.PackageID;
-
 
1013
               ele.Update();
-
 
1014
               gChangeHistoryPackage.Elements.Refresh();
-
 
1015
            }
-
 
1016
            else
-
 
1017
            {
-
 
1018
               ele.PackageID = gNewReqProDBPackage.PackageID;
-
 
1019
               ele.Update();
-
 
1020
            }
-
 
1021
         }
-
 
1022
 
-
 
1023
         foreach(EA.Diagram diag in parentPackage.Diagrams)
-
 
1024
         {
-
 
1025
            diag.PackageID = gNewReqProDBPackage.PackageID;
-
 
1026
            diag.Update();
-
 
1027
         }
-
 
1028
 
-
 
1029
         foreach(EA.Package sub_pkg in parentPackage.Packages)
-
 
1030
         {
-
 
1031
            migrate_old_import_packages_to_change_history_package_recurser(sub_pkg);   // recurse
-
 
1032
         }
-
 
1033
      }
-
 
1034
 
-
 
1035
 
-
 
1036
      private EA.Package find_or_create_change_history_package(EA.Package parentPackage)
-
 
1037
      {
-
 
1038
         foreach(EA.Package sub_pkg in parentPackage.Packages)
-
 
1039
         {
-
 
1040
            if (sub_pkg.Name.StartsWith("Change History"))
-
 
1041
            {
-
 
1042
               return sub_pkg;
-
 
1043
            }
-
 
1044
         }
-
 
1045
         EA.Package pkg = EA_Utilities.createPackage(parentPackage, "Change History", 1);
-
 
1046
         return pkg;
-
 
1047
      }
-
 
1048
 
-
 
1049
      private EA.Package find_or_create_orphans_package(EA.Package parentPackage)
-
 
1050
      {
-
 
1051
         foreach(EA.Package sub_pkg in parentPackage.Packages)
-
 
1052
         {
-
 
1053
            if (sub_pkg.Name.StartsWith("Orphaned Requirements"))
-
 
1054
            {
-
 
1055
               return sub_pkg;
-
 
1056
            }
-
 
1057
         }
-
 
1058
         EA.Package pkg = EA_Utilities.createPackage(parentPackage, "Orphaned Requirements", 1);
-
 
1059
         return pkg;
-
 
1060
      }
-
 
1061
 
-
 
1062
 
-
 
1063
      /// <summary>
-
 
1064
      /// This function removes any empty packages it can find in the ReqPro import area. This is 
-
 
1065
      /// a tidying up operation.
-
 
1066
      /// </summary>
-
 
1067
      /// <param name="parentPackage"></param>
-
 
1068
      /// <returns></returns>
-
 
1069
      private bool prune_empty_packages(EA.Package parentPackage)
-
 
1070
      {
-
 
1071
         bool retVal = false;
-
 
1072
         bool needRefresh = false;
-
 
1073
         short i;
-
 
1074
         for(i=0; i<parentPackage.Packages.Count; i++)
-
 
1075
         {
-
 
1076
            EA.Package sub_pkg = (EA.Package)parentPackage.Packages.GetAt(i);
-
 
1077
 
-
 
1078
            if (true == prune_empty_packages(sub_pkg))   // recurse
-
 
1079
            {
-
 
1080
               parentPackage.Packages.DeleteAt(i, false);
-
 
1081
               needRefresh = true;
-
 
1082
            }
-
 
1083
         }
-
 
1084
 
-
 
1085
         if (needRefresh)
-
 
1086
         {
-
 
1087
            parentPackage.Packages.Refresh();
-
 
1088
         }
-
 
1089
 
-
 
1090
         if (parentPackage.Packages.Count == 0 
-
 
1091
            && parentPackage.Elements.Count == 0
-
 
1092
            && parentPackage.Diagrams.Count == 0)
-
 
1093
         {
-
 
1094
            retVal = true;
-
 
1095
         }
-
 
1096
 
-
 
1097
         return retVal;
-
 
1098
      }
703
	}
1099
	}
704
}
1100
}