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