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 salomeTMF_plug.requirements.sqlWrapper;
0025:
0026: import java.io.File;
0027: import java.net.URL;
0028: import java.sql.Date;
0029: import java.sql.PreparedStatement;
0030: import java.sql.ResultSet;
0031: import java.util.ArrayList;
0032: import java.util.Calendar;
0033: import java.util.GregorianCalendar;
0034: import java.util.Vector;
0035:
0036: import org.objectweb.salome_tmf.api.Api;
0037: import org.objectweb.salome_tmf.api.Util;
0038: import org.objectweb.salome_tmf.api.data.AttachementWrapper;
0039: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
0040: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
0041: import org.objectweb.salome_tmf.api.data.TestWrapper;
0042: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
0043:
0044: public class SQLRequirement implements ISQLRequirement {
0045:
0046: int idPersonne = 0;
0047:
0048: /**
0049: * Insert a requirments in database
0050: * @param name
0051: * @param description
0052: * @param req_type : 1 for requirement or 0 for requirement set
0053: * @param id_parent
0054: * @param id_project
0055: * @return the id of the requirment
0056: * @throws Exception
0057: */
0058: public int add(String name, String description, int req_type,
0059: int id_parent, int id_project, int priority)
0060: throws Exception {
0061: int id = -1;
0062: if (req_type < 0) {
0063: throw new Exception(
0064: "[SQLRequirement] data entry are not valid");
0065: }
0066: if (id_parent < 0) {
0067: throw new Exception(
0068: "[SQLRequirement] data entry are not valid");
0069: }
0070: if (id_project < 0) {
0071: throw new Exception(
0072: "[SQLRequirement] data entry are not valid");
0073: }
0074: if (name == null || name.equals("")) {
0075: throw new Exception(
0076: "[SQLRequirement] data entry are not valid");
0077: }
0078: if (description == null) {
0079: throw new Exception(
0080: "[SQLRequirement] data entry are not valid");
0081: }
0082: ReqWrapper pReqWrapper = getReq(name, id_parent, id_project);
0083: if (pReqWrapper != null) {
0084: throw new Exception(
0085: "[SQLRequirement] requiment name already exist");
0086: }
0087:
0088: int transNumber = -1;
0089:
0090: try {
0091: transNumber = SQLWrapper.beginTransaction();
0092: PreparedStatement prep = SQLWrapper
0093: .getSQLAddQuery("addRequirement");
0094: prep.setInt(1, id_project);
0095: prep.setString(2, name);
0096: prep.setString(3, description);
0097: prep.setInt(4, id_parent);
0098: prep.setInt(5, req_type);
0099: prep.setInt(6, priority);
0100: SQLWrapper.runAddQuery(prep);
0101:
0102: pReqWrapper = getReq(name, id_parent, id_project);
0103: id = pReqWrapper.getIdBDD();
0104:
0105: /* HISTORY */
0106: try {
0107: addHistory(id, idPersonne, HIST_CREATE_REQ, name);
0108: if (id_parent != 0) {
0109: int code = HIST_ADD_REQLEAF;
0110: if (req_type == 0) {
0111: code = HIST_ADD_REQFAM;
0112: }
0113: addHistory(id_parent, idPersonne, code, name);
0114: }
0115: } catch (Exception eH) {
0116:
0117: }
0118: if (id == id_parent) {
0119: throw new Exception(
0120: "[SQLRequirement->add] A requeriement canot have same id of his parent");
0121: }
0122: SQLWrapper.commitTrans(transNumber);
0123: } catch (Exception e) {
0124: SQLWrapper.rollBackTrans(transNumber);
0125: throw e;
0126: }
0127:
0128: return id;
0129: }
0130:
0131: /**
0132: * Attach a file attach to a test in table ATTACHEMENT and reference in table REQ_ATTACHEMENT
0133: * @param idReq : id of the requirement
0134: * @param f : the file
0135: * @param description of the file
0136: * @return the id of the attachment in the table ATTACHEMENT
0137: * @throws Exception
0138: * @See ISQLFileAttachment.insert(File, String);
0139: * no permission needed
0140: */
0141: public int addAttachFile(int idReq, SalomeFileWrapper f,
0142: String description) throws Exception {
0143: if (idReq < 1 || f == null) {
0144: throw new Exception(
0145: "[SQLRequirement->addAttachFile] entry data are not valid");
0146: }
0147: int transNumber = -1;
0148: int idAttach = -1;
0149: try {
0150: transNumber = SQLWrapper.beginTransaction();
0151:
0152: idAttach = Api.getISQLObjectFactory()
0153: .getISQLFileAttachment().insert(f, description);
0154:
0155: PreparedStatement prep = SQLWrapper
0156: .getSQLAddQuery("addAttachToReq");
0157: prep.setInt(1, idReq);
0158: prep.setInt(2, idAttach);
0159: SQLWrapper.runAddQuery(prep);
0160:
0161: /* HISTORY */
0162: try {
0163: addHistory(idReq, idPersonne, HIST_ADD_ATTACH, f
0164: .getName()
0165: + " [id = " + idAttach + "]");
0166: } catch (Exception eH) {
0167:
0168: }
0169:
0170: SQLWrapper.commitTrans(transNumber);
0171: } catch (Exception e) {
0172: SQLWrapper.rollBackTrans(transNumber);
0173: Util.log("[SQLRequirement->addAttachFile]" + e);
0174: if (Api.isDEBUG()) {
0175: e.printStackTrace();
0176: }
0177: throw e;
0178: }
0179: return idAttach;
0180: }
0181:
0182: /**
0183: * Attach a url to a test in table ATTACHEMENT and reference in table REQ_ATTACHEMENT
0184: * @param idReq : id of the requirement
0185: * @param url
0186: * @param description of the url
0187: * @return the id of the attachment in the table ATTACHEMENT
0188: * @see ISQLUrlAttachment.insert(String, String);
0189: * @throws Exception
0190: */
0191: public int addAttachUrl(int idReq, String url, String description)
0192: throws Exception {
0193: if (idReq < 1 || url == null) {
0194: throw new Exception(
0195: "[SQLRequirement->addAttachUrl] entry data are not valid");
0196: }
0197: int transNumber = -1;
0198: int idAttach = -1;
0199: try {
0200: transNumber = SQLWrapper.beginTransaction();
0201: idAttach = Api.getISQLObjectFactory()
0202: .getISQLUrlAttachment().insert(url, description);
0203:
0204: PreparedStatement prep = SQLWrapper
0205: .getSQLAddQuery("addAttachToReq");
0206: prep.setInt(1, idReq);
0207: prep.setInt(2, idAttach);
0208: SQLWrapper.runAddQuery(prep);
0209:
0210: /* HISTORY */
0211: try {
0212: addHistory(idReq, idPersonne, HIST_ADD_ATTACH, url
0213: + " [id = " + idAttach + "]");
0214: } catch (Exception eH) {
0215:
0216: }
0217: SQLWrapper.commitTrans(transNumber);
0218: } catch (Exception e) {
0219: SQLWrapper.rollBackTrans(transNumber);
0220: Util.log("[SQLRequirement->addAttachUrl]" + e);
0221: if (Api.isDEBUG()) {
0222: e.printStackTrace();
0223: }
0224: throw e;
0225: }
0226:
0227: return idAttach;
0228: }
0229:
0230: public void addReqConvert(int idReq, int idTest) throws Exception {
0231: int transNumber = -1;
0232: if (idReq < 0) {
0233: throw new Exception(
0234: "[SQLRequirement->addReqConvert] data entry are not valid");
0235: }
0236: if (idTest < 0) {
0237: throw new Exception(
0238: "[SQLRequirement->addReqConvert] data entry are not valid");
0239: }
0240: try {
0241: transNumber = SQLWrapper.beginTransaction();
0242:
0243: PreparedStatement prep = SQLWrapper
0244: .getSQLAddQuery("addReqCover");
0245: prep.setInt(1, idReq);
0246: prep.setInt(2, idTest);
0247:
0248: SQLWrapper.runAddQuery(prep);
0249:
0250: /* HISTORY */
0251: try {
0252: addHistory(idReq, idPersonne, HIST_ADD_COVER, ""
0253: + idTest);
0254: } catch (Exception eH) {
0255:
0256: }
0257:
0258: SQLWrapper.commitTrans(transNumber);
0259: } catch (Exception e) {
0260: SQLWrapper.rollBackTrans(transNumber);
0261: Util.log("[SQLRequirement->addReqConvert]" + e);
0262: if (Api.isDEBUG()) {
0263: e.printStackTrace();
0264: }
0265: throw e;
0266: }
0267: }
0268:
0269: public void updateName(int idReq, String newName, int id_parent,
0270: int idProjet) throws Exception {
0271:
0272: if (idReq < 0) {
0273: throw new Exception(
0274: "[SQLRequirement->updateName] data entry are not valid");
0275: }
0276: if (idProjet < 0) {
0277: throw new Exception(
0278: "[SQLRequirement->updateName] data entry are not valid");
0279: }
0280: if (newName == null || newName.equals("")) {
0281: throw new Exception(
0282: "[SQLRequirement->updateName] data entry are not valid");
0283: }
0284:
0285: ReqWrapper pReqWrapper = getReq(newName, id_parent, idProjet);
0286: if (pReqWrapper != null) {
0287: throw new Exception(
0288: "[SQLRequirement->updateName] requiment name already exist");
0289: }
0290:
0291: int transNumber = -1;
0292: try {
0293: transNumber = SQLWrapper.beginTransaction();
0294:
0295: PreparedStatement prep = SQLWrapper
0296: .getSQLUpdateQuery("updateReqName");
0297: prep.setString(1, newName);
0298: prep.setInt(2, idReq);
0299: SQLWrapper.runUpdateQuery(prep);
0300:
0301: /* HISTORY */
0302: try {
0303: addHistory(idReq, idPersonne, HIST_UPDATE_NAME, newName);
0304: } catch (Exception eH) {
0305:
0306: }
0307:
0308: SQLWrapper.commitTrans(transNumber);
0309: } catch (Exception e) {
0310: SQLWrapper.rollBackTrans(transNumber);
0311: throw e;
0312: }
0313: }
0314:
0315: public void updateDescription(int idReq, String newdescription)
0316: throws Exception {
0317: int transNumber = -1;
0318: if (idReq < 0) {
0319: throw new Exception(
0320: "[SQLRequirement->updateDescription] data entry are not valid");
0321: }
0322: if (newdescription == null) {
0323: throw new Exception(
0324: "[SQLRequirement->updateDescription] data entry are not valid");
0325: }
0326: try {
0327: transNumber = SQLWrapper.beginTransaction();
0328: PreparedStatement prep = SQLWrapper
0329: .getSQLUpdateQuery("updateReqDescription");
0330: prep.setString(1, newdescription);
0331: prep.setInt(2, idReq);
0332: SQLWrapper.runUpdateQuery(prep);
0333:
0334: /* HISTORY */
0335: try {
0336: String strDesc = newdescription;
0337: if (strDesc.length() > 254) {
0338: strDesc = strDesc.substring(0, 254);
0339: }
0340: addHistory(idReq, idPersonne, HIST_UPDATE_DESCRIPTION,
0341: strDesc);
0342: } catch (Exception eH) {
0343:
0344: }
0345:
0346: SQLWrapper.commitTrans(transNumber);
0347: } catch (Exception e) {
0348: SQLWrapper.rollBackTrans(transNumber);
0349: throw e;
0350: }
0351: }
0352:
0353: public void updateVersion(int idReq, String version)
0354: throws Exception {
0355: int transNumber = -1;
0356: if (idReq < 0) {
0357: throw new Exception(
0358: "[SQLRequirement->updateVersion] data entry are not valid");
0359: }
0360: if (version == null) {
0361: throw new Exception(
0362: "[SQLRequirement->updateVersion] data entry are not valid");
0363: }
0364: try {
0365: transNumber = SQLWrapper.beginTransaction();
0366: PreparedStatement prep = SQLWrapper
0367: .getSQLUpdateQuery("updateVersion");
0368: prep.setString(1, version);
0369: prep.setInt(2, idReq);
0370: SQLWrapper.runUpdateQuery(prep);
0371:
0372: /* HISTORY */
0373: try {
0374: addHistory(idReq, idPersonne, HIST_UPDATE_VERSION,
0375: version);
0376: } catch (Exception eH) {
0377:
0378: }
0379:
0380: SQLWrapper.commitTrans(transNumber);
0381: } catch (Exception e) {
0382: SQLWrapper.rollBackTrans(transNumber);
0383: throw e;
0384: }
0385: }
0386:
0387: public void updateReference(int idReq, String reference)
0388: throws Exception {
0389: int transNumber = -1;
0390: if (idReq < 0) {
0391: throw new Exception(
0392: "[SQLRequirement->updateReference] data entry are not valid");
0393: }
0394: if (reference == null) {
0395: throw new Exception(
0396: "[SQLRequirement->updateReference] data entry are not valid");
0397: }
0398: try {
0399: transNumber = SQLWrapper.beginTransaction();
0400: PreparedStatement prep = SQLWrapper
0401: .getSQLUpdateQuery("updateReference");
0402: prep.setString(1, reference);
0403: prep.setInt(2, idReq);
0404: SQLWrapper.runUpdateQuery(prep);
0405:
0406: /* HISTORY */
0407: try {
0408: addHistory(idReq, idPersonne, HIST_UPDATE_REFERENCE,
0409: reference);
0410: } catch (Exception eH) {
0411:
0412: }
0413: SQLWrapper.commitTrans(transNumber);
0414: } catch (Exception e) {
0415: SQLWrapper.rollBackTrans(transNumber);
0416: throw e;
0417: }
0418: }
0419:
0420: public void updateInfo(int idReq, String _version, String _origine,
0421: String _verif, String _reference) throws Exception {
0422: int transNumber = -1;
0423: if (idReq < 0) {
0424: throw new Exception(
0425: "[SQLRequirement->updateInfo] data entry are not valid");
0426: }
0427: if (_version == null) {
0428: throw new Exception(
0429: "[SQLRequirement->updateInfo] data entry are not valid");
0430: }
0431: if (_origine == null) {
0432: throw new Exception(
0433: "[SQLRequirement->updateInfo] data entry are not valid");
0434: }
0435: if (_verif == null) {
0436: throw new Exception(
0437: "[SQLRequirement->updateInfo] data entry are not valid");
0438: }
0439: if (_reference == null) {
0440: throw new Exception(
0441: "[SQLRequirement->updateInfo] data entry are not valid");
0442: }
0443: try {
0444: transNumber = SQLWrapper.beginTransaction();
0445: PreparedStatement prep = SQLWrapper
0446: .getSQLUpdateQuery("updateInfo");
0447: prep.setString(1, _version);
0448: prep.setString(2, _origine);
0449: prep.setString(3, _verif);
0450: prep.setString(4, _reference);
0451: prep.setInt(5, idReq);
0452: SQLWrapper.runUpdateQuery(prep);
0453:
0454: /* HISTORY */
0455: try {
0456: addHistory(idReq, idPersonne, HIST_UPDATE_INFO, "["
0457: + _origine + "]; [" + _reference + "]; ["
0458: + _version + "]; [" + _verif + "]");
0459: } catch (Exception eH) {
0460:
0461: }
0462: SQLWrapper.commitTrans(transNumber);
0463: } catch (Exception e) {
0464: SQLWrapper.rollBackTrans(transNumber);
0465: throw e;
0466: }
0467: }
0468:
0469: public void updatePriority(int idReq, int priority)
0470: throws Exception {
0471: int transNumber = -1;
0472: if (idReq < 0) {
0473: throw new Exception(
0474: "[SQLRequirement->updatePriority] data entry are not valid");
0475: }
0476: if (priority < 1 || priority > 1000) {
0477: throw new Exception(
0478: "[SQLRequirement->updatePriority] data entry are not valid");
0479: }
0480: try {
0481: transNumber = SQLWrapper.beginTransaction();
0482: PreparedStatement prep = SQLWrapper
0483: .getSQLUpdateQuery("updatePriority");
0484: prep.setInt(1, priority);
0485: prep.setInt(2, idReq);
0486: SQLWrapper.runUpdateQuery(prep);
0487: /* HISTORY */
0488: try {
0489: addHistory(idReq, idPersonne, HIST_UPDATE_PRIORITY, ""
0490: + priority);
0491: } catch (Exception eH) {
0492:
0493: }
0494: SQLWrapper.commitTrans(transNumber);
0495: } catch (Exception e) {
0496: SQLWrapper.rollBackTrans(transNumber);
0497: throw e;
0498: }
0499: }
0500:
0501: /**
0502: *
0503: * @param idReq
0504: * @param cat 0 to 7
0505: * @throws Exception
0506: */
0507: public void updateCat(int idReq, int cat) throws Exception {
0508: int transNumber = -1;
0509: if (idReq < 0) {
0510: throw new Exception(
0511: "[SQLRequirement->updateCat] data entry are not valid");
0512: }
0513: if (cat < 0 || cat > 7) {
0514: throw new Exception(
0515: "[SQLRequirement->updateCat] data entry are not valid");
0516: }
0517: try {
0518: transNumber = SQLWrapper.beginTransaction();
0519: PreparedStatement prep = SQLWrapper
0520: .getSQLUpdateQuery("updateCat");
0521: prep.setInt(1, cat);
0522: prep.setInt(2, idReq);
0523: SQLWrapper.runUpdateQuery(prep);
0524: /* HISTORY */
0525: try {
0526: addHistory(idReq, idPersonne, HIST_UPDATE_CATEGORY, ""
0527: + cat);
0528: } catch (Exception eH) {
0529:
0530: }
0531: SQLWrapper.commitTrans(transNumber);
0532: } catch (Exception e) {
0533: SQLWrapper.rollBackTrans(transNumber);
0534: throw e;
0535: }
0536: }
0537:
0538: public void updateComplexe(int idReq, int comp) throws Exception {
0539: int transNumber = -1;
0540: if (idReq < 0) {
0541: throw new Exception(
0542: "[SQLRequirement->updateComplexe] data entry are not valid");
0543: }
0544: if (comp < 1 || comp > 1000) {
0545: throw new Exception(
0546: "[SQLRequirement->updateComplexe] data entry are not valid");
0547: }
0548: try {
0549: transNumber = SQLWrapper.beginTransaction();
0550: PreparedStatement prep = SQLWrapper
0551: .getSQLUpdateQuery("updateComplexe");
0552: prep.setInt(1, comp);
0553: prep.setInt(2, idReq);
0554: SQLWrapper.runUpdateQuery(prep);
0555: /* HISTORY */
0556: try {
0557: addHistory(idReq, idPersonne, HIST_UPDATE_COMPLEXITY,
0558: "" + comp);
0559: } catch (Exception eH) {
0560:
0561: }
0562: SQLWrapper.commitTrans(transNumber);
0563: } catch (Exception e) {
0564: SQLWrapper.rollBackTrans(transNumber);
0565: throw e;
0566: }
0567: }
0568:
0569: public void updateOrigine(int idReq, String org) throws Exception {
0570: int transNumber = -1;
0571: if (idReq < 0) {
0572: throw new Exception(
0573: "[SQLRequirement->updateOrigine] data entry are not valid");
0574: }
0575: if (org == null) {
0576: org = "";
0577: }
0578: try {
0579: transNumber = SQLWrapper.beginTransaction();
0580: PreparedStatement prep = SQLWrapper
0581: .getSQLUpdateQuery("updateOrigine");
0582: prep.setString(1, org);
0583: prep.setInt(2, idReq);
0584: SQLWrapper.runUpdateQuery(prep);
0585: /* HISTORY */
0586: try {
0587: addHistory(idReq, idPersonne, HIST_UPDATE_ORIGINE, org);
0588: } catch (Exception eH) {
0589:
0590: }
0591: SQLWrapper.commitTrans(transNumber);
0592: } catch (Exception e) {
0593: SQLWrapper.rollBackTrans(transNumber);
0594: throw e;
0595: }
0596: }
0597:
0598: public void updateState(int idReq, int state) throws Exception {
0599: int transNumber = -1;
0600: if (idReq < 0) {
0601: throw new Exception(
0602: "[SQLRequirement->updateState] data entry are not valid");
0603: }
0604: if (state < 0 || state > 7) {
0605: throw new Exception(
0606: "[SQLRequirement->updateState] data entry are not valid");
0607: }
0608: try {
0609: transNumber = SQLWrapper.beginTransaction();
0610: PreparedStatement prep = SQLWrapper
0611: .getSQLUpdateQuery("updateState");
0612: prep.setInt(1, state);
0613: prep.setInt(2, idReq);
0614: SQLWrapper.runUpdateQuery(prep);
0615: /* HISTORY */
0616: try {
0617: addHistory(idReq, idPersonne, HIST_UPDATE_SATE, ""
0618: + state);
0619: } catch (Exception eH) {
0620:
0621: }
0622: SQLWrapper.commitTrans(transNumber);
0623: } catch (Exception e) {
0624: SQLWrapper.rollBackTrans(transNumber);
0625: throw e;
0626: }
0627: }
0628:
0629: public void updateVerif(int idReq, String verif) throws Exception {
0630: int transNumber = -1;
0631: if (idReq < 0) {
0632: throw new Exception(
0633: "[SQLRequirement->updateVerif] data entry are not valid");
0634: }
0635: if (verif == null) {
0636: verif = "";
0637: }
0638: try {
0639: transNumber = SQLWrapper.beginTransaction();
0640: PreparedStatement prep = SQLWrapper
0641: .getSQLUpdateQuery("updateVerif");
0642: prep.setString(1, verif);
0643: prep.setInt(2, idReq);
0644: SQLWrapper.runUpdateQuery(prep);
0645: /* HISTORY */
0646: try {
0647: addHistory(idReq, idPersonne, HIST_UPDATE_VERIFWAY,
0648: verif);
0649: } catch (Exception eH) {
0650:
0651: }
0652: SQLWrapper.commitTrans(transNumber);
0653: } catch (Exception e) {
0654: SQLWrapper.rollBackTrans(transNumber);
0655: throw e;
0656: }
0657: }
0658:
0659: public void updateParent(int idReq, int idParent) throws Exception {
0660: int transNumber = -1;
0661: if (idReq < 0) {
0662: throw new Exception(
0663: "[SQLRequirement->updateParent] data entry are not valid");
0664: }
0665: if (idParent < 0) {
0666: throw new Exception(
0667: "[SQLRequirement->updateParent] data entry are not valid");
0668: }
0669: if (idParent == idReq) {
0670: throw new Exception(
0671: "[SQLRequirement->updateParent] data entry are not valid parent equals req");
0672: }
0673: try {
0674: transNumber = SQLWrapper.beginTransaction();
0675: PreparedStatement prep = SQLWrapper
0676: .getSQLUpdateQuery("updateReqParent");
0677: prep.setInt(1, idParent);
0678: prep.setInt(2, idReq);
0679: SQLWrapper.runUpdateQuery(prep);
0680: /* HISTORY */
0681: try {
0682: addHistory(idReq, idPersonne, HIST_UPDATE_PARENT, ""
0683: + idParent);
0684: } catch (Exception eH) {
0685:
0686: }
0687: SQLWrapper.commitTrans(transNumber);
0688: } catch (Exception e) {
0689: SQLWrapper.rollBackTrans(transNumber);
0690: throw e;
0691: }
0692: }
0693:
0694: public void deleteReq(int idReq) throws Exception {
0695: if (idReq < 0) {
0696: throw new Exception(
0697: "[SQLRequirement] data entry are not valid");
0698: }
0699: int transNumber = -1;
0700: try {
0701: transNumber = SQLWrapper.beginTransaction();
0702:
0703: ReqWrapper[] reqChild = getFistChildInReqFamily(idReq);
0704: int sizeChild = reqChild.length;
0705: for (int i = 0; i < sizeChild; i++) {
0706: ReqWrapper pReqWrapper = (ReqWrapper) reqChild[i];
0707: deleteReq(pReqWrapper.getIdBDD());
0708: }
0709:
0710: simpleDeleteReq(idReq);
0711: /*NO History because delete req*/
0712:
0713: SQLWrapper.commitTrans(transNumber);
0714: } catch (Exception e) {
0715: SQLWrapper.rollBackTrans(transNumber);
0716: throw e;
0717: }
0718: }
0719:
0720: protected void simpleDeleteReq(int idReq) throws Exception {
0721: //Delete LINK
0722: deleteAllReqCover(idReq);
0723:
0724: //Delete Action LINK
0725: deleteAllReqActionCover(idReq);
0726:
0727: //Delete Attachement
0728: deleteAllAttach(idReq);
0729:
0730: //Delete History
0731: deleteAllHistory(idReq);
0732:
0733: //Delete Reference
0734: deleteAllReference(idReq);
0735:
0736: //Delete Requirement
0737: PreparedStatement prep = SQLWrapper
0738: .getSQLDeleteQuery("deleteRequirement");
0739: prep.setInt(1, idReq);
0740: SQLWrapper.runDeleteQuery(prep);
0741:
0742: }
0743:
0744: public void deleteAllTestCover(int idTest) throws Exception {
0745: if (idTest < 1) {
0746: throw new Exception(
0747: "[SQLRequirement->deleteAllTestCover] entry data are not valid");
0748: }
0749: int transNumber = -1;
0750: try {
0751: transNumber = SQLWrapper.beginTransaction();
0752:
0753: /*DO History*/
0754: ReqWrapper[] reqConcerned = getReqCoveredByTest(idTest);
0755: int sizeConcerned = reqConcerned.length;
0756: for (int i = 0; i < sizeConcerned; i++) {
0757: ReqWrapper pReqWrapper = (ReqWrapper) reqConcerned[i];
0758: /* HISTORY */
0759: try {
0760: addHistory(pReqWrapper.getIdBDD(), idPersonne,
0761: HIST_DEL_COVER, "" + idTest);
0762: } catch (Exception eH) {
0763:
0764: }
0765: }
0766:
0767: PreparedStatement prep = SQLWrapper
0768: .getSQLDeleteQuery("deleteAllTestCover");
0769: prep.setInt(1, idTest);
0770: SQLWrapper.runDeleteQuery(prep);
0771:
0772: SQLWrapper.commitTrans(transNumber);
0773: } catch (Exception e) {
0774: SQLWrapper.rollBackTrans(transNumber);
0775: Util.log("[SQLTest->deleteAllTestCover]" + e);
0776: if (Api.isDEBUG()) {
0777: e.printStackTrace();
0778: }
0779: throw e;
0780: }
0781: }
0782:
0783: public void deleteAllReqCover(int idReq) throws Exception {
0784: if (idReq < 1) {
0785: throw new Exception(
0786: "[SQLRequirement->deteleAllReqCover] entry data are not valid");
0787: }
0788: int transNumber = -1;
0789: try {
0790: transNumber = SQLWrapper.beginTransaction();
0791:
0792: PreparedStatement prep = SQLWrapper
0793: .getSQLDeleteQuery("deleteAllReqCover");
0794: prep.setInt(1, idReq);
0795: SQLWrapper.runDeleteQuery(prep);
0796: /*NO History because delete req*/
0797:
0798: SQLWrapper.commitTrans(transNumber);
0799: } catch (Exception e) {
0800: SQLWrapper.rollBackTrans(transNumber);
0801: Util.log("[SQLTest->deteleAllReqCover]" + e);
0802: if (Api.isDEBUG()) {
0803: e.printStackTrace();
0804: }
0805: throw e;
0806: }
0807: }
0808:
0809: protected void deleteAllReqActionCover(int idReq) throws Exception {
0810: if (idReq < 1) {
0811: throw new Exception(
0812: "[SQLRequirement->deleteAllReqActionCover] entry data are not valid");
0813: }
0814: int transNumber = -1;
0815: try {
0816: transNumber = SQLWrapper.beginTransaction();
0817:
0818: PreparedStatement prep = SQLWrapper
0819: .getSQLDeleteQuery("deleteAllReqCoverAction");
0820: prep.setInt(1, idReq);
0821: SQLWrapper.runDeleteQuery(prep);
0822: /*NO History because delete req*/
0823:
0824: SQLWrapper.commitTrans(transNumber);
0825: } catch (Exception e) {
0826: SQLWrapper.rollBackTrans(transNumber);
0827: Util.log("[SQLTest->deleteAllReqActionCover]" + e);
0828: if (Api.isDEBUG()) {
0829: e.printStackTrace();
0830: }
0831: throw e;
0832: }
0833: }
0834:
0835: public void deleteCover(int idReq, int idTest) throws Exception {
0836: if (idReq < 1 || idTest < 1) {
0837: throw new Exception(
0838: "[SQLRequirement->deleteCover] entry data are not valid");
0839: }
0840: int transNumber = -1;
0841: try {
0842: transNumber = SQLWrapper.beginTransaction();
0843:
0844: PreparedStatement prep = SQLWrapper
0845: .getSQLDeleteQuery("deleteOneCover");
0846: prep.setInt(1, idTest);
0847: prep.setInt(2, idReq);
0848: SQLWrapper.runDeleteQuery(prep);
0849: /*DO History */
0850: try {
0851: addHistory(idReq, idPersonne, HIST_DEL_COVER, ""
0852: + idTest);
0853: } catch (Exception eH) {
0854:
0855: }
0856:
0857: SQLWrapper.commitTrans(transNumber);
0858: } catch (Exception e) {
0859: SQLWrapper.rollBackTrans(transNumber);
0860: Util.log("[SQLTest->deleteCover]" + e);
0861: if (Api.isDEBUG()) {
0862: e.printStackTrace();
0863: }
0864: throw e;
0865: }
0866: }
0867:
0868: /**
0869: * Delete all attachment in table (REQ_ATTACHEMENT and ATTACHEMENT) for the test
0870: * @param idReq : id of the requirement
0871: * @throws Exception
0872: * @see deleteAttach(int, int)
0873: * no permission needed
0874: */
0875: public void deleteAllAttach(int idReq) throws Exception {
0876: if (idReq < 1) {
0877: throw new Exception(
0878: "[SQLRequirement->deleteAllAttach] entry data are not valid");
0879: }
0880: int transNumber = -1;
0881: try {
0882: transNumber = SQLWrapper.beginTransaction();
0883: AttachementWrapper[] attachList = getAllAttachemnt(idReq);
0884:
0885: for (int i = 0; i < attachList.length; i++) {
0886: AttachementWrapper pAttachementWrapper = (AttachementWrapper) attachList[i];
0887: deleteAttach(idReq, pAttachementWrapper.getIdBDD(),
0888: false);
0889: }
0890: SQLWrapper.commitTrans(transNumber);
0891: } catch (Exception e) {
0892: SQLWrapper.rollBackTrans(transNumber);
0893: Util.log("[SQLTest->deleteAllAttach]" + e);
0894: if (Api.isDEBUG()) {
0895: e.printStackTrace();
0896: }
0897: throw e;
0898: }
0899: }
0900:
0901: /**
0902: * Delete attachement for the test and the attachement (tables REQ_ATTACHEMENT, ATTACHEMENT)
0903: * @param idReq : id of the requirement
0904: * @param attachId : id of the attachment
0905: * @throws Exception
0906: * @see ISQLAttachment.delete(int)
0907: * no permission needed
0908: */
0909: public void deleteAttach(int idReq, int attachId) throws Exception {
0910: deleteAttach(idReq, attachId, true);
0911: }
0912:
0913: protected void deleteAttach(int idReq, int attachId, boolean history)
0914: throws Exception {
0915: if (idReq < 1 || attachId < 1) {
0916: throw new Exception(
0917: "[SQLRequirement->deleteAttach] entry data are not valid");
0918: }
0919: int transNumber = -1;
0920: try {
0921: transNumber = SQLWrapper.beginTransaction();
0922:
0923: PreparedStatement prep = SQLWrapper
0924: .getSQLDeleteQuery("deleteAttachFromReq");
0925: prep.setInt(1, idReq);
0926: prep.setInt(2, attachId);
0927: SQLWrapper.runDeleteQuery(prep);
0928: if (history) {
0929: /*DO History */
0930: try {
0931: addHistory(idReq, idPersonne, HIST_DEL_ATTACH, ""
0932: + attachId);
0933: } catch (Exception eH) {
0934: }
0935: }
0936: Api.getISQLObjectFactory().getISQLAttachment().delete(
0937: attachId);
0938:
0939: SQLWrapper.commitTrans(transNumber);
0940: } catch (Exception e) {
0941: SQLWrapper.rollBackTrans(transNumber);
0942: Util.log("[SQLRequirement->deleteAttach]" + e);
0943: if (Api.isDEBUG()) {
0944: e.printStackTrace();
0945: }
0946: throw e;
0947: }
0948: }
0949:
0950: public ReqWrapper getReq(String name, int id_parent, int id_project)
0951: throws Exception {
0952: if (name == null || name.equals("")) {
0953: throw new Exception(
0954: "[SQLRequirement->getReq] data entry are not valid");
0955: }
0956: if (id_project < 0) {
0957: throw new Exception(
0958: "[SQLRequirement->getReq] data entry are not valid");
0959: }
0960:
0961: ReqWrapper pReqWrapper = null;
0962: int transNumber = -1;
0963: try {
0964: transNumber = SQLWrapper.beginTransaction();
0965: PreparedStatement prep = SQLWrapper
0966: .getSQLSelectQuery("selectRequirement");
0967: prep.setString(1, name);
0968: prep.setInt(2, id_parent);
0969: prep.setInt(3, id_project);
0970: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
0971: SQLWrapper.commitTrans(transNumber);
0972: transNumber = -1;
0973: if (stmtRes.next()) {
0974: pReqWrapper = new ReqWrapper();
0975: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
0976: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
0977: pReqWrapper.setName(stmtRes.getString("req_name"));
0978: pReqWrapper.setDescription(stmtRes
0979: .getString("req_description"));
0980: pReqWrapper.setParent_id(stmtRes
0981: .getInt("id_req_parent"));
0982: pReqWrapper.setType(stmtRes.getInt("req_type"));
0983: //FROM 1.2
0984: pReqWrapper.setPriority(stmtRes.getInt("priority"));
0985: pReqWrapper.setVersion(stmtRes.getString("version"));
0986: //FROM 1.3
0987: pReqWrapper.setCat(stmtRes.getInt("cat"));
0988: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
0989: pReqWrapper.setOrigine(stmtRes.getString("origine"));
0990: pReqWrapper.setState(stmtRes.getInt("state"));
0991: pReqWrapper.setVerif(stmtRes.getString("verif"));
0992: pReqWrapper
0993: .setReference(stmtRes.getString("reference"));
0994: }
0995:
0996: } catch (Exception e) {
0997: SQLWrapper.rollBackTrans(transNumber);
0998: Util.log("[SQLRequirement->getReq]" + e);
0999: if (Api.isDEBUG()) {
1000: e.printStackTrace();
1001: }
1002: throw e;
1003: }
1004: return pReqWrapper;
1005: }
1006:
1007: public ReqWrapper getReqById(int idReq) throws Exception {
1008: if (idReq < 0) {
1009: throw new Exception(
1010: "[SQLRequirement->getReqById] data entry are not valid");
1011: }
1012: ReqWrapper pReqWrapper = null;
1013: int transNumber = -1;
1014: try {
1015: transNumber = SQLWrapper.beginTransaction();
1016: PreparedStatement prep = SQLWrapper
1017: .getSQLSelectQuery("selectRequirementByID");
1018: prep.setInt(1, idReq);
1019: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1020: SQLWrapper.commitTrans(transNumber);
1021: transNumber = -1;
1022: if (stmtRes.next()) {
1023: pReqWrapper = new ReqWrapper();
1024: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1025: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1026: pReqWrapper.setName(stmtRes.getString("req_name"));
1027: pReqWrapper.setDescription(stmtRes
1028: .getString("req_description"));
1029: pReqWrapper.setParent_id(stmtRes
1030: .getInt("id_req_parent"));
1031: pReqWrapper.setType(stmtRes.getInt("req_type"));
1032: //FROM 1.2
1033: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1034: pReqWrapper.setVersion(stmtRes.getString("version"));
1035: //FROM 1.3
1036: pReqWrapper.setCat(stmtRes.getInt("cat"));
1037: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1038: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1039: pReqWrapper.setState(stmtRes.getInt("state"));
1040: pReqWrapper.setVerif(stmtRes.getString("verif"));
1041: pReqWrapper
1042: .setReference(stmtRes.getString("reference"));
1043: }
1044: } catch (Exception e) {
1045: SQLWrapper.rollBackTrans(transNumber);
1046: Util.log("[SQLRequirement->getReqById]" + e);
1047: if (Api.isDEBUG()) {
1048: e.printStackTrace();
1049: }
1050: throw e;
1051: }
1052: return pReqWrapper;
1053: }
1054:
1055: public ReqWrapper[] getProjectRequirements(int idProject)
1056: throws Exception {
1057: if (idProject < 0) {
1058: throw new Exception(
1059: "[SQLRequirement->getProjectRequirements] data entry are not valid");
1060: }
1061: Vector res = new Vector();
1062: int transNumber = -1;
1063: try {
1064: transNumber = SQLWrapper.beginTransaction();
1065: PreparedStatement prep = SQLWrapper
1066: .getSQLSelectQuery("selectAllRequirement");
1067: prep.setInt(1, idProject);
1068: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1069: SQLWrapper.commitTrans(transNumber);
1070: transNumber = -1;
1071: while (stmtRes.next()) {
1072: ReqWrapper pReqWrapper = new ReqWrapper();
1073: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1074: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1075: pReqWrapper.setName(stmtRes.getString("req_name"));
1076: pReqWrapper.setDescription(stmtRes
1077: .getString("req_description"));
1078: pReqWrapper.setParent_id(stmtRes
1079: .getInt("id_req_parent"));
1080: pReqWrapper.setType(stmtRes.getInt("req_type"));
1081: //FROM 1.2
1082: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1083: pReqWrapper.setVersion(stmtRes.getString("version"));
1084: //FROM 1.3
1085: pReqWrapper.setCat(stmtRes.getInt("cat"));
1086: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1087: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1088: pReqWrapper.setState(stmtRes.getInt("state"));
1089: pReqWrapper.setVerif(stmtRes.getString("verif"));
1090: pReqWrapper
1091: .setReference(stmtRes.getString("reference"));
1092: res.add(pReqWrapper);
1093: }
1094: } catch (Exception e) {
1095: SQLWrapper.rollBackTrans(transNumber);
1096: Util.log("[SQLRequirement->getProjectRequirements]" + e);
1097: if (Api.isDEBUG()) {
1098: e.printStackTrace();
1099: }
1100: throw e;
1101: }
1102:
1103: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1104: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1105: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1106: }
1107:
1108: return tmpArray;
1109: }
1110:
1111: public ReqWrapper[] getProjectRequirementByType(int idProject,
1112: int type) throws Exception {
1113: if (idProject < 0) {
1114: throw new Exception(
1115: "[SQLRequirement->getProjectRequirements] data entry are not valid");
1116: }
1117: Vector res = new Vector();
1118: int transNumber = -1;
1119: try {
1120: transNumber = SQLWrapper.beginTransaction();
1121: PreparedStatement prep = SQLWrapper
1122: .getSQLSelectQuery("selectAllRequirementByType");
1123: prep.setInt(1, idProject);
1124: prep.setInt(2, type);
1125: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1126: SQLWrapper.commitTrans(transNumber);
1127: transNumber = -1;
1128: while (stmtRes.next()) {
1129: ReqWrapper pReqWrapper = new ReqWrapper();
1130: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1131: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1132: pReqWrapper.setName(stmtRes.getString("req_name"));
1133: pReqWrapper.setDescription(stmtRes
1134: .getString("req_description"));
1135: pReqWrapper.setParent_id(stmtRes
1136: .getInt("id_req_parent"));
1137: pReqWrapper.setType(stmtRes.getInt("req_type"));
1138: //FROM 1.2
1139: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1140: pReqWrapper.setVersion(stmtRes.getString("version"));
1141: //FROM 1.3
1142: pReqWrapper.setCat(stmtRes.getInt("cat"));
1143: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1144: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1145: pReqWrapper.setState(stmtRes.getInt("state"));
1146: pReqWrapper.setVerif(stmtRes.getString("verif"));
1147: pReqWrapper
1148: .setReference(stmtRes.getString("reference"));
1149: res.add(pReqWrapper);
1150: }
1151: } catch (Exception e) {
1152: SQLWrapper.rollBackTrans(transNumber);
1153: Util.log("[SQLRequirement->getProjectRequirementByType]"
1154: + e);
1155: if (Api.isDEBUG()) {
1156: e.printStackTrace();
1157: }
1158: throw e;
1159: }
1160:
1161: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1162: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1163: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1164: }
1165:
1166: return tmpArray;
1167: }
1168:
1169: public ReqWrapper[] getFistChildInReqFamily(int idReq)
1170: throws Exception {
1171: if (idReq < 0) {
1172: throw new Exception(
1173: "[SQLRequirement->getFistChildInReqFamily] data entry are not valid");
1174: }
1175: Vector res = new Vector();
1176: int transNumber = -1;
1177: try {
1178: transNumber = SQLWrapper.beginTransaction();
1179: PreparedStatement prep = SQLWrapper
1180: .getSQLSelectQuery("selectRequirementsInFamily");
1181: prep.setInt(1, idReq);
1182: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1183: SQLWrapper.commitTrans(transNumber);
1184: transNumber = -1;
1185: while (stmtRes.next()) {
1186: ReqWrapper pReqWrapper = new ReqWrapper();
1187: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1188: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1189: pReqWrapper.setName(stmtRes.getString("req_name"));
1190: pReqWrapper.setDescription(stmtRes
1191: .getString("req_description"));
1192: pReqWrapper.setParent_id(stmtRes
1193: .getInt("id_req_parent"));
1194: pReqWrapper.setType(stmtRes.getInt("req_type"));
1195: //FROM 1.2
1196: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1197: pReqWrapper.setVersion(stmtRes.getString("version"));
1198: //FROM 1.3
1199: pReqWrapper.setCat(stmtRes.getInt("cat"));
1200: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1201: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1202: pReqWrapper.setState(stmtRes.getInt("state"));
1203: pReqWrapper.setVerif(stmtRes.getString("verif"));
1204: pReqWrapper
1205: .setReference(stmtRes.getString("reference"));
1206: res.add(pReqWrapper);
1207: }
1208: } catch (Exception e) {
1209: SQLWrapper.rollBackTrans(transNumber);
1210: Util.log("[SQLRequirement->getFistChildInReqFamily]" + e);
1211: if (Api.isDEBUG()) {
1212: e.printStackTrace();
1213: }
1214: throw e;
1215: }
1216:
1217: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1218: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1219: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1220: }
1221:
1222: return tmpArray;
1223: }
1224:
1225: public ReqWrapper[] getReqWrapperCoveredByCamp(int idCamp)
1226: throws Exception {
1227: if (idCamp < 0) {
1228: throw new Exception(
1229: "[SQLRequirement->getReqCoveredByTest] data entry are not valid");
1230: }
1231: Vector res = new Vector();
1232: int transNumber = -1;
1233: try {
1234: transNumber = SQLWrapper.beginTransaction();
1235: PreparedStatement prep = SQLWrapper
1236: .getSQLSelectQuery("selectRequirementsForCamp");
1237: prep.setInt(1, idCamp);
1238: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1239: SQLWrapper.commitTrans(transNumber);
1240: transNumber = -1;
1241: while (stmtRes.next()) {
1242: ReqWrapper pReqWrapper = new ReqWrapper();
1243: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1244: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1245: pReqWrapper.setName(stmtRes.getString("req_name"));
1246: pReqWrapper.setDescription(stmtRes
1247: .getString("req_description"));
1248: pReqWrapper.setParent_id(stmtRes
1249: .getInt("id_req_parent"));
1250: pReqWrapper.setType(stmtRes.getInt("req_type"));
1251: //FROM 1.2
1252: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1253: pReqWrapper.setVersion(stmtRes.getString("version"));
1254: //FROM 1.3
1255: pReqWrapper.setCat(stmtRes.getInt("cat"));
1256: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1257: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1258: pReqWrapper.setState(stmtRes.getInt("state"));
1259: pReqWrapper.setVerif(stmtRes.getString("verif"));
1260: pReqWrapper
1261: .setReference(stmtRes.getString("reference"));
1262: res.add(pReqWrapper);
1263: }
1264: } catch (Exception e) {
1265: SQLWrapper.rollBackTrans(transNumber);
1266: Util.log("[SQLRequirement->getReqCoveredByTest]" + e);
1267: if (Api.isDEBUG()) {
1268: e.printStackTrace();
1269: }
1270: throw e;
1271: }
1272:
1273: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1274: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1275: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1276: }
1277:
1278: return tmpArray;
1279: }
1280:
1281: public boolean isReqReqCoveredByTest(int idReq, int idTest)
1282: throws Exception {
1283: if (idTest < 0) {
1284: throw new Exception(
1285: "[SQLRequirement->isReqReqCoveredByTest] data entry are not valid");
1286: }
1287: if (idReq < 0) {
1288: throw new Exception(
1289: "[SQLRequirement->isReqReqCoveredByTest] data entry are not valid");
1290: }
1291: boolean res = false;
1292: int transNumber = -1;
1293: try {
1294: transNumber = SQLWrapper.beginTransaction();
1295: PreparedStatement prep = SQLWrapper
1296: .getSQLSelectQuery("selectTestRequirement");
1297: prep.setInt(1, idReq);
1298: prep.setInt(2, idTest);
1299: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1300:
1301: SQLWrapper.commitTrans(transNumber);
1302: transNumber = -1;
1303: if (stmtRes.next()) {
1304: res = true;
1305: }
1306:
1307: } catch (Exception e) {
1308: SQLWrapper.rollBackTrans(transNumber);
1309: Util.log("[SQLRequirement->isReqReqCoveredByTest]" + e);
1310: if (Api.isDEBUG()) {
1311: e.printStackTrace();
1312: }
1313: throw e;
1314: }
1315: return res;
1316: }
1317:
1318: public ReqWrapper[] getReqCoveredByTest(int idTest)
1319: throws Exception {
1320: if (idTest < 0) {
1321: throw new Exception(
1322: "[SQLRequirement->getReqCoveredByTest] data entry are not valid");
1323: }
1324: Vector res = new Vector();
1325: int transNumber = -1;
1326: try {
1327: transNumber = SQLWrapper.beginTransaction();
1328: PreparedStatement prep = SQLWrapper
1329: .getSQLSelectQuery("selectRequirementsForTest");
1330: prep.setInt(1, idTest);
1331: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1332: SQLWrapper.commitTrans(transNumber);
1333: transNumber = -1;
1334: while (stmtRes.next()) {
1335: ReqWrapper pReqWrapper = new ReqWrapper();
1336: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1337: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1338: pReqWrapper.setName(stmtRes.getString("req_name"));
1339: pReqWrapper.setDescription(stmtRes
1340: .getString("req_description"));
1341: pReqWrapper.setParent_id(stmtRes
1342: .getInt("id_req_parent"));
1343: pReqWrapper.setType(stmtRes.getInt("req_type"));
1344: //FROM 1.2
1345: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1346: pReqWrapper.setVersion(stmtRes.getString("version"));
1347: //FROM 1.3
1348: pReqWrapper.setCat(stmtRes.getInt("cat"));
1349: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1350: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1351: pReqWrapper.setState(stmtRes.getInt("state"));
1352: pReqWrapper.setVerif(stmtRes.getString("verif"));
1353: pReqWrapper
1354: .setReference(stmtRes.getString("reference"));
1355: res.add(pReqWrapper);
1356: }
1357: } catch (Exception e) {
1358: SQLWrapper.rollBackTrans(transNumber);
1359: Util.log("[SQLRequirement->getReqCoveredByTest]" + e);
1360: if (Api.isDEBUG()) {
1361: e.printStackTrace();
1362: }
1363: throw e;
1364: }
1365:
1366: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1367: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1368: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1369: }
1370:
1371: return tmpArray;
1372: }
1373:
1374: public ReqWrapper[] getCoveredReq(int idProject) throws Exception {
1375: if (idProject < 0) {
1376: throw new Exception(
1377: "[SQLRequirement->getCoveredReq] data entry are not valid");
1378: }
1379: Vector res = new Vector();
1380: int transNumber = -1;
1381: try {
1382: transNumber = SQLWrapper.beginTransaction();
1383: PreparedStatement prep = SQLWrapper
1384: .getSQLSelectQuery("selectReqCovered");
1385: prep.setInt(1, idProject);
1386: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1387: SQLWrapper.commitTrans(transNumber);
1388: transNumber = -1;
1389: while (stmtRes.next()) {
1390: ReqWrapper pReqWrapper = new ReqWrapper();
1391: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1392: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1393: pReqWrapper.setName(stmtRes.getString("req_name"));
1394: pReqWrapper.setDescription(stmtRes
1395: .getString("req_description"));
1396: pReqWrapper.setParent_id(stmtRes
1397: .getInt("id_req_parent"));
1398: pReqWrapper.setType(stmtRes.getInt("req_type"));
1399: //FROM 1.2
1400: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1401: pReqWrapper.setVersion(stmtRes.getString("version"));
1402: //FROM 1.3
1403: pReqWrapper.setCat(stmtRes.getInt("cat"));
1404: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1405: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1406: pReqWrapper.setState(stmtRes.getInt("state"));
1407: pReqWrapper.setVerif(stmtRes.getString("verif"));
1408: pReqWrapper
1409: .setReference(stmtRes.getString("reference"));
1410: res.add(pReqWrapper);
1411: }
1412: } catch (Exception e) {
1413: SQLWrapper.rollBackTrans(transNumber);
1414: Util.log("[SQLRequirement->getCoveredReq]" + e);
1415: if (Api.isDEBUG()) {
1416: e.printStackTrace();
1417: }
1418: throw e;
1419: }
1420:
1421: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1422: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1423: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1424: }
1425:
1426: return tmpArray;
1427: }
1428:
1429: public ReqWrapper[] getReqCoveredByResExecAndStatus(int idExec,
1430: String satus) throws Exception {
1431: if (idExec < 0) {
1432: throw new Exception(
1433: "[SQLRequirement->getReqCoveredByTest] data entry are not valid");
1434: }
1435: if (satus == null || satus.equals("")) {
1436: throw new Exception(
1437: "[SQLRequirement->getReqCoveredByTest] data entry are not valid");
1438: }
1439: Vector res = new Vector();
1440: int transNumber = -1;
1441: try {
1442: transNumber = SQLWrapper.beginTransaction();
1443: PreparedStatement prep = SQLWrapper
1444: .getSQLSelectQuery("selectStatusRequirementsForResExec");
1445: prep.setInt(1, idExec);
1446: prep.setString(2, satus);
1447: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1448: SQLWrapper.commitTrans(transNumber);
1449: transNumber = -1;
1450: while (stmtRes.next()) {
1451: ReqWrapper pReqWrapper = new ReqWrapper();
1452: pReqWrapper.setIdBDD(stmtRes.getInt("id_req"));
1453: pReqWrapper.setProject_id(stmtRes.getInt("id_project"));
1454: pReqWrapper.setName(stmtRes.getString("req_name"));
1455: pReqWrapper.setDescription(stmtRes
1456: .getString("req_description"));
1457: pReqWrapper.setParent_id(stmtRes
1458: .getInt("id_req_parent"));
1459: pReqWrapper.setType(stmtRes.getInt("req_type"));
1460: //FROM 1.2
1461: pReqWrapper.setPriority(stmtRes.getInt("priority"));
1462: pReqWrapper.setVersion(stmtRes.getString("version"));
1463: //FROM 1.3
1464: pReqWrapper.setCat(stmtRes.getInt("cat"));
1465: pReqWrapper.setComplexe(stmtRes.getInt("complexe"));
1466: pReqWrapper.setOrigine(stmtRes.getString("origine"));
1467: pReqWrapper.setState(stmtRes.getInt("state"));
1468: pReqWrapper.setVerif(stmtRes.getString("verif"));
1469: pReqWrapper
1470: .setReference(stmtRes.getString("reference"));
1471: res.add(pReqWrapper);
1472: }
1473: } catch (Exception e) {
1474: SQLWrapper.rollBackTrans(transNumber);
1475: Util
1476: .log("[SQLRequirement->getReqCoveredByResExecAndStatus]"
1477: + e);
1478: if (Api.isDEBUG()) {
1479: e.printStackTrace();
1480: }
1481: throw e;
1482: }
1483:
1484: ReqWrapper[] tmpArray = new ReqWrapper[res.size()];
1485: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1486: tmpArray[tmpI] = (ReqWrapper) res.get(tmpI);
1487: }
1488:
1489: return tmpArray;
1490: }
1491:
1492: public TestWrapper[] getTestCoveredForReq(int idReq)
1493: throws Exception {
1494: if (idReq < 0) {
1495: throw new Exception(
1496: "[SQLRequirement->getTestCoveredForReq] data entry are not valid");
1497: }
1498: Vector res = new Vector();
1499: int transNumber = -1;
1500: try {
1501: transNumber = SQLWrapper.beginTransaction();
1502: PreparedStatement prep = SQLWrapper
1503: .getSQLSelectQuery("selectTestCoveredReq");
1504: prep.setInt(1, idReq);
1505: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1506: SQLWrapper.commitTrans(transNumber);
1507: transNumber = -1;
1508: while (stmtRes.next()) {
1509: TestWrapper pTest = new TestWrapper();
1510: pTest.setName(stmtRes.getString("nom_cas"));
1511: pTest.setDescription(stmtRes
1512: .getString("description_cas"));
1513: pTest.setIdBDD(stmtRes.getInt("id_cas"));
1514: pTest.setOrder(stmtRes.getInt("ordre_cas"));
1515: pTest.setIdSuite(stmtRes.getInt("SUITE_TEST_id_suite"));
1516: pTest.setType(stmtRes.getString("type_cas"));
1517: res.add(pTest);
1518: }
1519: } catch (Exception e) {
1520: SQLWrapper.rollBackTrans(transNumber);
1521: Util.log("[SQLRequirement->getTestCoveredForReq]" + e);
1522: if (Api.isDEBUG()) {
1523: e.printStackTrace();
1524: }
1525: throw e;
1526: }
1527:
1528: TestWrapper[] tmpArray = new TestWrapper[res.size()];
1529: for (int tmpI = 0; tmpI < res.size(); tmpI++) {
1530: tmpArray[tmpI] = (TestWrapper) res.get(tmpI);
1531: }
1532:
1533: return tmpArray;
1534: }
1535:
1536: /**
1537: * Get a Vector of AttachementWrapper (FileAttachementWrapper, UrlAttachementWrapper)
1538: * for the requirement identified by idReq
1539: * @param idReq : id of the requirement
1540: * @return
1541: * @throws Exception
1542: */
1543: public AttachementWrapper[] getAllAttachemnt(int idReq)
1544: throws Exception {
1545: if (idReq < 1) {
1546: throw new Exception(
1547: "[SQLRequirement->getAllAttachemnt] entry data are not valid");
1548: }
1549: // Vector result = new Vector();
1550: //
1551: // Vector fileList = getAllAttachFiles(idReq);
1552: // Vector urlList = getAllAttachUrls(idReq);
1553: // result.addAll(fileList);
1554: // result.addAll(urlList);
1555:
1556: FileAttachementWrapper[] fileList = getAllAttachFiles(idReq);
1557: UrlAttachementWrapper[] urlList = getAllAttachUrls(idReq);
1558:
1559: AttachementWrapper[] result = new AttachementWrapper[fileList.length
1560: + urlList.length];
1561:
1562: for (int i = 0; i < fileList.length; i++) {
1563: result[i] = fileList[i];
1564: }
1565: for (int i = 0; i < urlList.length; i++) {
1566: result[fileList.length + i] = urlList[i];
1567: }
1568:
1569: return result;
1570: }
1571:
1572: /**
1573: * Get a Vector of FileAttachementWrapper for the requirement identified by idreq
1574: * @param idReq : id of the requirement
1575: * @return
1576: * @throws Exception
1577: */
1578: public FileAttachementWrapper[] getAllAttachFiles(int idReq)
1579: throws Exception {
1580: if (idReq < 1) {
1581: throw new Exception(
1582: "[SQLRequirement->getAllAttachFiles] entry data are not valid");
1583: }
1584: ArrayList<FileAttachementWrapper> result = new ArrayList<FileAttachementWrapper>();
1585: int transNumber = -1;
1586: try {
1587: transNumber = SQLWrapper.beginTransaction();
1588: PreparedStatement prep = SQLWrapper
1589: .getSQLSelectQuery("selectReqAttachFiles");
1590: prep.setInt(1, idReq);
1591: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1592: SQLWrapper.commitTrans(transNumber);
1593: transNumber = -1;
1594: while (stmtRes.next()) {
1595: FileAttachementWrapper fileAttach = new FileAttachementWrapper();
1596: fileAttach.setName(stmtRes.getString("nom_attach"));
1597: fileAttach.setLocalisation("");
1598: fileAttach.setDate(stmtRes.getDate("date_attachement"));
1599: fileAttach.setSize(new Long(stmtRes
1600: .getLong("taille_attachement")));
1601: fileAttach.setDescription(stmtRes
1602: .getString("description_attach"));
1603: fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
1604: result.add(fileAttach);
1605: }
1606: } catch (Exception e) {
1607: SQLWrapper.rollBackTrans(transNumber);
1608: Util.log("[SQLRequirement->getAllAttachFiles]" + e);
1609: if (Api.isDEBUG()) {
1610: e.printStackTrace();
1611: }
1612: throw e;
1613: }
1614:
1615: return result
1616: .toArray(new FileAttachementWrapper[result.size()]);
1617: /*FileAttachementWrapper[] tmpArray = new FileAttachementWrapper[result.size()];
1618: for(int tmpI = 0; tmpI < result.size(); tmpI++) {
1619: tmpArray[tmpI] = (FileAttachementWrapper) result.get(tmpI);
1620: }
1621:
1622: return tmpArray;*/
1623: }
1624:
1625: /**
1626: * Get a Vector of UrlAttachementWrapper for the requirement identified by idReq
1627: * @param idReq : id of the requirement
1628: * @return
1629: * @throws Exception
1630: */
1631: public UrlAttachementWrapper[] getAllAttachUrls(int idReq)
1632: throws Exception {
1633: if (idReq < 1) {
1634: throw new Exception(
1635: "[SQLRequirement->getAllAttachUrls] entry data are not valid");
1636: }
1637: Vector result = new Vector();
1638: int transNumber = -1;
1639: try {
1640: transNumber = SQLWrapper.beginTransaction();
1641: PreparedStatement prep = SQLWrapper
1642: .getSQLSelectQuery("selectReqAttachUrls");
1643: prep.setInt(1, idReq);
1644: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1645: SQLWrapper.commitTrans(transNumber);
1646: transNumber = -1;
1647: while (stmtRes.next()) {
1648: UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
1649: String url = stmtRes.getString("url_attach");
1650: // pUrlAttachment.setUrl(url);
1651: pUrlAttachment.setName(url);
1652: pUrlAttachment.setDescription(stmtRes
1653: .getString("description_attach"));
1654: ;
1655: pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
1656: result.addElement(pUrlAttachment);
1657: }
1658: } catch (Exception e) {
1659: SQLWrapper.rollBackTrans(transNumber);
1660: Util.log("[SQLRequirement->getAllAttachUrls]" + e);
1661: if (Api.isDEBUG()) {
1662: e.printStackTrace();
1663: }
1664: throw e;
1665: }
1666:
1667: UrlAttachementWrapper[] tmpArray = new UrlAttachementWrapper[result
1668: .size()];
1669: for (int tmpI = 0; tmpI < result.size(); tmpI++) {
1670: tmpArray[tmpI] = (UrlAttachementWrapper) result.get(tmpI);
1671: }
1672:
1673: return tmpArray;
1674: }
1675:
1676: public void deleteProjectReq(int idProject) throws Exception {
1677: if (idProject < 1) {
1678: throw new Exception(
1679: "[SQLRequirement->deleteProjectReq] entry data are not valid");
1680: }
1681: int transNumber = -1;
1682: try {
1683: transNumber = SQLWrapper.beginTransaction();
1684:
1685: /* ALL Reference test link */
1686: PreparedStatement prep = SQLWrapper
1687: .getSQLDeleteQuery("deleteAllProjectReq1");
1688: prep.setInt(1, idProject);
1689: SQLWrapper.runDeleteQuery(prep);
1690:
1691: /* ALL Reference attachement */
1692: prep = SQLWrapper.getSQLDeleteQuery("deleteAllProjectReq2");
1693: prep.setInt(1, idProject);
1694: SQLWrapper.runDeleteQuery(prep);
1695:
1696: /* ALL Reference action linlk */
1697: prep = SQLWrapper.getSQLDeleteQuery("deleteAllProjectReq4");
1698: prep.setInt(1, idProject);
1699: SQLWrapper.runDeleteQuery(prep);
1700:
1701: /* ALL Reference history */
1702: prep = SQLWrapper.getSQLDeleteQuery("deleteAllProjectReq5");
1703: prep.setInt(1, idProject);
1704: SQLWrapper.runDeleteQuery(prep);
1705:
1706: /* ALL Reference source */
1707: prep = SQLWrapper.getSQLDeleteQuery("deleteAllProjectReq6");
1708: prep.setInt(1, idProject);
1709: SQLWrapper.runDeleteQuery(prep);
1710:
1711: /* ALL Reference target */
1712: prep = SQLWrapper.getSQLDeleteQuery("deleteAllProjectReq7");
1713: prep.setInt(1, idProject);
1714: SQLWrapper.runDeleteQuery(prep);
1715:
1716: /* ALL Requirement */
1717: prep = SQLWrapper.getSQLDeleteQuery("deleteAllProjectReq3");
1718: prep.setInt(1, idProject);
1719: SQLWrapper.runDeleteQuery(prep);
1720:
1721: SQLWrapper.commitTrans(transNumber);
1722: } catch (Exception e) {
1723: SQLWrapper.rollBackTrans(transNumber);
1724: Util.log("[SQLRequirement->deleteProjectReq]" + e);
1725: if (Api.isDEBUG()) {
1726: e.printStackTrace();
1727: }
1728: throw e;
1729: }
1730: }
1731:
1732: /********************************** History *************************************************/
1733:
1734: protected void deleteAllHistory(int idReq) throws Exception {
1735: if (idReq < 1) {
1736: throw new Exception(
1737: "[SQLRequirement->deleteAllHistory] entry data are not valid");
1738: }
1739: int transNumber = -1;
1740: try {
1741: transNumber = SQLWrapper.beginTransaction();
1742:
1743: PreparedStatement prep = SQLWrapper
1744: .getSQLDeleteQuery("deleteAllHistory");
1745: prep.setInt(1, idReq);
1746: SQLWrapper.runDeleteQuery(prep);
1747:
1748: SQLWrapper.commitTrans(transNumber);
1749: } catch (Exception e) {
1750: SQLWrapper.rollBackTrans(transNumber);
1751: Util.log("[SQLTest->deleteAllHistory]" + e);
1752: if (Api.isDEBUG()) {
1753: e.printStackTrace();
1754: }
1755: throw e;
1756: }
1757: }
1758:
1759: protected void deleteAllReference(int idReq) throws Exception {
1760: if (idReq < 1) {
1761: throw new Exception(
1762: "[SQLRequirement->deleteAllReference] entry data are not valid");
1763: }
1764: int transNumber = -1;
1765: try {
1766: transNumber = SQLWrapper.beginTransaction();
1767:
1768: PreparedStatement prep = SQLWrapper
1769: .getSQLDeleteQuery("deleteAllReferenceSource");
1770: prep.setInt(1, idReq);
1771: SQLWrapper.runDeleteQuery(prep);
1772:
1773: prep = SQLWrapper
1774: .getSQLDeleteQuery("deleteAllReferenceTarget");
1775: prep.setInt(1, idReq);
1776: SQLWrapper.runDeleteQuery(prep);
1777:
1778: SQLWrapper.commitTrans(transNumber);
1779: } catch (Exception e) {
1780: SQLWrapper.rollBackTrans(transNumber);
1781: Util.log("[SQLTest->deleteAllHistory]" + e);
1782: if (Api.isDEBUG()) {
1783: e.printStackTrace();
1784: }
1785: throw e;
1786: }
1787: }
1788:
1789: /**
1790: * Add History when a requiremnt change (create, update, deleted)
1791: * @param idReq
1792: * @param idUser
1793: * @param code
1794: * @param valeur
1795: */
1796: protected void addHistory(int idReq, int idUser, int code,
1797: String valeur) throws Exception {
1798: if (idReq < 1 || code < 0) {
1799: throw new Exception(
1800: "[SQLRequirement->addHistory] entry data are not valid");
1801: }
1802: int transNumber = -1;
1803: try {
1804: transNumber = SQLWrapper.beginTransaction();
1805:
1806: PreparedStatement prep = SQLWrapper
1807: .getSQLAddQuery("addReqHistory");
1808: prep.setInt(1, idReq);
1809: prep.setInt(2, idUser);
1810: prep.setDate(3, getCurrentDate());
1811: prep.setInt(4, code);
1812: prep.setString(5, valeur);
1813:
1814: SQLWrapper.runAddQuery(prep);
1815:
1816: SQLWrapper.commitTrans(transNumber);
1817: } catch (Exception e) {
1818: SQLWrapper.rollBackTrans(transNumber);
1819: Util.log("[SQLRequirement->addHistory]" + e);
1820: if (Api.isDEBUG()) {
1821: e.printStackTrace();
1822: }
1823: throw e;
1824: }
1825: }
1826:
1827: public HistoryWrapper[] getHistory(int idReq) throws Exception {
1828: ArrayList<HistoryWrapper> result = new ArrayList<HistoryWrapper>();
1829: int transNumber = -1;
1830: try {
1831: transNumber = SQLWrapper.beginTransaction();
1832: PreparedStatement prep = SQLWrapper
1833: .getSQLSelectQuery("selectReqHistory");
1834: prep.setInt(1, idReq);
1835: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
1836: SQLWrapper.commitTrans(transNumber);
1837: transNumber = -1;
1838: while (stmtRes.next()) {
1839: int code = stmtRes.getInt("code");
1840: int idUser = stmtRes.getInt("PERSONNE_id_personne");
1841: Date date = stmtRes.getDate("date");
1842: String valeur = stmtRes.getString("valeur");
1843: HistoryWrapper history = new HistoryWrapper(idReq,
1844: code, idUser, date, valeur);
1845: result.add(history);
1846: }
1847: } catch (Exception e) {
1848: SQLWrapper.rollBackTrans(transNumber);
1849: Util.log("[SQLRequirement->getAllAttachFiles]" + e);
1850: if (Api.isDEBUG()) {
1851: e.printStackTrace();
1852: }
1853: throw e;
1854: }
1855: //HistoryWrapper[] ret;
1856: return result.toArray(new HistoryWrapper[result.size()]);
1857: }
1858:
1859: protected Date getCurrentDate() {
1860: Calendar calendar = new GregorianCalendar();
1861: int year = calendar.get(Calendar.YEAR);
1862: int month = calendar.get(Calendar.MONTH) + 1;
1863: int day = calendar.get(Calendar.DAY_OF_MONTH);
1864: String chaineDateActuelle = year + "-" + month + "-" + day;
1865: Date dateActuelle = Date.valueOf(chaineDateActuelle);
1866: return dateActuelle;
1867: }
1868: }
|