Subversion Repositories DevTools

Rev

Rev 2157 | Rev 2161 | 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;
2151 ghuddy 2
using System.Text;
3
using System.Globalization;
4
using System.Collections;
5
using System.Windows.Forms;
2141 ghuddy 6
using ReqPro40;
7
 
8
 
9
namespace EA_ReqPro
10
{
11
 
12
	/// <summary>
2155 ghuddy 13
   /// ImportReqProDatabase is a specialisation of CopyReqProDatabaseToMemory, designed to copy the 
14
   /// ReqPro database content into an EA database, discarding the structure of and hierarchy of 
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.
2141 ghuddy 17
	/// </summary>
2155 ghuddy 18
   public class ImportReqProDatabase : CopyReqProDatabaseToMemory
19
   {
2151 ghuddy 20
      private int totalRequirements = 0;
21
 
2141 ghuddy 22
      /// <summary>
23
      /// Constructor logic
24
      /// </summary>
25
      /// <param name="ea_repository"></param>
2151 ghuddy 26
      public ImportReqProDatabase(): base()
2155 ghuddy 27
      {
2151 ghuddy 28
         totalRequirements = 0;
2155 ghuddy 29
      }
2141 ghuddy 30
 
31
 
32
      /// <summary>
33
      /// Method to parse a ReqPro database using the information in a ReqProDB artifact,
34
      /// assumed to be selected in EA's project browser prior to the method call.
35
      /// </summary>
36
      /// <param name="ea_repository"></param>
37
      /// <returns></returns>
2155 ghuddy 38
      public override bool prompt_and_parse(ReqProDB_Artifact.MODE mode, out bool cancelled)
2151 ghuddy 39
      {
2155 ghuddy 40
         cancelled = false;
41
 
2151 ghuddy 42
         try
43
         {
2155 ghuddy 44
            base.structure_only = false;
45
 
46
            string importDateTime = System.DateTime.Now.ToString();
47
 
48
            Main.WriteOutput("EA Requirement import at " + importDateTime, -1 );
49
            Main.WriteOutput("",-1);
50
 
51
            if (true == base.prompt_and_parse(mode, out cancelled))
2151 ghuddy 52
            {
53
               if (Main.mustAbort)
54
                  return false;
55
 
56
               Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
57
 
58
               // Configure the ReqProDB artifact as a traceability artifact
59
               RQ_Artifact.set_traceability_mode(RQ_Element);
60
 
2155 ghuddy 61
               ImportFromReqPro(importDateTime);
2151 ghuddy 62
 
63
               return true;
64
            }
65
         }
66
         catch (Exception ex)
67
         {
2153 ghuddy 68
            Main.MessageBoxException(ex, "Exception (parse)");
2151 ghuddy 69
         }      
2155 ghuddy 70
 
2151 ghuddy 71
         return false;
72
      }
73
 
2141 ghuddy 74
      /// <summary>
75
      /// 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.
77
      /// </summary>
78
      /// <param name="ea_repository"></param>
2151 ghuddy 79
      /// <param name="changeLog"></param>
80
      public void displayChangeLog(EA.Element changeLog)
2141 ghuddy 81
      {
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
 
2155 ghuddy 97
         Main.WriteOutput("Displaying Import Change Log", -1);
2141 ghuddy 98
 
99
         foreach(string s in log_strings)
100
         {
2151 ghuddy 101
            if (Main.mustAbort)
102
               break;
103
 
2141 ghuddy 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.
112
            try
113
            {
114
               if (s.StartsWith("{"))
115
               {
116
                  string trimmed_s = s.Trim();
117
 
118
                  // Get log entry;s parameters.
119
                  string[] parameters = trimmed_s.Split(delim, 10);
120
 
121
                  // The first parameter is the GUID so use it to get the requirement element
2151 ghuddy 122
                  EA.Element ea_req = Main.EA_Repository.GetElementByGuid(parameters[0]);
2141 ghuddy 123
 
124
                  // Now discriminate actions based on the second parameter
125
 
126
                  if (parameters[1].StartsWith("Created"))
127
                  {
2155 ghuddy 128
                     Main.WriteOutput("  Created : " + ea_req.Name, ea_req.ElementID );
2141 ghuddy 129
                  }
2155 ghuddy 130
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 131
                  else if (parameters[1].StartsWith("Orphaned"))
132
                  {
2155 ghuddy 133
                     Main.WriteOutput("  Orphaned : " + ea_req.Name, ea_req.ElementID );
2141 ghuddy 134
 
135
                     foreach (EA.Connector theConnector in ea_req.Connectors)
136
                     {
2159 ghuddy 137
                        int destId = -1;
138
 
139
                        // we dont care about direction of relationship, so test for both
140
                        if (theConnector.ClientID == ea_req.ElementID)
141
                           destId = theConnector.SupplierID;
142
                        else if (theConnector.SupplierID == ea_req.ElementID)
143
                           destId = theConnector.ClientID;
144
                        else 
145
                           destId = theConnector.SupplierID;
146
 
147
                        // and make sure we filter out self-referential connectors
148
                        if (destId != ea_req.ElementID)
2141 ghuddy 149
                        {
2159 ghuddy 150
                           EA.Package tgt_pkg = (EA.Package)Main.EA_Repository.GetPackageByID( destId );
151
                           if (tgt_pkg != null)
2141 ghuddy 152
                           {
2159 ghuddy 153
                              Main.WriteOutput("     --> " + tgt_pkg.Name, tgt_pkg.PackageID);
2141 ghuddy 154
                           }
2159 ghuddy 155
                           else
156
                           {
157
                              EA.Element tgt_ele = (EA.Element)Main.EA_Repository.GetElementByID( destId );
158
                              if (tgt_ele != null)
159
                              {
160
                                 //if (!tgt_ele.Type.StartsWith("Requirement"))
161
                                 Main.WriteOutput("     --> " + tgt_ele.Name, tgt_ele.ElementID);
162
                              }
163
                           }
2141 ghuddy 164
                        }
165
                     }
166
                  }
2155 ghuddy 167
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 168
                  else if (parameters[1].StartsWith("Name"))
169
                  {
2155 ghuddy 170
                     Main.WriteOutput("  Modified Name: " + ea_req.Name, ea_req.ElementID );
171
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
172
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 173
                  }
2155 ghuddy 174
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 175
                  else if (parameters[1].StartsWith("Notes"))
176
                  {
2155 ghuddy 177
                     Main.WriteOutput("  Modified Description: " + ea_req.Name, ea_req.ElementID );
178
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
179
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 180
                  }
2155 ghuddy 181
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 182
                  else if (parameters[1].StartsWith("Difficulty"))
183
                  {
2155 ghuddy 184
                     Main.WriteOutput("  Modified Difficulty: " + ea_req.Name, ea_req.ElementID );
185
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
186
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 187
                  }
2155 ghuddy 188
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 189
                  else if (parameters[1].StartsWith("Priority"))
190
                  {
2155 ghuddy 191
                     Main.WriteOutput("  Modified Priority: " + ea_req.Name, ea_req.ElementID );
192
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
193
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 194
                  }
2155 ghuddy 195
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 196
                  else if (parameters[1].StartsWith("Version"))
197
                  {
2155 ghuddy 198
                     Main.WriteOutput("  Modified Version: " + ea_req.Name, ea_req.ElementID );
199
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
200
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 201
                  }
2155 ghuddy 202
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2141 ghuddy 203
                  else if (parameters[1].StartsWith("Status"))
204
                  {
2155 ghuddy 205
                     Main.WriteOutput("  Modified Status: " + ea_req.Name, ea_req.ElementID );
206
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
207
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
2141 ghuddy 208
                  }
2155 ghuddy 209
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
210
                  else if (parameters[1].StartsWith("Subsystem"))
211
                  {
212
                     Main.WriteOutput("  Modified Subsystem: " + ea_req.Name, ea_req.ElementID );
213
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
214
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
215
                  }
216
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
217
                  else if (parameters[1].StartsWith("Stability"))
218
                  {
219
                     Main.WriteOutput("  Modified Stability: " + ea_req.Name, ea_req.ElementID );
220
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
221
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
222
                  }
223
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
224
                  else if (parameters[1].StartsWith("ReqType"))
225
                  {
226
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
227
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
228
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
229
                  }
230
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
231
                  else if (parameters[1].StartsWith("SourceVersion"))
232
                  {
233
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
234
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
235
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
236
                  }
237
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
238
                  else if (parameters[1].StartsWith("SourceSection"))
239
                  {
240
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
241
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
242
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
243
                  }
244
                     /////////////////////////////////////////////////////////////////////////////////////////////////////////////
245
                  else if (parameters[1].StartsWith("Source"))
246
                  {
247
                     Main.WriteOutput("  Modified Type: " + ea_req.Name, ea_req.ElementID );
248
                     Main.WriteOutput("     <<< " + parameters[2], ea_req.ElementID);
249
                     Main.WriteOutput("     >>> " + parameters[3], ea_req.ElementID);
250
                  }
2141 ghuddy 251
 
252
                  // accumulate good item into the newList
253
                  newList += trimmed_s + "\r\n";
254
               }
255
            }
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
 
263
         // Update the change log
264
         changeLog.Notes = newList;
265
         changeLog.Update();
266
      }
267
 
2147 ghuddy 268
 
269
      /// <summary>
270
      /// Rid a string of any : char because we use that as a delimiter in the change log and so we 
271
      /// do not want a users use of the character to confuse the change log display mechanism.
272
      /// </summary>
273
      /// <param name="s"></param>
274
      /// <returns></returns>
275
      private string NO_COLONS(string s)
276
      {
277
         string sc =  s.Replace(':', ' ');
278
         sc = sc.Replace('\r' , ' ');
279
         sc = sc.Replace('\n' , ' ');
280
 
281
         return sc;
282
      }
2151 ghuddy 283
 
2155 ghuddy 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
         }
2151 ghuddy 308
 
2155 ghuddy 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
 
316
 
317
 
2151 ghuddy 318
      /// <summary>
319
      /// A method that imports requirements from a ReqPro database into EA for the purpose
320
      /// of supporting requirement-to-design traceability.
321
      /// </summary>
322
      /// <param name="repository"></param>
2155 ghuddy 323
      private void ImportFromReqPro(string importDateTime)
2151 ghuddy 324
      {
325
         try
326
         {
327
            // Get a list of EA requirements and their associated ReqPro GUIDs
328
            ArrayList ea_reqs;
329
            ArrayList ea_GUIDs = new ArrayList();
330
            ArrayList ea_req_matched = new ArrayList();
331
 
332
            // Obtain the EA parent package so that we can create under it an import package
333
            // if need be, and scan for existing requirement elements.
334
            EA.Package parentPackage = Main.EA_Repository.GetPackageByID( base.RQ_Element.PackageID );
335
 
336
            ArrayList allowedElementTypes = new ArrayList();
337
            allowedElementTypes.Add("Requirement");
338
            allowedElementTypes.Add("UseCase");
339
 
2155 ghuddy 340
            Main.WriteOutput("Acquiring list of elements already in EA", -1);
2151 ghuddy 341
            ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
2153 ghuddy 342
            EA_Utilities.findAndProcessPackageElements( parentPackage, reqLister, true );
2151 ghuddy 343
 
344
            if (Main.mustAbort)
345
               return;
346
 
347
            ea_reqs = reqLister.Elements; 
348
            foreach (EA.Element ea_req in ea_reqs)
349
            {
2155 ghuddy 350
               string GUID = EA_TaggedValues.Read(ea_req, Constants.TAG_GUID);
2151 ghuddy 351
               ea_GUIDs.Add(GUID);
352
               ea_req_matched.Add(false);
353
            }
354
 
355
            if (Main.mustAbort)
356
               return;
357
 
2155 ghuddy 358
            // Create an import package to store new requirements and the change log
359
            EA.Package importPackage = createImportPackage(parentPackage, importDateTime);
2151 ghuddy 360
 
2155 ghuddy 361
            // Create the change log element in the import package
2151 ghuddy 362
            EA.Element changeLog = (EA.Element)importPackage.Elements.AddNew("Change Log","InformationItem");
363
            changeLog.Update();
364
 
365
            // Get a flattened list of requirements from the hierarchical data the user has filtered
366
            ArrayList rq_req_collection = new ArrayList();
367
            get_rq_req_collection(ref rq_req_collection);
368
 
369
            int newRequirementCount = 0;
370
            int modifiedRequirementCount = 0;
371
            int statusUpdatedRequirementCount = 0;
372
            int orphanedCount = 0;
373
 
374
 
2155 ghuddy 375
            Main.WriteOutput("Merging ReqPro content to EA", -1);
2151 ghuddy 376
            // loop through all of the ReqPro requirements
377
            foreach(ReqPro_object rq_obj in rq_req_collection)
378
            {
379
               if (Main.mustAbort)
380
                  break;
381
 
382
               try
383
               {
384
                  // Find which EA requirement element refers to the current ReqPro GUID
385
                  int i_ea_req;
386
                  i_ea_req = ea_GUIDs.IndexOf( rq_obj.guid );
387
 
388
                  // If EA element was found
389
                  if (0 <= i_ea_req)
390
                  {
391
                     ea_req_matched[i_ea_req] = true;
392
 
393
                     EA.Element ea_req = ((EA.Element)ea_reqs[i_ea_req]);
394
 
395
                     rq_obj.ea_element_ID = ea_req.ElementID;
396
 
2155 ghuddy 397
                     // Only update the requirement if it was not mastered in EA, or
398
                     // unrestricted imports have been enabled
399
                     if (  (false == EA_TaggedValues.Read(ea_req, Constants.TAG_CREATED_IN_EA, Constants.DEFAULT_CREATED_IN_EA))
400
                        || (true == EA_TaggedValues.Read(ea_req, Constants.TAG_UNRESTRICTED_IMPORTS, Constants.DEFAULT_UNRESTRICTED_IMPORTS)) )
401
                     {
402
                        // This ReqPro requirement already has a counterpart in EA, so we must simply
403
                        // update the counterpart. But, to aid the designer, we need to try to tell them
404
                        // how the requirement has changed, which could ofcoarse change the meaning 
405
                        // of the requirement and require design changes to be done.
2151 ghuddy 406
 
2155 ghuddy 407
                        bool meaningMayHaveChanged = false;
408
                        bool statusMayHaveChanged = false;
2151 ghuddy 409
 
2155 ghuddy 410
                        string ea_req_name = rq_obj.tag + " " + rq_obj.name;
2151 ghuddy 411
 
2155 ghuddy 412
                        Main.WriteOutput("Updating: " + ea_req_name, rq_obj.ea_element_ID);
2151 ghuddy 413
 
2155 ghuddy 414
                        ea_req.Name       = updated_property_value_if_changed(changeLog, ea_req, ea_req.Name, "Name", ea_req_name, ref meaningMayHaveChanged);
2151 ghuddy 415
 
2155 ghuddy 416
                        ea_req.Notes      = updated_property_value_if_changed(changeLog, ea_req, ea_req.Notes, "Notes", rq_obj.text, ref meaningMayHaveChanged);
2151 ghuddy 417
 
2155 ghuddy 418
                        ea_req.Difficulty = updated_property_value_if_changed(changeLog, ea_req, ea_req.Difficulty, "Difficulty", rq_obj.difficulty, ref statusMayHaveChanged);
2151 ghuddy 419
 
2155 ghuddy 420
                        ea_req.Priority   = updated_property_value_if_changed(changeLog, ea_req, ea_req.Priority, "Priority", rq_obj.priority, ref statusMayHaveChanged);
2151 ghuddy 421
 
2155 ghuddy 422
                        ea_req.Status     = updated_property_value_if_changed(changeLog, ea_req, ea_req.Status, "Status", rq_obj.status, ref statusMayHaveChanged);
423
 
424
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE, "Source", rq_obj.source, ref statusMayHaveChanged);
425
 
426
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE_VERSION, "SourceVersion", rq_obj.sourceVersion, ref statusMayHaveChanged);
427
 
428
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SOURCE_SECTION, "SourceSection", rq_obj.sourceSection, ref statusMayHaveChanged);
429
 
430
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_SUBSYSTEM, "Subsystem", rq_obj.subsystem, ref statusMayHaveChanged);
431
 
432
                        if_tagged_value_changed_update_it(changeLog, ea_req, Constants.TAG_STABILITY, "Stability", rq_obj.stability, ref statusMayHaveChanged);
433
 
434
                        // Requirement Types are actually implemented using ordinary EA element stereotypes.
2157 ghuddy 435
                        if (!ea_req.Stereotype.Equals(rq_obj.type))
2155 ghuddy 436
                        {
437
                           changeLog.Notes += ea_req.ElementGUID + ":ReqType:" + ea_req.Stereotype + ":" + rq_obj.type + "\r\n";
438
                           changeLog.Update();
439
                           statusMayHaveChanged = true;
2157 ghuddy 440
                           ea_req.StereotypeEx = rq_obj.type;
441
                           ea_req.Stereotype = rq_obj.type;
2155 ghuddy 442
                        }
443
 
444
                        ea_req.Update();
445
 
446
                        if (meaningMayHaveChanged)
447
                        {
448
                           modifiedRequirementCount++;
449
                        }
2151 ghuddy 450
 
2155 ghuddy 451
                        if (statusMayHaveChanged)
452
                        {
453
                           statusUpdatedRequirementCount++;
454
                        }
455
 
456
                        totalRequirements++;
2151 ghuddy 457
                     }
458
 
459
                  }
460
                  else
461
                  {
462
                     totalRequirements++;
463
 
464
                     // This ReqPro requirement does not have a counterpart in EA, so we must create
465
                     // a new one.
466
                     newRequirementCount++;
467
 
468
                     // create the new EA requirement in the import package
469
                     EA.Element ea_req = (EA.Element)importPackage.Elements.AddNew( rq_obj.tag + " " + rq_obj.name, "Requirement");
470
 
471
                     rq_obj.ea_element_ID = ea_req.ElementID;
472
 
2155 ghuddy 473
                     CopyReqProDatabase.copyReq(ea_req, rq_obj);
2151 ghuddy 474
 
2155 ghuddy 475
                     ea_req.Notes = rq_obj.text;
476
 
2151 ghuddy 477
                     ea_req.Update();
478
 
479
                     changeLog.Notes += ea_req.ElementGUID + ":Created:" + ea_req.Name + "\r\n";
480
                     changeLog.Update();
481
 
2155 ghuddy 482
                     Main.WriteOutput("Created: " + ea_req.Name, ea_req.ElementID);
2151 ghuddy 483
                  }
484
 
485
               }
486
               catch (Exception ex)
487
               {
2155 ghuddy 488
                  Main.WriteOutput("Exception (ImportFromReqPro), " + ex.Message + ", " + rq_obj.name, -1);
2151 ghuddy 489
               }
490
            }
