Source Code Cross Referenced for ImportXML2.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » docXML » importxml » 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.docXML.importxml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * SalomeTMF is a Test Management Framework
0003:         * Copyright (C) 2005 France Telecom R&D
0004:         *
0005:         * This library is free software; you can redistribute it and/or
0006:         * modify it under the terms of the GNU Lesser General Public
0007:         * License as published by the Free Software Foundation; either
0008:         * version 2 of the License, or (at your option) any later version.
0009:         *
0010:         * This library is distributed in the hope that it will be useful,
0011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013:         * Lesser General Public License for more details.
0014:         *
0015:         * You should have received a copy of the GNU Lesser General Public
0016:         * License along with this library; if not, write to the Free Software
0017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018:         *
0019:         * @author Aurore PENAULT
0020:         *
0021:         * Contact: mikael.marche@rd.francetelecom.com
0022:         */
0023:        package salomeTMF_plug.docXML.importxml;
0024:
0025:        import java.io.File;
0026:        import java.io.FileInputStream;
0027:        import java.io.FileNotFoundException;
0028:        import java.util.ArrayList;
0029:        import java.util.Enumeration;
0030:        import java.util.HashMap;
0031:        import java.util.Hashtable;
0032:        import java.util.Iterator;
0033:        import java.util.List;
0034:        import java.util.Vector;
0035:
0036:        import javax.swing.JDialog;
0037:        import javax.swing.JTable;
0038:
0039:        import org.dom4j.Document;
0040:        import org.dom4j.DocumentHelper;
0041:        import org.dom4j.Element;
0042:        import org.dom4j.Node;
0043:        import org.java.plugin.Extension;
0044:        import org.objectweb.salome_tmf.api.Api;
0045:        import org.objectweb.salome_tmf.api.ApiConstants;
0046:        import org.objectweb.salome_tmf.api.Util;
0047:        import org.objectweb.salome_tmf.data.Action;
0048:        import org.objectweb.salome_tmf.data.AdminVTData;
0049:        import org.objectweb.salome_tmf.data.Attachment;
0050:        import org.objectweb.salome_tmf.data.AutomaticTest;
0051:        import org.objectweb.salome_tmf.data.Campaign;
0052:        import org.objectweb.salome_tmf.data.DataSet;
0053:        import org.objectweb.salome_tmf.data.Environment;
0054:        import org.objectweb.salome_tmf.data.Execution;
0055:        import org.objectweb.salome_tmf.data.ExecutionResult;
0056:        import org.objectweb.salome_tmf.data.ExecutionTestResult;
0057:        import org.objectweb.salome_tmf.data.Family;
0058:        import org.objectweb.salome_tmf.data.FileAttachment;
0059:        import org.objectweb.salome_tmf.data.ManualExecutionResult;
0060:        import org.objectweb.salome_tmf.data.ManualTest;
0061:        import org.objectweb.salome_tmf.data.Parameter;
0062:        import org.objectweb.salome_tmf.data.Project;
0063:        import org.objectweb.salome_tmf.data.Script;
0064:        import org.objectweb.salome_tmf.data.Test;
0065:        import org.objectweb.salome_tmf.data.TestList;
0066:        import org.objectweb.salome_tmf.data.UrlAttachment;
0067:        import org.objectweb.salome_tmf.data.User;
0068:        import org.objectweb.salome_tmf.data.WithAttachment;
0069:        import org.objectweb.salome_tmf.ihm.IHMConstants;
0070:        import org.objectweb.salome_tmf.ihm.admin.Administration;
0071:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
0072:        import org.objectweb.salome_tmf.ihm.models.MyTableModel;
0073:        import org.objectweb.salome_tmf.ihm.tools.Tools;
0074:        import org.objectweb.salome_tmf.plugins.IPlugObject;
0075:        import org.objectweb.salome_tmf.plugins.JPFManager;
0076:        import org.objectweb.salome_tmf.plugins.UICompCst;
0077:        import org.objectweb.salome_tmf.plugins.core.TestDriver;
0078:        import org.objectweb.salome_tmf.plugins.core.XMLLoaderPlugin;
0079:        import org.objectweb.salome_tmf.plugins.core.XMLPrinterPlugin;
0080:
0081:        import salomeTMF_plug.docXML.common.CreateProjectDialog;
0082:        import salomeTMF_plug.docXML.languages.Language;
0083:
0084:        public class ImportXML2 implements  ApiConstants, IHMConstants,
0085:                XMLLoaderPlugin {
0086:
0087:            private ArrayList<Family> familySelectionList;
0088:            private ArrayList<TestList> suiteSelectionList;
0089:            private ArrayList<Test> testSelectionList;
0090:
0091:            private IPlugObject pIPlugObject;
0092:            private AdminVTData pAdminVTData;
0093:            private Project project;
0094:            private Vector<XMLPrinterPlugin> listXMLPlugin = new Vector<XMLPrinterPlugin>();
0095:
0096:            private Document doc;
0097:            private String dirXml;
0098:
0099:            private ImportDialog2 idialog;
0100:            private CreateProjectDialog cdialog;
0101:
0102:            private boolean cancelled = false;
0103:            private boolean initSelection;
0104:            private boolean importCampaign = false;
0105:            private boolean attachmentException = false;
0106:            private boolean newProject = false;
0107:            private Vector<AutomaticTest> automatedTest2Update = new Vector<AutomaticTest>();
0108:            private Vector<Test> savedTests = new Vector<Test>();
0109:
0110:            public ImportXML2(JDialog dialog, Document document,
0111:                    ArrayList<Family> familySelectionList,
0112:                    ArrayList<TestList> suiteSelectionList,
0113:                    ArrayList<Test> testSelectionList, AdminVTData adminVTData,
0114:                    IPlugObject plugObject) {
0115:                super ();
0116:
0117:                this .familySelectionList = familySelectionList;
0118:                this .suiteSelectionList = suiteSelectionList;
0119:                this .testSelectionList = testSelectionList;
0120:                this .pIPlugObject = plugObject;
0121:                this .doc = document;
0122:                this .pAdminVTData = adminVTData;
0123:
0124:                Vector<Extension> listExtXMLPlugin = pIPlugObject
0125:                        .getXMLPrintersExtension();
0126:                for (Extension pXMLExt : listExtXMLPlugin) {
0127:                    JPFManager pJPFManager = pIPlugObject.getPluginManager();
0128:                    try {
0129:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) pJPFManager
0130:                                .activateExtension(pXMLExt);
0131:                        if (!listXMLPlugin.contains(pXMLPrinterPlugin)) {
0132:                            listXMLPlugin.add(pXMLPrinterPlugin);
0133:                        }
0134:                    } catch (Exception e) {
0135:                    }
0136:                }
0137:
0138:                if (dialog instanceof  ImportDialog2) {
0139:                    idialog = (ImportDialog2) dialog;
0140:                } else {
0141:                    cdialog = (CreateProjectDialog) dialog;
0142:                }
0143:            }
0144:
0145:            /**
0146:             * Launch the import process
0147:             * @throws Exception 
0148:             */
0149:            public void importInProject() throws Exception {
0150:                project = DataModel.getCurrentProject(); //Add for V2
0151:                DataModel.reloadFromBase(false);
0152:
0153:                if (idialog.isSupprElement() && !cancelled) {
0154:                    projectDeletions();
0155:                    testsDeletions();
0156:                    campaignsDeletions();
0157:
0158:                    /***** Plugin manage XML delete for Project *****/
0159:                    int size = listXMLPlugin.size();
0160:                    for (int i = 0; i < size; i++) {
0161:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0162:                                .elementAt(i);
0163:                        pXMLPrinterPlugin.manageDelete(doc, this );
0164:                    }
0165:                }
0166:
0167:                coreImport();
0168:
0169:                DataModel.reloadFromBase(true);
0170:
0171:                /***** Plugin manage XML refresh *****/
0172:                int size = listXMLPlugin.size();
0173:                for (int i = 0; i < size; i++) {
0174:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0175:                            .elementAt(i);
0176:                    pXMLPrinterPlugin.refreshNewData();
0177:                }
0178:                /***** (END) Plugin manage XML refresh *****/
0179:
0180:            }
0181:
0182:            /**
0183:             * Launch the import process from the createDialog in Administration of Salome
0184:             * @throws Exception
0185:             */
0186:            public void importInNewProject() throws Exception {
0187:                newProject = true;
0188:                ArrayList<Object> data = new ArrayList<Object>();
0189:                project = cdialog.getNewProject();
0190:                if (project != null && !cancelled) {
0191:                    if (Api.isConnected()) {
0192:                        try {
0193:                            project.addInDB();
0194:                            project.setUserInModel(project
0195:                                    .getAdministratorFromModel());
0196:
0197:                            data.add(Tools.createAppletImageIcon(
0198:                                    PATH_TO_PROJECT_ICON, ""));
0199:                            data.add(project.getNameFromModel().trim());
0200:                            data.add(project.getAdministratorFromModel()
0201:                                    .getLoginFromModel());
0202:                            data.add(project.getCreationDateFromModel()
0203:                                    .toString());
0204:                            data.add(project.getDescriptionFromModel());
0205:                            JTable projectTable = (JTable) Administration
0206:                                    .getUIComponent(UICompCst.ADMIN_PROJECT_MANAGEMENT_TABLE);
0207:                            ((MyTableModel) projectTable.getModel())
0208:                                    .addRow(data);
0209:                            project.setUserInModel(project
0210:                                    .getAdministratorFromModel());
0211:                            pAdminVTData.addProjectInModel(project);
0212:                            pAdminVTData.addAdminToProjectInModel(project
0213:                                    .getAdministratorFromModel(), project);
0214:                            projectTable.getColumnModel().getColumn(0)
0215:                                    .setMaxWidth(18);
0216:                        } catch (Exception exception) {
0217:                            cdialog
0218:                                    .setErrorMessage(cdialog.getErrorMessage()
0219:                                            + Language
0220:                                                    .getInstance()
0221:                                                    .getText(
0222:                                                            "Problème_lors_de_la_création_du_nouveau_projet"));
0223:                            cdialog.showErrorMessage();
0224:                            setAnnule(true);
0225:                        }
0226:                    }
0227:                }
0228:
0229:                if (!cancelled) {
0230:                    coreImport();
0231:                }
0232:            }
0233:
0234:            /**
0235:             * Delete attachments of project which are in database and not in XML document.
0236:             */
0237:            private void projectDeletions() throws Exception {
0238:                Element projectElem = (Element) doc
0239:                        .selectSingleNode("//ProjetVT");
0240:                attachmentDeletions(projectElem, project);
0241:            }
0242:
0243:            /**
0244:             * Delete elements of test plan which are in database and not 
0245:             * in XML document
0246:             * @throws Exception 
0247:             */
0248:            private void testsDeletions() throws Exception {
0249:                //Deletion of project parameters
0250:                parameterDeletion();
0251:                if (cancelled) {
0252:                    throw new Exception("[ImportAlgo->suppressionParameter]");
0253:                }
0254:
0255:                //Deletion of environments
0256:                environmentDeletion();
0257:                if (cancelled) {
0258:                    throw new Exception(
0259:                            "[ImportAlgo->suppressionEnvironnement]");
0260:                }
0261:
0262:                //deletion of families
0263:                familyDeletion();
0264:                if (cancelled) {
0265:                    throw new Exception("[ImportAlgo->suppressionFamily]");
0266:                }
0267:            }
0268:
0269:            /**
0270:             * Delete elements of campaigns which are in database
0271:             * and not in XML document
0272:             * @throws Exception
0273:             */
0274:            private void campaignsDeletions() throws Exception {
0275:                ArrayList<Campaign> campList = project
0276:                        .getCampaignListFromModel();
0277:                ArrayList<Campaign> campToRemove = new ArrayList<Campaign>();
0278:                List<Element> campListXML = doc.selectNodes("//CampagneTest");
0279:                Element campElem = null;
0280:                Iterator<Campaign> itCamp = campList.iterator();
0281:                while (itCamp.hasNext() && !cancelled) {
0282:                    Campaign camp = (Campaign) itCamp.next();
0283:                    boolean belong = false;
0284:                    Iterator<Element> itCampXML = campListXML.iterator();
0285:                    while (itCampXML.hasNext() && !belong) {
0286:                        campElem = itCampXML.next();
0287:                        if (campElem.elementText("Nom").equals(
0288:                                camp.getNameFromModel())) {
0289:                            belong = true;
0290:                        }
0291:                    }
0292:                    if (!belong) {
0293:                        campToRemove.add(camp);
0294:                    } else {
0295:                        //suppression des jeux de données
0296:                        dataSetDeletion(campElem, camp);
0297:
0298:                        //suppression des attachements des campagnes
0299:                        attachmentDeletions(campElem, camp);
0300:
0301:                        //suppression Tests
0302:                        testInCampDeletion(campElem, camp);
0303:
0304:                        //suppression Exécutions -> suppression résultats d'exécution
0305:                        execInCampDeletion(campElem, camp);
0306:                    }
0307:                }
0308:                Iterator<Campaign> itCampRm = campToRemove.iterator();
0309:                while (itCampRm.hasNext() && !cancelled) {
0310:                    Campaign campRm = itCampRm.next();
0311:                    try {
0312:                        project.deleteCampaignInDBAndModel(campRm);
0313:                    } catch (Exception e) {
0314:                        Tools.ihmExceptionView(e);
0315:                        throw e;
0316:                    }
0317:                }
0318:            }
0319:
0320:            /**
0321:             * Delete project parameters are in project database and not in XML document.
0322:             * @return true if there was an error during deletion
0323:             */
0324:            private void parameterDeletion() throws Exception {
0325:                Hashtable<String, Parameter> paramSet = project
0326:                        .getParameterSetFromModel();
0327:                Enumeration<Parameter> itParamProjet = paramSet.elements();
0328:
0329:                while (itParamProjet.hasMoreElements() && !cancelled) {
0330:                    Parameter param = itParamProjet.nextElement();
0331:                    List<Element> listParamXML = doc.selectNodes("//Param");
0332:                    boolean belong = false;
0333:                    for (Element paramElem : listParamXML) {
0334:                        if (paramElem.elementText("Nom").equals(
0335:                                param.getNameFromModel())) {
0336:                            belong = true;
0337:                        }
0338:                    }
0339:                    if (!belong) {
0340:                        try {
0341:                            project.deleteParamInDBndModel(param);
0342:                        } catch (Exception e) {
0343:                            Tools.ihmExceptionView(e);
0344:                            cancelled = true;
0345:                        }
0346:                    }
0347:                }
0348:            }
0349:
0350:            /**
0351:             * Delete project environment and associated data are in project database
0352:             * and not in XML document
0353:             * @return true if there was an error during deletion
0354:             */
0355:            private void environmentDeletion() throws Exception {
0356:                //environments deletion
0357:                List<Element> envList = doc.selectNodes("//Environnement");
0358:                ArrayList<Environment> envInBDD = project
0359:                        .getEnvironmentListFromModel();
0360:                Iterator<Environment> itEnv = envInBDD.iterator();
0361:
0362:                while (itEnv.hasNext() && !cancelled) {
0363:                    Environment env = itEnv.next();
0364:                    Iterator<Element> itEnvXML = envList.iterator();
0365:                    Element envElem = null;
0366:                    boolean belong = false;
0367:                    while (itEnvXML.hasNext() && !belong) {
0368:                        envElem = (Element) itEnvXML.next();
0369:                        if (envElem.elementText("Nom").equals(
0370:                                env.getNameFromModel())) {
0371:                            belong = true;
0372:                        }
0373:                    }
0374:                    if (!belong) {
0375:                        try {
0376:                            project.deleteEnvironmentInDBandModel(env);
0377:                        } catch (Exception e) {
0378:                            Tools.ihmExceptionView(e);
0379:                            cancelled = true;
0380:                        }
0381:                    } else {
0382:                        //delete parameters with value in environment
0383:                        List<Element> paramEnvListXML = envElem
0384:                                .selectNodes("ValeurParams/ValeurParam");
0385:                        Hashtable<Parameter, String> paramEnvList = env
0386:                                .getParametersHashTableFromModel();
0387:                        Enumeration<Parameter> enumEnv = paramEnvList.keys();
0388:                        while (enumEnv.hasMoreElements()) {
0389:                            belong = false;
0390:                            Parameter paramEnv = enumEnv.nextElement();
0391:                            Iterator<Element> itParamEnvXML = paramEnvListXML
0392:                                    .iterator();
0393:                            while (itParamEnvXML.hasNext()) {
0394:                                Element paramElem = (Element) itParamEnvXML
0395:                                        .next();
0396:                                String nomParam = paramElem.elementText("Nom");
0397:                                if (paramEnv.getNameFromModel()
0398:                                        .equals(nomParam)) {
0399:                                    belong = true;
0400:                                }
0401:                            }
0402:                            if (!belong) {
0403:                                try {
0404:                                    env.deleteDefParamInDBAndModel(paramEnv);
0405:                                } catch (Exception e) {
0406:                                    Tools.ihmExceptionView(e);
0407:                                }
0408:                            }
0409:                        }
0410:                        //suppression du script de l'environnement
0411:                        Script script = env.getInitScriptFromModel();
0412:                        if (script != null) {
0413:                            if (envElem.element("Script") == null) {
0414:                                try {
0415:                                    env.deleteScriptInDBAndModel();
0416:                                } catch (Exception e) {
0417:                                    Tools.ihmExceptionView(e);
0418:                                }
0419:                            }
0420:                        }
0421:                        //suppression des attachements de l'environnement
0422:                        attachmentDeletions(envElem, env);
0423:                    }
0424:                }
0425:            }
0426:
0427:            /**
0428:             * Delete families and associated elements are in project database 
0429:             * and not in XML document.
0430:             * @return
0431:             */
0432:            private void familyDeletion() throws Exception {
0433:                //suppression des familles
0434:                ArrayList<Family> familleList = project
0435:                        .getFamilyListFromModel();
0436:                ArrayList<Family> familyToRemove = new ArrayList<Family>();
0437:                List<Element> familleListXML = doc.selectNodes("//Famille");
0438:                Element famElem = null;
0439:                Iterator<Family> itFamily = familleList.iterator();
0440:                while (itFamily.hasNext() && !cancelled) {
0441:                    Family family = itFamily.next();
0442:                    boolean belong = false;
0443:                    Iterator<Element> itFamXML = familleListXML.iterator();
0444:                    while (itFamXML.hasNext() && !belong) {
0445:                        famElem = (Element) itFamXML.next();
0446:                        if (famElem.elementText("Nom").equals(
0447:                                family.getNameFromModel())) {
0448:                            if (isInitSelection()) {
0449:                                boolean selectFamily = false;
0450:                                for (Family selectedFamily : familySelectionList) {
0451:                                    if (selectedFamily.getNameFromModel()
0452:                                            .equals(family.getNameFromModel())) {
0453:                                        selectFamily = true;
0454:                                    }
0455:                                }
0456:                                if (selectFamily) {
0457:                                    belong = true;
0458:                                }
0459:                            } else {
0460:                                belong = true;
0461:                            }
0462:                        }
0463:                    }
0464:                    if (!belong) {
0465:                        familyToRemove.add(family);
0466:                    } else {
0467:                        //
0468:                        attachmentDeletions(famElem, family);
0469:                        //la famille appartient au document XML, gestion des suites
0470:                        suiteDeletion(famElem, family);
0471:                    }
0472:                }
0473:                Iterator<Family> itFamRm = familyToRemove.iterator();
0474:                while (itFamRm.hasNext() && !cancelled) {
0475:                    Family family = itFamRm.next();
0476:                    try {
0477:                        project.deleteFamilyInDBAndModel(family);
0478:                    } catch (Exception e) {
0479:                        Tools.ihmExceptionView(e);
0480:                        cancelled = true;
0481:                    }
0482:                }
0483:            }
0484:
0485:            /**
0486:             * Delete suites and associated elements are in project database 
0487:             * and not in XML document.
0488:             * @return
0489:             */
0490:            private void suiteDeletion(Element famElem, Family pFamily)
0491:                    throws Exception {
0492:                //gestion des suites
0493:                boolean belong = false;
0494:                ArrayList<TestList> suiteList = pFamily.getSuiteListFromModel();
0495:                ArrayList<TestList> suiteToRemove = new ArrayList<TestList>();
0496:                Element suiteElem = null;
0497:                List<Element> suiteListXML = famElem
0498:                        .selectNodes("SuiteTests/SuiteTest");
0499:                Iterator<TestList> itSuite = suiteList.iterator();
0500:                while (itSuite.hasNext() && !cancelled) {
0501:                    TestList suite = itSuite.next();
0502:                    belong = false;
0503:                    Iterator<Element> itSuiteXML = suiteListXML.iterator();
0504:                    while (itSuiteXML.hasNext() && !belong) {
0505:                        suiteElem = itSuiteXML.next();
0506:                        if (suiteElem.elementText("Nom").equals(
0507:                                suite.getNameFromModel())) {
0508:                            if (isInitSelection()) {
0509:                                Iterator<TestList> itSuiteSelect = suiteSelectionList
0510:                                        .iterator();
0511:                                boolean selectionneSuite = false;
0512:                                while (itSuiteSelect.hasNext()) {
0513:                                    TestList suiteSelect = (TestList) itSuiteSelect
0514:                                            .next();
0515:                                    if (suiteSelect.getNameFromModel().equals(
0516:                                            suite.getNameFromModel())
0517:                                            && suiteSelect
0518:                                                    .getFamilyFromModel()
0519:                                                    .getNameFromModel()
0520:                                                    .equals(
0521:                                                            suite
0522:                                                                    .getFamilyFromModel()
0523:                                                                    .getNameFromModel())) {
0524:                                        selectionneSuite = true;
0525:                                    }
0526:                                }
0527:                                if (selectionneSuite) {
0528:                                    belong = true;
0529:                                }
0530:                            } else {
0531:                                belong = true;
0532:                            }
0533:                        }
0534:                    }
0535:                    if (!belong) {
0536:                        suiteToRemove.add(suite);
0537:                    } else {
0538:                        //gestion de la suppression des attachements de la suite
0539:                        attachmentDeletions(suiteElem, suite);
0540:                        //on gère la suppression des tests appartenant à la suite
0541:                        testDeletion(suiteElem, suite);
0542:                    }
0543:                }
0544:                Iterator<TestList> itSuiteRm = suiteToRemove.iterator();
0545:                while (itSuiteRm.hasNext() && !cancelled) {
0546:                    TestList suite = (TestList) itSuiteRm.next();
0547:                    try {
0548:                        project.deleteTestListInDBandModel(suite);
0549:                    } catch (Exception e) {
0550:                        Tools.ihmExceptionView(e);
0551:                        cancelled = true;
0552:                    }
0553:                }
0554:            }
0555:
0556:            /**
0557:             * Delete tests and associated elements are in project database 
0558:             * and not in XML document.
0559:             * @return
0560:             */
0561:            private void testDeletion(Element suiteElem, TestList suite)
0562:                    throws Exception {
0563:                boolean belong = false;
0564:                ArrayList<Test> testList = suite.getTestListFromModel();
0565:                ArrayList<Test> testToRm = new ArrayList<Test>();
0566:                Iterator<Test> itTest = testList.iterator();
0567:                while (itTest.hasNext() && !cancelled) {
0568:                    Test test = itTest.next();
0569:                    belong = false;
0570:                    Element testElem = null;
0571:                    if (suiteElem != null) {
0572:                        Iterator<Element> itTestXML = suiteElem.selectNodes(
0573:                                "Tests/Test").iterator();
0574:                        while (itTestXML.hasNext() && !belong) {
0575:                            testElem = itTestXML.next();
0576:                            if (testElem.elementText("Nom").equals(
0577:                                    test.getNameFromModel())) {
0578:                                if (isInitSelection()) {
0579:                                    Iterator<Test> itTestSelect = testSelectionList
0580:                                            .iterator();
0581:                                    boolean selectTest = false;
0582:                                    while (itTestSelect.hasNext()) {
0583:                                        Test testSelect = itTestSelect.next();
0584:                                        if (testSelect
0585:                                                .getNameFromModel()
0586:                                                .equals(test.getNameFromModel())
0587:                                                && testSelect
0588:                                                        .getTestListFromModel()
0589:                                                        .getNameFromModel()
0590:                                                        .equals(
0591:                                                                test
0592:                                                                        .getTestListFromModel()
0593:                                                                        .getNameFromModel())
0594:                                                && testSelect
0595:                                                        .getTestListFromModel()
0596:                                                        .getFamilyFromModel()
0597:                                                        .getNameFromModel()
0598:                                                        .equals(
0599:                                                                test
0600:                                                                        .getTestListFromModel()
0601:                                                                        .getFamilyFromModel()
0602:                                                                        .getNameFromModel())) {
0603:                                            selectTest = true;
0604:                                        }
0605:                                    }
0606:                                    if (selectTest) {
0607:                                        belong = true;
0608:                                    }
0609:                                } else {
0610:                                    belong = true;
0611:                                }
0612:                            }
0613:                        }
0614:                    }
0615:                    if (!belong) {
0616:                        testToRm.add(test);
0617:                    } else {
0618:                        //gestion des paramètres
0619:                        ArrayList<Parameter> paramTestList = test
0620:                                .getParameterListFromModel();
0621:                        List<Element> paramTestXML = testElem
0622:                                .selectNodes("ParamsT/ParamT");
0623:                        ArrayList<Parameter> paramTestToRemove = new ArrayList<Parameter>();
0624:                        Iterator<Parameter> itParamTest = paramTestList
0625:                                .iterator();
0626:                        while (itParamTest.hasNext()) {
0627:                            Parameter param = itParamTest.next();
0628:                            belong = false;
0629:                            Iterator<Element> itParamTestXML = paramTestXML
0630:                                    .iterator();
0631:                            while (itParamTestXML.hasNext()) {
0632:                                Element paramElem = itParamTestXML.next();
0633:                                String nomParam = paramElem.elementText("Nom");
0634:                                if (param.getNameFromModel().equals(nomParam)) {
0635:                                    belong = true;
0636:                                }
0637:                            }
0638:                            if (!belong) {
0639:                                paramTestToRemove.add(param);
0640:                            }
0641:                        }
0642:                        Iterator<Parameter> itParamRm = paramTestToRemove
0643:                                .iterator();
0644:                        while (itParamRm.hasNext()) {
0645:                            Parameter param = itParamRm.next();
0646:                            try {
0647:                                test.deleteUseParamInDBAndModel(param);
0648:                            } catch (Exception e) {
0649:                                Tools.ihmExceptionView(e);
0650:                            }
0651:                        }
0652:                        //gestion des attachements
0653:                        attachmentDeletions(testElem, test);
0654:
0655:                        //si test automatique gestion du script
0656:                        if (test instanceof  AutomaticTest) {
0657:                            Script script = ((AutomaticTest) test)
0658:                                    .getScriptFromModel();
0659:                            if (script != null) {
0660:                                Element scriptElem = (Element) testElem
0661:                                        .selectSingleNode("TestAuto/Script");
0662:                                if (scriptElem == null
0663:                                        || !scriptElem
0664:                                                .attributeValue("nom")
0665:                                                .equals(
0666:                                                        script
0667:                                                                .getNameFromModel())) {
0668:                                    try {
0669:                                        ((AutomaticTest) test)
0670:                                                .deleteScriptInDBAndModel();
0671:                                    } catch (Exception e) {
0672:                                        Tools.ihmExceptionView(e);
0673:                                    }
0674:                                }
0675:                            }
0676:                        } else {
0677:                            //si test manuel gestion des actions
0678:                            actionDeletion(testElem, (ManualTest) test);
0679:                        }
0680:                    }
0681:                }
0682:                Iterator<Test> itTestRm = testToRm.iterator();
0683:                while (itTestRm.hasNext() && !cancelled) {
0684:                    Test test = (Test) itTestRm.next();
0685:                    try {
0686:                        suite.deleteTestInDBAndModel(test);
0687:                    } catch (Exception e) {
0688:                        Tools.ihmExceptionView(e);
0689:                        cancelled = true;
0690:                    }
0691:                }
0692:            }
0693:
0694:            /**
0695:             * Delete actions of manual test and associated elements are in project database 
0696:             * and not in XML document.
0697:             * @param testElem concerned XML element
0698:             * @param test manual test in DB
0699:             */
0700:            private void actionDeletion(Element testElem, ManualTest test)
0701:                    throws Exception {
0702:                ArrayList<Action> actionList = test
0703:                        .getActionListFromModel(false);
0704:                List<Element> actionListXML = testElem
0705:                        .selectNodes("TestManuel/ActionTest");
0706:                ArrayList<Action> actionToRemove = new ArrayList<Action>();
0707:                boolean belong;
0708:                Iterator<Action> itAction = actionList.iterator();
0709:                while (itAction.hasNext()) {
0710:                    Action action = itAction.next();
0711:                    Element actionElem = null;
0712:                    belong = false;
0713:                    Iterator<Element> itActionXML = actionListXML.iterator();
0714:                    while (itActionXML.hasNext() && !belong) {
0715:                        actionElem = (Element) itActionXML.next();
0716:                        if (actionElem.elementText("Nom").equals(
0717:                                action.getNameFromModel())) {
0718:                            belong = true;
0719:                        }
0720:                    }
0721:                    if (!belong) {
0722:                        actionToRemove.add(action);
0723:                    } else {
0724:                        //gestion des paramètres des actions
0725:                        Hashtable<String, Parameter> actionParam = action
0726:                                .getParameterHashSetFromModel();
0727:                        Enumeration<Parameter> itParamAction = actionParam
0728:                                .elements();
0729:                        ArrayList<Parameter> paramActionToRemove = new ArrayList<Parameter>();
0730:                        while (itParamAction.hasMoreElements()) {
0731:                            Parameter param = itParamAction.nextElement();
0732:                            belong = false;
0733:                            Iterator<Element> itParamActionXML = actionElem
0734:                                    .selectNodes("ParamsT/ParamT").iterator();
0735:                            while (itParamActionXML.hasNext()) {
0736:                                Element paramElem = itParamActionXML.next();
0737:                                String nomParam = paramElem.elementText("Nom");
0738:                                if (param.getNameFromModel().equals(nomParam)) {
0739:                                    belong = true;
0740:                                }
0741:                            }
0742:                            if (!belong) {
0743:                                paramActionToRemove.add(param);
0744:                            }
0745:                        }
0746:                        Iterator<Parameter> itParamActionRm = paramActionToRemove
0747:                                .iterator();
0748:                        while (itParamActionRm.hasNext()) {
0749:                            Parameter param = itParamActionRm.next();
0750:                            try {
0751:                                action.deleteUseParamInDBAndModel(param);
0752:                            } catch (Exception e) {
0753:                                Tools.ihmExceptionView(e);
0754:                            }
0755:                        }
0756:                        //gestion des attachements des actions
0757:                        attachmentDeletions(actionElem, action);
0758:                    }
0759:
0760:                }
0761:                Iterator<Action> itActionRm = actionToRemove.iterator();
0762:                while (itActionRm.hasNext()) {
0763:                    Action actionRm = itActionRm.next();
0764:                    try {
0765:                        test.deleteActionInDBModel(actionRm);
0766:                    } catch (Exception e) {
0767:                        Tools.ihmExceptionView(e);
0768:                        cancelled = true;
0769:                    }
0770:                }
0771:            }
0772:
0773:            /**
0774:             * Delete attachments of the given element which are in database
0775:             * and not in the XML document
0776:             * @param pDocElem XML element
0777:             * @param pWithAttachment element with attachment in DB
0778:             */
0779:            private void attachmentDeletions(Element pDocElem,
0780:                    WithAttachment pWithAttachment) throws Exception {
0781:                boolean belong;
0782:                List<Node> urlAttachementList = pDocElem
0783:                        .selectNodes("Attachements/UrlAttachement");
0784:                List<Node> fileAttachementList = pDocElem
0785:                        .selectNodes("Attachements/FileAttachement");
0786:                HashMap<String, Attachment> envMap = pWithAttachment
0787:                        .getAttachmentMapFromModel();
0788:                ArrayList<Attachment> envMapToRemove = new ArrayList<Attachment>();
0789:                Iterator<Attachment> itWithAttachmentMap = envMap.values()
0790:                        .iterator();
0791:                while (itWithAttachmentMap.hasNext()) {
0792:                    belong = false;
0793:                    Attachment attach = itWithAttachmentMap.next();
0794:                    if (attach instanceof  UrlAttachment) {
0795:                        UrlAttachment pUrlAttachment = (UrlAttachment) attach;
0796:                        Iterator<Node> itWithAttachmentUrlAttachXML = urlAttachementList
0797:                                .iterator();
0798:                        while (itWithAttachmentUrlAttachXML.hasNext()
0799:                                && belong == false) {
0800:                            Element urlElem = (Element) itWithAttachmentUrlAttachXML
0801:                                    .next();
0802:                            if (pUrlAttachment.getNameFromModel().equals(
0803:                                    urlElem.attributeValue("url"))) {
0804:                                belong = true;
0805:                            }
0806:                        }
0807:                    } else {
0808:                        FileAttachment pFileAttachment = (FileAttachment) attach;
0809:                        Iterator<Node> itEnvFileAttachXML = fileAttachementList
0810:                                .iterator();
0811:                        while (itEnvFileAttachXML.hasNext() && belong == false) {
0812:                            Element fileElem = (Element) itEnvFileAttachXML
0813:                                    .next();
0814:                            if (pFileAttachment.getNameFromModel().equals(
0815:                                    fileElem.attributeValue("nom"))) {
0816:                                belong = true;
0817:                            }
0818:                        }
0819:                    }
0820:                    if (!belong) {
0821:                        envMapToRemove.add(attach);
0822:                    }
0823:
0824:                }
0825:                for (Attachment attach : envMapToRemove) {
0826:                    try {
0827:                        pWithAttachment.deleteAttachementInDBAndModel(attach);
0828:                    } catch (Exception e) {
0829:                        Tools.ihmExceptionView(e);
0830:                    }
0831:                }
0832:            }
0833:
0834:            /**
0835:             * Delete data sets of the campaign which are in database
0836:             * and not in the XML document
0837:             * @param pDocElem XML element
0838:             * @param pWithAttachment element with attachment in DB
0839:             */
0840:            private void dataSetDeletion(Element campElem, Campaign camp) {
0841:                ArrayList<DataSet> datasetList = camp.getDataSetListFromModel();
0842:                ArrayList<DataSet> datasetToRemove = new ArrayList<DataSet>();
0843:                List<Element> datatsetListXML = campElem
0844:                        .selectNodes("JeuxDonnees/JeuDonnees");
0845:                Element jeuElem = null;
0846:                Iterator<DataSet> itJeu = datasetList.iterator();
0847:                boolean belong;
0848:                while (itJeu.hasNext()) {
0849:                    DataSet jeu = itJeu.next();
0850:                    belong = false;
0851:                    Iterator<Element> itJeuXML = datatsetListXML.iterator();
0852:                    while (itJeuXML.hasNext()) {
0853:                        jeuElem = itJeuXML.next();
0854:                        if (jeuElem.elementText("Nom").equals(
0855:                                jeu.getNameFromModel())) {
0856:                            belong = true;
0857:                        }
0858:                    }
0859:                    if (!belong) {
0860:                        datasetToRemove.add(jeu);
0861:                    }
0862:                }
0863:                Iterator<DataSet> itDatasetRm = datasetToRemove.iterator();
0864:                while (itDatasetRm.hasNext()) {
0865:                    DataSet jeuRm = itDatasetRm.next();
0866:                    try {
0867:                        camp.deleteDataSetInDBAndModel(jeuRm);
0868:                    } catch (Exception e) {
0869:                        Tools.ihmExceptionView(e);
0870:                    }
0871:                }
0872:            }
0873:
0874:            /**
0875:             * Supprime les tests d'une campagne qui sont présents dans le projet mais pas dans le documents
0876:             * @param campElem
0877:             * @param camp
0878:             */
0879:            private void testInCampDeletion(Element campElem, Campaign camp)
0880:                    throws Exception {
0881:                ArrayList<Test> testList = camp.getTestListFromModel();
0882:                ArrayList<Test> testToRemove = new ArrayList<Test>();
0883:                List<Element> testListXML = campElem
0884:                        .selectNodes("FamillesCamp/FamilleRef/SuiteTestsCamp/SuiteTestRef/TestsCamp/TestRef");
0885:                Element testElem = null;
0886:                Iterator<Test> itTest = testList.iterator();
0887:                boolean belong;
0888:                while (itTest.hasNext()) {
0889:                    Test test = itTest.next();
0890:                    String suiteName = test.getTestListFromModel()
0891:                            .getNameFromModel();
0892:                    String familyName = test.getTestListFromModel()
0893:                            .getFamilyFromModel().getNameFromModel();
0894:                    belong = false;
0895:                    Iterator<Element> itTestXML = testListXML.iterator();
0896:                    while (itTestXML.hasNext() && !belong) {
0897:                        testElem = itTestXML.next();
0898:                        String nomSuite = ((Element) testElem
0899:                                .selectSingleNode("ancestor::SuiteTestRef[1]"))
0900:                                .elementText("Nom");
0901:                        String nomFamille = ((Element) testElem
0902:                                .selectSingleNode("ancestor::FamilleRef[1]"))
0903:                                .elementText("Nom");
0904:                        String nomTest = testElem.elementText("Nom");
0905:                        if (test.getNameFromModel().equals(nomTest)
0906:                                && suiteName.equals(nomSuite)
0907:                                && familyName.equals(nomFamille)) {
0908:                            belong = true;
0909:                        }
0910:                    }
0911:                    if (!belong) {
0912:                        testToRemove.add(test);
0913:                    }
0914:                }
0915:                Iterator<Test> itTestRm = testToRemove.iterator();
0916:                while (itTestRm.hasNext()) {
0917:                    Test testRm = (Test) itTestRm.next();
0918:                    try {
0919:                        camp.deleteTestFromCampInDBAndModel(testRm, true);
0920:                    } catch (Exception e) {
0921:                        Tools.ihmExceptionView(e);
0922:                    }
0923:                }
0924:            }
0925:
0926:            /**
0927:             * Delete executions which are in database and not in XML document
0928:             * @param campElem
0929:             * @param camp
0930:             */
0931:            void execInCampDeletion(Element campElem, Campaign camp)
0932:                    throws Exception {
0933:                ArrayList<Execution> execList = camp
0934:                        .getExecutionListFromModel();
0935:                ArrayList<Execution> execToRemove = new ArrayList<Execution>();
0936:                List<Node> execListXML = campElem
0937:                        .selectNodes("ExecCampTests/ExecCampTest");
0938:                Element execElem = null;
0939:                Iterator<Execution> itExec = execList.iterator();
0940:                boolean belong;
0941:                while (itExec.hasNext() && !cancelled) {
0942:                    Execution exec = itExec.next();
0943:                    String execName = exec.getNameFromModel();
0944:                    belong = false;
0945:                    Iterator<Node> itExecXML = execListXML.iterator();
0946:                    while (itExecXML.hasNext() && !belong) {
0947:                        execElem = (Element) itExecXML.next();
0948:                        String nomExec = execElem.elementText("Nom");
0949:                        if (nomExec.equals(execName)) {
0950:                            belong = true;
0951:                        }
0952:                    }
0953:                    if (!belong) {
0954:                        execToRemove.add(exec);
0955:                    } else {
0956:                        //suppression des résultats d'exécution
0957:                        ArrayList<ExecutionResult> resExecList = exec
0958:                                .getExecutionResultListFromModel();
0959:                        ArrayList<ExecutionResult> resExecToRemove = new ArrayList<ExecutionResult>();
0960:                        List<Node> resExecListXML = execElem
0961:                                .selectNodes("ResulExecCampTests/ResulExecCampTest");
0962:                        Element resExecElem = null;
0963:                        Iterator<ExecutionResult> itResExec = resExecList
0964:                                .iterator();
0965:                        while (itResExec.hasNext()) {
0966:                            ExecutionResult resExec = itResExec.next();
0967:                            String resExecName = resExec.getNameFromModel();
0968:                            belong = false;
0969:                            Iterator<Node> itResExecXML = resExecListXML
0970:                                    .iterator();
0971:                            while (itResExecXML.hasNext() && !belong) {
0972:                                resExecElem = (Element) itResExecXML.next();
0973:                                String nomResExec = resExecElem
0974:                                        .elementText("Nom");
0975:                                if (nomResExec.equals(resExecName)) {
0976:                                    belong = true;
0977:                                }
0978:                            }
0979:                            if (!belong) {
0980:                                resExecToRemove.add(resExec);
0981:                            }
0982:                        }
0983:                        Iterator<ExecutionResult> itResExecRm = resExecToRemove
0984:                                .iterator();
0985:                        while (itResExecRm.hasNext()) {
0986:                            ExecutionResult resExecRm = itResExecRm.next();
0987:                            try {
0988:                                exec
0989:                                        .deleteExecutionResultInDBAndModel(resExecRm);
0990:                            } catch (Exception e) {
0991:                                Tools.ihmExceptionView(e);
0992:                            }
0993:                        }
0994:                    }
0995:                }
0996:                Iterator<Execution> itExecRm = execToRemove.iterator();
0997:                while (itExecRm.hasNext() && !cancelled) {
0998:                    Execution execRm = itExecRm.next();
0999:                    try {
1000:                        camp.deleteExecutionInDBAndModel(execRm);
1001:                    } catch (Exception e) {
1002:                        Tools.ihmExceptionView(e);
1003:                    }
1004:                }
1005:            }
1006:
1007:            /**
1008:             * Method to manage the import process
1009:             */
1010:            private void coreImport() {
1011:
1012:                try {
1013:
1014:                    /***** Plugin update globale data *****/
1015:                    int size = listXMLPlugin.size();
1016:                    for (int i = 0; i < size; i++) {
1017:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1018:                                .elementAt(i);
1019:                        if (idialog != null) {
1020:                            pXMLPrinterPlugin.updateProjectFromXML(doc, idialog
1021:                                    .isSupprElement(), project, this );
1022:                        } else {
1023:                            pXMLPrinterPlugin.updateProjectFromXML(doc, false,
1024:                                    project, this );
1025:                        }
1026:                    }
1027:                    /***** (END) Plugin update globale data *****/
1028:                    //Attachements du projet
1029:                    updateProjectAttachement();
1030:                    //Paramètres du projet
1031:                    updateProjectParameter();
1032:                    //Environnement du projet
1033:                    updateProjectEnvironment();
1034:                    //Arbre des test
1035:                    updateFamily();
1036:                    if (importCampaign && !cancelled) {
1037:                        updateCampaigns();
1038:                    }
1039:                    updatePlugin();
1040:
1041:                } catch (Exception e) {
1042:                    Tools.ihmExceptionView(e);
1043:                    cancelled = true;
1044:                    return;
1045:                }
1046:            }
1047:
1048:            /**
1049:             * Update attachments of project
1050:             */
1051:            private void updateProjectAttachement() throws Exception {
1052:                Element projectElem = (Element) doc
1053:                        .selectSingleNode("//ProjetVT");
1054:                updateElementAttachement(projectElem, project, false);
1055:            }
1056:
1057:            /**
1058:             * Update parameters of project
1059:             * @throws Exception
1060:             */
1061:            private void updateProjectParameter() throws Exception {
1062:                ArrayList<Node> paramList = (ArrayList<Node>) doc
1063:                        .selectNodes("//Param");
1064:                Iterator<Node> itParam = paramList.iterator();
1065:                while (itParam.hasNext() && !cancelled) {
1066:                    Element paramElem = (Element) itParam.next();
1067:                    String nomParam = paramElem.elementText("Nom");
1068:                    String descriptionParam = (paramElem
1069:                            .elementText("Description") == null) ? ""
1070:                            : paramElem.elementText("Description");
1071:                    descriptionParam = descriptionParam.replaceAll("\\\\n",
1072:                            "\n");
1073:                    Parameter newParamter = new Parameter(nomParam,
1074:                            descriptionParam);
1075:                    boolean existe = false;
1076:                    Parameter par = null;
1077:                    Enumeration<Parameter> itParam2 = project
1078:                            .getParameterSetFromModel().elements();
1079:                    while (itParam2.hasMoreElements() && !existe) {
1080:                        par = itParam2.nextElement();
1081:                        if (par.getNameFromModel().equals(nomParam)) {
1082:                            existe = true;
1083:                        }
1084:                    }
1085:
1086:                    if (!existe) {
1087:                        //Ajout du nouveau parametre
1088:                        project.addParameterToDBAndModel(newParamter);
1089:                        par = newParamter;
1090:                    } else {
1091:                        //Modification du parametre
1092:                        par.updateDescriptionInDBAndModel(descriptionParam);
1093:                    }
1094:                    /***** Plugin update parameter data *****/
1095:                    int size = listXMLPlugin.size();
1096:                    for (int i = 0; i < size; i++) {
1097:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1098:                                .elementAt(i);
1099:                        if (idialog != null) {
1100:                            pXMLPrinterPlugin.updateParameterFromXML(paramElem,
1101:                                    par, idialog.isSupprElement(), this );
1102:                        } else {
1103:                            pXMLPrinterPlugin.updateParameterFromXML(paramElem,
1104:                                    par, false, this );
1105:                        }
1106:                    }
1107:                    /***** (END) Plugin update parameter data *****/
1108:                }
1109:            }
1110:
1111:            /**
1112:             * Add environment in project if it does not exist in database, 
1113:             * if it already exists, update this environment
1114:             * @throws Exception
1115:             */
1116:            private void updateProjectEnvironment() throws Exception {
1117:                //Environnements du projet
1118:                Element paramsElem = (Element) doc.selectSingleNode("//Params");
1119:                ArrayList<Node> envList = (ArrayList<Node>) doc
1120:                        .selectNodes("//Environnement");
1121:                ArrayList<Environment> envInBDD = project
1122:                        .getEnvironmentListFromModel();
1123:                Iterator<Node> itEnv = envList.iterator();
1124:                while (itEnv.hasNext() && !cancelled) {
1125:                    Element envElem = (Element) itEnv.next();
1126:                    String nomEnv = envElem.elementText("Nom");
1127:                    String descriptionEnv = (envElem.elementText("Description") == null) ? ""
1128:                            : envElem.elementText("Description");
1129:                    descriptionEnv = descriptionEnv.replaceAll("\\\\n", "\n");
1130:                    Iterator<Environment> itEnvBDD = envInBDD.iterator();
1131:                    Environment env = null;
1132:                    boolean existeEnv = false;
1133:                    while (itEnvBDD.hasNext() && !existeEnv) {
1134:                        env = itEnvBDD.next();
1135:                        if (env.getNameFromModel().equals(nomEnv)) {
1136:                            existeEnv = true;
1137:                        }
1138:                    }
1139:                    boolean newEnv = false;
1140:                    if (!existeEnv) {
1141:                        env = null;
1142:                        env = new Environment(nomEnv, descriptionEnv);
1143:                        project.addEnvironmentInDBAndModel(env);
1144:                        newEnv = true;
1145:                    } else {
1146:                        env.updateInDBAndModel(nomEnv, descriptionEnv);
1147:                    }
1148:                    // Valeurs des paramètres
1149:                    List<Node> paramEnvList = envElem
1150:                            .selectNodes("ValeurParams/ValeurParam");
1151:                    Iterator<Node> itParamEnv = paramEnvList.iterator();
1152:                    while (itParamEnv.hasNext()) {
1153:                        Element paramElem = (Element) itParamEnv.next();
1154:                        String valeurParam = (paramElem
1155:                                .attributeValue("valeur") != null) ? paramElem
1156:                                .attributeValue("valeur") : "";
1157:                        String id_paramDoc = paramElem.attributeValue("ref");
1158:                        Element paramRootElem = (Element) paramsElem
1159:                                .selectSingleNode("Param[@id_param = '"
1160:                                        + id_paramDoc + "']");
1161:                        String nomParam = paramRootElem.elementText("Nom");
1162:                        //String descriptionParam = (paramRootElem.elementText("Description") == null)?"":paramRootElem.elementText("Description");
1163:                        boolean existe = false;
1164:                        Parameter paramEnv = null;
1165:                        if (env != null && newEnv == false) {
1166:                            Hashtable<Parameter, String> paramEnvInBDD = env
1167:                                    .getParametersHashTableFromModel();
1168:                            Enumeration<Parameter> enumParamEnv = paramEnvInBDD
1169:                                    .keys();
1170:                            while (enumParamEnv.hasMoreElements() && !existe) {
1171:                                paramEnv = enumParamEnv.nextElement();
1172:                                if (nomParam
1173:                                        .equals(paramEnv.getNameFromModel())) {
1174:                                    existe = true;
1175:                                }
1176:                            }
1177:                        }
1178:                        if (!existe) {
1179:                            paramEnv = project.getParameterFromModel(nomParam);
1180:                            if (paramEnv != null) {
1181:                                env.addParameterValueInDBModel(paramEnv,
1182:                                        valeurParam);
1183:                            }
1184:                        } else {
1185:                            env.addParameterValueInDBModel(paramEnv,
1186:                                    valeurParam);
1187:                        }
1188:                    }
1189:                    //Ajout ou mise à jour du script de l'environnement
1190:                    if (envElem.element("Script") != null) {
1191:                        String classpath = envElem.element("Script")
1192:                                .elementText("Classpath");
1193:                        String argScript = envElem.element("Script")
1194:                                .elementText("ArgScript");
1195:                        String type = envElem.element("Script").attributeValue(
1196:                                "type");
1197:                        String dirScript = envElem.element("Script")
1198:                                .attributeValue("dir");
1199:                        dirScript = restorePath(dirScript);
1200:                        File fScript = new File(dirXml + File.separator
1201:                                + dirScript);
1202:
1203:                        Script pScritp = new Script(fScript.getName(), "");
1204:                        pScritp.setTypeInModel(type);
1205:                        pScritp.setScriptExtensionInModel(classpath);
1206:                        pScritp.updatePlugArgInModel(argScript);
1207:                        try {
1208:                            if (newEnv == true) {
1209:                                env.addScriptInDBAndModel(pScritp, fScript);
1210:                            } else {
1211:                                env.deleteScriptInDBAndModel();
1212:                                env.addScriptInDBAndModel(pScritp, fScript);
1213:                            }
1214:                        } catch (Exception e) {
1215:                            Tools.ihmExceptionView(e);
1216:                        }
1217:                    }
1218:                    updateElementAttachement(envElem, env, newEnv);
1219:
1220:                    /***** Plugin update Env data *****/
1221:                    int size = listXMLPlugin.size();
1222:                    for (int i = 0; i < size; i++) {
1223:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1224:                                .elementAt(i);
1225:                        if (idialog != null) {
1226:                            pXMLPrinterPlugin.updateEnvironmentFromXML(envElem,
1227:                                    env, idialog.isSupprElement(), this );
1228:                        } else {
1229:                            pXMLPrinterPlugin.updateEnvironmentFromXML(envElem,
1230:                                    env, false, this );
1231:                        }
1232:                    }
1233:                    /***** (END) Plugin update Env data *****/
1234:                }
1235:            }
1236:
1237:            /**
1238:             * Add family if it does not exist in database,
1239:             * update it otherwise
1240:             * @throws Exception
1241:             */
1242:            private void updateFamily() throws Exception {
1243:                ArrayList<Node> familyList = (ArrayList<Node>) doc
1244:                        .selectNodes("//Famille");
1245:                ArrayList<Family> familleListModel = project
1246:                        .getFamilyListFromModel();
1247:                if (familyList != null) {
1248:                    Iterator<Node> it = familyList.iterator();
1249:                    while (it.hasNext() && !cancelled) {
1250:                        Element familyElem = (Element) it.next();
1251:                        String familyName = familyElem.elementText("Nom");
1252:                        String familyDescription = (familyElem
1253:                                .elementText("Description") == null) ? ""
1254:                                : familyElem.elementText("Description");
1255:                        if (familyElem.element("Description") != null
1256:                                && familyElem.element("Description").attribute(
1257:                                        "isHTML") != null
1258:                                && familyElem.element("Description")
1259:                                        .attributeValue("isHTML")
1260:                                        .equals("true")) {
1261:                            familyDescription = giveHTMLDescription(familyElem);
1262:                        } else {
1263:                            familyDescription = familyDescription.replaceAll(
1264:                                    "\\\\n", "<br>");
1265:                            familyDescription = "<html><head></head><body>"
1266:                                    + familyDescription + "</body></html>";
1267:                        }
1268:                        boolean selectionne = false;
1269:                        if (initSelection) {
1270:                            Iterator<Family> itFamily = familySelectionList
1271:                                    .iterator();
1272:                            while (itFamily.hasNext()) {
1273:                                Family family = itFamily.next();
1274:                                if (familyName
1275:                                        .equals(family.getNameFromModel())) {
1276:                                    selectionne = true;
1277:                                }
1278:                            }
1279:                        }
1280:                        if (!initSelection || selectionne) {
1281:                            boolean appartient = false;
1282:                            Family fam = null;
1283:                            boolean newFamily = false;
1284:                            Iterator<Family> itFam = familleListModel
1285:                                    .iterator();
1286:                            while (itFam.hasNext() && !appartient) {
1287:                                fam = itFam.next();
1288:                                if (fam.getNameFromModel().equals(familyName)) {
1289:                                    appartient = true;
1290:                                }
1291:                            }
1292:                            try {
1293:                                if (!appartient) {
1294:                                    fam = new Family(familyName,
1295:                                            familyDescription);
1296:                                    project.addFamilyInDBAndModel(fam);
1297:                                    newFamily = true;
1298:                                } else {
1299:                                    fam
1300:                                            .updateDescriptionInModel(familyDescription);
1301:                                }
1302:
1303:                                //updatesuite
1304:                                updateElementAttachement(familyElem, fam,
1305:                                        newFamily);
1306:
1307:                                /***** Plugin update FamilyData data *****/
1308:                                int size = listXMLPlugin.size();
1309:                                for (int i = 0; i < size; i++) {
1310:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1311:                                            .elementAt(i);
1312:                                    if (idialog != null) {
1313:                                        pXMLPrinterPlugin
1314:                                                .updateFamilyFromXML(
1315:                                                        familyElem,
1316:                                                        fam,
1317:                                                        idialog
1318:                                                                .isSupprElement(),
1319:                                                        this );
1320:                                    } else {
1321:                                        pXMLPrinterPlugin.updateFamilyFromXML(
1322:                                                familyElem, fam, false, this );
1323:                                    }
1324:                                }
1325:                                /***** (END) Plugin update FamilyData data *****/
1326:
1327:                                updateSuite(familyElem, fam, newFamily);
1328:
1329:                            } catch (Exception e) {
1330:                                Tools.ihmExceptionView(e);
1331:                            }
1332:                        }
1333:                    }
1334:                }
1335:            }
1336:
1337:            /**
1338:             * 
1339:             * @param familyElem
1340:             * @param pFamily
1341:             * @param newFamily
1342:             * @throws Exception
1343:             */
1344:            private void updateSuite(Element familyElem, Family pFamily,
1345:                    boolean newFamily) throws Exception {
1346:                ArrayList<Node> suiteList = (ArrayList<Node>) familyElem
1347:                        .selectNodes(".//SuiteTest");
1348:                if (suiteList != null) {
1349:                    Iterator<Node> it2 = suiteList.iterator();
1350:                    while (it2.hasNext() && !cancelled) {
1351:                        Element suiteElem = (Element) it2.next();
1352:                        String suiteName = suiteElem.elementText("Nom");
1353:                        String suiteDescription = (suiteElem
1354:                                .elementText("Description") == null) ? ""
1355:                                : suiteElem.elementText("Description");
1356:                        if (suiteElem.element("Description") != null
1357:                                && suiteElem.element("Description").attribute(
1358:                                        "isHTML") != null
1359:                                && suiteElem.element("Description")
1360:                                        .attributeValue("isHTML")
1361:                                        .equals("true")) {
1362:                            suiteDescription = giveHTMLDescription(suiteElem);
1363:                        } else {
1364:                            suiteDescription = suiteDescription.replaceAll(
1365:                                    "\\\\n", "<br>");
1366:                            suiteDescription = "<html><head></head><body>"
1367:                                    + suiteDescription + "</body></html>";
1368:                        }
1369:                        //boolean erreur  = false;
1370:                        boolean selectionneSuite = false;
1371:                        if (isInitSelection()) {
1372:                            Iterator<TestList> itSuite = suiteSelectionList
1373:                                    .iterator();
1374:                            while (itSuite.hasNext()) {
1375:                                TestList suite = itSuite.next();
1376:                                if (suiteName.equals(suite.getNameFromModel())) {
1377:                                    selectionneSuite = true;
1378:                                }
1379:                            }
1380:                        }
1381:                        boolean newSuite = false;
1382:                        if (!isInitSelection() || selectionneSuite) {
1383:                            boolean appartient = false;
1384:                            TestList suite = null;
1385:                            if (pFamily != null && newFamily == false) {
1386:                                ArrayList<TestList> suiteTestList = pFamily
1387:                                        .getSuiteListFromModel();
1388:                                Iterator<TestList> itSuite = suiteTestList
1389:                                        .iterator();
1390:                                while (itSuite.hasNext() && !appartient) {
1391:                                    suite = itSuite.next();
1392:                                    if (suite.getNameFromModel().equals(
1393:                                            suiteName)) {
1394:                                        appartient = true;
1395:                                    }
1396:                                }
1397:                            }
1398:
1399:                            try {
1400:                                if (!appartient) {
1401:                                    suite = new TestList(suiteName,
1402:                                            suiteDescription);
1403:                                    pFamily.addTestListInDBAndModel(suite);
1404:                                    newSuite = true;
1405:                                } else {
1406:                                    suite.updateInDBAndModel(suiteName,
1407:                                            suiteDescription);
1408:                                }
1409:                                //gérer les attachements
1410:                                updateElementAttachement(suiteElem, suite,
1411:                                        newSuite);
1412:
1413:                                /***** Plugin update Suite Data *****/
1414:                                int size = listXMLPlugin.size();
1415:                                for (int i = 0; i < size; i++) {
1416:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1417:                                            .elementAt(i);
1418:                                    if (idialog != null) {
1419:                                        pXMLPrinterPlugin
1420:                                                .updateSuiteFromXML(
1421:                                                        suiteElem,
1422:                                                        suite,
1423:                                                        idialog
1424:                                                                .isSupprElement(),
1425:                                                        this );
1426:                                    } else {
1427:                                        pXMLPrinterPlugin.updateSuiteFromXML(
1428:                                                suiteElem, suite, false, this );
1429:                                    }
1430:                                }
1431:                                /***** (END) Plugin update Suite Data *****/
1432:
1433:                                //les tests
1434:                                updateTests(suiteElem, pFamily, suite,
1435:                                        newFamily, newSuite);
1436:                            } catch (Exception e) {
1437:                                Tools.ihmExceptionView(e);
1438:                            }
1439:                        }
1440:                    }
1441:                }
1442:            }
1443:
1444:            /**
1445:             * Manage insertion and update of tests in database from XML file
1446:             * @param suiteElem
1447:             * @param fam
1448:             * @param suite
1449:             * @param newFamily
1450:             * @param newSuite
1451:             */
1452:            private void updateTests(Element suiteElem, Family fam,
1453:                    TestList suite, boolean newFamily, boolean newSuite)
1454:                    throws Exception {
1455:                List<Element> testList = suiteElem.selectNodes(".//Test");
1456:                if (testList == null) {
1457:                    return;
1458:                }
1459:
1460:                Iterator<Element> it = testList.iterator();
1461:                while (it.hasNext() && !cancelled) {
1462:                    try {
1463:                        Element testElem = it.next();
1464:                        String testName = testElem.elementText("Nom");
1465:                        boolean newTest = false;
1466:                        boolean selectionneTest = false;
1467:                        if (isInitSelection()) {
1468:                            Iterator<Test> itTest = testSelectionList
1469:                                    .iterator();
1470:                            while (itTest.hasNext()) {
1471:                                Test test = (Test) itTest.next();
1472:                                if (testName.equals(test.getNameFromModel())) {
1473:                                    selectionneTest = true;
1474:                                }
1475:                            }
1476:                        }
1477:                        if (!isInitSelection() || selectionneTest) {
1478:                            //Vérification de l'existence ou non du test
1479:                            boolean appartient = false;
1480:                            Test test = null;
1481:                            if (suite != null) {
1482:                                ArrayList<Test> testListBDD = suite
1483:                                        .getTestListFromModel();
1484:                                Iterator<Test> itTest = testListBDD.iterator();
1485:                                while (itTest.hasNext() && !appartient) {
1486:                                    test = itTest.next();
1487:                                    if (test.getNameFromModel()
1488:                                            .equals(testName)) {
1489:                                        appartient = true;
1490:                                    }
1491:                                }
1492:                            }
1493:                            //récupération des données dans le document
1494:                            String loginConceptor = "";
1495:                            //User pUser;
1496:                            if (!appartient) {
1497:                                loginConceptor = getLogin(testElem);
1498:                                if (loginConceptor == null) {
1499:                                    if (!newProject) {
1500:                                        loginConceptor = DataModel
1501:                                                .getCurrentUser()
1502:                                                .getLoginFromModel();
1503:                                    } else {
1504:                                        loginConceptor = project
1505:                                                .getAdministratorFromModel()
1506:                                                .getLoginFromModel();
1507:                                    }
1508:                                }
1509:                            } else {
1510:                                loginConceptor = test
1511:                                        .getConceptorLoginFromModel();
1512:                            }
1513:                            String testDescription = (testElem
1514:                                    .elementText("Description") == null) ? ""
1515:                                    : testElem.elementText("Description");
1516:                            if (testElem.element("Description") != null
1517:                                    && testElem.element("Description")
1518:                                            .attribute("isHTML") != null
1519:                                    && testElem.element("Description")
1520:                                            .attributeValue("isHTML").equals(
1521:                                                    "true")) {
1522:                                testDescription = giveHTMLDescription(testElem);
1523:                            } else {
1524:                                testDescription = testDescription.replaceAll(
1525:                                        "\\\\n", "<br>");
1526:                                testDescription = "<html><head></head><body>"
1527:                                        + testDescription + "</body></html>";
1528:                            }
1529:
1530:                            String testType;
1531:                            String plug_ext;
1532:                            if (testElem.element("TestAuto") == null) {
1533:                                testType = "MANUAL";
1534:                                plug_ext = "";
1535:                            } else {
1536:                                testType = "AUTOMATED";
1537:                                String plug = testElem.element("TestAuto")
1538:                                        .attributeValue("plug_ext");
1539:                                if (plug != null) {
1540:                                    plug_ext = plug;
1541:                                } else {
1542:                                    plug_ext = "";
1543:                                }
1544:                            }
1545:                            if (!appartient) {
1546:
1547:                                newTest = true;
1548:                                if (testType.equals("AUTOMATED")) {
1549:                                    test = new AutomaticTest(testName,
1550:                                            testDescription, plug_ext);
1551:                                } else {
1552:                                    test = new ManualTest(testName,
1553:                                            testDescription);
1554:                                }
1555:                                test.setConceptorLoginInModel(loginConceptor);
1556:                                suite.addTestInDBAndModel(test);
1557:
1558:                                updateElementAttachement(testElem, test,
1559:                                        newTest);
1560:
1561:                                updateParametresTest(testElem, test);
1562:
1563:                                /***** Plugin update Test Data *****/
1564:                                int size = listXMLPlugin.size();
1565:                                for (int i = 0; i < size; i++) {
1566:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1567:                                            .elementAt(i);
1568:                                    if (idialog != null) {
1569:                                        pXMLPrinterPlugin
1570:                                                .updateTestFromXML(
1571:                                                        testElem,
1572:                                                        test,
1573:                                                        idialog
1574:                                                                .isSupprElement(),
1575:                                                        this );
1576:                                    } else {
1577:                                        pXMLPrinterPlugin.updateTestFromXML(
1578:                                                testElem, test, false, this );
1579:                                    }
1580:                                }
1581:                                /***** (END) Plugin update Test Data *****/
1582:
1583:                                if (testType == "AUTOMATED") {
1584:                                    updateTestScript(testElem,
1585:                                            (AutomaticTest) test);
1586:                                    automatedTest2Update
1587:                                            .add((AutomaticTest) test);
1588:                                } else {
1589:                                    ajouterActions(testElem, (ManualTest) test);
1590:                                }
1591:
1592:                            } else { //test already present in DB
1593:                                boolean noupdate = true;
1594:                                Test testDB = project.getTestFromModel(fam
1595:                                        .getNameFromModel(), suite
1596:                                        .getNameFromModel(), testName);
1597:                                boolean isDifferent = detecterModif(fam, suite,
1598:                                        testElem);
1599:                                if (!idialog.isKeepOriginalOption()
1600:                                        && isDifferent) {
1601:                                    Test testToUpdate = null;
1602:                                    if (idialog.isKeepOriginalAndImportOption()
1603:                                            || idialog
1604:                                                    .isKeepOriginalAndUpdateOption()) {
1605:                                        String newName = "save_" + testName;
1606:                                        int i = 0;
1607:                                        while (Test.isInBase(suite, newName)) {
1608:                                            newName = newName + "_" + i;
1609:                                            i++;
1610:                                        }
1611:                                        testDB
1612:                                                .updateInDBAndModel(
1613:                                                        newName,
1614:                                                        testDB
1615:                                                                .getDescriptionFromModel());
1616:                                        savedTests.add(testDB);
1617:                                        if (idialog
1618:                                                .isKeepOriginalAndUpdateOption()) {
1619:                                            if (testDB instanceof  ManualTest) {
1620:                                                testToUpdate = ManualTest
1621:                                                        .createCopyInDBAndModel(
1622:                                                                (ManualTest) testDB,
1623:                                                                testName);
1624:                                            } else if (testDB instanceof  AutomaticTest) {
1625:                                                testToUpdate = AutomaticTest
1626:                                                        .createCopyInDBAndModel(
1627:                                                                (AutomaticTest) testDB,
1628:                                                                testName);
1629:                                            }
1630:                                        }
1631:                                    } else if (idialog
1632:                                            .isEraseOriginalAndImport()) {
1633:                                        project.deleteTestInDBandModel(testDB);
1634:                                    }
1635:                                    if (idialog.isKeepOriginalAndImportOption()
1636:                                            || idialog
1637:                                                    .isEraseOriginalAndImport()) {
1638:                                        //import test from XML
1639:                                        newTest = true;
1640:                                        if (testType.equals("AUTOMATED")) {
1641:                                            test = new AutomaticTest(testName,
1642:                                                    testDescription, plug_ext);
1643:                                        } else {
1644:                                            test = new ManualTest(testName,
1645:                                                    testDescription);
1646:                                        }
1647:                                        test
1648:                                                .setConceptorLoginInModel(loginConceptor);
1649:                                        suite.addTestInDBAndModel(test);
1650:
1651:                                        updateElementAttachement(testElem,
1652:                                                test, newTest);
1653:
1654:                                        updateParametresTest(testElem, test);
1655:
1656:                                        /***** Plugin update Test Data *****/
1657:                                        int size = listXMLPlugin.size();
1658:                                        for (int i = 0; i < size; i++) {
1659:                                            XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1660:                                                    .elementAt(i);
1661:                                            if (idialog != null) {
1662:                                                pXMLPrinterPlugin
1663:                                                        .updateTestFromXML(
1664:                                                                testElem,
1665:                                                                test,
1666:                                                                idialog
1667:                                                                        .isSupprElement(),
1668:                                                                this );
1669:                                            } else {
1670:                                                pXMLPrinterPlugin
1671:                                                        .updateTestFromXML(
1672:                                                                testElem, test,
1673:                                                                false, this );
1674:                                            }
1675:                                        }
1676:                                        /***** (END) Plugin update Test Data *****/
1677:
1678:                                        if (testType == "AUTOMATED") {
1679:                                            updateTestScript(testElem,
1680:                                                    (AutomaticTest) test);
1681:                                            automatedTest2Update
1682:                                                    .add((AutomaticTest) test);
1683:                                        } else {
1684:                                            ajouterActions(testElem,
1685:                                                    (ManualTest) test);
1686:                                        }
1687:                                        noupdate = false;
1688:                                    } else if (idialog
1689:                                            .isKeepOriginalAndUpdateOption()
1690:                                            || idialog.isUpdateOriginalOption()) {
1691:                                        if (idialog.isUpdateOriginalOption()) {
1692:                                            testToUpdate = testDB;
1693:                                        }
1694:                                        //update testToUpdate
1695:                                        testToUpdate.updateInModel(testName,
1696:                                                testDescription);
1697:                                        updateElementAttachement(testElem,
1698:                                                testToUpdate, newTest);
1699:                                        updateParametresTest(testElem,
1700:                                                testToUpdate);
1701:                                        /***** Plugin update Test Data *****/
1702:                                        for (XMLPrinterPlugin pXMLPrinterPlugin : listXMLPlugin) {
1703:                                            pXMLPrinterPlugin
1704:                                                    .updateTestFromXML(
1705:                                                            testElem,
1706:                                                            testToUpdate,
1707:                                                            idialog
1708:                                                                    .isSupprElement(),
1709:                                                            this );
1710:                                        }
1711:                                        /***** (END) Plugin update Test Data *****/
1712:                                        if (testType == "AUTOMATED") {
1713:                                            updateTestScript(
1714:                                                    testElem,
1715:                                                    (AutomaticTest) testToUpdate);
1716:                                            Util
1717:                                                    .log("[ImportDialog] Add test auto "
1718:                                                            + testToUpdate
1719:                                                                    .getIdBdd());
1720:                                            automatedTest2Update
1721:                                                    .add((AutomaticTest) testToUpdate);
1722:                                        } else {
1723:                                            ManualTest manualTest = (ManualTest) testToUpdate;
1724:                                            ArrayList<Action> actionList = manualTest
1725:                                                    .getActionListFromModel(false);
1726:                                            ArrayList<String> actionToRemove = new ArrayList<String>();
1727:                                            for (Action action : actionList) {
1728:                                                if (!actionToRemove
1729:                                                        .contains(action
1730:                                                                .getNameFromModel()))
1731:                                                    actionToRemove
1732:                                                            .add(action
1733:                                                                    .getNameFromModel());
1734:                                            }
1735:                                            for (String actionName : actionToRemove) {
1736:                                                manualTest
1737:                                                        .deleteActionInDBModel(manualTest
1738:                                                                .getActionFromModel(actionName));
1739:                                            }
1740:                                            ajouterActions(testElem,
1741:                                                    (ManualTest) testToUpdate);
1742:                                        }
1743:                                        noupdate = false;
1744:                                    }
1745:                                }
1746:                                if (noupdate) {/* Si aucune modification sur l'element on appelle les plugins*/
1747:
1748:                                    /***** Plugin update Test Data *****/
1749:                                    for (XMLPrinterPlugin pXMLPrinterPlugin : listXMLPlugin) {
1750:                                        pXMLPrinterPlugin
1751:                                                .updateTestFromXML(
1752:                                                        testElem,
1753:                                                        testDB,
1754:                                                        idialog
1755:                                                                .isSupprElement(),
1756:                                                        this );
1757:                                    }
1758:                                    /***** (END) Plugin update Test Data *****/
1759:                                }
1760:                            }
1761:                        }
1762:                    } catch (Exception e) {
1763:                        Tools.ihmExceptionView(e);
1764:                    }
1765:                }
1766:            }
1767:
1768:            /**
1769:             * Dans le cas où le test était déjà dans la BD, ajout ou mise à jour du script
1770:             * @param familyName nom de la famille auquelle appartient le test
1771:             * @param suiteName nom de la suite auquelle appartient le test
1772:             * @param testElem élément qui représente le test dans le document XML
1773:             * @param id_test identifiant du test qui a été ajouté à la BD
1774:             */
1775:            public void updateTestScript(Element testElem, AutomaticTest test)
1776:                    throws Exception {
1777:                Element scriptElem = (Element) testElem
1778:                        .selectSingleNode("TestAuto/Script");
1779:                try {
1780:                    if (scriptElem != null) {
1781:                        String classpath = scriptElem.elementText("Classpath");
1782:                        String argScript = scriptElem.elementText("ArgScript");
1783:                        String type = scriptElem.attributeValue("type");
1784:                        String dirScript = scriptElem.attributeValue("dir");
1785:                        dirScript = restorePath(dirScript);
1786:                        File fScript = new File(dirXml + File.separator
1787:                                + dirScript);
1788:
1789:                        Script pScritp = new Script(fScript.getName(), "");
1790:                        pScritp.setTypeInModel(type);
1791:                        pScritp.setScriptExtensionInModel(classpath);
1792:                        pScritp.updatePlugArgInModel(argScript);
1793:
1794:                        if (test != null) {
1795:                            if (test.getScriptFromModel() != null) {
1796:                                test.deleteScriptInDBAndModel();
1797:                            }
1798:                        }
1799:                        test.addScriptInDBAndModel(pScritp, fScript);
1800:                    } else {
1801:                        if (test.getScriptFromModel() != null) {
1802:                            test.deleteScriptInDBAndModel();
1803:                        }
1804:                    }
1805:                } catch (Exception e) {
1806:                    e.printStackTrace();
1807:                    idialog
1808:                            .setErrorMessage(idialog.getErrorMessage()
1809:                                    + Language
1810:                                            .getInstance()
1811:                                            .getText(
1812:                                                    "Problème_lors_de_la_suppression_d'un_script"));
1813:                    idialog.showErrorMessage();
1814:                }
1815:            }
1816:
1817:            /**
1818:             * On cherche à savoir si le test du projet possède des différences avec le test présent dans le fichier XML,
1819:             * ces différences générant un conflit
1820:             * @param familyName nom de la famille auquelle appartient le test
1821:             * @param suiteName nom de la suite auquelle appartient le test
1822:             * @param testElem élément test du document XML
1823:             * @return true si réel conflit, false sinon
1824:             */
1825:            public boolean detecterModif(Family pFamily, TestList suite,
1826:                    Element testElem) throws Exception {
1827:                //on vérifie que tous les paramètres qui sont dans le document d'import sont dans le projet
1828:                String testName = testElem.elementText("Nom");
1829:                Test test = project.getTestFromModel(
1830:                        pFamily.getNameFromModel(), suite.getNameFromModel(),
1831:                        testName);
1832:                List<Element> paramsImport = testElem
1833:                        .selectNodes("ParamsT/ParamT/Nom");
1834:                ArrayList<Parameter> paramsProjet = test
1835:                        .getParameterListFromModel();
1836:                Iterator<Element> itImport = paramsImport.iterator();
1837:                while (itImport.hasNext()) {
1838:                    String nomParamImport = ((Element) itImport.next())
1839:                            .getText();
1840:                    boolean appartient = false;
1841:                    Iterator<Parameter> itParamProjet = paramsProjet.iterator();
1842:                    while (itParamProjet.hasNext()) {
1843:                        Parameter param = itParamProjet.next();
1844:                        if (param.getNameFromModel().equals(nomParamImport)) {
1845:                            appartient = true;
1846:                        }
1847:                    }
1848:                    if (!appartient) {
1849:                        return true;
1850:                    }
1851:                }
1852:                String descriptionXML = "";
1853:                Element descElem = testElem.element("Description");
1854:                if (descElem != null && descElem.hasContent()) {
1855:                    descriptionXML = testElem.element("Description").asXML();
1856:                    descriptionXML = getTextFromChildren(testElem
1857:                            .element("Description"), "");
1858:                }
1859:                String descriptionDB = test.getDescriptionFromModel();
1860:                if (descriptionDB != null && !descriptionDB.equals("")) {
1861:                    descriptionDB = descriptionDB.replaceAll("<br>", "<br/>");
1862:                    if (!descriptionDB.startsWith("<html>")) {
1863:                        descriptionDB = "<html>" + descriptionDB + "</html>";
1864:                    }
1865:                    Document document = DocumentHelper.parseText(descriptionDB);
1866:                    descriptionDB = getTextFromChildren(document
1867:                            .getRootElement(), "");
1868:                }
1869:                if (descriptionXML == null)
1870:                    descriptionXML = "";
1871:                if (descriptionDB == null)
1872:                    descriptionDB = "";
1873:                if (!descriptionXML.equals(descriptionDB)) {
1874:                    return true;
1875:                }
1876:                //on vérifie que tous les paramètres qui sont dans le projet sont bien dans le document d'import
1877:                Iterator<Parameter> itProj = paramsProjet.iterator();
1878:                while (itProj.hasNext()) {
1879:                    Parameter param = itProj.next();
1880:                    boolean appartient = false;
1881:                    Iterator<Element> itDonnees = paramsImport.iterator();
1882:                    while (itDonnees.hasNext()) {
1883:                        String nomParam = (itDonnees.next()).getText();
1884:                        if (nomParam.equals(param.getNameFromModel())) {
1885:                            appartient = true;
1886:                        }
1887:                    }
1888:                    if (!appartient) {
1889:                        return true;
1890:                    }
1891:                }
1892:                //Vérification des actions si paramètres ok
1893:                if (test instanceof  ManualTest) {
1894:                    //détection de modifications dans les actions
1895:                    ManualTest testManuel = (ManualTest) test;
1896:                    List<Element> actionList = testElem
1897:                            .selectNodes(".//ActionTest");
1898:                    Iterator<Element> itAction = actionList.iterator();
1899:                    while (itAction.hasNext()) {
1900:                        Element actionElem = itAction.next();
1901:                        String nomAction = actionElem.elementText("Nom");
1902:                        String descriptionAction = (actionElem
1903:                                .elementText("Description") == null) ? ""
1904:                                : actionElem.elementText("Description");
1905:                        String resulAttendu = (actionElem
1906:                                .elementText("ResultAttendu") == null) ? ""
1907:                                : actionElem.elementText("ResultAttendu");
1908:                        descriptionAction = descriptionAction.replaceAll(
1909:                                "\\\\n", "\n");
1910:                        resulAttendu = resulAttendu.replaceAll("\\\\n", "\n");
1911:
1912:                        Action pAction = testManuel
1913:                                .getActionFromModel(nomAction);
1914:                        if (pAction == null) {
1915:                            return true;
1916:                        } else {
1917:                            if (!pAction.getDescriptionFromModel().trim()
1918:                                    .equals(descriptionAction)
1919:                                    || !pAction.getAwaitedResultFromModel()
1920:                                            .trim().equals(resulAttendu)) {
1921:                                return true;
1922:                            }
1923:                            if (existModifInParamsAction(actionElem, pAction)) {
1924:                                return true;
1925:                            }
1926:                        }
1927:                    }
1928:
1929:                    //vérifier que toutes les actions qui sont dans le projet sont dans le fichier XML
1930:                    ArrayList<Action> actionsProjet = testManuel
1931:                            .getActionListFromModel(false);
1932:                    for (Action action : actionsProjet) {
1933:                        boolean appartient = false;
1934:                        Iterator<Element> itDonnees = actionList.iterator();
1935:                        while (itDonnees.hasNext()) {
1936:                            Element actionElem = itDonnees.next();
1937:                            String nomAction = actionElem.elementText("Nom");
1938:                            if (action.getNameFromModel().equals(nomAction)) {
1939:                                appartient = true;
1940:                            }
1941:                        }
1942:                        if (!appartient) {
1943:                            return true;
1944:                        }
1945:                    }
1946:                }
1947:
1948:                //vérification des attachements
1949:                List<Element> urlAttachementList = testElem
1950:                        .selectNodes("Attachements/UrlAttachement");
1951:                HashMap<String, Attachment> envMap = test
1952:                        .getAttachmentMapFromModel();
1953:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
1954:                for (Element urlElem : urlAttachementList) {
1955:                    String url = urlElem.attributeValue("url");
1956:                    boolean belong = false;
1957:                    for (Attachment attach : envMap.values()) {
1958:                        if ((attach instanceof  UrlAttachment)
1959:                                && ((UrlAttachment) attach).getNameFromModel()
1960:                                        .equals(url)) {
1961:                            belong = true;
1962:                        }
1963:                    }
1964:                    if (!belong) {
1965:                        return true;
1966:                    }
1967:                }
1968:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
1969:                for (Attachment attach : envMap.values()) {
1970:                    if (attach instanceof  UrlAttachment) {
1971:                        boolean belong = false;
1972:                        String url = ((UrlAttachment) attach)
1973:                                .getNameFromModel();
1974:                        for (Element urlElem : urlAttachementList) {
1975:                            if (url.equals(urlElem.attributeValue("url"))) {
1976:                                belong = true;
1977:                            }
1978:                        }
1979:                        if (!belong) {
1980:                            return true;
1981:                        }
1982:                    }
1983:                }
1984:
1985:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
1986:                List<Element> fileAttachmentList = testElem
1987:                        .selectNodes("Attachements/FileAttachement");
1988:                for (Element fileElem : fileAttachmentList) {
1989:                    String nom = fileElem.attributeValue("nom");
1990:                    boolean belong = false;
1991:                    for (Attachment attach : envMap.values()) {
1992:                        if ((attach instanceof  FileAttachment)
1993:                                && ((FileAttachment) attach).getNameFromModel()
1994:                                        .equals(nom)) {
1995:                            belong = true;
1996:                        }
1997:                    }
1998:                    if (!belong) {
1999:                        return true;
2000:                    }
2001:                }
2002:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
2003:                for (Attachment attach : envMap.values()) {
2004:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
2005:                    boolean belong = false;
2006:                    for (Element fileElem : fileAttachmentList) {
2007:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
2008:                            belong = true;
2009:                        }
2010:                    }
2011:                    if (!belong) {
2012:                        return true;
2013:                    }
2014:                }
2015:
2016:                //vérification des scripts des tests automatiques
2017:                if (test instanceof  AutomaticTest) {
2018:                    AutomaticTest testAuto = (AutomaticTest) test;
2019:                    Script script = testAuto.getScriptFromModel();
2020:                    if (script != null) {
2021:                        //calculate md5 from file from DB
2022:                        Element scriptElem = (Element) testElem
2023:                                .selectSingleNode("TestAuto/Script");
2024:                        if (scriptElem == null) {
2025:                            return true;
2026:                        }
2027:                        File tempScriptFile = script.getFileFromDB(null);
2028:                        File fromXMLScriptFile = new File(dirXml
2029:                                + File.separator
2030:                                + scriptElem.attributeValue("dir"));
2031:                        String md5DBScript = getDigest(tempScriptFile);
2032:                        String md5XMLScript = getDigest(fromXMLScriptFile);
2033:                        if (!md5DBScript.equals(md5XMLScript)) {
2034:                            return true;
2035:                        }
2036:                        tempScriptFile.delete();
2037:                    } else {
2038:                        Element scriptElem = (Element) testElem
2039:                                .selectSingleNode("TestAuto/Script");
2040:                        if (scriptElem != null) {
2041:                            return true;
2042:                        }
2043:                    }
2044:                }
2045:                return false;
2046:            }
2047:
2048:            private String getTextFromChildren(Element testElem, String txt) {
2049:                String text = txt + testElem.getTextTrim();
2050:                Iterator<Element> it = testElem.elementIterator();
2051:                while (it.hasNext()) {
2052:                    Element elem = it.next();
2053:                    text += getTextFromChildren(elem, text);
2054:                }
2055:                return text;
2056:            }
2057:
2058:            /**
2059:             * Gives MD5 of the given file
2060:             * @param f
2061:             * @return
2062:             */
2063:            public String getDigest(File f) {
2064:                String digest = null;
2065:                if (f != null) {
2066:                    FileInputStream fis = null;
2067:                    try {
2068:                        fis = new FileInputStream(f);
2069:                        digest = Digest.runMD5(fis);
2070:                    } catch (FileNotFoundException e) {
2071:                        e.printStackTrace();
2072:                    }
2073:                }
2074:                return digest;
2075:            }
2076:
2077:            /**
2078:             * Méthode qui évalue si il y a une différence entre les paramètres d'une action dans le document XML
2079:             * et ceux de cette même action dans le projet Salomé
2080:             * @param actionElem élément du document DOM4J contenant l'action
2081:             * @param action action dans le modèle de SaloméTMF
2082:             * @return
2083:             */
2084:            public boolean existModifInParamsAction(Element actionElem,
2085:                    Action action) throws Exception {
2086:                List<Element> paramsImport = actionElem
2087:                        .selectNodes("ParamsT/ParamT/Nom");
2088:                Hashtable<String, Parameter> paramsProjet = action
2089:                        .getParameterHashSetFromModel();
2090:                //on vérifie que tous les paramètres qui sont dans le document d'import sont bien dans le projet
2091:                for (Element paramElem : paramsImport) {
2092:                    String nomParamImport = paramElem.getText();
2093:                    if (action.getParameterFromModel(nomParamImport) == null) {
2094:                        return true;
2095:                    }
2096:                }
2097:                //on vérifie que tous les paramètres qui sont dans le projet sont bien dans le document d'import
2098:                Enumeration<Parameter> itProj = paramsProjet.elements();
2099:                while (itProj.hasMoreElements()) {
2100:                    Parameter param = itProj.nextElement();
2101:                    boolean appartient = false;
2102:                    for (Element paramElem : paramsImport) {
2103:                        String nomParam = paramElem.getText();
2104:                        if (nomParam.equals(param.getNameFromModel())) {
2105:                            appartient = true;
2106:                        }
2107:                    }
2108:                    if (!appartient) {
2109:                        return true;
2110:                    }
2111:                }
2112:                return false;
2113:            }
2114:
2115:            /**
2116:             * Dans le cas où le test était déjà dans la BD, ajout des paramètres
2117:             * @param test le test concerné
2118:             * @param testElem élément qui représente le test dans le document XML
2119:             * @param id_test identifiant du test qui a été ajouté à la BD
2120:             */
2121:            public void updateParametresTest(Element testElem, Test test)
2122:                    throws Exception {
2123:                //on ajoute les paramètres que si ils n'existent pas déjà dans la bd
2124:                List<Element> paramList = testElem
2125:                        .selectNodes("ParamsT/ParamT/Nom");
2126:                Iterator<Element> itParam = paramList.iterator();
2127:                while (itParam.hasNext()) {
2128:                    String nomParam = (itParam.next()).getText();
2129:                    boolean appartient = false;
2130:                    Parameter param = null;
2131:                    if (test != null) {
2132:                        ArrayList<Parameter> paramListBDD = test
2133:                                .getParameterListFromModel();
2134:                        Iterator<Parameter> itparam = paramListBDD.iterator();
2135:                        while (itparam.hasNext() && !appartient) {
2136:                            param = itparam.next();
2137:                            if (param.getNameFromModel().equals(nomParam)) {
2138:                                appartient = true;
2139:                            }
2140:                        }
2141:                    }
2142:                    try {
2143:                        if (!appartient) {
2144:                            param = project.getParameterFromModel(nomParam);
2145:                            if (param != null) {
2146:                                test.setUseParamInDBAndModel(param);
2147:                            }
2148:                        }
2149:                    } catch (Exception e) {
2150:                        Tools.ihmExceptionView(e);
2151:                    }
2152:                }
2153:            }
2154:
2155:            private String getLogin(Element pElem) throws Exception {
2156:                String login = pElem.element("Concepteur").elementText("Login");
2157:                if (project.containUser(login) != -1) {
2158:                    return login;
2159:                } else {
2160:                    return null;
2161:                }
2162:            }
2163:
2164:            /**
2165:             * Transform description in XML in description compatible with HTML description
2166:             * @param elem
2167:             * @return
2168:             */
2169:            private String giveHTMLDescription(Element elem) {
2170:                String description = elem.element("Description").asXML();
2171:                description = description.substring(27, description
2172:                        .indexOf("</Description>"));
2173:                description = description.replaceAll("<br/>", "<br>");
2174:                description = "<html><head></head><body>" + description
2175:                        + "</body></html>";
2176:                return description;
2177:            }
2178:
2179:            void updatePlugin() throws Exception {
2180:                //gestion des drivers des scripts des tests automatiques
2181:                for (AutomaticTest test : automatedTest2Update) {
2182:                    try {
2183:                        TestDriver driver = null;
2184:                        if (idialog != null) {
2185:                            driver = ((AutomaticTest) test).ActivateExtention(
2186:                                    (Extension) pIPlugObject
2187:                                            .getAssociatedExtension(test
2188:                                                    .getExtensionFromModel()),
2189:                                    pIPlugObject.getUrlBase(), pIPlugObject
2190:                                            .getPluginManager());
2191:                        }
2192:                        if (test.getScriptFromModel() != null && driver != null) {
2193:                            File file = ((AutomaticTest) test)
2194:                                    .getTestScriptFromDB();
2195:                            if (file != null) {
2196:                                driver.updateTestScriptFromImport(file
2197:                                        .getAbsolutePath(),
2198:                                        (AutomaticTest) test);
2199:                            }
2200:                        }
2201:                    } catch (Exception e) {
2202:                        e.printStackTrace();
2203:                        idialog
2204:                                .setErrorMessage(idialog.getErrorMessage()
2205:                                        + Language
2206:                                                .getInstance()
2207:                                                .getText(
2208:                                                        "Problème_lors_de_la_mise_à_jour_des_drivers_des_scripts"));
2209:                        idialog.showErrorMessage();
2210:                    }
2211:                }
2212:            }
2213:
2214:            /**
2215:             * Update attachments of an element
2216:             */
2217:            public void updateElementAttachement(Element element,
2218:                    WithAttachment data, boolean isNewElement) {
2219:                try {
2220:                    //URL
2221:                    List<Node> urlAttachementList = element
2222:                            .selectNodes("Attachements/UrlAttachement");
2223:                    Iterator<Node> itEnvUrlAttach = urlAttachementList
2224:                            .iterator();
2225:                    while (itEnvUrlAttach.hasNext()) {
2226:                        Element urlElem = (Element) itEnvUrlAttach.next();
2227:                        String url = urlElem.attributeValue("url");
2228:                        String description = (urlElem
2229:                                .elementText("Description") == null) ? ""
2230:                                : urlElem.elementText("Description");
2231:                        description = description.replaceAll("\\\\n", "\n");
2232:                        boolean appartient = false;
2233:                        Attachment attach = null;
2234:                        if (isNewElement == false) {
2235:                            HashMap<String, Attachment> envMap = data
2236:                                    .getAttachmentMapFromModel();
2237:                            Iterator<Attachment> itEnvAttachs = envMap.values()
2238:                                    .iterator();
2239:                            while (itEnvAttachs.hasNext() && !appartient) {
2240:                                attach = itEnvAttachs.next();
2241:                                if ((attach instanceof  UrlAttachment)
2242:                                        && ((UrlAttachment) attach)
2243:                                                .getNameFromModel().equals(url)) {
2244:                                    appartient = true;
2245:                                }
2246:                            }
2247:                        }
2248:                        if (!appartient) {
2249:                            data.addAttachementInDBAndModel(new UrlAttachment(
2250:                                    url, description));
2251:                        } else {
2252:                            ((UrlAttachment) attach)
2253:                                    .updateDescriptionInDBdAndModel(description);
2254:                        }
2255:                    }
2256:                    //fichiers
2257:                    List<Node> envFileAttachementList = element
2258:                            .selectNodes("Attachements/FileAttachement");
2259:                    Iterator<Node> itEnvFileAttach = envFileAttachementList
2260:                            .iterator();
2261:                    while (itEnvFileAttach.hasNext()) {
2262:                        Element fileElem = (Element) itEnvFileAttach.next();
2263:                        String dirAtt = fileElem.attributeValue("dir");
2264:                        String nom = fileElem.attributeValue("nom");
2265:                        dirAtt = restorePath(dirAtt);
2266:                        File f = new File(dirXml + File.separator + dirAtt);
2267:                        String description = (fileElem
2268:                                .elementText("Description") == null) ? ""
2269:                                : fileElem.elementText("Description");
2270:                        description = description.replaceAll("\\\\n", "\n");
2271:                        boolean appartient = false;
2272:                        Attachment attach = null;
2273:                        if (isNewElement == false) {
2274:                            HashMap<String, Attachment> envMap = data
2275:                                    .getAttachmentMapFromModel();
2276:                            Iterator<Attachment> itEnvAttachs = envMap.values()
2277:                                    .iterator();
2278:                            while (itEnvAttachs.hasNext() && !appartient) {
2279:                                attach = (Attachment) itEnvAttachs.next();
2280:                                if ((attach instanceof  FileAttachment)
2281:                                        && ((FileAttachment) attach)
2282:                                                .getNameFromModel().equals(nom)) {
2283:                                    appartient = true;
2284:                                }
2285:                            }
2286:                        }
2287:                        if (!appartient) {
2288:                            attach = new FileAttachment(f, description);
2289:                            data.addAttachementInDBAndModel(attach);
2290:                        } else {
2291:                            ((FileAttachment) attach).updateInDBAndModel(f);
2292:                            ((FileAttachment) attach)
2293:                                    .updateDescriptionInDBdAndModel(description);
2294:                        }
2295:                    }
2296:                } catch (Exception e) {
2297:                    e.printStackTrace();
2298:                    if (!attachmentException) {
2299:                        idialog
2300:                                .setErrorMessage(idialog.getErrorMessage()
2301:                                        + Language
2302:                                                .getInstance()
2303:                                                .getText(
2304:                                                        "Problème_lors_de_la_récupération_des_attachements"));
2305:                        attachmentException = true;
2306:                    }
2307:                    idialog.showErrorMessage();
2308:                }
2309:            }
2310:
2311:            /**
2312:             * Dans le cas où le test n'était pas déjà dans la BD, ajout des actions
2313:             * @param testElem élément qui représente le test dans le document XML
2314:             * @param id_test identifiant du test qui a été ajouté à la BD
2315:             */
2316:            public void ajouterActions(Element testElem, ManualTest test)
2317:                    throws Exception {
2318:                List<Element> actionList = testElem
2319:                        .selectNodes(".//ActionTest");
2320:                for (Element actionElem : actionList) {
2321:                    String nomAction = actionElem.elementText("Nom");
2322:                    String description = (actionElem.elementText("Description") == null) ? ""
2323:                            : actionElem.elementText("Description");
2324:                    String resulAttendu = (actionElem
2325:                            .elementText("ResultAttendu") == null) ? ""
2326:                            : actionElem.elementText("ResultAttendu");
2327:                    description = description.replaceAll("\\\\n", "\n");
2328:                    resulAttendu = resulAttendu.replaceAll("\\\\n", "\n");
2329:
2330:                    Action newAction = new Action(test, nomAction, description);
2331:                    newAction.setAwaitedResultInModel(resulAttendu);
2332:                    test.addActionInDBAndModel(newAction);
2333:
2334:                    ajouterAttachements(actionElem, newAction);
2335:                    ajoutParametresActions(actionElem, newAction);
2336:
2337:                    /***** Plugin update Action Data *****/
2338:                    int size = listXMLPlugin.size();
2339:                    for (int i = 0; i < size; i++) {
2340:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
2341:                                .elementAt(i);
2342:                        if (idialog != null) {
2343:                            pXMLPrinterPlugin.updateActionFromXML(actionElem,
2344:                                    newAction, idialog.isSupprElement(), this );
2345:                        } else {
2346:                            pXMLPrinterPlugin.updateActionFromXML(actionElem,
2347:                                    newAction, false, this );
2348:                        }
2349:                    }
2350:                    /***** (END) Plugin update Action Data *****/
2351:                }
2352:            }
2353:
2354:            /**
2355:             * Dans le cas où  attachableElement n'était pas déjà dans la BD, ajout des attachements
2356:             * @param elem :  élément qui représente le WithAttachment dans le document XML
2357:             * @param attachableElement
2358:             */
2359:            public void ajouterAttachements(Element elem,
2360:                    WithAttachment attachableElement) throws Exception {
2361:                List<Node> urlAttachementList = elem
2362:                        .selectNodes("Attachements/UrlAttachement");
2363:                Iterator<Node> itUrlAttach = urlAttachementList.iterator();
2364:                while (itUrlAttach.hasNext()) {
2365:                    Element urlElem = (Element) itUrlAttach.next();
2366:                    String url = urlElem.attributeValue("url");
2367:                    String description = (urlElem.elementText("Description") == null) ? ""
2368:                            : urlElem.elementText("Description");
2369:                    description = description.replaceAll("\\\\n", "\n");
2370:                    UrlAttachment pUrlAttachment = new UrlAttachment(url,
2371:                            description);
2372:                    try {
2373:                        attachableElement
2374:                                .addAttachementInDBAndModel(pUrlAttachment);
2375:                    } catch (Exception e1) {
2376:                        Tools.ihmExceptionView(e1);
2377:                    }
2378:                }
2379:                List<Node> testFileAttachementList = elem
2380:                        .selectNodes("Attachements/FileAttachement");
2381:                Iterator<Node> itFileAttach = testFileAttachementList
2382:                        .iterator();
2383:                while (itFileAttach.hasNext()) {
2384:                    Element fileElem = (Element) itFileAttach.next();
2385:                    String dirAtt = fileElem.attributeValue("dir");
2386:                    dirAtt = restorePath(dirAtt);
2387:                    File f = new File(dirXml + File.separator + dirAtt);
2388:                    String description = (fileElem.elementText("Description") == null) ? ""
2389:                            : fileElem.elementText("Description");
2390:                    description = description.replaceAll("\\\\n", "\n");
2391:                    FileAttachment pFileAttachment = new FileAttachment(f,
2392:                            description);
2393:                    try {
2394:                        attachableElement
2395:                                .addAttachementInDBAndModel(pFileAttachment);
2396:                    } catch (Exception e2) {
2397:                        Tools.ihmExceptionView(e2);
2398:                    }
2399:                }
2400:            }
2401:
2402:            /**
2403:             * Si l'action existait dans la BD, ajout ou mise à jour des paramètres
2404:             * @param pAction identifiant de l'action
2405:             * @param actionElem élément action du document comportant les données
2406:             */
2407:            public void ajoutParametresActions(Element actionElem,
2408:                    Action pAction) throws Exception {
2409:                List<Node> paramActionList = actionElem
2410:                        .selectNodes("ParamsT/ParamT/Nom");
2411:                Iterator<Node> itParamAction = paramActionList.iterator();
2412:                while (itParamAction.hasNext()) {
2413:                    String nomParamImport = ((Element) itParamAction.next())
2414:                            .getText();
2415:                    boolean appartient = false;
2416:                    if (pAction.getParameterFromModel(nomParamImport) != null) {
2417:                        appartient = true;
2418:                    }
2419:                    if (!appartient) {
2420:                        Parameter param;
2421:                        Test pTest = pAction.getTest();
2422:                        param = pTest.getUsedParameterFromModel(nomParamImport);
2423:                        if (param != null) {
2424:                            pAction.setUseParamInDBAndModel(param);
2425:                        } else {
2426:                            param = project
2427:                                    .getParameterFromModel(nomParamImport);
2428:                            if (param != null) {
2429:                                pTest.setUseParamInDBAndModel(param);
2430:                                pAction.setUseParamInDBAndModel(param);
2431:                            } else {
2432:                                //AIE
2433:                            }
2434:                        }
2435:                    }
2436:                }
2437:            }
2438:
2439:            /**
2440:             * Update list of campaigns with information from the XML file
2441:             */
2442:            private void updateCampaigns() {
2443:                ArrayList<Campaign> campList = project
2444:                        .getCampaignListFromModel();
2445:                List<Element> campListXML = doc.selectNodes("//CampagneTest");
2446:                Iterator<Element> itCampXML = campListXML.iterator();
2447:                while (itCampXML.hasNext() && !cancelled) {
2448:                    try {
2449:                        Element campElem = (Element) itCampXML.next();
2450:                        String campName = campElem.elementText("Nom");
2451:                        String campDescription = (campElem
2452:                                .elementText("Description") == null) ? ""
2453:                                : campElem.elementText("Description");
2454:                        if (campElem.element("Description") != null
2455:                                && campElem.element("Description").attribute(
2456:                                        "isHTML") != null
2457:                                && campElem.element("Description")
2458:                                        .attributeValue("isHTML")
2459:                                        .equals("true")) {
2460:                            campDescription = giveHTMLDescription(campElem);
2461:                        } else {
2462:                            campDescription = campDescription.replaceAll(
2463:                                    "\\\\n", "<br>");
2464:                            campDescription = "<html><head></head><body>"
2465:                                    + campDescription + "</body></html>";
2466:                        }
2467:                        boolean appartient = false;
2468:                        Campaign campaign = null;
2469:                        Iterator<Campaign> itCamp = campList.iterator();
2470:                        while (itCamp.hasNext() && !appartient) {
2471:                            campaign = (Campaign) itCamp.next();
2472:                            if (campElem.elementText("Nom").equals(
2473:                                    campaign.getNameFromModel())) {
2474:                                appartient = true;
2475:                            }
2476:                            Util.log("[gestionDesCampagnes] compare "
2477:                                    + campaign.getNameFromModel() + " avec "
2478:                                    + campElem.elementText("Nom")
2479:                                    + " result = " + appartient);
2480:                        }
2481:                        if (!appartient) {
2482:
2483:                            Campaign camp = new Campaign(campName,
2484:                                    campDescription);
2485:                            project.addCampaignInDBandModel(camp);
2486:
2487:                            //ajout des attachements
2488:                            ajouterAttachements(campElem, camp);
2489:                            /***** Plugin update Campaign Data *****/
2490:                            int size = listXMLPlugin.size();
2491:                            for (int i = 0; i < size; i++) {
2492:                                XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
2493:                                        .elementAt(i);
2494:                                if (idialog != null) {
2495:                                    pXMLPrinterPlugin.updateCampaignFromXML(
2496:                                            campElem, camp, idialog
2497:                                                    .isSupprElement(), this );
2498:                                } else {
2499:                                    pXMLPrinterPlugin.updateCampaignFromXML(
2500:                                            campElem, camp, false, this );
2501:                                }
2502:                            }
2503:                            /***** (END) Plugin update Campaing Data *****/
2504:                            //ajout des jeux de données
2505:                            ajouterJeuxDonnees(campElem, camp);
2506:                            //ajout des tests associées à la campagne
2507:                            ajoutTestsToCamp(campElem, camp);
2508:                            //ajout des exécutions
2509:                            ajouterExecutions(campElem, camp);
2510:                        } else { //the campaign is in DB
2511:                            if (!idialog.isKeepOriginalOption()) {
2512:                                // option is keepOriginalAndImport
2513:                                // if some tests are copied, the campaign is in conflict, keep a copy and import the new campaign
2514:                                boolean keepCopy = mustKeepCopy(campaign,
2515:                                        campElem);
2516:                                if (keepCopy) {
2517:                                    //change name of original campaign in "save_..."
2518:                                    String newName = "save_" + campName;
2519:                                    int i = 0;
2520:                                    while (Campaign.isInBase(project, newName)) {
2521:                                        newName = newName + "_" + i;
2522:                                        i++;
2523:                                    }
2524:                                    campaign.updateInDBAndModel(newName,
2525:                                            campaign.getDescriptionFromModel());
2526:                                    //import campaign from XML
2527:                                    Campaign camp = new Campaign(campName,
2528:                                            campDescription);
2529:                                    project.addCampaignInDBandModel(camp);
2530:
2531:                                    //ajout des attachements
2532:                                    ajouterAttachements(campElem, camp);
2533:                                    /***** Plugin update Campaign Data *****/
2534:                                    int size = listXMLPlugin.size();
2535:                                    for (int j = 0; j < size; j++) {
2536:                                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
2537:                                                .elementAt(j);
2538:                                        if (idialog != null) {
2539:                                            pXMLPrinterPlugin
2540:                                                    .updateCampaignFromXML(
2541:                                                            campElem,
2542:                                                            camp,
2543:                                                            idialog
2544:                                                                    .isSupprElement(),
2545:                                                            this );
2546:                                        } else {
2547:                                            pXMLPrinterPlugin
2548:                                                    .updateCampaignFromXML(
2549:                                                            campElem, camp,
2550:                                                            false, this );
2551:                                        }
2552:                                    }
2553:                                    /***** (END) Plugin update Campaing Data *****/
2554:                                    //ajout des jeux de données
2555:                                    ajouterJeuxDonnees(campElem, camp);
2556:                                    //ajout des tests associées à la campagne
2557:                                    ajoutTestsToCamp(campElem, camp);
2558:                                    //ajout des exécutions
2559:                                    ajouterExecutions(campElem, camp);
2560:                                } else {
2561:                                    //execution level
2562:                                    List<Element> execList = campElem
2563:                                            .selectNodes("ExecCampTests/ExecCampTest");
2564:                                    Iterator<Element> itExec = execList
2565:                                            .iterator();
2566:                                    while (itExec.hasNext() && !cancelled) {
2567:                                        Element execElem = itExec.next();
2568:                                        String execName = execElem
2569:                                                .elementText("Nom");
2570:                                        boolean belong = false;
2571:                                        ArrayList<Execution> execCampList = campaign
2572:                                                .getExecutionListFromModel();
2573:                                        Iterator<Execution> itExecCamp = execCampList
2574:                                                .iterator();
2575:                                        Execution exec = null;
2576:                                        while (itExecCamp.hasNext() && !belong) {
2577:                                            exec = itExecCamp.next();
2578:                                            if (execName.equals(exec
2579:                                                    .getNameFromModel())) {
2580:                                                belong = true;
2581:                                            }
2582:                                        }
2583:                                        if (!belong) {
2584:                                            ajouterExecution(execElem, campaign);
2585:                                        } else {
2586:                                            if (!idialog.isKeepOriginalOption()) {
2587:                                                //search differences
2588:                                                boolean keepCopyExec = mustKeepCopy(
2589:                                                        exec, execElem);
2590:                                                if (keepCopyExec) {
2591:                                                    String newName = "save_"
2592:                                                            + execName;
2593:                                                    int i = 0;
2594:                                                    while (Execution.isInBase(
2595:                                                            campaign, newName)) {
2596:                                                        newName = newName + "_"
2597:                                                                + i;
2598:                                                        i++;
2599:                                                    }
2600:                                                    exec
2601:                                                            .updateInDBAndModel(
2602:                                                                    newName,
2603:                                                                    exec
2604:                                                                            .getDescriptionFromModel());
2605:                                                    ajouterExecution(execElem,
2606:                                                            campaign);
2607:                                                } else {
2608:                                                    List<Element> resExecList = execElem
2609:                                                            .selectNodes("ResulExecCampTests/ResulExecCampTest");
2610:                                                    Iterator<Element> itResExec = resExecList
2611:                                                            .iterator();
2612:                                                    while (itResExec.hasNext()
2613:                                                            && !cancelled) {
2614:                                                        Element resExecElem = itResExec
2615:                                                                .next();
2616:                                                        String resExecName = resExecElem
2617:                                                                .elementText("Nom");
2618:                                                        boolean belong2 = false;
2619:                                                        ArrayList<ExecutionResult> resExecutionList = exec
2620:                                                                .getExecutionResultListFromModel();
2621:                                                        Iterator<ExecutionResult> itResExecution = resExecutionList
2622:                                                                .iterator();
2623:                                                        ExecutionResult resExec = null;
2624:                                                        while (itResExecution
2625:                                                                .hasNext()
2626:                                                                && !belong2) {
2627:                                                            resExec = itResExecution
2628:                                                                    .next();
2629:                                                            if (resExecName
2630:                                                                    .equals(resExec
2631:                                                                            .getNameFromModel())) {
2632:                                                                belong = true;
2633:                                                            }
2634:                                                        }
2635:                                                        if (!belong) {
2636:                                                            //add execution result
2637:                                                            ajouterResulExec(
2638:                                                                    resExecElem,
2639:                                                                    exec);
2640:                                                        } else {
2641:                                                            if (!idialog
2642:                                                                    .isKeepOriginalOption()) {
2643:                                                                //search differences
2644:                                                                boolean keepCopyResExec = mustKeepCopy(
2645:                                                                        resExec,
2646:                                                                        resExecElem);
2647:                                                                if (keepCopyResExec) {
2648:                                                                    /*String newName = "save_"+resExecName;
2649:                                                                    int i = 0;
2650:                                                                    while (containsResExec(exec, newName)) {
2651:                                                                    	newName = newName + "_" + i;
2652:                                                                    	i++;
2653:                                                                    }
2654:                                                                    resExec.updateInDBAndModel(newName, resExec.getDescriptionFromModel());*/
2655:                                                                    //TODO implement updateInDBAndModel
2656:                                                                    ajouterResulExec(
2657:                                                                            resExecElem,
2658:                                                                            exec);
2659:                                                                }
2660:                                                            }
2661:                                                        }
2662:                                                    }
2663:                                                }
2664:                                            }
2665:                                        }
2666:                                    }
2667:                                }
2668:                            }
2669:                        }
2670:                    } catch (Exception e) {
2671:                        Tools.ihmExceptionView(e);
2672:                    }
2673:                }
2674:            }
2675:
2676:            /*private boolean containsResExec(Execution exec, String newName) {
2677:            	ArrayList<ExecutionResult> resExecList = exec.getExecutionResultListFromModel();
2678:            	for (ExecutionResult resExec : resExecList) {
2679:            		if (newName.equals(resExec.getNameFromModel())) {
2680:            			return true;
2681:            		}
2682:            	}
2683:            	return false;
2684:            }*/
2685:
2686:            /**
2687:             * Si la campagne n'existait pas déjà dans la BD, ajout des jeux de données
2688:             * @param campElem élément représentant la campagne dans le document XML
2689:             * @param id_camp identifiant de la campagne ajoutée dans la base de données
2690:             */
2691:            private void ajouterJeuxDonnees(Element campElem, Campaign pCamp)
2692:                    throws Exception {
2693:                List<Element> jeuListXML = campElem
2694:                        .selectNodes("JeuxDonnees/JeuDonnees");
2695:                for (Element jeuElem : jeuListXML) {
2696:                    String nomJeu = jeuElem.elementText("Nom");
2697:                    String description = jeuElem.elementText("Description");
2698:                    if (description == null) {
2699:                        description = "";
2700:                    } else {
2701:                        description = description.replaceAll("\\\\n", "\n");
2702:                    }
2703:                    DataSet pDataSet = new DataSet(nomJeu, description);
2704:                    pCamp.addDataSetInDBAndModel(pDataSet);
2705:
2706:                    //ajout du jeu de données au modèle
2707:                    //ajout des paramètres valués du jeu de données
2708:                    List<Element> paramList = jeuElem
2709:                            .selectNodes("ValeurParams/ValeurParam");
2710:                    for (Element paramElem : paramList) {
2711:                        String valParam = (paramElem.attributeValue("valeur") != null) ? paramElem
2712:                                .attributeValue("valeur")
2713:                                : "";
2714:                        String nomParam = paramElem.elementText("Nom");
2715:
2716:                        Parameter param = project
2717:                                .getParameterFromModel(nomParam);
2718:                        pDataSet.addParamValueToDBAndModel(valParam, param);
2719:                    }
2720:
2721:                    /***** Plugin update DataSet *****/
2722:                    int size = listXMLPlugin.size();
2723:                    for (int i = 0; i < size; i++) {
2724:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
2725:                                .elementAt(i);
2726:                        if (idialog != null) {
2727:                            pXMLPrinterPlugin.updateDataSetFromXML(jeuElem,
2728:                                    pDataSet, idialog.isSupprElement(), this );
2729:                        } else {
2730:                            pXMLPrinterPlugin.updateDataSetFromXML(jeuElem,
2731:                                    pDataSet, false, this );
2732:                        }
2733:                    }
2734:                    /***** (END) Plugin update DataSet *****/
2735:                }
2736:            }
2737:
2738:            private void ajoutTestsToCamp(Element campElem, Campaign pCamp)
2739:                    throws Exception {
2740:                List<Element> familyListXML = campElem
2741:                        .selectNodes("FamillesCamp/FamilleRef");
2742:                for (Element famElem : familyListXML) {
2743:                    String nomFamille = famElem.elementText("Nom");
2744:                    Family family = project.getFamilyFromModel(nomFamille);
2745:                    List<Node> suiteListXML = famElem
2746:                            .selectNodes("SuiteTestsCamp/SuiteTestRef");
2747:                    Iterator<Node> itSuite = suiteListXML.iterator();
2748:                    while (itSuite.hasNext()) {
2749:                        Element suiteElem = (Element) itSuite.next();
2750:                        String nomSuite = suiteElem.elementText("Nom");
2751:                        TestList testList = family.getTestListInModel(nomSuite);
2752:                        List<Node> testListXML = suiteElem
2753:                                .selectNodes("TestsCamp/TestRef");
2754:                        Iterator<Node> itTest = testListXML.iterator();
2755:                        while (itTest.hasNext()) {
2756:                            Element testElem = (Element) itTest.next();
2757:                            String nomTest = testElem.elementText("Nom");
2758:                            int userID = -1;
2759:                            String loginAssigned = testElem
2760:                                    .attributeValue("loginAssigned");
2761:                            if (loginAssigned != null
2762:                                    && !loginAssigned.equals("")) {
2763:                                userID = project.containUser(loginAssigned);
2764:                            }
2765:                            if (userID == -1) {
2766:                                if (idialog != null) {
2767:                                    //ConnectionData.getCampTestInsert().addResExecCampUsingID(nom, id_exec, DataModel.getCurrentUser().getLogin(), description, statut, resultat);
2768:                                    userID = DataModel.getCurrentUser()
2769:                                            .getIdBdd();
2770:                                } else {
2771:                                    //ConnectionData.getCampTestInsert().addResExecCampUsingID(nom, id_exec, cdialog.getNewProject().getAdministrator().getLogin(), description, statut, resultat);
2772:                                    userID = project
2773:                                            .getAdministratorFromModel()
2774:                                            .getIdBdd();
2775:                                }
2776:                            }
2777:                            Test pTest = testList.getTestFromModel(nomTest);
2778:                            pCamp.importTestInDBAndModel(pTest, userID);
2779:                        }
2780:                    }
2781:                }
2782:            }
2783:
2784:            /**
2785:             * Méthode qui ajoute les exécutions aux campagnes qui n'était pas au préalable dans la BD
2786:             * @param campElem élément représentant la campagne dans le document XML
2787:             * @param id_camp identifiant de la campagne dans la BD
2788:             */
2789:            public void ajouterExecutions(Element campElem, Campaign pCamp)
2790:                    throws Exception {
2791:                List<Element> listExecXML = campElem
2792:                        .selectNodes("ExecCampTests/ExecCampTest");
2793:                for (Element execElem : listExecXML) {
2794:                    ajouterExecution(execElem, pCamp);
2795:                }
2796:            }
2797:
2798:            /**
2799:             * Méthode qui ajoute une exécution à une campagne
2800:             * @param campElem élément représentant la campagne dans le document XML
2801:             * @param id_camp identifiant de la campagne dans la BD
2802:             */
2803:            private void ajouterExecution(Element execElem, Campaign pCamp) {
2804:                String nomExec = execElem.elementText("Nom");
2805:                String description = (execElem.elementText("Description") != null) ? execElem
2806:                        .elementText("Description")
2807:                        : "";
2808:                description = description.replaceAll("\\\\n", "\n");
2809:                Execution pExecution = new Execution(nomExec, description);
2810:
2811:                Element jeuElem = execElem.element("JeuDonneesEx");
2812:                DataSet pDataSet = null;
2813:                if (jeuElem != null) {
2814:                    String nomJeu = jeuElem.elementText("Nom");
2815:                    //id_jeu = ConnectionData.getCampTestSelect().getDataSetId(nomJeu, campName);
2816:                    pDataSet = pCamp.getDataSetFromModel(nomJeu);
2817:                } else {
2818:                    pDataSet = new DataSet(ApiConstants.EMPTY_NAME, "");
2819:                }
2820:                pExecution.updateDatasetInModel(pDataSet);
2821:
2822:                Element envElem = execElem.element("EnvironnementEx");
2823:                String nomEnvXML = envElem.elementText("Nom");
2824:
2825:                Environment pEnvironement = project
2826:                        .getEnvironmentFromModel(nomEnvXML);
2827:                pExecution.updateEnvInModel(pEnvironement);
2828:
2829:                User pUser = null;
2830:                if (idialog != null) {
2831:                    pUser = DataModel.getCurrentUser();
2832:                } else {
2833:                    pUser = project.getAdministratorFromModel();
2834:                }
2835:                try {
2836:                    pCamp.addExecutionInDBAndModel(pExecution, pUser);
2837:
2838:                    //Ajout des scripts
2839:                    Element scriptPre = (Element) execElem
2840:                            .selectSingleNode("Script[1]");
2841:                    if (scriptPre != null) {
2842:                        ajouterScriptToExec(scriptPre, pExecution);
2843:                    }
2844:                    Element scriptPost = (Element) execElem
2845:                            .selectSingleNode("Script[2]");
2846:                    if (scriptPost != null) {
2847:                        ajouterScriptToExec(scriptPost, pExecution);
2848:                    }
2849:
2850:                    //ajouter les attachements
2851:                    ajouterAttachements(execElem, pExecution);
2852:
2853:                    /***** Plugin update Execution Data *****/
2854:                    int size = listXMLPlugin.size();
2855:                    for (int i = 0; i < size; i++) {
2856:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
2857:                                .elementAt(i);
2858:                        if (idialog != null) {
2859:                            pXMLPrinterPlugin.updateExecutionFromXML(execElem,
2860:                                    pExecution, idialog.isSupprElement(), this );
2861:                        } else {
2862:                            pXMLPrinterPlugin.updateExecutionFromXML(execElem,
2863:                                    pExecution, false, this );
2864:                        }
2865:                    }
2866:                    /***** (END) Plugin update Execution Data *****/
2867:
2868:                    //ajouter les résultats d'exécutions
2869:                    ajouterResulExecs(execElem, pExecution);
2870:                } catch (Exception e) {
2871:                    Tools.ihmExceptionView(e);
2872:                }
2873:
2874:            }
2875:
2876:            /**
2877:             * Méthode qui ajoute un script à une exécution
2878:             * @param script élément script du document XML
2879:             * @param id_exec identifiant de l'exécution
2880:             */
2881:            public void ajouterScriptToExec(Element script, Execution pExecution)
2882:                    throws Exception {
2883:                String classpath = script.elementText("Classpath");
2884:                String argScript = script.elementText("ArgScript");
2885:                String type = script.attributeValue("type");
2886:                String dirScript = script.attributeValue("dir");
2887:                dirScript = restorePath(dirScript);
2888:                File fScript = new File(dirXml + File.separator + dirScript);
2889:
2890:                Script pScritp = new Script(fScript.getName(), "");
2891:                pScritp.setTypeInModel(type);
2892:                pScritp.setScriptExtensionInModel(classpath);
2893:                pScritp.updatePlugArgInModel(argScript);
2894:                try {
2895:                    pExecution.addScriptInDBAndModel(pScritp, fScript);
2896:                } catch (Exception e) {
2897:                    Tools.ihmExceptionView(e);
2898:                }
2899:            }
2900:
2901:            /**
2902:             * Méthode qui rajoute les résultats d'exécution à une campagne
2903:             * @param execElem élément représentant l'exécution d'une campagne dans le document XML
2904:             * @param id_exec identifiant de l'exécution dans la BD
2905:             * @param campName nom de la campagne qui contient l'exécution
2906:             */
2907:            public void ajouterResulExecs(Element execElem, Execution pExecution)
2908:                    throws Exception {
2909:                List<Element> resulExecListXML = execElem
2910:                        .selectNodes("ResulExecCampTests/ResulExecCampTest");
2911:                for (Element rexecElem : resulExecListXML) {
2912:                    ajouterResulExec(rexecElem, pExecution);
2913:
2914:                }
2915:            }
2916:
2917:            /**
2918:             * Méthode qui rajoute un résultat d'exécution à une exécution
2919:             * @param rexecElem élément représentant le résultat d'exécution d'une campagne dans le document XML
2920:             * @param pExecution exécution dans la DB
2921:             */
2922:            private void ajouterResulExec(Element rexecElem,
2923:                    Execution pExecution) throws Exception {
2924:
2925:                String nom = rexecElem.elementText("Nom");
2926:                String description = (rexecElem.elementText("Description") != null) ? rexecElem
2927:                        .elementText("Description")
2928:                        : "";
2929:                description = description.replaceAll("\\\\n", "\n");
2930:                String resultat = rexecElem.attributeValue("statut");
2931:                Element resExecElem = rexecElem.element("ResulExecs");
2932:                User pUser = null;
2933:                if (idialog != null) {
2934:                    pUser = DataModel.getCurrentUser();
2935:                } else {
2936:                    pUser = project.getAdministratorFromModel();
2937:                }
2938:                ExecutionResult pExecutionResult = new ExecutionResult(nom,
2939:                        description, pExecution);
2940:                pExecutionResult.setExecutionStatusInModel(resultat);
2941:                pExecution.addExecutionResultInDBAndModel(pExecutionResult,
2942:                        pUser);
2943:
2944:                ajouterAttachements(rexecElem, pExecutionResult);
2945:                if (resExecElem != null) {
2946:                    List<Element> execCasList = resExecElem
2947:                            .selectNodes("ResulExec");
2948:                    for (Element execCasElem : execCasList) {
2949:                        String res = execCasElem.attributeValue("res");
2950:                        Element refTest = execCasElem.element("RefTest");
2951:                        String nomTest = refTest.elementText("NomTest");
2952:                        String nomSuite = refTest.elementText("NomSuite");
2953:                        String nomFamille = refTest.elementText("NomFamille");
2954:
2955:                        Test pTest = project.getTestFromModel(nomFamille,
2956:                                nomSuite, nomTest);
2957:                        ExecutionTestResult pExecutionTestResult = pExecutionResult
2958:                                .initTestResultStatusInModel(pTest, res, 0,
2959:                                        pExecution.getCampagneFromModel());
2960:                        if (!pExecutionTestResult.isInBase()) {
2961:                            pExecutionResult.addExecTestResultInDB(pTest);
2962:                        }
2963:                        ajouterAttachements(execCasElem, pExecutionTestResult);
2964:
2965:                    }
2966:                }
2967:
2968:                List<Element> resActionList = rexecElem
2969:                        .selectNodes("ResulActionTests/ResulActionTest");
2970:                for (Element resAction : resActionList) {
2971:                    Element refAction = resAction.element("RefAction");
2972:                    String nomAction = refAction.elementText("NomAction");
2973:                    String nomTest = refAction.elementText("NomTest");
2974:                    String nomSuite = refAction.elementText("NomSuite");
2975:                    String nomFamille = refAction.elementText("NomFamille");
2976:
2977:                    Test pTest = project.getTestFromModel(nomFamille, nomSuite,
2978:                            nomTest);
2979:                    Action pAction = ((ManualTest) pTest)
2980:                            .getActionFromModel(nomAction);
2981:                    ManualExecutionResult pManualExecutionResult = (ManualExecutionResult) pExecutionResult
2982:                            .getExecutionTestResultFromModel(pTest);
2983:                    if (!pManualExecutionResult.isInBase()) {
2984:                        pExecutionResult
2985:                                .addExecTestResultInDB((ManualTest) pTest);
2986:                    }
2987:                    String resultatAction = resAction.attributeValue("res");
2988:                    if (resultatAction.equals("NonRenseigne")) {
2989:                        resultatAction = "";
2990:                    }
2991:                    String descAction = (resAction.elementText("Description") == null) ? ""
2992:                            : resAction.elementText("Description");
2993:                    String resulAttendu = (resAction
2994:                            .elementText("ResultAttendu") == null) ? ""
2995:                            : resAction.elementText("ResultAttendu");
2996:                    String effectiveAttendu = (resAction
2997:                            .elementText("ResulEffectif") == null) ? ""
2998:                            : resAction.elementText("ResulEffectif");
2999:
3000:                    descAction = descAction.replaceAll("\\\\n", "\n");
3001:                    resulAttendu = resulAttendu.replaceAll("\\\\n", "\n");
3002:                    effectiveAttendu = effectiveAttendu.replaceAll("\\\\n",
3003:                            "\n");
3004:
3005:                    //ConnectionData.getCampTestInsert().addResExecActionUsingID(id_exec_res, id_test, id_action, resultatAction, descAction, resulAttendu);
3006:
3007:                    pManualExecutionResult.addStatusForActionInModel(pAction,
3008:                            resultatAction);
3009:                    pManualExecutionResult.addEffectivResultInModel(pAction,
3010:                            effectiveAttendu);
3011:                    pManualExecutionResult.addDescriptionResultInModel(pAction,
3012:                            descAction);
3013:                    pManualExecutionResult.addAwaitedResultInModel(pAction,
3014:                            resulAttendu);
3015:                    pExecutionResult.addExecActionResultInDB(pTest, pAction);
3016:                    //pManualExecutionResult.addActionResultInDB(pAction);
3017:
3018:                }
3019:
3020:                /***** Plugin update ExecutionResult Data *****/
3021:                int size = listXMLPlugin.size();
3022:                for (int i = 0; i < size; i++) {
3023:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
3024:                            .elementAt(i);
3025:                    if (idialog != null) {
3026:                        pXMLPrinterPlugin.updateResExecutionFromXML(rexecElem,
3027:                                pExecutionResult, idialog.isSupprElement(),
3028:                                this );
3029:                    } else {
3030:                        pXMLPrinterPlugin.updateResExecutionFromXML(rexecElem,
3031:                                pExecutionResult, false, this );
3032:                    }
3033:                }
3034:                /***** (END) Plugin update ExecutionResult Data *****/
3035:            }
3036:
3037:            /**
3038:             * Method which detects if the campaign in database must be copied or not.
3039:             * The campaign in database must be copied if it contains tests 
3040:             * which have been saved in the test plan or it does not contain the same tests.
3041:             * @param campaign campaign in DB
3042:             * @param campElem campaign in XML document
3043:             * @return
3044:             */
3045:            public boolean mustKeepCopy(Campaign campaign, Element campElem)
3046:                    throws Exception {
3047:                //tests list
3048:                ArrayList<Test> testList = campaign.getTestListFromModel();
3049:                List<Element> testListXML = campElem
3050:                        .selectNodes("FamillesCamp/FamilleRef/SuiteTestsCamp/SuiteTestRef/TestsCamp/TestRef");
3051:                for (Test test : testList) {
3052:                    if (savedTests.contains(test)) {
3053:                        return true;
3054:                    }
3055:                    boolean belong = false;
3056:                    Iterator<Element> itTestListXML = testListXML.iterator();
3057:                    while (itTestListXML.hasNext() && !belong) {
3058:                        Element testRef = itTestListXML.next();
3059:                        String nomTest = testRef.elementText("Nom");
3060:                        String nomSuite = ((Element) testRef
3061:                                .selectSingleNode("ancestor::SuiteTestRef[1]"))
3062:                                .elementText("Nom");
3063:                        String nomFamille = ((Element) testRef
3064:                                .selectSingleNode("ancestor::FamilleRef[1]"))
3065:                                .elementText("Nom");
3066:                        String suiteName = test.getTestListFromModel()
3067:                                .getNameFromModel();
3068:                        String familyName = test.getTestListFromModel()
3069:                                .getFamilyFromModel().getNameFromModel();
3070:                        if (test.getNameFromModel().equals(nomTest)
3071:                                && suiteName.equals(nomSuite)
3072:                                && familyName.equals(nomFamille)) {
3073:                            belong = true;
3074:                        }
3075:                    }
3076:                    if (!belong) {
3077:                        return true;
3078:                    }
3079:                }
3080:                if (testListXML.size() != testList.size()) {
3081:                    return true;
3082:                }
3083:                for (Element testRef : testListXML) {
3084:                    String nomTest = testRef.elementText("Nom");
3085:                    String nomSuite = ((Element) testRef
3086:                            .selectSingleNode("ancestor::SuiteTestRef[1]"))
3087:                            .elementText("Nom");
3088:                    String nomFamille = ((Element) testRef
3089:                            .selectSingleNode("ancestor::FamilleRef[1]"))
3090:                            .elementText("Nom");
3091:                    boolean appartient = false;
3092:                    Iterator<Test> itTestList = testList.iterator();
3093:                    while (itTestList.hasNext() && !appartient) {
3094:                        Test test = itTestList.next();
3095:                        String suiteName = test.getTestListFromModel()
3096:                                .getNameFromModel();
3097:                        String familyName = test.getTestListFromModel()
3098:                                .getFamilyFromModel().getNameFromModel();
3099:                        if (test.getNameFromModel().equals(nomTest)
3100:                                && suiteName.equals(nomSuite)
3101:                                && familyName.equals(nomFamille)) {
3102:                            appartient = true;
3103:                        }
3104:                    }
3105:                    if (!appartient) {
3106:                        return true;
3107:                    }
3108:                }
3109:
3110:                //description
3111:                String descriptionXML = "";
3112:                Element descElem = campElem.element("Description");
3113:                if (descElem != null && descElem.hasContent()) {
3114:                    descriptionXML = campElem.element("Description").asXML();
3115:                    descriptionXML = getTextFromChildren(campElem
3116:                            .element("Description"), "");
3117:                }
3118:                String descriptionDB = campaign.getDescriptionFromModel();
3119:                if (descriptionDB != null && !descriptionDB.equals("")) {
3120:                    descriptionDB = descriptionDB.replaceAll("<br>", "<br/>");
3121:                    if (!descriptionDB.startsWith("<html>")) {
3122:                        descriptionDB = "<html>" + descriptionDB + "</html>";
3123:                    }
3124:                    Document document = DocumentHelper.parseText(descriptionDB);
3125:                    descriptionDB = getTextFromChildren(document
3126:                            .getRootElement(), "");
3127:                }
3128:                if (descriptionDB == null)
3129:                    descriptionDB = "";
3130:                if (!descriptionXML.equals(descriptionDB)) {
3131:                    return true;
3132:                }
3133:
3134:                //attachments
3135:                List<Element> urlAttachementList = campElem
3136:                        .selectNodes("Attachements/UrlAttachement");
3137:                HashMap<String, Attachment> envMap = campaign
3138:                        .getAttachmentMapFromModel();
3139:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
3140:                for (Element urlElem : urlAttachementList) {
3141:                    String url = urlElem.attributeValue("url");
3142:                    boolean belong = false;
3143:                    for (Attachment attach : envMap.values()) {
3144:                        if ((attach instanceof  UrlAttachment)
3145:                                && ((UrlAttachment) attach).getNameFromModel()
3146:                                        .equals(url)) {
3147:                            belong = true;
3148:                        }
3149:                    }
3150:                    if (!belong) {
3151:                        return true;
3152:                    }
3153:                }
3154:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
3155:                for (Attachment attach : envMap.values()) {
3156:                    if (attach instanceof  UrlAttachment) {
3157:                        boolean belong = false;
3158:                        String url = ((UrlAttachment) attach)
3159:                                .getNameFromModel();
3160:                        for (Element urlElem : urlAttachementList) {
3161:                            if (url.equals(urlElem.attributeValue("url"))) {
3162:                                belong = true;
3163:                            }
3164:                        }
3165:                        if (!belong) {
3166:                            return true;
3167:                        }
3168:                    }
3169:                }
3170:
3171:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
3172:                List<Element> fileAttachmentList = campElem
3173:                        .selectNodes("Attachements/FileAttachement");
3174:                for (Element fileElem : fileAttachmentList) {
3175:                    String nom = fileElem.attributeValue("nom");
3176:                    boolean belong = false;
3177:                    for (Attachment attach : envMap.values()) {
3178:                        if ((attach instanceof  FileAttachment)
3179:                                && ((FileAttachment) attach).getNameFromModel()
3180:                                        .equals(nom)) {
3181:                            belong = true;
3182:                        }
3183:                    }
3184:                    if (!belong) {
3185:                        return true;
3186:                    }
3187:                }
3188:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
3189:                for (Attachment attach : envMap.values()) {
3190:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
3191:                    boolean belong = false;
3192:                    for (Element fileElem : fileAttachmentList) {
3193:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
3194:                            belong = true;
3195:                        }
3196:                    }
3197:                    if (!belong) {
3198:                        return true;
3199:                    }
3200:                }
3201:
3202:                //data sets
3203:                List<Element> dataSetList = campElem
3204:                        .selectNodes("JeuxDonnees/JeuDonnees");
3205:                for (Element dataSetElem : dataSetList) {
3206:                    String dataSetName = dataSetElem.elementText("Nom");
3207:                    ArrayList<DataSet> datasets = campaign
3208:                            .getDataSetListFromModel();
3209:                    boolean belong = false;
3210:                    Iterator<DataSet> itDataSet = datasets.iterator();
3211:                    while (itDataSet.hasNext() && !belong) {
3212:                        DataSet dataSet = itDataSet.next();
3213:                        if (dataSetName.equals(dataSet.getNameFromModel())) {
3214:                            belong = true;
3215:                            String dataSetDescription = dataSetElem
3216:                                    .elementText("Description");
3217:                            if (!dataSetDescription.equals(dataSet
3218:                                    .getDescriptionFromModel())) {
3219:                                return true;
3220:                            }
3221:                            List<Element> paramList = dataSetElem
3222:                                    .selectNodes("ValeurParams/ValeurParam");
3223:                            for (Element paramElem : paramList) {
3224:                                String paramName = paramElem.elementText("Nom");
3225:                                boolean belong2 = false;
3226:                                HashMap<String, String> paramHashMap = dataSet
3227:                                        .getParametersHashMapFromModel();
3228:                                Iterator<String> itparam = paramHashMap
3229:                                        .keySet().iterator();
3230:                                while (itparam.hasNext() && !belong2) {
3231:                                    String paramNom = itparam.next();
3232:                                    if (paramNom.equals(paramName)) {
3233:                                        belong2 = true;
3234:                                        String paramValue = paramElem
3235:                                                .attributeValue("valeur");
3236:                                        String paramValeur = paramHashMap
3237:                                                .get(paramNom);
3238:                                        if (paramValue != null
3239:                                                && !paramValue
3240:                                                        .equals(paramValeur)) {
3241:                                            return true;
3242:                                        }
3243:                                    }
3244:                                }
3245:                                if (!belong2) {
3246:                                    return true;
3247:                                }
3248:                            }
3249:                        }
3250:                    }
3251:                    if (!belong) {
3252:                        return true;
3253:                    }
3254:                }
3255:                ArrayList<DataSet> datasets = campaign
3256:                        .getDataSetListFromModel();
3257:                for (DataSet dataSet : datasets) {
3258:                    boolean belong = false;
3259:                    Iterator<Element> itDataSet = dataSetList.iterator();
3260:                    while (itDataSet.hasNext() && !belong) {
3261:                        Element dataSetElem = itDataSet.next();
3262:                        String dataSetName = dataSetElem.elementText("Nom");
3263:                        if (dataSetName.equals(dataSet.getNameFromModel())) {
3264:                            belong = true;
3265:                        }
3266:                    }
3267:                    if (!belong) {
3268:                        return true;
3269:                    }
3270:                }
3271:                return false;
3272:            }
3273:
3274:            /**
3275:             * Method which detects if the execution in database must be copied or not.
3276:             * @param exec execution in DB
3277:             * @param execElem execution in XML document
3278:             * @return
3279:             */
3280:            private boolean mustKeepCopy(Execution exec, Element execElem)
3281:                    throws Exception {
3282:                //attachments
3283:                List<Element> urlAttachementList = execElem
3284:                        .selectNodes("Attachements/UrlAttachement");
3285:                HashMap<String, Attachment> envMap = exec
3286:                        .getAttachmentMapFromModel();
3287:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
3288:                for (Element urlElem : urlAttachementList) {
3289:                    String url = urlElem.attributeValue("url");
3290:                    boolean belong = false;
3291:                    for (Attachment attach : envMap.values()) {
3292:                        if ((attach instanceof  UrlAttachment)
3293:                                && ((UrlAttachment) attach).getNameFromModel()
3294:                                        .equals(url)) {
3295:                            belong = true;
3296:                        }
3297:                    }
3298:                    if (!belong) {
3299:                        return true;
3300:                    }
3301:                }
3302:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
3303:                for (Attachment attach : envMap.values()) {
3304:                    if (attach instanceof  UrlAttachment) {
3305:                        boolean belong = false;
3306:                        String url = ((UrlAttachment) attach)
3307:                                .getNameFromModel();
3308:                        for (Element urlElem : urlAttachementList) {
3309:                            if (url.equals(urlElem.attributeValue("url"))) {
3310:                                belong = true;
3311:                            }
3312:                        }
3313:                        if (!belong) {
3314:                            return true;
3315:                        }
3316:                    }
3317:                }
3318:
3319:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
3320:                List<Element> fileAttachmentList = execElem
3321:                        .selectNodes("Attachements/FileAttachement");
3322:                for (Element fileElem : fileAttachmentList) {
3323:                    String nom = fileElem.attributeValue("nom");
3324:                    boolean belong = false;
3325:                    for (Attachment attach : envMap.values()) {
3326:                        if ((attach instanceof  FileAttachment)
3327:                                && ((FileAttachment) attach).getNameFromModel()
3328:                                        .equals(nom)) {
3329:                            belong = true;
3330:                        }
3331:                    }
3332:                    if (!belong) {
3333:                        return true;
3334:                    }
3335:                }
3336:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
3337:                for (Attachment attach : envMap.values()) {
3338:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
3339:                    boolean belong = false;
3340:                    for (Element fileElem : fileAttachmentList) {
3341:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
3342:                            belong = true;
3343:                        }
3344:                    }
3345:                    if (!belong) {
3346:                        return true;
3347:                    }
3348:                }
3349:
3350:                //dataset
3351:                Element jeuDonneesElem = execElem.element("JeuDonneesEx");
3352:                if (jeuDonneesElem != null) {
3353:                    String idExec = jeuDonneesElem.attributeValue("ref");
3354:                    if (idExec != null) {
3355:                        Element datasetElem = (Element) doc.getRootElement()
3356:                                .selectSingleNode(
3357:                                        "//JeuDonnees[@id_jeu='" + idExec
3358:                                                + "']");
3359:                        String datasetName = datasetElem.elementText("Nom");
3360:                        if (exec.getDataSetFromModel() == null
3361:                                || exec.getDataSetFromModel() != null
3362:                                && !datasetName.equals(exec
3363:                                        .getDataSetFromModel()
3364:                                        .getNameFromModel())) {
3365:                            return true;
3366:                        }
3367:                    }
3368:                }
3369:
3370:                //environment
3371:                String idEnv = execElem.element("EnvironnementEx")
3372:                        .attributeValue("ref");
3373:                Element envElem = (Element) doc.getRootElement()
3374:                        .selectSingleNode(
3375:                                "//Environnement[@idEnv='" + idEnv + "']");
3376:                String envName = envElem.elementText("Nom");
3377:                if (!envName.equals(exec.getEnvironmentFromModel()
3378:                        .getNameFromModel())) {
3379:                    return true;
3380:                }
3381:
3382:                //pre-script
3383:                Element preScriptElem = (Element) execElem
3384:                        .selectSingleNode("Script[@type='PRE_SCRIPT']");
3385:                if (preScriptElem != null) {
3386:                    Script preScript = exec.getPreScriptFromModel();
3387:                    if (preScript == null) {
3388:                        return true;
3389:                    } else {//compare md5
3390:                        File tempScriptFile = preScript.getFileFromDB(null);
3391:                        File fromXMLScriptFile = new File(dirXml
3392:                                + File.separator
3393:                                + preScriptElem.attributeValue("dir"));
3394:                        String md5DBScript = getDigest(tempScriptFile);
3395:                        String md5XMLScript = getDigest(fromXMLScriptFile);
3396:                        if (!md5DBScript.equals(md5XMLScript)) {
3397:                            return true;
3398:                        }
3399:                        tempScriptFile.delete();
3400:                    }
3401:                }
3402:
3403:                //post-script
3404:                Element postScriptElem = (Element) execElem
3405:                        .selectSingleNode("Script[@type='POST_SCRIPT']");
3406:                if (postScriptElem != null) {
3407:                    Script postScript = exec.getPostScriptFromModel();
3408:                    if (postScript == null) {
3409:                        return true;
3410:                    } else {//compare md5
3411:                        File tempScriptFile = postScript.getFileFromDB(null);
3412:                        File fromXMLScriptFile = new File(dirXml
3413:                                + File.separator
3414:                                + preScriptElem.attributeValue("dir"));
3415:                        String md5DBScript = getDigest(tempScriptFile);
3416:                        String md5XMLScript = getDigest(fromXMLScriptFile);
3417:                        if (!md5DBScript.equals(md5XMLScript)) {
3418:                            return true;
3419:                        }
3420:                        tempScriptFile.delete();
3421:                    }
3422:                }
3423:
3424:                return false;
3425:            }
3426:
3427:            /**
3428:             * Method which detects if the execution result in database must be copied or not.
3429:             * @param resExec execution result in DB
3430:             * @param resExecElem execution result in XML document
3431:             * @return
3432:             */
3433:            private boolean mustKeepCopy(ExecutionResult resExec,
3434:                    Element resExecElem) throws Exception {
3435:                //testeur
3436:                String testeur = resExecElem.elementText("Testeur");
3437:                if (testeur != null
3438:                        && !testeur.equals(resExec.getTesterFromModel())) {
3439:                    return true;
3440:                }
3441:
3442:                //attachements
3443:                List<Element> urlAttachementList = resExecElem
3444:                        .selectNodes("Attachements/UrlAttachement");
3445:                HashMap<String, Attachment> envMap = resExec
3446:                        .getAttachmentMapFromModel();
3447:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
3448:                for (Element urlElem : urlAttachementList) {
3449:                    String url = urlElem.attributeValue("url");
3450:                    boolean belong = false;
3451:                    for (Attachment attach : envMap.values()) {
3452:                        if ((attach instanceof  UrlAttachment)
3453:                                && ((UrlAttachment) attach).getNameFromModel()
3454:                                        .equals(url)) {
3455:                            belong = true;
3456:                        }
3457:                    }
3458:                    if (!belong) {
3459:                        return true;
3460:                    }
3461:                }
3462:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
3463:                for (Attachment attach : envMap.values()) {
3464:                    if (attach instanceof  UrlAttachment) {
3465:                        boolean belong = false;
3466:                        String url = ((UrlAttachment) attach)
3467:                                .getNameFromModel();
3468:                        for (Element urlElem : urlAttachementList) {
3469:                            if (url.equals(urlElem.attributeValue("url"))) {
3470:                                belong = true;
3471:                            }
3472:                        }
3473:                        if (!belong) {
3474:                            return true;
3475:                        }
3476:                    }
3477:                }
3478:
3479:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
3480:                List<Element> fileAttachmentList = resExecElem
3481:                        .selectNodes("Attachements/FileAttachement");
3482:                for (Element fileElem : fileAttachmentList) {
3483:                    String nom = fileElem.attributeValue("nom");
3484:                    boolean belong = false;
3485:                    for (Attachment attach : envMap.values()) {
3486:                        if ((attach instanceof  FileAttachment)
3487:                                && ((FileAttachment) attach).getNameFromModel()
3488:                                        .equals(nom)) {
3489:                            belong = true;
3490:                        }
3491:                    }
3492:                    if (!belong) {
3493:                        return true;
3494:                    }
3495:                }
3496:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
3497:                for (Attachment attach : envMap.values()) {
3498:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
3499:                    boolean belong = false;
3500:                    for (Element fileElem : fileAttachmentList) {
3501:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
3502:                            belong = true;
3503:                        }
3504:                    }
3505:                    if (!belong) {
3506:                        return true;
3507:                    }
3508:                }
3509:
3510:                //resulExec
3511:                List<Element> resulExecList = resExecElem
3512:                        .selectNodes("ResulExecs/ResulExec");
3513:                for (Element resulExec : resulExecList) {
3514:                    String idResulExecString = resulExec
3515:                            .attributeValue("refTest");
3516:                    int idResulExec = new Integer(idResulExecString
3517:                            .substring(5)).intValue();
3518:                    Test test = project.getTestFromModel(idResulExec);
3519:                    ExecutionTestResult testResult = resExec
3520:                            .getExecutionTestResultFromModel(test);
3521:                    String res = resulExec.attributeValue("res");
3522:                    String status = testResult.getStatusFromModel();
3523:                    if (res != null
3524:                            && (res.equals("PASSED") || res.equals("FAILED") || res
3525:                                    .equals("INCONCLUSIF"))) {
3526:                        if (!res.equals(status)) {
3527:                            return true;
3528:                        }
3529:                    } else if ((res == null || res.equals("") || res
3530:                            .equals("NonRenseigne"))
3531:                            && !status.equals("")) {
3532:                        return true;
3533:                    }
3534:                }
3535:
3536:                //resultActionTest
3537:                List<Element> resulActionTestList = resExecElem
3538:                        .selectNodes("ResulActionTests/ResulActionTest");
3539:                for (Element resulActionElem : resulActionTestList) {
3540:                    String idActionString = resulActionElem
3541:                            .attributeValue("refAction");
3542:                    String actionName = resulActionElem.element("RefAction")
3543:                            .elementText("NomAction");
3544:                    Element actionElem = (Element) doc.getRootElement()
3545:                            .selectSingleNode(
3546:                                    "//ActionTest[@id_action='"
3547:                                            + idActionString + "']");
3548:                    Element testElem = actionElem.getParent().getParent();
3549:                    String idTestString = testElem.attributeValue("id_test");
3550:                    int idTest = new Integer(idTestString.substring(5))
3551:                            .intValue();
3552:                    Test test = project.getTestFromModel(idTest);
3553:                    if (test instanceof  ManualTest) {
3554:                        Action action = ((ManualTest) test)
3555:                                .getActionFromModel(actionName);
3556:                        ExecutionTestResult pExecutionTestResult = resExec
3557:                                .getExecutionTestResultFromModel(test);
3558:                        if (pExecutionTestResult instanceof  ManualExecutionResult) {
3559:                            ManualExecutionResult pManualExecutionResult = (ManualExecutionResult) pExecutionTestResult;
3560:                            HashMap<Action, String> actionMap = pManualExecutionResult
3561:                                    .getActionsMapInModel();
3562:                            String resBD = actionMap.get(action);
3563:                            String resXML = resulActionElem
3564:                                    .attributeValue("res");
3565:                            if (resXML != null
3566:                                    && (resXML.equals("PASSED")
3567:                                            || resXML.equals("FAILED") || resXML
3568:                                            .equals("INCONCLUSIF"))) {
3569:                                if (!resXML.equals(resBD)) {
3570:                                    return true;
3571:                                }
3572:                            } else if ((resXML == null || resXML.equals("") || resXML
3573:                                    .equals("NonRenseigne"))
3574:                                    && !resBD.equals("")) {
3575:                                return true;
3576:                            }
3577:                        } else {
3578:                            return true;
3579:                        }
3580:                    } else {
3581:                        return true;
3582:                    }
3583:                }
3584:                return false;
3585:            }
3586:
3587:            private String restorePath(String path) throws Exception {
3588:                if (File.separator.equals("\\")) {
3589:                    //Unix2Windows
3590:                    return path.replace('/', '\\');
3591:                } else {
3592:                    return path.replace('\\', '/');
3593:                }
3594:            }
3595:
3596:            /**
3597:             * Cancel the current task
3598:             * @param b
3599:             */
3600:            public void setAnnule(boolean b) {
3601:                cancelled = b;
3602:            }
3603:
3604:            /**
3605:             * Verify if the task was cancelled
3606:             * @return
3607:             */
3608:            public boolean isAnnule() {
3609:                return cancelled;
3610:            }
3611:
3612:            /**
3613:             * Set the field defines if campaigns are also imported
3614:             * @param selected
3615:             */
3616:            public void setImportCampaign(boolean importCampaign) {
3617:                this .importCampaign = importCampaign;
3618:            }
3619:
3620:            /**
3621:             * Set the directory where the XML file is
3622:             * @param dirXml
3623:             */
3624:            public void setDirXml(String dirXml) {
3625:                this .dirXml = dirXml;
3626:            }
3627:
3628:            /**
3629:             * Return true if the list of selected tests was initialized
3630:             * @return
3631:             */
3632:            public boolean isInitSelection() {
3633:                return initSelection;
3634:            }
3635:
3636:            /**
3637:             * True in parameter if the test selection has been already initialized
3638:             * @param initSelection
3639:             */
3640:            public void setInitSelection(boolean initSelection) {
3641:                this.initSelection = initSelection;
3642:            }
3643:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.