Subversion Repositories DevTools

Rev

Rev 2141 | Rev 2147 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2141 ghuddy 1
using System;
2
using System.Text;
3
using System.Globalization;
4
using System.Collections;
5
using System.Windows.Forms;
6
using ReqPro40;
7
 
8
 
9
namespace EA_ReqPro
10
{
11
 
12
	/// <summary>
13
	/// Summary description for ImportReqProDatabase.
14
	/// </summary>
15
	public class ImportReqProDatabase : CopyReqProDatabaseToMemory
16
	{
17
      /// <summary>
18
      /// Constructor logic
19
      /// </summary>
20
      /// <param name="ea_repository"></param>
21
      public ImportReqProDatabase(EA.Repository ea_repository): base(ea_repository)
22
		{
23
		}
24
 
25
 
26
      /// <summary>
27
      /// Method to parse a ReqPro database using the information in a ReqProDB artifact,
28
      /// assumed to be selected in EA's project browser prior to the method call.
29
      /// </summary>
30
      /// <param name="ea_repository"></param>
31
      /// <returns></returns>
2145 ghuddy 32
      public override bool prompt_and_parse(EA.Repository ea_repository, ReqProDB_Artifact.MODE mode)
2141 ghuddy 33
      {
34
         try
35
         {
2145 ghuddy 36
            if (true == base.prompt_and_parse(ea_repository, mode))
2141 ghuddy 37
            {
38
               ea_repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
39
               ImportFromReqPro(ea_repository);
2145 ghuddy 40
 
41
               // Configure the ReqProDB artifact as a traceability artifact
42
               RQ_Artifact.set_traceability_mode(ea_repository, RQ_Element);
43
 
2141 ghuddy 44
               return true;
45
            }
46
         }
47
         catch (Exception ex)
48
         {
49
            MessageBox.Show(ex.Message, "Error (ImportReqProDatabase::parse)", MessageBoxButtons.OK);
50
         }      
51
         return false;
52
      }
53
 
54
      /// <summary>
55
      /// Displays the content of the change log element to the output trace display. This method must
56
      /// be kept in sync with the ImportFromReqPro method, obviously.
57
      /// </summary>
58
      /// <param name="ea_repository"></param>
59
      /// <param name="changeLog"></param>
60
      public void displayChangeLog(EA.Repository ea_repository, EA.Element changeLog)
61
      {
62
         // The change log element contains all the log in its notes section. Break it up into
63
         // lines, because each line is a single log entry, so that we can process them one at
64
         // a time.
65
         string delimStr = "\n";
66
         char [] delim = delimStr.ToCharArray();
67
         string[] log_strings = changeLog.Notes.Split(delim,2000);
68
 
69
         // Prepare a string to form an updated change log (needed to support the activity of orphaned 
70
         // requirement deletion).
71
         string newList = "";
72
 
73
         // modify delimiters to : character so that we can extract the parameters for each log entry
74
         delimStr = ":";
75
         delim = delimStr.ToCharArray();
76
 
77
         ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,"Displaying Import Change Log", -1);
78
 
79
         foreach(string s in log_strings)
80
         {
81
            // over time, users may delete the orphaned requirements from the EA database, but their
82
            // GUIDs will still exist in the change log. Use of such a GUID will cause 
83
            // an exception in the GetElementByGuid() function. What should we do? We can attempt
84
            // to remove those GUIDs from the list. We can do this by accumulating a new list of GUIDs
85
            // that is formed from the old list, where only good items from the old list find their 
86
            // way into the new list. Gradually, the list is wittled away as EA users delete orphaned
87
            // requirements having first dealt with the design change impacts that resulted from their
88
            // orphanage.
89
            try
90
            {
91
               if (s.StartsWith("{"))
92
               {
93
                  string trimmed_s = s.Trim();
94
 
95
                  // Get log entry;s parameters.
96
                  string[] parameters = trimmed_s.Split(delim, 10);
97
 
98
                  // The first parameter is the GUID so use it to get the requirement element
99
                  EA.Element ea_req = ea_repository.GetElementByGuid(parameters[0]);
100
 
101
                  // Now discriminate actions based on the second parameter
102
 
103
                  if (parameters[1].StartsWith("Created"))
104
                  {
105
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,"  Created : " + ea_req.Name, ea_req.ElementID );
106
                  }
107
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
108
                  else if (parameters[1].StartsWith("Orphaned"))
109
                  {
110
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,"  Orphaned : " + ea_req.Name, ea_req.ElementID );
111
 
112
                     foreach (EA.Connector theConnector in ea_req.Connectors)
113
                     {
114
                        EA.Element tgt_ele = (EA.Element)ea_repository.GetElementByID( theConnector.SupplierID );
115
                        if (tgt_ele != null)
116
                        {
117
                           if (!tgt_ele.Type.StartsWith("Requirement"))
118
                           {
119
                              ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     --> " + tgt_ele.Name, tgt_ele.ElementID);
120
                           }
121
                        }
122
                     }
123
                  }
124
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
125
                  else if (parameters[1].StartsWith("Name"))
126
                  {
127
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "  Modified Name: " + ea_req.Name, ea_req.ElementID );
128
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     <<< " + parameters[2], ea_req.ElementID);
129
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     >>> " + parameters[3], ea_req.ElementID);
130
                  }
131
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
132
                  else if (parameters[1].StartsWith("Notes"))
133
                  {
134
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "  Modified Description: " + ea_req.Name, ea_req.ElementID );
135
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     <<< " + parameters[2], ea_req.ElementID);
136
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     >>> " + parameters[3], ea_req.ElementID);
137
                  }
138
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
139
                  else if (parameters[1].StartsWith("Difficulty"))
140
                  {
141
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "  Modified Difficulty: " + ea_req.Name, ea_req.ElementID );
142
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     <<< " + parameters[2], ea_req.ElementID);
143
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     >>> " + parameters[3], ea_req.ElementID);
144
                  }