491
 
492
            if (Main.mustAbort)
493
               return;
494
 
2155 ghuddy 495
            Main.WriteOutput("Checking for orphaned requirements", -1);
2151 ghuddy 496
            // Now check for orphaned EA requirements
497
            for (int i = 0; i < ea_GUIDs.Count; i++)
498
            {
499
               if (Main.mustAbort)
500
                  break;
501
 
502
               string rq_GUID = (string)ea_GUIDs[i];
503
               if (rq_GUID != "")
504
               {
505
                  if ((bool)ea_req_matched[i] == false)
506
                  {
507
                     EA.Element ea_req = (EA.Element)ea_reqs[i];
508
 
509
                     orphanedCount++;
510
 
511
                     changeLog.Notes += ea_req.ElementGUID + ":Orphaned:" + ea_req.Name + "\r\n";
512
                     changeLog.Update();
513
                  }
514
               }
515
            }
516
 
2155 ghuddy 517
            bool changeLogDeleted = false;
518
            if (changeLog.Notes != null && changeLog.Notes.Length > 0)
519
            {
520
               DialogResult dlgres = MessageBoxEx.Show("Display Change Log?", "Change Log", MessageBoxButtons.YesNo);
521
               if (dlgres == DialogResult.Yes)
522
                  displayChangeLog(changeLog);
523
            }
