001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.data;
025:
026: import java.io.File;
027: import java.sql.Date;
028: import java.sql.Time;
029: import java.util.ArrayList;
030: import java.util.HashMap;
031: import java.util.Hashtable;
032: import java.util.Iterator;
033: import java.util.Set;
034: import java.util.Vector;
035:
036: import org.objectweb.salome_tmf.api.Api;
037: import org.objectweb.salome_tmf.api.ApiConstants;
038: import org.objectweb.salome_tmf.api.data.DataSetWrapper;
039: import org.objectweb.salome_tmf.api.data.EnvironmentWrapper;
040: import org.objectweb.salome_tmf.api.data.ExecutionResultWrapper;
041: import org.objectweb.salome_tmf.api.data.ExecutionWrapper;
042: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
043: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
044: import org.objectweb.salome_tmf.api.data.ScriptWrapper;
045: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
046: import org.objectweb.salome_tmf.api.sql.ISQLExecution;
047:
048: public class Execution extends WithAttachment {
049:
050: static ISQLExecution pISQLExecution = null;
051:
052: protected Date creationDate = null;
053: protected Environment environment;
054: protected Campaign campagne;
055: protected Script initScript;
056: protected Script postScript;
057: protected DataSet dataSet;
058: protected ArrayList executionResultList;
059: protected Date lastDate = null;
060:
061: public Execution(String name, String description) {
062: super (name, description);
063: executionResultList = new ArrayList();
064: if (pISQLExecution == null) {
065: pISQLExecution = Api.getISQLObjectFactory()
066: .getISQLExecution();
067: }
068:
069: }
070:
071: public Execution(ExecutionWrapper exec) {
072: super (exec.getName(), exec.getDescription());
073: idBdd = exec.getIdBDD();
074: lastDate = exec.getLastDate();
075: creationDate = exec.getCreationDate();
076: executionResultList = new ArrayList();
077: if (pISQLExecution == null) {
078: pISQLExecution = Api.getISQLObjectFactory()
079: .getISQLExecution();
080: }
081: }
082:
083: public Execution(Campaign campagne, ExecutionWrapper exec) {
084: this (exec);
085: this .campagne = campagne;
086: }
087:
088: /******************************************************************************/
089: /** ACCESSEURS ET MUTATEURS ***/
090: /******************************************************************************/
091:
092: public Campaign getCampagneFromModel() {
093: return campagne;
094: }
095:
096: public Date getCreationDateFromModel() {
097: return creationDate;
098: }
099:
100: public ArrayList getExecutionResultListFromModel() {
101: return executionResultList;
102: }
103:
104: public Date getLastDateFromModel() {
105: return lastDate;
106: }
107:
108: /*public void setCampagneInModel(Campaign campagne) {
109: this.campagne = campagne;
110: } */
111:
112: public void setCreationDateInModel(Date date) {
113: creationDate = date;
114: }
115:
116: void addInDB(User pUser) throws Exception {
117: if (isInBase()) {
118: throw new Exception("Execution " + name
119: + " is already in BDD");
120: }
121: int idDataSet = dataSet.getIdBdd();
122: if (campagne.getIdBdd() == -1) {
123: throw new Exception("Campagne "
124: + campagne.getNameFromModel() + " is not in BDD");
125: }
126:
127: if (environment.getIdBdd() == -1) {
128: throw new Exception("Environment "
129: + environment.getNameFromModel() + " is not in BDD");
130: }
131:
132: if (idDataSet == -1
133: && dataSet.getNameFromModel().equals(
134: ApiConstants.EMPTY_NAME)) {
135: idDataSet = 0;
136: } else if (idDataSet < 1) {
137: throw new Exception("DataSet " + dataSet.getNameFromModel()
138: + " is not in BDD");
139: }
140:
141: if (pUser.getIdBdd() == -1) {
142: throw new Exception("User " + pUser.getNameFromModel()
143: + " is not in BDD");
144: }
145:
146: idBdd = pISQLExecution.insert(campagne.getIdBdd(), name,
147: environment.getIdBdd(), idDataSet, pUser.getIdBdd(),
148: description);
149: Project.pCurrentProject.notifyChanged(
150: ApiConstants.INSERT_EXECUTION, this );
151: }
152:
153: void addInModel(Campaign campagne, Environment environment,
154: DataSet dataSet) {
155: this .campagne = campagne;
156: this .environment = environment;
157: this .dataSet = dataSet;
158: }
159:
160: void addInBDAndModel(Campaign campagne, Environment environment,
161: DataSet dataSet, User pUser) throws Exception {
162: addInDB(pUser);
163: addInModel(campagne, environment, dataSet);
164: }
165:
166: void addInModel(Campaign pCampaign) {
167: this .campagne = pCampaign;
168: }
169:
170: void addInModel(Campaign pCampaign, HashMap pAttachmentMap) {
171: this .campagne = pCampaign;
172: setAttachmentMapInModel(pAttachmentMap);
173: }
174:
175: void addInDB(User pUser, HashMap pAttachmentMap, File fPre,
176: File fPost) throws Exception {
177: if (isInBase()) {
178: throw new Exception("Execution " + name
179: + " is already in BDD");
180: }
181: int transNumber = -1;
182: try {
183: transNumber = Api.beginTransaction(11,
184: ApiConstants.INSERT_EXECUTION);
185: addInDB(pUser);
186: Set keysSet = pAttachmentMap.keySet();
187:
188: if (keysSet != null) {
189: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
190: Attachment attach = getAttachmentFromModel((String) iter
191: .next());
192: if (attach instanceof FileAttachment) {
193: addAttachFileInDB((FileAttachment) attach);
194: } else {
195: addAttachUrlInDB((UrlAttachment) attach);
196: }
197: }
198: }
199: Script initScript = getPreScriptFromModel();
200: Script postScript = getPostScriptFromModel();
201: if (initScript != null) {
202: addScriptInDB(initScript, fPre);
203: }
204: if (postScript != null) {
205: addScriptInDB(postScript, fPost);
206: }
207:
208: Api.commitTrans(transNumber);
209:
210: } catch (Exception exception) {
211: Api.forceRollBackTrans(transNumber);
212: throw exception;
213: }
214: }
215:
216: void addInDBAndModel(User pUser, Campaign pCampaign,
217: HashMap pAttachmentMap, File fPre, File fPost)
218: throws Exception {
219: addInDB(pUser, pAttachmentMap, fPre, fPost);
220: addInModel(pCampaign, pAttachmentMap);
221: }
222:
223: void addInDBAndModel(User pUser, Campaign pCampaign, File fPre,
224: File fPost) throws Exception {
225: addInDB(pUser, getAttachmentMapFromModel(), fPre, fPost);
226: addInModel(pCampaign);
227: }
228:
229: void updateNameInDB(String newName) throws Exception {
230: if (!isInBase()) {
231: throw new Exception("Execution " + name + " is not in BDD");
232: }
233: pISQLExecution.updateName(idBdd, newName);
234: Project.pCurrentProject.notifyChanged(
235: ApiConstants.UPDATE_EXECUTION, this , new String(name),
236: newName);
237: }
238:
239: public void updateNameInModel(String newName) {
240: name = newName;
241: }
242:
243: public void updateNameInDBAndModel(String newName) throws Exception {
244: updateNameInDB(newName);
245: updateNameInModel(newName);
246: }
247:
248: public void updateInDBAndModel(String newName, String newDesc)
249: throws Exception {
250: updateNameInDB(newName);
251: updateNameInModel(newName);
252: }
253:
254: public void updateLastExecDateInDB(Date newDate) throws Exception {
255: if (!isInBase()) {
256: throw new Exception("Execution " + name + " is not in BDD");
257: }
258: pISQLExecution.updateDate(idBdd, newDate);
259:
260: }
261:
262: public void updateLastExecDateInModel(Date newDate) {
263: lastDate = newDate;
264: }
265:
266: public void updateLastExecDateInDBAndModel(Date newDate)
267: throws Exception {
268: updateLastExecDateInDB(newDate);
269: updateLastExecDateInModel(newDate);
270: }
271:
272: /* call from Camp */
273: void deleteInDB() throws Exception {
274: if (!isInBase()) {
275: throw new Exception("Execution " + name + " is not in BDD");
276: }
277: pISQLExecution.delete(idBdd);
278: Project.pCurrentProject.notifyChanged(
279: ApiConstants.DELETE_EXECUTION, this );
280: }
281:
282: /* call from Camp */
283: void deleteInModel() {
284: //campagne.removeExecution(this);
285: for (int i = 0; i < executionResultList.size(); i++) {
286: ExecutionResult pExecutionResult = (ExecutionResult) executionResultList
287: .get(i);
288: pExecutionResult.deleteInModel();
289: Project.pCurrentProject.notifyChanged(
290: ApiConstants.DELETE_EXECUTION_RESULT,
291: pExecutionResult);
292: }
293: clearAttachInModel();
294: executionResultList = null;
295: }
296:
297: /* call from Camp */
298: void deleteInDBAndModel() throws Exception {
299: deleteInDB();
300: deleteInModel();
301: }
302:
303: public Vector getResultsTimeFromDB() throws Exception {
304: if (!isInBase()) {
305: throw new Exception("Execution " + name + " is not in BDD");
306: }
307: long[] tmpArray = pISQLExecution.getAllExecDate(idBdd);
308: Vector tmpVector = new Vector();
309: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
310: tmpVector.add(new Time(tmpArray[tmpI]));
311: }
312: return tmpVector;
313: }
314:
315: /*************************** About Environnement *******************************/
316:
317: public void reloadEnvFromDB(ArrayList envInModel,
318: Hashtable paramInModel) throws Exception {
319: if (!isInBase()) {
320: throw new Exception("Execution " + name + " is not in BDD");
321: }
322: Environment environment = null;
323: EnvironmentWrapper pEnvW = getEnvironmentWrapperFromDB();
324: if (envInModel != null) {
325: boolean find = false;
326: int i = 0;
327: while (i < envInModel.size() && !find) {
328: if (((Environment) envInModel.get(i))
329: .getNameFromModel().equals(pEnvW.getName())) {
330: environment = (Environment) envInModel.get(i);
331: find = true;
332: }
333: i++;
334: }
335: }
336: if (environment == null) {
337: environment = new Environment(pEnvW);
338: environment.reloadFromDB(false, paramInModel);
339: updateEnvInModel(environment);
340: if (envInModel != null) {
341: envInModel.add(environment);
342: }
343: } else {
344: updateEnvInModel(environment);
345: }
346:
347: }
348:
349: void updateEnvInDB(int idEnv) throws Exception {
350: if (!isInBase()) {
351: throw new Exception("Execution " + name + " is not in BDD");
352: }
353: pISQLExecution.updateEnv(idBdd, idEnv);
354: }
355:
356: public void updateEnvInModel(Environment pEnv) {
357: environment = pEnv;
358: }
359:
360: public void updateEnvInDBAndModel(Environment pEnv)
361: throws Exception {
362: updateEnvInDB(pEnv.getIdBdd());
363: updateEnvInModel(pEnv);
364:
365: }
366:
367: public Environment getEnvironmentFromModel() {
368: return environment;
369: }
370:
371: public EnvironmentWrapper getEnvironmentWrapperFromDB()
372: throws Exception {
373: if (!isInBase()) {
374: throw new Exception("Execution " + name + " is not in BDD");
375: }
376: return pISQLExecution.getEnvironmentWrapper(idBdd);
377: }
378:
379: /*************************** About Datasets ************************************/
380:
381: public void reloadDataSetFromDB(ArrayList dataSetInModel,
382: Hashtable paramInModel) throws Exception {
383: if (!isInBase()) {
384: throw new Exception("Execution " + name + " is not in BDD");
385: }
386: DataSet dataSet = null;
387: DataSetWrapper pDataSetWrapper = getDataSetWrapperFromDB();
388:
389: if (pDataSetWrapper == null) {
390: dataSet = new DataSet(ApiConstants.EMPTY_NAME, "");
391: updateDatasetInModel(dataSet);
392: return;
393: }
394:
395: if (dataSetInModel != null) {
396: boolean find = false;
397: int i = 0;
398: while (i < dataSetInModel.size() && !find) {
399: if (((DataSet) dataSetInModel.get(i))
400: .getNameFromModel().equals(
401: pDataSetWrapper.getName())) {
402: dataSet = (DataSet) dataSetInModel.get(i);
403: find = true;
404: }
405: i++;
406: }
407: }
408: if (dataSet == null) {
409: dataSet = new DataSet(pDataSetWrapper);
410: dataSet.reloadFromDB(false, paramInModel);
411: updateDatasetInModel(dataSet);
412: if (dataSetInModel != null) {
413: dataSetInModel.add(dataSet);
414: }
415: } else {
416: updateDatasetInModel(dataSet);
417: }
418: }
419:
420: void updateDatasetInDB(int idDataset) throws Exception {
421: if (!isInBase()) {
422: throw new Exception("Execution " + name + " is not in BDD");
423: }
424: pISQLExecution.updateDataset(idBdd, idDataset);
425: }
426:
427: public void updateDatasetInModel(DataSet pDataSet) {
428: dataSet = pDataSet;
429: }
430:
431: public void updateDatasetInDBAndModel(DataSet pDataSet)
432: throws Exception {
433: updateDatasetInDB(pDataSet.getIdBdd());
434: updateDatasetInModel(pDataSet);
435: }
436:
437: public DataSet getDataSetFromModel() {
438: return dataSet;
439: }
440:
441: public DataSetWrapper getDataSetWrapperFromDB() throws Exception {
442: if (!isInBase()) {
443: throw new Exception("Execution " + name + " is not in BDD");
444: }
445: return pISQLExecution.getDataSetWrapper(idBdd);
446: }
447:
448: /*************************** About Attachements ******************************/
449:
450: void addAttachFileInDB(FileAttachment file) throws Exception {
451: if (!isInBase()) {
452: throw new Exception("Execution " + name + " is not in BDD");
453: }
454: File f = file.getLocalFile();
455: int id = pISQLExecution.addAttachFile(idBdd,
456: new SalomeFileWrapper(f), file
457: .getDescriptionFromModel());
458: file.setIdBdd(id);
459: }
460:
461: void addAttachUrlInDB(UrlAttachment url) throws Exception {
462: if (!isInBase()) {
463: throw new Exception("Execution " + name + " is not in BDD");
464: }
465: int id = pISQLExecution.addAttachUrl(idBdd, url
466: .getNameFromModel(), url.getDescriptionFromModel());
467: url.setIdBdd(id);
468: }
469:
470: public void addAttachInModel(Attachment attach) {
471: if (!containsAttachmentInModel(attach)) {
472: addAttachementInModel(attach);
473: }
474: }
475:
476: public void addAttachementInDB(Attachment attach) throws Exception {
477: if (attach instanceof FileAttachment) {
478: addAttachFileInDB((FileAttachment) attach);
479: } else {
480: addAttachUrlInDB((UrlAttachment) attach);
481: }
482: }
483:
484: public void addAttachInDBAndModel(Attachment attach)
485: throws Exception {
486: addAttachementInDB(attach);
487: addAttachInModel(attach);
488: }
489:
490: protected void deleteAttachementInDB(int attachId) throws Exception {
491: if (!isInBase()) {
492: throw new Exception("Execution " + name + " is not in BDD");
493: }
494: pISQLExecution.deleteAttach(idBdd, attachId);
495:
496: }
497:
498: public void deleteAttachementInDBAndModel(Attachment pAttach)
499: throws Exception {
500: //BDD
501: deleteAttachementInDB(pAttach.getIdBdd());
502:
503: //Mode
504: deleteAttachmentInModel(pAttach);
505: }
506:
507: public Vector getAttachFilesFromDB() throws Exception {
508: if (!isInBase()) {
509: throw new Exception("Execution " + name + " is not in BDD");
510: }
511: FileAttachementWrapper[] tmpArray = pISQLExecution
512: .getAttachFiles(idBdd);
513: Vector tmpVector = new Vector();
514: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
515: tmpVector.add(tmpArray[tmpI]);
516: }
517: return tmpVector;
518: }
519:
520: public Vector getAttachUrlsFromDB() throws Exception {
521: if (!isInBase()) {
522: throw new Exception("Execution " + name + " is not in BDD");
523: }
524: UrlAttachementWrapper[] tmpArray = pISQLExecution
525: .getAttachUrls(idBdd);
526: Vector tmpVector = new Vector();
527: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
528: tmpVector.add(tmpArray[tmpI]);
529: }
530: return tmpVector;
531:
532: }
533:
534: /*************************** About Scripts ************************************/
535:
536: public void reloadScriptFromDB() throws Exception {
537: if (!isInBase()) {
538: throw new Exception("Execution " + name + " is not in BDD");
539: }
540: ScriptWrapper[] pScripts = pISQLExecution
541: .getExecutionScripts(idBdd);
542: for (int i = 0; i < 2; i++) {
543: ScriptWrapper pScriptWrapper = pScripts[i];
544: if (pScripts[i] != null) {
545: Script pScript = new Script(pScriptWrapper);
546: addScriptInModel(pScript);
547: }
548: }
549:
550: }
551:
552: public void addScriptInDB(Script script, File file)
553: throws Exception {
554: if (!isInBase()) {
555: throw new Exception("Execution " + name + " is not in BDD");
556: }
557: int id = -1;
558: if (script.getTypeFromModel().equals(ApiConstants.PRE_SCRIPT)) {
559: id = pISQLExecution.addPreScript(idBdd,
560: new SalomeFileWrapper(file), script
561: .getDescriptionFromModel(), script
562: .getNameFromModel(), script
563: .getScriptExtensionFromModel(), script
564: .getPlugArgFromModel());
565: } else {
566: id = pISQLExecution.addPostScript(idBdd,
567: new SalomeFileWrapper(file), script
568: .getDescriptionFromModel(), script
569: .getNameFromModel(), script
570: .getScriptExtensionFromModel(), script
571: .getPlugArgFromModel());
572: }
573: script.setIdBdd(id);
574: }
575:
576: public void addScriptInModel(Script script) {
577: if (script.getTypeFromModel().equals(ApiConstants.PRE_SCRIPT)) {
578: initScript = script;
579: } else {
580: postScript = script;
581: }
582: }
583:
584: public void addPreScriptInModel(Script script) {
585: initScript = script;
586: }
587:
588: public void addPostScriptInModel(Script script) {
589: postScript = script;
590: }
591:
592: public void addPreScriptInDBAndModel(Script script, File file)
593: throws Exception {
594: //Bdd
595: addScriptInDB(script, file);
596: //Model
597: addScriptInModel(script);
598: }
599:
600: public void addPostScriptInDBAndModel(Script script, File file)
601: throws Exception {
602: //Bdd
603: addScriptInDB(script, file);
604:
605: //Model
606: addScriptInModel(script);
607: }
608:
609: public void addScriptInDBAndModel(Script script, File file)
610: throws Exception {
611: //Bdd
612: addScriptInDB(script, file);
613: //Model
614: addScriptInModel(script);
615: }
616:
617: public void deleteScriptInDB(String type) throws Exception {
618: if (!isInBase()) {
619: throw new Exception("Execution " + name + " is not in BDD");
620: }
621: if (type.equals(ApiConstants.PRE_SCRIPT)) {
622: pISQLExecution.deletePreScript(idBdd);
623: } else {
624: pISQLExecution.deletePostScript(idBdd);
625: }
626: }
627:
628: public void deleteScriptInModel(String type) {
629: if (type.equals(ApiConstants.PRE_SCRIPT)) {
630: initScript = null;
631: } else {
632: postScript = null;
633: }
634: }
635:
636: public void deleteScriptInBDAndModel(String type) throws Exception {
637: deleteScriptInDB(type);
638: deleteScriptInModel(type);
639: }
640:
641: public void deletePreScriptInDBAndModel() throws Exception {
642: deleteScriptInDB(ApiConstants.PRE_SCRIPT);
643: deleteScriptInModel(ApiConstants.PRE_SCRIPT);
644: }
645:
646: public void deletePostScriptInDBAndModel() throws Exception {
647: deleteScriptInDB(ApiConstants.POST_SCRIPT);
648: deleteScriptInModel(ApiConstants.POST_SCRIPT);
649: }
650:
651: public File getExecScriptFromDB(String type) throws Exception {
652: if (type.equals(ApiConstants.PRE_SCRIPT)) {
653: return getPreExecScriptFromDB();
654: } else {
655: return getPostExecScriptFromDB();
656: }
657: }
658:
659: public File getPreExecScriptFromDB() throws Exception {
660: if (!isInBase()) {
661: throw new Exception("Execution " + name + " is not in BDD");
662: }
663: return pISQLExecution.getPreScript(idBdd).toFile();
664: }
665:
666: public File getPostExecScriptFromDB() throws Exception {
667: if (!isInBase()) {
668: throw new Exception("Execution " + name + " is not in BDD");
669: }
670: return pISQLExecution.getPostScript(idBdd).toFile();
671: }
672:
673: public Script getPreScriptFromModel() { //Init
674: return initScript;
675: }
676:
677: public Script getPostScriptFromModel() {
678: return postScript;
679: }
680:
681: public ScriptWrapper getPreScriptWrapperFromDB() throws Exception {
682: if (!isInBase()) {
683: throw new Exception("Execution " + name + " is not in BDD");
684: }
685: return getScriptWrapperFromDB(ApiConstants.PRE_SCRIPT);
686: }
687:
688: public ScriptWrapper getPostScriptWrapperFromDB() throws Exception {
689: if (!isInBase()) {
690: throw new Exception("Execution " + name + " is not in BDD");
691: }
692: return getScriptWrapperFromDB(ApiConstants.POST_SCRIPT);
693: }
694:
695: ScriptWrapper getScriptWrapperFromDB(String type) throws Exception {
696: if (!isInBase()) {
697: throw new Exception("Execution " + name + " is not in BDD");
698: }
699: ScriptWrapper[] pScripts = pISQLExecution
700: .getExecutionScripts(idBdd);
701: int i = 0;
702: while (i < 2) {
703: ScriptWrapper pScriptWrapper = pScripts[i];
704: if (pScripts[i] != null) {
705: if (pScriptWrapper.getType().equals(type)) {
706: return pScriptWrapper;
707: }
708: }
709: i++;
710: }
711: return null;
712: }
713:
714: /************ About Execution Result ***************/
715:
716: public void reloadExecResultFromDB() throws Exception {
717: if (!isInBase()) {
718: throw new Exception("Execution " + name + " is not in BDD");
719: }
720: for (int i = 0; i < executionResultList.size(); i++) {
721: deleteExecutionResultInModel((ExecutionResult) executionResultList
722: .get(i));
723: }
724: executionResultList.clear();
725: Vector execResWrapList = getExceutionsResultWrapperFromDB();
726: for (int i = 0; i < execResWrapList.size(); i++) {
727: ExecutionResult execResult = new ExecutionResult(
728: (ExecutionResultWrapper) execResWrapList.get(i),
729: this );
730: //execResult.reloadFromDB(false, campagne.getTestListFromModel());
731: execResult.reloadFromDB(false);
732: addExecutionResultInModel(execResult);
733: }
734: }
735:
736: public void setExecutionResultListInModel(ArrayList list) {
737: executionResultList = list;
738: }
739:
740: public void addExecutionResultInModel(ExecutionResult result) {
741: executionResultList.add(result);
742: }
743:
744: public void addExecutionResultInDB(ExecutionResult result,
745: User pUser) throws Exception {
746: result.addInDB(this , pUser);
747: }
748:
749: public void addExecutionResultInDBAndModel(ExecutionResult result,
750: User pUser) throws Exception {
751: addExecutionResultInDB(result, pUser);
752: addExecutionResultInModel(result);
753: }
754:
755: public ExecutionResult getExecutionResultFromModel(String name) {
756: for (int i = 0; i < executionResultList.size(); i++) {
757: if (((ExecutionResult) executionResultList.get(i))
758: .getNameFromModel().equals(name)) {
759: return (ExecutionResult) executionResultList.get(i);
760: }
761: }
762: return null;
763: }
764:
765: public void deleteExecutionResultInModel(ExecutionResult execResult) {
766: execResult.deleteInModel();
767: executionResultList.remove(execResult);
768: }
769:
770: public void deleteExecutionResultInDBAndModel(
771: ExecutionResult execResult) throws Exception {
772: execResult.deleteInDB();
773: deleteExecutionResultInModel(execResult);
774: }
775:
776: public void deleteTestFromExecInModel(Test test) {
777: for (int i = 0; i < executionResultList.size(); i++)
778: ((ExecutionResult) executionResultList.get(i))
779: .removeTestResult(test);
780: }
781:
782: public Vector getExceutionsResultWrapperFromDB() throws Exception {
783: if (!isInBase()) {
784: throw new Exception("Execution " + name + " is not in BDD");
785: }
786: ExecutionResultWrapper[] tmpArray = pISQLExecution
787: .getExecResults(idBdd);
788: Vector tmpVector = new Vector();
789: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
790: tmpVector.add(tmpArray[tmpI]);
791: }
792: return tmpVector;
793: }
794:
795: public static boolean isInBase(Campaign pCamp, String execName) {
796: try {
797: int id = pISQLExecution.getID(pCamp.getIdBdd(), execName);
798: if (id > 0) {
799: return true;
800: }
801: return false;
802: } catch (Exception e) {
803:
804: }
805: return false;
806: } // Fin de la méthode isInBase/1
807:
808: public boolean existeInBase() throws Exception {
809: if (!isInBase()) {
810: return false;
811: }
812: return pISQLExecution.getID(campagne.getIdBdd(), name) == idBdd;
813: }
814:
815: /**************************** Model Conformity operation *************************/
816:
817: /**
818: * Return true if the excution and his component are in base
819: */
820: public boolean isValideModel() throws Exception {
821: //dataSet
822:
823: int transNuber = -1;
824: try {
825: transNuber = Api.beginTransaction(11, ApiConstants.LOADING);
826: if (!existeInBase()) {
827: return false;
828: }
829: if (!dataSet.getNameFromModel().equals(
830: ApiConstants.EMPTY_NAME)
831: && !dataSet.existeInBase()) {
832: return false;
833: }
834: if (!environment.existeInBase()) {
835: return false;
836: }
837: Api.commitTrans(transNuber);
838: return true;
839: } catch (Exception e) {
840: Api.forceRollBackTrans(transNuber);
841: throw e;
842: }
843: }
844: }
|