001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.data;
025:
026: import java.net.URL;
027: import java.util.ArrayList;
028: import java.util.Enumeration;
029: import java.util.Hashtable;
030: import java.util.Vector;
031:
032: import org.objectweb.salome_tmf.api.Api;
033: import org.objectweb.salome_tmf.api.ApiConstants;
034: import org.objectweb.salome_tmf.api.Util;
035: import org.objectweb.salome_tmf.api.data.AutomaticTestWrapper;
036: import org.objectweb.salome_tmf.api.data.CampaignWrapper;
037: import org.objectweb.salome_tmf.api.data.EnvironmentWrapper;
038: import org.objectweb.salome_tmf.api.data.ExecutionWrapper;
039: import org.objectweb.salome_tmf.api.data.FamilyWrapper;
040: import org.objectweb.salome_tmf.api.data.ManualTestWrapper;
041: import org.objectweb.salome_tmf.api.data.ParameterWrapper;
042: import org.objectweb.salome_tmf.api.data.SuiteWrapper;
043: import org.objectweb.salome_tmf.api.data.TestCampWrapper;
044: import org.objectweb.salome_tmf.api.data.TestWrapper;
045:
046: public class DataLoader {
047: /* Environnement vide */
048: static private Environment emptyEnvironment;
049:
050: /* Jeu de données vide */
051: static private DataSet emptyDataSet;
052:
053: /* Wrapper to IHM */
054: static private IDataModelWrapper pDataModelWrapper = null;
055: static private Project currentProject;
056: static private User currentUser;
057:
058: static boolean isDynamic = true;
059:
060: /* Constructeur */
061: public DataLoader(IDataModelWrapper pDataModelWrapper) {
062: this .pDataModelWrapper = pDataModelWrapper;
063: }
064:
065: /**************************************************************************/
066: /** METHODES D'ACCES AUX DONNES ***/
067: /**************************************************************************/
068:
069: public static void setDataModelWrapper(
070: IDataModelWrapper ptrDataModelWrapper) {
071: pDataModelWrapper = ptrDataModelWrapper;
072: }
073:
074: public static DataSet getEmptyDataSet() {
075: if (emptyDataSet == null) {
076: emptyDataSet = new DataSet(ApiConstants.EMPTY_NAME, "");
077: }
078: return emptyDataSet;
079: }
080:
081: public static Environment getEmptyEnvironment() {
082: if (emptyEnvironment == null) {
083: emptyEnvironment = new Environment(ApiConstants.EMPTY_NAME,
084: "");
085: }
086: return emptyEnvironment;
087: }
088:
089: public static User getCurrentUser() {
090: return currentUser;
091: }
092:
093: public static Project getCurrentProject() {
094: return currentProject;
095: }
096:
097: //****************** Open Connection to BDD DATA ********************/
098:
099: public static boolean dataConnected() {
100: return Api.isConnected();
101: }
102:
103: /**************** Chargement des données ********************************/
104:
105: private static void clearData() {
106: currentProject.clearCampaignData();
107: currentProject.clearTestPlanData();
108: }
109:
110: private static void clearTestPlanData() {
111: currentProject.clearTestPlanData();
112: }
113:
114: private static void clearCampainData() {
115: currentProject.clearCampaignData();
116: }
117:
118: public static void loadData(String projectName, String userLogin,
119: URL url, boolean dynamicLoad) throws Exception {
120: try {
121: isDynamic = dynamicLoad;
122: if (Api.isConnected()) {
123: currentProject = new Project(projectName);
124: currentUser = new User(userLogin);
125: currentProject.setUserInModel(currentUser);
126: Api.getISQLObjectFactory().setConnexionInfo(
127: currentProject.getIdBdd(),
128: currentUser.getIdBdd());
129: int transNumber = -1;
130: try {
131: transNumber = Api.beginTransaction(111,
132: ApiConstants.LOADING);
133: currentProject.setLoad(true);
134: loadParametersData();
135: loadEnvironmentData();
136: loadTestData();
137: loadCampaignData();
138: currentProject.setLoad(false);
139: Api.commitTrans(transNumber);
140: } catch (Exception exception) {
141: Api.forceRollBackTrans(transNumber);
142: currentProject.setLoad(false);
143: throw exception;
144: }
145: }
146: } catch (Exception e) {
147: e.printStackTrace();
148: throw e;
149: }
150: } // Fin de la méthode initDataTests
151:
152: private static void loadParametersData() throws Exception {
153: Vector projectParam = currentProject
154: .getParametersWrapperFromDB();
155: if (pDataModelWrapper != null) {
156: Util
157: .log("[DataLoader->loadParametersData] clearParameterToModel");
158: pDataModelWrapper.clearParameterToModel();
159: }
160: for (int m = 0; m < projectParam.size(); m++) {
161: ParameterWrapper paramBdd = (ParameterWrapper) projectParam
162: .get(m);
163: Parameter param = new Parameter(paramBdd);
164: currentProject.addParameterToModel(param);
165:
166: ArrayList data = new ArrayList();
167: data.add(param.getNameFromModel());
168: data.add(param.getDescriptionFromModel());
169:
170: if (pDataModelWrapper != null)
171: pDataModelWrapper.addParameterToModel(data);
172:
173: }
174: }
175:
176: public static void reloadData(boolean dynamicLoad) throws Exception {
177: currentProject.setLoad(true);
178: clearTestPlanData();
179: clearCampainData();
180: isDynamic = dynamicLoad;
181: int transNumber = -1;
182: if (Api.isConnected()) {
183: transNumber = Api.beginTransaction(111,
184: ApiConstants.LOADING);
185: try {
186:
187: loadParametersData();
188: loadEnvironmentData();
189: loadTestData();
190: loadCampaignData();
191:
192: Api.commitTrans(transNumber);
193: } catch (Exception exception) {
194: Api.forceRollBackTrans(transNumber);
195: currentProject.setLoad(false);
196: throw exception;
197: }
198:
199: }
200: currentProject.setLoad(false);
201: }
202:
203: /* ancien refresh refreshAllTestData*/
204: public static void realoadTestData(boolean dynamicLoad)
205: throws Exception {
206: if (Api.isConnected()) {
207: isDynamic = dynamicLoad;
208: currentProject.setLoad(true);
209: loadTestData();
210: currentProject.setLoad(false);
211: }
212: }
213:
214: /* ancien refresh refreshAllCampaignData*/
215: public static void reloadCampaignData(boolean dynamicLoad)
216: throws Exception {
217: if (Api.isConnected()) {
218: isDynamic = dynamicLoad;
219: currentProject.setLoad(true);
220: loadCampaignData();
221: currentProject.setLoad(false);
222: }
223: }
224:
225: /* ancien refresh refreshEnvironmentAndParameter */
226: public static void reloadEnvironmentAndParameterData(
227: boolean dynamicLoad) throws Exception {
228: if (Api.isConnected()) {
229: isDynamic = dynamicLoad;
230: currentProject.setLoad(true);
231: loadParametersData();
232: loadEnvironmentData();
233: currentProject.setLoad(false);
234: }
235: }
236:
237: private static void loadEnvironmentData() throws Exception {
238: Vector environmentOfProject = currentProject
239: .getEnvironmentWrapperFromDB();
240: for (int m = 0; m < environmentOfProject.size(); m++) {
241: EnvironmentWrapper envDB = (EnvironmentWrapper) environmentOfProject
242: .get(m);
243: Environment env = new Environment(envDB);
244: currentProject.addEnvironmentInModel(env);
245:
246: env.reloadFromDB(false, currentProject
247: .getParameterSetFromModel());
248:
249: ArrayList data = new ArrayList();
250: data.add(env.getNameFromModel());
251: if (env.getInitScriptFromModel() != null) {
252: data.add(env.getInitScriptFromModel()
253: .getNameFromModel());
254: } else {
255: data.add("");
256: }
257: data.add(env.getParametersHashTableFromModel());
258: data.add(env.getDescriptionFromModel());
259: if (pDataModelWrapper != null)
260: pDataModelWrapper.addEnvToModel(data);
261:
262: }
263:
264: }
265:
266: private static void loadFamilyData(Family family) throws Exception {
267: Vector testListVector = family.getSuitesWrapperFromDB();
268: for (int j = 0; j < testListVector.size(); j++) {
269: SuiteWrapper testListBdd = (SuiteWrapper) testListVector
270: .get(j);
271: TestList testList = new TestList(family, testListBdd);
272: family.addTestListInModel(testList);
273:
274: if (pDataModelWrapper != null) {
275: pDataModelWrapper.addTestListToModel(family, testList);
276: }
277: //testList.loadAttachmentDataFromDB();
278: testList.reloadAttachmentDataFromDB(false);
279: //family.addTestList(testList);
280: loadTestListData(testList);
281:
282: if (pDataModelWrapper != null)
283: pDataModelWrapper.refreshTestListToModel(testList);
284:
285: }
286: } // Fin de la méthode initFamily/2
287:
288: private static void loadTestListData(TestList testList)
289: throws Exception {
290: Vector testVector = testList.getTestsWrapperFromDB();
291:
292: for (int k = 0; k < testVector.size(); k++) {
293: TestWrapper testBdd = (TestWrapper) testVector.get(k);
294: Test test = null;
295: if (testBdd.getType().equals(ApiConstants.MANUAL)) {
296: test = new ManualTest(new ManualTestWrapper(testBdd));
297: // test = new ManualTest((ManualTestWrapper)testBdd);
298: } else {
299: test = new AutomaticTest(new AutomaticTestWrapper(
300: testBdd));
301: // test = new AutomaticTest((AutomaticTestWrapper)testBdd);
302: }
303: testList.addTestInModel(test);
304: test.reloadFromDB(false, currentProject
305: .getParameterSetFromModel(), true);
306:
307: if (pDataModelWrapper != null) {
308: pDataModelWrapper.addTestToModel(testList, test);
309: }
310: }
311:
312: } // Fin de la méthode refreshTestList/2
313:
314: private static void loadTestData() throws Exception {
315:
316: Vector familyVector = currentProject
317: .getProjectFamiliesWrapperFromDB();
318: for (int i = 0; i < familyVector.size(); i++) {
319: FamilyWrapper familyBdd = (FamilyWrapper) familyVector
320: .get(i);
321: Family family = new Family(currentProject, familyBdd);
322: currentProject.addFamilyInModel(family);
323:
324: if (pDataModelWrapper != null) {
325: pDataModelWrapper.addFamilyToModel(family);
326: }
327:
328: loadFamilyData(family);
329:
330: if (pDataModelWrapper != null)
331: pDataModelWrapper.refreshFamilyToModel(family);
332: }
333: }
334:
335: private static void loadCampaignData() throws Exception {
336: //boolean newCampaign = false;
337: Vector campaignVector = currentProject
338: .getCampaignsWrapperListFromDB();
339: for (int i = 0; i < campaignVector.size(); i++) {
340: CampaignWrapper campaignBdd = (CampaignWrapper) campaignVector
341: .get(i);
342: Campaign campaign = new Campaign(campaignBdd);
343: //currentProject.addCampaignInModel(campaign);
344: if (pDataModelWrapper != null) {
345: pDataModelWrapper.addCampaignToModel(campaign);
346: }
347: Vector testCampWrapperList = campaign
348: .getTestsByOrderFromDB();
349:
350: for (int j = 0; j < testCampWrapperList.size(); j++) {
351: TestCampWrapper pTestCampWrapper = (TestCampWrapper) testCampWrapperList
352: .elementAt(j);
353: int idTest = pTestCampWrapper.getIdBDD();
354: int idUser = pTestCampWrapper.getIdUser();
355: if (idUser == -1) {
356: idUser = currentUser.getIdBdd();
357: }
358: Test pTest = currentProject.getTestFromModel(idTest);
359: TestList pTestList = pTest.getTestListFromModel();
360: Family pFamily = pTestList.getFamilyFromModel();
361:
362: if (campaign.containsFamilyInModel(pFamily)) {
363: if (pDataModelWrapper != null) {
364: pDataModelWrapper.upadateCampaignFamilyToModel(
365: campaign, pFamily);
366: }
367: } else {
368: if (pDataModelWrapper != null) {
369: pDataModelWrapper.addCampaignFamilyToModel(
370: campaign, pFamily);
371: }
372: }
373: if (campaign.containsTestListInModel(pTestList)) {
374: if (pDataModelWrapper != null) {
375: pDataModelWrapper
376: .upadateCampaignTestListToModel(
377: campaign, pFamily, pTestList);
378: }
379: } else {
380: if (pDataModelWrapper != null) {
381: pDataModelWrapper.addCampaignTestListToModel(
382: pFamily, pTestList);
383: }
384: }
385: if (!campaign.containsTestInModel(pTest)) {
386: if (pDataModelWrapper != null) {
387: pDataModelWrapper.addCampaignTestToModel(
388: pTestList, pTest);
389: }
390: }
391:
392: campaign.addTestInModel(pTest, idUser);
393: }
394:
395: campaign.loadDataSetFromBase(currentProject
396: .getParameterSetFromModel());
397:
398: Vector execVector = campaign
399: .getExecutionWrapperListFromDB();
400: for (int k = 0; k < execVector.size(); k++) {
401: Execution exec = new Execution(campaign,
402: (ExecutionWrapper) execVector.get(k));
403: exec.reloadEnvFromDB(currentProject
404: .getEnvironmentListFromModel(), currentProject
405: .getParameterSetFromModel());
406: exec.reloadDataSetFromDB(campaign
407: .getDataSetListFromModel(), currentProject
408: .getParameterSetFromModel());
409: exec.reloadScriptFromDB();
410: exec.reloadExecResultFromDB();
411: //exec.loadAttachmentDataFromDB();
412: exec.reloadAttachmentDataFromDB(false);
413:
414: campaign.addExecutionInModel(exec);
415:
416: /*Vector execResults = ConnectionData.getCampTestSelect().getExecutionResults(exec.getIdBdd());
417: for (int h = 0; h < execResults.size(); h++) {
418: ExecutionResult execResult = new ExecutionResult ((ExecutionResultWrapper) execResults.get(h));
419: execResult.reloadTestResult(campaign.getTestListFromModel());
420: execResult.reloadAttachmentDataFromDB();
421: exec.addExecutionResultInModel(execResult);
422: }*/
423: }
424: //campaign.loadAttachmentDataFromDB();
425: campaign.reloadAttachmentDataFromDB(false);
426: currentProject.addCampaignInModel(campaign);
427: if (pDataModelWrapper != null) {
428: pDataModelWrapper.refreshCampaignToModel(campaign);
429: }
430: }
431: }
432:
433: }
|