145
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
146
                  else if (parameters[1].StartsWith("Priority"))
147
                  {
148
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "  Modified Priority: " + ea_req.Name, ea_req.ElementID );
149
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     <<< " + parameters[2], ea_req.ElementID);
150
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     >>> " + parameters[3], ea_req.ElementID);
151
                  }
152
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
153
                  else if (parameters[1].StartsWith("Version"))
154
                  {
155
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "  Modified Version: " + ea_req.Name, ea_req.ElementID );
156
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     <<< " + parameters[2], ea_req.ElementID);
157
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     >>> " + parameters[3], ea_req.ElementID);
158
                  }
159
                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
160
                  else if (parameters[1].StartsWith("Status"))
161
                  {
162
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "  Modified Status: " + ea_req.Name, ea_req.ElementID );
163
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     <<< " + parameters[2], ea_req.ElementID);
164
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "     >>> " + parameters[3], ea_req.ElementID);
165
                  }
166
 
167
                  // accumulate good item into the newList
168
                  newList += trimmed_s + "\r\n";
169
               }
170
            }
171
            catch
172
            {
173
               // do nothing - the newList accumulator will not have the GUID that caused the exception
174
               // so the next time a display operation is attempted, the exception wont happen.
175
            }
176
         }
177
 
178
         // Update the change log
179
         changeLog.Notes = newList;
180
         changeLog.Update();
181
      }
182
 
183
 
184
 
185
      /// <summary>
186
      /// A method that imports requirements from a ReqPro database into EA for the purpose
187
      /// of supporting requirement-to-design traceability.
188
      /// </summary>
189
      /// <param name="repository"></param>
190
      private void ImportFromReqPro(EA.Repository ea_repository)