524
            else
525
            {
526
               importPackage.Elements.Refresh();
527
               if (importPackage.Elements.Count == 1)
528
               {
529
                  EA_Utilities.deletePackage(importPackage);
530
                  changeLogDeleted = true;
531
               }
532
            }
2151 ghuddy 533
 
534
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
535
 
2149 ghuddy 536
            // Setup the internal requirement to requirement connectivity. This is seperate from the browser
537
            // organisation of elements in EA, but since in ReqPro, that organisation tells part of the story
538
            // of requirement to requirement connectivity, it is mirrored in the internal connectivity, along
539
            // with explicit trace relationships setup in ReqPro.
540
            // The purpose of this internal connectivity is to support relationship matrix tables in documentation
541
            // generated by EA_DocGen, or to support diagrammatic representations of the requirements in EA,
542
            // where the connectivity will become apparent through links ajoining the requirement elements in the
543
            // diagram.
2151 ghuddy 544
            write_traces(totalRequirements);
2141 ghuddy 545
 
2151 ghuddy 546
            if (Main.mustAbort)
547
               return;
2141 ghuddy 548
 
2155 ghuddy 549
            writeDelayedMessages();
550
 
2151 ghuddy 551
            // display summary stats
2155 ghuddy 552
            Main.WriteOutput(newRequirementCount.ToString() + " new requirements", -1);
