Source Code Cross Referenced for ImportXMLReq.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » requirements » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » salome tmf » salomeTMF_plug.requirements 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package salomeTMF_plug.requirements;
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.tree.DefaultMutableTreeNode;
009:
010:        import org.dom4j.Document;
011:        import org.dom4j.Element;
012:        import org.objectweb.salome_tmf.api.Util;
013:        import org.objectweb.salome_tmf.data.Test;
014:        import org.objectweb.salome_tmf.ihm.tools.Tools;
015:        import org.objectweb.salome_tmf.plugins.core.XMLLoaderPlugin;
016:
017:        import salomeTMF_plug.requirements.data.ReqFamily;
018:        import salomeTMF_plug.requirements.data.ReqLeaf;
019:        import salomeTMF_plug.requirements.data.Requirement;
020:        import salomeTMF_plug.requirements.sqlWrapper.ReqWrapper;
021:
022:        public class ImportXMLReq {
023:
024:            //	ReqPlugin pReqPlugin = null;
025:            ReqPlugin pReqPlugin = null;
026:
027:            Hashtable projectReqByName;
028:            Hashtable projectReqById;
029:            Hashtable docReqById;
030:            Hashtable docElementById;
031:            Hashtable docReqByName;
032:            //ReqFamily reqRoot;
033:            ReqFamily reqRoot;
034:            //boolean importReq;
035:            XMLLoaderPlugin pImport;
036:
037:            ImportXMLReq(ReqPlugin _pReqPlugin, XMLLoaderPlugin pXMLLoader) {
038:                //Requirements
039:                pReqPlugin = _pReqPlugin;
040:                //importReq = _importReq;
041:                pImport = pXMLLoader;
042:                projectReqByName = new Hashtable();
043:                projectReqById = new Hashtable();
044:                docReqByName = new Hashtable();
045:                docReqById = new Hashtable();
046:                docElementById = new Hashtable();
047:            }
048:
049:            void loadRequirementCacheFromModel(
050:                    DefaultMutableTreeNode pTempNode, boolean first)
051:                    throws Exception {
052:                Requirement pTempReq = (Requirement) pTempNode.getUserObject();
053:                if (!first) {
054:                    projectReqByName.put(pTempReq.getLongName(), pTempReq);
055:                    projectReqById.put(new Integer(pTempReq.getIdBdd()),
056:                            pTempReq);
057:                } else {
058:                    first = false;
059:                }
060:
061:                if (pTempReq instanceof  ReqLeaf) {
062:                    return;
063:                } else {
064:                    int nbChild = pTempNode.getChildCount();
065:
066:                    for (int i = 0; i < nbChild; i++) {
067:                        loadRequirementCacheFromModel(
068:                                (DefaultMutableTreeNode) pTempNode
069:                                        .getChildAt(i), first);
070:                    }
071:                }
072:            }
073:
074:            void loadRequirementCacheFromXML(Document doc) throws Exception {
075:                docElementById.clear();
076:                docReqById.clear();
077:                docReqByName.clear();
078:                reqRoot = new ReqFamily("Requirements_"
079:                        + ReqPlugin.getProjectRef().getNameFromModel(), "");
080:                docReqById.put(new Integer(0), reqRoot);
081:                Iterator itReqFamilyfXML = doc.selectNodes(
082:                        "//RequirementFamily").iterator();
083:                while (itReqFamilyfXML.hasNext()) {
084:                    Element reqElem = (Element) itReqFamilyfXML.next();
085:                    String nomReq = reqElem.elementText("Nom");
086:                    String desc = (reqElem.elementText("Description") == null) ? ""
087:                            : reqElem.elementText("Description");
088:                    if (reqElem.element("Description") != null
089:                            && reqElem.element("Description").attribute(
090:                                    "isHTML") != null
091:                            && reqElem.element("Description").attributeValue(
092:                                    "isHTML").equals("true")) {
093:                        desc = giveHTMLDescription(reqElem);
094:                    } else {
095:                        desc = desc.replaceAll("\\\\n", "<br>");
096:                        desc = "<html><head></head><body>" + desc
097:                                + "</body></html>";
098:                    }
099:                    String id_reqDoc = reqElem.attributeValue("id_req");
100:                    id_reqDoc = id_reqDoc.substring(4, id_reqDoc.length()); //remove Req_
101:                    String id_reqParentDoc = reqElem
102:                            .attributeValue("id_req_parent");
103:                    id_reqParentDoc = id_reqParentDoc.substring(4,
104:                            id_reqParentDoc.length()); //remove Req_
105:
106:                    //docReqByName.put(nomReq, reqElem);
107:                    docElementById.put(new Integer(id_reqDoc), reqElem);
108:                    ReqWrapper pReqWrapper = new ReqWrapper();
109:                    pReqWrapper.setName(nomReq);
110:                    pReqWrapper.setDescription(desc);
111:                    pReqWrapper.setIdBDD(new Integer(id_reqDoc).intValue());
112:                    //pReqWrapper.setType(0);
113:                    ReqFamily pParent = (ReqFamily) docReqById.get(new Integer(
114:                            id_reqParentDoc));
115:                    ReqFamily pReqFamily = new ReqFamily(pReqWrapper, pParent);
116:                    pParent.addRequirement(pReqFamily);
117:                    docReqById.put(new Integer(id_reqDoc), pReqFamily);
118:                }
119:                Iterator itReqLeqfXML = doc.selectNodes("//Requirement")
120:                        .iterator();
121:                while (itReqLeqfXML.hasNext()) {
122:                    Element reqElem = (Element) itReqLeqfXML.next();
123:                    String nomReq = reqElem.elementText("Nom");
124:
125:                    int priority = -1;
126:                    String version = null;
127:                    int cat = -1;
128:                    int comp = -1;
129:                    int state = -1;
130:                    String origine = null;
131:                    String verifway = null;
132:                    String reference = null;
133:                    try {
134:                        priority = (new Integer(reqElem
135:                                .attributeValue("priority"))).intValue();
136:                        version = reqElem.attributeValue("version");
137:                        cat = (new Integer(reqElem.attributeValue("category")))
138:                                .intValue();
139:                        comp = (new Integer(reqElem
140:                                .attributeValue("complexity"))).intValue();
141:                        state = (new Integer(reqElem.attributeValue("state")))
142:                                .intValue();
143:                        origine = reqElem.attributeValue("origine");
144:                        verifway = reqElem.attributeValue("verifway");
145:                        reference = reqElem.attributeValue("reference");
146:                    } catch (Exception e) {
147:                        //XML from old plugin
148:                    }
149:                    String desc = (reqElem.elementText("Description") == null) ? ""
150:                            : reqElem.elementText("Description");
151:                    if (reqElem.element("Description") != null
152:                            && reqElem.element("Description").attribute(
153:                                    "isHTML") != null
154:                            && reqElem.element("Description").attributeValue(
155:                                    "isHTML").equals("true")) {
156:                        desc = giveHTMLDescription(reqElem);
157:                    } else {
158:                        desc = desc.replaceAll("\\\\n", "<br>");
159:                        desc = "<html><head></head><body>" + desc
160:                                + "</body></html>";
161:                    }
162:                    String id_reqDoc = reqElem.attributeValue("id_req");
163:                    id_reqDoc = id_reqDoc.substring(4, id_reqDoc.length()); //remove Req_
164:                    String id_reqParentDoc = reqElem
165:                            .attributeValue("id_req_parent");
166:                    id_reqParentDoc = id_reqParentDoc.substring(4,
167:                            id_reqParentDoc.length()); //remove Req_
168:
169:                    ReqWrapper pReqWrapper = new ReqWrapper();
170:                    pReqWrapper.setName(nomReq);
171:                    pReqWrapper.setDescription(desc);
172:                    pReqWrapper.setIdBDD(new Integer(id_reqDoc).intValue());
173:                    if (priority != -1) {
174:                        pReqWrapper.setPriority(priority);
175:                    }
176:                    if (version != null) {
177:                        pReqWrapper.setVersion(version);
178:                    }
179:                    if (cat != -1) {
180:                        pReqWrapper.setCat(cat);
181:                    }
182:                    if (comp != -1) {
183:                        pReqWrapper.setComplexe(comp);
184:                    }
185:                    if (state != -1) {
186:                        pReqWrapper.setState(state);
187:                    }
188:                    if (origine != null) {
189:                        pReqWrapper.setOrigine(origine);
190:                    }
191:                    if (verifway != null) {
192:                        pReqWrapper.setVerif(verifway);
193:                    }
194:                    if (reference != null) {
195:                        pReqWrapper.setReference(reference);
196:                    }
197:                    ReqFamily pParent = (ReqFamily) docReqById.get(new Integer(
198:                            id_reqParentDoc));
199:                    ReqLeaf pReq = new ReqLeaf(pReqWrapper, pParent);
200:                    pParent.addRequirement(pReq);
201:                    docReqById.put(new Integer(id_reqDoc), pReq);
202:                    docElementById.put(new Integer(id_reqDoc), reqElem);
203:                }
204:                Enumeration enumReqs = docReqById.elements();
205:                while (enumReqs.hasMoreElements()) {
206:                    Requirement pReq = (Requirement) enumReqs.nextElement();
207:                    docReqByName.put(pReq.getLongName(), pReq);
208:                }
209:            }
210:
211:            /**
212:             * Supprime les liens qui ne sont pas dans le XML
213:             * @param testElem
214:             * @param test
215:             */
216:            public void removeReqLink(Element testElem, Test test) {
217:                try {
218:                    Vector listReqWrapper = Requirement
219:                            .getReqWrapperCoveredByTest(test.getIdBdd());
220:                    int size = listReqWrapper.size();
221:
222:                    for (int i = 0; i < size; i++) {
223:                        ReqWrapper pReqWrapper = (ReqWrapper) listReqWrapper
224:                                .elementAt(i);
225:                        Requirement pReq = (Requirement) projectReqById
226:                                .get(new Integer(pReqWrapper.getIdBDD()));
227:
228:                        Iterator itReqLinkXML = testElem.selectNodes(
229:                                "LinkRequirement/RequirementRef").iterator();
230:                        boolean appartient = false;
231:                        while (itReqLinkXML.hasNext() && !appartient) {
232:                            Element linkElem = (Element) itReqLinkXML.next();
233:                            String id = linkElem.attributeValue("ref");
234:                            id = id.substring(4, id.length());
235:                            Requirement pTmpReq = (Requirement) docReqById
236:                                    .get(new Integer(id));
237:                            //String nomReq = linkElem.elementText("Nom");
238:                            if (pReq != null
239:                                    && pTmpReq != null
240:                                    && pTmpReq.getLongName().equals(
241:                                            pReq.getLongName())) {
242:                                appartient = true;
243:                            }
244:                        }
245:                        if (!appartient) {
246:                            if (pReq != null) {
247:                                try {
248:                                    pReq.deleteCoverForTest(test.getIdBdd());
249:                                } catch (Exception e1) {
250:                                    Tools.ihmExceptionView(e1);
251:                                }
252:                            }
253:                        }
254:                    }
255:                } catch (Exception e) {
256:                    Tools.ihmExceptionView(e);
257:                }
258:            }
259:
260:            /**
261:             * Suprrime les exigences qui ne sont pas dans le XML
262:             * @param doc
263:             * @throws Exception
264:             */
265:            public void gestionDesSuppressionsRequirements(Document doc)
266:                    throws Exception {
267:
268:                Enumeration itReqProjet = projectReqByName.elements();
269:
270:                /* Analyse des requiements feuilles */
271:                while (itReqProjet.hasMoreElements()) {
272:                    Requirement pReq = (Requirement) itReqProjet.nextElement();
273:                    if (pReq instanceof  ReqLeaf) {
274:
275:                        Iterator itReqLeqfXML = doc
276:                                .selectNodes("//Requirement").iterator();
277:                        boolean appartient = false;
278:                        Element reqElem = null;
279:                        while (itReqLeqfXML.hasNext() && !appartient) {
280:                            reqElem = (Element) itReqLeqfXML.next();
281:                            String id = reqElem.attributeValue("id_req");
282:                            id = id.substring(4, id.length());
283:                            Requirement pTmpReq = (Requirement) docReqById
284:                                    .get(new Integer(id));
285:                            if (pTmpReq.getLongName()
286:                                    .equals(pReq.getLongName())) {
287:                                appartient = true;
288:                            }
289:                        }
290:                        if (!appartient) {
291:                            try {
292:                                pReq.deleteInDBAndModel();
293:                                projectReqByName.remove(pReq.getLongName());
294:                                projectReqById.remove(new Integer(pReq
295:                                        .getIdBdd()));
296:                            } catch (Exception e) {
297:                                Tools.ihmExceptionView(e);
298:                            }
299:                        }
300:                    } else if (pReq.getIdBdd() > 0) {
301:                        Iterator itReqFamXML = doc.selectNodes(
302:                                "//RequirementFamily").iterator();
303:                        boolean appartient = false;
304:                        Element reqElem = null;
305:                        while (itReqFamXML.hasNext() && !appartient) {
306:                            reqElem = (Element) itReqFamXML.next();
307:                            String id = reqElem.attributeValue("id_req");
308:                            id = id.substring(4, id.length());
309:                            Requirement pTmpReq = (Requirement) docReqById
310:                                    .get(new Integer(id));
311:                            if (pTmpReq.getLongName()
312:                                    .equals(pReq.getLongName())) {
313:                                appartient = true;
314:                            }
315:                        }
316:                        if (!appartient) {
317:                            try {
318:                                Vector reqLeafs = ((ReqFamily) pReq)
319:                                        .getAllLeaf();
320:                                if (reqLeafs.size() == 0) {
321:                                    pReq.deleteInDBAndModel();
322:                                    projectReqByName.remove(pReq.getLongName());
323:                                    projectReqById.remove(new Integer(pReq
324:                                            .getIdBdd()));
325:                                } else {
326:                                    for (int i = 0; i < reqLeafs.size(); i++) {
327:                                        Requirement pTmpReq = (Requirement) reqLeafs
328:                                                .elementAt(i);
329:                                        projectReqByName.remove(pTmpReq
330:                                                .getLongName());
331:                                    }
332:                                }
333:                            } catch (Exception e) {
334:                                Tools.ihmExceptionView(e);
335:                            }
336:                        }
337:                    }
338:                }
339:            }
340:
341:            /**
342:             * Mise à jour des couverture d'exigence avec le doc XML
343:             * Ajout des nouvelle couverture et suppression des couvertures qui ne sont pas dans le XML si supprElement = true
344:             * @param testElem
345:             * @param test
346:             * @param supprElement
347:             * @throws Exception
348:             */
349:            public void updateReqLink(Element testElem, Test test,
350:                    boolean supprElement) throws Exception {
351:                Iterator itReqLinkXML = testElem.selectNodes(
352:                        "LinkRequirement/RequirementRef").iterator();
353:                try {
354:                    Vector listReqWrapper = Requirement
355:                            .getReqWrapperCoveredByTest(test.getIdBdd());
356:                    int size = listReqWrapper.size();
357:                    while (itReqLinkXML.hasNext()) {
358:                        Element linkElem = (Element) itReqLinkXML.next();
359:                        String nomReq = linkElem.elementText("Nom");
360:                        String id = linkElem.attributeValue("ref");
361:                        id = id.substring(4, id.length());
362:                        Requirement pTmpReq = (Requirement) docReqById
363:                                .get(new Integer(id));
364:                        /*Util.log ("[updateReqLink] id = " + id);
365:                        Util.log ("[updateReqLink] pTmpReq = " + pTmpReq);
366:                        Util.log ("[updateReqLink] nomReq = " + nomReq);
367:                        Util.log ("[updateReqLink] test = " + test.getNameFromModel() + ", suite : " + test.getTestListFromModel().getNameFromModel()
368:                        		 + ", famille : " + test.getTestListFromModel().getFamilyFromModel().getNameFromModel());*/
369:                        boolean doLink = true;
370:                        if (pTmpReq == null) {
371:                            doLink = false;
372:                            Util
373:                                    .log("[ImportXMLReq->updateReqLink] requirement linked not found in XML");
374:                        }
375:                        Requirement pReq = null;
376:                        if (doLink) {
377:                            pReq = (Requirement) projectReqByName.get(pTmpReq
378:                                    .getLongName());
379:                        }
380:                        if (doLink && pReq == null) {
381:                            Tools.ihmExceptionView(new Exception(
382:                                    "[updateReqLink] Requirment " + nomReq
383:                                            + " not found"));
384:                            doLink = false;
385:                        }
386:                        if (doLink && pReq instanceof  ReqFamily) {
387:                            Tools
388:                                    .ihmExceptionView(new Exception(
389:                                            "[updateReqLink] Requirment "
390:                                                    + nomReq
391:                                                    + " is a family and can't be linked to the test "
392:                                                    + test.getNameFromModel()));
393:                            doLink = false;
394:                        }
395:                        if (doLink) {
396:                            boolean couvre = false;
397:                            int i = 0;
398:                            while (i < size && !couvre) {
399:                                ReqWrapper pReqWrapper = (ReqWrapper) listReqWrapper
400:                                        .elementAt(i);
401:                                Requirement pTmpReq2 = (Requirement) projectReqById
402:                                        .get(new Integer(pReqWrapper.getIdBDD()));
403:                                if (pTmpReq2.getLongName().equals(
404:                                        pTmpReq.getLongName())) {
405:                                    couvre = true;
406:                                }
407:                                i++;
408:                            }
409:
410:                            if (!couvre) {
411:                                try {
412:                                    pReq
413:                                            .addTestCoverInDB(test.getIdBdd(),
414:                                                    true);
415:                                } catch (Exception e1) {
416:                                    Tools.ihmExceptionView(e1);
417:                                }
418:                            }
419:                        }
420:                    }
421:                    if (supprElement) {
422:                        removeReqLink(testElem, test);
423:                    }
424:                } catch (Exception e) {
425:                    Tools.ihmExceptionView(e);
426:                }
427:            }
428:
429:            /**
430:             * Ajout les Requirements du XML dans le projet
431:             * (Ne fait pas de test pour savoir si requirement est déja présent)
432:             * @param reqElem
433:             * @param ReqFamily la famille d'exigence ou ajouter le requirement
434:             * Si null, recherche de la famille
435:             * @throws Exception
436:             */
437:            private void ajoutRequirement(Element reqElem, ReqFamily pReqParent)
438:                    throws Exception {
439:                String nomReq = reqElem.elementText("Nom");
440:                int priority = -1;
441:                String version = null;
442:                int cat = -1;
443:                int comp = -1;
444:                int state = -1;
445:                String origine = null;
446:                String verifway = null;
447:                String reference = null;
448:
449:                try {
450:                    priority = (new Integer(reqElem.attributeValue("priority")))
451:                            .intValue();
452:                    version = reqElem.attributeValue("version");
453:                    cat = (new Integer(reqElem.attributeValue("category")))
454:                            .intValue();
455:                    comp = (new Integer(reqElem.attributeValue("complexity")))
456:                            .intValue();
457:                    state = (new Integer(reqElem.attributeValue("state")))
458:                            .intValue();
459:                    origine = reqElem.attributeValue("origine");
460:                    verifway = reqElem.attributeValue("verifway");
461:                    reference = reqElem.attributeValue("reference");
462:                } catch (Exception e) {
463:                    //XML from old plugin
464:                }
465:
466:                String desc = (reqElem.elementText("Description") == null) ? ""
467:                        : reqElem.elementText("Description");
468:                if (reqElem.element("Description") != null
469:                        && reqElem.element("Description").attribute("isHTML") != null
470:                        && reqElem.element("Description").attributeValue(
471:                                "isHTML").equals("true")) {
472:                    desc = giveHTMLDescription(reqElem);
473:                } else {
474:                    desc = desc.replaceAll("\\\\n", "<br>");
475:                    desc = "<html><head></head><body>" + desc
476:                            + "</body></html>";
477:                }
478:                String strId_reqParent = reqElem
479:                        .attributeValue("id_req_parent");
480:                strId_reqParent = strId_reqParent.substring(4, strId_reqParent
481:                        .length()); //remove Req_
482:                Integer id_reqParent = new Integer(strId_reqParent);
483:
484:                //ReqFamily pReqParent;
485:                if (pReqParent == null) {
486:                    if (id_reqParent.equals(new Integer(0))) {
487:                        pReqParent = (ReqFamily) reqRoot;
488:                    } else {
489:                        pReqParent = (ReqFamily) docReqById.get(id_reqParent);
490:                        Requirement pTempReq = (Requirement) projectReqByName
491:                                .get(pReqParent.getLongName());
492:
493:                        if (pTempReq != null && pTempReq instanceof  ReqFamily) {
494:                            pReqParent = (ReqFamily) pTempReq;
495:                        } else {
496:                            pReqParent = (ReqFamily) reqRoot;
497:                        }
498:                    }
499:                }
500:
501:                ReqLeaf pNewReq = new ReqLeaf(nomReq, desc, pReqParent,
502:                        priority);
503:                try {
504:                    pNewReq.addInDB();
505:                    if (cat != -1) {
506:                        pNewReq.updateCatInDBAndModel(cat);
507:                    }
508:                    if (comp != -1) {
509:                        pNewReq.updateComplexeInDBAndModel(comp);
510:                    }
511:                    if (state != -1) {
512:                        pNewReq.updateStateInDBAndModel(state);
513:                    }
514:                    if (version != null && origine != null && verifway != null
515:                            && reference != null) {
516:                        pNewReq.updateInfoInDB(version, origine, verifway,
517:                                reference);
518:                    } else {
519:                        if (version != null) {
520:                            pNewReq.updateVersionInDBAndModel(version);
521:                        }
522:                        if (origine != null) {
523:                            pNewReq.updateOrigineInDBAndModel(origine);
524:                        }
525:                        if (verifway != null) {
526:                            pNewReq.updateVerifInDBAndModel(verifway);
527:                        }
528:                        if (reference != null) {
529:                            pNewReq.updateReferenceInDBAndModel(reference);
530:                        }
531:                    }
532:                    pReqParent.addRequirement(pNewReq);
533:                    projectReqByName.put(pNewReq.getLongName(), pNewReq);
534:                    projectReqById
535:                            .put(new Integer(pNewReq.getIdBdd()), pNewReq);
536:                    pImport.updateElementAttachement(reqElem, pNewReq, true);
537:                } catch (Exception e) {
538:                    Tools.ihmExceptionView(e);
539:                }
540:            }
541:
542:            /**
543:             * Ajoute l'exigence famille au repository (pas de test si déja présente)
544:             * @param reqElem
545:             * @return
546:             * @throws Exception
547:             */
548:            private ReqFamily ajoutReqFamily(Element reqElem) throws Exception {
549:                if (reqElem == null) {
550:                    return (ReqFamily) reqRoot;
551:                }
552:                String nomReq = reqElem.elementText("Nom");
553:                String id = reqElem.attributeValue("id_req");
554:                id = id.substring(4, id.length());
555:                Requirement pTmpReq = (Requirement) docReqById.get(new Integer(
556:                        id));
557:                pTmpReq = (Requirement) projectReqByName.get(pTmpReq
558:                        .getLongName());
559:                if (pTmpReq != null && pTmpReq instanceof  ReqFamily) {
560:                    return (ReqFamily) pTmpReq;
561:                }
562:
563:                String strId_reqParent = reqElem
564:                        .attributeValue("id_req_parent");
565:                strId_reqParent = strId_reqParent.substring(4, strId_reqParent
566:                        .length()); //remove Req_
567:                Integer id_reqParent = new Integer(strId_reqParent);
568:                Element reqParentElement = (Element) docElementById
569:                        .get(id_reqParent);
570:                ReqFamily pParent = ajoutReqFamily(reqParentElement);
571:
572:                String desc = (reqElem.elementText("Description") == null) ? ""
573:                        : reqElem.elementText("Description");
574:                if (reqElem.element("Description") != null
575:                        && reqElem.element("Description").attribute("isHTML") != null
576:                        && reqElem.element("Description").attributeValue(
577:                                "isHTML").equals("true")) {
578:                    desc = giveHTMLDescription(reqElem);
579:                } else {
580:                    desc = desc.replaceAll("\\\\n", "<br>");
581:                    desc = "<html><head></head><body>" + desc
582:                            + "</body></html>";
583:                }
584:                ReqFamily pNewReqFamily = new ReqFamily(nomReq, desc, pParent);
585:
586:                try {
587:                    pNewReqFamily.addInDB();
588:                    pParent.addRequirement(pNewReqFamily);
589:                    projectReqByName.put(pNewReqFamily.getLongName(),
590:                            pNewReqFamily);
591:                    projectReqById.put(new Integer(pNewReqFamily.getIdBdd()),
592:                            pNewReqFamily);
593:                    pImport.updateElementAttachement(reqElem, pNewReqFamily,
594:                            true);
595:                } catch (Exception e) {
596:                    Tools.ihmExceptionView(e);
597:                }
598:                return pNewReqFamily;
599:            }
600:
601:            private String giveHTMLDescription(Element elem) {
602:                Element descElem = elem.element("Description");
603:                String description = "";
604:                if (descElem.hasContent()) {
605:                    description = elem.element("Description").asXML();
606:                    description = description.substring(27, description
607:                            .indexOf("</Description>"));
608:                    description = description.replaceAll("<br/>", "<br>");
609:                    description = "<html><head></head><body>" + description
610:                            + "</body></html>";
611:                }
612:                return description;
613:            }
614:
615:            /**
616:             * Mise a jour des Requirements existants et ajout des nouveaux
617:             * (Si gestion des suppression déja effectué, ne fait rien)
618:             * @param doc
619:             * @throws Exception
620:             */
621:            public void updateProjectRequirement(Document doc) throws Exception {
622:                Vector reqElementToAdd = new Vector();
623:                Vector reqFamilyToAdd = new Vector();
624:
625:                Iterator itReqLeqfXML = doc.selectNodes("//Requirement")
626:                        .iterator();
627:                while (itReqLeqfXML.hasNext()) {
628:                    Element reqElem = (Element) itReqLeqfXML.next();
629:                    //String nomReq = reqElem.elementText("Nom");
630:
631:                    int priority = -1;
632:                    String version = null;
633:                    int cat = -1;
634:                    int comp = -1;
635:                    int state = -1;
636:                    String origine = null;
637:                    String verifway = null;
638:                    String reference = null;
639:                    try {
640:                        priority = (new Integer(reqElem
641:                                .attributeValue("priority"))).intValue();
642:                        version = reqElem.attributeValue("version");
643:                        cat = (new Integer(reqElem.attributeValue("category")))
644:                                .intValue();
645:                        comp = (new Integer(reqElem
646:                                .attributeValue("complexity"))).intValue();
647:                        state = (new Integer(reqElem.attributeValue("state")))
648:                                .intValue();
649:                        origine = reqElem.attributeValue("origine");
650:                        verifway = reqElem.attributeValue("verifway");
651:                        reference = reqElem.attributeValue("reference");
652:                    } catch (Exception e) {
653:                        //XML from old plugin
654:                    }
655:                    String desc = (reqElem.elementText("Description") == null) ? ""
656:                            : reqElem.elementText("Description");
657:                    if (reqElem.element("Description") != null
658:                            && reqElem.element("Description").attribute(
659:                                    "isHTML") != null
660:                            && reqElem.element("Description").attributeValue(
661:                                    "isHTML").equals("true")) {
662:                        desc = giveHTMLDescription(reqElem);
663:                    } else {
664:                        desc = desc.replaceAll("\\\\n", "<br>");
665:                        desc = "<html><head></head><body>" + desc
666:                                + "</body></html>";
667:                    }
668:                    String id_reqDoc = reqElem.attributeValue("id_req");
669:                    id_reqDoc = id_reqDoc.substring(4, id_reqDoc.length()); //remove Req_
670:
671:                    Requirement docXMLReq = (Requirement) docReqById
672:                            .get(new Integer(id_reqDoc));
673:                    Requirement pReq = null;
674:                    if (docXMLReq != null) {
675:                        pReq = (Requirement) projectReqByName.get(docXMLReq
676:                                .getLongName());
677:                    }
678:
679:                    if (pReq != null) {
680:                        //Existe --> Update
681:                        if (reqElem != null) {
682:                            pImport.updateElementAttachement(reqElem, pReq,
683:                                    false);
684:                            if (desc != null) {
685:                                pReq.updateDescriptionInDBAndModel(desc);
686:                            }
687:                            if (pReq instanceof  ReqLeaf) {
688:                                if (version != null && origine != null
689:                                        && verifway != null
690:                                        && reference != null) {
691:                                    ((ReqLeaf) pReq).updateInfoInDB(version,
692:                                            origine, verifway, reference);
693:                                } else {
694:                                    if (version != null) {
695:                                        ((ReqLeaf) pReq)
696:                                                .updateVersionInDBAndModel(version);
697:                                    }
698:                                    if (origine != null) {
699:                                        ((ReqLeaf) pReq)
700:                                                .updateOrigineInDBAndModel(origine);
701:                                    }
702:                                    if (verifway != null) {
703:                                        ((ReqLeaf) pReq)
704:                                                .updateVerifInDBAndModel(verifway);
705:                                    }
706:                                    if (reference != null) {
707:                                        ((ReqLeaf) pReq)
708:                                                .updateReferenceInDBAndModel(reference);
709:                                    }
710:                                }
711:                                if (priority != -1) {
712:                                    ((ReqLeaf) pReq)
713:                                            .updatePriorityInDBAndModel(priority);
714:                                }
715:                                if (cat != -1) {
716:                                    ((ReqLeaf) pReq).updateCatInDBAndModel(cat);
717:                                }
718:                                if (comp != -1) {
719:                                    ((ReqLeaf) pReq)
720:                                            .updateComplexeInDBAndModel(comp);
721:                                }
722:                                if (state != -1) {
723:                                    ((ReqLeaf) pReq)
724:                                            .updateStateInDBAndModel(state);
725:                                }
726:                            }
727:                        }
728:                    } else {
729:                        //Not Existe --> Ajout
730:                        reqElementToAdd.add(reqElem);
731:
732:                    }
733:                }
734:
735:                Iterator itReqFamilyfXML = doc.selectNodes(
736:                        "//RequirementFamily").iterator();
737:                while (itReqFamilyfXML.hasNext()) {
738:                    Element reqElem = (Element) itReqFamilyfXML.next();
739:                    //String nomReq = reqElem.elementText("Nom");
740:                    String desc = (reqElem.elementText("Description") == null) ? ""
741:                            : reqElem.elementText("Description");
742:                    if (reqElem.element("Description") != null
743:                            && reqElem.element("Description").attribute(
744:                                    "isHTML") != null
745:                            && reqElem.element("Description").attributeValue(
746:                                    "isHTML").equals("true")) {
747:                        desc = giveHTMLDescription(reqElem);
748:                    } else {
749:                        desc = desc.replaceAll("\\\\n", "<br>");
750:                        desc = "<html><head></head><body>" + desc
751:                                + "</body></html>";
752:                    }
753:                    String id_reqDoc = reqElem.attributeValue("id_req");
754:                    id_reqDoc = id_reqDoc.substring(4, id_reqDoc.length()); //remove Req_
755:                    Requirement docXMLReq = (Requirement) docReqById
756:                            .get(new Integer(id_reqDoc));
757:                    Requirement pReq = null;
758:                    if (docXMLReq != null) {
759:                        pReq = (Requirement) projectReqByName.get(docXMLReq
760:                                .getLongName());
761:                    }
762:
763:                    if (pReq != null) {
764:                        //Existe --> Update
765:                        if (reqElem != null) {
766:                            pImport.updateElementAttachement(reqElem, pReq,
767:                                    false);
768:                            if (desc != null) {
769:                                pReq.updateDescriptionInDBAndModel(desc);
770:                            }
771:                        }
772:                    } else {
773:                        //Not Existe --> Ajout
774:                        reqFamilyToAdd.add(reqElem);
775:                        //updateElementAttachement(reqElem, pReq, true);
776:                    }
777:                }
778:                // Ajput des nouveau requirements
779:                for (int i = 0; i < reqFamilyToAdd.size(); i++) {
780:                    Element reqElem = (Element) reqFamilyToAdd.elementAt(i);
781:                    ajoutReqFamily(reqElem);
782:                }
783:                for (int i = 0; i < reqElementToAdd.size(); i++) {
784:                    Element reqElem = (Element) reqElementToAdd.elementAt(i);
785:                    ajoutRequirement(reqElem, null);
786:                }
787:            }
788:
789:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.