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.Enumeration;
0032: import java.util.Hashtable;
0033: import java.util.Observer;
0034: import java.util.Vector;
0035:
0036: import org.objectweb.salome_tmf.api.Api;
0037: import org.objectweb.salome_tmf.api.ApiConstants;
0038: import org.objectweb.salome_tmf.api.Util;
0039: import org.objectweb.salome_tmf.api.data.CampaignWrapper;
0040: import org.objectweb.salome_tmf.api.data.EnvironmentWrapper;
0041: import org.objectweb.salome_tmf.api.data.FamilyWrapper;
0042: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
0043: import org.objectweb.salome_tmf.api.data.ParameterWrapper;
0044: import org.objectweb.salome_tmf.api.data.ProjectWrapper;
0045: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
0046: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
0047: import org.objectweb.salome_tmf.api.data.UserWrapper;
0048: import org.objectweb.salome_tmf.api.sql.ISQLProject;
0049: import org.objectweb.salome_tmf.data.Family.ComparateurTestList;
0050:
0051: public class Project extends WithAttachment {
0052: static ISQLProject pISQLProject = null;
0053:
0054: /* Parameter of this project */
0055: protected Hashtable parametersSet;
0056: protected ArrayList environmentList;
0057: protected User pUser;
0058: protected User administrator;
0059: protected ArrayList groupList;
0060: protected Date creationDate;
0061: transient protected Vector userWrapperOfProject;
0062: ObservableProject pObservableProject;
0063: boolean load = false;
0064:
0065: public static Project pCurrentProject = null;
0066:
0067: public Project(String name, String description) {
0068: super (name, description);
0069: campaignList = new ArrayList();
0070: familyList = new ArrayList();
0071: if (pISQLProject == null) {
0072: pISQLProject = Api.getISQLObjectFactory().getISQLProject();
0073: }
0074: creationDate = Util.getCurrentDate();
0075: groupList = new ArrayList();
0076: environmentList = new ArrayList();
0077: familyList = new ArrayList();
0078: campaignList = new ArrayList();
0079: parametersSet = new Hashtable();
0080: pCurrentProject = this ;
0081: pObservableProject = new ObservableProject();
0082: }
0083:
0084: public Project(String name) throws Exception {
0085: super (name, "");
0086: if (pISQLProject == null) {
0087: pISQLProject = Api.getISQLObjectFactory().getISQLProject();
0088: }
0089: ProjectWrapper pProjectWrapper = pISQLProject.getProject(name);
0090: creationDate = pProjectWrapper.getCreatedDate();
0091: description = pProjectWrapper.getDescription();
0092: idBdd = pProjectWrapper.getIdBDD();
0093: groupList = new ArrayList();
0094: environmentList = new ArrayList();
0095: familyList = new ArrayList();
0096: campaignList = new ArrayList();
0097: parametersSet = new Hashtable();
0098: pCurrentProject = this ;
0099: loadProjectInfo();
0100: pObservableProject = new ObservableProject();
0101: }
0102:
0103: public Project(ProjectWrapper pProjectWrapper) {
0104: super (pProjectWrapper.getName(), pProjectWrapper
0105: .getDescription());
0106: creationDate = pProjectWrapper.getCreatedDate();
0107: idBdd = pProjectWrapper.getIdBDD();
0108: if (pISQLProject == null) {
0109: pISQLProject = Api.getISQLObjectFactory().getISQLProject();
0110: }
0111: groupList = new ArrayList();
0112: environmentList = new ArrayList();
0113: familyList = new ArrayList();
0114: campaignList = new ArrayList();
0115: parametersSet = new Hashtable();
0116: pCurrentProject = this ;
0117: loadProjectInfo();
0118: pObservableProject = new ObservableProject();
0119: }
0120:
0121: public void setUserInModel(User pUser) {
0122: this .pUser = pUser;
0123: }
0124:
0125: public void setLoad(boolean isloading) {
0126: load = isloading;
0127: if (isloading == false) {
0128: notifyChanged(ApiConstants.LOADING, this );
0129: }
0130: }
0131:
0132: public void registerObserver(Observer o) {
0133: try {
0134: pObservableProject.addObserver(o);
0135: } catch (Exception ex) {
0136: ex.printStackTrace();
0137: }
0138: }
0139:
0140: public void unRegisterObserver(Observer o) {
0141: try {
0142: pObservableProject.deleteObserver(o);
0143: } catch (Exception ex) {
0144: ex.printStackTrace();
0145: }
0146: }
0147:
0148: public void notifyChanged(SalomeEvent e) {
0149: try {
0150: if (!load) {
0151: pObservableProject.notifyChanged(e);
0152: }
0153: } catch (Exception ex) {
0154: ex.printStackTrace();
0155: }
0156: }
0157:
0158: public void notifyChanged(int code, Object arg) {
0159: try {
0160: if (!load) {
0161: pObservableProject.notifyChanged(code, arg);
0162: }
0163: } catch (Exception ex) {
0164: ex.printStackTrace();
0165: }
0166: }
0167:
0168: public void notifyChanged(int code, Object arg, Object oldV,
0169: Object newV) {
0170: try {
0171: if (!load) {
0172: pObservableProject.notifyChanged(code, arg, oldV, newV);
0173: }
0174: } catch (Exception ex) {
0175: ex.printStackTrace();
0176: }
0177: }
0178:
0179: /****************************************************************************************/
0180: /*********************** PROJECT METHODES **********************************************/
0181: /****************************************************************************************/
0182:
0183: public User getAdministratorFromModel() {
0184: return administrator;
0185: }
0186:
0187: public void loadProjectInfo() {
0188: if (isInBase()) {
0189: try {
0190: UserWrapper[] tmpArray = pISQLProject
0191: .getUsersOfProject(name);
0192: Vector tmpVector = new Vector();
0193: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0194: tmpVector.add(tmpArray[tmpI]);
0195: }
0196: userWrapperOfProject = tmpVector;
0197: } catch (Exception e) {
0198: e.printStackTrace();
0199: userWrapperOfProject = new Vector();
0200: }
0201: } else {
0202: userWrapperOfProject = new Vector();
0203: }
0204: }
0205:
0206: public Vector getAllUsersWrapper() {
0207: return userWrapperOfProject;
0208: }
0209:
0210: public int containUser(String login) {
0211: int id = -1;
0212: if (userWrapperOfProject == null) {
0213: return id;
0214: }
0215: int userSize = userWrapperOfProject.size();
0216: boolean trouve = false;
0217: int i = 0;
0218: while (i < userSize && !trouve) {
0219: UserWrapper pUserWrapper = (UserWrapper) userWrapperOfProject
0220: .elementAt(i);
0221: if (pUserWrapper.getLogin().equals(login)) {
0222: id = pUserWrapper.getIdBDD();
0223: trouve = true;
0224: }
0225: i++;
0226: }
0227: return id;
0228: }
0229:
0230: public Vector getALLAdministratorWrapperFromDB() throws Exception {
0231: if (!isInBase()) {
0232: throw new Exception("Project " + name + " is not in DB");
0233: }
0234: UserWrapper[] tmpArray = pISQLProject.getAdminsOfProject(name);
0235: Vector tmpVector = new Vector();
0236: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0237: tmpVector.add(tmpArray[tmpI]);
0238: }
0239: return tmpVector;
0240: }
0241:
0242: public UserWrapper getAdministratorWrapperFromDB() throws Exception {
0243: if (!isInBase()) {
0244: throw new Exception("Project " + name + " is not in DB");
0245: }
0246: Vector adminList = getALLAdministratorWrapperFromDB();
0247: UserWrapper pUserWrapper = null;
0248: if (adminList.size() > 0) {
0249: pUserWrapper = (UserWrapper) adminList.elementAt(0);
0250: } else {
0251: throw new Exception("Project " + name
0252: + " have no administrator");
0253: }
0254: return pUserWrapper;
0255: }
0256:
0257: public Vector getUserOfGroupFromDB(String groupName)
0258: throws Exception {
0259: if (!isInBase()) {
0260: throw new Exception("Project " + name + " is not in DB");
0261: }
0262: UserWrapper[] tmpArray = pISQLProject.getUserOfGroupInProject(
0263: name, groupName);
0264: Vector tmpVector = new Vector();
0265: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0266: tmpVector.add(tmpArray[tmpI]);
0267: }
0268: return tmpVector;
0269: }
0270:
0271: public Date getCreationDateFromModel() {
0272: return creationDate;
0273: }
0274:
0275: public ArrayList getGroupListFromModel() {
0276: return groupList;
0277: } // Fin de la méthode getGroupList/0
0278:
0279: /*public int getStatus() {
0280: return status;
0281: } */
0282:
0283: public void setAdministratorInModel(User user) {
0284: administrator = user;
0285: }
0286:
0287: public void setCreationDateInModel(Date date) {
0288: creationDate = date;
0289: }
0290:
0291: public void setGroupListInModel(ArrayList list) {
0292: groupList = list;
0293: }
0294:
0295: public void addInDB() throws Exception {
0296: if (isInBase()) {
0297: throw new Exception("Project " + name + " is already in DB");
0298: }
0299: idBdd = pISQLProject.insert(name, description, administrator
0300: .getIdBdd());
0301: loadProjectInfo();
0302: }
0303:
0304: void addInDB(Project p, boolean suite, boolean campagne,
0305: boolean users, boolean groupe) throws Exception {
0306: if (isInBase()) {
0307: throw new Exception("Project " + name + " is already in DB");
0308: }
0309: idBdd = pISQLProject.copyProject(name, description,
0310: administrator.getIdBdd(), p.getIdBdd(), suite,
0311: campagne, users, groupe);
0312: }
0313:
0314: void deleteInDB() throws Exception {
0315: if (!isInBase()) {
0316: throw new Exception("Project " + name + " is not in DB");
0317: }
0318: pISQLProject.delete(idBdd, name);
0319: }
0320:
0321: public void updateInDB(String newName, String newDesc)
0322: throws Exception {
0323: if (!isInBase()) {
0324: throw new Exception("Project " + name + " is not in DB");
0325: }
0326: pISQLProject.update(idBdd, newName, newDesc);
0327: }
0328:
0329: public void updateInModel(String newName, String newDesc) {
0330: name = newName;
0331: description = newDesc;
0332: }
0333:
0334: public void updateInDBAndModel(String newName, String newDesc)
0335: throws Exception {
0336: updateInDB(newName, newDesc);
0337: updateInModel(newName, newDesc);
0338: }
0339:
0340: /******************************************************************************/
0341: /** METHODES PUBLIQUES ***/
0342: /******************************************************************************/
0343: /**
0344: * Ajoute un environnement au projet
0345: */
0346: public void addEnvironmentInModel(Environment env) {
0347: environmentList.add(env);
0348: env.addInModel(this );
0349: } // Fin de la méthode addEnvironment/1
0350:
0351: public void addEnvironmentInDBAndModel(Environment env)
0352: throws Exception {
0353: env.addInDB(idBdd);
0354: addEnvironmentInModel(env);
0355: } // Fin de la méthode addEnvironment/1
0356:
0357: /**
0358: * Ajoute un groupe au projet
0359: */
0360: public void addGroupInModel(Group group) {
0361: groupList.add(group);
0362: }
0363:
0364: /**
0365: * Retourne la liste des environnements
0366: * @return la liste des environnements
0367: */
0368: public ArrayList getEnvironmentListFromModel() {
0369: return environmentList;
0370: } // Fin de la méthode getEnvironmentList/0
0371:
0372: /**
0373: * Retourne l'environnement dont le nom est passé en paramètre, null si le
0374: * nom n'est pas celui d'un environnement
0375: * @param name un nom
0376: * @return l'environnement dont le nom est passé en paramètre, null si le
0377: * nom n'est pas celui d'un environnement
0378: */
0379: public Environment getEnvironmentFromModel(String name) {
0380: for (int i = 0; i < environmentList.size(); i++) {
0381: if (((Environment) environmentList.get(i))
0382: .getNameFromModel().equals(name)) {
0383: return (Environment) environmentList.get(i);
0384: }
0385: }
0386: return null;
0387: } // Fin de la méthode getEnvironment/0
0388:
0389: /**
0390: * Retourne l'environnement dont l'id est passé en paramètre, null si le
0391: * nom n'est pas celui d'un environnement
0392: * @param name un nom
0393: * @return l'environnement dont le nom est passé en paramètre, null si le
0394: * nom n'est pas celui d'un environnement
0395: */
0396: public Environment getEnvironmentFromModel(int id) {
0397: for (int i = 0; i < environmentList.size(); i++) {
0398: if (((Environment) environmentList.get(i)).getIdBdd() == id) {
0399: return (Environment) environmentList.get(i);
0400: }
0401: }
0402: return null;
0403: } // Fin de la méthode getEnvironment/0
0404:
0405: /**
0406: * Retourne le groupe dont le nom est passé en paramètre, null si le nom
0407: * n'est pas celui d'un groupe
0408: * @param name un nom
0409: * @return un groupe, ou <code>null</code> si le nom n'est pas celui d'un
0410: * groupe
0411: */
0412: public Group getGroupFromModel(String name) {
0413: for (int i = 0; i < groupList.size(); i++) {
0414: if (((Group) groupList.get(i)).getNameFromModel().equals(
0415: name)) {
0416: return (Group) groupList.get(i);
0417: }
0418: }
0419: return null;
0420: } // Fin de la méthode getGroup/1
0421:
0422: /**
0423: * Supprime un environnement de la liste des environnments
0424: * @param env un environnement
0425: */
0426: public void deleteEnvironmentInModel(Environment env) {
0427:
0428: for (int i = 0; i < campaignList.size(); i++) {
0429: Campaign pCampaign = (Campaign) campaignList.get(i);
0430: ArrayList pExcutionList = pCampaign
0431: .getExecutionListFromModel();
0432: for (int j = 0; j < pExcutionList.size(); j++) {
0433: Execution pExecution = (Execution) pExcutionList.get(j);
0434: Environment pEnv = pExecution.getEnvironmentFromModel();
0435: if (env.getNameFromModel().equals(
0436: pEnv.getNameFromModel())
0437: && env.getIdBdd() == pEnv.getIdBdd()) {
0438: pCampaign.deleteExecutionInModel(pExecution);
0439: }
0440: }
0441: }
0442: env.deleteInModel();
0443: environmentList.remove(env);
0444: } // Fin de la méthode removeEnvironment/1
0445:
0446: /**
0447: * Supprime un environnement de la liste des environnments
0448: * @param env un nom d'environnement
0449: */
0450: /*void removeEnvironmentInModel(String envName) {
0451: for (int i = 0; i < environmentList.size(); i ++) {
0452: if (((Environment)environmentList.get(i)).getNameFromModel().equals(envName)) {
0453: environmentList.remove(i);
0454: return;
0455: }
0456: }
0457: } // Fin de la méthode removeEnvironment/1*/
0458:
0459: public void deleteEnvironmentInDBandModel(Environment env)
0460: throws Exception {
0461: env.deleteInDB();
0462: deleteEnvironmentInModel(env);
0463: }
0464:
0465: /**
0466: *
0467: * @param name
0468: * @return
0469: */
0470: public boolean containsEnvironment(String name) {
0471: for (int i = 0; i < environmentList.size(); i++) {
0472: if (((Environment) environmentList.get(i))
0473: .getNameFromModel().equals(name)) {
0474: return true;
0475: }
0476: }
0477: return false;
0478: } // Fin de la méthode containsEnvironment/1
0479:
0480: public Vector getEnvironmentWrapperFromDB() throws Exception {
0481: if (!isInBase()) {
0482: throw new Exception("Project " + name + " is not in DB");
0483: }
0484: EnvironmentWrapper[] tmpArray = pISQLProject
0485: .getProjectEnvs(idBdd);
0486: Vector tmpVector = new Vector();
0487: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0488: tmpVector.add(tmpArray[tmpI]);
0489: }
0490: return tmpVector;
0491: }
0492:
0493: public void loadEnvironnementsFromDB() throws Exception {
0494: if (!isInBase()) {
0495: throw new Exception("Project " + name + " is not in DB");
0496: }
0497: environmentList.clear();
0498: Vector environmentOfProject = getEnvironmentWrapperFromDB();
0499: for (int i = 0; i < environmentOfProject.size(); i++) {
0500: EnvironmentWrapper envDB = (EnvironmentWrapper) environmentOfProject
0501: .get(i);
0502: Environment env = new Environment(envDB);
0503: addEnvironmentInModel(env);
0504: }
0505: }
0506:
0507: /**
0508: *
0509: * @param group
0510: */
0511: public void removeGroup(Group group) {
0512: groupList.remove(group);
0513: } // Fin de la méthode removeGroup/1
0514:
0515: public void addParameterToModel(Parameter param) {
0516: parametersSet.put(param.getNameFromModel(), param);
0517: }
0518:
0519: public void addParameterToDBAndModel(Parameter param)
0520: throws Exception {
0521: param.addInDB(idBdd);
0522:
0523: addParameterToModel(param);
0524: }
0525:
0526: /*void removeParameter(Parameter param) {
0527: parametersSet.remove(param);
0528: }*/
0529:
0530: /*void removeParameterInModel(String paramName) {
0531: for (Iterator iter = parametersSet.iterator(); iter.hasNext();) {
0532: Parameter element = (Parameter)iter.next();
0533: if (element.getNameFromModel().equals(paramName)) {
0534: parametersSet.remove(element);
0535: return;
0536: }
0537: }
0538: }*/
0539:
0540: public boolean containsParameterInModel(String paramName) {
0541: return (parametersSet.get(paramName) != null);
0542: /*for (Iterator iter = parametersSet.iterator(); iter.hasNext();) {
0543: Parameter element = (Parameter)iter.next();
0544: if (element.getNameFromModel().equals(paramName)) {
0545: return true;
0546: }
0547: }
0548: return false;*/
0549: }
0550:
0551: public boolean containsParameterInModel(Parameter param) {
0552: return parametersSet.containsValue(param);
0553: }
0554:
0555: public Parameter getParameterFromModel(String paramName) {
0556: return (Parameter) parametersSet.get(paramName);
0557: /*for (Iterator iter = parametersSet.iterator(); iter.hasNext();) {
0558: Parameter element = (Parameter)iter.next();
0559: if (element.getNameFromModel().equals(paramName)) {
0560: return element;
0561: }
0562: }
0563: return null;*/
0564: }
0565:
0566: public Parameter getParameterFromModel(int id) {
0567: Enumeration listParams = parametersSet.elements();
0568: while (listParams.hasMoreElements()) {
0569: Parameter element = (Parameter) listParams.nextElement();
0570: if (element.getIdBdd() == id) {
0571: return element;
0572: }
0573: }
0574: return null;
0575: /*for (Iterator iter = parametersSet.elements(); iter.hasNext();) {
0576: Parameter element = (Parameter)iter.next();
0577: if (element.getIdBdd() == id) {
0578: return element;
0579: }
0580: }
0581: return null;*/
0582: }
0583:
0584: public Hashtable getParameterSetFromModel() {
0585: return parametersSet;
0586: }
0587:
0588: public Vector getParametersWrapperFromDB() throws Exception {
0589: if (!isInBase()) {
0590: throw new Exception("Project " + name + " is not in DB");
0591: }
0592: ParameterWrapper[] tmpArray = pISQLProject
0593: .getProjectParams(idBdd);
0594: Vector tmpVector = new Vector();
0595: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0596: tmpVector.add(tmpArray[tmpI]);
0597: }
0598: return tmpVector;
0599: }
0600:
0601: public void loadParamtersFromDB() throws Exception {
0602: if (!isInBase()) {
0603: throw new Exception("Project " + name + " is not in DB");
0604: }
0605: Vector projectParam = getParametersWrapperFromDB();
0606: parametersSet.clear();
0607: for (int m = 0; m < projectParam.size(); m++) {
0608: ParameterWrapper paramBdd = (ParameterWrapper) projectParam
0609: .get(m);
0610: Parameter param = new Parameter(paramBdd);
0611: addParameterToModel(param);
0612: }
0613: }
0614:
0615: /****************************************************************************************/
0616: /*********************** TESTPLAN METHODES **********************************************/
0617: /****************************************************************************************/
0618:
0619: protected ArrayList familyList;
0620:
0621: void clearTestPlanData() {
0622: for (int i = 0; i < familyList.size(); i++) {
0623: Family pFamily = (Family) familyList.get(i);
0624: pFamily.deleteInModel();
0625: }
0626: familyList.clear();
0627: for (int i = 0; i < environmentList.size(); i++) {
0628: Environment pEnvironment = (Environment) environmentList
0629: .get(i);
0630: pEnvironment.deleteInModel();
0631: }
0632: environmentList.clear();
0633: parametersSet.clear();
0634: }
0635:
0636: /**
0637: * Retourne la liste ordonnée des tests d'une suite
0638: * @param list une suite
0639: * @return liste ordonnée de la suite passée en paramètre
0640: */
0641: public ArrayList getAllTestFromModel(TestList list) {
0642: return list.getTestListFromModel();
0643: } // Fin de la méthode getAllTest/1
0644:
0645: /**
0646: * Retourne la liste ordonnée des objets "suites de tests"
0647: * @return la liste ordonnée de tous les objets "suites de tests"
0648: */
0649: public ArrayList getAllTestListFromModel(Family family) {
0650: return family.getSuiteListFromModel();
0651: } // Fin de la méthode getAllTestList/1
0652:
0653: /**
0654: * Retourne la liste ordonnée des familles
0655: */
0656: public ArrayList getFamilyListFromModel() {
0657: return familyList;
0658: }
0659:
0660: public Vector getProjectFamiliesWrapperFromDB() throws Exception {
0661: if (!isInBase()) {
0662: throw new Exception("Project " + name + " is not in DB");
0663: }
0664: FamilyWrapper[] tmpArray = pISQLProject.getFamily(idBdd);
0665: Vector tmpVector = new Vector();
0666: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0667: tmpVector.add(tmpArray[tmpI]);
0668: }
0669: return tmpVector;
0670: }
0671:
0672: /**
0673: * Retourne la famille dont le nom est passé en paramètre
0674: * @param familyName un nom
0675: * @return Retourne la famille dont le nom est passé en paramètre, <code>null</code>
0676: * si le nom n'est pas celui d'une famille
0677: */
0678: public Family getFamilyFromModel(String familyName) {
0679: for (int i = 0; i < familyList.size(); i++) {
0680: if (((Family) familyList.get(i)).getNameFromModel().equals(
0681: familyName)) {
0682: return (Family) familyList.get(i);
0683: }
0684: }
0685: return null;
0686: }
0687:
0688: /**
0689: * Retourne la famille dont le nom est passé en paramètre
0690: * @param int id l'id d'une famille
0691: * @return Retourne la famille dont le nom est passé en paramètre, <code>null</code>
0692: * si le nom n'est pas celui d'une famille
0693: */
0694: public Family getFamilyFromModel(int id) {
0695: for (int i = 0; i < familyList.size(); i++) {
0696: if (((Family) familyList.get(i)).getIdBdd() == id) {
0697: return (Family) familyList.get(i);
0698: }
0699: }
0700: return null;
0701: }
0702:
0703: /**
0704: * Retourne la suite de tests dont le nom est passé en paramètre
0705: * @param familyName un nom de famille
0706: * @param testListName un nom
0707: * @return Retourne la suite de tests dont le nom est passé en paramètre, <code>null</code>
0708: * si le nom n'est pas celui d'une suite de tests
0709: */
0710: public TestList getTestListFromModel(String familyName,
0711: String testListName) {
0712: for (int i = 0; i < familyList.size(); i++) {
0713: if (((Family) familyList.get(i)).getNameFromModel().equals(
0714: familyName)) {
0715: ArrayList list = ((Family) familyList.get(i))
0716: .getSuiteListFromModel();
0717: for (int j = 0; j < list.size(); j++) {
0718: if (((TestList) list.get(j)).getNameFromModel()
0719: .equals(testListName)) {
0720: return (TestList) list.get(j);
0721: }
0722:
0723: }
0724: }
0725: }
0726: return null;
0727: }
0728:
0729: /**
0730: * Retourne le test dont le nom est passé en paramètre
0731: * @param familyName un nom de famille
0732: * @param testListName un nom de suite
0733: * @param un nom de test
0734: * @return Retourne le test dont le nom est passé en paramètre, <code>null</code>
0735: * si le nom n'est pas celui d'un test
0736: */
0737: public Test getTestFromModel(String familyName,
0738: String testListName, String testName) {
0739: for (int i = 0; i < familyList.size(); i++) {
0740: if (((Family) familyList.get(i)).getNameFromModel().equals(
0741: familyName)) {
0742: ArrayList list = ((Family) familyList.get(i))
0743: .getSuiteListFromModel();
0744: for (int j = 0; j < list.size(); j++) {
0745: if (((TestList) list.get(j)).getNameFromModel()
0746: .equals(testListName)) {
0747: ArrayList tests = ((TestList) list.get(j))
0748: .getTestListFromModel();
0749: for (int k = 0; k < tests.size(); k++) {
0750: if (((Test) tests.get(k))
0751: .getNameFromModel()
0752: .equals(testName)) {
0753: return (Test) tests.get(k);
0754: }
0755: }
0756: }
0757:
0758: }
0759: }
0760: }
0761: return null;
0762: }
0763:
0764: /**
0765: * Retourne le test dont l' id est passé en paramètre
0766: * @param id du test
0767: * @return Retourne le test dont le nom est passé en paramètre, <code>null</code>
0768: * si le nom n'est pas celui d'un test
0769: */
0770: public Test getTestFromModel(int idTest) {
0771: for (int i = 0; i < familyList.size(); i++) {
0772: ArrayList list = ((Family) familyList.get(i))
0773: .getSuiteListFromModel();
0774: for (int j = 0; j < list.size(); j++) {
0775: ArrayList tests = ((TestList) list.get(j))
0776: .getTestListFromModel();
0777: for (int k = 0; k < tests.size(); k++) {
0778: if (((Test) tests.get(k)).getIdBdd() == idTest) {
0779: return (Test) tests.get(k);
0780: }
0781: }
0782: }
0783:
0784: }
0785:
0786: return null;
0787: }
0788:
0789: public ArrayList getTestOfParameterFromModel(String paramName) {
0790: ArrayList result = new ArrayList();
0791: for (int i = 0; i < familyList.size(); i++) {
0792: ArrayList testListArrayList = ((Family) familyList.get(i))
0793: .getSuiteListFromModel();
0794: for (int j = 0; j < testListArrayList.size(); j++) {
0795: ArrayList testArrayList = ((TestList) testListArrayList
0796: .get(j)).getTestListFromModel();
0797: for (int k = 0; k < testArrayList.size(); k++) {
0798: if (((Test) testArrayList.get(k))
0799: .getUsedParameterFromModel(paramName) != null) {
0800: result.add(testArrayList.get(k));
0801: }
0802: }
0803: }
0804: }
0805: return result;
0806: }
0807:
0808: public ArrayList getAlltestFromModel() {
0809: ArrayList testInModel = new ArrayList();
0810: ArrayList familyList = getFamilyListFromModel();
0811: int size = familyList.size();
0812: for (int i = 0; i < size; i++) {
0813: Family pFamily = (Family) familyList.get(i);
0814: ArrayList suiteList = pFamily.getSuiteListFromModel();
0815: int size2 = suiteList.size();
0816: for (int j = 0; j < size2; j++) {
0817: TestList pSuite = (TestList) suiteList.get(j);
0818: ArrayList testList = pSuite.getTestListFromModel();
0819: int size3 = testList.size();
0820: for (int k = 0; k < size3; k++) {
0821: Test pTest = (Test) testList.get(k);
0822: testInModel.add(pTest);
0823: }
0824:
0825: }
0826: }
0827: return testInModel;
0828: }
0829:
0830: /**************** Operations d'ajout dans le modele de données **********************************/
0831: /*
0832: * Ajoute une famille
0833: * @param familyName le nom de la famille
0834: */
0835: public void addFamilyInModel(Family family) {
0836: family.addInModel(this );
0837: familyList.add(family);
0838: }
0839:
0840: public void addFamilyInDB(Family family) throws Exception {
0841: family.addInDB(idBdd);
0842: }
0843:
0844: public void addFamilyInDBAndModel(Family family) throws Exception {
0845: addFamilyInDB(family);
0846: addFamilyInModel(family);
0847: }
0848:
0849: /**
0850: * Ajoute une suite de tests dans une famille existante
0851: * @param list
0852: * @param family
0853: */
0854: public void addTestListInFamilyInModel(TestList list, Family family) {
0855: family.addTestListInModel(list);
0856: }
0857:
0858: // Return True if IHM need refresh
0859: public void addTestListInFamilyInDBAndModel(TestList pList,
0860: Family pFamily) throws Exception {
0861: //BDD
0862: if (pFamily == null) {
0863: throw new Exception();
0864: }
0865: if (pFamily.getIdBdd() == -1) {
0866: throw new Exception();
0867: }
0868: pList.addInDB(pFamily.getIdBdd());
0869:
0870: addTestListInFamilyInModel(pList, pFamily);
0871: }
0872:
0873: public void addTestInListInModel(Test test, TestList list) {
0874: list.addTestInModel(test);
0875: }
0876:
0877: public void addTestInListInDBAndModel(Test pTest, TestList list)
0878: throws Exception {
0879: list.addTestInDB(pTest);
0880: addTestInListInModel(pTest, list);
0881: }
0882:
0883: /**************** Operations de suppression dans données **********************************/
0884:
0885: /**
0886: * Supprime un test
0887: * @param test un test
0888: */
0889: public void deleteTestInModel(Test pTest) {
0890: TestList pList = pTest.getTestListFromModel();
0891: ArrayList campaignList = getCampaignOfTest(pTest);
0892:
0893: pList.deleteTestInModel(pTest);
0894: for (int i = 0; i < campaignList.size(); i++) {
0895: deleteTestFromCampaignInModel(pTest,
0896: (Campaign) campaignList.get(i));
0897: }
0898:
0899: }
0900:
0901: public void deleteTestInDBandModel(Test pTest) throws Exception {
0902:
0903: pTest.deleteInDB();
0904: //pTest.deleteInBddAndModel(true);
0905: // Model
0906: deleteTestInModel(pTest);
0907: } // Fin de la méthode deleteTest/1
0908:
0909: /**
0910: * Supprime une suite de tests
0911: * @param list une suite de tests
0912: */
0913: public void deleteTestListInModel(TestList pList) {
0914: ArrayList campaignList = getCampaignOfTestList(pList);
0915:
0916: Family pFamily = pList.getFamilyFromModel();
0917: pFamily.deleteTestListInModel(pList);
0918:
0919: for (int i = 0; i < campaignList.size(); i++) {
0920: deleteTestListFromCampaignInModel(pList,
0921: (Campaign) campaignList.get(i));
0922: }
0923:
0924: }
0925:
0926: public void deleteTestListInDBandModel(TestList pList)
0927: throws Exception {
0928: pList.deleteInDB();
0929: //Model
0930: deleteTestListInModel(pList);
0931: }
0932:
0933: /**
0934: * Supprime une famille du model en mettant à jour le model
0935: * Suppression dans les campagnes
0936: * @param family une famille
0937: */
0938: public void deleteFamilyInModel(Family pFamily) {
0939: ArrayList campaignList = getCampaignOfFamily(pFamily);
0940: familyList.remove(pFamily);
0941: pFamily.deleteInModel();
0942: for (int i = 0; i < campaignList.size(); i++) {
0943: deleteFamilyFromCampaignFromModel(pFamily,
0944: (Campaign) campaignList.get(i));
0945: }
0946: } // Fin de la méthode deleteFamily/1
0947:
0948: public void deleteFamilyInDBAndModel(Family pFamily)
0949: throws Exception {
0950: pFamily.deleteInDB();
0951: deleteFamilyInModel(pFamily);
0952: }
0953:
0954: /**********************************************************************************************************/
0955:
0956: /**
0957: * Méthode qui rend vrai si la suite passée en paramètre
0958: * possède un test dont le nom est passé en paramètre, faux sinon.
0959: * @param testListName le nom d'une suite
0960: * @param testName le nom d'un test
0961: * @return vrai si la suite dont le nom est passée en paramètre
0962: * possède un test dont le nom est passé en paramètre, faux sinon.
0963: */
0964: public boolean containsTestInModel(TestList testList,
0965: String testName) {
0966: for (int i = 0; i < testList.getTestListFromModel().size(); i++) {
0967: Test test = (Test) testList.getTestListFromModel().get(i);
0968: if (test.getNameFromModel().equals(testName)) {
0969: return true;
0970: }
0971: }
0972: return false;
0973: } // Fin de la méthode containsTest/2
0974:
0975: /**
0976: * Rend vrai si la famille passée en paramètre contient une suite de tests
0977: * dont le nom est passé en paramètre, faux sinon.
0978: * @param family une famille
0979: * @param testListName une suite de tests
0980: * @return Rend vrai si la famille passée en paramètre contient une suite de tests
0981: * dont le nom est passé en paramètre, faux sinon.
0982: */
0983: public boolean containsTestListInModel(Family family,
0984: String testListName) {
0985: for (int i = 0; i < family.getSuiteListFromModel().size(); i++) {
0986: if (((TestList) family.getSuiteListFromModel().get(i))
0987: .getNameFromModel().equals(testListName)) {
0988: return true;
0989: }
0990: }
0991: return false;
0992: }
0993:
0994: /**
0995: * Rend vrai si le nom passé en paramètre correspond au nom d'une famille
0996: * @param familyName le nom d'une famille
0997: * @return Rend vrai si le nom passé en paramètre correspond au nom d'une
0998: * famille, faux sinon.
0999: */
1000: public boolean containsFamilyInModel(String familyName) {
1001: for (int i = 0; i < familyList.size(); i++) {
1002: if (((Family) familyList.get(i)).getNameFromModel().equals(
1003: familyName)) {
1004: return true;
1005: }
1006: }
1007: return false;
1008: }
1009:
1010: /********************************** Sélécteur *************************************************/
1011:
1012: public ArrayList getEnvironmentOfParameterFromModel(String paramName) {
1013: ArrayList result = new ArrayList();
1014: for (int i = 0; i < getEnvironmentListFromModel().size(); i++) {
1015: if (((Environment) getEnvironmentListFromModel().get(i))
1016: .containsParameterInModel(paramName)) {
1017: result.add(getEnvironmentListFromModel().get(i));
1018: }
1019: }
1020: return result;
1021: }
1022:
1023: /************************************ Suppréssion *****************************/
1024:
1025: public void delParamInModel(Parameter pParam) {
1026: ArrayList envOfParam = getEnvironmentOfParameterFromModel(pParam
1027: .getNameFromModel());
1028: ArrayList testsOfParam = getTestOfParameterFromModel(pParam
1029: .getNameFromModel());
1030:
1031: // Suppression du paramétre des environnements
1032: for (int i = 0; i < envOfParam.size(); i++) {
1033: ((Environment) envOfParam.get(i))
1034: .deleteDefParameterInModel(pParam
1035: .getNameFromModel());
1036: }
1037: //Suppression du paramètre des tests (et actions)
1038: for (int j = 0; j < testsOfParam.size(); j++) {
1039:
1040: Test currentTest = (Test) testsOfParam.get(j);
1041: currentTest.deleteUseParameterInModel(pParam);
1042:
1043: // On purge les campagnes concernées des tests utilisant le paramètre
1044: ArrayList campaignOfTest = getCampaignOfTest(currentTest);
1045: for (int k = 0; k < campaignOfTest.size(); k++) {
1046: Campaign campaign = (Campaign) campaignOfTest.get(k);
1047: deleteTestFromCampaignInModel((Test) testsOfParam
1048: .get(j), campaign);
1049:
1050: //Suppression du paramétre des jeux de données des campagnes concernées
1051: for (int l = 0; l < campaign.getDataSetListFromModel()
1052: .size(); l++) {
1053: DataSet dataSet = (DataSet) campaign
1054: .getDataSetListFromModel().get(l);
1055: dataSet.removeParameterInModel(pParam
1056: .getNameFromModel());
1057: }
1058: }
1059:
1060: }
1061: parametersSet.remove(pParam.getNameFromModel());
1062: //removeParameterInModel(pParam.getNameFromModel());
1063: }
1064:
1065: public void deleteParamInDBndModel(Parameter pParam)
1066: throws Exception {
1067: //BDD
1068: pParam.deleteInDB();
1069:
1070: //DATA
1071: delParamInModel(pParam);
1072: }
1073:
1074: /****************************************************************************************/
1075: /*********************** CAMPAIGN METHODES **********************************************/
1076: /****************************************************************************************/
1077:
1078: protected ArrayList campaignList;
1079:
1080: //static private ArrayList execResultList = new ArrayList();;
1081:
1082: /***********************************************************************************/
1083: void clearCampaignData() {
1084: for (int i = 0; i < campaignList.size(); i++) {
1085: Campaign pCampaign = (Campaign) campaignList.get(i);
1086: pCampaign.deleteInModel();
1087: }
1088: campaignList.clear();
1089: }
1090:
1091: /***********************************************************************************/
1092: public Vector getCampaignsWrapperListFromDB() throws Exception {
1093: if (!isInBase()) {
1094: throw new Exception("Project " + name + " is not in DB");
1095: }
1096: CampaignWrapper[] tmpArray = pISQLProject
1097: .getPrjectCampaigns(idBdd);
1098: Vector tmpVector = new Vector();
1099: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1100: tmpVector.add(tmpArray[tmpI]);
1101: }
1102: return tmpVector;
1103: }
1104:
1105: public ArrayList getCampaignListFromModel() {
1106: return campaignList;
1107: }
1108:
1109: public Campaign getCampaignFromModel(String campaignName) {
1110: for (int i = 0; i < campaignList.size(); i++) {
1111: if (((Campaign) campaignList.get(i)).getNameFromModel()
1112: .equals(campaignName)) {
1113: return (Campaign) campaignList.get(i);
1114: }
1115: }
1116: return null;
1117: }
1118:
1119: public Campaign getCampaignFromModel(int id) {
1120: for (int i = 0; i < campaignList.size(); i++) {
1121: if (((Campaign) campaignList.get(i)).getIdBdd() == id) {
1122: return (Campaign) campaignList.get(i);
1123: }
1124: }
1125: return null;
1126: }
1127:
1128: public ArrayList getCampaignOfTest(Test test) {
1129: ArrayList result = new ArrayList();
1130: for (int i = 0; i < campaignList.size(); i++) {
1131: if (((Campaign) campaignList.get(i))
1132: .containsTestInModel(test)) {
1133: result.add(campaignList.get(i));
1134: }
1135: }
1136: return result;
1137: }
1138:
1139: public ArrayList getCampaignOfTestList(TestList testList) {
1140: ArrayList result = new ArrayList();
1141: for (int i = 0; i < campaignList.size(); i++) {
1142: if (((Campaign) campaignList.get(i))
1143: .containsTestListInModel(testList)) {
1144: result.add(campaignList.get(i));
1145: }
1146: }
1147: return result;
1148: }
1149:
1150: public ArrayList getCampaignOfFamily(Family family) {
1151: ArrayList result = new ArrayList();
1152: for (int i = 0; i < campaignList.size(); i++) {
1153: if (((Campaign) campaignList.get(i))
1154: .containsFamilyInModel(family)) {
1155: result.add(campaignList.get(i));
1156: }
1157: }
1158: return result;
1159: }
1160:
1161: public ArrayList getExecutionOfEnvironmentInModel(String envName) {
1162: ArrayList result = new ArrayList();
1163: for (int i = 0; i < getCampaignListFromModel().size(); i++) {
1164: for (int j = 0; j < ((Campaign) campaignList.get(i))
1165: .getExecutionListFromModel().size(); j++) {
1166: if (((Execution) ((Campaign) campaignList.get(i))
1167: .getExecutionListFromModel().get(j))
1168: .getEnvironmentFromModel().getNameFromModel()
1169: .equals(envName)) {
1170: result.add((((Campaign) campaignList.get(i))
1171: .getExecutionListFromModel().get(j)));
1172: }
1173: }
1174: }
1175: return result;
1176: }
1177:
1178: public ArrayList getExecutionsOfDataSetInCamp(Campaign camp,
1179: String dataSetName) {
1180: return camp.getExecutionsOfDataSetInCamp(dataSetName);
1181: }
1182:
1183: public String getCampaignWithExecResultWhereTestIsUse(Test test) {
1184: String message = "";
1185: for (int i = 0; i < campaignList.size(); i++) {
1186: Campaign camp = (Campaign) campaignList.get(i);
1187: if (camp.containsTestInModel(test)
1188: && camp.containsExecutionResultInModel())
1189: message = message + "* " + camp.getNameFromModel()
1190: + "\n";
1191: }
1192: return message;
1193: }
1194:
1195: /**************** Operations d'ajout dans le modele de données **********************************/
1196:
1197: void addTestInCampaignInModel(Test test, Campaign campaign,
1198: int userID) {
1199: campaign.addTestInModel(test, userID);
1200: }
1201:
1202: public ArrayList addTestInCampaignInDBAndModel(Test pTest,
1203: Campaign pCampain, int userID) throws Exception {
1204: boolean newDataSetCreated = false;
1205: ArrayList datasetsCreated = new ArrayList();
1206: ArrayList dataSets = pCampain.getDataSetListFromModel();
1207: //BDD
1208: int transNumber = -1;
1209: try {
1210: // BDD
1211: transNumber = Api.beginTransaction(110,
1212: ApiConstants.INSERT_TEST_INTO_CAMPAIGN);
1213:
1214: pCampain.importTestInDB(pTest.getIdBdd(), userID);
1215: for (int i = 0; i < pTest.getParameterListFromModel()
1216: .size(); i++) {
1217: if (dataSets != null) {
1218: if ((dataSets.size() == 0)
1219: && (!newDataSetCreated)
1220: && pCampain.getExecutionListFromModel()
1221: .size() != 0) {
1222: newDataSetCreated = true;
1223: for (int k = 0; k < pCampain
1224: .getExecutionListFromModel().size(); k++) {
1225: Execution pExecution = pCampain
1226: .getExecutionFromModel(k);
1227: DataSet newDataSet = new DataSet("dataSet_"
1228: + k, ApiConstants.DEFAULT_DATA_SET);
1229: newDataSet.addInDB(pCampain.getIdBdd());
1230:
1231: Parameter param = (Parameter) pTest
1232: .getParameterListFromModel().get(i);
1233: Environment env = pExecution
1234: .getEnvironmentFromModel();
1235:
1236: if (env.getParameterFromModel(param
1237: .getNameFromModel()) != null) {
1238: newDataSet
1239: .addParameterValueInDB(
1240: env
1241: .getParameterValueFromModel(param),
1242: param);
1243: } else {
1244: newDataSet.addParameterValueInDB("",
1245: param);
1246: }
1247:
1248: pExecution.updateDatasetInDB(newDataSet
1249: .getIdBdd());
1250: datasetsCreated.add(i, newDataSet);
1251: }
1252: } else {
1253: for (int k = 0; k < dataSets.size(); k++) {
1254: DataSet dataSet = (DataSet) dataSets.get(k);
1255: if (!dataSet
1256: .getParametersHashMapFromModel()
1257: .containsKey(
1258: ((Parameter) pTest
1259: .getParameterListFromModel()
1260: .get(i))
1261: .getNameFromModel())) {
1262: Parameter param = (Parameter) pTest
1263: .getParameterListFromModel()
1264: .get(i);
1265: if (Api.isDYNAMIC_VALUE_DATASET()) {
1266: dataSet
1267: .addParameterValueInDB(
1268: DataConstants.PARAM_VALUE_FROM_ENV,
1269: param);
1270: } else {
1271: dataSet.addParameterValueInDB("",
1272: param);
1273: }
1274: }
1275: }
1276: }
1277: }
1278: }
1279: Api.commitTrans(transNumber);
1280: } catch (Exception e) {
1281: Api.forceRollBackTrans(transNumber);
1282: }
1283: //Model
1284: for (int i = 0; i < pTest.getParameterListFromModel().size(); i++) {
1285: Parameter param = (Parameter) pTest
1286: .getParameterListFromModel().get(i);
1287: if (dataSets != null) {
1288: if (newDataSetCreated) {
1289: for (int ind = 0; ind < datasetsCreated.size(); ind++) {
1290: DataSet dataset = (DataSet) datasetsCreated
1291: .get(ind);
1292: pCampain.addDataSetInModel(dataset);
1293: //dataset.addParameter(param.getName(), "");
1294: }
1295: for (int k = 0; k < pCampain
1296: .getExecutionListFromModel().size(); k++) {
1297: Execution pExecution = pCampain
1298: .getExecutionFromModel(k);
1299: Environment env = pExecution
1300: .getEnvironmentFromModel();
1301: String paramValue = "";
1302: if (env.getParameterFromModel(param
1303: .getNameFromModel()) != null) {
1304: paramValue = env
1305: .getParameterValueFromModel(param);
1306: }
1307: ((DataSet) datasetsCreated.get(k))
1308: .addParameterValueInModel(param
1309: .getNameFromModel(), paramValue);
1310: pExecution
1311: .updateDatasetInModel((DataSet) datasetsCreated
1312: .get(k));
1313:
1314: //executionTableModel.setValueAt(((DataSet)datasetsCreated.get(k)).getName(),k,3);
1315: }
1316: } else {
1317: for (int k = 0; k < dataSets.size(); k++) {
1318: DataSet dataSet = (DataSet) dataSets.get(k);
1319: //String defParam = "\n";
1320: //int add = 0;
1321: if (!dataSet
1322: .getParametersHashMapFromModel()
1323: .containsKey(
1324: ((Parameter) pTest
1325: .getParameterListFromModel()
1326: .get(i))
1327: .getNameFromModel())) {
1328: //defParam += param.getNameFromModel() + " ";
1329: //add++;
1330: if (Api.isDYNAMIC_VALUE_DATASET()) {
1331: dataSet
1332: .addParameterValueInModel(
1333: param
1334: .getNameFromModel(),
1335: DataConstants.PARAM_VALUE_FROM_ENV);
1336: } else {
1337: dataSet.addParameterValueInModel(param
1338: .getNameFromModel(), "");
1339: }
1340: }
1341: /*if (add == 1){
1342: JOptionPane.showMessageDialog(AskNewExecution.this,
1343: Language.getInstance().getText("Le_parametre") + defParam + Language.getInstance().getText("Ajoute_aux_jeux"),
1344: Language.getInstance().getText("Attention_!"),
1345: JOptionPane.WARNING_MESSAGE);
1346: } else if (add > 1 ){
1347: JOptionPane.showMessageDialog(AskNewExecution.this,
1348: Language.getInstance().getText("Les_parametres") + defParam + Language.getInstance().getText("Ajoutes_aux_jeux"),
1349: Language.getInstance().getText("Attention_!"),
1350: JOptionPane.WARNING_MESSAGE);
1351: }*/
1352: }
1353: }
1354: }
1355: }
1356:
1357: addTestInCampaignInModel(pTest, pCampain, userID);
1358: return datasetsCreated;
1359: }
1360:
1361: public void addCampaignInModel(Campaign campaign) {
1362: campaignList.add(campaign);
1363: } // Fin de la méthode addcampaign/1
1364:
1365: public void addCampaignInDBandModel(Campaign campaign)
1366: throws Exception {
1367: campaign.addInDB(idBdd, pUser.getIdBdd());
1368: addCampaignInModel(campaign);
1369: }
1370:
1371: /**************** Operations de suppression dans données **********************************/
1372:
1373: /**
1374: * Supprime une campagne en mettant à jour le model
1375: * @param campagne une campagne
1376: */
1377: public void deleteCampaignInModel(Campaign pCampaign) {
1378: campaignList.remove(pCampaign);
1379: pCampaign.deleteInModel();
1380: //System.out.println("campaigne size" + campaignList.size());
1381: }
1382:
1383: public void deleteCampaignInDBAndModel(Campaign pCampaign)
1384: throws Exception {
1385: pCampaign.deleteInDB();
1386: deleteCampaignInModel(pCampaign);
1387: }
1388:
1389: /**
1390: * Supprime un test d'une campagne en mettan à jour l'ensemble du model
1391: * @param test un test
1392: * @param campagne une campagne
1393: * @return vrai si la campagne est vide
1394: */
1395: public boolean deleteTestFromCampaignInModel(Test test,
1396: Campaign campaign) {
1397: return campaign.deleteTestFromCampInModel(test, true);
1398:
1399: } // Fin de la méthode deleteTestFromCampaign/2
1400:
1401: public boolean deleteTestFromCampaignInDBAndModel(Test pTest,
1402: Campaign pCampaign) throws Exception {
1403: //BDD
1404: pCampaign.deleteTestFromCampInDB(pTest.getIdBdd(), true);
1405: //Model
1406: return deleteTestFromCampaignInModel(pTest, pCampaign);
1407:
1408: }
1409:
1410: /**
1411: * Supprime une suite de tests d'une campagne en mettan à jour l'ensemble du model
1412: * @param list une suite de tests
1413: * @param campagne une campagne
1414: * @return vrai si la campgne est vide
1415: */
1416: public boolean deleteTestListFromCampaignInModel(
1417: TestList pTestList, Campaign campaign) {
1418: return campaign.removeTestListInModel(pTestList);
1419: }
1420:
1421: /*
1422: * @TODO Utiliser les donnees de la BDD
1423: */
1424: public boolean deleteTestListFromCampaignInDBAndModel(
1425: TestList pTestList, Campaign campaign) throws Exception {
1426: //BDD
1427: int transNumber = -1;
1428: ArrayList pListofTest = campaign.getTestListFromModel();
1429: try {
1430: transNumber = Api.beginTransaction(10,
1431: ApiConstants.DELETE_TEST_FROM_CAMPAIGN);
1432: for (int i = 0; i < pListofTest.size(); i++) {
1433: Test pTest = (Test) pListofTest.get(i);
1434: if (pTestList.getTestFromModel(pTest.getIdBdd()) != null) {
1435: campaign.deleteTestFromCampInDB(pTest.getIdBdd(),
1436: true);
1437: }
1438: }
1439: Api.commitTrans(transNumber);
1440: } catch (Exception e) {
1441: Api.forceRollBackTrans(transNumber);
1442: throw e;
1443: }
1444: //Model
1445: return deleteTestListFromCampaignInModel(pTestList, campaign);
1446: } // Fin de la méthode deleteTestListFromCampaign/2
1447:
1448: /**
1449: * Supprime une famille d'une campagne en mettan à jour l'ensemble du model
1450: * @param family une famille
1451: * @param campagne une campagne
1452: * @return vrai si la campgne est vide
1453: */
1454: public boolean deleteFamilyFromCampaignFromModel(Family family,
1455: Campaign campaign) {
1456: return campaign.removeFamily(family);
1457: }
1458:
1459: /*
1460: * @TODO Utiliser les donnees de la BDD
1461: */
1462: public boolean deleteFamilyFromCampaignInDBAndModel(Family family,
1463: Campaign campaign) throws Exception {
1464: //BDD
1465: int transNumber = -1;
1466: ArrayList pListofTest = campaign.getTestListFromModel();
1467: try {
1468: transNumber = Api.beginTransaction(10,
1469: ApiConstants.DELETE_TEST_FROM_CAMPAIGN);
1470: for (int i = 0; i < pListofTest.size(); i++) {
1471: Test pTest = (Test) pListofTest.get(i);
1472: if (family.isContainTestInModel(pTest)) {
1473: campaign.deleteTestFromCampInDB(pTest.getIdBdd(),
1474: true);
1475: }
1476: }
1477: Api.commitTrans(transNumber);
1478: } catch (Exception e) {
1479: Api.forceRollBackTrans(transNumber);
1480: throw e;
1481: }
1482:
1483: //Model
1484: return deleteFamilyFromCampaignFromModel(family, campaign);
1485: }
1486:
1487: /************************** ATTACHEMENTS **********************/
1488: public void addAttachementInDB(Attachment attach) throws Exception {
1489: if (attach instanceof FileAttachment) {
1490: addAttachFileInDB((FileAttachment) attach);
1491: } else {
1492: addAttachUrlInDB((UrlAttachment) attach);
1493: }
1494: }
1495:
1496: void addAttachFileInDB(FileAttachment file) throws Exception {
1497: if (!isInBase()) {
1498: throw new Exception("TestList " + name + " is not in BDD");
1499: }
1500: File f = file.getLocalFile();
1501: int id = pISQLProject.addAttachFile(idBdd,
1502: new SalomeFileWrapper(f), file
1503: .getDescriptionFromModel());
1504: file.setIdBdd(id);
1505: }
1506:
1507: void addAttachUrlInDB(UrlAttachment url) throws Exception {
1508: if (!isInBase()) {
1509: throw new Exception("TestList " + name + " is not in BDD");
1510: }
1511: int id = pISQLProject.addAttachUrl(idBdd, url
1512: .getNameFromModel(), url.getDescriptionFromModel());
1513: url.setIdBdd(id);
1514: }
1515:
1516: protected void deleteAttachementInDB(int attachId) throws Exception {
1517: if (!isInBase()) {
1518: throw new Exception("TestList " + name + " is not in BDD");
1519: }
1520: pISQLProject.deleteAttach(idBdd, attachId);
1521: }
1522:
1523: public void deleteAttachementInDBAndModel(Attachment attach)
1524: throws Exception {
1525: deleteAttachementInDB(attach.getIdBdd());
1526: deleteAttachmentInModel(attach);
1527: }
1528:
1529: public Vector getAttachFilesFromDB() throws Exception {
1530: if (!isInBase()) {
1531: throw new Exception("TestList " + name + " is not in BDD");
1532: }
1533: FileAttachementWrapper[] tmpArray = pISQLProject
1534: .getAllAttachFiles(idBdd);
1535: Vector tmpVector = new Vector();
1536: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1537: tmpVector.add(tmpArray[tmpI]);
1538: }
1539: return tmpVector;
1540: }
1541:
1542: public Vector getAttachUrlsFromDB() throws Exception {
1543: if (!isInBase()) {
1544: throw new Exception("TestList " + name + " is not in BDD");
1545: }
1546: UrlAttachementWrapper[] tmpArray = pISQLProject
1547: .getAllAttachUrls(idBdd);
1548: Vector tmpVector = new Vector();
1549: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1550: tmpVector.add(tmpArray[tmpI]);
1551: }
1552: return tmpVector;
1553: }
1554:
1555: /******************************************************************************************************************/
1556:
1557: /**
1558: * Rend vrai si le nom passé en paramètre correspond au nom d'une campagne
1559: * @param campagneName un nom
1560: * @return Rend vrai si le nom passé en paramètre correspond au nom d'une
1561: * campagne, faux sinon.
1562: */
1563: public boolean containsCampaignInModel(String campaignName) {
1564: for (int i = 0; i < campaignList.size(); i++) {
1565: if (((Campaign) campaignList.get(i)).getNameFromModel()
1566: .equals(campaignName)) {
1567: return true;
1568: }
1569: }
1570: return false;
1571: }
1572:
1573: public boolean existeInBase() throws Exception {
1574: if (!isInBase()) {
1575: return false;
1576: }
1577: ProjectWrapper pProject = pISQLProject.getProject(name);
1578: return pProject.getIdBDD() == idBdd;
1579: }
1580:
1581: public void triFamilleInModel() {
1582: Collections.sort(familyList, new ComparateurFamille());
1583: }
1584:
1585: class ComparateurFamille implements Comparator {
1586: public int compare(Object poTest1, Object poTest2) {
1587: Family pFam1 = (Family) poTest1;
1588: Family pFam2 = (Family) poTest2;
1589: /*
1590: System.out.println(" ORDER1 = " + pTest1.getNameFromModel() + " " + pTest1.order);
1591: System.out.println(" ORDER2 = " + pTest2.getNameFromModel() + " " + pTest2.order);
1592: */
1593: if (pFam1.order > pFam2.order) {
1594: return 1;
1595: } else {
1596: return -1;
1597: }
1598: }
1599: }
1600:
1601: public void triCampagneInModel() {
1602: Collections.sort(campaignList, new ComparateurCampagne());
1603: }
1604:
1605: class ComparateurCampagne implements Comparator {
1606: public int compare(Object poTest1, Object poTest2) {
1607: Campaign pCamp1 = (Campaign) poTest1;
1608: Campaign pCamp2 = (Campaign) poTest2;
1609: /*
1610: System.out.println(" ORDER1 = " + pTest1.getNameFromModel() + " " + pTest1.order);
1611: System.out.println(" ORDER2 = " + pTest2.getNameFromModel() + " " + pTest2.order);
1612: */
1613: if (pCamp1.order > pCamp2.order) {
1614: return 1;
1615: } else {
1616: return -1;
1617: }
1618: }
1619: }
1620: }
|