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.util.Vector;
028:
029: import org.objectweb.salome_tmf.api.Api;
030: import org.objectweb.salome_tmf.api.ApiConstants;
031: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
032: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
033: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
034: import org.objectweb.salome_tmf.api.sql.ISQLExecutionTestResult;
035:
036: public class ExecutionTestResult extends WithAttachment {
037: static ISQLExecutionTestResult pISQLExecutionTestResult = null;
038:
039: protected Test test;
040: protected String status;
041: protected int order = -1;
042:
043: public ExecutionTestResult(Test pTest) {
044: super ("", "");
045: status = "";
046: test = pTest;
047: if (pISQLExecutionTestResult == null) {
048: pISQLExecutionTestResult = Api.getISQLObjectFactory()
049: .getISQLExecutionTestResult();
050: }
051: }
052:
053: public ExecutionTestResult(Test pTest, String stat) {
054: super ("", "");
055: test = pTest;
056: status = stat;
057: if (pISQLExecutionTestResult == null) {
058: pISQLExecutionTestResult = Api.getISQLObjectFactory()
059: .getISQLExecutionTestResult();
060: }
061: }
062:
063: public void setOrderInModel(int i) {
064: order = i;
065: }
066:
067: public int getOderFromModel() {
068: return order;
069: }
070:
071: public String getStatusFromModel() {
072: return status;
073: }
074:
075: public void setStatusInModel(String string) {
076: status = string;
077: }
078:
079: public Test getTestFromModel() {
080: return test;
081: }
082:
083: void addInDB(int idExecRes, int idTest) throws Exception {
084: if (isInBase()) {
085: throw new Exception("ExecutionTestResult " + name
086: + " already in BDD");
087: }
088: idBdd = pISQLExecutionTestResult.insert(idExecRes, idTest,
089: status);
090: Project.pCurrentProject.notifyChanged(
091: ApiConstants.INSERT_EXECUTION_TEST_RESULT, this );
092: }
093:
094: void updateInDB() throws Exception {
095: if (!isInBase()) {
096: throw new Exception("ExecutionTestResult " + name
097: + " is not in BDD");
098: }
099: pISQLExecutionTestResult.update(idBdd, status);
100: Project.pCurrentProject.notifyChanged(
101: ApiConstants.UPDATE_EXECUTION_TEST_RESULT, this );
102: }
103:
104: void deleteInDB() throws Exception {
105: if (!isInBase()) {
106: throw new Exception("ExecutionTestResult " + name
107: + " is not in BDD");
108: }
109: pISQLExecutionTestResult.delete(idBdd);
110: Project.pCurrentProject.notifyChanged(
111: ApiConstants.DELETE_EXECUTION_TEST_RESULT, this );
112: }
113:
114: void deleteInModel() {
115: test = null;
116: clearAttachInModel();
117: }
118:
119: void deleteInDBAndModel() throws Exception {
120: deleteInDB();
121: deleteInModel();
122: }
123:
124: public void updateInDBAndModel(String newName, String newDesc)
125: throws Exception {
126: throw new Exception("NOT IMPLEMENTED");
127: }
128:
129: /***************** About Attachements **********************/
130:
131: public void addAttachementInDB(Attachment attach) throws Exception {
132: if (attach instanceof FileAttachment) {
133: addAttachFileInDB((FileAttachment) attach);
134: } else {
135: addAttachUrlInDB((UrlAttachment) attach);
136: }
137: }
138:
139: void addAttachFileInDB(FileAttachment file) throws Exception {
140: if (!isInBase()) {
141: throw new Exception("ExecutionTestResult " + name
142: + " is not in BDD");
143: }
144:
145: File f = file.getLocalFile();
146: int id = pISQLExecutionTestResult.addAttachFile(idBdd,
147: new SalomeFileWrapper(f), file
148: .getDescriptionFromModel());
149: file.setIdBdd(id);
150: }
151:
152: void addAttachUrlInDB(UrlAttachment url) throws Exception {
153: if (!isInBase()) {
154: throw new Exception("ExecutionTestResult " + name
155: + " is not in BDD");
156: }
157:
158: int id = pISQLExecutionTestResult.addAttachUrl(idBdd, url
159: .getNameFromModel(), url.getDescriptionFromModel());
160: url.setIdBdd(id);
161: }
162:
163: public void deleteAttachementInDB(int attachId) throws Exception {
164: if (!isInBase()) {
165: throw new Exception("ExecutionTestResult " + name
166: + " is not in BDD");
167: }
168: pISQLExecutionTestResult.deleteAttach(idBdd, attachId);
169: }
170:
171: public void deleteAttachementInDBAndModel(Attachment attach)
172: throws Exception {
173: deleteAttachementInDB(attach.getIdBdd());
174: deleteAttachmentInModel(attach);
175: }
176:
177: public Vector getAttachFilesFromDB() throws Exception {
178: if (!isInBase()) {
179: throw new Exception("ExecutionTestResult " + name
180: + " is not in BDD");
181: }
182: FileAttachementWrapper[] tmpArray = pISQLExecutionTestResult
183: .getAttachFiles(idBdd);
184: Vector tmpVector = new Vector();
185: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
186: tmpVector.add(tmpArray[tmpI]);
187: }
188: return tmpVector;
189: }
190:
191: public Vector getAttachUrlsFromDB() throws Exception {
192: if (!isInBase()) {
193: throw new Exception("ExecutionTestResult " + name
194: + " is not in BDD");
195: }
196: UrlAttachementWrapper[] tmpArray = pISQLExecutionTestResult
197: .getAttachUrls(idBdd);
198: Vector tmpVector = new Vector();
199: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
200: tmpVector.add(tmpArray[tmpI]);
201: }
202: return tmpVector;
203: }
204:
205: public boolean existeInBase() throws Exception {
206: /* TODO */
207: return isInBase();
208:
209: }
210: }
|