553
            Main.WriteOutput(modifiedRequirementCount.ToString() + " requirements modified", -1);
554
            Main.WriteOutput(statusUpdatedRequirementCount.ToString() + " requirements had status changes", -1);
555
            Main.WriteOutput(orphanedCount.ToString() + " requirements were orphaned", -1);
2151 ghuddy 556
 
2155 ghuddy 557
            if (changeLogDeleted)
558
            {
559
               Main.WriteOutput("NOTE: import package and change log deleted, since nothing changed in this import", -1);
560
            }
2151 ghuddy 561
 
2155 ghuddy 562
            Main.WriteOutput("Import Completed", -1);
563
            MessageBoxEx.Show("Import Completed");
2151 ghuddy 564
         }
565
         catch (Exception ex)
566
         {
2153 ghuddy 567
            Main.MessageBoxException(ex, "Exception (ImportFromReqPro)");
2151 ghuddy 568
         }
569
      }
570
 
2155 ghuddy 571
      private string updated_property_value_if_changed(EA.Element changeLog, 
572
         EA.Element ea_req, 
573
         string dest_value, 
574
         string changeLogName, 
575
         string source_value,
576
         ref bool mayHaveChanged)
577
      {
578
         if (dest_value.CompareTo(source_value) != 0 )
579
         {
580
            changeLog.Notes += ea_req.ElementGUID + ":" + changeLogName+ ":" + NO_COLONS(dest_value) + ":" + NO_COLONS(source_value) + "\r\n";
581
            changeLog.Update();
582
            mayHaveChanged = true;
583
            return source_value;
584
         }
585
         return dest_value;
586
      }
