001: package salomeTMF_plug.gen_doc_xml;
002:
003: import java.util.Enumeration;
004: import java.util.Hashtable;
005: import java.util.Iterator;
006: import java.util.Vector;
007:
008: import javax.swing.JTree;
009: import javax.swing.tree.DefaultMutableTreeNode;
010: import javax.swing.tree.DefaultTreeModel;
011:
012: import org.dom4j.Document;
013: import org.dom4j.Element;
014: import org.java.plugin.Extension;
015: import org.objectweb.salome_tmf.data.Test;
016: import org.objectweb.salome_tmf.ihm.tools.Tools;
017: import org.objectweb.salome_tmf.plugins.IPlugObject;
018:
019: public class ImportReq {
020:
021: // ReqPlugin pReqPlugin = null;
022: Object pReqPlugin = null;
023: Hashtable projectReqByName;
024: Hashtable projectReqById;
025: //ReqFamily reqRoot;
026: Object reqRoot;
027: boolean reqAreUpdated;
028: //boolean importReq;
029: Import pImport;
030:
031: ImportReq(IPlugObject pIPlugObject, Import _pImport)
032: throws Exception {
033: // Requirments //
034: pReqPlugin = null;
035: //importReq = _importReq;
036: pImport = _pImport;
037: projectReqByName = new Hashtable();
038: projectReqById = new Hashtable();
039: Extension ext = (Extension) pIPlugObject
040: .getAssociatedExtension("requirements.Common");
041: if (ext != null) {
042:
043: pReqPlugin = (salomeTMF_plug.requirements.ReqPlugin) pIPlugObject
044: .getPluginManager().activateExtension(ext);
045: JTree pTree = ((salomeTMF_plug.requirements.ReqPlugin) pReqPlugin)
046: .getTreeRequirement();
047: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) pTree
048: .getModel()).getRoot();
049: salomeTMF_plug.requirements.data.Requirement pTempReq = (salomeTMF_plug.requirements.data.Requirement) node
050: .getUserObject();
051: projectReqByName.put(pTempReq.getNameFromModel(), pTempReq);
052: projectReqById.put(new Integer(0), pTempReq);
053: reqRoot = (salomeTMF_plug.requirements.data.ReqFamily) pTempReq;
054: if (node.getChildCount() > 0) {
055: loadRequirementModel(node, true, projectReqByName,
056: projectReqById);
057: reqAreUpdated = false;
058: }
059: } else {
060: throw new Exception("No requirements plugins");
061: }
062: }
063:
064: void loadRequirementModel(DefaultMutableTreeNode pTempNode,
065: boolean first, Hashtable projectReqByName,
066: Hashtable projectReqById) {
067: salomeTMF_plug.requirements.data.Requirement pTempReq = (salomeTMF_plug.requirements.data.Requirement) pTempNode
068: .getUserObject();
069: if (!first) {
070: projectReqByName.put(pTempReq.getNameFromModel(), pTempReq);
071: projectReqById.put(new Integer(0), pTempReq);
072:
073: } else {
074: first = false;
075: }
076:
077: if (pTempReq instanceof salomeTMF_plug.requirements.data.ReqLeaf) {
078: return;
079: } else {
080: int nbChild = pTempNode.getChildCount();
081:
082: for (int i = 0; i < nbChild; i++) {
083: loadRequirementModel((DefaultMutableTreeNode) pTempNode
084: .getChildAt(i), first, projectReqByName,
085: projectReqById);
086: }
087:
088: }
089: }
090:
091: void removeReqLink(Element testElem, Test test) {
092: try {
093: Vector listReqWrapper = salomeTMF_plug.requirements.data.Requirement
094: .getReqWrapperCoveredByTest(test.getIdBdd());
095: int size = listReqWrapper.size();
096:
097: for (int i = 0; i < size; i++) {
098: salomeTMF_plug.requirements.sqlWrapper.ReqWrapper pReqWrapper = (salomeTMF_plug.requirements.sqlWrapper.ReqWrapper) listReqWrapper
099: .elementAt(i);
100: salomeTMF_plug.requirements.data.Requirement pReq = (salomeTMF_plug.requirements.data.Requirement) projectReqByName
101: .get(pReqWrapper.getName());
102: Iterator itReqLinkXML = testElem.selectNodes(
103: "LinkRequirement/RequirementRef").iterator();
104: boolean appartient = false;
105: while (itReqLinkXML.hasNext() && !appartient) {
106: Element linkElem = (Element) itReqLinkXML.next();
107: String nomReq = linkElem.elementText("Nom");
108: if (pReqWrapper.getName().equals(nomReq)) {
109: appartient = true;
110: }
111: }
112: if (!appartient) {
113: if (pReq != null) {
114: try {
115:
116: pReq.deleteCoverForTest(test.getIdBdd());
117: } catch (Exception e1) {
118: Tools.ihmExceptionView(e1);
119: }
120: }
121: }
122: }
123: } catch (Exception e) {
124: Tools.ihmExceptionView(e);
125: }
126: }
127:
128: public void gestionDesSuppressionsRequirements(Document doc)
129: throws Exception {
130: //Suppression des requirements du projet
131: reqAreUpdated = true;
132: Enumeration itReqProjet = projectReqByName.elements();
133:
134: while (itReqProjet.hasMoreElements()) {
135: salomeTMF_plug.requirements.data.Requirement pReq = (salomeTMF_plug.requirements.data.Requirement) itReqProjet
136: .nextElement();
137: if (pReq instanceof salomeTMF_plug.requirements.data.ReqLeaf) {
138:
139: Iterator itReqLeqfXML = doc
140: .selectNodes("//Requirement").iterator();
141: boolean appartient = false;
142: Element reqElem = null;
143: String desc = null;
144: while (itReqLeqfXML.hasNext() && !appartient) {
145: reqElem = (Element) itReqLeqfXML.next();
146: if (reqElem.elementText("Nom").equals(
147: pReq.getNameFromModel())) {
148: desc = (reqElem.elementText("Description") == null) ? ""
149: : reqElem.elementText("Description");
150: desc = desc.replaceAll("\\\\n", "\n");
151: appartient = true;
152: }
153: }
154: if (!appartient) {
155: try {
156: pReq.deleteInDBAndModel();
157: projectReqByName
158: .remove(pReq.getNameFromModel());
159: projectReqById.remove(new Integer(pReq
160: .getIdBdd()));
161: } catch (Exception e) {
162: Tools.ihmExceptionView(e);
163: }
164: } else {
165: // Update
166: if (reqElem != null) {
167: pImport.updateElementAttachement(reqElem, pReq,
168: false);
169: if (desc != null) {
170: pReq.updateDescriptionInDBAndModel(desc);
171: }
172: }
173: }
174: }
175: }
176: itReqProjet = projectReqByName.elements();
177: while (itReqProjet.hasMoreElements()) {
178: salomeTMF_plug.requirements.data.Requirement pReq = (salomeTMF_plug.requirements.data.Requirement) itReqProjet
179: .nextElement();
180: if (pReq instanceof salomeTMF_plug.requirements.data.ReqFamily
181: && pReq.getIdBdd() > 0) {
182:
183: Iterator itReqFamXML = doc.selectNodes(
184: "//RequirementFamily").iterator();
185: boolean appartient = false;
186: Element reqElem = null;
187: String desc = null;
188: while (itReqFamXML.hasNext() && !appartient) {
189: reqElem = (Element) itReqFamXML.next();
190: if (reqElem.elementText("Nom").equals(
191: pReq.getNameFromModel())) {
192: desc = (reqElem.elementText("Description") == null) ? ""
193: : reqElem.elementText("Description");
194: desc = desc.replaceAll("\\\\n", "\n");
195: appartient = true;
196: }
197: }
198: if (!appartient) {
199: try {
200: Vector reqLeafs = ((salomeTMF_plug.requirements.data.ReqFamily) pReq)
201: .getFistLeaf();
202: if (reqLeafs.size() == 0) {
203: pReq.deleteInDBAndModel();
204: projectReqByName.remove(pReq
205: .getNameFromModel());
206: projectReqById.remove(new Integer(pReq
207: .getIdBdd()));
208: } else {
209: for (int i = 0; i < reqLeafs.size(); i++) {
210: salomeTMF_plug.requirements.data.Requirement pTmpReq = (salomeTMF_plug.requirements.data.Requirement) reqLeafs
211: .elementAt(i);
212: pTmpReq
213: .updateParentInDBAndModel((salomeTMF_plug.requirements.data.ReqFamily) reqRoot);
214: }
215: }
216: } catch (Exception e) {
217: Tools.ihmExceptionView(e);
218: }
219: } else {// Update
220: if (reqElem != null) {
221: pImport.updateElementAttachement(reqElem, pReq,
222: false);
223: if (desc != null) {
224: pReq.updateDescriptionInDBAndModel(desc);
225: }
226: }
227: }
228: }
229: }
230:
231: }
232:
233: void updateReqLink(Element testElem, Test test, boolean supprElement) {
234: Iterator itReqLinkXML = testElem.selectNodes(
235: "LinkRequirement/RequirementRef").iterator();
236: try {
237: Vector listReqWrapper = salomeTMF_plug.requirements.data.Requirement
238: .getReqWrapperCoveredByTest(test.getIdBdd());
239: int size = listReqWrapper.size();
240: while (itReqLinkXML.hasNext()) {
241: Element linkElem = (Element) itReqLinkXML.next();
242: String nomReq = linkElem.elementText("Nom");
243: salomeTMF_plug.requirements.data.Requirement pReq = (salomeTMF_plug.requirements.data.Requirement) projectReqByName
244: .get(nomReq);
245: if (pReq == null) {
246: Tools.ihmExceptionView(new Exception(
247: "[updateReqLink] Requirment " + nomReq
248: + " not found"));
249: }
250: if (pReq instanceof salomeTMF_plug.requirements.data.ReqFamily) {
251: Tools
252: .ihmExceptionView(new Exception(
253: "[updateReqLink] Requirment "
254: + nomReq
255: + " is a family and can't be linked to the test "
256: + test.getNameFromModel()));
257: }
258: boolean appartient = false;
259: int i = 0;
260: while (i < size && !appartient) {
261: salomeTMF_plug.requirements.sqlWrapper.ReqWrapper pReqWrapper = (salomeTMF_plug.requirements.sqlWrapper.ReqWrapper) listReqWrapper
262: .elementAt(i);
263: if (pReqWrapper.getName().equals(nomReq)) {
264: appartient = true;
265: }
266: i++;
267: }
268: if (!appartient) {
269: try {
270: pReq.addTestCoverInDB(test.getIdBdd(), true);
271: } catch (Exception e1) {
272: Tools.ihmExceptionView(e1);
273: }
274: }
275: }
276: if (supprElement) {
277: removeReqLink(testElem, test);
278: }
279: } catch (Exception e) {
280: Tools.ihmExceptionView(e);
281: }
282: }
283:
284: void ajoutRequirement(Element reqElem, Hashtable docReqById) {
285: String nomReq = reqElem.elementText("Nom");
286:
287: int priority = (new Integer(reqElem.attributeValue("priority")))
288: .intValue();
289: String version = reqElem.attributeValue("version");
290:
291: String desc = (reqElem.elementText("Description") == null) ? ""
292: : reqElem.elementText("Description");
293: desc = desc.replaceAll("\\\\n", "\n");
294: String strId_reqParent = reqElem
295: .attributeValue("id_req_parent");
296: strId_reqParent = strId_reqParent.substring(4, strId_reqParent
297: .length()); //remove Req_
298: Integer id_reqParent = new Integer(strId_reqParent);
299:
300: Element reqParentElement = (Element) docReqById
301: .get(id_reqParent);
302: salomeTMF_plug.requirements.data.ReqFamily pReqParent;
303: if (id_reqParent.equals(new Integer(0))) {
304: pReqParent = (salomeTMF_plug.requirements.data.ReqFamily) reqRoot;
305: } else {
306: String nomParentReq = reqParentElement.elementText("Nom");
307: salomeTMF_plug.requirements.data.Requirement pTempReq = (salomeTMF_plug.requirements.data.Requirement) projectReqByName
308: .get(nomParentReq);
309:
310: if (pTempReq != null
311: && pTempReq instanceof salomeTMF_plug.requirements.data.ReqFamily) {
312: pReqParent = (salomeTMF_plug.requirements.data.ReqFamily) pTempReq;
313: } else {
314: pReqParent = (salomeTMF_plug.requirements.data.ReqFamily) reqRoot;
315: }
316: }
317: salomeTMF_plug.requirements.data.ReqLeaf pNewReq = new salomeTMF_plug.requirements.data.ReqLeaf(
318: nomReq, desc, pReqParent, priority);
319: pNewReq.updateVersionInModel(version);
320: try {
321: pNewReq.addInDB();
322: pReqParent.addRequirement(pNewReq);
323: projectReqByName.put(pNewReq.getNameFromModel(), pNewReq);
324: projectReqById
325: .put(new Integer(pNewReq.getIdBdd()), pNewReq);
326: pImport.updateElementAttachement(reqElem, pNewReq, true);
327: } catch (Exception e) {
328: Tools.ihmExceptionView(e);
329: }
330: }
331:
332: salomeTMF_plug.requirements.data.ReqFamily ajoutReqFamily(
333: Element reqElem, Hashtable docReqByName,
334: Hashtable docReqById) {
335: if (reqElem == null) {
336: return (salomeTMF_plug.requirements.data.ReqFamily) reqRoot;
337: }
338: String nomReq = reqElem.elementText("Nom");
339: salomeTMF_plug.requirements.data.Requirement pTempReq = (salomeTMF_plug.requirements.data.Requirement) projectReqByName
340: .get(nomReq);
341: if (pTempReq != null
342: && pTempReq instanceof salomeTMF_plug.requirements.data.ReqFamily) {
343: return (salomeTMF_plug.requirements.data.ReqFamily) pTempReq;
344: }
345:
346: String strId_reqParent = reqElem
347: .attributeValue("id_req_parent");
348: strId_reqParent = strId_reqParent.substring(4, strId_reqParent
349: .length()); //remove Req_
350: Integer id_reqParent = new Integer(strId_reqParent);
351:
352: Element reqParentElement = (Element) docReqById
353: .get(id_reqParent);
354: salomeTMF_plug.requirements.data.ReqFamily pParent = ajoutReqFamily(
355: reqParentElement, docReqByName, docReqById);
356: String desc = (reqElem.elementText("Description") == null) ? ""
357: : reqElem.elementText("Description");
358: desc = desc.replaceAll("\\\\n", "\n");
359: salomeTMF_plug.requirements.data.ReqFamily pNewReqFamily = new salomeTMF_plug.requirements.data.ReqFamily(
360: nomReq, desc, pParent);
361:
362: try {
363: pNewReqFamily.addInDB();
364: pParent.addRequirement(pNewReqFamily);
365: projectReqByName.put(pNewReqFamily.getNameFromModel(),
366: pNewReqFamily);
367: projectReqById.put(new Integer(pNewReqFamily.getIdBdd()),
368: pNewReqFamily);
369: pImport.updateElementAttachement(reqElem, pNewReqFamily,
370: true);
371: } catch (Exception e) {
372: Tools.ihmExceptionView(e);
373: }
374: return pNewReqFamily;
375: }
376:
377: void updateProjectRequirement(Document doc) throws Exception {
378: //Mise a jour des Requirements existants et ajout des nouveaux
379:
380: Hashtable docReqByName = new Hashtable();
381: Hashtable docReqById = new Hashtable();
382: Vector reqElementToAdd = new Vector();
383: Vector reqFamilyToAdd = new Vector();
384:
385: Iterator itReqLeqfXML = doc.selectNodes("//Requirement")
386: .iterator();
387: while (itReqLeqfXML.hasNext()) {
388: Element reqElem = (Element) itReqLeqfXML.next();
389: String nomReq = reqElem.elementText("Nom");
390: String desc = (reqElem.elementText("Description") == null) ? ""
391: : reqElem.elementText("Description");
392: desc = desc.replaceAll("\\\\n", "\n");
393: String id_reqDoc = reqElem.attributeValue("id_req");
394: id_reqDoc = id_reqDoc.substring(4, id_reqDoc.length()); //remove Req_
395: salomeTMF_plug.requirements.data.Requirement pReq = (salomeTMF_plug.requirements.data.Requirement) projectReqByName
396: .get(nomReq);
397: docReqByName.put(nomReq, reqElem);
398: docReqById.put(new Integer(id_reqDoc), reqElem);
399:
400: if (pReq != null) {
401: //Existe --> Update
402: if (reqElem != null && !reqAreUpdated) {
403: pImport.updateElementAttachement(reqElem, pReq,
404: false);
405: if (desc != null) {
406: pReq.updateDescriptionInDBAndModel(desc);
407: }
408: }
409: } else {
410: //Not Existe --> Ajout
411: reqElementToAdd.add(reqElem);
412:
413: }
414: }
415:
416: Iterator itReqFamilyfXML = doc.selectNodes(
417: "//RequirementFamily").iterator();
418: while (itReqFamilyfXML.hasNext()) {
419: Element reqElem = (Element) itReqFamilyfXML.next();
420: String nomReq = reqElem.elementText("Nom");
421: String desc = (reqElem.elementText("Description") == null) ? ""
422: : reqElem.elementText("Description");
423: desc = desc.replaceAll("\\\\n", "\n");
424: String id_reqDoc = reqElem.attributeValue("id_req");
425: id_reqDoc = id_reqDoc.substring(4, id_reqDoc.length()); //remove Req_
426: salomeTMF_plug.requirements.data.Requirement pReq = (salomeTMF_plug.requirements.data.Requirement) projectReqByName
427: .get(nomReq);
428: docReqByName.put(nomReq, reqElem);
429: docReqById.put(new Integer(id_reqDoc), reqElem);
430: if (pReq != null) {
431: //Existe --> Update
432: if (reqElem != null && !reqAreUpdated) {
433: pImport.updateElementAttachement(reqElem, pReq,
434: false);
435: if (desc != null) {
436: pReq.updateDescriptionInDBAndModel(desc);
437: }
438: }
439: } else {
440: //Not Existe --> Ajout
441: reqFamilyToAdd.add(reqElem);
442: //updateElementAttachement(reqElem, pReq, true);
443: }
444: }
445: // Ajput des nouveau requirements
446: for (int i = 0; i < reqFamilyToAdd.size(); i++) {
447: Element reqElem = (Element) reqFamilyToAdd.elementAt(i);
448: ajoutReqFamily(reqElem, docReqByName, docReqById);
449: }
450: for (int i = 0; i < reqElementToAdd.size(); i++) {
451: Element reqElem = (Element) reqElementToAdd.elementAt(i);
452: ajoutRequirement(reqElem, docReqById);
453: }
454:
455: }
456:
457: void reloadReq() {
458: if (pReqPlugin != null) {
459: try {
460: ((salomeTMF_plug.requirements.ReqPlugin) pReqPlugin)
461: .reloadReq();
462: } catch (Exception e) {
463: }
464: }
465: }
466: }
|