0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.databaseSQL;
0025:
0026: import java.net.URL;
0027: import java.sql.PreparedStatement;
0028: import java.sql.ResultSet;
0029: import java.util.Vector;
0030:
0031: import org.objectweb.salome_tmf.api.Api;
0032: import org.objectweb.salome_tmf.api.ApiConstants;
0033: import org.objectweb.salome_tmf.api.Permission;
0034: import org.objectweb.salome_tmf.api.Util;
0035: import org.objectweb.salome_tmf.api.data.AttachementWrapper;
0036: import org.objectweb.salome_tmf.api.data.CampaignWrapper;
0037: import org.objectweb.salome_tmf.api.data.DataSetWrapper;
0038: import org.objectweb.salome_tmf.api.data.DataWrapper;
0039: import org.objectweb.salome_tmf.api.data.ExecutionAttachmentWrapper;
0040: import org.objectweb.salome_tmf.api.data.ExecutionWrapper;
0041: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
0042: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
0043: import org.objectweb.salome_tmf.api.data.SuiteWrapper;
0044: import org.objectweb.salome_tmf.api.data.TestCampWrapper;
0045: import org.objectweb.salome_tmf.api.data.TestWrapper;
0046: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
0047: import org.objectweb.salome_tmf.api.sql.ISQLCampaign;
0048:
0049: public class SQLCampaign implements ISQLCampaign {
0050:
0051: /**
0052: * Inset a campaign in table CAMPAGNE_TEST
0053: * @param idProject : id of the projet where to insert the campaign
0054: * @param name of the campaign
0055: * @param description of the campaign
0056: * @param idPers : id of the user who insert the campaign
0057: * @return the id (id_camp) of new campaign
0058: * @throws Exception
0059: * need permission canCreateCamp
0060: */
0061: public int insert(int idProject, String name, String description,
0062: int idPers) throws Exception {
0063: int idCamp = -1;
0064: int transNumber = -1;
0065: if (!SQLEngine.specialAllow) {
0066: if (!(Permission.canCreateCamp())) {
0067: throw new SecurityException(
0068: "[SQLCampaign : insert -> canCreateCamp]");
0069: }
0070: }
0071: if (idProject < 1) {
0072: throw new Exception(
0073: "[SQLCampaign->insert] project have no id");
0074: }
0075: try {
0076: transNumber = SQLEngine.beginTransaction(10,
0077: ApiConstants.INSERT_CAMPAIGN);
0078: int nbTestCamp = -1;
0079: nbTestCamp = getNumberOfCampaign(idProject);
0080:
0081: PreparedStatement prep = SQLEngine
0082: .getSQLAddQuery("addCampaign"); //ok
0083: prep.setString(1, name);
0084: prep.setDate(2, Util.getCurrentDate());
0085: prep.setTime(3, Util.getCurrentTime());
0086: prep.setString(4, description);
0087: prep.setInt(5, idPers);
0088: prep.setInt(6, idProject);
0089: prep.setInt(7, nbTestCamp); //because order index begin at 0
0090: SQLEngine.runAddQuery(prep);
0091:
0092: idCamp = getID(idProject, name);
0093: if (idCamp < 1) {
0094: throw new Exception(
0095: "[SQLCampaign : insert -> campaign have no id]");
0096: }
0097: SQLEngine.commitTrans(transNumber);
0098: } catch (Exception e) {
0099: Util.log("[SQLCampaign->insert]" + e);
0100: if (Api.isDEBUG()) {
0101: e.printStackTrace();
0102: }
0103: SQLEngine.rollBackTrans(transNumber);
0104: throw e;
0105: }
0106: return idCamp;
0107:
0108: }
0109:
0110: /**
0111: * Import a test identified by idTest (in table CAS_TEST) in the campaign identified by idCamp
0112: * in table CAMPAGNE_CAS
0113: * @param idCamp
0114: * @param idTest
0115: * @return the order of the test in the campaign
0116: * @throws Exception
0117: * need permission canCreateCamp
0118: */
0119: public int importTest(int idCamp, int idTest, int userID)
0120: throws Exception {
0121: int transNumber = -1;
0122: int order = -1;
0123: if (!SQLEngine.specialAllow) {
0124: if (!(Permission.canUpdateCamp())) {
0125: throw new SecurityException(
0126: "[SQLCampaign : importTest -> canCreateCamp]");
0127: }
0128: }
0129: if (idCamp < 1 || idTest < 1) {
0130: throw new Exception(
0131: "[SQLCampaign->importTest] entry data are not valid");
0132: }
0133:
0134: try {
0135: transNumber = SQLEngine.beginTransaction(110,
0136: ApiConstants.INSERT_TEST_INTO_CAMPAIGN);
0137: order = getNumberOfTestInCampaign(idCamp);
0138:
0139: PreparedStatement prep = SQLEngine
0140: .getSQLAddQuery("addTestToCamp"); //ok
0141: prep.setInt(1, idCamp);
0142: prep.setInt(2, idTest);
0143: prep.setInt(3, order);//because order index begin at 0
0144: prep.setInt(4, userID);
0145: SQLEngine.runAddQuery(prep);
0146:
0147: SQLEngine.commitTrans(transNumber);
0148: } catch (Exception e) {
0149: Util.log("[SQLCampaign->importTest]" + e);
0150: if (Api.isDEBUG()) {
0151: e.printStackTrace();
0152: }
0153: SQLEngine.rollBackTrans(transNumber);
0154: throw e;
0155: }
0156: return order;
0157: }
0158:
0159: /**
0160: * Attach a file to a campaign identified by idCamp (table CAMPAGNE_ATTACHEMENT)
0161: * @param idCamp
0162: * @param file : the file to insert in the database
0163: * @param description
0164: * @return the id of the attachement in the table ATTACHEMENT
0165: * @throws Exception
0166: * @see ISQLFileAttachment.insert(File, String)
0167: * no permission needed
0168: */
0169: public int addAttachFile(int idCamp, SalomeFileWrapper file,
0170: String description) throws Exception {
0171: int transNumber = -1;
0172: int idAttach = -1;
0173: if (idCamp < 1 || file == null) {
0174: throw new Exception(
0175: "[SQLCampaign->addAttachFile] entry data are not valid");
0176: }
0177: try {
0178: transNumber = SQLEngine.beginTransaction(10,
0179: ApiConstants.INSERT_ATTACHMENT);
0180: idAttach = SQLObjectFactory
0181: .getInstanceOfISQLFileAttachment().insert(file,
0182: description);
0183:
0184: PreparedStatement prep = SQLEngine
0185: .getSQLAddQuery("addFileAttachToCampaign"); //ok
0186: prep.setInt(1, idCamp);
0187: prep.setInt(2, idAttach);
0188: SQLEngine.runAddQuery(prep);
0189:
0190: SQLEngine.commitTrans(transNumber);
0191: } catch (Exception e) {
0192: Util.log("[SQLCampaign->addAttachFile]" + e);
0193: if (Api.isDEBUG()) {
0194: e.printStackTrace();
0195: }
0196: SQLEngine.rollBackTrans(transNumber);
0197: throw e;
0198: }
0199: return idAttach;
0200: }
0201:
0202: /**
0203: * Attach a URL to a campaign identified by idCamp (table CAMPAGNE_ATTACHEMENT)
0204: * @param idCamp
0205: * @param url : the url to insert in the database
0206: * @param description
0207: * @return the id of the attachement in the table ATTACHEMENT
0208: * @throws Exception
0209: * @see ISQLUrlAttachment.insert(String String)
0210: * no permission needed
0211: */
0212: public int addAttachUrl(int idCamp, String url, String description)
0213: throws Exception {
0214: int transNumber = -1;
0215: int idAttach = -1;
0216: if (idCamp < 1 || url == null) {
0217: throw new Exception(
0218: "[SQLCampaign->addAttachUrl] entry data are not valid");
0219: }
0220: try {
0221: transNumber = SQLEngine.beginTransaction(10,
0222: ApiConstants.INSERT_ATTACHMENT);
0223: idAttach = SQLObjectFactory
0224: .getInstanceOfISQLUrlAttachment().insert(url,
0225: description);
0226:
0227: PreparedStatement prep = SQLEngine
0228: .getSQLAddQuery("addUrlAttachToCampaign"); //ok
0229: prep.setInt(1, idCamp);
0230: prep.setInt(2, idAttach);
0231: SQLEngine.runAddQuery(prep);
0232:
0233: SQLEngine.commitTrans(transNumber);
0234: } catch (Exception e) {
0235: Util.log("[SQLCampaign->addAttachUrl]" + e);
0236: if (Api.isDEBUG()) {
0237: e.printStackTrace();
0238: }
0239: SQLEngine.rollBackTrans(transNumber);
0240: throw e;
0241: }
0242:
0243: return idAttach;
0244: }
0245:
0246: /**
0247: * Update the name and the description of the campaign identified by idCamp
0248: * @param idCamp of the campaign
0249: * @param name : new name of the campaign
0250: * @param description : new description of the campaign
0251: * @throws Exception
0252: * need permission canUpdateCamp
0253: */
0254: public void update(int idCamp, String name, String description)
0255: throws Exception {
0256: int transNumber = -1;
0257: if (!SQLEngine.specialAllow) {
0258: if (!(Permission.canUpdateCamp())) {
0259: throw new SecurityException(
0260: "[SQLCampaign : update -> canUpdateCamp]");
0261: }
0262: }
0263: if (idCamp < 1) {
0264: throw new Exception(
0265: "[SQLCampaign->update] entry data are not valid");
0266: }
0267: try {
0268: transNumber = SQLEngine.beginTransaction(10,
0269: ApiConstants.UPDATE_CAMPAIGN);
0270: PreparedStatement prep = SQLEngine
0271: .getSQLUpdateQuery("updateCampaign"); //ok
0272: prep.setString(1, name);
0273: prep.setString(2, description);
0274: prep.setInt(3, idCamp);
0275: SQLEngine.runUpdateQuery(prep);
0276:
0277: SQLEngine.commitTrans(transNumber);
0278: } catch (Exception e) {
0279: Util.log("[SQLCampaign->update]" + e);
0280: if (Api.isDEBUG()) {
0281: e.printStackTrace();
0282: }
0283: SQLEngine.rollBackTrans(transNumber);
0284: throw e;
0285: }
0286: }
0287:
0288: void updateOrder(int idCamp, int order) throws Exception {
0289: int transNumber = -1;
0290: if (idCamp < 1 || order < 0) {
0291: throw new Exception(
0292: "[SQLCampaign->updateOrder] entry data are not valid");
0293: }
0294: try {
0295: transNumber = SQLEngine.beginTransaction(10,
0296: ApiConstants.UPDATE_CAMPAIGN);
0297:
0298: PreparedStatement prep = SQLEngine
0299: .getSQLUpdateQuery("updateCampaignOrder"); //ok
0300: prep.setInt(1, order);
0301: prep.setInt(2, idCamp);
0302: SQLEngine.runUpdateQuery(prep);
0303:
0304: SQLEngine.commitTrans(transNumber);
0305: } catch (Exception e) {
0306: Util.log("[SQLCampaign->updateOrder]" + e);
0307: if (Api.isDEBUG()) {
0308: e.printStackTrace();
0309: }
0310: SQLEngine.rollBackTrans(transNumber);
0311: throw e;
0312: }
0313: }
0314:
0315: /**
0316: * Update the order of the campaign by incrementation (if increment = true) or decrementation
0317: * @param idCamp : id of the campaign
0318: * @param increment
0319: * @return
0320: * @throws Exception
0321: * need permission canUpdateCamp or canExecutCamp
0322: */
0323: public int updateOrder(int idCamp, boolean increment)
0324: throws Exception {
0325: int transNumber = -1;
0326: int orderIndex = -1;
0327: if (idCamp < 1) {
0328: throw new Exception(
0329: "[SQLCampaign->updateOrder] entry data are not valid");
0330: }
0331: if (!SQLEngine.specialAllow) {
0332: if (!(Permission.canUpdateCamp() || Permission
0333: .canExecutCamp())) {
0334: throw new SecurityException(
0335: "[SQLCampaign : updateOrder -> canUpdateCamp]");
0336: }
0337: }
0338: try {
0339: transNumber = SQLEngine.beginTransaction(10,
0340: ApiConstants.UPDATE_CAMPAIGN);
0341:
0342: CampaignWrapper pCamp = getCampaign(idCamp);
0343: orderIndex = pCamp.getOrder();
0344: if (increment) {
0345: int maxOrder = getNumberOfCampaign(pCamp.getIdProject());
0346: maxOrder--; //because order index begin at 0
0347: if (orderIndex < maxOrder) {
0348: CampaignWrapper pCamp2 = getCampaignByOrder(pCamp
0349: .getIdProject(), orderIndex + 1);
0350: updateOrder(idCamp, orderIndex + 1);
0351: updateOrder(pCamp2.getIdBDD(), orderIndex);
0352: orderIndex++;
0353: }
0354: } else {
0355: if (orderIndex > 0) {
0356: CampaignWrapper pCamp2 = getCampaignByOrder(pCamp
0357: .getIdProject(), orderIndex - 1);
0358: updateOrder(idCamp, orderIndex - 1);
0359: updateOrder(pCamp2.getIdBDD(), orderIndex);
0360: orderIndex--;
0361: }
0362: }
0363:
0364: SQLEngine.commitTrans(transNumber);
0365: } catch (Exception e) {
0366: Util.log("[SQLCampaign->updateOrder]" + e);
0367: if (Api.isDEBUG()) {
0368: e.printStackTrace();
0369: }
0370: SQLEngine.rollBackTrans(transNumber);
0371: throw e;
0372: }
0373: return orderIndex;
0374: }
0375:
0376: void updateTestOrder(int idCamp, int idTest, int order)
0377: throws Exception {
0378: int transNumber = -1;
0379: if (idCamp < 1 || idTest < 1 || order < 0) {
0380: throw new Exception(
0381: "[SQLCampaign->updateTestOrder] entry data are not valid");
0382: }
0383: try {
0384: transNumber = SQLEngine.beginTransaction(10,
0385: ApiConstants.UPDATE_CAMPAIGN);
0386:
0387: PreparedStatement prep = SQLEngine
0388: .getSQLUpdateQuery("updateTestCampaignOrder"); //ok
0389: prep.setInt(1, order);
0390: prep.setInt(2, idCamp);
0391: prep.setInt(3, idTest);
0392: SQLEngine.runUpdateQuery(prep);
0393:
0394: SQLEngine.commitTrans(transNumber);
0395: } catch (Exception e) {
0396: Util.log("[SQLCampaign->updateTestOrder]" + e);
0397: if (Api.isDEBUG()) {
0398: e.printStackTrace();
0399: }
0400: SQLEngine.rollBackTrans(transNumber);
0401: throw e;
0402: }
0403: }
0404:
0405: /**
0406: * replace all reference of user oldIdUser by newIdUser in the table (CAMPAGNE_CAS) whrerre campagne = idCamp
0407: * @param oldIdUser
0408: * @param newIdUser
0409: * @throws Exception
0410: * no permission needed
0411: */
0412: public void updateUserRef(int idCamp, int oldIdUser, int newIdUser)
0413: throws Exception {
0414: int transNumber = -1;
0415: if (idCamp < 1 || oldIdUser < 1 || newIdUser < 1) {
0416: throw new Exception(
0417: "[SQLCampaign->updateUserRef] entry data are not valid");
0418: }
0419: try {
0420: transNumber = SQLEngine.beginTransaction(10,
0421: ApiConstants.UPDATE_CAMPAIGN);
0422:
0423: PreparedStatement prep = SQLEngine
0424: .getSQLUpdateQuery("updateCampagneUser"); //OK
0425: prep.setInt(1, newIdUser);
0426: prep.setInt(2, oldIdUser);
0427: prep.setInt(3, idCamp);
0428: SQLEngine.runUpdateQuery(prep);
0429:
0430: SQLEngine.commitTrans(transNumber);
0431: } catch (Exception e) {
0432: Util.log("[SQLCampaign->updateUserRef]" + e);
0433: if (Api.isDEBUG()) {
0434: e.printStackTrace();
0435: }
0436: SQLEngine.rollBackTrans(transNumber);
0437: throw e;
0438: }
0439: }
0440:
0441: /**
0442: * Update test suite order in the campaign (+1 if increment = true) or -1
0443: * @param idCamp : id of the campaign
0444: * @param idSuite : id of the suite in table SUITE_TEST
0445: * @param increment
0446: * @throws Exception
0447: * need permission canUpdateCamp or canExecutCamp
0448: */
0449: public void updateTestSuiteOrder(int idCamp, int idSuite,
0450: boolean increment) throws Exception {
0451: int transNumber = -1;
0452: if (idCamp < 1 || idSuite < 1) {
0453: throw new Exception(
0454: "[SQLCampaign->updateTestSuiteOrder] entry data are not valid");
0455: }
0456: if (!SQLEngine.specialAllow) {
0457: if (!(Permission.canUpdateCamp() || Permission
0458: .canExecutCamp())) {
0459: throw new SecurityException(
0460: "[SQLCampaign : updateTestSuiteOrder -> canUpdateCamp]");
0461: }
0462: }
0463: try {
0464: transNumber = SQLEngine.beginTransaction(10,
0465: ApiConstants.UPDATE_CAMPAIGN);
0466:
0467: TestCampWrapper pLastInSuite = getInCampaignLastTestInSuite(
0468: idCamp, idSuite);
0469: TestCampWrapper pFirstInSuite = getInCampaignFirstTestInSuite(
0470: idCamp, idSuite);
0471: int firstorder = pFirstInSuite.getOrder();
0472: int lastorder = pLastInSuite.getOrder();
0473: int nbTesttoMove = (lastorder - firstorder) + 1;
0474: if (increment) { //desc
0475: TestCampWrapper pFirstInSuite2 = getTestCampByOrder(
0476: idCamp, lastorder + 1);
0477: TestWrapper pTest = SQLObjectFactory
0478: .getInstanceOfISQLTest().getTest(
0479: pFirstInSuite2.getIdBDD());
0480: int size = getSizeOfSuiteInCampaign(idCamp, pTest
0481: .getIdSuite());
0482:
0483: int tmpOrder = lastorder;
0484: for (int i = 0; i < nbTesttoMove; i++) {
0485: int idTest = getTestCampByOrder(idCamp, tmpOrder)
0486: .getIdBDD();
0487: for (int j = 0; j < size; j++) {
0488: updateTestOrder(idCamp, idTest, true);
0489: }
0490: tmpOrder--;
0491: }
0492: } else { //mont
0493: TestCampWrapper pLastInSuite2 = getTestCampByOrder(
0494: idCamp, firstorder - 1);
0495: TestWrapper pTest = SQLObjectFactory
0496: .getInstanceOfISQLTest().getTest(
0497: pLastInSuite2.getIdBDD());
0498: int size = getSizeOfSuiteInCampaign(idCamp, pTest
0499: .getIdSuite());
0500:
0501: int tmpOrder = firstorder;
0502: for (int i = 0; i < nbTesttoMove; i++) {
0503: int idTest = getTestCampByOrder(idCamp, tmpOrder)
0504: .getIdBDD();
0505: for (int j = 0; j < size; j++) {
0506: updateTestOrder(idCamp, idTest, false);
0507: }
0508: tmpOrder++;
0509: }
0510: }
0511: SQLEngine.commitTrans(transNumber);
0512: } catch (Exception e) {
0513: Util.log("[SQLCampaign->updateTestSuiteOrder]" + e);
0514: if (Api.isDEBUG()) {
0515: e.printStackTrace();
0516: }
0517: SQLEngine.rollBackTrans(transNumber);
0518: throw e;
0519: }
0520: }
0521:
0522: /**
0523: * Update a family order in the campaign (+1 if increment = true) or -1
0524: * @param idCamp
0525: * @param idFamily : id of the suite in table FAMILLE_TEST
0526: * @param increment
0527: * @throws Exception
0528: * need permission canUpdateCamp or canExecutCamp
0529: */
0530: public void updateTestFamilyOrder(int idCamp, int idFamily,
0531: boolean increment) throws Exception {
0532: int transNumber = -1;
0533: if (idCamp < 1 || idFamily < 1) {
0534: throw new Exception(
0535: "[SQLCampaign->updateTestFamilyOrder] entry data are not valid");
0536: }
0537: if (!SQLEngine.specialAllow) {
0538: if (!(Permission.canUpdateCamp() || Permission
0539: .canExecutCamp())) {
0540: throw new SecurityException(
0541: "[SQLCampaign : updateTestFamilyOrder -> canUpdateCamp]");
0542: }
0543: }
0544: try {
0545: transNumber = SQLEngine.beginTransaction(10,
0546: ApiConstants.UPDATE_CAMPAIGN);
0547:
0548: TestCampWrapper pLastInSuite = getInCampaignLastTestInFamily(
0549: idCamp, idFamily);
0550: TestCampWrapper pFirstInSuite = getInCampaignFirstTestInFamily(
0551: idCamp, idFamily);
0552: int firstorder = pFirstInSuite.getOrder();
0553: int lastorder = pLastInSuite.getOrder();
0554: int nbTesttoMove = (lastorder - firstorder) + 1;
0555: if (increment) { //desc
0556: TestCampWrapper pFirstInSuite2 = getTestCampByOrder(
0557: idCamp, lastorder + 1);
0558: TestWrapper pTest = SQLObjectFactory
0559: .getInstanceOfISQLTest().getTest(
0560: pFirstInSuite2.getIdBDD());
0561: SuiteWrapper pSuite = SQLObjectFactory
0562: .getInstanceOfISQLTestList().getTestList(
0563: pTest.getIdSuite());
0564: int size = getSizeOfFamilyInCampaign(idCamp, pSuite
0565: .getIdFamille());
0566: int tmpOrder = lastorder;
0567: for (int i = 0; i < nbTesttoMove; i++) {
0568: int idTest = getTestCampByOrder(idCamp, tmpOrder)
0569: .getIdBDD();
0570: for (int j = 0; j < size; j++) {
0571: updateTestOrder(idCamp, idTest, true);
0572: }
0573: tmpOrder--;
0574: }
0575: } else { //mont
0576: TestCampWrapper pLastInSuite2 = getTestCampByOrder(
0577: idCamp, firstorder - 1);
0578: TestWrapper pTest = SQLObjectFactory
0579: .getInstanceOfISQLTest().getTest(
0580: pLastInSuite2.getIdBDD());
0581: SuiteWrapper pSuite = SQLObjectFactory
0582: .getInstanceOfISQLTestList().getTestList(
0583: pTest.getIdSuite());
0584: int size = getSizeOfFamilyInCampaign(idCamp, pSuite
0585: .getIdFamille());
0586: int tmpOrder = firstorder;
0587: for (int i = 0; i < nbTesttoMove; i++) {
0588: int idTest = getTestCampByOrder(idCamp, tmpOrder)
0589: .getIdBDD();
0590: for (int j = 0; j < size; j++) {
0591: updateTestOrder(idCamp, idTest, false);
0592: }
0593: tmpOrder++;
0594: }
0595:
0596: }
0597: SQLEngine.commitTrans(transNumber);
0598: } catch (Exception e) {
0599: Util.log("[SQLCampaign->updateTestFamilyOrder]" + e);
0600: if (Api.isDEBUG()) {
0601: e.printStackTrace();
0602: }
0603: SQLEngine.rollBackTrans(transNumber);
0604: throw e;
0605: }
0606: }
0607:
0608: /**
0609: * Update a test order in the campaign (+1 if increment = true) or -1
0610: * @param idCamp
0611: * @param idTest : id of the test in the table CAS_TEST
0612: * @param increment
0613: * @return
0614: * @throws Exception
0615: * need permission canUpdateCamp
0616: */
0617: public int updateTestOrder(int idCamp, int idTest, boolean increment)
0618: throws Exception {
0619: int transNumber = -1;
0620: if (idCamp < 1 || idTest < 1) {
0621: throw new Exception(
0622: "[SQLCampaign->updateTestOrder] entry data are not valid");
0623: }
0624: if (!SQLEngine.specialAllow) {
0625: if (!(Permission.canUpdateCamp())) {
0626: throw new SecurityException(
0627: "[SQLCampaign : updateTestOrder -> canUpdateCamp]");
0628: }
0629: }
0630: int orderIndex = -1;
0631: try {
0632: transNumber = SQLEngine.beginTransaction(10,
0633: ApiConstants.UPDATE_CAMPAIGN);
0634:
0635: TestCampWrapper pTestCas = getTestCampById(idCamp, idTest);
0636: orderIndex = pTestCas.getOrder();
0637: if (increment) {
0638: int maxOrder = getNumberOfTestInCampaign(idCamp);
0639: maxOrder--; //because order index begin at 0
0640: if (orderIndex < maxOrder) {
0641: TestCampWrapper pTestCas2 = getTestCampByOrder(
0642: idCamp, orderIndex + 1);
0643: updateTestOrder(idCamp, idTest, orderIndex + 1);
0644: updateTestOrder(idCamp, pTestCas2.getIdBDD(),
0645: orderIndex);
0646: orderIndex++;
0647: }
0648: } else {
0649: if (orderIndex > 0) {
0650: TestCampWrapper pTestCas2 = getTestCampByOrder(
0651: idCamp, orderIndex - 1);
0652: updateTestOrder(idCamp, idTest, orderIndex - 1);
0653: updateTestOrder(idCamp, pTestCas2.getIdBDD(),
0654: orderIndex);
0655: orderIndex--;
0656: }
0657: }
0658:
0659: SQLEngine.commitTrans(transNumber);
0660: } catch (Exception e) {
0661: Util.log("[SQLCampaign->updateTestOrder]" + e);
0662: if (Api.isDEBUG()) {
0663: e.printStackTrace();
0664: }
0665: SQLEngine.rollBackTrans(transNumber);
0666: throw e;
0667: }
0668: return orderIndex;
0669: }
0670:
0671: /**
0672: * Update test Assignation (field assigned_user_id) in CAMPAGNE_CAS
0673: * @param idCamp
0674: * @param idTest
0675: * @param assignedID
0676: * @return
0677: * @throws Exception
0678: */
0679: public void updateTestAssignation(int idCamp, int idTest,
0680: int assignedID) throws Exception {
0681: int transNumber = -1;
0682: if (idCamp < 1 || idTest < 1 || assignedID < 1) {
0683: throw new Exception(
0684: "[SQLCampaign->updateTestAssignation] entry data are not valid");
0685: }
0686: if (!SQLEngine.specialAllow) {
0687: if (!(Permission.canUpdateCamp())) {
0688: throw new SecurityException(
0689: "[SQLCampaign : updateTestAssignation -> canUpdateCamp]");
0690: }
0691: }
0692: try {
0693: transNumber = SQLEngine.beginTransaction(10,
0694: ApiConstants.UPDATE_CAMPAIGN);
0695:
0696: PreparedStatement prep = SQLEngine
0697: .getSQLUpdateQuery("updateAssignedTestInCampagne"); //OK
0698: prep.setInt(1, assignedID);
0699: prep.setInt(2, idCamp);
0700: prep.setInt(3, idTest);
0701: SQLEngine.runUpdateQuery(prep);
0702:
0703: SQLEngine.commitTrans(transNumber);
0704: } catch (Exception e) {
0705: Util.log("[SQLCampaign->updateTestAssignation]" + e);
0706: if (Api.isDEBUG()) {
0707: e.printStackTrace();
0708: }
0709: SQLEngine.rollBackTrans(transNumber);
0710: throw e;
0711: }
0712: }
0713:
0714: /**
0715: * Update Suite Assignation (field assigned_user_id for all tests in the suite) in CAMPAGNE_CAS
0716: * @param idCamp
0717: * @param idTest
0718: * @param assignedID
0719: * @return
0720: * @throws Exception
0721: */
0722: public void updateSuiteAssignation(int idCamp, int idSuite,
0723: int assignedID) throws Exception {
0724: int transNumber = -1;
0725: if (idCamp < 1 || idSuite < 1 || assignedID < 1) {
0726: throw new Exception(
0727: "[SQLCampaign->updateSuiteAssignation] entry data are not valid");
0728: }
0729: if (!SQLEngine.specialAllow) {
0730: if (!(Permission.canUpdateCamp())) {
0731: throw new SecurityException(
0732: "[SQLCampaign : updateSuiteAssignation -> canUpdateCamp]");
0733: }
0734: }
0735: try {
0736: transNumber = SQLEngine.beginTransaction(10,
0737: ApiConstants.UPDATE_CAMPAIGN);
0738:
0739: PreparedStatement prep = SQLEngine
0740: .getSQLUpdateQuery("updateAssignedSuiteInCampagne"); //OK
0741: prep.setInt(1, assignedID);
0742: prep.setInt(2, idCamp);
0743: prep.setInt(3, idSuite);
0744: SQLEngine.runUpdateQuery(prep);
0745:
0746: SQLEngine.commitTrans(transNumber);
0747: } catch (Exception e) {
0748: Util.log("[SQLCampaign->updateSuiteAssignation]" + e);
0749: if (Api.isDEBUG()) {
0750: e.printStackTrace();
0751: }
0752: SQLEngine.rollBackTrans(transNumber);
0753: throw e;
0754: }
0755: }
0756:
0757: /**
0758: * Update Suite Assignation (field assigned_user_id for all tests in the suite) in CAMPAGNE_CAS
0759: * @param idCamp
0760: * @param idTest
0761: * @param assignedID
0762: * @return
0763: * @throws Exception
0764: */
0765: public void updateFamilyAssignation(int idCamp, int idFamille,
0766: int assignedID) throws Exception {
0767: int transNumber = -1;
0768: if (idCamp < 1 || idFamille < 1 || assignedID < 1) {
0769: throw new Exception(
0770: "[SQLCampaign->updateFamilyAssignation] entry data are not valid");
0771: }
0772: if (!SQLEngine.specialAllow) {
0773: if (!(Permission.canUpdateCamp())) {
0774: throw new SecurityException(
0775: "[SQLCampaign : updateFamilyAssignation -> canUpdateCamp]");
0776: }
0777: }
0778: try {
0779: transNumber = SQLEngine.beginTransaction(10,
0780: ApiConstants.UPDATE_CAMPAIGN);
0781:
0782: PreparedStatement prep = SQLEngine
0783: .getSQLUpdateQuery("updateAssignedFamilyInCampagne"); //OK
0784: prep.setInt(1, assignedID);
0785: prep.setInt(2, idCamp);
0786: prep.setInt(3, idFamille);
0787: SQLEngine.runUpdateQuery(prep);
0788:
0789: SQLEngine.commitTrans(transNumber);
0790: } catch (Exception e) {
0791: Util.log("[SQLCampaign->updateFamilyAssignation]" + e);
0792: if (Api.isDEBUG()) {
0793: e.printStackTrace();
0794: }
0795: SQLEngine.rollBackTrans(transNumber);
0796: throw e;
0797: }
0798: }
0799:
0800: /**
0801: * Update test Assignation for all reference of old assignation (field assigned_user_id) in CAMPAGNE_CAS
0802: * @param idCamp
0803: * @param idTest
0804: * @param assignedID
0805: * @return
0806: * @throws Exception
0807: */
0808: public void updateTestAssignationRef(int idCamp, int assignedOldID,
0809: int assignedNewID) throws Exception {
0810: int transNumber = -1;
0811: if (idCamp < 1 || assignedOldID < 1 || assignedNewID < 1) {
0812: throw new Exception(
0813: "[SQLCampaign->updateTestAssignationRef] entry data are not valid");
0814: }
0815: if (!SQLEngine.specialAllow) {
0816: if (!(Permission.canUpdateCamp())) {
0817: throw new SecurityException(
0818: "[SQLCampaign : updateTestAssignationRef -> canUpdateCamp]");
0819: }
0820: }
0821: try {
0822: transNumber = SQLEngine.beginTransaction(10,
0823: ApiConstants.UPDATE_CAMPAIGN);
0824:
0825: PreparedStatement prep = SQLEngine
0826: .getSQLUpdateQuery("updateAllAssignedTestInCampagne"); //OK
0827: prep.setInt(1, assignedNewID);
0828: prep.setInt(2, idCamp);
0829: prep.setInt(3, assignedOldID);
0830: SQLEngine.runUpdateQuery(prep);
0831:
0832: SQLEngine.commitTrans(transNumber);
0833: } catch (Exception e) {
0834: Util.log("[SQLCampaign->updateTestAssignationRef]" + e);
0835: if (Api.isDEBUG()) {
0836: e.printStackTrace();
0837: }
0838: SQLEngine.rollBackTrans(transNumber);
0839: throw e;
0840: }
0841: }
0842:
0843: /**
0844: * Update All test Assignation (field assigned_user_id) in CAMPAGNE_CAS
0845: * @param idCamp
0846: * @param idTest
0847: * @param assignedID
0848: * @return
0849: * @throws Exception
0850: */
0851: public void updateCampagneAssignationRef(int idCamp,
0852: int assignedNewID) throws Exception {
0853: int transNumber = -1;
0854: if (idCamp < 1 || assignedNewID < 1) {
0855: throw new Exception(
0856: "[SQLCampaign->updateTestAssignationRef] entry data are not valid");
0857: }
0858: if (!SQLEngine.specialAllow) {
0859: if (!(Permission.canUpdateCamp())) {
0860: throw new SecurityException(
0861: "[SQLCampaign : updateCampagneAssignedTest -> canUpdateCamp]");
0862: }
0863: }
0864: try {
0865: transNumber = SQLEngine.beginTransaction(10,
0866: ApiConstants.UPDATE_CAMPAIGN);
0867:
0868: PreparedStatement prep = SQLEngine
0869: .getSQLUpdateQuery("updateCampagneAssignedTest"); //OK
0870: prep.setInt(1, assignedNewID);
0871: prep.setInt(2, idCamp);
0872: SQLEngine.runUpdateQuery(prep);
0873:
0874: SQLEngine.commitTrans(transNumber);
0875: } catch (Exception e) {
0876: Util.log("[SQLCampaign->updateCampagneAssignationRef]" + e);
0877: if (Api.isDEBUG()) {
0878: e.printStackTrace();
0879: }
0880: SQLEngine.rollBackTrans(transNumber);
0881: throw e;
0882: }
0883: }
0884:
0885: /**
0886: * Delete a campaign and it's related links in the database
0887: * include : delete test in campaign, dataset, execution (and result), and attachment
0888: * reorder the campaign in the project
0889: * @param idCamp
0890: * @throws Exception
0891: * need permission canDeleteCamp
0892: * @see deleteTest(int,int)
0893: * @see deleteAllExec(int)
0894: * @see deleteAllAttach(int)
0895: * @see deleteAllDataset(int)
0896: * need permission canDeleteCamp
0897: */
0898: public void delete(int idCamp) throws Exception {
0899: delete(idCamp, true);
0900: }
0901:
0902: /**
0903: * Delete a campaign and it's related links in the database
0904: * include : delete test in campaign, dataset, execution (and result), and attachment
0905: * reorder the campaign in the project if reorder = true
0906: * @param idCamp
0907: * @throws Exception
0908: * need permission canDeleteCamp
0909: * @see deleteTest(int,int)
0910: * @see deleteAllExec(int)
0911: * @see deleteAllAttach(int)
0912: * @see deleteAllDataset(int)
0913: * need permission canDeleteCamp
0914: * @TODO SOAP
0915: */
0916: public void delete(int idCamp, boolean reorder) throws Exception {
0917: int transNumber = -1;
0918: if (idCamp < 1) {
0919: throw new Exception(
0920: "[SQLCampaign->delete] entry data are not valid");
0921: }
0922: boolean dospecialAllow = false;
0923: if (!SQLEngine.specialAllow) {
0924: if (!(Permission.canDeleteCamp())) {
0925: throw new SecurityException(
0926: "[SQLCampaign : delete -> canDeleteCamp]");
0927: }
0928: dospecialAllow = true;
0929: SQLEngine.setSpecialAllow(true);
0930: }
0931:
0932: try {
0933: transNumber = SQLEngine.beginTransaction(10,
0934: ApiConstants.DELETE_CAMPAIGN);
0935:
0936: CampaignWrapper pCamp = null;
0937: int orderIndex = -1;
0938: int maxOrder = -1;
0939: maxOrder--; //because order index begin at 0
0940:
0941: if (reorder) {
0942: pCamp = getCampaign(idCamp);
0943: orderIndex = pCamp.getOrder();
0944: maxOrder = getNumberOfCampaign(pCamp.getIdProject());
0945: maxOrder--; //because order index begin at 0
0946: }
0947:
0948: /* ConnectionData.getCampTestDelete().deleteCampaignUsingID(idBdd);*/
0949: /* Delete test in campaign */
0950: PreparedStatement prep = SQLEngine
0951: .getSQLSelectQuery("selectCampaignTestsUsingID"); //ok
0952: prep.setInt(1, idCamp);
0953: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
0954: while (stmtRes.next()) {
0955: int idTest = stmtRes.getInt("CAS_TEST_id_cas");
0956: purgeTest(idCamp, idTest, true);
0957: }
0958:
0959: /* Delete execution in campaign */
0960: deleteAllExec(idCamp);
0961:
0962: // Suppression des attachements
0963: deleteAllAttach(idCamp);
0964:
0965: /* Delete dataset */
0966: deleteAllDataset(idCamp);
0967:
0968: // Suppression de la campagne de test
0969: prep = SQLEngine.getSQLDeleteQuery("deleteCampaign"); //ok
0970: prep.setInt(1, idCamp);
0971: SQLEngine.runDeleteQuery(prep);
0972:
0973: if (reorder) {
0974: if (orderIndex < maxOrder) {
0975: for (int i = orderIndex + 1; i <= maxOrder; i++) {
0976: CampaignWrapper pCamp2 = getCampaignByOrder(
0977: pCamp.getIdProject(), i);
0978: updateOrder(pCamp2.getIdBDD(), i - 1);
0979: }
0980: }
0981: }
0982:
0983: SQLEngine.commitTrans(transNumber);
0984: } catch (Exception e) {
0985: if (dospecialAllow) {
0986: SQLEngine.setSpecialAllow(false);
0987: }
0988: Util.log("[SQLCampaign->delete]" + e);
0989: if (Api.isDEBUG()) {
0990: e.printStackTrace();
0991: }
0992: SQLEngine.rollBackTrans(transNumber);
0993: throw e;
0994: }
0995: if (dospecialAllow) {
0996: SQLEngine.setSpecialAllow(false);
0997: }
0998: }
0999:
1000: /**
1001: * Delete all executions reference (and it's result) for the campaign identified by idCamp
1002: * @param idCamp
1003: * @throws Exception
1004: * @see ISQLExecution.delete(int)
1005: * need permission canExecutCamp or canDeleteCamp
1006: */
1007: public void deleteAllExec(int idCamp) throws Exception {
1008: int transNumber = -1;
1009: if (idCamp < 1) {
1010: throw new Exception(
1011: "[SQLCampaign->deleteAllExec] entry data are not valid");
1012: }
1013: if (!SQLEngine.specialAllow) {
1014: if (!(Permission.canExecutCamp() || Permission
1015: .canDeleteCamp())) {
1016: throw new SecurityException(
1017: "[SQLDataset : delete -> canExecutCamp]");
1018: }
1019: }
1020: try {
1021: transNumber = SQLEngine.beginTransaction(10,
1022: ApiConstants.DELETE_EXECUTION);
1023:
1024: PreparedStatement prep = SQLEngine
1025: .getSQLSelectQuery("selectCampaignExecutions"); //ok
1026: prep.setInt(1, idCamp);
1027: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1028: while (stmtRes.next()) {
1029: int idExec = stmtRes.getInt("id_exec_camp");
1030: SQLObjectFactory.getInstanceOfISQLExecution().delete(
1031: idExec);
1032: }
1033:
1034: SQLEngine.commitTrans(transNumber);
1035: } catch (Exception e) {
1036: Util.log("[SQLCampaign->deleteAllExec]" + e);
1037: if (Api.isDEBUG()) {
1038: e.printStackTrace();
1039: }
1040: SQLEngine.rollBackTrans(transNumber);
1041: throw e;
1042: }
1043: }
1044:
1045: /**
1046: * Delete all datasets reference for the campaign identified by idCamp
1047: * @param idCamp
1048: * @throws Exception
1049: * @see ISQLDataset.delete(int)
1050: * need permission canExecutCamp or canDeleteCamp
1051: */
1052: public void deleteAllDataset(int idCamp) throws Exception {
1053: int transNumber = -1;
1054: if (idCamp < 1) {
1055: throw new Exception(
1056: "[SQLCampaign->deleteAllDataset] entry data are not valid");
1057: }
1058: if (!SQLEngine.specialAllow) {
1059: if (!(Permission.canExecutCamp() || Permission
1060: .canDeleteCamp())) {
1061: throw new SecurityException(
1062: "[SQLDataset : delete -> canExecutCamp]");
1063: }
1064: }
1065: try {
1066: transNumber = SQLEngine.beginTransaction(10,
1067: ApiConstants.DELETE_DATA_SET);
1068:
1069: PreparedStatement prep = SQLEngine
1070: .getSQLSelectQuery("selectCampJeuxDonnees"); //ok
1071: prep.setInt(1, idCamp);
1072: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1073:
1074: while (stmtRes.next()) {
1075: int idDataset = stmtRes.getInt("id_jeu_donnees");
1076: SQLObjectFactory.getInstanceOfISQLDataset().delete(
1077: idDataset);
1078: }
1079:
1080: SQLEngine.commitTrans(transNumber);
1081: } catch (Exception e) {
1082: Util.log("[SQLCampaign->deleteAllDataset]" + e);
1083: if (Api.isDEBUG()) {
1084: e.printStackTrace();
1085: }
1086: SQLEngine.rollBackTrans(transNumber);
1087: throw e;
1088: }
1089: }
1090:
1091: public void deleteTest(int idCamp, int testId, boolean deleteExec)
1092: throws Exception {
1093: deleteTest(idCamp, testId, deleteExec, true);
1094: }
1095:
1096: /**
1097: * Delete a test reference for the campaign identified by idCamp
1098: * then reoder the test in the campaign, and clean result on Excecution
1099: * then delete execution if empty and deleteExec = true
1100: * @param idCamp
1101: * @param testId
1102: * @param deleteExec
1103: * @throws Exception
1104: * need permission canDeleteCamp
1105: */
1106: public void deleteTest(int idCamp, int testId, boolean deleteExec,
1107: boolean reorder) throws Exception {
1108: int transNumber = -1;
1109: int orderIndex = -1;
1110: if (idCamp < 1 || testId < 1) {
1111: throw new Exception(
1112: "[SQLCampaign->deleteTest] entry data are not valid");
1113: }
1114: if (!SQLEngine.specialAllow) {
1115: if (!(Permission.canDeleteCamp())) {
1116: throw new SecurityException(
1117: "[SQLCampaign : deleteTest -> canDeleteCamp]");
1118: }
1119: }
1120: try {
1121: transNumber = SQLEngine.beginTransaction(10,
1122: ApiConstants.DELETE_TEST_FROM_CAMPAIGN);
1123: int maxOrder = -1;
1124: TestCampWrapper pTestCamp = null;
1125: if (reorder) {
1126: pTestCamp = getTestCampById(idCamp, testId);
1127: orderIndex = pTestCamp.getOrder();
1128: maxOrder = getNumberOfTestInCampaign(idCamp);
1129: maxOrder--; //because index begin at 0
1130: }
1131:
1132: purgeTest(idCamp, testId, deleteExec);
1133:
1134: if (reorder) {
1135: if (orderIndex < maxOrder) {
1136: for (int i = orderIndex + 1; i <= maxOrder; i++) {
1137: TestCampWrapper pTestCamp2 = getTestCampByOrder(
1138: idCamp, i);
1139: updateTestOrder(idCamp, pTestCamp2.getIdBDD(),
1140: i - 1);
1141: }
1142: }
1143: }
1144:
1145: SQLEngine.commitTrans(transNumber);
1146: } catch (Exception e) {
1147: Util.log("[SQLCampaign->deleteTest]" + e);
1148: if (Api.isDEBUG()) {
1149: e.printStackTrace();
1150: }
1151: SQLEngine.rollBackTrans(transNumber);
1152: throw e;
1153: }
1154: }
1155:
1156: void purgeTest(int idCamp, int idTest, boolean deleteExec)
1157: throws Exception {
1158: int transNumber = -1;
1159: if (idCamp < 1 || idTest < 1) {
1160: throw new Exception(
1161: "[SQLCampaign->purgeTest] entry data are not valid");
1162: }
1163: boolean doSpecialAllow = false;
1164: if (!SQLEngine.isSpecialAllow()) {
1165: SQLEngine.setSpecialAllow(true);
1166: doSpecialAllow = true;
1167: }
1168: try {
1169: transNumber = SQLEngine.beginTransaction(10,
1170: ApiConstants.DELETE_TEST_FROM_CAMPAIGN);
1171: PreparedStatement prep;
1172: int id_cas_exec = 0;
1173:
1174: /*Suppression de tous les resultats d'execution du test dans la campagne*/
1175: if (deleteExec) {
1176: prep = SQLEngine
1177: .getSQLSelectQuery("selectAllResExecTestInCamp"); //ok
1178: prep.setInt(1, idTest);
1179: prep.setInt(2, idCamp);
1180: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1181:
1182: while (stmtRes.next()) {
1183: id_cas_exec = stmtRes.getInt("id_exec_cas");
1184: SQLObjectFactory
1185: .getInstanceOfISQLExecutionTestResult()
1186: .delete(id_cas_exec);
1187: }
1188: }
1189: /*Suppression du test de la campagagne de tests*/
1190: prep = SQLEngine
1191: .getSQLDeleteQuery("deleteTestFromCampaign"); //ok
1192: prep.setInt(1, idCamp);
1193: prep.setInt(2, idTest);
1194: SQLEngine.runDeleteQuery(prep);
1195:
1196: /* Si la campagne de test est vide, on supprime ses résultats d'exécution */
1197: prep = SQLEngine
1198: .getSQLSelectQuery("SelectAllTestFromCampagne"); //ok
1199: prep.setInt(1, idCamp);
1200: ResultSet stmtRes2 = SQLEngine.runSelectQuery(prep);
1201: if (!stmtRes2.next()) {
1202: prep = SQLEngine
1203: .getSQLSelectQuery("selectExecutionWithCampagne"); //ok
1204: prep.setInt(1, idCamp);
1205: ResultSet stmtRes3 = SQLEngine.runSelectQuery(prep);
1206: while (stmtRes3.next()) {
1207: int id_exec_camp = stmtRes3.getInt("id_exec_camp");
1208: if (deleteExec) {
1209: SQLObjectFactory.getInstanceOfISQLExecution()
1210: .delete(id_exec_camp);
1211: } else {
1212: //SQLObjectFactory.getInstanceOfISQLExecution().deleteAllExecResult(id_exec_camp);
1213: }
1214: }
1215: }
1216: SQLEngine.commitTrans(transNumber);
1217: } catch (Exception e) {
1218: if (doSpecialAllow) {
1219: SQLEngine.setSpecialAllow(false);
1220: }
1221: Util.log("[SQLCampaign->purgeTest]" + e);
1222: if (Api.isDEBUG()) {
1223: e.printStackTrace();
1224: }
1225: SQLEngine.rollBackTrans(transNumber);
1226: throw e;
1227: }
1228: if (doSpecialAllow) {
1229: SQLEngine.setSpecialAllow(false);
1230: }
1231: }
1232:
1233: /**
1234: * Delete an attachment idAttach in the campaign (table CAMPAGNE_ATTACHEMENT and ATTACHEMENT)
1235: * @param idCamp
1236: * @param idAttach
1237: * @throws Exception
1238: * @see ISQLAttachment.delete(int)
1239: * no permission needed
1240: */
1241: public void deleteAttach(int idCamp, int idAttach) throws Exception {
1242: int transNumber = -1;
1243: if (idCamp < 1 || idAttach < 1) {
1244: throw new Exception(
1245: "[SQLCampaign->deleteAttach] entry data are not valid");
1246: }
1247: try {
1248: transNumber = SQLEngine.beginTransaction(10,
1249: ApiConstants.DELETE_ATTACHMENT);
1250:
1251: PreparedStatement prep = SQLEngine
1252: .getSQLDeleteQuery("deleteAttachFromCampaign"); //ok
1253: prep.setInt(1, idCamp);
1254: prep.setInt(2, idAttach);
1255: SQLEngine.runDeleteQuery(prep);
1256:
1257: SQLObjectFactory.getInstanceOfISQLAttachment().delete(
1258: idAttach);
1259:
1260: SQLEngine.commitTrans(transNumber);
1261: } catch (Exception e) {
1262: Util.log("[SQLCampaign->deleteAttach]" + e);
1263: if (Api.isDEBUG()) {
1264: e.printStackTrace();
1265: }
1266: SQLEngine.rollBackTrans(transNumber);
1267: throw e;
1268: }
1269: }
1270:
1271: /**
1272: * Delete all attachments in the campaign (table CAMPAGNE_ATTACHEMENT and ATTACHEMENT)
1273: * @param idCamp
1274: * @see deleteAttach(int, int)
1275: * @throws Exception
1276: */
1277: public void deleteAllAttach(int idCamp) throws Exception {
1278: int transNumber = -1;
1279: if (idCamp < 1) {
1280: throw new Exception(
1281: "[SQLCampaign->deleteAllAttach] entry data are not valid");
1282: }
1283: try {
1284: transNumber = SQLEngine.beginTransaction(10,
1285: ApiConstants.DELETE_ATTACHMENT);
1286:
1287: AttachementWrapper[] attachList = getAttachs(idCamp);
1288: for (int i = 0; i < attachList.length; i++) {
1289: AttachementWrapper pAttachementWrapper = attachList[i];
1290: deleteAttach(idCamp, pAttachementWrapper.getIdBDD());
1291: }
1292:
1293: SQLEngine.commitTrans(transNumber);
1294: } catch (Exception e) {
1295: Util.log("[SQLCampaign->deleteAllAttach]" + e);
1296: if (Api.isDEBUG()) {
1297: e.printStackTrace();
1298: }
1299: SQLEngine.rollBackTrans(transNumber);
1300: throw e;
1301: }
1302: }
1303:
1304: /**
1305: * Delete a test reference in all campaign and then reorder the tests in the campaign
1306: * @param idTest
1307: * @see deleteTest(int, int)
1308: * need permission canDeleteCamp
1309: * @throws Exception
1310: */
1311: public void deleteTestInAllCampaign(int idTest) throws Exception {
1312: int transNumber = -1;
1313: if (idTest < 1) {
1314: throw new Exception(
1315: "[SQLCampaign->deleteTestInAllCampaign] entry data are not valid");
1316: }
1317: boolean doSpecialAllow = false;
1318: if (!SQLEngine.specialAllow) {
1319: if (!(Permission.canDeleteCamp())) {
1320: throw new SecurityException(
1321: "[SQLCampaign : deleteTestInAllCampaign -> canDeleteCamp]");
1322: }
1323: SQLEngine.setSpecialAllow(true);
1324: doSpecialAllow = true;
1325: }
1326:
1327: try {
1328: transNumber = SQLEngine.beginTransaction(10,
1329: ApiConstants.DELETE_TEST_FROM_CAMPAIGN);
1330:
1331: PreparedStatement prep = SQLEngine
1332: .getSQLSelectQuery("SelectCampagneFormTest"); //ok
1333: prep.setInt(1, idTest);
1334: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1335:
1336: while (stmtRes.next()) {
1337: int idCamp = stmtRes.getInt("CAMPAGNE_TEST_id_camp");
1338: //purgeTest(idCamp, idTest, true);
1339: deleteTest(idCamp, idTest, true);
1340: }
1341:
1342: SQLEngine.commitTrans(transNumber);
1343: } catch (Exception e) {
1344: if (doSpecialAllow) {
1345: SQLEngine.setSpecialAllow(false);
1346: }
1347: Util.log("[SQLCampaign->deleteTestInAllCampaign]" + e);
1348: if (Api.isDEBUG()) {
1349: e.printStackTrace();
1350: }
1351: SQLEngine.rollBackTrans(transNumber);
1352: throw e;
1353: }
1354: if (doSpecialAllow) {
1355: SQLEngine.setSpecialAllow(false);
1356: }
1357: }
1358:
1359: /**
1360: * Get a Vector of AttachementWrapper (FileAttachementWrapper, UrlAttachementWrapper)
1361: * for the campaign identified by idCamp
1362: * @param idCamp : id of the campaign
1363: * @return
1364: * @throws Exception
1365: */
1366:
1367: public AttachementWrapper[] getAttachs(int idCamp) throws Exception {
1368: if (idCamp < 1) {
1369: throw new Exception(
1370: "[SQLCampaign->getAttachs] entry data are not valid");
1371: }
1372:
1373: FileAttachementWrapper[] fileList = getAttachFiles(idCamp);
1374: UrlAttachementWrapper[] urlList = getAttachUrls(idCamp);
1375:
1376: AttachementWrapper[] result = new AttachementWrapper[fileList.length
1377: + urlList.length];
1378:
1379: for (int i = 0; i < fileList.length; i++) {
1380: result[i] = fileList[i];
1381: }
1382: for (int i = 0; i < urlList.length; i++) {
1383: result[fileList.length + i] = urlList[i];
1384: }
1385:
1386: return result;
1387: }
1388:
1389: /**
1390: * Get a Vector of FileAttachementWrapper for the campaign identified by idCamp
1391: * @param idCamp : id of the campaign
1392: * @return
1393: * @throws Exception
1394: */
1395: public FileAttachementWrapper[] getAttachFiles(int idCamp)
1396: throws Exception {
1397: if (idCamp < 1) {
1398: throw new Exception(
1399: "[SQLCampaign->getAttachFiles] entry data are not valid");
1400: }
1401: Vector result = new Vector();
1402: PreparedStatement prep = SQLEngine
1403: .getSQLSelectQuery("selectCampaignAttachFiles"); //ok
1404: prep.setInt(1, idCamp);
1405: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1406: while (stmtRes.next()) {
1407: FileAttachementWrapper fileAttach = new FileAttachementWrapper();
1408: fileAttach.setName(stmtRes.getString("nom_attach"));
1409: fileAttach.setLocalisation("");
1410: fileAttach.setDate(stmtRes.getDate("date_attachement"));
1411: fileAttach.setSize(new Long(stmtRes
1412: .getLong("taille_attachement")));
1413: fileAttach.setDescription(stmtRes
1414: .getString("description_attach"));
1415: fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
1416: result.addElement(fileAttach);
1417: }
1418: FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
1419: .size()];
1420: for (int i = 0; i < result.size(); i++) {
1421: fawArray[i] = (FileAttachementWrapper) result.get(i);
1422: }
1423: return fawArray;
1424: }
1425:
1426: /**
1427: * Get a Vector of UrlAttachementWrapper for the campaign identified by idCamp
1428: * @param idCamp : id of the campaign
1429: * @return
1430: * @throws Exception
1431: */
1432: public UrlAttachementWrapper[] getAttachUrls(int idCamp)
1433: throws Exception {
1434: if (idCamp < 1) {
1435: throw new Exception(
1436: "[SQLCampaign->getAttachUrls] entry data are not valid");
1437: }
1438: Vector result = new Vector();
1439: PreparedStatement prep = SQLEngine
1440: .getSQLSelectQuery("selectCampaignAttachUrls"); //ok
1441: prep.setInt(1, idCamp);
1442: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1443: while (stmtRes.next()) {
1444: UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
1445: String url = stmtRes.getString("url_attach");
1446: // pUrlAttachment.setUrl(url);
1447: pUrlAttachment.setName(url);
1448: pUrlAttachment.setDescription(stmtRes
1449: .getString("description_attach"));
1450: ;
1451: pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
1452: result.addElement(pUrlAttachment);
1453: }
1454: UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
1455: .size()];
1456: for (int i = 0; i < result.size(); i++) {
1457: uawArray[i] = (UrlAttachementWrapper) result.get(i);
1458: }
1459: return uawArray;
1460: }
1461:
1462: /**
1463: * Return the number of campaign in the project identified by idProject
1464: * @param idProject
1465: * @return
1466: * @throws Exception
1467: */
1468: public int getNumberOfCampaign(int idProject) throws Exception {
1469: if (idProject < 1) {
1470: throw new Exception(
1471: "[SQLCampaign->getNumberOfCampaign] entry data are not valid");
1472: }
1473: int numberOfCampaign = 0;
1474: int transNuber = -1;
1475: try {
1476: transNuber = SQLEngine.beginTransaction(10,
1477: ApiConstants.LOADING);
1478:
1479: PreparedStatement prep = SQLEngine
1480: .getSQLSelectQuery("selectProjectCampaigns"); //ok
1481: prep.setInt(1, idProject);
1482: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1483:
1484: while (stmtRes.next()) {
1485: numberOfCampaign++;
1486: }
1487: SQLEngine.commitTrans(transNuber);
1488: } catch (Exception e) {
1489: SQLEngine.rollBackTrans(transNuber);
1490: throw e;
1491: }
1492: return numberOfCampaign;
1493: }
1494:
1495: /**
1496: * Return the number of tests in the campaign identified by idCamp
1497: * @param idCamp
1498: * @return
1499: * @throws Exception
1500: */
1501: public int getNumberOfTestInCampaign(int idCamp) throws Exception {
1502: if (idCamp < 1) {
1503: throw new Exception(
1504: "[SQLCampaign->getNumberOfTestInCampaign] entry data are not valid");
1505: }
1506: int numberOftest = 0;
1507: int transNuber = -1;
1508: try {
1509: transNuber = SQLEngine.beginTransaction(10,
1510: ApiConstants.LOADING);
1511:
1512: PreparedStatement prep = SQLEngine
1513: .getSQLSelectQuery("selectCampaignTestsUsingID"); //ok
1514: prep.setInt(1, idCamp);
1515: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1516: while (stmtRes.next()) {
1517: numberOftest++;
1518: }
1519: SQLEngine.commitTrans(transNuber);
1520: } catch (Exception e) {
1521: SQLEngine.rollBackTrans(transNuber);
1522: throw e;
1523: }
1524: return numberOftest;
1525: }
1526:
1527: /**
1528: * Return a Vector of CampaignWrapper representing the campaign of the project identified by idProject
1529: * @param idProject
1530: * @return
1531: * @throws Exception
1532: */
1533: public CampaignWrapper[] getAllCampaigns(int idProject)
1534: throws Exception {
1535: if (idProject < 1) {
1536: throw new Exception(
1537: "[SQLCampaign->getAllCampaigns] entry data are not valid");
1538: }
1539: Vector result = new Vector();
1540: // TODO set conceptor
1541: int transNuber = -1;
1542: try {
1543: transNuber = SQLEngine.beginTransaction(10,
1544: ApiConstants.LOADING);
1545:
1546: PreparedStatement prep = SQLEngine
1547: .getSQLSelectQuery("selectProjectCampaigns"); //ok
1548: prep.setInt(1, idProject);
1549: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1550:
1551: while (stmtRes.next()) {
1552: CampaignWrapper pCampaign = new CampaignWrapper();
1553: pCampaign.setName(stmtRes.getString("nom_camp"));
1554: pCampaign.setIdBDD(stmtRes.getInt("id_camp"));
1555: pCampaign.setIdProject(idProject);
1556: pCampaign
1557: .setConceptor(SQLObjectFactory
1558: .getInstanceOfISQLPersonne()
1559: .getLogin(
1560: stmtRes
1561: .getInt("PERSONNE_id_personne")));
1562: pCampaign.setDescription(stmtRes
1563: .getString("description_camp"));
1564: pCampaign
1565: .setDate(stmtRes.getDate("date_creation_camp"));
1566: result.addElement(pCampaign);
1567: }
1568: SQLEngine.commitTrans(transNuber);
1569: } catch (Exception e) {
1570: SQLEngine.rollBackTrans(transNuber);
1571: throw e;
1572: }
1573: CampaignWrapper[] cwArray = new CampaignWrapper[result.size()];
1574: for (int i = 0; i < result.size(); i++) {
1575: cwArray[i] = (CampaignWrapper) result.get(i);
1576: }
1577: return cwArray;
1578: }
1579:
1580: /**
1581: * Return a CampaignWrapper representing a campaign at order 'order' in the project identified by idProject
1582: * @param idProject
1583: * @param order
1584: * @return
1585: * @throws Exception
1586: */
1587: public CampaignWrapper getCampaignByOrder(int idProject, int order)
1588: throws Exception {
1589: if (idProject < 1 || order < 0) {
1590: throw new Exception(
1591: "[SQLCampaign->CampaignWrapper] entry data are not valid");
1592: }
1593: CampaignWrapper pCampaign = null;
1594: int transNuber = -1;
1595: try {
1596: transNuber = SQLEngine.beginTransaction(10,
1597: ApiConstants.LOADING);
1598:
1599: PreparedStatement prep = SQLEngine
1600: .getSQLSelectQuery("selectCampaignByOrder"); //ok
1601: prep.setInt(1, idProject);
1602: prep.setInt(2, order);
1603: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1604:
1605: if (stmtRes.next()) {
1606: pCampaign = new CampaignWrapper();
1607: pCampaign.setName(stmtRes.getString("nom_camp"));
1608: pCampaign.setDescription(stmtRes
1609: .getString("description_camp"));
1610: pCampaign.setIdBDD(stmtRes.getInt("id_camp"));
1611: pCampaign.setOrder(stmtRes.getInt("ordre_camp"));
1612: pCampaign.setIdProject(idProject);
1613: }
1614: SQLEngine.commitTrans(transNuber);
1615: } catch (Exception e) {
1616: SQLEngine.rollBackTrans(transNuber);
1617: throw e;
1618: }
1619: return pCampaign;
1620: }
1621:
1622: /**
1623: * Return a CampaignWrapper for the campaign identified by idCamp
1624: * @param idCamp
1625: * @return
1626: * @throws Exception
1627: */
1628: public CampaignWrapper getCampaign(int idCamp) throws Exception {
1629: if (idCamp < 1) {
1630: throw new Exception(
1631: "[SQLCampaign->getCampaign] entry data are not valid");
1632: }
1633: CampaignWrapper pCampaign = null;
1634: int transNuber = -1;
1635: try {
1636: transNuber = SQLEngine.beginTransaction(10,
1637: ApiConstants.LOADING);
1638: PreparedStatement prep = SQLEngine
1639: .getSQLSelectQuery("selectCampaignUsingID"); //ok
1640: prep.setInt(1, idCamp);
1641: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1642: if (stmtRes.next()) {
1643: pCampaign = new CampaignWrapper();
1644: pCampaign.setName(stmtRes.getString("nom_camp"));
1645: pCampaign.setDescription(stmtRes
1646: .getString("description_camp"));
1647: pCampaign.setIdBDD(stmtRes.getInt("id_camp"));
1648: pCampaign.setOrder(stmtRes.getInt("ordre_camp"));
1649: pCampaign.setIdProject(stmtRes
1650: .getInt("PROJET_VOICE_TESTING_id_projet"));
1651: }
1652: SQLEngine.commitTrans(transNuber);
1653: } catch (Exception e) {
1654: SQLEngine.rollBackTrans(transNuber);
1655: throw e;
1656: }
1657: return pCampaign;
1658: }
1659:
1660: TestCampWrapper getInCampaignLastTestInSuite(int idCamp, int idSuite)
1661: throws Exception {
1662: if (idCamp < 1 || idSuite < 1) {
1663: throw new Exception(
1664: "[SQLCampaign->getInCampaignLastTestInSuite] entry data are not valid");
1665: }
1666: TestCampWrapper pTestCampWrapper = null;
1667: int transNuber = -1;
1668: try {
1669: transNuber = SQLEngine.beginTransaction(10,
1670: ApiConstants.LOADING);
1671:
1672: PreparedStatement prep = SQLEngine
1673: .getSQLSelectQuery("selectSuiteTestsInCamp"); //ok
1674: prep.setInt(1, idCamp);
1675: prep.setInt(2, idSuite);
1676: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1677: //stmtRes.last();
1678: while (stmtRes.next()) {
1679: pTestCampWrapper = new TestCampWrapper();
1680: pTestCampWrapper.setIdBDD(stmtRes
1681: .getInt("CAS_TEST_id_cas"));
1682: pTestCampWrapper.setIdCamp(stmtRes
1683: .getInt("CAMPAGNE_TEST_id_camp"));
1684: pTestCampWrapper.setOrder(stmtRes
1685: .getInt("ordre_cas_camp"));
1686: pTestCampWrapper.setIdUser(stmtRes
1687: .getInt("assigned_user_id"));
1688: }
1689: SQLEngine.commitTrans(transNuber);
1690: } catch (Exception e) {
1691: SQLEngine.rollBackTrans(transNuber);
1692: throw e;
1693: }
1694: return pTestCampWrapper;
1695: }
1696:
1697: TestCampWrapper getInCampaignFirstTestInSuite(int idCamp,
1698: int idSuite) throws Exception {
1699: if (idCamp < 1 || idSuite < 1) {
1700: throw new Exception(
1701: "[SQLCampaign->getInCampaignFirstTestInSuite] entry data are not valid");
1702: }
1703: TestCampWrapper pTestCampWrapper = null;
1704: int transNuber = -1;
1705: try {
1706: transNuber = SQLEngine.beginTransaction(10,
1707: ApiConstants.LOADING);
1708:
1709: PreparedStatement prep = SQLEngine
1710: .getSQLSelectQuery("selectSuiteTestsInCamp"); //ok
1711: prep.setInt(1, idCamp);
1712: prep.setInt(2, idSuite);
1713: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1714:
1715: if (stmtRes.next()) {
1716: pTestCampWrapper = new TestCampWrapper();
1717: pTestCampWrapper.setIdBDD(stmtRes
1718: .getInt("CAS_TEST_id_cas"));
1719: pTestCampWrapper.setIdCamp(stmtRes
1720: .getInt("CAMPAGNE_TEST_id_camp"));
1721: pTestCampWrapper.setOrder(stmtRes
1722: .getInt("ordre_cas_camp"));
1723: pTestCampWrapper.setIdUser(stmtRes
1724: .getInt("assigned_user_id"));
1725: }
1726: SQLEngine.commitTrans(transNuber);
1727: } catch (Exception e) {
1728: SQLEngine.rollBackTrans(transNuber);
1729: throw e;
1730: }
1731: return pTestCampWrapper;
1732: }
1733:
1734: TestCampWrapper getInCampaignLastTestInFamily(int idCamp,
1735: int idFamily) throws Exception {
1736: if (idCamp < 1 || idFamily < 1) {
1737: throw new Exception(
1738: "[SQLCampaign->getInCampaignLastTestInFamily] entry data are not valid");
1739: }
1740: TestCampWrapper pTestCampWrapper = null;
1741: int transNuber = -1;
1742: try {
1743: transNuber = SQLEngine.beginTransaction(10,
1744: ApiConstants.LOADING);
1745:
1746: PreparedStatement prep = SQLEngine
1747: .getSQLSelectQuery("selectFamilyTestsInCamp"); //ok
1748: prep.setInt(1, idCamp);
1749: prep.setInt(2, idFamily);
1750: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1751: //stmtRes.last();
1752: while (stmtRes.next()) {
1753: pTestCampWrapper = new TestCampWrapper();
1754: pTestCampWrapper.setIdBDD(stmtRes
1755: .getInt("CAS_TEST_id_cas"));
1756: pTestCampWrapper.setIdCamp(stmtRes
1757: .getInt("CAMPAGNE_TEST_id_camp"));
1758: pTestCampWrapper.setOrder(stmtRes
1759: .getInt("ordre_cas_camp"));
1760: pTestCampWrapper.setIdUser(stmtRes
1761: .getInt("assigned_user_id"));
1762: }
1763:
1764: SQLEngine.commitTrans(transNuber);
1765: } catch (Exception e) {
1766: SQLEngine.rollBackTrans(transNuber);
1767: throw e;
1768: }
1769: return pTestCampWrapper;
1770: }
1771:
1772: TestCampWrapper getInCampaignFirstTestInFamily(int idCamp,
1773: int idFamily) throws Exception {
1774: if (idCamp < 1 || idFamily < 1) {
1775: throw new Exception(
1776: "[SQLCampaign->getInCampaignFirstTestInFamily] entry data are not valid");
1777: }
1778: TestCampWrapper pTestCampWrapper = null;
1779: int transNuber = -1;
1780: try {
1781: transNuber = SQLEngine.beginTransaction(10,
1782: ApiConstants.LOADING);
1783:
1784: PreparedStatement prep = SQLEngine
1785: .getSQLSelectQuery("selectFamilyTestsInCamp"); //ok
1786: prep.setInt(1, idCamp);
1787: prep.setInt(2, idFamily);
1788: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1789:
1790: if (stmtRes.next()) {
1791: pTestCampWrapper = new TestCampWrapper();
1792: pTestCampWrapper.setIdBDD(stmtRes
1793: .getInt("CAS_TEST_id_cas"));
1794: pTestCampWrapper.setIdCamp(stmtRes
1795: .getInt("CAMPAGNE_TEST_id_camp"));
1796: pTestCampWrapper.setOrder(stmtRes
1797: .getInt("ordre_cas_camp"));
1798: pTestCampWrapper.setIdUser(stmtRes
1799: .getInt("assigned_user_id"));
1800: }
1801: SQLEngine.commitTrans(transNuber);
1802: } catch (Exception e) {
1803: SQLEngine.rollBackTrans(transNuber);
1804: throw e;
1805: }
1806: return pTestCampWrapper;
1807: }
1808:
1809: /**
1810: * Get a TestCampWrapper representing the test at defined order in the campagne idCamp
1811: * @param idCamp
1812: * @param order
1813: * @return
1814: * @throws Exception
1815: */
1816: public TestCampWrapper getTestCampByOrder(int idCamp, int order)
1817: throws Exception {
1818: if (idCamp < 1 || order < 0) {
1819: throw new Exception(
1820: "[SQLCampaign->getTestCampByOrder] entry data are not valid");
1821: }
1822: TestCampWrapper pTestCampWrapper = null;
1823: int transNuber = -1;
1824: try {
1825: transNuber = SQLEngine.beginTransaction(10,
1826: ApiConstants.LOADING);
1827:
1828: PreparedStatement prep = SQLEngine
1829: .getSQLSelectQuery("selectTestCampByOrder"); //ok
1830: prep.setInt(1, idCamp);
1831: prep.setInt(2, order);
1832: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1833:
1834: if (stmtRes.next()) {
1835: pTestCampWrapper = new TestCampWrapper();
1836: pTestCampWrapper.setIdBDD(stmtRes
1837: .getInt("CAS_TEST_id_cas"));
1838: pTestCampWrapper.setIdCamp(stmtRes
1839: .getInt("CAMPAGNE_TEST_id_camp"));
1840: pTestCampWrapper.setOrder(stmtRes
1841: .getInt("ordre_cas_camp"));
1842: pTestCampWrapper.setIdUser(stmtRes
1843: .getInt("assigned_user_id"));
1844: }
1845: SQLEngine.commitTrans(transNuber);
1846: } catch (Exception e) {
1847: SQLEngine.rollBackTrans(transNuber);
1848: throw e;
1849: }
1850: return pTestCampWrapper;
1851: }
1852:
1853: /**
1854: * Get a TestCampWrapper representing the test idTest in the campagne idCamp
1855: * @param idCamp
1856: * @param idTest
1857: * @return
1858: * @throws Exception
1859: */
1860: public TestCampWrapper getTestCampById(int idCamp, int idTest)
1861: throws Exception {
1862: if (idCamp < 1 || idTest < 1) {
1863: throw new Exception(
1864: "[SQLCampaign->getTestCampById] entry data are not valid");
1865: }
1866: TestCampWrapper pTestCampWrapper = null;
1867: int transNuber = -1;
1868: try {
1869: transNuber = SQLEngine.beginTransaction(10,
1870: ApiConstants.LOADING);
1871:
1872: PreparedStatement prep = SQLEngine
1873: .getSQLSelectQuery("selectTestCampUsingID"); //ok
1874: prep.setInt(1, idCamp);
1875: prep.setInt(2, idTest);
1876: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1877:
1878: if (stmtRes.next()) {
1879: pTestCampWrapper = new TestCampWrapper();
1880: pTestCampWrapper.setIdBDD(stmtRes
1881: .getInt("CAS_TEST_id_cas"));
1882: pTestCampWrapper.setIdCamp(stmtRes
1883: .getInt("CAMPAGNE_TEST_id_camp"));
1884: pTestCampWrapper.setOrder(stmtRes
1885: .getInt("ordre_cas_camp"));
1886: pTestCampWrapper.setIdUser(stmtRes
1887: .getInt("assigned_user_id"));
1888: }
1889: SQLEngine.commitTrans(transNuber);
1890: } catch (Exception e) {
1891: SQLEngine.rollBackTrans(transNuber);
1892: throw e;
1893: }
1894: return pTestCampWrapper;
1895: }
1896:
1897: /**
1898: * Get an ordered Vector of TestCampWrapper representing test available in the campaign idCamp
1899: * @param idCamp
1900: * @return
1901: * @throws Exception
1902: */
1903: public TestCampWrapper[] getTestsByOrder(int idCamp)
1904: throws Exception {
1905: if (idCamp < 1) {
1906: throw new Exception(
1907: "[SQLCampaign->getTestsByOrder] entry data are not valid");
1908: }
1909: Vector result = new Vector();
1910: int transNuber = -1;
1911: try {
1912: transNuber = SQLEngine.beginTransaction(10,
1913: ApiConstants.LOADING);
1914:
1915: PreparedStatement prep = SQLEngine
1916: .getSQLSelectQuery("selectCampaignTestsOrdered"); //ok
1917: prep.setInt(1, idCamp);
1918: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1919:
1920: while (stmtRes.next()) {
1921: TestCampWrapper pTestCampWrapper = new TestCampWrapper();
1922: pTestCampWrapper.setIdBDD(stmtRes
1923: .getInt("CAS_TEST_id_cas"));
1924: pTestCampWrapper.setIdCamp(stmtRes
1925: .getInt("CAMPAGNE_TEST_id_camp"));
1926: pTestCampWrapper.setOrder(stmtRes
1927: .getInt("ordre_cas_camp"));
1928: pTestCampWrapper.setIdUser(stmtRes
1929: .getInt("assigned_user_id"));
1930: result.add(pTestCampWrapper);
1931: }
1932:
1933: SQLEngine.commitTrans(transNuber);
1934: } catch (Exception e) {
1935: SQLEngine.rollBackTrans(transNuber);
1936: throw e;
1937: }
1938: TestCampWrapper[] tcwArray = new TestCampWrapper[result.size()];
1939: for (int i = 0; i < result.size(); i++) {
1940: tcwArray[i] = (TestCampWrapper) result.get(i);
1941: }
1942: return tcwArray;
1943: }
1944:
1945: /**
1946: * Get the number of tests in the family idFamily in the campaign idCamp
1947: * @param idCamp
1948: * @param idFamily
1949: * @return
1950: * @throws Exception
1951: */
1952: public int getSizeOfFamilyInCampaign(int idCamp, int idFamily)
1953: throws Exception {
1954: if (idCamp < 1 || idFamily < 1) {
1955: throw new Exception(
1956: "[SQLCampaign->getSizeOfFamilyInCampaign] entry data are not valid");
1957: }
1958: int size = 0;
1959: int transNuber = -1;
1960: try {
1961: transNuber = SQLEngine.beginTransaction(10,
1962: ApiConstants.LOADING);
1963:
1964: PreparedStatement prep = SQLEngine
1965: .getSQLSelectQuery("selectFamilyTestsInCamp"); //ok
1966: prep.setInt(1, idCamp);
1967: prep.setInt(2, idFamily);
1968: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1969:
1970: while (stmtRes.next()) {
1971: size++;
1972: }
1973: SQLEngine.commitTrans(transNuber);
1974: } catch (Exception e) {
1975: SQLEngine.rollBackTrans(transNuber);
1976: throw e;
1977: }
1978: return size;
1979: }
1980:
1981: /**
1982: * Get the number of tests in the suite idSuite in the campaign idCamp
1983: * @param idCamp
1984: * @param idSuite
1985: * @return
1986: * @throws Exception
1987: */
1988: public int getSizeOfSuiteInCampaign(int idCamp, int idSuite)
1989: throws Exception {
1990: if (idCamp < 1 || idSuite < 1) {
1991: throw new Exception(
1992: "[SQLCampaign->getSizeOfSuiteInCampaign] entry data are not valid");
1993: }
1994: int size = 0;
1995:
1996: int transNuber = -1;
1997: try {
1998: transNuber = SQLEngine.beginTransaction(10,
1999: ApiConstants.LOADING);
2000:
2001: PreparedStatement prep = SQLEngine
2002: .getSQLSelectQuery("selectSuiteTestsInCamp"); //ok
2003: prep.setInt(1, idCamp);
2004: prep.setInt(2, idSuite);
2005: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
2006:
2007: while (stmtRes.next()) {
2008: size++;
2009: }
2010: SQLEngine.commitTrans(transNuber);
2011: } catch (Exception e) {
2012: SQLEngine.rollBackTrans(transNuber);
2013: throw e;
2014: }
2015: return size;
2016: }
2017:
2018: /**
2019: * Get the id of the campaign identified by name in the project identified by idProject
2020: * @param idProject
2021: * @param name
2022: * @return
2023: * @throws Exception
2024: */
2025: public int getID(int idProject, String name) throws Exception {
2026: if (idProject < 1) {
2027: throw new Exception(
2028: "[SQLCampaign->getID] entry data are not valid");
2029: }
2030: int idCamp = -1;
2031: int transNuber = -1;
2032: try {
2033: transNuber = SQLEngine.beginTransaction(10,
2034: ApiConstants.LOADING);
2035:
2036: PreparedStatement prep = SQLEngine
2037: .getSQLSelectQuery("selectCampId"); //ok
2038: prep.setString(1, name);
2039: prep.setInt(2, idProject);
2040: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
2041:
2042: if (stmtRes.next()) {
2043: idCamp = stmtRes.getInt("id_camp");
2044: }
2045: SQLEngine.commitTrans(transNuber);
2046: } catch (Exception e) {
2047: SQLEngine.rollBackTrans(transNuber);
2048: throw e;
2049: }
2050: return idCamp;
2051: }
2052:
2053: /**
2054: * Get a vector of DataSetWrapper used by the campaign idCamp
2055: * @param idCamp
2056: * @return
2057: * @throws Exception
2058: */
2059: public DataSetWrapper[] getDatsets(int idCamp) throws Exception {
2060: if (idCamp < 1) {
2061: throw new Exception(
2062: "[SQLCampaign->getDatsets] entry data are not valid");
2063: }
2064: Vector result = new Vector();
2065: int transNuber = -1;
2066: try {
2067: transNuber = SQLEngine.beginTransaction(10,
2068: ApiConstants.LOADING);
2069:
2070: PreparedStatement prep = SQLEngine
2071: .getSQLSelectQuery("selectCampJeuxDonnees"); //ok
2072: prep.setInt(1, idCamp);
2073: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
2074: while (stmtRes.next()) {
2075: DataSetWrapper pDataSet = new DataSetWrapper();
2076: pDataSet.setDescription(stmtRes
2077: .getString("desc_jeu_donnees"));
2078: pDataSet.setName(stmtRes.getString("nom_jeu_donnees"));
2079: pDataSet.setIdBDD(stmtRes.getInt("id_jeu_donnees"));
2080: result.addElement(pDataSet);
2081: }
2082:
2083: SQLEngine.commitTrans(transNuber);
2084: } catch (Exception e) {
2085: SQLEngine.rollBackTrans(transNuber);
2086: throw e;
2087: }
2088: DataSetWrapper[] dswArray = new DataSetWrapper[result.size()];
2089: for (int i = 0; i < result.size(); i++) {
2090: dswArray[i] = (DataSetWrapper) result.get(i);
2091: }
2092: return dswArray;
2093: }
2094:
2095: /**
2096: * Get a vector of ExecutionWrapper used by the campaign idCamp
2097: * @param idCamp
2098: * @return
2099: * @throws Exception
2100: */
2101: public ExecutionWrapper[] getExecutions(int idCamp)
2102: throws Exception {
2103: if (idCamp < 1) {
2104: throw new Exception(
2105: "[SQLCampaign->getExecutions] entry data are not valid");
2106: }
2107: Vector result = new Vector();
2108: int transNuber = -1;
2109: try {
2110: transNuber = SQLEngine.beginTransaction(10,
2111: ApiConstants.LOADING);
2112:
2113: PreparedStatement prep = SQLEngine
2114: .getSQLSelectQuery("selectCampaignExecutions"); //ok
2115: prep.setInt(1, idCamp);
2116: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
2117: while (stmtRes.next()) {
2118: ExecutionWrapper exec = new ExecutionWrapper();
2119: exec.setName(stmtRes.getString("nom_exec_camp"));
2120: exec.setLastDate(stmtRes.getDate("last_exec_date"));
2121: exec.setCreationDate(stmtRes.getDate("date_exec_camp"));
2122: exec.setIdBDD(stmtRes.getInt("id_exec_camp"));
2123: exec
2124: .setDescription(stmtRes
2125: .getString("desc_exec_camp"));
2126: exec.setCampId(idCamp);
2127: result.addElement(exec);
2128: }
2129:
2130: SQLEngine.commitTrans(transNuber);
2131: } catch (Exception e) {
2132: SQLEngine.rollBackTrans(transNuber);
2133: throw e;
2134: }
2135: ExecutionWrapper[] ewArray = new ExecutionWrapper[result.size()];
2136: for (int i = 0; i < result.size(); i++) {
2137: ewArray[i] = (ExecutionWrapper) result.get(i);
2138: }
2139: return ewArray;
2140: }
2141:
2142: /**
2143: * Get an Array of ExecutionAttachmentWrapper
2144: * representing all attachement of all execution result
2145: * @param idCamp
2146: * @return
2147: * @throws Exception
2148: */
2149: public ExecutionAttachmentWrapper[] getResExecutionsAttachment(
2150: int idCamp) throws Exception {
2151:
2152: if (idCamp < 1) {
2153: throw new Exception(
2154: "[SQLCampaign->getExecutions] entry data are not valid");
2155: }
2156: Vector result = new Vector();
2157: PreparedStatement prep = SQLEngine
2158: .getSQLSelectQuery("selectResExecAttachFromCamp"); //ok
2159: prep.setInt(1, idCamp);
2160: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
2161: while (stmtRes.next()) {
2162: ExecutionWrapper exec = new ExecutionWrapper();
2163: exec.setName(stmtRes.getString("nom_exec_camp"));
2164: exec.setIdBDD(stmtRes.getInt("id_exec_camp"));
2165: exec.setCampId(idCamp);
2166: TestCampWrapper pTestCampWrapper = new TestCampWrapper();
2167: pTestCampWrapper
2168: .setIdBDD(stmtRes.getInt("CAS_TEST_id_cas"));
2169: pTestCampWrapper.setIdCamp(idCamp);
2170: FileAttachementWrapper fileAttach = null;
2171: UrlAttachementWrapper pUrlAttachment = null;
2172: if (stmtRes.getString("url_attach") == null) {
2173: fileAttach = new FileAttachementWrapper();
2174: fileAttach.setName(stmtRes.getString("nom_attach"));
2175: fileAttach.setLocalisation("");
2176: fileAttach.setDate(stmtRes.getDate("date_attachement"));
2177: fileAttach.setSize(new Long(stmtRes
2178: .getLong("taille_attachement")));
2179: fileAttach.setDescription(stmtRes
2180: .getString("description_attach"));
2181: fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
2182: } else {
2183: pUrlAttachment = new UrlAttachementWrapper();
2184: String url = stmtRes.getString("url_attach");
2185: // pUrlAttachment.setUrl(url);
2186: pUrlAttachment.setName(url);
2187: pUrlAttachment.setDescription(stmtRes
2188: .getString("description_attach"));
2189: ;
2190: pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
2191: }
2192: ExecutionAttachmentWrapper executionAttach = new ExecutionAttachmentWrapper();
2193: executionAttach.setExecution(exec);
2194: executionAttach.setTestCamp(pTestCampWrapper);
2195: executionAttach.setFileAttachment(fileAttach);
2196: executionAttach.setUrlAttachment(pUrlAttachment);
2197:
2198: result.add(executionAttach);
2199: }
2200: ExecutionAttachmentWrapper[] eawArray = new ExecutionAttachmentWrapper[result
2201: .size()];
2202: for (int i = 0; i < result.size(); i++) {
2203: eawArray[i] = (ExecutionAttachmentWrapper) result.get(i);
2204: }
2205:
2206: return eawArray;
2207: }
2208: }
|