KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > cms > CofaxToolsUser


1 /*
2  * CofaxToolsUser is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/cms/CofaxToolsUser.java,v 1.13.2.1 2006/12/11 16:28:22 fxrobin Exp $
21  */

22
23 package org.cofax.cms;
24
25 import org.cofax.*;
26 import javax.servlet.http.*;
27 import java.util.*;
28
29 /**
30  * CofaxToolsUser: CofaxToolsUser is instantiated as a session object for each
31  * new user - utilities for permissions, workflow, etc flow through this object.
32  *
33  * @author Charles Harvey
34  */

35 public class CofaxToolsUser {
36
37     /**
38      * Contains info from the user table such as name, phone, etc.
39      *
40      */

41     public HashMap userInfoHash;
42
43     /**
44      * Contains Hashes of publications this user is grouped to and group type
45      * permissions for each pub.
46      *
47      */

48     public Vector userPubsVectorOHash;
49
50     /**
51      * Contains a list of all pubIDs/ pubDescs this user is associated with.
52      *
53      */

54     public HashMap userPubDescPubIDHash;
55
56     /**
57      * Contains a list of all pubIDs/ pubNames this user is associated with.
58      *
59      */

60     public HashMap userPubNamePubIDHash;
61
62     /**
63      * Contains a list of all pubNames/ pubDescs this user is associated with.
64      *
65      */

66     public HashMap userPubNamePubDescHash;
67
68     /**
69      * Contains a list of all groups this user is associated with.
70      *
71      */

72     public Vector userGroupVector;
73
74     /**
75      * Contains a list of all groups types this user is associated with.
76      *
77      */

78     public Vector userGroupTypeVector;
79
80     /**
81      * Contains a list of all group names and id's this user is associated with.
82      *
83      */

84     public HashMap userGroupNameGroupIDHash;
85
86     /**
87      * Contains the current pubID that this user is grouped to.
88      *
89      */

90     public String JavaDoc workingPub;
91
92     /**
93      * Contains the current pubDesc that this user is grouped to.
94      *
95      */

96     public String JavaDoc workingPubDesc;
97
98     /**
99      * Contains the current pubName that this user is grouped to.
100      *
101      */

102     public String JavaDoc workingPubName;
103
104     /**
105      * Contains the configuration (global variables) for the user's current
106      * working publication.
107      *
108      */

109     public HashMap workingPubConfigElementsHash;
110
111     /**
112      * Contains articles previously edited by this user in this session.
113      *
114      */

115     public HashMap userPreviousArticlesHash;
116
117     /**
118      * Show the current contents of the user instance.
119      *
120      */

121     public void report() {
122         CofaxToolsUtil.showHash("userInfoHash", userInfoHash);
123         CofaxToolsUtil.showVector("userGroupVector", userGroupVector);
124         CofaxToolsUtil.showHash("userPubDescPubIDHash", userPubDescPubIDHash);
125         CofaxToolsUtil.showHash("userPubNamePubIDHash", userPubNamePubIDHash);
126         CofaxToolsUtil.showHash("workingPubConfigElementsHash", workingPubConfigElementsHash);
127         CofaxToolsUtil.showHash("userPreviousArticlesHash", userPreviousArticlesHash);
128         CofaxToolsUtil.showHash("userPubNamePubDescHash", userPubNamePubDescHash);
129         CofaxToolsUtil.showHash("userGroupNameGroupIDHash", userGroupNameGroupIDHash);
130         CofaxToolsUtil.showVectorOfHashes("userPubsVectorOHash", userPubsVectorOHash);
131         CofaxToolsUtil.log("Working pub: " + workingPub);
132         CofaxToolsUtil.log("Working pub description: " + workingPubDesc);
133         CofaxToolsUtil.log("Working pub name: " + workingPubName);
134     }
135
136     public boolean hasPublicationRights(String JavaDoc askingPub) {
137         Vector vec = userPubsVectorOHash;
138         Iterator it = vec.iterator();
139         boolean hasPubRights = false;
140         while (it.hasNext()) {
141             Object JavaDoc hasPub = it.next();
142             HashMap hasPubHash = (HashMap) hasPub;
143             Iterator en = hasPubHash.keySet().iterator();
144             while (en.hasNext()) {
145                 String JavaDoc pubS = (String JavaDoc) en.next();
146                 if (pubS.equals(askingPub)) {
147                     hasPubRights = true;
148                 }
149             }
150         }
151         return hasPubRights;
152     }
153
154     /**
155      * Sets the globals that we will need when working with the current pub for
156      * http construction, FTP file transfer, etc.
157      *
158      * @param db
159      * The new userWorkingPubConfigElements value
160      * @param session
161      * The new userWorkingPubConfigElements value
162      * @param askingPub
163      * The new userWorkingPubConfigElements value
164      */

165     public boolean setUserWorkingPubConfigElements(DataStore db, HttpSession session, String JavaDoc askingPub) {
166         boolean hasRights = false;
167         if (hasPublicationRights(askingPub)) {
168             workingPubDesc = CofaxToolsUtil.getPubDescFromID(db, askingPub);
169             workingPub = askingPub;
170             workingPubName = CofaxToolsUtil.getPubNameFromID(db, askingPub);
171
172             HashMap fillReq = new HashMap();
173             fillReq.put("PUBID", askingPub);
174             String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromConfigByPubID");
175             workingPubConfigElementsHash = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
176             hasRights = true;
177         }
178         return hasRights;
179     }
180
181     /**
182      * Updates or inserts info into the user table and associated tables as
183      * appropriate.
184      *
185      * @param db
186      * The new userInfo value
187      * @param req
188      * The new userInfo value
189      * @return Description of the Return Value
190      */

191     public static String JavaDoc setUserInfo(DataStore db, HttpServletRequest req) {
192         HashMap ht = CofaxToolsUtil.splitPostQuery(req);
193         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
194         String JavaDoc tag = "";
195
196         String JavaDoc userID = (String JavaDoc) ht.get("USERID");
197         String JavaDoc homePub = (String JavaDoc) ht.get("PUBLICATION");
198         String JavaDoc firstName = (String JavaDoc) ht.get("FIRSTNAME");
199         String JavaDoc lastName = (String JavaDoc) ht.get("LASTNAME");
200         ht.put("HOMEPUB", homePub);
201
202         String JavaDoc userName = (String JavaDoc) ht.get("USERNAME");
203         String JavaDoc userPassword = (String JavaDoc) ht.get("USERPASSWORD");
204         String JavaDoc userPasswordValidation = (String JavaDoc) ht.get("userPasswordValidation");
205         String JavaDoc delete = req.getParameter("delete");
206         int checkBoxTableLength = Integer.parseInt((String JavaDoc) ht.get("checkBoxTableLength"));
207         int checkBoxTableLength2 = 0;
208         try {
209             checkBoxTableLength2 = Integer.parseInt((String JavaDoc) ht.get("checkBoxTableRightLength"));
210         } catch (Exception JavaDoc e) {
211             checkBoxTableLength2 = 0;
212         }
213
214         if (delete == null) {
215             if ((firstName.equals("")) || (lastName.equals("")) || (userName.equals(""))) {
216                 return ("<FONT COLOR=RED>You must enter a user name, user " + "password, first name, and last name on creation of a user...</FONT>");
217             }
218
219             if (!userPassword.equals(userPasswordValidation)) {
220                 return ("<FONT COLOR=RED>Passwords do not match. Please click " + "back on your browser and try again.</FONT>");
221             }
222
223             // check to see if no or too many groups have been selected
224
int groupCheck = 0;
225             for (int i = 0; i <= checkBoxTableLength; i++) {
226                 String JavaDoc temp = String.valueOf(i);
227                 String JavaDoc test = req.getParameter(temp);
228                 if (test != null) {
229                     groupCheck++;
230                 }
231             }
232             if (groupCheck == 0) {
233                 return ("<FONT COLOR=RED>A user must be joined to at least " + "one group before creation. Please click back on your "
234                         + "browser and try again.</FONT>");
235             }
236         }
237
238         if (delete != null) {
239             HashMap htTempor = new HashMap();
240             if (userID != null) {
241                 htTempor.put("USERID", userID);
242                 tag = CofaxToolsDbUtils.fillTag(db, "deleteUserFromTblUsersAndTblUserToGroups");
243                 List list = CofaxToolsDbUtils.getPackageData(db, htTempor, tag);
244                 return ("User " + userID + " (" + ht.get("USERNAME") + ") killed");
245             } else {
246                 return ("<FONT COLOR=RED>You must choose a user before you can " + "delete a user...</FONT>");
247             }
248         }
249
250         if ((userID == null) || (userID.equals(""))) {
251             userID = "0";
252         }
253         ht.put("USERID", userID);
254
255         tag = CofaxToolsDbUtils.fillTag(db, "updateUserInfo");
256         List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
257
258         HashMap dupHolder = (HashMap) list.get(0);
259         String JavaDoc duplicateCheck = (String JavaDoc) dupHolder.get("DUPLICATE");
260         if ((duplicateCheck != null) && (!duplicateCheck.equals(""))) {
261             return ("<FONT COLOR=RED>You have attempted to add a user with " + "the same user name as a current user. Please click back "
262                     + "on your browser, change the user name, and try again.</FONT>");
263         }
264
265         // get the user new id back
266
HashMap hm = (HashMap) list.get(0);
267         userID = (String JavaDoc) hm.get("USERID");
268
269         // update User Sections
270
HashMap htTempp = new HashMap();
271         htTempp.put("USERID", userID);
272         for (int i = 0; i < checkBoxTableLength2; i++) {
273             String JavaDoc temp = String.valueOf(i);
274             String JavaDoc Section = req.getParameter("PARAM" + temp);
275             htTempp.put("MappingCode", Section);
276             String JavaDoc groupID = req.getParameter("s" + temp);
277             String JavaDoc Director = req.getParameter("d" + temp);
278             if (groupID != null && (Director == null)) {
279                 htTempp.put("director", "0");
280                 htTempp.put("action", "1");
281             } else if ((groupID != null) && (Director != null)) {
282                 htTempp.put("director", Director);
283                 htTempp.put("action", "2");
284             } else if ((groupID == null) && (Director != null)) {
285                 htTempp.put("director", Director);
286                 htTempp.put("action", "2");
287             } else {
288                 htTempp.put("action", "0");
289             }
290             tag = CofaxToolsDbUtils.fillTag(db, "updateUserSection");
291             List res = CofaxToolsDbUtils.getPackageData(db, htTempp, tag);
292         }
293
294         // update User Groups
295
HashMap htTempo = new HashMap();
296         htTempo.put("USERID", userID);
297
298         for (int i = 0; i < checkBoxTableLength; i++) {
299             String JavaDoc temp = String.valueOf(i);
300             String JavaDoc groupIDName = req.getParameter("PARAMNAME" + temp);
301             htTempo.put("groupID", groupIDName);
302
303             String JavaDoc groupID = req.getParameter(temp);
304             if (groupID != null) {
305                 htTempo.put("action", "1");
306             } else {
307                 htTempo.put("action", "0");
308             }
309
310             tag = CofaxToolsDbUtils.fillTag(db, "updateUserGroups");
311             List res = CofaxToolsDbUtils.getPackageData(db, htTempo, tag);
312         }
313
314         return ("User " + req.getParameter("USERNAME") + " saved. Please choose another action.");
315     }
316
317     /**
318      * Updates or inserts info into the user table and associated tables as
319      * appropriate.
320      *
321      * @param db
322      * The new userInfo value
323      * @param req
324      * The new userInfo value
325      * @return Description of the Return Value
326      */

327     public static String JavaDoc setMyCountInfo(DataStore db, HttpServletRequest req) {
328         HashMap ht = CofaxToolsUtil.splitPostQuery(req);
329         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
330         String JavaDoc tag = "";
331
332         String JavaDoc userID = (String JavaDoc) ht.get("USERID");
333         String JavaDoc homePub = (String JavaDoc) ht.get("PUBLICATION");
334         String JavaDoc firstName = (String JavaDoc) ht.get("FIRSTNAME");
335         String JavaDoc lastName = (String JavaDoc) ht.get("LASTNAME");
336         ht.put("HOMEPUB", homePub);
337
338         String JavaDoc userName = (String JavaDoc) ht.get("USERNAME");
339         String JavaDoc userPassword = (String JavaDoc) ht.get("USERPASSWORD");
340         String JavaDoc userPasswordValidation = (String JavaDoc) ht.get("userPasswordValidation");
341
342         if ((firstName.equals("")) || (lastName.equals("")) || (userName.equals(""))) {
343             return ("<FONT COLOR=RED>You must enter a user name, user " + ", first name, and last name on creation of a user...</FONT>");
344         }
345         if (!(userPassword.equals(""))) {
346             if (!userPassword.equals(userPasswordValidation)) {
347                 return ("<FONT COLOR=RED>Passwords do not match. Please click " + "back on your browser and try again.</FONT>");
348             }
349         }
350         if ((userID == null) || (userID.equals(""))) {
351             userID = "0";
352         }
353         ht.put("USERID", userID);
354
355         tag = CofaxToolsDbUtils.fillTag(db, "updateUserInfo");
356         List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
357
358         HashMap dupHolder = (HashMap) list.get(0);
359         String JavaDoc duplicateCheck = (String JavaDoc) dupHolder.get("DUPLICATE");
360         if ((duplicateCheck != null) && (!duplicateCheck.equals(""))) {
361             return ("<FONT COLOR=RED>You have attempted to add a user with " + "the same user name as a current user. Please click back "
362                     + "on your browser, change the user name, and try again.</FONT>");
363         }
364
365         // get the user new id back
366
HashMap hm = (HashMap) list.get(0);
367         userID = (String JavaDoc) hm.get("USERID");
368
369         return ("Your count was successfully modified. Please choose another action.");
370     }
371
372     /**
373      * Delete a saved search
374      *
375      */

376     public static String JavaDoc deleteSavedSearch(DataStore db, HttpServletRequest req) {
377
378         String JavaDoc userID = req.getParameter("USERID");
379         String JavaDoc searchName = req.getParameter("SEARCHNAME");
380
381         if (((userID != null) && (!(userID.equals("")))) && ((searchName != null) && (!(searchName.equals(""))))) {
382             StringBuffer JavaDoc v_del = new StringBuffer JavaDoc();
383             v_del.append("delete from tblpermsavedsearches WHERE userID = " + userID + " and searchName='" + searchName + "' ");
384             HashMap ht = new HashMap();
385             List del = CofaxToolsDbUtils.getPackageData(db, ht, v_del.toString());
386             return ("Search " + searchName + " deleted.");
387         } else {
388             return ("You must select a search");
389         }
390     }
391
392 }
393
Popular Tags