Subversion Repositories DevTools

Rev

Rev 2141 | Rev 2145 | 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
namespace EA_ReqPro
9
{
10
	/// <summary>
11
	/// CopyReqProDatabase is a specialisation of ReqProParser, designed to copy the 
12
	/// ReqPro database content into an EA database, maintaining the structure of 
13
	/// and hierarchy of packages and requirements found in the ReqPro database.
14
	/// </summary>
15
   public class CopyReqProDatabase : CopyReqProDatabaseToMemory
16
   {
17
      /// <summary>
18
      /// Construct the object
19
      /// </summary>
20
      /// <param name="ea_repository"></param>
21
      public CopyReqProDatabase(EA.Repository ea_repository): base(ea_repository)
22
      {
23
         try
24
         {
25
            if (ea_rootPackage.Elements.Count > 0
26
               || ea_rootPackage.Packages.Count > 0)
27
            {
28
               DialogResult dlgRes = MessageBox.Show("Package is not empty, delete existing content first?", "Confirm", MessageBoxButtons.YesNo);
29
               if (dlgRes == DialogResult.Yes)
30
               {
31
                  // Delete packages and requirement elements
32
                  short i;
33
                  for(i=0; i < ea_rootPackage.Packages.Count; i++)
34
                  {
35
                     ea_rootPackage.Packages.Delete(i);
36
                  }
37
                  for(i=0; i < ea_rootPackage.Elements.Count; i++)
38
                  {
39
                     if ( ((EA.Element)ea_rootPackage.Elements.GetAt(i)).Type.StartsWith("Requirement") )
40
                     {
41
                        ea_rootPackage.Elements.Delete(i);
42
                     }
43
                  }
44
                  ea_rootPackage.Packages.Refresh();
45
                  // refresh project browser view
46
                  ea_repository.RefreshModelView(ea_rootPackage.PackageID);               }
47
            }
48
         }
49
         catch (Exception ex)
50
         {
51
            MessageBox.Show(ex.Message, "Error (CopyReqProDatabase::CopyReqProDatabase)", MessageBoxButtons.OK);
52
         }           
53
      }
54
 
55
 
56
      /// <summary>
57
      /// Method to parse a ReqPro database and copy it into an EA database.
58
      /// </summary>
59
      /// <param name="ea_repository"></param>
60
      /// <returns></returns>
61
      public override bool prompt_and_parse(EA.Repository ea_repository)
62
      {
63
         try
64
         {
65
            // use the base classes parser to read the ReqPro database content and allow the user to
66
            // filter it.
67
            if (true == base.prompt_and_parse(ea_repository))
68
            {
69
               ea_repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
70
 
71
               // write the captured info from reqpro, into the ea database, obeying the filter
72
               // settings the user has specified.
73
               write_ea_database(ea_repository);
2143 ghuddy 74
               MessageBox.Show("Import Completed");
2141 ghuddy 75
               return true;
76
            }
77
         }
78
         catch (Exception ex)
79
         {
80
            MessageBox.Show(ex.Message, "Error (CopyReqProDatabase::parse)", MessageBoxButtons.OK);
81
         }      
82
         return false;
83
      }
84
 
85
 
86
 
2143 ghuddy 87
      /// <summary>
88
      /// Finds and returns the ReqPro_object instance that contains the specified GUID. The
89
      /// GUID is that of the originating ReqPro requirement, which is copied into a ReqPro_object
90
      /// instance when it is created. This find operation supports the ability to resolve object to
91
      /// object trace relationships mirrored from the ReqPro database during the construction
92
      /// of the ReqPro_object hierarchy.
93
      /// </summary>
94
      /// <param name="rq_obj"></param>
95
      /// <param name="ReqProGUID"></param>
96
      /// <returns></returns>
97
      private ReqPro_object findReqPro_object_byReqProGUID(ReqPro_object rq_obj, string ReqProGUID)
98
      {
99
         if (rq_obj.guid.CompareTo(ReqProGUID) == 0)
100
         {
101
            return rq_obj;
102
         }
2141 ghuddy 103
 
2143 ghuddy 104
         foreach (ReqPro_object sub_rq_obj in rq_obj.ReqPro_objects)
105
         {
106
            ReqPro_object tgt_obj = findReqPro_object_byReqProGUID(sub_rq_obj, ReqProGUID);
107
            if (tgt_obj != null)
108
               return tgt_obj;
109
         }
110
 
111
         return null;
112
      }
2141 ghuddy 113
 
114
 
115
      /// <summary>
2143 ghuddy 116
      /// This method examines all of the ReqPro_object trace relationships and mirrors them in 
117
      /// the EA requirement elements that have been formed from each un-filtered ReqPro_objects.
118
      /// </summary>
119
      /// <param name="ea_repository"></param>
120
      /// <param name="rq_obj"></param>
121
      private void write_traces(EA.Repository ea_repository, ReqPro_object rq_obj)
122
      {
123
         if (rq_obj.isRequirement)
124
         {
125
            // if this object had an EA element made for it during the write_ea_database() process...
126
            if (rq_obj.ea_element_ID != -1)
127
            {
128
               EA.Element ea_rq_obj = ea_repository.GetElementByID(rq_obj.ea_element_ID);
129
               if (ea_rq_obj != null)
130
               {
131
                  foreach(string s in rq_obj.ReqPro_traces)
132
                  {
133
                     ReqPro_object tgt_obj = findReqPro_object_byReqProGUID(rq_root_package,s);
134
                     if (tgt_obj != null)
135
                     {
136
                        if (tgt_obj.ea_element_ID != -1)
137
                        {
138
                           EA.Element ea_tgt_obj = ea_repository.GetElementByID(tgt_obj.ea_element_ID);
139
                           if (ea_tgt_obj != null)
140
                           {
141
                              add_connection(ea_repository, ea_rq_obj, ea_tgt_obj);
142
                           }
143
                        }
144
                     }
145
                  }
146
               }
147
            }
148
         }
149
 
150
         // recurse to ensure we examine the entire hiearchy
151
         foreach(ReqPro_object sub_obj in rq_obj.ReqPro_objects)
152
         {
153
            write_traces(ea_repository, sub_obj);
154
         }
155
      }
156
 
157
      /// <summary>
158
      /// Adds a connection between one EA element and another
159
      /// </summary>
160
      /// <param name="repository"></param>
161
      /// <param name="rq_artifact"></param>
162
      /// <param name="ea_req"></param>
163
      private void add_connection(EA.Repository ea_repository, EA.Element src_element, EA.Element dest_element)
164
      {
165
         // Add the new requirement to the src_element
166
         EA.Connector c = (EA.Connector)src_element.Connectors.AddNew("", "Relationship");
167
         c.SupplierID = dest_element.ElementID;
168
         //c.Stereotype = "trace";
169
         c.Direction = "Source -> Destination";
170
         if (false == c.Update())
171
         {
172
            ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "New Connector Error : " + c.GetLastError(), dest_element.ElementID );
173
         }
174
         src_element.Connectors.Refresh();
175
      }
176
 
177
      /// <summary>
2141 ghuddy 178
      /// This method (along with its sibling overloads) perform the copy operation once
179
      /// the ReqPro database content has been acquired, and the user has submitted their
180
      /// filtering requirements. This method begins the copy operation, but the real nitty
181
      /// gritty of it occurs in the other overloaded method.
182
      /// </summary>
183
      /// <param name="ea_repository"></param>
184
      private void write_ea_database(EA.Repository ea_repository)
185
      {
186
         ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Copying ReqPro Database Content to EA", -1);
187
 
188
         foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
189
         {
190
            write_ea_database(ea_repository, ea_rootPackage, null, sub_obj);
191
         }
192
 
193
         ea_rootPackage.Packages.Refresh();
194
         // refresh project browser view
195
         ea_repository.RefreshModelView(ea_rootPackage.PackageID);
2143 ghuddy 196
 
197
         // Setup the internal requirement to requirement connectivity. This is seperate from the browser
198
         // organisation of elements in EA, but since in ReqPro, that organisation tells part of the story
199
         // of requirement to requirement connectivity, it is mirrored in the internal connectivity, along
200
         // with explicit trace relationships setup in ReqPro.
201
         // The purpose of this internal connectivity is to support relationship matrix tables in documentation
202
         // generated by EA_DocGen, or to support diagrammatic representations of the requirements in EA,
203
         // where the connectivity will become apparent through links ajoining the requirement elements in the
204
         // diagram.
205
         ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Writing Trace Information", -1);
206
         foreach( ReqPro_object sub_obj in rq_root_package.ReqPro_objects )
207
         {
208
            write_traces(ea_repository, sub_obj);
209
         }
2141 ghuddy 210
      }
211
 
212
      private void write_ea_database(EA.Repository ea_repository,
213
                                     EA.Package ea_parent_package,
214
                                     EA.Element ea_parent_element,
215
                                     ReqPro_object rq_obj )
216
      {
217
         if (rq_obj.isPackage)
218
         {
219
            if (rq_obj.filtered == false)
220
            {
221
               if (ea_parent_package != null)
222
               {
223
                  // create a representative package in EA
224
                  EA.Package new_ea_package = EA_Utils.createPackage(ea_parent_package, rq_obj.name, rq_obj.treePos);
2143 ghuddy 225
                  rq_obj.ea_element_ID = new_ea_package.PackageID;
2141 ghuddy 226
                  ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Package : " + rq_obj.name, new_ea_package.PackageID );
227
 
228
                  // Using recursion, scan this objects sub-objects
229
                  foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
230
                  {
231
                     write_ea_database(ea_repository, new_ea_package, null, sub_obj);
232
                  }
233
               }
234
               else
235
               {
2143 ghuddy 236
                  // should never get here - I have never seen it happen so far.
2141 ghuddy 237
                  ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ERROR,write_ea_database, parent package was null", -1);
238
               }
239
            }
240
            else if (base.allowPackageStructureFragments)
241
            {
242
               // Using recursion, scan this objects sub-objects
243
               foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
244
               {
245
                  if (sub_obj.isPackage)
246
                     write_ea_database(ea_repository, ea_parent_package, null, sub_obj);
247
               }
248
            }
249
         }
250
         else if (rq_obj.isRequirement)
251
         {
252
            if ( ! (reqTypeIsFiltered(rq_obj) || reqStatusTypeIsFiltered(rq_obj)))
253
            {
2143 ghuddy 254
               string rq_obj_name = rq_obj.tag + " " + rq_obj.name;
255
 
256
               // If needed, create the requirement element as a child of a parent element
2141 ghuddy 257
               if (ea_parent_element != null)
258
               {
259
                  // create a representative element in EA
2143 ghuddy 260
                  EA.Element new_ea_element = (EA.Element)ea_parent_element.Elements.AddNew(rq_obj_name, "Requirement");
261
                  rq_obj.ea_element_ID = new_ea_element.ElementID;
262
                  ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Element : " + rq_obj_name, new_ea_element.ElementID );
2141 ghuddy 263
 
2143 ghuddy 264
                  // In ReqPro, a requirement can be related to another requirement in several ways:
265
                  // 1. By virtue of its position relative to another in the browser display. That is, 
266
                  //    if you place a requirement beneath a parent requirement, you are establishing a 
267
                  //    parent-child relationship.
268
                  // 2. By virtue of a specific TraceTo relationship being made via the Traceability menu
269
                  //    option. 
270
                  // Interestingly, ReqPro prevents you creating a relationship of one of the above types,
271
                  // if a relationship of the other type already exists. This implies that the relationship
272
                  // between a parent and child requirement must be singular and is important regardless
273
                  // of the manner in which it was created or represented.
274
                  // The CopyReqProDatabaseToMemory base class will already have taken care of recording
275
                  // relationships detected from ReqPro made using method 2 above. What we need to do here is
276
                  // take care of those apparent from the browser based hierarchical organisation (ie. made
277
                  // in ReqPro using method 1).
278
                  // All we need to do is grab the parent object (if any) and add the GUID of the child to 
279
                  // its list of trace-to's. Later on, the write_traces() class method will turn these into
280
                  // EA based connection objects that belong to the parent requirement elements.
281
                  if (rq_obj.parent != null)
282
                  {
283
                     rq_obj.parent.ReqPro_traces.Add(rq_obj.guid);
284
                  }
285
 
2141 ghuddy 286
                  // If the ReqPro requirements detailed text is more than what the name already contains (allowing for it
287
                  // to have a stop character that the name may not have) then copy it over, otherwise ignore it. This
288
                  // prevents the same text appearing twice in any generated document made using EA_DocGen.
289
                  if (!rq_obj.text.StartsWith(rq_obj.name) || (rq_obj.text.Length > (rq_obj.name.Length + 1)))
290
                     new_ea_element.Notes = rq_obj.text;
291
 
292
                  new_ea_element.TreePos = rq_obj.treePos;
293
                  new_ea_element.Status  = rq_obj.status;
294
                  new_ea_element.Update();
295
 
2143 ghuddy 296
                  // Write EA tag information exactly as is done for the import for traceability use. This 
297
                  // opens up the possibility that a document model import could be converted into a traceability
298
                  // use model in some future update to EA_ReqPro addin.
299
                  EA_Utils.WriteTag(new_ea_element, "GUID", rq_obj.guid);
300
                  EA_Utils.WriteTag(new_ea_element, "TAG", rq_obj.tag);
301
 
2141 ghuddy 302
                  // Using recursion, scan this objects sub-objects
303
                  foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
304
                  {
305
                     write_ea_database(ea_repository, null, new_ea_element, sub_obj);
306
                  }
307
               }
2143 ghuddy 308
               // else create the requirement element as a child of a parent package
2141 ghuddy 309
               else if (ea_parent_package != null)
310
               {
311
                  // create a representative element in EA
2143 ghuddy 312
                  EA.Element new_ea_element = (EA.Element)ea_parent_package.Elements.AddNew(rq_obj_name, "Requirement");
313
                  rq_obj.ea_element_ID = new_ea_element.ElementID;
314
                  ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Created Element : " + rq_obj_name, new_ea_element.ElementID );
2141 ghuddy 315
 
316
                  // If the ReqPro requirements detailed text is more than what the name already contains (allowing for it
317
                  // to have a stop character that the name may not have) then copy it over, otherwise ignore it. This
318
                  // prevents the same text appearing twice in any generated document made using EA_DocGen.
319
                  if (!rq_obj.text.StartsWith(rq_obj.name) || (rq_obj.text.Length > (rq_obj.name.Length + 1)))
320
                     new_ea_element.Notes = rq_obj.text;
321
 
322
                  new_ea_element.TreePos = rq_obj.treePos;
323
                  new_ea_element.Status  = rq_obj.status;
324
                  new_ea_element.Update();
325
 
2143 ghuddy 326
                  // Write EA tag information exactly as is done for the import for traceability use. This 
327
                  // opens up the possibility that a document model import could be converted into a traceability
328
                  // use model in some future update to EA_ReqPro addin.
329
                  EA_Utils.WriteTag(new_ea_element, "GUID", rq_obj.guid);
330
                  EA_Utils.WriteTag(new_ea_element, "TAG", rq_obj.tag);
331
 
2141 ghuddy 332
                  // Using recursion, scan this objects sub-objects
333
                  foreach( ReqPro_object sub_obj in rq_obj.ReqPro_objects )
334
                  {
335
                     write_ea_database(ea_repository, null, new_ea_element, sub_obj);
336
                  }
337
               }
338
               else
339
               {
2143 ghuddy 340
                  // should never get here - I have never seen it happen so far.
2141 ghuddy 341
                  ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "ERROR,write_ea_database, parent package was null", -1);
342
               }
343
            }
344
         }
345
      }
346
 
347
 
348
 
349
 
350
	}
351
 
352
 
353
}