191
      {
192
         try
193
         {
194
            //IFormatProvider cultureInfo = new CultureInfo("en-US", true);
195
 
196
            string importDateTime = System.TimeZone.CurrentTimeZone.ToUniversalTime( System.DateTime.Now ).ToString();
197
 
198
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "EA Requirement import at " + importDateTime, -1 );
199
 
200
            // Update the ReqProDB stereotypes element with all the EA requirements in the package
2145 ghuddy 201
            base.RQ_Artifact.UpdatePackageToReqProDatabaseAssociation(ea_repository, base.RQ_Element);
2141 ghuddy 202
 
203
            // Get a list of EA requirements and their associated ReqPro GUIDs
204
            ArrayList ea_reqs = new ArrayList();
205
            ArrayList ea_GUIDs = new ArrayList();
206
            ArrayList ea_req_matched = new ArrayList();
2145 ghuddy 207
            foreach (EA.Connector connector in base.RQ_Element.Connectors)
2141 ghuddy 208
            {
209
               EA.Element ea_req = ea_repository.GetElementByID( connector.SupplierID );
210
               if (ea_req != null)
211
               {
212
                  ea_reqs.Add(ea_req);
213
                  string GUID = EA_Utils.ReadTag(ea_req, "GUID");
214
                  ea_GUIDs.Add(GUID);
215
                  ea_req_matched.Add(false);
216
               }
217
            }
218
 
219
            // Obtain the EA parent package so that we can create under it an import package
220
            // if need be.
2145 ghuddy 221
            EA.Package parentPackage = ea_repository.GetPackageByID( base.RQ_Element.PackageID );
2141 ghuddy 222
 
223
            EA.Package importPackage = (EA.Package )parentPackage.Packages.AddNew( "import " + importDateTime, "Package");
224
            importPackage.Update();
225
 
226
            EA.Element changeLog = (EA.Element)importPackage.Elements.AddNew("Change Log","InformationItem");
227
            changeLog.Update();
228
 
229
            // Get a flattened list of requirements from the hierarchical data the user has filtered
230
            ArrayList rq_req_collection = new ArrayList();
231
            get_rq_req_collection(ea_repository, ref rq_req_collection);
232
 
233
            int newRequirementCount = 0;
234
            int modifiedRequirementCount = 0;
235
            int statusUpdatedRequirementCount = 0;
236
            int orphanedCount = 0;
237
 
238
 
239
            // loop through all of the ReqPro requirements
240
            foreach(ReqPro_object rq_obj in rq_req_collection)
241
            {
242
               try
243
               {
244
                  // Find which EA requirement element refers to the current ReqPro GUID
245
                  int i_ea_req;
246
                  i_ea_req = ea_GUIDs.IndexOf( rq_obj.guid );
247
 
248
                  // If EA element was found
249
                  if (0 <= i_ea_req)
250
                  {
251
                     ea_req_matched[i_ea_req] = true;
252
 
253
                     EA.Element ea_req = ((EA.Element)ea_reqs[i_ea_req]);
254
 
255
                     // This ReqPro requirement already has a counterpart in EA, so we must simply
256
                     // update the counterpart. But, to aid the designer, we need to try to tell them
2145 ghuddy 257
                     // how the requirement has changed, which could ofcoarse change the meaning 
258
                     // of the requirement and require design changes to be done.
2141 ghuddy 259
 
260
                     bool meaningMayHaveChanged = false;
261
                     bool statusMayHaveChanged = false;
262
 
263
                     string ea_req_name = rq_obj.tag + " " + rq_obj.name;
264
 
265
                     if ( ea_req.Name.CompareTo(ea_req_name) != 0 )
266
                     {
267
                        changeLog.Notes += ea_req.ElementGUID + ":Name:" + ea_req.Name + ":" + ea_req_name + "\r\n";
268
                        changeLog.Update();
269
                        meaningMayHaveChanged = true;
270
                        ea_req.Name  = ea_req_name;
271
                     }
272
 
273
                     if ( ea_req.Notes.CompareTo(rq_obj.text) != 0 )
274
                     {
275
                        changeLog.Notes += ea_req.ElementGUID + ":Notes:" + ea_req.Notes + ":" + rq_obj.text + "\r\n";
276
                        changeLog.Update();
277
                        meaningMayHaveChanged = true;
278
                        ea_req.Notes = rq_obj.text;
279
                     }
280
 
281
                     if (ea_req.Difficulty != rq_obj.difficulty)
282
                     {
283
                        changeLog.Notes += ea_req.ElementGUID + ":Difficulty:" + ea_req.Difficulty + ":" + rq_obj.difficulty + "\r\n";
284
                        changeLog.Update();
285
                        statusMayHaveChanged = true;
286
                        ea_req.Difficulty    = rq_obj.difficulty;
287
                     }
288
                     if (ea_req.Priority != rq_obj.priority)
289
                     {
290
                        changeLog.Notes += ea_req.ElementGUID + ":Priority:" + ea_req.Priority + ":" + rq_obj.priority + "\r\n";
291
                        changeLog.Update();
292
                        statusMayHaveChanged = true;
293
                        ea_req.Priority      = rq_obj.priority;
294
                     }
295
                     if (ea_req.Version != rq_obj.version)
296
                     {
297
                        changeLog.Notes += ea_req.ElementGUID + ":Version:" + ea_req.Version + ":" + rq_obj.version + "\r\n";
298
                        changeLog.Update();
299
                        statusMayHaveChanged = true;
300
                        ea_req.Version       = rq_obj.version;
301
                     }
302
                     if (ea_req.Status != rq_obj.status)
303
                     {
304
                        changeLog.Notes += ea_req.ElementGUID + ":Status:" + ea_req.Status + ":" + rq_obj.status + "\r\n";
305
                        changeLog.Update();
306
                        statusMayHaveChanged = true;
307
                        ea_req.Status        = rq_obj.status;
308
                     }
309
 
310
                     ea_req.Update();
311
 
312
                     if (meaningMayHaveChanged)
313
                     {
314
                        modifiedRequirementCount++;
315
                     }
316
 
317
                     if (statusMayHaveChanged)
318
                     {
319
                        statusUpdatedRequirementCount++;
320
                     }
321
                  }
322
                  else
323
                  {
324
                     // This ReqPro requirement does not have a counterpart in EA, so we must create
325
                     // a new one.
326
                     newRequirementCount++;
327
 
328
                     // create the new EA requirement in the import package
329
                     EA.Element ea_req = (EA.Element)importPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");
330
                     ea_req.Notes = rq_obj.text;
331
 
332
                     ea_req.Difficulty = rq_obj.difficulty;
333
                     ea_req.Priority   = rq_obj.priority;
334
                     ea_req.Version    = rq_obj.version;
335
                     ea_req.Status     = rq_obj.status;
336
 
337
                     EA_Utils.WriteTag(ea_req, "GUID", rq_obj.guid);
338
                     EA_Utils.WriteTag(ea_req, "TAG", rq_obj.tag);
339
                     ea_req.Update();
340
 
341
                     // Connect the new requirement to the ea_rq_artifact
2145 ghuddy 342
                     base.RQ_Artifact.add_connection(ea_repository, base.RQ_Element, ea_req);
2141 ghuddy 343
 
344
                     changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";
345
                     changeLog.Update();
346
                  }
347
 
348
               }
349
               catch (Exception ex)
350
               {
351
                  ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exception (ImportFromReqPro), " + ex.Message + ", " + rq_obj.name, -1);
352
               }
353
            }
354
 
355
 
356
            // Now check for orphaned EA requirements
357
            for (int i = 0; i < ea_GUIDs.Count; i++)
358
            {
359
               string rq_GUID = (string)ea_GUIDs[i];
360
               if (rq_GUID != "")
361
               {
362
                  if ((bool)ea_req_matched[i] == false)
363
                  {
364
                     EA.Element ea_req = (EA.Element)ea_reqs[i];
365
 
366
                     orphanedCount++;
367
 
368
                     changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";
369
                     changeLog.Update();
370
                  }
371
               }
372
            }
373
 
374
            displayChangeLog(ea_repository, changeLog);
375
 
376
            ea_repository.RefreshModelView(parentPackage.PackageID);
377
 
2145 ghuddy 378
            // display summary stats
2141 ghuddy 379
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, newRequirementCount.ToString() + " new requirements", -1);
380
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, modifiedRequirementCount.ToString() + " requirements modified", -1);
381
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);
382
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, orphanedCount.ToString() + " requirements were orphaned", -1);
383
 
