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 salomeTMF_plug.requirements.data;
025:
026: import java.util.Vector;
027:
028: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
029:
030: import salomeTMF_plug.requirements.ReqPlugin;
031: import salomeTMF_plug.requirements.sqlWrapper.ReqWrapper;
032:
033: public class ReqFamily extends Requirement {
034:
035: Vector reqLeafList;
036:
037: public ReqFamily(String name, String description, ReqFamily parent) {
038: super (name, description, parent);
039: reqLeafList = new Vector();
040: }
041:
042: public ReqFamily(String name, String description) {
043: super (name, description, null);
044: reqLeafList = new Vector();
045: idBdd = 0;
046: }
047:
048: public ReqFamily(ReqWrapper pReqWrapper, ReqFamily parent) {
049: super (pReqWrapper.getName(), pReqWrapper.getDescription(),
050: parent);
051: idBdd = pReqWrapper.getIdBDD();
052: reqLeafList = new Vector();
053: //LoadAttachement
054: }
055:
056: public Requirement getCopie(ReqFamily pReqFamily) {
057: ReqFamily pReqFam = new ReqFamily(name, description, pReqFamily);
058:
059: int size = reqLeafList.size();
060: for (int i = 0; i < size; i++) {
061: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
062: pReqFam.addRequirement(pReq.getCopie(pReqFam));
063: }
064: return pReqFam;
065: }
066:
067: public void pastInDBandModel(Requirement pReq,
068: ReqFamily pReqOringine, boolean testName) throws Exception {
069: if (pReqOringine == null) {
070: pReq.m_parent = this ;
071: }
072: //GetUniqueName
073: String tmpName = pReq.getNameFromModel();
074: boolean trouve = false;
075: int j = 0;
076: while (!trouve && testName) {
077: ReqWrapper pReqWrapper = pSQLRequirement.getReq(pReq
078: .getNameFromModel(), idBdd, ReqPlugin
079: .getProjectRef().getIdBdd());
080: if (pReqWrapper == null) {
081: trouve = true;
082: } else {
083: pReq.updateNameInModel("copy_" + j + "_" + tmpName);
084: j++;
085: }
086: }
087: pReq.addInDB();
088: if (pReq instanceof ReqFamily) {
089: ReqFamily pReqFam = (ReqFamily) pReq;
090: Vector reqLeafList2 = pReqFam.reqLeafList;
091: int size = reqLeafList2.size();
092: for (int i = 0; i < size; i++) {
093: Requirement pReqTmp = (Requirement) reqLeafList2
094: .elementAt(i);
095: pastInDBandModel(pReqTmp, this , false);
096: }
097: } else {
098: ReqLeaf pReqLef = (ReqLeaf) pReq;
099: pReqLef.updateInfoInDB(pReqLef.version, pReqLef.origine,
100: pReqLef.verif, pReqLef.reference);
101: pReqLef.updateCatInDB(pReqLef.cat);
102: pReqLef.updateComplexeInDB(pReqLef.complexe);
103: pReqLef.updateStateInDB(pReqLef.state);
104: }
105: }
106:
107: public void addRequirement(Requirement req) {
108: if (contain(req) == null) {
109: reqLeafList.add(req);
110: }
111: }
112:
113: Requirement contain(Requirement reqTested) {
114: int size = reqLeafList.size();
115: for (int i = 0; i < size; i++) {
116: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
117: if (reqTested.getNameFromModel().equals(
118: pReq.getNameFromModel())) {
119: return pReq;
120: }
121: }
122: return null;
123: }
124:
125: public Vector getFistLeaf() {
126: Vector res = new Vector();
127: int size = reqLeafList.size();
128: for (int i = 0; i < size; i++) {
129: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
130: if (pReq instanceof ReqLeaf) {
131: res.add(pReq);
132: }
133: }
134: return res;
135: }
136:
137: public Vector getFirstFamily() {
138: Vector res = new Vector();
139: int size = reqLeafList.size();
140: for (int i = 0; i < size; i++) {
141: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
142: if (pReq instanceof ReqFamily) {
143: res.add(pReq);
144: }
145: }
146: return res;
147: }
148:
149: public Vector getAllLeaf() {
150: Vector res = new Vector();
151: int size = reqLeafList.size();
152: for (int i = 0; i < size; i++) {
153: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
154: if (pReq instanceof ReqLeaf) {
155: res.add(pReq);
156: } else {
157: Vector reqLeafList2 = ((ReqFamily) pReq).getAllLeaf();
158: for (int j = 0; j < reqLeafList2.size(); j++) {
159: res.add(reqLeafList2.elementAt(j));
160: }
161: }
162: }
163: return res;
164: }
165:
166: public Vector getAllLeaf(IReqFilter filtre) {
167: Vector res = new Vector();
168: int size = reqLeafList.size();
169: for (int i = 0; i < size; i++) {
170: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
171:
172: if (pReq instanceof ReqLeaf) {
173: int reqP = ((ReqLeaf) pReq).getPriorityFromModel();
174: //if (( reqP | filtre) == filtre){
175: if (filtre.isFiltred(pReq)) {
176: res.add(pReq);
177: }
178: } else {
179: Vector reqLeafList2 = ((ReqFamily) pReq)
180: .getAllLeaf(filtre);
181: for (int j = 0; j < reqLeafList2.size(); j++) {
182: res.add(reqLeafList2.elementAt(j));
183: }
184: }
185: }
186: return res;
187: }
188:
189: public Vector getAllLeafByPriority(int filtre) {
190: Vector res = new Vector();
191: int size = reqLeafList.size();
192: for (int i = 0; i < size; i++) {
193: Requirement pReq = (Requirement) reqLeafList.elementAt(i);
194:
195: if (pReq instanceof ReqLeaf) {
196: int reqP = ((ReqLeaf) pReq).getPriorityFromModel();
197: if ((reqP | filtre) == filtre) {
198: //if (filtre.isFiltred(pReq)){
199: res.add(pReq);
200: }
201: } else {
202: Vector reqLeafList2 = ((ReqFamily) pReq)
203: .getAllLeafByPriority(filtre);
204: for (int j = 0; j < reqLeafList2.size(); j++) {
205: res.add(reqLeafList2.elementAt(j));
206: }
207: }
208: }
209: return res;
210: }
211:
212: public boolean isFamilyReq() {
213: return true;
214: }
215:
216: void removeRequirment(Requirement req) {
217: //reqLeafList.remove(req);
218: Requirement reqToDel = contain(req);
219: if (reqToDel != null) {
220: reqLeafList.remove(reqToDel);
221: }
222: }
223:
224: void deleteInModel() {
225: reqLeafList.clear();
226: }
227:
228: public String toString() {
229: return "ReqSet : " + name;
230: }
231:
232: public String getLongName() {
233: if (m_parent != null) {
234: String parentName = m_parent.getLongName();
235: if (parentName != "") {
236: return parentName + "." + name;
237: } else {
238: return name;
239: }
240: } else {
241: return "";
242: }
243: }
244:
245: public void addInDB() throws Exception {
246: if (isInBase()) {
247: throw new Exception(
248: "[ReqFamily->addInDB] requirment already in base");
249: }
250: int idParent = m_parent.getIdBdd();
251: idBdd = pSQLRequirement.add(name, description, 0, idParent,
252: ReqPlugin.getProjectRef().getIdBdd(), 100);
253: }
254:
255: public void addTestCoverInDB(int idTest, boolean verifie)
256: throws Exception {
257: throw new Exception(
258: "[ReqFamily->addTestCover] unable to link test with a set of requiments");
259: }
260: }
|