Source Code Cross Referenced for Campaign.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » data » 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 » org.objectweb.salome_tmf.data 
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 Marche Mikael
0020:         *
0021:         * Contact: mikael.marche@rd.francetelecom.com
0022:         */
0023:
0024:        package org.objectweb.salome_tmf.data;
0025:
0026:        import java.io.File;
0027:        import java.sql.Date;
0028:        import java.util.ArrayList;
0029:        import java.util.Collections;
0030:        import java.util.Comparator;
0031:        import java.util.GregorianCalendar;
0032:        import java.util.Hashtable;
0033:        import java.util.Vector;
0034:
0035:        import org.objectweb.salome_tmf.api.Api;
0036:        import org.objectweb.salome_tmf.api.ApiConstants;
0037:        import org.objectweb.salome_tmf.api.Util;
0038:        import org.objectweb.salome_tmf.api.data.CampaignWrapper;
0039:        import org.objectweb.salome_tmf.api.data.DataSetWrapper;
0040:        import org.objectweb.salome_tmf.api.data.ExecutionAttachmentWrapper;
0041:        import org.objectweb.salome_tmf.api.data.ExecutionWrapper;
0042:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
0043:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
0044:        import org.objectweb.salome_tmf.api.data.TestCampWrapper;
0045:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
0046:        import org.objectweb.salome_tmf.api.sql.ISQLCampaign;
0047:
0048:        public class Campaign extends WithAttachment {
0049:
0050:            static ISQLCampaign pISQLCampaign = null;
0051:            protected ArrayList suiteList;
0052:            protected ArrayList testList;
0053:            protected Hashtable testAssigned;
0054:            protected ArrayList familyList;
0055:            protected Date creationDate;
0056:            protected String conceptor;
0057:            protected ArrayList executionList;
0058:            protected ArrayList dataSetList;
0059:            protected int order;
0060:
0061:            public Campaign(String name, String description) {
0062:                super (name, description);
0063:                suiteList = new ArrayList();
0064:                testList = new ArrayList();
0065:                familyList = new ArrayList();
0066:                creationDate = new Date(GregorianCalendar.getInstance()
0067:                        .getTimeInMillis());
0068:                conceptor = "";
0069:                executionList = new ArrayList();
0070:                dataSetList = new ArrayList();
0071:                testAssigned = new Hashtable();
0072:                if (pISQLCampaign == null) {
0073:                    pISQLCampaign = Api.getISQLObjectFactory()
0074:                            .getISQLCampaign();
0075:                }
0076:
0077:            }
0078:
0079:            public Campaign(CampaignWrapper pCampaign) {
0080:                super (pCampaign.getName(), pCampaign.getDescription());
0081:                creationDate = pCampaign.getDate();
0082:                conceptor = pCampaign.getConceptor();
0083:                idBdd = pCampaign.getIdBDD();
0084:                suiteList = new ArrayList();
0085:                testList = new ArrayList();
0086:                familyList = new ArrayList();
0087:                executionList = new ArrayList();
0088:                dataSetList = new ArrayList();
0089:                testAssigned = new Hashtable();
0090:                order = pCampaign.getOrder();
0091:                if (pISQLCampaign == null) {
0092:                    pISQLCampaign = Api.getISQLObjectFactory()
0093:                            .getISQLCampaign();
0094:                }
0095:            }
0096:
0097:            public static Campaign copieIn(Campaign toCopie, User pUser)
0098:                    throws Exception {
0099:                Campaign pCopie = new Campaign(toCopie.getNameFromModel(),
0100:                        toCopie.getDescriptionFromModel());
0101:                String campName = toCopie.getNameFromModel();
0102:                int i = 0;
0103:                while (pCopie
0104:                        .isInBase(DataLoader.getCurrentProject(), campName)) {
0105:                    campName = toCopie.getNameFromModel() + "_" + i;
0106:                    i++;
0107:                }
0108:                pCopie.updateInModel(campName, toCopie
0109:                        .getDescriptionFromModel());
0110:                DataLoader.getCurrentProject().addCampaignInDBandModel(pCopie);
0111:                ArrayList testList = toCopie.getTestListFromModel();
0112:                int size = testList.size();
0113:                for (i = 0; i < size; i++) {
0114:                    Test pTest = (Test) testList.get(i);
0115:                    int userID = pUser.getIdBdd();
0116:                    pCopie.importTestInDBAndModel(pTest, userID);
0117:                }
0118:                pCopie.setConceptorInModel(pUser.getLoginFromModel());
0119:                return pCopie;
0120:            }
0121:
0122:            public Date getDateFromModel() {
0123:                return creationDate;
0124:            }
0125:
0126:            public String getConceptorFroModel() {
0127:                return conceptor;
0128:            }
0129:
0130:            public void setConceptorInModel(String name) {
0131:                conceptor = name;
0132:            }
0133:
0134:            public int getAssignedUserID(Test pTest) {
0135:                int id = -1;
0136:                Integer userID = (Integer) testAssigned.get(new Integer(pTest
0137:                        .getIdBdd()));
0138:                if (userID != null) {
0139:                    id = userID.intValue();
0140:                }
0141:                return id;
0142:            }
0143:
0144:            public void clearAssignedUserForTest() {
0145:                testAssigned.clear();
0146:            }
0147:
0148:            public void setDateInModel(Date date) {
0149:                creationDate = date;
0150:            }
0151:
0152:            public Family containsFamilyInModel(String name) {
0153:                for (int i = 0; i < familyList.size(); i++) {
0154:                    if (((Family) familyList.get(i)).getNameFromModel().equals(
0155:                            name)) {
0156:                        return (Family) familyList.get(i);
0157:                    }
0158:                }
0159:                return null;
0160:            }
0161:
0162:            public boolean containsFamilyInModel(Family family) {
0163:                for (int i = 0; i < familyList.size(); i++) {
0164:                    if (((Family) familyList.get(i)).equals(family)) {
0165:                        return true;
0166:                    }
0167:                }
0168:                return false;
0169:            }
0170:
0171:            public boolean containsTestListInModel(TestList testList) {
0172:                for (int i = 0; i < suiteList.size(); i++) {
0173:                    if (((TestList) suiteList.get(i)).equals(testList)) {
0174:                        return true;
0175:                    }
0176:                }
0177:                return false;
0178:            }
0179:
0180:            public TestList containsTestListInModel(String name) {
0181:                for (int i = 0; i < suiteList.size(); i++) {
0182:                    if (((TestList) suiteList.get(i)).getNameFromModel()
0183:                            .equals(name)) {
0184:                        return (TestList) suiteList.get(i);
0185:                    }
0186:                }
0187:                return null;
0188:            }
0189:
0190:            public boolean containsTestInModel(Test test) {
0191:                for (int i = 0; i < testList.size(); i++) {
0192:                    if (((Test) testList.get(i)).equals(test)) {
0193:                        return true;
0194:                    }
0195:                }
0196:                return false;
0197:            }
0198:
0199:            public Test containsTestInModel(int testId) {
0200:                for (int i = 0; i < testList.size(); i++) {
0201:                    Test pTest = (Test) testList.get(i);
0202:                    if (pTest.getIdBdd() == testId) {
0203:                        return pTest;
0204:                    }
0205:                }
0206:                return null;
0207:            }
0208:
0209:            public boolean containsTestInModel(String testName) {
0210:                for (int i = 0; i < testList.size(); i++) {
0211:                    if (((Test) testList.get(i)).getNameFromModel().equals(
0212:                            testName)) {
0213:                        return true;
0214:                    }
0215:                }
0216:                return false;
0217:            }
0218:
0219:            public boolean containsExecutionResultInModel() {
0220:                for (int i = 0; i < executionList.size(); i++) {
0221:                    if (((Execution) executionList.get(i))
0222:                            .getExecutionResultListFromModel().size() > 0) {
0223:                        return true;
0224:                    }
0225:                }
0226:                return false;
0227:            }
0228:
0229:            public boolean containsExecutionInModel(String execName) {
0230:                for (int i = 0; i < executionList.size(); i++) {
0231:                    if (((Execution) executionList.get(i)).getNameFromModel()
0232:                            .equals(execName)) {
0233:                        return true;
0234:                    }
0235:                }
0236:                return false;
0237:            }
0238:
0239:            /************* Basic Operation ****************/
0240:
0241:            public void addInDB(int idProject, int idUser) throws Exception {
0242:                if (isInBase()) {
0243:                    throw new Exception("Campaign " + name
0244:                            + " is already in BDD");
0245:                }
0246:                idBdd = pISQLCampaign.insert(idProject, name, description,
0247:                        idUser);
0248:                Project.pCurrentProject.notifyChanged(
0249:                        ApiConstants.INSERT_CAMPAIGN, this );
0250:
0251:            }
0252:
0253:            /**
0254:             * 
0255:             * @return true if model is inconistant
0256:             * @throws Exception
0257:             */
0258:            public boolean reloadCampain(ArrayList testInModel,
0259:                    ArrayList envInModel, Hashtable paramInModel)
0260:                    throws Exception {
0261:                boolean ret = false;
0262:                CampaignWrapper pCampaignWrapper = pISQLCampaign
0263:                        .getCampaign(idBdd);
0264:                updateInModel(pCampaignWrapper.getName(), pCampaignWrapper
0265:                        .getDescription());
0266:                ret = reloadTestInCampaign(testInModel);
0267:                if (ret == true) {
0268:                    return ret;
0269:                }
0270:                reloadDataSetFromBase(paramInModel);
0271:                reloadExcecutionInModel(envInModel, paramInModel);
0272:                return ret;
0273:            }
0274:
0275:            public void reloadTestCampain(ArrayList testInModel)
0276:                    throws Exception {
0277:                reloadTestInCampaign(testInModel);
0278:            }
0279:
0280:            int importTestInDB(int testId, int userID) throws Exception {
0281:                if (!isInBase()) {
0282:                    throw new Exception("Campaign " + name + " is not in BDD");
0283:                }
0284:
0285:                return pISQLCampaign.importTest(idBdd, testId, userID);
0286:            }
0287:
0288:            boolean importTestInDB(int testId, int order, int userID)
0289:                    throws Exception {
0290:                boolean needUpdate = false;
0291:                if (isInBase()) {
0292:                    throw new Exception("Campaign " + name
0293:                            + " is already in BDD");
0294:                }
0295:                int maxOrder = importTestInDB(testId, userID);
0296:                if (order != maxOrder) {
0297:                    needUpdate = true;
0298:                }
0299:                return needUpdate;
0300:
0301:            }
0302:
0303:            public void importTestInDBAndModel(Test pTest, int userID)
0304:                    throws Exception {
0305:                importTestInDB(pTest.getIdBdd(), userID);
0306:                addTestInModel(pTest, userID);
0307:            }
0308:
0309:            public void updateInDB(String newName, String newDesc)
0310:                    throws Exception {
0311:                if (!isInBase()) {
0312:                    throw new Exception("Campaign " + name + " is not in BDD");
0313:                }
0314:                if (!isInBase()) {
0315:                    throw new Exception("Campaign " + name + " is not in BDD");
0316:                }
0317:                pISQLCampaign.update(idBdd, newName, newDesc);
0318:                Project.pCurrentProject.notifyChanged(
0319:                        ApiConstants.UPDATE_CAMPAIGN, this , new String(name),
0320:                        newName);
0321:            }
0322:
0323:            public void updateInModel(String newName, String newDesc) {
0324:                setNameInModel(newName);
0325:                updateDescriptionInModel(newDesc);
0326:            }
0327:
0328:            public void updateInDBAndModel(String newName, String newDesc)
0329:                    throws Exception {
0330:                updateInDB(newName, newDesc);
0331:                updateInModel(newName, newDesc);
0332:            }
0333:
0334:            public void updateOrderInDBAndModel(boolean inc) throws Exception {
0335:                if (!isInBase()) {
0336:                    throw new Exception("Campaign " + name + " is not in BDD");
0337:                }
0338:                pISQLCampaign.updateOrder(idBdd, inc);
0339:            }
0340:
0341:            public void updateTestSuiteOrderInDB(int idSuite, boolean inc)
0342:                    throws Exception {
0343:                if (!isInBase()) {
0344:                    throw new Exception("Campaign " + name + " is not in BDD");
0345:                }
0346:                pISQLCampaign.updateTestSuiteOrder(idBdd, idSuite, inc);
0347:            }
0348:
0349:            public void updateTestFamilyOrderInDB(int idFamily, boolean inc)
0350:                    throws Exception {
0351:                if (!isInBase()) {
0352:                    throw new Exception("Campaign " + name + " is not in BDD");
0353:                }
0354:                pISQLCampaign.updateTestFamilyOrder(idBdd, idFamily, inc);
0355:            }
0356:
0357:            public void updateTestOrderInDB(int testId, boolean inc)
0358:                    throws Exception {
0359:                if (!isInBase()) {
0360:                    throw new Exception("Campaign " + name + " is not in BDD");
0361:                }
0362:                pISQLCampaign.updateTestOrder(idBdd, testId, inc);
0363:            }
0364:
0365:            public void deleteInDB() throws Exception {
0366:                if (!isInBase()) {
0367:                    throw new Exception("Campaign " + name + " is not in BDD");
0368:                }
0369:                pISQLCampaign.delete(idBdd);
0370:                Project.pCurrentProject.notifyChanged(
0371:                        ApiConstants.DELETE_CAMPAIGN, this );
0372:            }
0373:
0374:            void updateTestAssignationInDB(int idTest, int idUser)
0375:                    throws Exception {
0376:                if (!isInBase()) {
0377:                    throw new Exception("Campaign " + name + " is not in BDD");
0378:                }
0379:                pISQLCampaign.updateTestAssignation(idBdd, idTest, idUser);
0380:            }
0381:
0382:            void updateTestAssignationInModel(int idTest, int idUser) {
0383:                //if (containsTestInModel(idTest) != null){;
0384:                testAssigned.put(new Integer(idTest), new Integer(idUser));
0385:                //}
0386:            }
0387:
0388:            public void updateTestAssignationInDBAndModel(int idTest, int idUser)
0389:                    throws Exception {
0390:                updateTestAssignationInDB(idTest, idUser);
0391:                updateTestAssignationInModel(idTest, idUser);
0392:            }
0393:
0394:            void updateSuiteAssignationInDB(int idSuite, int idUser)
0395:                    throws Exception {
0396:                if (!isInBase()) {
0397:                    throw new Exception("Campaign " + name + " is not in BDD");
0398:                }
0399:                pISQLCampaign.updateSuiteAssignation(idBdd, idSuite, idUser);
0400:            }
0401:
0402:            void updateSuiteAssignationInModel(int idSuite, int idUser) {
0403:                int size = testList.size();
0404:                for (int i = 0; i < size; i++) {
0405:                    Test pTest = (Test) testList.get(i);
0406:                    if (pTest.getTestListFromModel().getIdBdd() == idSuite) {
0407:                        updateTestAssignationInModel(pTest.getIdBdd(), idUser);
0408:                    }
0409:                }
0410:                /*int size = suiteList.size();
0411:                for (int i = 0 ; i < size ; i++){
0412:                	TestList pTestList = (TestList) suiteList.get(i);
0413:                	if (pTestList.getIdBdd() == idSuite){
0414:                		ArrayList listOfTest = pTestList.getTestListFromModel();
0415:                		int size2 = listOfTest.size();
0416:                		for (int j=0; j < size2 ; j++){
0417:                			Test pTest = (Test) listOfTest.get(j);
0418:                			if (containsTestInModel(pTest.getIdBdd()) != null){
0419:                				updateTestAssignationInModel(pTest.getIdBdd(), idUser);
0420:                			}
0421:                		}
0422:                		i = size; // Break IF 
0423:                	}
0424:                }*/
0425:            }
0426:
0427:            public void updateSuiteAssignationInDBAndModel(int idSuite,
0428:                    int idUser) throws Exception {
0429:                updateSuiteAssignationInDB(idSuite, idUser);
0430:                updateSuiteAssignationInModel(idSuite, idUser);
0431:            }
0432:
0433:            void updateFamilyAssignationInDB(int idFamily, int idUser)
0434:                    throws Exception {
0435:                if (!isInBase()) {
0436:                    throw new Exception("Campaign " + name + " is not in BDD");
0437:                }
0438:                pISQLCampaign.updateFamilyAssignation(idBdd, idFamily, idUser);
0439:            }
0440:
0441:            void updateFamilyAssignationInModel(int idFamily, int idUser) {
0442:                int size = testList.size();
0443:                for (int i = 0; i < size; i++) {
0444:                    Test pTest = (Test) testList.get(i);
0445:                    if (pTest.getTestListFromModel().getFamilyFromModel()
0446:                            .getIdBdd() == idFamily) {
0447:                        updateTestAssignationInModel(pTest.getIdBdd(), idUser);
0448:                    }
0449:                }
0450:                /*int size = suiteList.size();
0451:                for (int i = 0 ; i < size ; i++){
0452:                	TestList pTestList = (TestList) suiteList.get(i);
0453:                	if (pTestList.getFamilyFromModel().getIdBdd() == idFamily){
0454:                		ArrayList listOfTest = pTestList.getTestListFromModel();
0455:                		int size2 = listOfTest.size();
0456:                		for (int j=0; j < size2 ; j++){
0457:                			Test pTest = (Test) listOfTest.get(j);
0458:                			if (containsTestInModel(pTest.getIdBdd()) != null){
0459:                				updateTestAssignationInModel(pTest.getIdBdd(), idUser);
0460:                			}
0461:                		}
0462:                		i = size; // Break IF 
0463:                	}
0464:                }*/
0465:            }
0466:
0467:            public void updateFamilyAssignationInDBAndModel(int idFamily,
0468:                    int idUser) throws Exception {
0469:                updateFamilyAssignationInDB(idFamily, idUser);
0470:                updateFamilyAssignationInModel(idFamily, idUser);
0471:            }
0472:
0473:            void updateCampaignAssignationInDB(int idUser) throws Exception {
0474:                if (!isInBase()) {
0475:                    throw new Exception("Campaign " + name + " is not in BDD");
0476:                }
0477:                pISQLCampaign.updateCampagneAssignationRef(idBdd, idUser);
0478:            }
0479:
0480:            void updateCampaignAssignationInModel(int idUser) {
0481:                int size = testList.size();
0482:                for (int i = 0; i < size; i++) {
0483:                    Test pTest = (Test) testList.get(i);
0484:                    updateTestAssignationInModel(pTest.getIdBdd(), idUser);
0485:                }
0486:            }
0487:
0488:            public void updateCampaignAssignationInDBAndModel(int idUser)
0489:                    throws Exception {
0490:                updateCampaignAssignationInDB(idUser);
0491:                updateCampaignAssignationInModel(idUser);
0492:            }
0493:
0494:            public void deleteInModel() {
0495:                testList.clear();
0496:                suiteList.clear();
0497:                familyList.clear();
0498:                purgeExcecutionInModel(true);
0499:                executionList.clear();
0500:                purgeDataSetInModel();
0501:                dataSetList.clear();
0502:                clearAttachInModel();
0503:            }
0504:
0505:            public void deleteInDBAndModel() throws Exception {
0506:                deleteInDB();
0507:                deleteInModel();
0508:            }
0509:
0510:            /******************* About Family **********************/
0511:            public void setFamilyListInModel(ArrayList list) {
0512:                familyList = list;
0513:            }
0514:
0515:            void addFamilyInModel(Family family) {
0516:                if (!familyList.contains(family)) {
0517:                    familyList.add(family);
0518:                }
0519:            }
0520:
0521:            public void addFamilyTestListAndTest(Family family) {
0522:                for (int i = 0; i < family.getSuiteListFromModel().size(); i++) {
0523:                    for (int j = 0; j < ((TestList) family
0524:                            .getSuiteListFromModel().get(i))
0525:                            .getTestListFromModel().size(); j++) {
0526:                        if (!testList.contains(((TestList) family
0527:                                .getSuiteListFromModel().get(i))
0528:                                .getTestListFromModel().get(j))) {
0529:                            this .testList.add(((TestList) family
0530:                                    .getSuiteListFromModel().get(i))
0531:                                    .getTestListFromModel().get(j));
0532:                        }
0533:                    }
0534:                    if (!suiteList.contains((family.getSuiteListFromModel()
0535:                            .get(i)))) {
0536:                        this .suiteList.add((family.getSuiteListFromModel()
0537:                                .get(i)));
0538:                    }
0539:                }
0540:                if (!familyList.contains(family)) {
0541:                    familyList.add(family);
0542:                }
0543:            }
0544:
0545:            public boolean removeFamily(Family family) {
0546:                for (int j = suiteList.size() - 1; j >= 0; j--) {
0547:                    if (((TestList) suiteList.get(j)).getFamilyFromModel()
0548:                            .getNameFromModel().equals(
0549:                                    family.getNameFromModel())) {
0550:                        TestList list = (TestList) suiteList.get(j);
0551:                        //removeTestList(list);
0552:                        suiteList.remove(j);
0553:                        for (int k = testList.size() - 1; k >= 0; k--) {
0554:                            if (((Test) testList.get(k)).getTestListFromModel()
0555:                                    .equals(list)) {
0556:                                for (int i = 0; i < executionList.size(); i++) {
0557:                                    ((Execution) executionList.get(i))
0558:                                            .deleteTestFromExecInModel(((Test) testList
0559:                                                    .get(k)));
0560:                                }
0561:                                testList.remove(k);
0562:                            }
0563:                        }
0564:                    }
0565:                }
0566:                familyList.remove(family);
0567:
0568:                purgeExcecutionInModel(true);
0569:
0570:                return (testList.size() == 0);
0571:            }
0572:
0573:            public ArrayList getFamilyListFromModel() {
0574:                return familyList;
0575:            }
0576:
0577:            /******************* About Suite *************************/
0578:
0579:            public void setSuiteListInModel(ArrayList list) {
0580:                suiteList = list;
0581:            }
0582:
0583:            public void addTestList(TestList list) {
0584:                for (int i = 0; i < list.getTestListFromModel().size(); i++) {
0585:                    if (!testList.contains(list.getTestListFromModel().get(i))) {
0586:                        this .testList.add(list.getTestListFromModel().get(i));
0587:                    }
0588:                }
0589:                if (!suiteList.contains(list)) {
0590:                    suiteList.add(list);
0591:                }
0592:                if (!familyList.contains(list.getFamilyFromModel())) {
0593:                    familyList.add(list.getFamilyFromModel());
0594:                }
0595:            }
0596:
0597:            public void addOnlyTestListInModel(TestList list) {
0598:                if (!suiteList.contains(list)) {
0599:                    suiteList.add(list);
0600:                }
0601:            }
0602:
0603:            public boolean removeTestListInModel(TestList list) {
0604:                int j = 0;
0605:                while (j < testList.size()) {
0606:                    if (((Test) testList.get(j)).getTestListFromModel()
0607:                            .getNameFromModel().equals(list.getNameFromModel())) {
0608:                        //removeTest(((Test) testList.get(j)));
0609:                        for (int k = 0; k < executionList.size(); k++) {
0610:                            ((Execution) executionList.get(k))
0611:                                    .deleteTestFromExecInModel(((Test) testList
0612:                                            .get(j)));
0613:                        }
0614:                        testList.remove(j);
0615:                    } else {
0616:                        j++;
0617:                    }
0618:                }
0619:                suiteList.remove(list);
0620:                boolean otherListOfSameFamilyExist = false;
0621:                int i = 0;
0622:                while (!otherListOfSameFamilyExist && i < suiteList.size()) {
0623:                    if (((TestList) suiteList.get(i)).getFamilyFromModel()
0624:                            .getNameFromModel().equals(
0625:                                    list.getFamilyFromModel()
0626:                                            .getNameFromModel())) {
0627:                        otherListOfSameFamilyExist = true;
0628:                    }
0629:                    i++;
0630:                }
0631:                if (!otherListOfSameFamilyExist) {
0632:                    familyList.remove(list.getFamilyFromModel());
0633:                }
0634:
0635:                purgeExcecutionInModel(true);
0636:
0637:                return (testList.size() == 0);
0638:            }
0639:
0640:            public ArrayList getSuitListFromModel() {
0641:                return suiteList;
0642:            }
0643:
0644:            public int getTestOrderInModel(Test test) {
0645:                for (int i = 0; i < testList.size(); i++) {
0646:                    if (((Test) testList.get(i)).equals(test)) {
0647:                        return i;
0648:                    }
0649:                }
0650:                return -1;
0651:            }
0652:
0653:            /********************* About tests  **********************/
0654:            Test findTestByID(int idTest, ArrayList testInModel) {
0655:                for (int i = 0; i < testInModel.size(); i++) {
0656:                    Test pTest = (Test) testInModel.get(i);
0657:                    if (pTest.getIdBdd() == idTest) {
0658:                        return pTest;
0659:                    }
0660:                }
0661:                return null;
0662:            }
0663:
0664:            /**
0665:             * 
0666:             * @param testInModel
0667:             * @return true if model is not completed
0668:             * @throws Exception
0669:             */
0670:            protected boolean reloadTestInCampaign(ArrayList testInModel)
0671:                    throws Exception {
0672:                boolean ret = false;
0673:                Vector testCampWrapperList = getTestsByOrderFromDB();
0674:                for (int i = 0; i < testCampWrapperList.size(); i++) {
0675:                    TestCampWrapper pTestCampWrapper = (TestCampWrapper) testCampWrapperList
0676:                            .elementAt(i);
0677:                    int idTest = pTestCampWrapper.getIdBDD();
0678:                    Test pTest = findTestByID(idTest, testList);
0679:                    if (pTest == null) {
0680:                        // Try to Find Test In testPlan
0681:                        pTest = findTestByID(idTest, testInModel);
0682:                        if (pTest != null) {
0683:                            addTestInModel(pTest, pTestCampWrapper.getIdUser());
0684:                        } else {
0685:                            /* TODO Reload Testplan */
0686:                            return true;
0687:                        }
0688:                    } else {
0689:                        //Update
0690:                        updateTestAssignationInModel(pTest.getIdBdd(),
0691:                                pTestCampWrapper.getIdUser());
0692:                    }
0693:                }
0694:                int size = testList.size();
0695:                Vector test2Remove = new Vector();
0696:                for (int i = 0; i < size; i++) {
0697:                    Test pTest = (Test) testList.get(i);
0698:                    boolean trouve = false;
0699:                    int j = 0;
0700:                    int size2 = testCampWrapperList.size();
0701:                    while (j < size2 && !trouve) {
0702:                        TestCampWrapper pTestCampWrapper = (TestCampWrapper) testCampWrapperList
0703:                                .elementAt(j);
0704:                        if (pTestCampWrapper.getIdBDD() == pTest.getIdBdd()) {
0705:                            trouve = true;
0706:                        }
0707:                        j++;
0708:                    }
0709:                    if (!trouve) {
0710:                        test2Remove.add(pTest);
0711:
0712:                    }
0713:
0714:                }
0715:                size = test2Remove.size();
0716:                for (int i = 0; i < size; i++) {
0717:                    Test pTest = (Test) test2Remove.get(i);
0718:                    deleteTestFromCampInModel(pTest, true);
0719:                }
0720:
0721:                //Roerder 
0722:                triTestInModel(testCampWrapperList);
0723:                return ret;
0724:
0725:                /*suiteList.clear();
0726:                testList.clear();
0727:                familyList.clear();
0728:                Vector testCampWrapperList = getTestsByOrderFromDB();
0729:                for (int i = 0; i < testCampWrapperList.size() ; i++){
0730:                	TestCampWrapper pTestCampWrapper = (TestCampWrapper)testCampWrapperList.elementAt(i);
0731:                	int idTest = pTestCampWrapper.getIdBDD();
0732:                	Test pTest = findTestByID(idTest,testInModel);
0733:                	addTestInModel(pTest);
0734:                }*/
0735:            }
0736:
0737:            public void setTestListInModel(ArrayList list) {
0738:                testList = list;
0739:
0740:            }
0741:
0742:            public void fillCampInModel(ArrayList list, User pUser) {
0743:                suiteList.clear();
0744:                testList.clear();
0745:                familyList.clear();
0746:                int size = list.size();
0747:                for (int i = 0; i < size; i++) {
0748:                    Util.log("Fill test : "
0749:                            + ((Test) list.get(i)).getNameFromModel());
0750:                    addTestInModel((Test) list.get(i), pUser.getIdBdd());
0751:                }
0752:            }
0753:
0754:            public void addTestInModel(Test test, int userID) {
0755:                if (!testList.contains(test)) {
0756:                    testList.add(test);
0757:                }
0758:                if (!suiteList.contains(test.getTestListFromModel())) {
0759:                    suiteList.add(test.getTestListFromModel());
0760:                    //test.getTestList().
0761:                }
0762:                if (!familyList.contains(test.getTestListFromModel()
0763:                        .getFamilyFromModel())) {
0764:                    familyList.add(test.getTestListFromModel()
0765:                            .getFamilyFromModel());
0766:                }
0767:                testAssigned.put(new Integer(test.getIdBdd()), new Integer(
0768:                        userID));
0769:            }
0770:
0771:            public void deleteTestFromCampInDB(int testId, boolean deleteExec)
0772:                    throws Exception {
0773:                if (!isInBase()) {
0774:                    throw new Exception("Campaign " + name + " is not in BDD");
0775:                }
0776:                pISQLCampaign.deleteTest(idBdd, testId, deleteExec);
0777:            }
0778:
0779:            public boolean deleteTestFromCampInModel(Test test,
0780:                    boolean deleteExec) {
0781:                testList.remove(test);
0782:                boolean otherTestOfSameListExist = false;
0783:                int i = 0;
0784:                while (!otherTestOfSameListExist && i < testList.size()) {
0785:                    if (((Test) testList.get(i)).getTestListFromModel()
0786:                            .getNameFromModel().equals(
0787:                                    test.getTestListFromModel()
0788:                                            .getNameFromModel())) {
0789:                        otherTestOfSameListExist = true;
0790:                    }
0791:                    i++;
0792:                }
0793:                if (!otherTestOfSameListExist) {
0794:                    suiteList.remove(test.getTestListFromModel());
0795:                }
0796:                boolean otherListOfSameFamilyExist = false;
0797:                i = 0;
0798:                while (!otherListOfSameFamilyExist && i < suiteList.size()) {
0799:                    if (((TestList) suiteList.get(i)).getFamilyFromModel()
0800:                            .getNameFromModel().equals(
0801:                                    test.getTestListFromModel()
0802:                                            .getFamilyFromModel()
0803:                                            .getNameFromModel())) {
0804:                        otherListOfSameFamilyExist = true;
0805:                    }
0806:                    i++;
0807:                }
0808:                if (!otherListOfSameFamilyExist) {
0809:                    familyList.remove(test.getTestListFromModel()
0810:                            .getFamilyFromModel());
0811:                }
0812:
0813:                for (int j = 0; j < executionList.size(); j++) {
0814:                    ((Execution) executionList.get(j))
0815:                            .deleteTestFromExecInModel(test);
0816:                }
0817:
0818:                purgeExcecutionInModel(deleteExec);
0819:                testAssigned.remove(new Integer(test.getIdBdd()));
0820:                return (testList.size() == 0);
0821:            }
0822:
0823:            public void deleteTestFromCampInDBAndModel(Test test,
0824:                    boolean deleteExec) throws Exception {
0825:                deleteTestFromCampInDB(test.getIdBdd(), deleteExec);
0826:                deleteTestFromCampInModel(test, deleteExec);
0827:            }
0828:
0829:            public ArrayList getTestListFromModel() {
0830:                return testList;
0831:            }
0832:
0833:            public Vector getTestsByOrderFromDB() throws Exception {
0834:                if (!isInBase()) {
0835:                    throw new Exception("Campaign " + name + " is not in BDD");
0836:                }
0837:                TestCampWrapper[] tmpArray = pISQLCampaign
0838:                        .getTestsByOrder(idBdd);
0839:                Vector tmpVector = new Vector();
0840:                for (int i = 0; i < tmpArray.length; i++) {
0841:                    tmpVector.add(tmpArray[i]);
0842:                }
0843:                return tmpVector;
0844:            }
0845:
0846:            /**
0847:             * Add test in campaign by synchronizing data in test plan (Family, Testlist) which is in the campaign 
0848:             * by addind contening test in the campaign
0849:             * @param data
0850:             * @return true if the campaign change
0851:             * @throws Exception
0852:             */
0853:            public boolean synchronizeWithTestPlanFromModel(SimpleData data,
0854:                    int userID) throws Exception {
0855:                boolean res = false;
0856:                ArrayList<Test> test2add = null;
0857:
0858:                if (data instanceof  TestList) {
0859:                    TestList pTestList = (TestList) data;
0860:                    if (!pTestList.isInBase()) {
0861:                        return false;
0862:                    }
0863:                    if (!containsTestListInModel(pTestList)) {
0864:                        return false;
0865:                    }
0866:                    test2add = (ArrayList<Test>) pTestList
0867:                            .getTestListFromModel();
0868:                } else if (data instanceof  Family) {
0869:                    Family pFamily = (Family) data;
0870:                    if (!pFamily.isInBase()) {
0871:                        return false;
0872:                    }
0873:                    if (!containsFamilyInModel(pFamily)) {
0874:                        return false;
0875:                    }
0876:                    ArrayList<TestList> suite2add = pFamily
0877:                            .getSuiteListFromModel();
0878:                    int size = suite2add.size();
0879:                    test2add = new ArrayList<Test>();
0880:                    for (int i = 0; i < size; i++) {
0881:                        TestList pTestList = suite2add.get(i);
0882:                        ArrayList<Test> test2add_tmp = (ArrayList<Test>) pTestList
0883:                                .getTestListFromModel();
0884:                        test2add.addAll(test2add_tmp);
0885:                    }
0886:                } else {
0887:                    return false;
0888:                }
0889:                int size = test2add.size();
0890:                for (int i = 0; i < size; i++) {
0891:                    Test pTest = test2add.get(i);
0892:                    if (!containsTestInModel(pTest)) {
0893:                        /** Ajout du test dans la campaigne **/
0894:                        importTestInDBAndModel(pTest, userID);
0895:                        res = true;
0896:                    }
0897:                }
0898:
0899:                return res;
0900:            }
0901:
0902:            /********************* About DataSet *********************/
0903:
0904:            public void loadDataSetFromBase(Hashtable paramsInModel)
0905:                    throws Exception {
0906:                if (!isInBase()) {
0907:                    throw new Exception("Campaign " + name + " is not in BDD");
0908:                }
0909:                purgeDataSetInModel();
0910:                Vector dataSetVector = getDatagetDataSetListWrapperFromDB();
0911:                for (int i = 0; i < dataSetVector.size(); i++) {
0912:                    DataSet dataSet = new DataSet(
0913:                            (DataSetWrapper) dataSetVector.get(i));
0914:                    dataSet.reloadFromDB(false, paramsInModel);
0915:                    addDataSetInModel(dataSet);
0916:                }
0917:
0918:            }
0919:
0920:            protected void reloadDataSetFromBase(Hashtable paramsInModel)
0921:                    throws Exception {
0922:                if (!isInBase()) {
0923:                    throw new Exception("Campaign " + name + " is not in BDD");
0924:                }
0925:                int size = dataSetList.size();
0926:                Vector dataSetVector = getDatagetDataSetListWrapperFromDB();
0927:                int size2 = dataSetVector.size();
0928:                Vector dataSet2Remove = new Vector();
0929:
0930:                for (int i = 0; i < size; i++) {
0931:                    DataSet pDataSet = (DataSet) dataSetList.get(i);
0932:                    int j = 0;
0933:                    boolean trouve = false;
0934:                    while (j < size2 && !trouve) {
0935:                        DataSet dataSet = new DataSet(
0936:                                (DataSetWrapper) dataSetVector.get(j));
0937:                        if (pDataSet.getIdBdd() == dataSet.getIdBdd()) {
0938:                            trouve = true;
0939:                            pDataSet.reloadFromDB(true, paramsInModel);
0940:                        }
0941:                        j++;
0942:                    }
0943:                    if (trouve == false) {
0944:                        dataSet2Remove.add(pDataSet);
0945:                    }
0946:                }
0947:
0948:                for (int i = 0; i < size2; i++) {
0949:                    DataSet dataSet = new DataSet(
0950:                            (DataSetWrapper) dataSetVector.get(i));
0951:                    boolean trouve = false;
0952:                    int j = 0;
0953:                    while (!trouve && j < size) {
0954:                        DataSet pDataSet = (DataSet) dataSetList.get(j);
0955:                        if (pDataSet.getIdBdd() == dataSet.getIdBdd()) {
0956:                            trouve = true;
0957:                        }
0958:                        j++;
0959:                    }
0960:                    if (trouve == false) {
0961:                        dataSet.reloadFromDB(false, paramsInModel);
0962:                        addDataSetInModel(dataSet);
0963:                    }
0964:                }
0965:
0966:                int size3 = dataSet2Remove.size();
0967:                for (int i = 0; i < size3; i++) {
0968:                    DataSet dataSet = (DataSet) dataSet2Remove.get(i);
0969:                    deleteDataSetInModel(dataSet);
0970:                }
0971:            }
0972:
0973:            public void addDataSetInModel(DataSet dataSet) {
0974:                dataSetList.add(dataSet);
0975:                dataSet.addInModel(this );
0976:            }
0977:
0978:            public void addDataSetInDB(DataSet dataSet) throws Exception {
0979:                dataSet.addInDB(idBdd);
0980:            }
0981:
0982:            public void addDataSetInDBAndModel(DataSet dataSet)
0983:                    throws Exception {
0984:                addDataSetInDB(dataSet);
0985:                addDataSetInModel(dataSet);
0986:            }
0987:
0988:            public ArrayList getExecutionsOfDataSetInCamp(String dataSetName) {
0989:                ArrayList result = new ArrayList();
0990:                for (int j = 0; j < getExecutionListFromModel().size(); j++) {
0991:                    if (((Execution) getExecutionListFromModel().get(j))
0992:                            .getDataSetFromModel().getNameFromModel().equals(
0993:                                    dataSetName)) {
0994:                        result.add((getExecutionListFromModel().get(j)));
0995:                    }
0996:                }
0997:                return result;
0998:            }
0999:
1000:            public void deleteDataSetInModel(DataSet dataSet) {
1001:                for (int j = 0; j < getExecutionListFromModel().size(); j++) {
1002:                    if (((Execution) getExecutionListFromModel().get(j))
1003:                            .getDataSetFromModel().getNameFromModel().equals(
1004:                                    dataSet.getNameFromModel())) {
1005:                        deleteExecutionInModel((Execution) (getExecutionListFromModel()
1006:                                .get(j)));
1007:                    }
1008:                }
1009:                dataSetList.remove(dataSet);
1010:                dataSet.deleteInModel();
1011:            }
1012:
1013:            public void deleteDataSetInDB(DataSet dataset) throws Exception {
1014:                if (!isInBase()) {
1015:                    throw new Exception("Campaign " + name + " is not in BDD");
1016:                }
1017:                dataset.deleteInDB();
1018:            }
1019:
1020:            public void deleteDataSetInDBAndModel(DataSet dataset)
1021:                    throws Exception {
1022:                deleteDataSetInDB(dataset);
1023:                deleteDataSetInModel(dataset);
1024:            }
1025:
1026:            /*public void removeDataSetInModel(String dataSetName) {
1027:            	for (int i = 0; i < dataSetList.size(); i++) {
1028:            		if (((DataSet) dataSetList.get(i)).getNameFromModel().equals(dataSetName)) {
1029:            			((DataSet) dataSetList.get(i)).deleteInModel();
1030:            			dataSetList.remove(i);
1031:            			return;
1032:            		}
1033:            	}
1034:            }*/
1035:
1036:            public DataSet getDataSetFromModel(String dataSetName) {
1037:                for (int i = 0; i < dataSetList.size(); i++) {
1038:                    if (((DataSet) dataSetList.get(i)).getNameFromModel()
1039:                            .equals(dataSetName)) {
1040:                        return (DataSet) dataSetList.get(i);
1041:                    }
1042:                }
1043:                return null;
1044:            }
1045:
1046:            public ArrayList getDataSetListFromModel() {
1047:                return dataSetList;
1048:            }
1049:
1050:            public Vector getDatagetDataSetListWrapperFromDB() throws Exception {
1051:                if (!isInBase()) {
1052:                    throw new Exception("Campaign " + name + " is not in BDD");
1053:                }
1054:                DataSetWrapper[] tmpArray = pISQLCampaign.getDatsets(idBdd);
1055:                Vector tmpVector = new Vector();
1056:                for (int i = 0; i < tmpArray.length; i++) {
1057:                    tmpVector.add(tmpArray[i]);
1058:                }
1059:                return tmpVector;
1060:            }
1061:
1062:            void purgeDataSetInModel() {
1063:                for (int i = 0; i < dataSetList.size(); i++) {
1064:                    DataSet pDataSet = (DataSet) dataSetList.get(i);
1065:                    pDataSet.deleteInModel();
1066:                }
1067:            }
1068:
1069:            /********************* About Execution ********************/
1070:
1071:            public void addExecutionInModel(Execution exec) {
1072:                executionList.add(exec);
1073:                exec.addInModel(this );
1074:            }
1075:
1076:            public void addExecutionInDBAndModel(Execution exec, User pUser,
1077:                    File preScript, File postScript) throws Exception {
1078:                exec.addInDB(pUser, exec.getAttachmentMapFromModel(),
1079:                        preScript, postScript);
1080:                addExecutionInModel(exec);
1081:            }
1082:
1083:            public void addExecutionInDBAndModel(Execution exec, User pUser)
1084:                    throws Exception {
1085:                exec.addInModel(this );
1086:                exec.addInDB(pUser);
1087:                addExecutionInModel(exec);
1088:            }
1089:
1090:            public void updateExecutionInModel(Execution exec) {
1091:                exec.addInModel(this );
1092:            }
1093:
1094:            public ArrayList getExecutionListFromModel() {
1095:                return executionList;
1096:            }
1097:
1098:            void purgeExcecutionInModel(boolean deleteExec) {
1099:                //Si la campagne est vide, suppression de ses résultats d'exécution
1100:                if (getTestListFromModel().size() == 0) {
1101:                    ArrayList execList = getExecutionListFromModel();
1102:                    //int execListSize = execList.size();
1103:                    for (int i = 0; i < execList.size(); i++) {
1104:                        ((Execution) execList.get(i))
1105:                                .getExecutionResultListFromModel().clear();
1106:                        if (deleteExec) {
1107:                            Project.pCurrentProject.notifyChanged(
1108:                                    ApiConstants.DELETE_EXECUTION,
1109:                                    (Execution) execList.get(i));
1110:                            deleteExecutionInModel((Execution) execList.get(i));
1111:                        }
1112:                    }
1113:                }
1114:            }
1115:
1116:            protected void reloadExcecutionInModel(ArrayList envInModel,
1117:                    Hashtable paramInModel) throws Exception {
1118:                int size = 0;
1119:                ArrayList execList = null;
1120:
1121:                execList = getExecutionListFromModel();
1122:                Vector execVector = getExecutionWrapperListFromDB();
1123:                Vector execToRemove = new Vector();
1124:                int size2 = execVector.size();
1125:
1126:                if (execList != null) {
1127:                    size = execList.size();
1128:                }
1129:                for (int i = 0; i < size; i++) {
1130:                    Execution pExec = (Execution) execList.get(i);
1131:                    boolean trouve = false;
1132:                    int j = 0;
1133:                    while (!trouve && j < size2) {
1134:                        Execution exec = new Execution(this ,
1135:                                (ExecutionWrapper) execVector.get(j));
1136:                        if (pExec.getIdBdd() == exec.getIdBdd()) {
1137:                            trouve = true;
1138:                        }
1139:                        j++;
1140:                    }
1141:                    if (trouve == true) {
1142:                        pExec.reloadEnvFromDB(envInModel, paramInModel);
1143:                        pExec.reloadDataSetFromDB(getDataSetListFromModel(),
1144:                                paramInModel);
1145:                        pExec.reloadScriptFromDB();
1146:                        pExec.reloadExecResultFromDB();
1147:                        //exec.loadAttachmentDataFromDB();
1148:                        pExec.reloadAttachmentDataFromDB(false);
1149:                    } else {
1150:                        execToRemove.add(pExec);
1151:                    }
1152:
1153:                }
1154:
1155:                int size3 = execToRemove.size();
1156:                for (int i = 0; i < size3; i++) {
1157:                    Execution pExec = (Execution) execToRemove.get(i);
1158:                    deleteExecutionInModel(pExec);
1159:                }
1160:                if (execList != null) {
1161:                    size = execList.size();
1162:                }
1163:
1164:                for (int k = 0; k < size2; k++) {
1165:                    Execution exec = new Execution(this ,
1166:                            (ExecutionWrapper) execVector.get(k));
1167:
1168:                    boolean trouve = false;
1169:                    int j = 0;
1170:                    while (!trouve && j < size) {
1171:                        Execution pExec = (Execution) execList.get(j);
1172:                        if (pExec.getIdBdd() == exec.getIdBdd()) {
1173:                            trouve = true;
1174:                        }
1175:                        j++;
1176:                    }
1177:                    if (trouve == false) {
1178:                        exec.reloadEnvFromDB(envInModel, paramInModel);
1179:                        exec.reloadDataSetFromDB(envInModel, paramInModel);
1180:                        exec.reloadScriptFromDB();
1181:                        exec.reloadExecResultFromDB();
1182:                        //exec.loadAttachmentDataFromDB();
1183:                        exec.reloadAttachmentDataFromDB(false);
1184:                        addExecutionInModel(exec);
1185:                    }
1186:                }
1187:
1188:            }
1189:
1190:            /*public void deleteExecutionInModel(int index) {
1191:            	Execution exec = (Execution) executionList.get(index);
1192:            	if (exec != null) {
1193:            		deleteExecutionInModel(exec);
1194:            	}
1195:            } */
1196:
1197:            public void deleteExecutionInModel(Execution exec) {
1198:                executionList.remove(exec);
1199:                exec.deleteInModel();
1200:
1201:            }
1202:
1203:            public void deleteExecutionInDBAndModel(Execution exec)
1204:                    throws Exception {
1205:                exec.deleteInDB();
1206:                deleteExecutionInModel(exec);
1207:            }
1208:
1209:            public void deleteExecutionInDB(Execution exec) throws Exception {
1210:                exec.deleteInDB();
1211:            }
1212:
1213:            public Execution getExecutionFromModel(int index) {
1214:                if (index >= executionList.size() || index < 0) {
1215:                    return null;
1216:                }
1217:                return (Execution) executionList.get(index);
1218:            }
1219:
1220:            public Execution getExecutionFromModel(String execName) {
1221:                for (int i = 0; i < executionList.size(); i++) {
1222:                    if (((Execution) executionList.get(i)).getNameFromModel()
1223:                            .equals(execName)) {
1224:                        return (Execution) executionList.get(i);
1225:                    }
1226:                }
1227:                return null;
1228:            }
1229:
1230:            public Vector getExecutionWrapperListFromDB() throws Exception {
1231:                if (!isInBase()) {
1232:                    throw new Exception("Campaign " + name + " is not in BDD");
1233:                }
1234:                ExecutionWrapper[] tmpArray = pISQLCampaign
1235:                        .getExecutions(idBdd);
1236:                Vector tmpVector = new Vector();
1237:                for (int i = 0; i < tmpArray.length; i++) {
1238:                    tmpVector.add(tmpArray[i]);
1239:                }
1240:                return tmpVector;
1241:            }
1242:
1243:            /********************** About Attachements *****************/
1244:
1245:            public void addAttachementInDB(Attachment attach) throws Exception {
1246:                if (attach instanceof  FileAttachment) {
1247:                    addAttachFileInDB((FileAttachment) attach);
1248:                } else {
1249:                    addAttachUrlInDB((UrlAttachment) attach);
1250:                }
1251:            }
1252:
1253:            void addAttachFileInDB(FileAttachment file) throws Exception {
1254:                if (!isInBase()) {
1255:                    throw new Exception("Campaign " + name + " is not in BDD");
1256:                }
1257:                File f = file.getLocalFile();
1258:                int id = pISQLCampaign.addAttachFile(idBdd,
1259:                        new SalomeFileWrapper(f), file
1260:                                .getDescriptionFromModel());
1261:                file.setIdBdd(id);
1262:            }
1263:
1264:            void addAttachUrlInDB(UrlAttachment url) throws Exception {
1265:                if (!isInBase()) {
1266:                    throw new Exception("Campaign " + name + " is not in BDD");
1267:                }
1268:                int id = pISQLCampaign.addAttachUrl(idBdd, url
1269:                        .getNameFromModel(), url.getDescriptionFromModel());
1270:                url.setIdBdd(id);
1271:            }
1272:
1273:            public void deleteAttachementInDB(int attachId) throws Exception {
1274:                if (!isInBase()) {
1275:                    throw new Exception("Campaign " + name + " is not in BDD");
1276:                }
1277:                pISQLCampaign.deleteAttach(idBdd, attachId);
1278:            }
1279:
1280:            public void deleteAttachementInDBAndModel(Attachment attach)
1281:                    throws Exception {
1282:                deleteAttachementInDB(attach.getIdBdd());
1283:                deleteAttachmentInModel(attach);
1284:            }
1285:
1286:            public Vector getAttachFilesFromDB() throws Exception {
1287:                if (!isInBase()) {
1288:                    throw new Exception("Campaign " + name + " is not in BDD");
1289:                }
1290:                FileAttachementWrapper[] tmpArray = pISQLCampaign
1291:                        .getAttachFiles(idBdd);
1292:                Vector tmpVector = new Vector();
1293:                for (int i = 0; i < tmpArray.length; i++) {
1294:                    tmpVector.add(tmpArray[i]);
1295:                }
1296:                return tmpVector;
1297:            }
1298:
1299:            public Vector getAttachUrlsFromDB() throws Exception {
1300:                if (!isInBase()) {
1301:                    throw new Exception("Campaign " + name + " is not in BDD");
1302:                }
1303:                UrlAttachementWrapper[] tmpArray = pISQLCampaign
1304:                        .getAttachUrls(idBdd);
1305:                Vector tmpVector = new Vector();
1306:                for (int i = 0; i < tmpArray.length; i++) {
1307:                    tmpVector.add(tmpArray[i]);
1308:                }
1309:                return tmpVector;
1310:            }
1311:
1312:            /**
1313:             * Get a Vector of Vector contening 3 data, a ExecutionWrapper, a  TestCampWrapper and  an Attachement
1314:             * representing all attachement of all execution result
1315:             * @return
1316:             * @throws Exception
1317:             */
1318:            public Vector getAllResExecAttahFromDB() throws Exception {
1319:                if (!isInBase()) {
1320:                    throw new Exception("Campaign " + name + " is not in BDD");
1321:                }
1322:                Vector res = new Vector();
1323:
1324:                ExecutionAttachmentWrapper[] tmpArray = pISQLCampaign
1325:                        .getResExecutionsAttachment(idBdd);
1326:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1327:                    Vector tmpData = new Vector();
1328:                    tmpData.add(0, tmpArray[tmpI].getExecution());
1329:                    tmpData.add(1, tmpArray[tmpI].getTestCamp());
1330:                    if (tmpArray[tmpI].getFileAttachment() != null) {
1331:                        tmpData.add(2, tmpArray[tmpI].getFileAttachment());
1332:                    } else if (tmpArray[tmpI].getUrlAttachment() != null) {
1333:                        tmpData.add(2, tmpArray[tmpI].getUrlAttachment());
1334:                    }
1335:                    res.add(tmpData);
1336:                }
1337:
1338:                return res;
1339:            }
1340:
1341:            /////////////////////////////////////////////////////////////////////////////
1342:            public static boolean isInBase(Project pProject, Campaign campaign) {
1343:                return isInBase(pProject, campaign.getNameFromModel());
1344:            } // Fin de la méthode isInBase/1
1345:
1346:            public static boolean isInBase(Project pProject, String campaignName) {
1347:                try {
1348:                    int id = pISQLCampaign.getID(pProject.getIdBdd(),
1349:                            campaignName);
1350:                    if (id > 0) {
1351:                        return true;
1352:                    }
1353:                    return false;
1354:                } catch (Exception e) {
1355:
1356:                }
1357:                return false;
1358:            } // Fin de la méthode isInBase/1
1359:
1360:            public boolean existeInBase() throws Exception {
1361:                if (!isInBase()) {
1362:                    return false;
1363:                }
1364:                return pISQLCampaign.getCampaign(idBdd) != null;
1365:            }
1366:
1367:            /**************************** Model Conformity operation *************************/
1368:
1369:            /** 
1370:             * Return true if the test in the campagn model are in base and in the campagn 
1371:             */
1372:            public boolean isValideModel() throws Exception {
1373:                int transNuber = -1;
1374:                try {
1375:                    transNuber = Api
1376:                            .beginTransaction(111, ApiConstants.LOADING);
1377:
1378:                    TestCampWrapper[] tmpArray = pISQLCampaign
1379:                            .getTestsByOrder(idBdd);
1380:                    Vector tmpVector = new Vector();
1381:                    for (int i = 0; i < tmpArray.length; i++) {
1382:                        tmpVector.add(tmpArray[i]);
1383:                    }
1384:                    Vector allTestDB = tmpVector;
1385:
1386:                    int allTestDdSize = allTestDB.size();
1387:                    int alltestModelSize = testList.size();
1388:                    if (allTestDdSize != alltestModelSize) {
1389:                        return false; //model are not coherant
1390:                    }
1391:                    for (int i = 0; i < allTestDdSize; i++) {
1392:                        TestCampWrapper pTestCampWrapper = (TestCampWrapper) allTestDB
1393:                                .elementAt(i);
1394:                        Test pTest = containsTestInModel(pTestCampWrapper
1395:                                .getIdBDD());
1396:                        if (pTest == null) {
1397:                            return false; //model are not coherant
1398:                        }
1399:                        /*if (!pTest.existeInBase()){
1400:                        	// Correct DB
1401:                        	try {
1402:                        		pISQLCampaign.deleteTest(idBdd, pTest.getIdBdd(), true);
1403:                        	} catch (Exception e){
1404:                        		
1405:                        	}
1406:                        	return false; //model are not coherant
1407:                        }*/
1408:                    }
1409:
1410:                    Api.commitTrans(transNuber);
1411:                    return true;
1412:                } catch (Exception e) {
1413:                    Api.forceRollBackTrans(transNuber);
1414:                    throw e;
1415:                }
1416:            }
1417:
1418:            /*************************************************************************/
1419:
1420:            public void triTestInModel(Vector testWrapperOrdered) {
1421:                Collections.sort(testList, new ComparateurTestCamp(
1422:                        testWrapperOrdered));
1423:            }
1424:
1425:            class ComparateurTestCamp implements  Comparator {
1426:                Vector testWrapperOrdered;
1427:                int size;
1428:
1429:                ComparateurTestCamp(Vector testWrapperOrdered) {
1430:                    this .testWrapperOrdered = testWrapperOrdered;
1431:                    size = testWrapperOrdered.size();
1432:                }
1433:
1434:                public int compare(Object poTest1, Object poTest2) {
1435:                    Test pTest1 = (Test) poTest1;
1436:                    Test pTest2 = (Test) poTest2;
1437:                    int order1 = -1;
1438:                    int order2 = -1;
1439:                    int i = 0;
1440:                    int trouve = 0;
1441:                    while (i < size && trouve < 2) {
1442:                        TestCampWrapper pTestCampWrapper = (TestCampWrapper) testWrapperOrdered
1443:                                .elementAt(i);
1444:                        if (pTestCampWrapper.getIdBDD() == pTest1.getIdBdd()) {
1445:                            trouve++;
1446:                            order1 = i;
1447:                        } else if (pTestCampWrapper.getIdBDD() == pTest2
1448:                                .getIdBdd()) {
1449:                            trouve++;
1450:                            order2 = i;
1451:                        }
1452:                        i++;
1453:                    }
1454:                    if (order1 > order2) {
1455:                        return 1;
1456:                    } else {
1457:                        return -1;
1458:                    }
1459:                }
1460:            }
1461:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.