Source Code Cross Referenced for ImportXML2.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » pluginxlsxml » Import » 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.pluginxlsxml.Import 
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.pluginxlsxml.Import;
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 ImportXLSDialog 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 ImportDialog){
0139:                //		idialog=(ImportDialog)dialog;
0140:                //	}else 
0141:                if (dialog instanceof  ImportXLSDialog) {
0142:                    idialog = (ImportXLSDialog) dialog;
0143:                } else {
0144:                    cdialog = (CreateProjectDialog) dialog;
0145:                }
0146:            }
0147:
0148:            /**
0149:             * Launch the import process
0150:             * @throws Exception 
0151:             */
0152:            public void importInProject() throws Exception {
0153:                project = DataModel.getCurrentProject(); //Add for V2
0154:                DataModel.reloadFromBase(false);
0155:
0156:                if (idialog.isSupprElement() && !cancelled) {
0157:                    projectDeletions();
0158:                    testsDeletions();
0159:                    campaignsDeletions();
0160:
0161:                    /***** Plugin manage XML delete for Project *****/
0162:                    int size = listXMLPlugin.size();
0163:                    for (int i = 0; i < size; i++) {
0164:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0165:                                .elementAt(i);
0166:                        pXMLPrinterPlugin.manageDelete(doc, this );
0167:                    }
0168:                }
0169:
0170:                coreImport();
0171:
0172:                DataModel.reloadFromBase(true);
0173:
0174:                /***** Plugin manage XML refresh *****/
0175:                int size = listXMLPlugin.size();
0176:                for (int i = 0; i < size; i++) {
0177:                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
0178:                            .elementAt(i);
0179:                    pXMLPrinterPlugin.refreshNewData();
0180:                }
0181:                /***** (END) Plugin manage XML refresh *****/
0182:
0183:            }
0184:
0185:            /**
0186:             * Launch the import process from the createDialog in Administration of Salome
0187:             * @throws Exception
0188:             */
0189:            public void importInNewProject() throws Exception {
0190:                newProject = true;
0191:                ArrayList<Object> data = new ArrayList<Object>();
0192:                project = cdialog.getNewProject();
0193:                if (project != null && !cancelled) {
0194:                    if (Api.isConnected()) {
0195:                        try {
0196:                            project.addInDB();
0197:                            project.setUserInModel(project
0198:                                    .getAdministratorFromModel());
0199:
0200:                            data.add(Tools.createAppletImageIcon(
0201:                                    PATH_TO_PROJECT_ICON, ""));
0202:                            data.add(project.getNameFromModel().trim());
0203:                            data.add(project.getAdministratorFromModel()
0204:                                    .getLoginFromModel());
0205:                            data.add(project.getCreationDateFromModel()
0206:                                    .toString());
0207:                            data.add(project.getDescriptionFromModel());
0208:                            JTable projectTable = (JTable) Administration
0209:                                    .getUIComponent(UICompCst.ADMIN_PROJECT_MANAGEMENT_TABLE);
0210:                            ((MyTableModel) projectTable.getModel())
0211:                                    .addRow(data);
0212:                            project.setUserInModel(project
0213:                                    .getAdministratorFromModel());
0214:                            pAdminVTData.addProjectInModel(project);
0215:                            pAdminVTData.addAdminToProjectInModel(project
0216:                                    .getAdministratorFromModel(), project);
0217:                            projectTable.getColumnModel().getColumn(0)
0218:                                    .setMaxWidth(18);
0219:                        } catch (Exception exception) {
0220:                            cdialog
0221:                                    .setErrorMessage(cdialog.getErrorMessage()
0222:                                            + Language
0223:                                                    .getInstance()
0224:                                                    .getText(
0225:                                                            "Problème_lors_de_la_création_du_nouveau_projet"));
0226:                            cdialog.showErrorMessage();
0227:                            setAnnule(true);
0228:                        }
0229:                    }
0230:                }
0231:
0232:                if (!cancelled) {
0233:                    coreImport();
0234:                }
0235:            }
0236:
0237:            /**
0238:             * Delete attachments of project which are in database and not in XML document.
0239:             */
0240:            private void projectDeletions() throws Exception {
0241:                Element projectElem = (Element) doc
0242:                        .selectSingleNode("//ProjetVT");
0243:                attachmentDeletions(projectElem, project);
0244:            }
0245:
0246:            /**
0247:             * Delete elements of test plan which are in database and not 
0248:             * in XML document
0249:             * @throws Exception 
0250:             */
0251:            private void testsDeletions() throws Exception {
0252:                //Deletion of project parameters
0253:                parameterDeletion();
0254:                if (cancelled) {
0255:                    throw new Exception("[ImportAlgo->suppressionParameter]");
0256:                }
0257:
0258:                //Deletion of environments
0259:                environmentDeletion();
0260:                if (cancelled) {
0261:                    throw new Exception(
0262:                            "[ImportAlgo->suppressionEnvironnement]");
0263:                }
0264:
0265:                //deletion of families
0266:                familyDeletion();
0267:                if (cancelled) {
0268:                    throw new Exception("[ImportAlgo->suppressionFamily]");
0269:                }
0270:            }
0271:
0272:            /**
0273:             * Delete elements of campaigns which are in database
0274:             * and not in XML document
0275:             * @throws Exception
0276:             */
0277:            private void campaignsDeletions() throws Exception {
0278:                ArrayList<Campaign> campList = project
0279:                        .getCampaignListFromModel();
0280:                ArrayList<Campaign> campToRemove = new ArrayList<Campaign>();
0281:                List<Element> campListXML = doc.selectNodes("//CampagneTest");
0282:                Element campElem = null;
0283:                Iterator<Campaign> itCamp = campList.iterator();
0284:                while (itCamp.hasNext() && !cancelled) {
0285:                    Campaign camp = (Campaign) itCamp.next();
0286:                    boolean belong = false;
0287:                    Iterator<Element> itCampXML = campListXML.iterator();
0288:                    while (itCampXML.hasNext() && !belong) {
0289:                        campElem = itCampXML.next();
0290:                        if (campElem.elementText("Nom").equals(
0291:                                camp.getNameFromModel())) {
0292:                            belong = true;
0293:                        }
0294:                    }
0295:                    if (!belong) {
0296:                        campToRemove.add(camp);
0297:                    } else {
0298:                        //suppression des jeux de données
0299:                        dataSetDeletion(campElem, camp);
0300:
0301:                        //suppression des attachements des campagnes
0302:                        attachmentDeletions(campElem, camp);
0303:
0304:                        //suppression Tests
0305:                        testInCampDeletion(campElem, camp);
0306:
0307:                        //suppression Exécutions -> suppression résultats d'exécution
0308:                        execInCampDeletion(campElem, camp);
0309:                    }
0310:                }
0311:                Iterator<Campaign> itCampRm = campToRemove.iterator();
0312:                while (itCampRm.hasNext() && !cancelled) {
0313:                    Campaign campRm = itCampRm.next();
0314:                    try {
0315:                        project.deleteCampaignInDBAndModel(campRm);
0316:                    } catch (Exception e) {
0317:                        Tools.ihmExceptionView(e);
0318:                        throw e;
0319:                    }
0320:                }
0321:            }
0322:
0323:            /**
0324:             * Delete project parameters are in project database and not in XML document.
0325:             * @return true if there was an error during deletion
0326:             */
0327:            private void parameterDeletion() throws Exception {
0328:                Hashtable<String, Parameter> paramSet = project
0329:                        .getParameterSetFromModel();
0330:                Enumeration<Parameter> itParamProjet = paramSet.elements();
0331:
0332:                while (itParamProjet.hasMoreElements() && !cancelled) {
0333:                    Parameter param = itParamProjet.nextElement();
0334:                    List<Element> listParamXML = doc.selectNodes("//Param");
0335:                    boolean belong = false;
0336:                    for (Element paramElem : listParamXML) {
0337:                        if (paramElem.elementText("Nom").equals(
0338:                                param.getNameFromModel())) {
0339:                            belong = true;
0340:                        }
0341:                    }
0342:                    if (!belong) {
0343:                        try {
0344:                            project.deleteParamInDBndModel(param);
0345:                        } catch (Exception e) {
0346:                            Tools.ihmExceptionView(e);
0347:                            cancelled = true;
0348:                        }
0349:                    }
0350:                }
0351:            }
0352:
0353:            /**
0354:             * Delete project environment and associated data are in project database
0355:             * and not in XML document
0356:             * @return true if there was an error during deletion
0357:             */
0358:            private void environmentDeletion() throws Exception {
0359:                //environments deletion
0360:                List<Element> envList = doc.selectNodes("//Environnement");
0361:                ArrayList<Environment> envInBDD = project
0362:                        .getEnvironmentListFromModel();
0363:                Iterator<Environment> itEnv = envInBDD.iterator();
0364:
0365:                while (itEnv.hasNext() && !cancelled) {
0366:                    Environment env = itEnv.next();
0367:                    Iterator<Element> itEnvXML = envList.iterator();
0368:                    Element envElem = null;
0369:                    boolean belong = false;
0370:                    while (itEnvXML.hasNext() && !belong) {
0371:                        envElem = (Element) itEnvXML.next();
0372:                        if (envElem.elementText("Nom").equals(
0373:                                env.getNameFromModel())) {
0374:                            belong = true;
0375:                        }
0376:                    }
0377:                    if (!belong) {
0378:                        try {
0379:                            project.deleteEnvironmentInDBandModel(env);
0380:                        } catch (Exception e) {
0381:                            Tools.ihmExceptionView(e);
0382:                            cancelled = true;
0383:                        }
0384:                    } else {
0385:                        //delete parameters with value in environment
0386:                        List<Element> paramEnvListXML = envElem
0387:                                .selectNodes("ValeurParams/ValeurParam");
0388:                        Hashtable<Parameter, String> paramEnvList = env
0389:                                .getParametersHashTableFromModel();
0390:                        Enumeration<Parameter> enumEnv = paramEnvList.keys();
0391:                        while (enumEnv.hasMoreElements()) {
0392:                            belong = false;
0393:                            Parameter paramEnv = enumEnv.nextElement();
0394:                            Iterator<Element> itParamEnvXML = paramEnvListXML
0395:                                    .iterator();
0396:                            while (itParamEnvXML.hasNext()) {
0397:                                Element paramElem = (Element) itParamEnvXML
0398:                                        .next();
0399:                                String nomParam = paramElem.elementText("Nom");
0400:                                if (paramEnv.getNameFromModel()
0401:                                        .equals(nomParam)) {
0402:                                    belong = true;
0403:                                }
0404:                            }
0405:                            if (!belong) {
0406:                                try {
0407:                                    env.deleteDefParamInDBAndModel(paramEnv);
0408:                                } catch (Exception e) {
0409:                                    Tools.ihmExceptionView(e);
0410:                                }
0411:                            }
0412:                        }
0413:                        //suppression du script de l'environnement
0414:                        Script script = env.getInitScriptFromModel();
0415:                        if (script != null) {
0416:                            if (envElem.element("Script") == null) {
0417:                                try {
0418:                                    env.deleteScriptInDBAndModel();
0419:                                } catch (Exception e) {
0420:                                    Tools.ihmExceptionView(e);
0421:                                }
0422:                            }
0423:                        }
0424:                        //suppression des attachements de l'environnement
0425:                        attachmentDeletions(envElem, env);
0426:                    }
0427:                }
0428:            }
0429:
0430:            /**
0431:             * Delete families and associated elements are in project database 
0432:             * and not in XML document.
0433:             * @return
0434:             */
0435:            private void familyDeletion() throws Exception {
0436:                //suppression des familles
0437:                ArrayList<Family> familleList = project
0438:                        .getFamilyListFromModel();
0439:                ArrayList<Family> familyToRemove = new ArrayList<Family>();
0440:                List<Element> familleListXML = doc.selectNodes("//Famille");
0441:                Element famElem = null;
0442:                Iterator<Family> itFamily = familleList.iterator();
0443:                while (itFamily.hasNext() && !cancelled) {
0444:                    Family family = itFamily.next();
0445:                    boolean belong = false;
0446:                    Iterator<Element> itFamXML = familleListXML.iterator();
0447:                    while (itFamXML.hasNext() && !belong) {
0448:                        famElem = (Element) itFamXML.next();
0449:                        if (famElem.elementText("Nom").equals(
0450:                                family.getNameFromModel())) {
0451:                            if (isInitSelection()) {
0452:                                boolean selectFamily = false;
0453:                                for (Family selectedFamily : familySelectionList) {
0454:                                    if (selectedFamily.getNameFromModel()
0455:                                            .equals(family.getNameFromModel())) {
0456:                                        selectFamily = true;
0457:                                    }
0458:                                }
0459:                                if (selectFamily) {
0460:                                    belong = true;
0461:                                }
0462:                            } else {
0463:                                belong = true;
0464:                            }
0465:                        }
0466:                    }
0467:                    if (!belong) {
0468:                        familyToRemove.add(family);
0469:                    } else {
0470:                        //
0471:                        attachmentDeletions(famElem, family);
0472:                        //la famille appartient au document XML, gestion des suites
0473:                        suiteDeletion(famElem, family);
0474:                    }
0475:                }
0476:                Iterator<Family> itFamRm = familyToRemove.iterator();
0477:                while (itFamRm.hasNext() && !cancelled) {
0478:                    Family family = itFamRm.next();
0479:                    try {
0480:                        project.deleteFamilyInDBAndModel(family);
0481:                    } catch (Exception e) {
0482:                        Tools.ihmExceptionView(e);
0483:                        cancelled = true;
0484:                    }
0485:                }
0486:            }
0487:
0488:            /**
0489:             * Delete suites and associated elements are in project database 
0490:             * and not in XML document.
0491:             * @return
0492:             */
0493:            private void suiteDeletion(Element famElem, Family pFamily)
0494:                    throws Exception {
0495:                //gestion des suites
0496:                boolean belong = false;
0497:                ArrayList<TestList> suiteList = pFamily.getSuiteListFromModel();
0498:                ArrayList<TestList> suiteToRemove = new ArrayList<TestList>();
0499:                Element suiteElem = null;
0500:                List<Element> suiteListXML = famElem
0501:                        .selectNodes("SuiteTests/SuiteTest");
0502:                Iterator<TestList> itSuite = suiteList.iterator();
0503:                while (itSuite.hasNext() && !cancelled) {
0504:                    TestList suite = itSuite.next();
0505:                    belong = false;
0506:                    Iterator<Element> itSuiteXML = suiteListXML.iterator();
0507:                    while (itSuiteXML.hasNext() && !belong) {
0508:                        suiteElem = itSuiteXML.next();
0509:                        if (suiteElem.elementText("Nom").equals(
0510:                                suite.getNameFromModel())) {
0511:                            if (isInitSelection()) {
0512:                                Iterator<TestList> itSuiteSelect = suiteSelectionList
0513:                                        .iterator();
0514:                                boolean selectionneSuite = false;
0515:                                while (itSuiteSelect.hasNext()) {
0516:                                    TestList suiteSelect = (TestList) itSuiteSelect
0517:                                            .next();
0518:                                    if (suiteSelect.getNameFromModel().equals(
0519:                                            suite.getNameFromModel())
0520:                                            && suiteSelect
0521:                                                    .getFamilyFromModel()
0522:                                                    .getNameFromModel()
0523:                                                    .equals(
0524:                                                            suite
0525:                                                                    .getFamilyFromModel()
0526:                                                                    .getNameFromModel())) {
0527:                                        selectionneSuite = true;
0528:                                    }
0529:                                }
0530:                                if (selectionneSuite) {
0531:                                    belong = true;
0532:                                }
0533:                            } else {
0534:                                belong = true;
0535:                            }
0536:                        }
0537:                    }
0538:                    if (!belong) {
0539:                        suiteToRemove.add(suite);
0540:                    } else {
0541:                        //gestion de la suppression des attachements de la suite
0542:                        attachmentDeletions(suiteElem, suite);
0543:                        //on gère la suppression des tests appartenant à la suite
0544:                        testDeletion(suiteElem, suite);
0545:                    }
0546:                }
0547:                Iterator<TestList> itSuiteRm = suiteToRemove.iterator();
0548:                while (itSuiteRm.hasNext() && !cancelled) {
0549:                    TestList suite = (TestList) itSuiteRm.next();
0550:                    try {
0551:                        project.deleteTestListInDBandModel(suite);
0552:                    } catch (Exception e) {
0553:                        Tools.ihmExceptionView(e);
0554:                        cancelled = true;
0555:                    }
0556:                }
0557:            }
0558:
0559:            /**
0560:             * Delete tests and associated elements are in project database 
0561:             * and not in XML document.
0562:             * @return
0563:             */
0564:            private void testDeletion(Element suiteElem, TestList suite)
0565:                    throws Exception {
0566:                boolean belong = false;
0567:                ArrayList<Test> testList = suite.getTestListFromModel();
0568:                ArrayList<Test> testToRm = new ArrayList<Test>();
0569:                Iterator<Test> itTest = testList.iterator();
0570:                while (itTest.hasNext() && !cancelled) {
0571:                    Test test = itTest.next();
0572:                    belong = false;
0573:                    Element testElem = null;
0574:                    if (suiteElem != null) {
0575:                        Iterator<Element> itTestXML = suiteElem.selectNodes(
0576:                                "Tests/Test").iterator();
0577:                        while (itTestXML.hasNext() && !belong) {
0578:                            testElem = itTestXML.next();
0579:                            if (testElem.elementText("Nom").equals(
0580:                                    test.getNameFromModel())) {
0581:                                if (isInitSelection()) {
0582:                                    Iterator<Test> itTestSelect = testSelectionList
0583:                                            .iterator();
0584:                                    boolean selectTest = false;
0585:                                    while (itTestSelect.hasNext()) {
0586:                                        Test testSelect = itTestSelect.next();
0587:                                        if (testSelect
0588:                                                .getNameFromModel()
0589:                                                .equals(test.getNameFromModel())
0590:                                                && testSelect
0591:                                                        .getTestListFromModel()
0592:                                                        .getNameFromModel()
0593:                                                        .equals(
0594:                                                                test
0595:                                                                        .getTestListFromModel()
0596:                                                                        .getNameFromModel())
0597:                                                && testSelect
0598:                                                        .getTestListFromModel()
0599:                                                        .getFamilyFromModel()
0600:                                                        .getNameFromModel()
0601:                                                        .equals(
0602:                                                                test
0603:                                                                        .getTestListFromModel()
0604:                                                                        .getFamilyFromModel()
0605:                                                                        .getNameFromModel())) {
0606:                                            selectTest = true;
0607:                                        }
0608:                                    }
0609:                                    if (selectTest) {
0610:                                        belong = true;
0611:                                    }
0612:                                } else {
0613:                                    belong = true;
0614:                                }
0615:                            }
0616:                        }
0617:                    }
0618:                    if (!belong) {
0619:                        testToRm.add(test);
0620:                    } else {
0621:                        //gestion des paramètres
0622:                        ArrayList<Parameter> paramTestList = test
0623:                                .getParameterListFromModel();
0624:                        List<Element> paramTestXML = testElem
0625:                                .selectNodes("ParamsT/ParamT");
0626:                        ArrayList<Parameter> paramTestToRemove = new ArrayList<Parameter>();
0627:                        Iterator<Parameter> itParamTest = paramTestList
0628:                                .iterator();
0629:                        while (itParamTest.hasNext()) {
0630:                            Parameter param = itParamTest.next();
0631:                            belong = false;
0632:                            Iterator<Element> itParamTestXML = paramTestXML
0633:                                    .iterator();
0634:                            while (itParamTestXML.hasNext()) {
0635:                                Element paramElem = itParamTestXML.next();
0636:                                String nomParam = paramElem.elementText("Nom");
0637:                                if (param.getNameFromModel().equals(nomParam)) {
0638:                                    belong = true;
0639:                                }
0640:                            }
0641:                            if (!belong) {
0642:                                paramTestToRemove.add(param);
0643:                            }
0644:                        }
0645:                        Iterator<Parameter> itParamRm = paramTestToRemove
0646:                                .iterator();
0647:                        while (itParamRm.hasNext()) {
0648:                            Parameter param = itParamRm.next();
0649:                            try {
0650:                                test.deleteUseParamInDBAndModel(param);
0651:                            } catch (Exception e) {
0652:                                Tools.ihmExceptionView(e);
0653:                            }
0654:                        }
0655:                        //gestion des attachements
0656:                        attachmentDeletions(testElem, test);
0657:
0658:                        //si test automatique gestion du script
0659:                        if (test instanceof  AutomaticTest) {
0660:                            Script script = ((AutomaticTest) test)
0661:                                    .getScriptFromModel();
0662:                            if (script != null) {
0663:                                Element scriptElem = (Element) testElem
0664:                                        .selectSingleNode("TestAuto/Script");
0665:                                if (scriptElem == null
0666:                                        || !scriptElem
0667:                                                .attributeValue("nom")
0668:                                                .equals(
0669:                                                        script
0670:                                                                .getNameFromModel())) {
0671:                                    try {
0672:                                        ((AutomaticTest) test)
0673:                                                .deleteScriptInDBAndModel();
0674:                                    } catch (Exception e) {
0675:                                        Tools.ihmExceptionView(e);
0676:                                    }
0677:                                }
0678:                            }
0679:                        } else {
0680:                            //si test manuel gestion des actions
0681:                            actionDeletion(testElem, (ManualTest) test);
0682:                        }
0683:                    }
0684:                }
0685:                Iterator<Test> itTestRm = testToRm.iterator();
0686:                while (itTestRm.hasNext() && !cancelled) {
0687:                    Test test = (Test) itTestRm.next();
0688:                    try {
0689:                        suite.deleteTestInDBAndModel(test);
0690:                    } catch (Exception e) {
0691:                        Tools.ihmExceptionView(e);
0692:                        cancelled = true;
0693:                    }
0694:                }
0695:            }
0696:
0697:            /**
0698:             * Delete actions of manual test and associated elements are in project database 
0699:             * and not in XML document.
0700:             * @param testElem concerned XML element
0701:             * @param test manual test in DB
0702:             */
0703:            private void actionDeletion(Element testElem, ManualTest test)
0704:                    throws Exception {
0705:                ArrayList<Action> actionList = test
0706:                        .getActionListFromModel(false);
0707:                List<Element> actionListXML = testElem
0708:                        .selectNodes("TestManuel/ActionTest");
0709:                ArrayList<Action> actionToRemove = new ArrayList<Action>();
0710:                boolean belong;
0711:                Iterator<Action> itAction = actionList.iterator();
0712:                while (itAction.hasNext()) {
0713:                    Action action = itAction.next();
0714:                    Element actionElem = null;
0715:                    belong = false;
0716:                    Iterator<Element> itActionXML = actionListXML.iterator();
0717:                    while (itActionXML.hasNext() && !belong) {
0718:                        actionElem = (Element) itActionXML.next();
0719:                        if (actionElem.elementText("Nom").equals(
0720:                                action.getNameFromModel())) {
0721:                            belong = true;
0722:                        }
0723:                    }
0724:                    if (!belong) {
0725:                        actionToRemove.add(action);
0726:                    } else {
0727:                        //gestion des paramètres des actions
0728:                        Hashtable<String, Parameter> actionParam = action
0729:                                .getParameterHashSetFromModel();
0730:                        Enumeration<Parameter> itParamAction = actionParam
0731:                                .elements();
0732:                        ArrayList<Parameter> paramActionToRemove = new ArrayList<Parameter>();
0733:                        while (itParamAction.hasMoreElements()) {
0734:                            Parameter param = itParamAction.nextElement();
0735:                            belong = false;
0736:                            Iterator<Element> itParamActionXML = actionElem
0737:                                    .selectNodes("ParamsT/ParamT").iterator();
0738:                            while (itParamActionXML.hasNext()) {
0739:                                Element paramElem = itParamActionXML.next();
0740:                                String nomParam = paramElem.elementText("Nom");
0741:                                if (param.getNameFromModel().equals(nomParam)) {
0742:                                    belong = true;
0743:                                }
0744:                            }
0745:                            if (!belong) {
0746:                                paramActionToRemove.add(param);
0747:                            }
0748:                        }
0749:                        Iterator<Parameter> itParamActionRm = paramActionToRemove
0750:                                .iterator();
0751:                        while (itParamActionRm.hasNext()) {
0752:                            Parameter param = itParamActionRm.next();
0753:                            try {
0754:                                action.deleteUseParamInDBAndModel(param);
0755:                            } catch (Exception e) {
0756:                                Tools.ihmExceptionView(e);
0757:                            }
0758:                        }
0759:                        //gestion des attachements des actions
0760:                        attachmentDeletions(actionElem, action);
0761:                    }
0762:
0763:                }
0764:                Iterator<Action> itActionRm = actionToRemove.iterator();
0765:                while (itActionRm.hasNext()) {
0766:                    Action actionRm = itActionRm.next();
0767:                    try {
0768:                        test.deleteActionInDBModel(actionRm);
0769:                    } catch (Exception e) {
0770:                        Tools.ihmExceptionView(e);
0771:                        cancelled = true;
0772:                    }
0773:                }
0774:            }
0775:
0776:            /**
0777:             * Delete attachments of the given element which are in database
0778:             * and not in the XML document
0779:             * @param pDocElem XML element
0780:             * @param pWithAttachment element with attachment in DB
0781:             */
0782:            private void attachmentDeletions(Element pDocElem,
0783:                    WithAttachment pWithAttachment) throws Exception {
0784:                boolean belong;
0785:                List<Node> urlAttachementList = pDocElem
0786:                        .selectNodes("Attachements/UrlAttachement");
0787:                List<Node> fileAttachementList = pDocElem
0788:                        .selectNodes("Attachements/FileAttachement");
0789:                HashMap<String, Attachment> envMap = pWithAttachment
0790:                        .getAttachmentMapFromModel();
0791:                ArrayList<Attachment> envMapToRemove = new ArrayList<Attachment>();
0792:                Iterator<Attachment> itWithAttachmentMap = envMap.values()
0793:                        .iterator();
0794:                while (itWithAttachmentMap.hasNext()) {
0795:                    belong = false;
0796:                    Attachment attach = itWithAttachmentMap.next();
0797:                    if (attach instanceof  UrlAttachment) {
0798:                        UrlAttachment pUrlAttachment = (UrlAttachment) attach;
0799:                        Iterator<Node> itWithAttachmentUrlAttachXML = urlAttachementList
0800:                                .iterator();
0801:                        while (itWithAttachmentUrlAttachXML.hasNext()
0802:                                && belong == false) {
0803:                            Element urlElem = (Element) itWithAttachmentUrlAttachXML
0804:                                    .next();
0805:                            if (pUrlAttachment.getNameFromModel().equals(
0806:                                    urlElem.attributeValue("url"))) {
0807:                                belong = true;
0808:                            }
0809:                        }
0810:                    } else {
0811:                        FileAttachment pFileAttachment = (FileAttachment) attach;
0812:                        Iterator<Node> itEnvFileAttachXML = fileAttachementList
0813:                                .iterator();
0814:                        while (itEnvFileAttachXML.hasNext() && belong == false) {
0815:                            Element fileElem = (Element) itEnvFileAttachXML
0816:                                    .next();
0817:                            if (pFileAttachment.getNameFromModel().equals(
0818:                                    fileElem.attributeValue("nom"))) {
0819:                                belong = true;
0820:                            }
0821:                        }
0822:                    }
0823:                    if (!belong) {
0824:                        envMapToRemove.add(attach);
0825:                    }
0826:
0827:                }
0828:                for (Attachment attach : envMapToRemove) {
0829:                    try {
0830:                        pWithAttachment.deleteAttachementInDBAndModel(attach);
0831:                    } catch (Exception e) {
0832:                        Tools.ihmExceptionView(e);
0833:                    }
0834:                }
0835:            }
0836:
0837:            /**
0838:             * Delete data sets of the campaign which are in database
0839:             * and not in the XML document
0840:             * @param pDocElem XML element
0841:             * @param pWithAttachment element with attachment in DB
0842:             */
0843:            private void dataSetDeletion(Element campElem, Campaign camp) {
0844:                ArrayList<DataSet> datasetList = camp.getDataSetListFromModel();
0845:                ArrayList<DataSet> datasetToRemove = new ArrayList<DataSet>();
0846:                List<Element> datatsetListXML = campElem
0847:                        .selectNodes("JeuxDonnees/JeuDonnees");
0848:                Element jeuElem = null;
0849:                Iterator<DataSet> itJeu = datasetList.iterator();
0850:                boolean belong;
0851:                while (itJeu.hasNext()) {
0852:                    DataSet jeu = itJeu.next();
0853:                    belong = false;
0854:                    Iterator<Element> itJeuXML = datatsetListXML.iterator();
0855:                    while (itJeuXML.hasNext()) {
0856:                        jeuElem = itJeuXML.next();
0857:                        if (jeuElem.elementText("Nom").equals(
0858:                                jeu.getNameFromModel())) {
0859:                            belong = true;
0860:                        }
0861:                    }
0862:                    if (!belong) {
0863:                        datasetToRemove.add(jeu);
0864:                    }
0865:                }
0866:                Iterator<DataSet> itDatasetRm = datasetToRemove.iterator();
0867:                while (itDatasetRm.hasNext()) {
0868:                    DataSet jeuRm = itDatasetRm.next();
0869:                    try {
0870:                        camp.deleteDataSetInDBAndModel(jeuRm);
0871:                    } catch (Exception e) {
0872:                        Tools.ihmExceptionView(e);
0873:                    }
0874:                }
0875:            }
0876:
0877:            /**
0878:             * Supprime les tests d'une campagne qui sont présents dans le projet mais pas dans le documents
0879:             * @param campElem
0880:             * @param camp
0881:             */
0882:            private void testInCampDeletion(Element campElem, Campaign camp)
0883:                    throws Exception {
0884:                ArrayList<Test> testList = camp.getTestListFromModel();
0885:                ArrayList<Test> testToRemove = new ArrayList<Test>();
0886:                List<Element> testListXML = campElem
0887:                        .selectNodes("FamillesCamp/FamilleRef/SuiteTestsCamp/SuiteTestRef/TestsCamp/TestRef");
0888:                Element testElem = null;
0889:                Iterator<Test> itTest = testList.iterator();
0890:                boolean belong;
0891:                while (itTest.hasNext()) {
0892:                    Test test = itTest.next();
0893:                    String suiteName = test.getTestListFromModel()
0894:                            .getNameFromModel();
0895:                    String familyName = test.getTestListFromModel()
0896:                            .getFamilyFromModel().getNameFromModel();
0897:                    belong = false;
0898:                    Iterator<Element> itTestXML = testListXML.iterator();
0899:                    while (itTestXML.hasNext() && !belong) {
0900:                        testElem = itTestXML.next();
0901:                        String nomSuite = ((Element) testElem
0902:                                .selectSingleNode("ancestor::SuiteTestRef[1]"))
0903:                                .elementText("Nom");
0904:                        String nomFamille = ((Element) testElem
0905:                                .selectSingleNode("ancestor::FamilleRef[1]"))
0906:                                .elementText("Nom");
0907:                        String nomTest = testElem.elementText("Nom");
0908:                        if (test.getNameFromModel().equals(nomTest)
0909:                                && suiteName.equals(nomSuite)
0910:                                && familyName.equals(nomFamille)) {
0911:                            belong = true;
0912:                        }
0913:                    }
0914:                    if (!belong) {
0915:                        testToRemove.add(test);
0916:                    }
0917:                }
0918:                Iterator<Test> itTestRm = testToRemove.iterator();
0919:                while (itTestRm.hasNext()) {
0920:                    Test testRm = (Test) itTestRm.next();
0921:                    try {
0922:                        camp.deleteTestFromCampInDBAndModel(testRm, true);
0923:                    } catch (Exception e) {
0924:                        Tools.ihmExceptionView(e);
0925:                    }
0926:                }
0927:            }
0928:
0929:            /**
0930:             * Delete executions which are in database and not in XML document
0931:             * @param campElem
0932:             * @param camp
0933:             */
0934:            void execInCampDeletion(Element campElem, Campaign camp)
0935:                    throws Exception {
0936:                ArrayList<Execution> execList = camp
0937:                        .getExecutionListFromModel();
0938:                ArrayList<Execution> execToRemove = new ArrayList<Execution>();
0939:                List<Node> execListXML = campElem
0940:                        .selectNodes("ExecCampTests/ExecCampTest");
0941:                Element execElem = null;
0942:                Iterator<Execution> itExec = execList.iterator();
0943:                boolean belong;
0944:                while (itExec.hasNext() && !cancelled) {
0945:                    Execution exec = itExec.next();
0946:                    String execName = exec.getNameFromModel();
0947:                    belong = false;
0948:                    Iterator<Node> itExecXML = execListXML.iterator();
0949:                    while (itExecXML.hasNext() && !belong) {
0950:                        execElem = (Element) itExecXML.next();
0951:                        String nomExec = execElem.elementText("Nom");
0952:                        if (nomExec.equals(execName)) {
0953:                            belong = true;
0954:                        }
0955:                    }
0956:                    if (!belong) {
0957:                        execToRemove.add(exec);
0958:                    } else {
0959:                        //suppression des résultats d'exécution
0960:                        ArrayList<ExecutionResult> resExecList = exec
0961:                                .getExecutionResultListFromModel();
0962:                        ArrayList<ExecutionResult> resExecToRemove = new ArrayList<ExecutionResult>();
0963:                        List<Node> resExecListXML = execElem
0964:                                .selectNodes("ResulExecCampTests/ResulExecCampTest");
0965:                        Element resExecElem = null;
0966:                        Iterator<ExecutionResult> itResExec = resExecList
0967:                                .iterator();
0968:                        while (itResExec.hasNext()) {
0969:                            ExecutionResult resExec = itResExec.next();
0970:                            String resExecName = resExec.getNameFromModel();
0971:                            belong = false;
0972:                            Iterator<Node> itResExecXML = resExecListXML
0973:                                    .iterator();
0974:                            while (itResExecXML.hasNext() && !belong) {
0975:                                resExecElem = (Element) itResExecXML.next();
0976:                                String nomResExec = resExecElem
0977:                                        .elementText("Nom");
0978:                                if (nomResExec.equals(resExecName)) {
0979:                                    belong = true;
0980:                                }
0981:                            }
0982:                            if (!belong) {
0983:                                resExecToRemove.add(resExec);
0984:                            }
0985:                        }
0986:                        Iterator<ExecutionResult> itResExecRm = resExecToRemove
0987:                                .iterator();
0988:                        while (itResExecRm.hasNext()) {
0989:                            ExecutionResult resExecRm = itResExecRm.next();
0990:                            try {
0991:                                exec
0992:                                        .deleteExecutionResultInDBAndModel(resExecRm);
0993:                            } catch (Exception e) {
0994:                                Tools.ihmExceptionView(e);
0995:                            }
0996:                        }
0997:                    }
0998:                }
0999:                Iterator<Execution> itExecRm = execToRemove.iterator();
1000:                while (itExecRm.hasNext() && !cancelled) {
1001:                    Execution execRm = itExecRm.next();
1002:                    try {
1003:                        camp.deleteExecutionInDBAndModel(execRm);
1004:                    } catch (Exception e) {
1005:                        Tools.ihmExceptionView(e);
1006:                    }
1007:                }
1008:            }
1009:
1010:            /**
1011:             * Method to manage the import process
1012:             */
1013:            private void coreImport() {
1014:
1015:                try {
1016:
1017:                    /***** Plugin update globale data *****/
1018:                    int size = listXMLPlugin.size();
1019:                    for (int i = 0; i < size; i++) {
1020:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1021:                                .elementAt(i);
1022:                        if (idialog != null) {
1023:                            pXMLPrinterPlugin.updateProjectFromXML(doc, idialog
1024:                                    .isSupprElement(), project, this );
1025:                        } else {
1026:                            pXMLPrinterPlugin.updateProjectFromXML(doc, false,
1027:                                    project, this );
1028:                        }
1029:                    }
1030:                    /***** (END) Plugin update globale data *****/
1031:                    //Attachements du projet
1032:                    updateProjectAttachement();
1033:                    //Paramètres du projet
1034:                    updateProjectParameter();
1035:                    //Environnement du projet
1036:                    updateProjectEnvironment();
1037:                    //Arbre des test
1038:                    updateFamily();
1039:                    if (importCampaign && !cancelled) {
1040:                        updateCampaigns();
1041:                    }
1042:                    updatePlugin();
1043:
1044:                } catch (Exception e) {
1045:                    Tools.ihmExceptionView(e);
1046:                    cancelled = true;
1047:                    return;
1048:                }
1049:            }
1050:
1051:            /**
1052:             * Update attachments of project
1053:             */
1054:            private void updateProjectAttachement() throws Exception {
1055:                Element projectElem = (Element) doc
1056:                        .selectSingleNode("//ProjetVT");
1057:                updateElementAttachement(projectElem, project, false);
1058:            }
1059:
1060:            /**
1061:             * Update parameters of project
1062:             * @throws Exception
1063:             */
1064:            private void updateProjectParameter() throws Exception {
1065:                ArrayList<Node> paramList = (ArrayList<Node>) doc
1066:                        .selectNodes("//Param");
1067:                Iterator<Node> itParam = paramList.iterator();
1068:                while (itParam.hasNext() && !cancelled) {
1069:                    Element paramElem = (Element) itParam.next();
1070:                    String nomParam = paramElem.elementText("Nom");
1071:                    String descriptionParam = (paramElem
1072:                            .elementText("Description") == null) ? ""
1073:                            : paramElem.elementText("Description");
1074:                    descriptionParam = descriptionParam.replaceAll("\\\\n",
1075:                            "\n");
1076:                    Parameter newParamter = new Parameter(nomParam,
1077:                            descriptionParam);
1078:                    boolean existe = false;
1079:                    Parameter par = null;
1080:                    Enumeration<Parameter> itParam2 = project
1081:                            .getParameterSetFromModel().elements();
1082:                    while (itParam2.hasMoreElements() && !existe) {
1083:                        par = itParam2.nextElement();
1084:                        if (par.getNameFromModel().equals(nomParam)) {
1085:                            existe = true;
1086:                        }
1087:                    }
1088:
1089:                    if (!existe) {
1090:                        //Ajout du nouveau parametre
1091:                        project.addParameterToDBAndModel(newParamter);
1092:                        par = newParamter;
1093:                    } else {
1094:                        //Modification du parametre
1095:                        par.updateDescriptionInDBAndModel(descriptionParam);
1096:                    }
1097:                    /***** Plugin update parameter data *****/
1098:                    int size = listXMLPlugin.size();
1099:                    for (int i = 0; i < size; i++) {
1100:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1101:                                .elementAt(i);
1102:                        if (idialog != null) {
1103:                            pXMLPrinterPlugin.updateParameterFromXML(paramElem,
1104:                                    par, idialog.isSupprElement(), this );
1105:                        } else {
1106:                            pXMLPrinterPlugin.updateParameterFromXML(paramElem,
1107:                                    par, false, this );
1108:                        }
1109:                    }
1110:                    /***** (END) Plugin update parameter data *****/
1111:                }
1112:            }
1113:
1114:            /**
1115:             * Add environment in project if it does not exist in database, 
1116:             * if it already exists, update this environment
1117:             * @throws Exception
1118:             */
1119:            private void updateProjectEnvironment() throws Exception {
1120:                //Environnements du projet
1121:                Element paramsElem = (Element) doc.selectSingleNode("//Params");
1122:                ArrayList<Node> envList = (ArrayList<Node>) doc
1123:                        .selectNodes("//Environnement");
1124:                ArrayList<Environment> envInBDD = project
1125:                        .getEnvironmentListFromModel();
1126:                Iterator<Node> itEnv = envList.iterator();
1127:                while (itEnv.hasNext() && !cancelled) {
1128:                    Element envElem = (Element) itEnv.next();
1129:                    String nomEnv = envElem.elementText("Nom");
1130:                    String descriptionEnv = (envElem.elementText("Description") == null) ? ""
1131:                            : envElem.elementText("Description");
1132:                    descriptionEnv = descriptionEnv.replaceAll("\\\\n", "\n");
1133:                    Iterator<Environment> itEnvBDD = envInBDD.iterator();
1134:                    Environment env = null;
1135:                    boolean existeEnv = false;
1136:                    while (itEnvBDD.hasNext() && !existeEnv) {
1137:                        env = itEnvBDD.next();
1138:                        if (env.getNameFromModel().equals(nomEnv)) {
1139:                            existeEnv = true;
1140:                        }
1141:                    }
1142:                    boolean newEnv = false;
1143:                    if (!existeEnv) {
1144:                        env = null;
1145:                        env = new Environment(nomEnv, descriptionEnv);
1146:                        project.addEnvironmentInDBAndModel(env);
1147:                        newEnv = true;
1148:                    } else {
1149:                        env.updateInDBAndModel(nomEnv, descriptionEnv);
1150:                    }
1151:                    // Valeurs des paramètres
1152:                    List<Node> paramEnvList = envElem
1153:                            .selectNodes("ValeurParams/ValeurParam");
1154:                    Iterator<Node> itParamEnv = paramEnvList.iterator();
1155:                    while (itParamEnv.hasNext()) {
1156:                        Element paramElem = (Element) itParamEnv.next();
1157:                        String valeurParam = (paramElem
1158:                                .attributeValue("valeur") != null) ? paramElem
1159:                                .attributeValue("valeur") : "";
1160:                        String id_paramDoc = paramElem.attributeValue("ref");
1161:                        Element paramRootElem = (Element) paramsElem
1162:                                .selectSingleNode("Param[@id_param = '"
1163:                                        + id_paramDoc + "']");
1164:                        String nomParam = paramRootElem.elementText("Nom");
1165:                        //String descriptionParam = (paramRootElem.elementText("Description") == null)?"":paramRootElem.elementText("Description");
1166:                        boolean existe = false;
1167:                        Parameter paramEnv = null;
1168:                        if (env != null && newEnv == false) {
1169:                            Hashtable<Parameter, String> paramEnvInBDD = env
1170:                                    .getParametersHashTableFromModel();
1171:                            Enumeration<Parameter> enumParamEnv = paramEnvInBDD
1172:                                    .keys();
1173:                            while (enumParamEnv.hasMoreElements() && !existe) {
1174:                                paramEnv = enumParamEnv.nextElement();
1175:                                if (nomParam
1176:                                        .equals(paramEnv.getNameFromModel())) {
1177:                                    existe = true;
1178:                                }
1179:                            }
1180:                        }
1181:                        if (!existe) {
1182:                            paramEnv = project.getParameterFromModel(nomParam);
1183:                            if (paramEnv != null) {
1184:                                env.addParameterValueInDBModel(paramEnv,
1185:                                        valeurParam);
1186:                            }
1187:                        } else {
1188:                            env.addParameterValueInDBModel(paramEnv,
1189:                                    valeurParam);
1190:                        }
1191:                    }
1192:                    //Ajout ou mise à jour du script de l'environnement
1193:                    if (envElem.element("Script") != null) {
1194:                        String classpath = envElem.element("Script")
1195:                                .elementText("Classpath");
1196:                        String argScript = envElem.element("Script")
1197:                                .elementText("ArgScript");
1198:                        String type = envElem.element("Script").attributeValue(
1199:                                "type");
1200:                        String dirScript = envElem.element("Script")
1201:                                .attributeValue("dir");
1202:                        dirScript = restorePath(dirScript);
1203:                        File fScript = new File(dirXml + File.separator
1204:                                + dirScript);
1205:
1206:                        Script pScritp = new Script(fScript.getName(), "");
1207:                        pScritp.setTypeInModel(type);
1208:                        pScritp.setScriptExtensionInModel(classpath);
1209:                        pScritp.updatePlugArgInModel(argScript);
1210:                        try {
1211:                            if (newEnv == true) {
1212:                                env.addScriptInDBAndModel(pScritp, fScript);
1213:                            } else {
1214:                                env.deleteScriptInDBAndModel();
1215:                                env.addScriptInDBAndModel(pScritp, fScript);
1216:                            }
1217:                        } catch (Exception e) {
1218:                            Tools.ihmExceptionView(e);
1219:                        }
1220:                    }
1221:                    updateElementAttachement(envElem, env, newEnv);
1222:
1223:                    /***** Plugin update Env data *****/
1224:                    int size = listXMLPlugin.size();
1225:                    for (int i = 0; i < size; i++) {
1226:                        XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1227:                                .elementAt(i);
1228:                        if (idialog != null) {
1229:                            pXMLPrinterPlugin.updateEnvironmentFromXML(envElem,
1230:                                    env, idialog.isSupprElement(), this );
1231:                        } else {
1232:                            pXMLPrinterPlugin.updateEnvironmentFromXML(envElem,
1233:                                    env, false, this );
1234:                        }
1235:                    }
1236:                    /***** (END) Plugin update Env data *****/
1237:                }
1238:            }
1239:
1240:            /**
1241:             * Add family if it does not exist in database,
1242:             * update it otherwise
1243:             * @throws Exception
1244:             */
1245:            private void updateFamily() throws Exception {
1246:                ArrayList<Node> familyList = (ArrayList<Node>) doc
1247:                        .selectNodes("//Famille");
1248:                ArrayList<Family> familleListModel = project
1249:                        .getFamilyListFromModel();
1250:                if (familyList != null) {
1251:                    Iterator<Node> it = familyList.iterator();
1252:                    while (it.hasNext() && !cancelled) {
1253:                        Element familyElem = (Element) it.next();
1254:                        String familyName = familyElem.elementText("Nom");
1255:                        String familyDescription = (familyElem
1256:                                .elementText("Description") == null) ? ""
1257:                                : familyElem.elementText("Description");
1258:                        if (familyElem.element("Description") != null
1259:                                && familyElem.element("Description").attribute(
1260:                                        "isHTML") != null
1261:                                && familyElem.element("Description")
1262:                                        .attributeValue("isHTML")
1263:                                        .equals("true")) {
1264:                            familyDescription = giveHTMLDescription(familyElem);
1265:                        } else {
1266:                            familyDescription = familyDescription.replaceAll(
1267:                                    "\\\\n", "<br>");
1268:                            familyDescription = "<html><head></head><body>"
1269:                                    + familyDescription + "</body></html>";
1270:                        }
1271:                        boolean selectionne = false;
1272:                        if (initSelection) {
1273:                            Iterator<Family> itFamily = familySelectionList
1274:                                    .iterator();
1275:                            while (itFamily.hasNext()) {
1276:                                Family family = itFamily.next();
1277:                                if (familyName
1278:                                        .equals(family.getNameFromModel())) {
1279:                                    selectionne = true;
1280:                                }
1281:                            }
1282:                        }
1283:                        if (!initSelection || selectionne) {
1284:                            boolean appartient = false;
1285:                            Family fam = null;
1286:                            boolean newFamily = false;
1287:                            Iterator<Family> itFam = familleListModel
1288:                                    .iterator();
1289:                            while (itFam.hasNext() && !appartient) {
1290:                                fam = itFam.next();
1291:                                if (fam.getNameFromModel().equals(familyName)) {
1292:                                    appartient = true;
1293:                                }
1294:                            }
1295:                            try {
1296:                                if (!appartient) {
1297:                                    fam = new Family(familyName,
1298:                                            familyDescription);
1299:                                    project.addFamilyInDBAndModel(fam);
1300:                                    newFamily = true;
1301:                                } else {
1302:                                    fam
1303:                                            .updateDescriptionInModel(familyDescription);
1304:                                }
1305:
1306:                                //updatesuite
1307:                                updateElementAttachement(familyElem, fam,
1308:                                        newFamily);
1309:
1310:                                /***** Plugin update FamilyData data *****/
1311:                                int size = listXMLPlugin.size();
1312:                                for (int i = 0; i < size; i++) {
1313:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1314:                                            .elementAt(i);
1315:                                    if (idialog != null) {
1316:                                        pXMLPrinterPlugin
1317:                                                .updateFamilyFromXML(
1318:                                                        familyElem,
1319:                                                        fam,
1320:                                                        idialog
1321:                                                                .isSupprElement(),
1322:                                                        this );
1323:                                    } else {
1324:                                        pXMLPrinterPlugin.updateFamilyFromXML(
1325:                                                familyElem, fam, false, this );
1326:                                    }
1327:                                }
1328:                                /***** (END) Plugin update FamilyData data *****/
1329:
1330:                                updateSuite(familyElem, fam, newFamily);
1331:
1332:                            } catch (Exception e) {
1333:                                Tools.ihmExceptionView(e);
1334:                            }
1335:                        }
1336:                    }
1337:                }
1338:            }
1339:
1340:            /**
1341:             * 
1342:             * @param familyElem
1343:             * @param pFamily
1344:             * @param newFamily
1345:             * @throws Exception
1346:             */
1347:            private void updateSuite(Element familyElem, Family pFamily,
1348:                    boolean newFamily) throws Exception {
1349:                ArrayList<Node> suiteList = (ArrayList<Node>) familyElem
1350:                        .selectNodes(".//SuiteTest");
1351:                if (suiteList != null) {
1352:                    Iterator<Node> it2 = suiteList.iterator();
1353:                    while (it2.hasNext() && !cancelled) {
1354:                        Element suiteElem = (Element) it2.next();
1355:                        String suiteName = suiteElem.elementText("Nom");
1356:                        String suiteDescription = (suiteElem
1357:                                .elementText("Description") == null) ? ""
1358:                                : suiteElem.elementText("Description");
1359:                        if (suiteElem.element("Description") != null
1360:                                && suiteElem.element("Description").attribute(
1361:                                        "isHTML") != null
1362:                                && suiteElem.element("Description")
1363:                                        .attributeValue("isHTML")
1364:                                        .equals("true")) {
1365:                            suiteDescription = giveHTMLDescription(suiteElem);
1366:                        } else {
1367:                            suiteDescription = suiteDescription.replaceAll(
1368:                                    "\\\\n", "<br>");
1369:                            suiteDescription = "<html><head></head><body>"
1370:                                    + suiteDescription + "</body></html>";
1371:                        }
1372:                        //boolean erreur  = false;
1373:                        boolean selectionneSuite = false;
1374:                        if (isInitSelection()) {
1375:                            Iterator<TestList> itSuite = suiteSelectionList
1376:                                    .iterator();
1377:                            while (itSuite.hasNext()) {
1378:                                TestList suite = itSuite.next();
1379:                                if (suiteName.equals(suite.getNameFromModel())) {
1380:                                    selectionneSuite = true;
1381:                                }
1382:                            }
1383:                        }
1384:                        boolean newSuite = false;
1385:                        if (!isInitSelection() || selectionneSuite) {
1386:                            boolean appartient = false;
1387:                            TestList suite = null;
1388:                            if (pFamily != null && newFamily == false) {
1389:                                ArrayList<TestList> suiteTestList = pFamily
1390:                                        .getSuiteListFromModel();
1391:                                Iterator<TestList> itSuite = suiteTestList
1392:                                        .iterator();
1393:                                while (itSuite.hasNext() && !appartient) {
1394:                                    suite = itSuite.next();
1395:                                    if (suite.getNameFromModel().equals(
1396:                                            suiteName)) {
1397:                                        appartient = true;
1398:                                    }
1399:                                }
1400:                            }
1401:
1402:                            try {
1403:                                if (!appartient) {
1404:                                    suite = new TestList(suiteName,
1405:                                            suiteDescription);
1406:                                    pFamily.addTestListInDBAndModel(suite);
1407:                                    newSuite = true;
1408:                                } else {
1409:                                    suite.updateInDBAndModel(suiteName,
1410:                                            suiteDescription);
1411:                                }
1412:                                //gérer les attachements
1413:                                updateElementAttachement(suiteElem, suite,
1414:                                        newSuite);
1415:
1416:                                /***** Plugin update Suite Data *****/
1417:                                int size = listXMLPlugin.size();
1418:                                for (int i = 0; i < size; i++) {
1419:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1420:                                            .elementAt(i);
1421:                                    if (idialog != null) {
1422:                                        pXMLPrinterPlugin
1423:                                                .updateSuiteFromXML(
1424:                                                        suiteElem,
1425:                                                        suite,
1426:                                                        idialog
1427:                                                                .isSupprElement(),
1428:                                                        this );
1429:                                    } else {
1430:                                        pXMLPrinterPlugin.updateSuiteFromXML(
1431:                                                suiteElem, suite, false, this );
1432:                                    }
1433:                                }
1434:                                /***** (END) Plugin update Suite Data *****/
1435:
1436:                                //les tests
1437:                                updateTests(suiteElem, pFamily, suite,
1438:                                        newFamily, newSuite);
1439:                            } catch (Exception e) {
1440:                                Tools.ihmExceptionView(e);
1441:                            }
1442:                        }
1443:                    }
1444:                }
1445:            }
1446:
1447:            /**
1448:             * Manage insertion and update of tests in database from XML file
1449:             * @param suiteElem
1450:             * @param fam
1451:             * @param suite
1452:             * @param newFamily
1453:             * @param newSuite
1454:             */
1455:            private void updateTests(Element suiteElem, Family fam,
1456:                    TestList suite, boolean newFamily, boolean newSuite)
1457:                    throws Exception {
1458:                List<Element> testList = suiteElem.selectNodes(".//Test");
1459:                if (testList == null) {
1460:                    return;
1461:                }
1462:
1463:                Iterator<Element> it = testList.iterator();
1464:                while (it.hasNext() && !cancelled) {
1465:                    try {
1466:                        Element testElem = it.next();
1467:                        String testName = testElem.elementText("Nom");
1468:                        boolean newTest = false;
1469:                        boolean selectionneTest = false;
1470:                        if (isInitSelection()) {
1471:                            Iterator<Test> itTest = testSelectionList
1472:                                    .iterator();
1473:                            while (itTest.hasNext()) {
1474:                                Test test = (Test) itTest.next();
1475:                                if (testName.equals(test.getNameFromModel())) {
1476:                                    selectionneTest = true;
1477:                                }
1478:                            }
1479:                        }
1480:                        if (!isInitSelection() || selectionneTest) {
1481:                            //Vérification de l'existence ou non du test
1482:                            boolean appartient = false;
1483:                            Test test = null;
1484:                            if (suite != null) {
1485:                                ArrayList<Test> testListBDD = suite
1486:                                        .getTestListFromModel();
1487:                                Iterator<Test> itTest = testListBDD.iterator();
1488:                                while (itTest.hasNext() && !appartient) {
1489:                                    test = itTest.next();
1490:                                    if (test.getNameFromModel()
1491:                                            .equals(testName)) {
1492:                                        appartient = true;
1493:                                    }
1494:                                }
1495:                            }
1496:                            //récupération des données dans le document
1497:                            String loginConceptor = "";
1498:                            //User pUser;
1499:                            if (!appartient) {
1500:                                loginConceptor = getLogin(testElem);
1501:                                if (loginConceptor == null) {
1502:                                    if (!newProject) {
1503:                                        loginConceptor = DataModel
1504:                                                .getCurrentUser()
1505:                                                .getLoginFromModel();
1506:                                    } else {
1507:                                        loginConceptor = project
1508:                                                .getAdministratorFromModel()
1509:                                                .getLoginFromModel();
1510:                                    }
1511:                                }
1512:                            } else {
1513:                                loginConceptor = test
1514:                                        .getConceptorLoginFromModel();
1515:                            }
1516:                            String testDescription = (testElem
1517:                                    .elementText("Description") == null) ? ""
1518:                                    : testElem.elementText("Description");
1519:                            if (testElem.element("Description") != null
1520:                                    && testElem.element("Description")
1521:                                            .attribute("isHTML") != null
1522:                                    && testElem.element("Description")
1523:                                            .attributeValue("isHTML").equals(
1524:                                                    "true")) {
1525:                                testDescription = giveHTMLDescription(testElem);
1526:                            } else {
1527:                                testDescription = testDescription.replaceAll(
1528:                                        "\\\\n", "<br>");
1529:                                testDescription = "<html><head></head><body>"
1530:                                        + testDescription + "</body></html>";
1531:                            }
1532:
1533:                            String testType;
1534:                            String plug_ext;
1535:                            if (testElem.element("TestAuto") == null) {
1536:                                testType = "MANUAL";
1537:                                plug_ext = "";
1538:                            } else {
1539:                                testType = "AUTOMATED";
1540:                                String plug = testElem.element("TestAuto")
1541:                                        .attributeValue("plug_ext");
1542:                                if (plug != null) {
1543:                                    plug_ext = plug;
1544:                                } else {
1545:                                    plug_ext = "";
1546:                                }
1547:                            }
1548:                            if (!appartient) {
1549:
1550:                                newTest = true;
1551:                                if (testType.equals("AUTOMATED")) {
1552:                                    test = new AutomaticTest(testName,
1553:                                            testDescription, plug_ext);
1554:                                } else {
1555:                                    test = new ManualTest(testName,
1556:                                            testDescription);
1557:                                }
1558:                                test.setConceptorLoginInModel(loginConceptor);
1559:                                suite.addTestInDBAndModel(test);
1560:
1561:                                updateElementAttachement(testElem, test,
1562:                                        newTest);
1563:
1564:                                updateParametresTest(testElem, test);
1565:
1566:                                /***** Plugin update Test Data *****/
1567:                                int size = listXMLPlugin.size();
1568:                                for (int i = 0; i < size; i++) {
1569:                                    XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1570:                                            .elementAt(i);
1571:                                    if (idialog != null) {
1572:                                        pXMLPrinterPlugin
1573:                                                .updateTestFromXML(
1574:                                                        testElem,
1575:                                                        test,
1576:                                                        idialog
1577:                                                                .isSupprElement(),
1578:                                                        this );
1579:                                    } else {
1580:                                        pXMLPrinterPlugin.updateTestFromXML(
1581:                                                testElem, test, false, this );
1582:                                    }
1583:                                }
1584:                                /***** (END) Plugin update Test Data *****/
1585:
1586:                                if (testType == "AUTOMATED") {
1587:                                    updateTestScript(testElem,
1588:                                            (AutomaticTest) test);
1589:                                    automatedTest2Update
1590:                                            .add((AutomaticTest) test);
1591:                                } else {
1592:                                    ajouterActions(testElem, (ManualTest) test);
1593:                                }
1594:
1595:                            } else { //test already present in DB
1596:                                boolean noupdate = true;
1597:                                Test testDB = project.getTestFromModel(fam
1598:                                        .getNameFromModel(), suite
1599:                                        .getNameFromModel(), testName);
1600:                                boolean isDifferent = detecterModif(fam, suite,
1601:                                        testElem);
1602:                                if (!idialog.isKeepOriginalOption()
1603:                                        && isDifferent) {
1604:                                    Test testToUpdate = null;
1605:                                    if (idialog.isKeepOriginalAndImportOption()
1606:                                            || idialog
1607:                                                    .isKeepOriginalAndUpdateOption()) {
1608:                                        String newName = "save_" + testName;
1609:                                        int i = 0;
1610:                                        while (Test.isInBase(suite, newName)) {
1611:                                            newName = newName + "_" + i;
1612:                                            i++;
1613:                                        }
1614:                                        testDB
1615:                                                .updateInDBAndModel(
1616:                                                        newName,
1617:                                                        testDB
1618:                                                                .getDescriptionFromModel());
1619:                                        savedTests.add(testDB);
1620:                                        if (idialog
1621:                                                .isKeepOriginalAndUpdateOption()) {
1622:                                            if (testDB instanceof  ManualTest) {
1623:                                                testToUpdate = ManualTest
1624:                                                        .createCopyInDBAndModel(
1625:                                                                (ManualTest) testDB,
1626:                                                                testName);
1627:                                            } else if (testDB instanceof  AutomaticTest) {
1628:                                                testToUpdate = AutomaticTest
1629:                                                        .createCopyInDBAndModel(
1630:                                                                (AutomaticTest) testDB,
1631:                                                                testName);
1632:                                            }
1633:                                        }
1634:                                    } else if (idialog
1635:                                            .isEraseOriginalAndImport()) {
1636:                                        project.deleteTestInDBandModel(testDB);
1637:                                    }
1638:                                    if (idialog.isKeepOriginalAndImportOption()
1639:                                            || idialog
1640:                                                    .isEraseOriginalAndImport()) {
1641:                                        //import test from XML
1642:                                        newTest = true;
1643:                                        if (testType.equals("AUTOMATED")) {
1644:                                            test = new AutomaticTest(testName,
1645:                                                    testDescription, plug_ext);
1646:                                        } else {
1647:                                            test = new ManualTest(testName,
1648:                                                    testDescription);
1649:                                        }
1650:                                        test
1651:                                                .setConceptorLoginInModel(loginConceptor);
1652:                                        suite.addTestInDBAndModel(test);
1653:
1654:                                        updateElementAttachement(testElem,
1655:                                                test, newTest);
1656:
1657:                                        updateParametresTest(testElem, test);
1658:
1659:                                        /***** Plugin update Test Data *****/
1660:                                        int size = listXMLPlugin.size();
1661:                                        for (int i = 0; i < size; i++) {
1662:                                            XMLPrinterPlugin pXMLPrinterPlugin = (XMLPrinterPlugin) listXMLPlugin
1663:                                                    .elementAt(i);
1664:                                            if (idialog != null) {
1665:                                                pXMLPrinterPlugin
1666:                                                        .updateTestFromXML(
1667:                                                                testElem,
1668:                                                                test,
1669:                                                                idialog
1670:                                                                        .isSupprElement(),
1671:                                                                this );
1672:                                            } else {
1673:                                                pXMLPrinterPlugin
1674:                                                        .updateTestFromXML(
1675:                                                                testElem, test,
1676:                                                                false, this );
1677:                                            }
1678:                                        }
1679:                                        /***** (END) Plugin update Test Data *****/
1680:
1681:                                        if (testType == "AUTOMATED") {
1682:                                            updateTestScript(testElem,
1683:                                                    (AutomaticTest) test);
1684:                                            automatedTest2Update
1685:                                                    .add((AutomaticTest) test);
1686:                                        } else {
1687:                                            ajouterActions(testElem,
1688:                                                    (ManualTest) test);
1689:                                        }
1690:                                        noupdate = false;
1691:                                    } else if (idialog
1692:                                            .isKeepOriginalAndUpdateOption()
1693:                                            || idialog.isUpdateOriginalOption()) {
1694:                                        if (idialog.isUpdateOriginalOption()) {
1695:                                            testToUpdate = testDB;
1696:                                        }
1697:                                        //update testToUpdate
1698:                                        testToUpdate.updateInModel(testName,
1699:                                                testDescription);
1700:                                        updateElementAttachement(testElem,
1701:                                                testToUpdate, newTest);
1702:                                        updateParametresTest(testElem,
1703:                                                testToUpdate);
1704:                                        /***** Plugin update Test Data *****/
1705:                                        for (XMLPrinterPlugin pXMLPrinterPlugin : listXMLPlugin) {
1706:                                            pXMLPrinterPlugin
1707:                                                    .updateTestFromXML(
1708:                                                            testElem,
1709:                                                            testToUpdate,
1710:                                                            idialog
1711:                                                                    .isSupprElement(),
1712:                                                            this );
1713:                                        }
1714:                                        /***** (END) Plugin update Test Data *****/
1715:                                        if (testType == "AUTOMATED") {
1716:                                            updateTestScript(
1717:                                                    testElem,
1718:                                                    (AutomaticTest) testToUpdate);
1719:                                            Util
1720:                                                    .log("[ImportDialog] Add test auto "
1721:                                                            + testToUpdate
1722:                                                                    .getIdBdd());
1723:                                            automatedTest2Update
1724:                                                    .add((AutomaticTest) testToUpdate);
1725:                                        } else {
1726:                                            ManualTest manualTest = (ManualTest) testToUpdate;
1727:                                            ArrayList<Action> actionList = manualTest
1728:                                                    .getActionListFromModel(false);
1729:                                            ArrayList<String> actionToRemove = new ArrayList<String>();
1730:                                            for (Action action : actionList) {
1731:                                                if (!actionToRemove
1732:                                                        .contains(action
1733:                                                                .getNameFromModel()))
1734:                                                    actionToRemove
1735:                                                            .add(action
1736:                                                                    .getNameFromModel());
1737:                                            }
1738:                                            for (String actionName : actionToRemove) {
1739:                                                manualTest
1740:                                                        .deleteActionInDBModel(manualTest
1741:                                                                .getActionFromModel(actionName));
1742:                                            }
1743:                                            ajouterActions(testElem,
1744:                                                    (ManualTest) testToUpdate);
1745:                                        }
1746:                                        noupdate = false;
1747:                                    }
1748:                                }
1749:                                if (noupdate) {/* Si aucune modification sur l'element on appelle les plugins*/
1750:
1751:                                    /***** Plugin update Test Data *****/
1752:                                    for (XMLPrinterPlugin pXMLPrinterPlugin : listXMLPlugin) {
1753:                                        pXMLPrinterPlugin
1754:                                                .updateTestFromXML(
1755:                                                        testElem,
1756:                                                        testDB,
1757:                                                        idialog
1758:                                                                .isSupprElement(),
1759:                                                        this );
1760:                                    }
1761:                                    /***** (END) Plugin update Test Data *****/
1762:                                }
1763:                            }
1764:                        }
1765:                    } catch (Exception e) {
1766:                        Tools.ihmExceptionView(e);
1767:                    }
1768:                }
1769:            }
1770:
1771:            /**
1772:             * Dans le cas où le test était déjà dans la BD, ajout ou mise à jour du script
1773:             * @param familyName nom de la famille auquelle appartient le test
1774:             * @param suiteName nom de la suite auquelle appartient le test
1775:             * @param testElem élément qui représente le test dans le document XML
1776:             * @param id_test identifiant du test qui a été ajouté à la BD
1777:             */
1778:            public void updateTestScript(Element testElem, AutomaticTest test)
1779:                    throws Exception {
1780:                Element scriptElem = (Element) testElem
1781:                        .selectSingleNode("TestAuto/Script");
1782:                try {
1783:                    if (scriptElem != null) {
1784:                        String classpath = scriptElem.elementText("Classpath");
1785:                        String argScript = scriptElem.elementText("ArgScript");
1786:                        String type = scriptElem.attributeValue("type");
1787:                        String dirScript = scriptElem.attributeValue("dir");
1788:                        dirScript = restorePath(dirScript);
1789:                        File fScript = new File(dirXml + File.separator
1790:                                + dirScript);
1791:
1792:                        Script pScritp = new Script(fScript.getName(), "");
1793:                        pScritp.setTypeInModel(type);
1794:                        pScritp.setScriptExtensionInModel(classpath);
1795:                        pScritp.updatePlugArgInModel(argScript);
1796:
1797:                        if (test != null) {
1798:                            if (test.getScriptFromModel() != null) {
1799:                                test.deleteScriptInDBAndModel();
1800:                            }
1801:                        }
1802:                        test.addScriptInDBAndModel(pScritp, fScript);
1803:                    } else {
1804:                        if (test.getScriptFromModel() != null) {
1805:                            test.deleteScriptInDBAndModel();
1806:                        }
1807:                    }
1808:                } catch (Exception e) {
1809:                    e.printStackTrace();
1810:                    idialog
1811:                            .setErrorMessage(idialog.getErrorMessage()
1812:                                    + Language
1813:                                            .getInstance()
1814:                                            .getText(
1815:                                                    "Problème_lors_de_la_suppression_d'un_script"));
1816:                    idialog.showErrorMessage();
1817:                }
1818:            }
1819:
1820:            /**
1821:             * On cherche à savoir si le test du projet possède des différences avec le test présent dans le fichier XML,
1822:             * ces différences générant un conflit
1823:             * @param familyName nom de la famille auquelle appartient le test
1824:             * @param suiteName nom de la suite auquelle appartient le test
1825:             * @param testElem élément test du document XML
1826:             * @return true si réel conflit, false sinon
1827:             */
1828:            public boolean detecterModif(Family pFamily, TestList suite,
1829:                    Element testElem) throws Exception {
1830:                //on vérifie que tous les paramètres qui sont dans le document d'import sont dans le projet
1831:                String testName = testElem.elementText("Nom");
1832:                Test test = project.getTestFromModel(
1833:                        pFamily.getNameFromModel(), suite.getNameFromModel(),
1834:                        testName);
1835:                List<Element> paramsImport = testElem
1836:                        .selectNodes("ParamsT/ParamT/Nom");
1837:                ArrayList<Parameter> paramsProjet = test
1838:                        .getParameterListFromModel();
1839:                Iterator<Element> itImport = paramsImport.iterator();
1840:                while (itImport.hasNext()) {
1841:                    String nomParamImport = ((Element) itImport.next())
1842:                            .getText();
1843:                    boolean appartient = false;
1844:                    Iterator<Parameter> itParamProjet = paramsProjet.iterator();
1845:                    while (itParamProjet.hasNext()) {
1846:                        Parameter param = itParamProjet.next();
1847:                        if (param.getNameFromModel().equals(nomParamImport)) {
1848:                            appartient = true;
1849:                        }
1850:                    }
1851:                    if (!appartient) {
1852:                        return true;
1853:                    }
1854:                }
1855:                String descriptionXML = "";
1856:                Element descElem = testElem.element("Description");
1857:                if (descElem != null && descElem.hasContent()) {
1858:                    descriptionXML = testElem.element("Description").asXML();
1859:                    descriptionXML = getTextFromChildren(testElem
1860:                            .element("Description"), "");
1861:                }
1862:                String descriptionDB = test.getDescriptionFromModel();
1863:                if (descriptionDB != null) {
1864:                    descriptionDB = descriptionDB.replaceAll("<br>", "<br/>");
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) {
3120:                    descriptionDB = descriptionDB.replaceAll("<br>", "<br/>");
3121:                    Document document = DocumentHelper.parseText(descriptionDB);
3122:                    descriptionDB = getTextFromChildren(document
3123:                            .getRootElement(), "");
3124:                }
3125:                if (descriptionDB == null)
3126:                    descriptionDB = "";
3127:                if (!descriptionXML.equals(descriptionDB)) {
3128:                    return true;
3129:                }
3130:
3131:                //attachments
3132:                List<Element> urlAttachementList = campElem
3133:                        .selectNodes("Attachements/UrlAttachement");
3134:                HashMap<String, Attachment> envMap = campaign
3135:                        .getAttachmentMapFromModel();
3136:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
3137:                for (Element urlElem : urlAttachementList) {
3138:                    String url = urlElem.attributeValue("url");
3139:                    boolean belong = false;
3140:                    for (Attachment attach : envMap.values()) {
3141:                        if ((attach instanceof  UrlAttachment)
3142:                                && ((UrlAttachment) attach).getNameFromModel()
3143:                                        .equals(url)) {
3144:                            belong = true;
3145:                        }
3146:                    }
3147:                    if (!belong) {
3148:                        return true;
3149:                    }
3150:                }
3151:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
3152:                for (Attachment attach : envMap.values()) {
3153:                    if (attach instanceof  UrlAttachment) {
3154:                        boolean belong = false;
3155:                        String url = ((UrlAttachment) attach)
3156:                                .getNameFromModel();
3157:                        for (Element urlElem : urlAttachementList) {
3158:                            if (url.equals(urlElem.attributeValue("url"))) {
3159:                                belong = true;
3160:                            }
3161:                        }
3162:                        if (!belong) {
3163:                            return true;
3164:                        }
3165:                    }
3166:                }
3167:
3168:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
3169:                List<Element> fileAttachmentList = campElem
3170:                        .selectNodes("Attachements/FileAttachement");
3171:                for (Element fileElem : fileAttachmentList) {
3172:                    String nom = fileElem.attributeValue("nom");
3173:                    boolean belong = false;
3174:                    for (Attachment attach : envMap.values()) {
3175:                        if ((attach instanceof  FileAttachment)
3176:                                && ((FileAttachment) attach).getNameFromModel()
3177:                                        .equals(nom)) {
3178:                            belong = true;
3179:                        }
3180:                    }
3181:                    if (!belong) {
3182:                        return true;
3183:                    }
3184:                }
3185:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
3186:                for (Attachment attach : envMap.values()) {
3187:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
3188:                    boolean belong = false;
3189:                    for (Element fileElem : fileAttachmentList) {
3190:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
3191:                            belong = true;
3192:                        }
3193:                    }
3194:                    if (!belong) {
3195:                        return true;
3196:                    }
3197:                }
3198:
3199:                //data sets
3200:                List<Element> dataSetList = campElem
3201:                        .selectNodes("JeuxDonnees/JeuDonnees");
3202:                for (Element dataSetElem : dataSetList) {
3203:                    String dataSetName = dataSetElem.elementText("Nom");
3204:                    ArrayList<DataSet> datasets = campaign
3205:                            .getDataSetListFromModel();
3206:                    boolean belong = false;
3207:                    Iterator<DataSet> itDataSet = datasets.iterator();
3208:                    while (itDataSet.hasNext() && !belong) {
3209:                        DataSet dataSet = itDataSet.next();
3210:                        if (dataSetName.equals(dataSet.getNameFromModel())) {
3211:                            belong = true;
3212:                            String dataSetDescription = dataSetElem
3213:                                    .elementText("Description");
3214:                            if (!dataSetDescription.equals(dataSet
3215:                                    .getDescriptionFromModel())) {
3216:                                return true;
3217:                            }
3218:                            List<Element> paramList = dataSetElem
3219:                                    .selectNodes("ValeurParams/ValeurParam");
3220:                            for (Element paramElem : paramList) {
3221:                                String paramName = paramElem.elementText("Nom");
3222:                                boolean belong2 = false;
3223:                                HashMap<String, String> paramHashMap = dataSet
3224:                                        .getParametersHashMapFromModel();
3225:                                Iterator<String> itparam = paramHashMap
3226:                                        .keySet().iterator();
3227:                                while (itparam.hasNext() && !belong2) {
3228:                                    String paramNom = itparam.next();
3229:                                    if (paramNom.equals(paramName)) {
3230:                                        belong2 = true;
3231:                                        String paramValue = paramElem
3232:                                                .attributeValue("valeur");
3233:                                        String paramValeur = paramHashMap
3234:                                                .get(paramNom);
3235:                                        if (paramValue != null
3236:                                                && !paramValue
3237:                                                        .equals(paramValeur)) {
3238:                                            return true;
3239:                                        }
3240:                                    }
3241:                                }
3242:                                if (!belong2) {
3243:                                    return true;
3244:                                }
3245:                            }
3246:                        }
3247:                    }
3248:                    if (!belong) {
3249:                        return true;
3250:                    }
3251:                }
3252:                ArrayList<DataSet> datasets = campaign
3253:                        .getDataSetListFromModel();
3254:                for (DataSet dataSet : datasets) {
3255:                    boolean belong = false;
3256:                    Iterator<Element> itDataSet = dataSetList.iterator();
3257:                    while (itDataSet.hasNext() && !belong) {
3258:                        Element dataSetElem = itDataSet.next();
3259:                        String dataSetName = dataSetElem.elementText("Nom");
3260:                        if (dataSetName.equals(dataSet.getNameFromModel())) {
3261:                            belong = true;
3262:                        }
3263:                    }
3264:                    if (!belong) {
3265:                        return true;
3266:                    }
3267:                }
3268:                return false;
3269:            }
3270:
3271:            /**
3272:             * Method which detects if the execution in database must be copied or not.
3273:             * @param exec execution in DB
3274:             * @param execElem execution in XML document
3275:             * @return
3276:             */
3277:            private boolean mustKeepCopy(Execution exec, Element execElem)
3278:                    throws Exception {
3279:                //attachments
3280:                List<Element> urlAttachementList = execElem
3281:                        .selectNodes("Attachements/UrlAttachement");
3282:                HashMap<String, Attachment> envMap = exec
3283:                        .getAttachmentMapFromModel();
3284:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
3285:                for (Element urlElem : urlAttachementList) {
3286:                    String url = urlElem.attributeValue("url");
3287:                    boolean belong = false;
3288:                    for (Attachment attach : envMap.values()) {
3289:                        if ((attach instanceof  UrlAttachment)
3290:                                && ((UrlAttachment) attach).getNameFromModel()
3291:                                        .equals(url)) {
3292:                            belong = true;
3293:                        }
3294:                    }
3295:                    if (!belong) {
3296:                        return true;
3297:                    }
3298:                }
3299:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
3300:                for (Attachment attach : envMap.values()) {
3301:                    if (attach instanceof  UrlAttachment) {
3302:                        boolean belong = false;
3303:                        String url = ((UrlAttachment) attach)
3304:                                .getNameFromModel();
3305:                        for (Element urlElem : urlAttachementList) {
3306:                            if (url.equals(urlElem.attributeValue("url"))) {
3307:                                belong = true;
3308:                            }
3309:                        }
3310:                        if (!belong) {
3311:                            return true;
3312:                        }
3313:                    }
3314:                }
3315:
3316:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
3317:                List<Element> fileAttachmentList = execElem
3318:                        .selectNodes("Attachements/FileAttachement");
3319:                for (Element fileElem : fileAttachmentList) {
3320:                    String nom = fileElem.attributeValue("nom");
3321:                    boolean belong = false;
3322:                    for (Attachment attach : envMap.values()) {
3323:                        if ((attach instanceof  FileAttachment)
3324:                                && ((FileAttachment) attach).getNameFromModel()
3325:                                        .equals(nom)) {
3326:                            belong = true;
3327:                        }
3328:                    }
3329:                    if (!belong) {
3330:                        return true;
3331:                    }
3332:                }
3333:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
3334:                for (Attachment attach : envMap.values()) {
3335:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
3336:                    boolean belong = false;
3337:                    for (Element fileElem : fileAttachmentList) {
3338:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
3339:                            belong = true;
3340:                        }
3341:                    }
3342:                    if (!belong) {
3343:                        return true;
3344:                    }
3345:                }
3346:
3347:                //dataset
3348:                Element jeuDonneesElem = execElem.element("JeuDonneesEx");
3349:                if (jeuDonneesElem != null) {
3350:                    String idExec = jeuDonneesElem.attributeValue("ref");
3351:                    if (idExec != null) {
3352:                        Element datasetElem = (Element) doc.getRootElement()
3353:                                .selectSingleNode(
3354:                                        "//JeuDonnees[@id_jeu='" + idExec
3355:                                                + "']");
3356:                        String datasetName = datasetElem.elementText("Nom");
3357:                        if (exec.getDataSetFromModel() == null
3358:                                || exec.getDataSetFromModel() != null
3359:                                && !datasetName.equals(exec
3360:                                        .getDataSetFromModel()
3361:                                        .getNameFromModel())) {
3362:                            return true;
3363:                        }
3364:                    }
3365:                }
3366:
3367:                //environment
3368:                String idEnv = execElem.element("EnvironnementEx")
3369:                        .attributeValue("ref");
3370:                Element envElem = (Element) doc.getRootElement()
3371:                        .selectSingleNode(
3372:                                "//Environnement[@idEnv='" + idEnv + "']");
3373:                String envName = envElem.elementText("Nom");
3374:                if (!envName.equals(exec.getEnvironmentFromModel()
3375:                        .getNameFromModel())) {
3376:                    return true;
3377:                }
3378:
3379:                //pre-script
3380:                Element preScriptElem = (Element) execElem
3381:                        .selectSingleNode("Script[@type='PRE_SCRIPT']");
3382:                if (preScriptElem != null) {
3383:                    Script preScript = exec.getPreScriptFromModel();
3384:                    if (preScript == null) {
3385:                        return true;
3386:                    } else {//compare md5
3387:                        File tempScriptFile = preScript.getFileFromDB(null);
3388:                        File fromXMLScriptFile = new File(dirXml
3389:                                + File.separator
3390:                                + preScriptElem.attributeValue("dir"));
3391:                        String md5DBScript = getDigest(tempScriptFile);
3392:                        String md5XMLScript = getDigest(fromXMLScriptFile);
3393:                        if (!md5DBScript.equals(md5XMLScript)) {
3394:                            return true;
3395:                        }
3396:                        tempScriptFile.delete();
3397:                    }
3398:                }
3399:
3400:                //post-script
3401:                Element postScriptElem = (Element) execElem
3402:                        .selectSingleNode("Script[@type='POST_SCRIPT']");
3403:                if (postScriptElem != null) {
3404:                    Script postScript = exec.getPostScriptFromModel();
3405:                    if (postScript == null) {
3406:                        return true;
3407:                    } else {//compare md5
3408:                        File tempScriptFile = postScript.getFileFromDB(null);
3409:                        File fromXMLScriptFile = new File(dirXml
3410:                                + File.separator
3411:                                + preScriptElem.attributeValue("dir"));
3412:                        String md5DBScript = getDigest(tempScriptFile);
3413:                        String md5XMLScript = getDigest(fromXMLScriptFile);
3414:                        if (!md5DBScript.equals(md5XMLScript)) {
3415:                            return true;
3416:                        }
3417:                        tempScriptFile.delete();
3418:                    }
3419:                }
3420:
3421:                return false;
3422:            }
3423:
3424:            /**
3425:             * Method which detects if the execution result in database must be copied or not.
3426:             * @param resExec execution result in DB
3427:             * @param resExecElem execution result in XML document
3428:             * @return
3429:             */
3430:            private boolean mustKeepCopy(ExecutionResult resExec,
3431:                    Element resExecElem) throws Exception {
3432:                //testeur
3433:                String testeur = resExecElem.elementText("Testeur");
3434:                if (testeur != null
3435:                        && !testeur.equals(resExec.getTesterFromModel())) {
3436:                    return true;
3437:                }
3438:
3439:                //attachements
3440:                List<Element> urlAttachementList = resExecElem
3441:                        .selectNodes("Attachements/UrlAttachement");
3442:                HashMap<String, Attachment> envMap = resExec
3443:                        .getAttachmentMapFromModel();
3444:                //vérifier que tous les url attachements qui sont dans le XML sont aussi dans la DB
3445:                for (Element urlElem : urlAttachementList) {
3446:                    String url = urlElem.attributeValue("url");
3447:                    boolean belong = false;
3448:                    for (Attachment attach : envMap.values()) {
3449:                        if ((attach instanceof  UrlAttachment)
3450:                                && ((UrlAttachment) attach).getNameFromModel()
3451:                                        .equals(url)) {
3452:                            belong = true;
3453:                        }
3454:                    }
3455:                    if (!belong) {
3456:                        return true;
3457:                    }
3458:                }
3459:                //vérifier que tous les url attachements qui sont dans la DB sont aussi dans le XML
3460:                for (Attachment attach : envMap.values()) {
3461:                    if (attach instanceof  UrlAttachment) {
3462:                        boolean belong = false;
3463:                        String url = ((UrlAttachment) attach)
3464:                                .getNameFromModel();
3465:                        for (Element urlElem : urlAttachementList) {
3466:                            if (url.equals(urlElem.attributeValue("url"))) {
3467:                                belong = true;
3468:                            }
3469:                        }
3470:                        if (!belong) {
3471:                            return true;
3472:                        }
3473:                    }
3474:                }
3475:
3476:                //vérification que tous les file attachments qui sont dans le XML sont aussi dans la DB
3477:                List<Element> fileAttachmentList = resExecElem
3478:                        .selectNodes("Attachements/FileAttachement");
3479:                for (Element fileElem : fileAttachmentList) {
3480:                    String nom = fileElem.attributeValue("nom");
3481:                    boolean belong = false;
3482:                    for (Attachment attach : envMap.values()) {
3483:                        if ((attach instanceof  FileAttachment)
3484:                                && ((FileAttachment) attach).getNameFromModel()
3485:                                        .equals(nom)) {
3486:                            belong = true;
3487:                        }
3488:                    }
3489:                    if (!belong) {
3490:                        return true;
3491:                    }
3492:                }
3493:                //vérification que tous les file attachment qui sont dans la bd sont aussi dans le document XML
3494:                for (Attachment attach : envMap.values()) {
3495:                    String nomBD = ((FileAttachment) attach).getNameFromModel();
3496:                    boolean belong = false;
3497:                    for (Element fileElem : fileAttachmentList) {
3498:                        if (nomBD.equals(fileElem.attributeValue("nom"))) {
3499:                            belong = true;
3500:                        }
3501:                    }
3502:                    if (!belong) {
3503:                        return true;
3504:                    }
3505:                }
3506:
3507:                //resulExec
3508:                List<Element> resulExecList = resExecElem
3509:                        .selectNodes("ResulExecs/ResulExec");
3510:                for (Element resulExec : resulExecList) {
3511:                    String idResulExecString = resulExec
3512:                            .attributeValue("refTest");
3513:                    int idResulExec = new Integer(idResulExecString
3514:                            .substring(5)).intValue();
3515:                    Test test = project.getTestFromModel(idResulExec);
3516:                    ExecutionTestResult testResult = resExec
3517:                            .getExecutionTestResultFromModel(test);
3518:                    String res = resulExec.attributeValue("res");
3519:                    String status = testResult.getStatusFromModel();
3520:                    if (res != null
3521:                            && (res.equals("PASSED") || res.equals("FAILED") || res
3522:                                    .equals("INCONCLUSIF"))) {
3523:                        if (!res.equals(status)) {
3524:                            return true;
3525:                        }
3526:                    } else if ((res == null || res.equals("") || res
3527:                            .equals("NonRenseigne"))
3528:                            && !status.equals("")) {
3529:                        return true;
3530:                    }
3531:                }
3532:
3533:                //resultActionTest
3534:                List<Element> resulActionTestList = resExecElem
3535:                        .selectNodes("ResulActionTests/ResulActionTest");
3536:                for (Element resulActionElem : resulActionTestList) {
3537:                    String idActionString = resulActionElem
3538:                            .attributeValue("refAction");
3539:                    String actionName = resulActionElem.element("RefAction")
3540:                            .elementText("NomAction");
3541:                    Element actionElem = (Element) doc.getRootElement()
3542:                            .selectSingleNode(
3543:                                    "//ActionTest[@id_action='"
3544:                                            + idActionString + "']");
3545:                    Element testElem = actionElem.getParent().getParent();
3546:                    String idTestString = testElem.attributeValue("id_test");
3547:                    int idTest = new Integer(idTestString.substring(5))
3548:                            .intValue();
3549:                    Test test = project.getTestFromModel(idTest);
3550:                    if (test instanceof  ManualTest) {
3551:                        Action action = ((ManualTest) test)
3552:                                .getActionFromModel(actionName);
3553:                        ExecutionTestResult pExecutionTestResult = resExec
3554:                                .getExecutionTestResultFromModel(test);
3555:                        if (pExecutionTestResult instanceof  ManualExecutionResult) {
3556:                            ManualExecutionResult pManualExecutionResult = (ManualExecutionResult) pExecutionTestResult;
3557:                            HashMap<Action, String> actionMap = pManualExecutionResult
3558:                                    .getActionsMapInModel();
3559:                            String resBD = actionMap.get(action);
3560:                            String resXML = resulActionElem
3561:                                    .attributeValue("res");
3562:                            if (resXML != null
3563:                                    && (resXML.equals("PASSED")
3564:                                            || resXML.equals("FAILED") || resXML
3565:                                            .equals("INCONCLUSIF"))) {
3566:                                if (!resXML.equals(resBD)) {
3567:                                    return true;
3568:                                }
3569:                            } else if ((resXML == null || resXML.equals("") || resXML
3570:                                    .equals("NonRenseigne"))
3571:                                    && !resBD.equals("")) {
3572:                                return true;
3573:                            }
3574:                        } else {
3575:                            return true;
3576:                        }
3577:                    } else {
3578:                        return true;
3579:                    }
3580:                }
3581:                return false;
3582:            }
3583:
3584:            private String restorePath(String path) throws Exception {
3585:                if (File.separator.equals("\\")) {
3586:                    //Unix2Windows
3587:                    return path.replace('/', '\\');
3588:                } else {
3589:                    return path.replace('\\', '/');
3590:                }
3591:            }
3592:
3593:            /**
3594:             * Cancel the current task
3595:             * @param b
3596:             */
3597:            public void setAnnule(boolean b) {
3598:                cancelled = b;
3599:            }
3600:
3601:            /**
3602:             * Verify if the task was cancelled
3603:             * @return
3604:             */
3605:            public boolean isAnnule() {
3606:                return cancelled;
3607:            }
3608:
3609:            /**
3610:             * Set the field defines if campaigns are also imported
3611:             * @param selected
3612:             */
3613:            public void setImportCampaign(boolean importCampaign) {
3614:                this .importCampaign = importCampaign;
3615:            }
3616:
3617:            /**
3618:             * Set the directory where the XML file is
3619:             * @param dirXml
3620:             */
3621:            public void setDirXml(String dirXml) {
3622:                this .dirXml = dirXml;
3623:            }
3624:
3625:            /**
3626:             * Return true if the list of selected tests was initialized
3627:             * @return
3628:             */
3629:            public boolean isInitSelection() {
3630:                return initSelection;
3631:            }
3632:
3633:            /**
3634:             * True in parameter if the test selection has been already initialized
3635:             * @param initSelection
3636:             */
3637:            public void setInitSelection(boolean initSelection) {
3638:                this.initSelection = initSelection;
3639:            }
3640:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.