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 Fayçal SOUGRATI
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023: package org.objectweb.salome_tmf.api.api2ihm.adminProject;
024:
025: import java.sql.PreparedStatement;
026: import java.sql.SQLException;
027: import java.util.Properties;
028:
029: import org.objectweb.salome_tmf.api.api2db.DataBase;
030: import org.objectweb.salome_tmf.api.api2db.DataSet;
031: import org.objectweb.salome_tmf.api.api2ihm.Utile;
032:
033: /**
034: * Fonctions de suppression relatives e l'aire fonctionnelle "Administrer un projet"
035: */
036:
037: public class AdminProjectDeleteImpl implements AdminProjectDelete {
038: /**
039: * Base de donnees
040: */
041: DataBase database;
042:
043: /**
044: * Fichier "properties" contenant les requetes SQL relatives aux suites de test
045: */
046: Properties prop;
047:
048: /**
049: * ID du projet SalomeTMF dans lequel on se situe
050: */
051: int idProject;
052:
053: /**
054: * Nom du projet SalomeTMF dans lequel on se situe
055: */
056: String nameProject;
057:
058: /**
059: * Constructeur
060: * @param db
061: * @param pr
062: */
063: public AdminProjectDeleteImpl(DataBase db, Properties pr) {
064: database = db;
065: prop = pr;
066: }
067:
068: /**
069: * Fonction qui fixe le projet SalomeTMF dans lequel l'utilisateur travaille
070: * @param projectName
071: */
072: public void setProject(String projectName) {
073: nameProject = projectName;
074: idProject = Utile.getIdProject(database, prop, projectName);
075: }
076:
077: /**
078: * Suppression d'un utilisateur d'un groupe du projet
079: * @param userLogin
080: * @param groupName
081: */
082: public void deleteUserFromGroup(String userLogin, String groupName) {
083: int userId = -1;
084: int groupId = -1;
085:
086: int _num = -1;
087: try {
088: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
089:
090: // Initialisation de l'ID de l'utilisateur
091: userId = Utile.getIdPerson(database, prop, userLogin);
092:
093: // Initialisation de l'ID du groupe
094: groupId = Utile.getIdGroup(database, prop, idProject,
095: groupName);
096:
097: // Suppression de l'utilisateur du groupe
098: PreparedStatement prep = database.prepareStatement(prop
099: .getProperty("deleteUserFromGroup"));
100: prep.setInt(1, userId);
101: prep.setInt(2, groupId);
102: prep.executeUpdate();
103:
104: } catch (SQLException e) {
105: e.printStackTrace();
106: org.objectweb.salome_tmf.api.Api.addException(
107: "deleteUserFromGroup", null, e);
108: } catch (Exception ex) {
109: ex.printStackTrace();
110: org.objectweb.salome_tmf.api.Api.addException(null, null,
111: ex);
112: }
113: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
114: }
115:
116: /**
117: * Suppression d'un utilisateur d'un projet
118: * @param userLogin
119: */
120: public void deleteUserFromProject(String userLogin) {
121: //int userId = -1;
122: DataSet stmtRes = null;
123:
124: int _num = -1;
125: try {
126: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
127:
128: // On initialise l'Id de l'utilisateur
129: //userId = Utile.getIdPerson(database,prop,userLogin);
130: // On recupere les groupes du projet
131: PreparedStatement prep = database.prepareStatement(prop
132: .getProperty("selectAllProjectGroupsName"));
133: prep.setInt(1, idProject);
134: stmtRes = new DataSet(prep.executeQuery());
135: while (stmtRes.hasMoreElements()) {
136: // On enleve l'utilisateur de chaque groupe du projet
137: deleteUserFromGroup(userLogin, stmtRes.getResults()
138: .getString("nom_groupe"));
139: }
140: } catch (SQLException e) {
141: e.printStackTrace();
142: org.objectweb.salome_tmf.api.Api.addException(
143: "selectAllProjectGroupsName", null, e);
144: } catch (Exception ex) {
145: ex.printStackTrace();
146: org.objectweb.salome_tmf.api.Api.addException(null, null,
147: ex);
148: }
149: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
150: }
151:
152: /**
153: * Suppression d'un groupe d'utilisateurs d'un projet
154: * @param groupName
155: */
156: public void deleteGroup(String groupName) {
157: int groupId = -1;
158: String sql = null;
159: int _num = -1;
160: try {
161: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
162:
163: // Initialisation de l'ID du groupe
164: groupId = Utile.getIdGroup(database, prop, idProject,
165: groupName);
166: sql = "deleteGroupUsers";
167: // Suppression des utilisateurs du groupe
168: PreparedStatement prep = database.prepareStatement(prop
169: .getProperty("deleteGroupUsers"));
170: prep.setInt(1, groupId);
171: prep.executeUpdate();
172:
173: sql = "deleteGroup";
174: // Suppression du groupe
175: prep = database.prepareStatement(prop
176: .getProperty("deleteGroup"));
177: prep.setInt(1, idProject);
178: prep.setInt(2, groupId);
179: prep.executeUpdate();
180: } catch (SQLException e) {
181: e.printStackTrace();
182: org.objectweb.salome_tmf.api.Api.addException(sql, null, e);
183: } catch (Exception ex) {
184: ex.printStackTrace();
185: org.objectweb.salome_tmf.api.Api.addException(null, null,
186: ex);
187: }
188: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
189: }
190:
191: /**
192: * Suppression d'un projet
193: * @param projectName
194: */
195: public void deleteProject() {
196: String sql = null;
197: int _num = -1;
198: try {
199: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
200:
201: DataSet stmtRes = null;
202: org.objectweb.salome_tmf.api.api2ihm.suiteTest.SuiteTestDelete st_d = org.objectweb.salome_tmf.api.Api
203: .getInstanceOfSuiteTest().getSuiteTestDelete();
204: st_d.setProject(nameProject);
205: sql = "selectFamilleOfProject";
206: PreparedStatement prep = database.prepareStatement(prop
207: .getProperty("selectFamilleOfProject"));
208: prep.setInt(1, idProject);
209: stmtRes = new DataSet(prep.executeQuery());
210: if (stmtRes.hasMoreElements()) {
211: int idFamily = stmtRes.getResults()
212: .getInt("id_famille");
213: String name = stmtRes.getResults().getString(
214: "nom_famille");
215: ((org.objectweb.salome_tmf.api.api2ihm.suiteTest.SuiteTestDeleteImpl) st_d)
216: .deleteFamily(idFamily, name);
217: }
218:
219: sql = "deleteCampFromProject";
220: prep = database.prepareStatement(prop
221: .getProperty("deleteCampFromProject"));
222: prep.setInt(1, idProject);
223: prep.executeUpdate();
224:
225: } catch (SQLException e) {
226: e.printStackTrace();
227: org.objectweb.salome_tmf.api.Api.addException(sql, null, e);
228: } catch (Exception ex) {
229: ex.printStackTrace();
230: org.objectweb.salome_tmf.api.Api.addException(null, null,
231: ex);
232: }
233: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
234: }
235: }
|