2151 ghuddy 587
 
2155 ghuddy 588
      private void if_tagged_value_changed_update_it(EA.Element changeLog, 
589
         EA.Element ea_req, 
590
         string tagname, 
591
         string changeLogName, 
592
         string source_value,
593
         ref bool statusMayHaveChanged)
594
      {
595
         string value = EA_TaggedValues.Read(ea_req, tagname, "");
596
         if ((source_value != null) && (false == source_value.Equals(value)))
597
         {
598
            changeLog.Notes += ea_req.ElementGUID + ":" + changeLogName + ":" + value + ":" + source_value + "\r\n";
599
            changeLog.Update();
600
            EA_TaggedValues.Write(ea_req, tagname, source_value);
601
            statusMayHaveChanged = true;
602
         }
603
      }
2151 ghuddy 604
 
605
 
2155 ghuddy 606
 
607
 
2141 ghuddy 608
      /// <summary>
609
      /// This method (along with its sibling overload) obtains a flattened view of the 
610
      /// hierarchical requirements obtained from the ReqPro database. This accumulation
611
      /// takes account of the users filtering requests.
612
      /// </summary>
613
      /// <param name="ea_repository"></param>
2151 ghuddy 614
      private void get_rq_req_collection(ref ArrayList rq_req_collection)
