Subversion Repositories DevTools

Rev

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