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.api2ihm.Utile;
031:
032: /**
033: * Fonctions d'insertion relatives e l'aire fonctionnelle "Administrer un projet"
034: */
035:
036: public class AdminProjectInsertImpl implements AdminProjectInsert {
037: /**
038: * Base de donnees
039: */
040: DataBase database;
041:
042: /**
043: * Fichier "properties" contenant les requetes SQL relatives aux suites de test
044: */
045: Properties prop;
046:
047: /**
048: * ID du projet SalomeTMF dans lequel on se situe
049: */
050: int idProject;
051:
052: /**
053: * Nom du projet SalomeTMF dans lequel on se situe
054: */
055: String nameProject;
056:
057: /**
058: * Constructeur
059: * @param db
060: * @param pr
061: */
062: public AdminProjectInsertImpl(DataBase db, Properties pr) {
063: database = db;
064: prop = pr;
065: }
066:
067: /**
068: * Fonction qui fixe le projet SalomeTMF dans lequel l'utilisateur travaille
069: * @param projectName
070: */
071: public void setProject(String projectName) {
072: nameProject = projectName;
073: idProject = Utile.getIdProject(database, prop, projectName);
074: }
075:
076: /**
077: * Ajout d'un groupe d'utilisateurs a un projet
078: * @param groupName
079: * @param groupDesc
080: */
081: public void addGroupToProject(String groupName, String groupDesc) {
082:
083: int _num = -1;
084: try {
085: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
086:
087: PreparedStatement prep = database.prepareStatement(prop
088: .getProperty("addGroupToProject"));
089: prep.setInt(1, idProject);
090: prep.setString(2, groupName);
091: prep.setString(3, groupDesc);
092:
093: prep.executeUpdate();
094: } catch (SQLException E) {
095: E.printStackTrace();
096: org.objectweb.salome_tmf.api.Api.addException(
097: "addGroupToProject", null, E);
098: } catch (Exception ex) {
099: ex.printStackTrace();
100: org.objectweb.salome_tmf.api.Api.addException(null, null,
101: ex);
102: }
103: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
104: }
105:
106: /**
107: * Fonction qui ajoute un utilisateur a un groupe existent
108: * @param userLogin
109: * @param groupName
110: * @param description
111: */
112: public void addUserToGroup(String userLogin, String groupName,
113: String description) {
114: int userId = 0;
115: int groupId = 0;
116:
117: // On initialise l'ID de l'utilisateur et celui du groupe
118: userId = Utile.getIdPerson(database, prop, userLogin);
119: groupId = Utile
120: .getIdGroup(database, prop, idProject, groupName);
121:
122: // on ajoute ensuite l'utilisateur au groupe
123:
124: int _num = -1;
125: try {
126: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
127:
128: PreparedStatement prep = database.prepareStatement(prop
129: .getProperty("addUserToGroup"));
130: prep.setInt(1, userId);
131: prep.setInt(2, groupId);
132: prep.setString(3, description);
133: prep.executeUpdate();
134: } catch (SQLException E) {
135: E.printStackTrace();
136: org.objectweb.salome_tmf.api.Api.addException(
137: "addUserToGroup", null, E);
138: } catch (Exception ex) {
139: ex.printStackTrace();
140: org.objectweb.salome_tmf.api.Api.addException(null, null,
141: ex);
142: }
143: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
144: }
145:
146: /**
147: * Ajout d'un parametre au projet dans la BdD SalomeTMF
148: * @param paramName
149: * @param paramDescription
150: */
151: public void addParamToProject(String paramName,
152: String paramDescription) {
153: int _num = -1;
154: try {
155: _num = org.objectweb.salome_tmf.api.Api.beginTrans();
156:
157: // on appelle la requete a executer
158: PreparedStatement prep = database.prepareStatement(prop
159: .getProperty("addParamToProject"));
160: prep.setInt(1, idProject);
161: prep.setString(2, paramName);
162: prep.setString(3, paramDescription);
163:
164: prep.executeUpdate();
165: } catch (SQLException E) {
166: E.printStackTrace();
167: org.objectweb.salome_tmf.api.Api.addException(
168: "addParamToProject", null, E);
169: } catch (Exception ex) {
170: ex.printStackTrace();
171: org.objectweb.salome_tmf.api.Api.addException(null, null,
172: ex);
173: }
174: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
175: }
176:
177: }
|