2141 ghuddy 615
      {
616
         foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
617
         {
2151 ghuddy 618
            get_rq_req_collection(ref rq_req_collection, sub_obj);
2141 ghuddy 619
         }
620
      }
621
 
2151 ghuddy 622
      private void get_rq_req_collection(ref ArrayList rq_req_collection,
2141 ghuddy 623
                                         ReqPro_object rq_obj )
624
      {
625
         if (rq_obj.isPackage)
626
         {
2147 ghuddy 627
            // if the package is not filtered, or if we are allowed to dig beneath filtered
628
            // packages...
629
            if (rq_obj.filtered == false || base.allowPackageStructureFragments)
2141 ghuddy 630
            {
631
               // Using recursion, scan this objects sub-objects
632
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
633
               {
2147 ghuddy 634
                  // if the sub-object is a package, always recurse to process it, else
635
                  // if the sub-object is a requirement, only recurse if the containing package
636
                  // is not filtered, so that requirements of filtered packages are themselves
637
                  // filtered out by virtue of their parent packages filtering state.
638
                  if (  sub_obj.isPackage
639
                     || (sub_obj.isRequirement && rq_obj.filtered == false))
640
                  {
2151 ghuddy 641
                     get_rq_req_collection(ref rq_req_collection, sub_obj);
2147 ghuddy 642
                  }
2141 ghuddy 643
               }
644
            }
645
         }
646
         else if (rq_obj.isRequirement)
647
         {
648
            if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)) )