384
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Completed import", -1);
385
 
386
            MessageBox.Show("Import Completed");
387
         }
388
         catch (Exception ex)
389
         {
390
            MessageBox.Show(ex.Message, "Error (ImportFromReqPro)", MessageBoxButtons.OK);
391
         }
392
      }
393
 
394
 
395
 
396
 
397
      /// <summary>
398
      /// This method (along with its sibling overload) obtains a flattened view of the 
399
      /// hierarchical requirements obtained from the ReqPro database. This accumulation
400
      /// takes account of the users filtering requests.
401
      /// </summary>
402
      /// <param name="ea_repository"></param>
403
      private void get_rq_req_collection(EA.Repository ea_repository, ref ArrayList rq_req_collection)
404
      {
405
         foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
406
         {
407
            get_rq_req_collection(ea_repository, ref rq_req_collection, sub_obj);
408
         }
409
      }
410
 
411
      private void get_rq_req_collection(EA.Repository ea_repository,
412
                                         ref ArrayList rq_req_collection,
413
                                         ReqPro_object rq_obj )
414
      {
415
         if (rq_obj.isPackage)
416
         {
417
            if (rq_obj.filtered == false)
418
            {
419
               // Using recursion, scan this objects sub-objects
420
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
421
               {
422
                  get_rq_req_collection(ea_repository, ref rq_req_collection, sub_obj);
423
               }
424
            }
425
         }
426
         else if (rq_obj.isRequirement)
427
         {
428
            if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)) )
429
            {
430
               // Add this requirement to the flattened list we are accumulating
431
               rq_req_collection.Add(rq_obj);
432
 
433
               // Using recursion, scan this objects sub-objects
434
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
435
               {
436
                  get_rq_req_collection(ea_repository, ref rq_req_collection, sub_obj);
437
               }
438
            }
439
         }
440
      }
441
 
442
 
443
	}
444
}