649
            {
650
               // Add this requirement to the flattened list we are accumulating
651
               rq_req_collection.Add(rq_obj);
652
 
2149 ghuddy 653
               // In ReqPro, a requirement can be related to another requirement in several ways:
654
               // 1. By virtue of its position relative to another in the browser display. That is, 
655
               //    if you place a requirement beneath a parent requirement, you are establishing a 
656
               //    parent-child relationship.
657
               // 2. By virtue of a specific TraceTo relationship being made via the Traceability menu
658
               //    option. 
659
               // Interestingly, ReqPro prevents you creating a relationship of one of the above types,
660
               // if a relationship of the other type already exists. This implies that the relationship
661
               // between a parent and child requirement must be singular and is important regardless
662
               // of the manner in which it was created or represented.
663
               // The CopyReqProDatabaseToMemory base class will already have taken care of recording
664
               // relationships detected from ReqPro made using method 2 above. What we need to do here is
665
               // take care of those apparent from the browser based hierarchical organisation (ie. made
666
               // in ReqPro using method 1).
667
               // All we need to do is grab the parent object (if any) and add the GUID of the child to 
668
               // its list of trace-to's. Later on, the write_traces() class method will turn these into
669
               // EA based connection objects that belong to the parent requirement elements.
670
               if (rq_obj.parent != null)
671
               {
672
                  rq_obj.parent.ReqPro_traces.Add(rq_obj.guid);
673
               }
674
 
2147 ghuddy 675
               // Using recursion, scan this objects sub-objects, which in practise will all
676
               // be requirement objects. At this time requirement objects cannot have packages 
677
               // as children.
2141 ghuddy 678
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
679
               {
2151 ghuddy 680
                  get_rq_req_collection(ref rq_req_collection, sub_obj);
2141 ghuddy 681
               }
682
            }
683
         }
684
      }
685
 
686
 
687
	}
688
}