KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > ScarabModule


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 // JDK classes
50
import java.io.Serializable JavaDoc;
51 import java.util.Comparator JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.List JavaDoc;
54 import java.util.ArrayList JavaDoc;
55 import java.util.Collections JavaDoc;
56
57 // Commons classes
58
import org.apache.commons.lang.StringUtils;
59
60 // Turbine classes
61
import org.apache.torque.TorqueException;
62 import org.apache.torque.om.Persistent;
63 import org.apache.torque.util.Criteria;
64
65 import java.sql.Connection JavaDoc;
66 import org.apache.fulcrum.security.TurbineSecurity;
67 import org.apache.fulcrum.security.util.RoleSet;
68 import org.apache.fulcrum.security.util.TurbineSecurityException;
69 import org.apache.fulcrum.security.entity.User;
70 import org.apache.fulcrum.security.entity.Group;
71 import org.apache.fulcrum.security.entity.Role;
72
73 // Scarab classes
74
import org.tigris.scarab.om.Module;
75 import org.tigris.scarab.om.MITList;
76 import org.tigris.scarab.om.ScarabUserManager;
77 import org.tigris.scarab.tools.localization.L10NKeySet;
78 import org.tigris.scarab.util.ScarabConstants;
79 import org.tigris.scarab.util.ScarabException;
80 import org.tigris.scarab.util.ScarabPaginatedList;
81 import org.tigris.scarab.util.ScarabLocalizedTorqueException;
82 import org.tigris.scarab.util.ScarabLocalizedTurbineSecurityException;
83 import org.tigris.scarab.services.cache.ScarabCache;
84
85 // FIXME! do not like referencing servlet inside of business objects
86
// though I have forgotten how I might avoid it
87
import org.apache.turbine.Turbine;
88 import org.apache.fulcrum.security.impl.db.entity
89
    .TurbinePermissionPeer;
90 import org.apache.fulcrum.security.impl.db.entity
91
    .TurbineUserGroupRolePeer;
92 import org.apache.fulcrum.security.impl.db.entity
93
    .TurbineRolePermissionPeer;
94 import org.apache.fulcrum.security.impl.db.entity.TurbineUserPeer;
95
96 /**
97  * The ScarabModule class is the focal point for dealing with
98  * Modules. It implements the concept of a Module which is a
99  * single module and is the base interface for all Modules. In code,
100  * one should <strong>never reference ScarabModule directly</strong>
101  * -- use its Module interface instead. This allows us to swap
102  * out Module implementations by modifying the Scarab.properties
103  * file.
104  *
105  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
106  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
107  * @version $Id: ScarabModule.java 9710 2005-05-28 08:45:40Z jorgeuriarte $
108  */

109 public class ScarabModule
110     extends BaseScarabModule
111     implements Persistent, Module, Group
112 {
113     private static final String JavaDoc GET_USERS = "getUsers";
114
115     protected static final Integer JavaDoc ROOT_ID = new Integer JavaDoc(0);
116
117     private String JavaDoc httpDomain = null;
118     private String JavaDoc instanceId = null;
119     private String JavaDoc port = null;
120     private String JavaDoc scheme = null;
121     private String JavaDoc scriptName = null;
122
123     /**
124      * Get the value of domain.
125      * @return value of domain.
126      */

127     public String JavaDoc getHttpDomain()
128     {
129         if (httpDomain == null || httpDomain.length() == 0)
130         {
131             try
132             {
133                 httpDomain = GlobalParameterManager
134                     .getString(ScarabConstants.HTTP_DOMAIN);
135             }
136             catch (Exception JavaDoc e)
137             {
138                 getLog().error("Error getting HTTP_DOMAIN:", e);
139             }
140         }
141         return httpDomain;
142     }
143     
144     /**
145      * Set the value of domain.
146      * @param v Value to assign to domain.
147      */

148     public void setHttpDomain(String JavaDoc v)
149     {
150         if (v != null)
151         {
152             this.httpDomain = v;
153         }
154     }
155
156     /**
157      * Get the value of the Scarab instance id.
158      * @return value of domain.
159      */

160     public String JavaDoc getScarabInstanceId()
161     {
162         if (instanceId == null || instanceId.length() == 0)
163         {
164             try
165             {
166                 instanceId = GlobalParameterManager
167                     .getString(ScarabConstants.INSTANCE_ID);
168             }
169             catch (Exception JavaDoc e)
170             {
171                 getLog().error("Error getting DOMAIN_NAME:", e);
172             }
173         }
174         return instanceId;
175     }
176     
177     /**
178      * Set the value of Scarab domain name.
179      * The value can be an arbirtrary String.
180      * Note: This instance attriute is NOT related to ip/email-domains!
181      * @param v Value to assign to domain.
182      */

183     public void setScarabInstanceId(String JavaDoc v)
184     {
185         if (v != null)
186         {
187             this.instanceId = v;
188         }
189     }
190
191     /**
192      * Get the value of port.
193      * @return value of port.
194      */

195     public String JavaDoc getPort()
196         throws Exception JavaDoc
197     {
198         if (port == null)
199         {
200             port = GlobalParameterManager
201                     .getString(ScarabConstants.HTTP_PORT);
202         }
203         return port;
204     }
205     
206     /**
207      * Set the value of port.
208      * @param v Value to assign to port.
209      */

210     public void setPort(String JavaDoc v)
211         throws Exception JavaDoc
212     {
213         if (v != null)
214         {
215             this.port = v;
216         }
217     }
218
219     /**
220      * Get the value of scheme.
221      * @return value of scheme.
222      */

223     public String JavaDoc getScheme()
224         throws Exception JavaDoc
225     {
226         if (scheme == null)
227         {
228             scheme = GlobalParameterManager
229                     .getString(ScarabConstants.HTTP_SCHEME);
230         }
231         return scheme;
232     }
233     
234     /**
235      * Set the value of scheme.
236      * @param v Value to assign to scheme.
237      */

238     public void setScheme(String JavaDoc v)
239         throws Exception JavaDoc
240     {
241         if (v != null)
242         {
243             this.scheme = v;
244         }
245     }
246
247     /**
248      * Get the value of scriptName.
249      * @return value of scriptName.
250      */

251     public String JavaDoc getScriptName()
252         throws Exception JavaDoc
253     {
254         if (scriptName == null)
255         {
256             scriptName = GlobalParameterManager
257                     .getString(ScarabConstants.HTTP_SCRIPT_NAME);
258         }
259         return scriptName;
260     }
261     
262     /**
263      * Set the value of scriptName.
264      * @param v Value to assign to scriptName.
265      */

266     public void setScriptName(String JavaDoc v)
267         throws Exception JavaDoc
268     {
269         if (v != null)
270         {
271             this.scriptName = v;
272         }
273     }
274
275     /**
276      * @see org.tigris.scarab.om.Module#getUsers(String)
277      */

278     public ScarabUser[] getUsers(String JavaDoc permission)
279     {
280         List JavaDoc perms = new ArrayList JavaDoc(1);
281         perms.add(permission);
282         return getUsers(perms);
283     }
284
285     /**
286      * @see org.tigris.scarab.om.Module#getUsers(List)
287      */

288     public ScarabUser[] getUsers(List JavaDoc permissions)
289     {
290         ScarabUser[] result = null;
291         Object JavaDoc obj = ScarabCache.get(this, GET_USERS,
292                                      (Serializable JavaDoc)permissions);
293         if (obj == null)
294         {
295             Criteria crit = new Criteria();
296             crit.setDistinct();
297             if (permissions.size() == 1)
298             {
299                 crit.add(TurbinePermissionPeer.NAME, permissions.get(0));
300             }
301             else if (permissions.size() > 1)
302             {
303                 crit.addIn(TurbinePermissionPeer.NAME, permissions);
304             }
305             
306             if (permissions.size() >= 1)
307             {
308                 ArrayList JavaDoc groups = new ArrayList JavaDoc(2);
309                 groups.add(getModuleId());
310                 groups.add(ROOT_ID);
311                 crit.addJoin(TurbinePermissionPeer.PERMISSION_ID,
312                              TurbineRolePermissionPeer.PERMISSION_ID);
313                 crit.addJoin(TurbineRolePermissionPeer.ROLE_ID,
314                              TurbineUserGroupRolePeer.ROLE_ID);
315                 crit.addIn(TurbineUserGroupRolePeer.GROUP_ID, groups);
316                 crit.addJoin(ScarabUserImplPeer.USER_ID,
317                              TurbineUserGroupRolePeer.USER_ID);
318                 
319                 crit.add(ScarabUserImplPeer.getColumnName(User.CONFIRM_VALUE),(Object JavaDoc)ScarabUser.DELETED,Criteria.NOT_EQUAL);
320                 
321
322                 try
323                 {
324                     User[] users = TurbineSecurity.getUsers(crit);
325                     result = new ScarabUser[users.length];
326                     for (int i=result.length-1; i>=0; i--)
327                     {
328                         result[i] = (ScarabUser)users[i];
329                     }
330                 }
331                 catch (Exception JavaDoc e)
332                 {
333                     getLog().error(
334                         "An exception prevented retrieving any users", e);
335                     // this method should probably throw the exception, but
336
// until the interface is changed, wrap it in a RuntimeExc.
337
throw new RuntimeException JavaDoc(
338                         "Please check turbine.log for more info: " +
339                         e.getMessage()); //EXCEPTION
340
}
341             }
342             else
343             {
344                 result = new ScarabUser[0];
345             }
346             ScarabCache.put(result, this, GET_USERS,
347                             (Serializable JavaDoc)permissions);
348         }
349         else
350         {
351             result = (ScarabUser[])obj;
352         }
353         return result;
354     }
355
356
357     /**
358      * @see org.tigris.scarab.om.Module#getUsers(String, String, String, String, IssueType)
359      * @param mitList MITs to restrict the user's search. If null, it will not be restricted.
360      */

361     public ScarabPaginatedList getUsers(String JavaDoc name, String JavaDoc username,
362                                         MITList mitList,
363                                         int pageNum, int resultsPerPage,
364                                         final String JavaDoc sortColumn, String JavaDoc sortPolarity,
365                                         boolean includeCommitters)
366         throws Exception JavaDoc
367     {
368         final int polarity = sortPolarity.equals("asc") ? 1 : -1;
369         List JavaDoc result = null;
370         ScarabPaginatedList paginated = null;
371
372         Comparator JavaDoc c = new Comparator JavaDoc()
373         {
374             public int compare(Object JavaDoc o1, Object JavaDoc o2)
375             {
376                 int i = 0;
377                 if ("username".equals(sortColumn))
378                 {
379                     i = polarity * ((ScarabUser)o1).getUserName()
380                               .compareTo(((ScarabUser)o2).getUserName());
381                 }
382                 else
383                 {
384                     i = polarity * ((ScarabUser)o1).getName()
385                              .compareTo(((ScarabUser)o2).getName());
386                 }
387                 return i;
388              }
389         };
390
391             Criteria crit = new Criteria();//
392
Criteria critCount = new Criteria();
393             critCount.addSelectColumn("COUNT(DISTINCT " + TurbineUserPeer.USERNAME + ")");
394             if (mitList != null)
395             {
396                 List JavaDoc modules = mitList.getModules();
397                 for (Iterator JavaDoc it = modules.iterator(); it.hasNext(); )
398                 {
399                     Module mod = (Module)it.next();
400                     List JavaDoc perms = mitList.getUserAttributePermissions();
401                     if (includeCommitters && !perms.contains(org.tigris.scarab.services.security.ScarabSecurity.ISSUE__ENTER))
402                     {
403                         perms.add(org.tigris.scarab.services.security.ScarabSecurity.ISSUE__ENTER);
404                     }
405
406                     crit.addIn(TurbinePermissionPeer.PERMISSION_NAME, perms);
407                     crit.setDistinct();
408                     critCount.addIn(TurbinePermissionPeer.PERMISSION_NAME, perms);
409                 }
410                 crit.addIn(TurbineUserGroupRolePeer.GROUP_ID, mitList.getModuleIds());
411                 critCount.addIn(TurbineUserGroupRolePeer.GROUP_ID, mitList.getModuleIds());
412             }
413             crit.addJoin(TurbineUserPeer.USER_ID, TurbineUserGroupRolePeer.USER_ID);
414             crit.addJoin(TurbineUserGroupRolePeer.ROLE_ID, TurbineRolePermissionPeer.ROLE_ID);
415             crit.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, TurbinePermissionPeer.PERMISSION_ID);
416             critCount.addJoin(TurbineUserPeer.USER_ID, TurbineUserGroupRolePeer.USER_ID);
417             critCount.addJoin(TurbineUserGroupRolePeer.ROLE_ID, TurbineRolePermissionPeer.ROLE_ID);
418             critCount.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, TurbinePermissionPeer.PERMISSION_ID);
419
420             if (name != null)
421             {
422                 int nameSeparator = name.indexOf(" ");
423                 if (nameSeparator != -1)
424                 {
425                     String JavaDoc firstName = name.substring(0, nameSeparator);
426                     String JavaDoc lastName = name.substring(nameSeparator+1, name.length());
427                     crit.add(ScarabUserImplPeer.FIRST_NAME,
428                              addWildcards(firstName), Criteria.LIKE);
429                     crit.add(ScarabUserImplPeer.LAST_NAME,
430                              addWildcards(lastName), Criteria.LIKE);
431                     critCount.add(ScarabUserImplPeer.FIRST_NAME,
432                             addWildcards(firstName), Criteria.LIKE);
433                     critCount.add(ScarabUserImplPeer.LAST_NAME,
434                             addWildcards(lastName), Criteria.LIKE);
435                     
436                 }
437                 else
438                 {
439                     String JavaDoc[] tableAndColumn = StringUtils.split(ScarabUserImplPeer.FIRST_NAME, ".");
440                     Criteria.Criterion fn = crit.getNewCriterion(tableAndColumn[0],
441                                                                  tableAndColumn[1],
442                                                                  addWildcards(name),
443                                                                  Criteria.LIKE);
444                     tableAndColumn = StringUtils.split(ScarabUserImplPeer.LAST_NAME, ".");
445                     Criteria.Criterion ln = crit.getNewCriterion(tableAndColumn[0],
446                                                                  tableAndColumn[1],
447                                                                  addWildcards(name),
448                                                                  Criteria.LIKE);
449                     fn.or(ln);
450                     crit.add(fn);
451                     critCount.add(fn);
452                 }
453             }
454
455             if (username != null)
456             {
457                 crit.add(ScarabUserImplPeer.LOGIN_NAME,
458                          addWildcards(username), Criteria.LIKE);
459                 critCount.add(ScarabUserImplPeer.LOGIN_NAME,
460                         addWildcards(username), Criteria.LIKE);
461             }
462             
463             String JavaDoc col = ScarabUserImplPeer.FIRST_NAME;
464             if (sortColumn.equals("username"))
465                 col = ScarabUserImplPeer.USERNAME;
466             if (sortPolarity.equals("asc"))
467             {
468                 crit.addAscendingOrderByColumn(col);
469             }
470             else
471             {
472                 crit.addDescendingOrderByColumn(col);
473             }
474             
475             int totalResultSize = ScarabUserImplPeer.getUsersCount(critCount);
476             
477             crit.setOffset((pageNum - 1)* resultsPerPage);
478             crit.setLimit(resultsPerPage);
479             result = ScarabUserImplPeer.doSelect(crit);
480
481             // if there are results, sort the result set
482
if (totalResultSize > 0 && resultsPerPage > 0)
483             {
484
485                 paginated = new ScarabPaginatedList(result, totalResultSize,
486                                                     pageNum,
487                                                     resultsPerPage);
488             }
489             else
490             {
491                 paginated = new ScarabPaginatedList();
492             }
493         
494         return paginated;
495     }
496
497
498     /**
499      * @see org.tigris.scarab.om.Module#getUsers(String, String, String, String, IssueType)
500      * This implementation adds wildcard prefix and suffix and performs an SQL
501      * LIKE query for each of the String args that are not null.
502      * WARNING: This is potentially a very EXPENSIVE method.
503      */

504     public List JavaDoc getUsers(String JavaDoc firstName, String JavaDoc lastName,
505                          String JavaDoc username, String JavaDoc email, IssueType issueType)
506         throws Exception JavaDoc
507     {
508         List JavaDoc result = null;
509         // 4th element is ignored due to bug in torque
510
Serializable JavaDoc[] keys = {this, GET_USERS, firstName, null, lastName,
511                                username, email, issueType};
512         Object JavaDoc obj = ScarabCache.get(keys);
513         if (obj == null)
514         {
515             ScarabUser[] eligibleUsers = getUsers(getUserPermissions(issueType));
516             if (eligibleUsers == null || eligibleUsers.length == 0)
517             {
518                 result = Collections.EMPTY_LIST;
519             }
520             else
521             {
522                 List JavaDoc userIds = new ArrayList JavaDoc();
523                 for (int i = 0; i < eligibleUsers.length; i++)
524                 {
525                     userIds.add(eligibleUsers[i].getUserId());
526                 }
527                 Criteria crit = new Criteria();
528                 crit.addIn(ScarabUserImplPeer.USER_ID, userIds);
529                 
530                 if (firstName != null)
531                 {
532                     crit.add(ScarabUserImplPeer.FIRST_NAME,
533                              addWildcards(firstName), Criteria.LIKE);
534                 }
535                 if (lastName != null)
536                 {
537                     crit.add(ScarabUserImplPeer.LAST_NAME,
538                              addWildcards(lastName), Criteria.LIKE);
539                 }
540                 if (username != null)
541                 {
542                     crit.add(ScarabUserImplPeer.LOGIN_NAME,
543                              addWildcards(username), Criteria.LIKE);
544                 }
545                 if (email != null)
546                 {
547                     crit.add(ScarabUserImplPeer.EMAIL, addWildcards(email),
548                              Criteria.LIKE);
549                 }
550                 result = ScarabUserImplPeer.doSelect(crit);
551             }
552             ScarabCache.put(result, keys);
553         }
554         else
555         {
556             result = (List JavaDoc)obj;
557         }
558         return result;
559     }
560
561     private Object JavaDoc addWildcards(String JavaDoc s)
562     {
563         return new StringBuffer JavaDoc(s.length() + 2)
564             .append('%').append(s).append('%').toString();
565     }
566
567     /**
568      * Wrapper method to perform the proper cast to the BaseModule method
569      * of the same name. FIXME: find a better way
570      */

571     public void setParent(Module v)
572         throws Exception JavaDoc
573     {
574         super.setModuleRelatedByParentId(v);
575         // setting the name to be null so that
576
// it gets rebuilt with the new information
577
setName(null);
578         resetAncestors();
579     }
580
581     /**
582      * Cast the getScarabModuleRelatedByParentId() to a Module
583      */

584     public Module getParent()
585         throws Exception JavaDoc
586     {
587         return super.getModuleRelatedByParentId();
588     }
589
590     /**
591      * Override method to make sure the module name gets recalculated.
592      *
593      * @param id a <code>Integer</code> value
594      */

595     public void setParentId(Integer JavaDoc id)
596         throws TorqueException
597     {
598         super.setParentId(id);
599         // setting the name to be null so that
600
// it gets rebuilt with the new information
601
setName(null);
602         resetAncestors();
603     }
604
605     /**
606      * This method returns a complete list of RModuleIssueTypes
607      * which are not deleted, have a IssueType.PARENT_ID of 0 and
608      * sorted ascending by PREFERRED_ORDER.
609      */

610     public List JavaDoc getRModuleIssueTypes()
611         throws TorqueException
612     {
613         return super.getRModuleIssueTypes("preferredOrder","asc");
614     }
615
616     /**
617      * Returns RModuleAttributes associated with this Module. Tries to find
618      * RModuleAttributes associated directly through the db, but if none are
619      * found it should look up the parent module tree until it finds a
620      * non-empty list.
621      */

622     public List JavaDoc getRModuleAttributes(Criteria crit)
623         throws TorqueException
624     {
625         return super.getRModuleAttributes(crit);
626     }
627
628     /**
629      * Returns associated RModuleOptions. if a related AttributeOption is
630      * deleted the RModuleOption will not show up in this list.
631      *
632      * @param crit a <code>Criteria</code> value
633      * @return a <code>List</code> value
634      */

635     public List JavaDoc getRModuleOptions(Criteria crit)
636         throws TorqueException
637     {
638         crit.addJoin(RModuleOptionPeer.OPTION_ID,
639                      AttributeOptionPeer.OPTION_ID)
640             .add(AttributeOptionPeer.DELETED, false);
641         return super.getRModuleOptions(crit);
642     }
643
644
645     public boolean allowsIssues()
646     {
647         return (true);
648     }
649     
650     /**
651      * Saves the module into the database
652      */

653     public void save()
654         throws TurbineSecurityException
655     {
656         try
657         {
658             super.save();
659         }
660         catch (Exception JavaDoc e)
661         {
662             throw new ScarabLocalizedTurbineSecurityException(e); //EXCEPTION
663
}
664     }
665
666     /**
667      * Saves the module into the database. Note that this
668      * cannot be used within a activitySet if the module isNew()
669      * because dbCon.commit() is called within the method. An
670      * update can be done within a activitySet though.
671      */

672     public void save(Connection JavaDoc dbCon)
673         throws TorqueException
674     {
675         // if new, make sure the code has a value.
676
if (isNew())
677         {
678             Criteria crit = new Criteria();
679             crit.add(ScarabModulePeer.MODULE_NAME, getRealName());
680             crit.add(ScarabModulePeer.PARENT_ID, getParentId());
681             // FIXME: this should be done with a method in Module
682
// that takes the two criteria values as a argument so that other
683
// implementations can benefit from being able to get the
684
// list of modules. -- do not agree - jdm
685

686             List JavaDoc result;
687             try {
688                 result = ScarabModulePeer.doSelect(crit);
689             }
690             catch (TorqueException te)
691             {
692              throw new ScarabLocalizedTorqueException(
693                      new ScarabException(
694                              L10NKeySet.ExceptionTorqueGeneric, te));
695             }
696             
697             if (result.size() > 0)
698             {
699                 throw new ScarabLocalizedTorqueException(
700                         new ScarabException(
701                                 L10NKeySet.ExceptionModuleAllreadyExists,
702                         getRealName(),
703                         getParentId()));
704             }
705
706             String JavaDoc code = getCode();
707             if (code == null || code.length() == 0)
708             {
709                 if (getParentId().equals(ROOT_ID))
710                 {
711                     throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionTopLevelModuleWithoutCode));
712                 }
713
714                 try
715                 {
716                     setCode(getParent().getCode());
717                 }
718                 catch (Exception JavaDoc e)
719                 {
720                     throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionCantPropagateModuleCode, e));
721                 }
722             }
723
724             // need to do this before the relationship save below
725
// in order to set the moduleid for the new module.
726
super.save(dbCon);
727             try
728             {
729                 dbCon.commit();
730             }
731             catch (Exception JavaDoc e)
732             {
733                 throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionGeneric, e));
734             }
735             
736             if (getOwnerId() == null)
737             {
738                 throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionSaveNeedsOwner));
739             }
740             // grant the ower of the module the Project Owner role
741
try
742             {
743                 User user = ScarabUserManager.getInstance(getOwnerId());
744                 // FIXME: get this Project Owner string out of here and into
745
// a constant (JSS)
746
Role role = TurbineSecurity.getRole("Project Owner");
747                 grant (user, role);
748                 setInitialAttributesAndIssueTypes();
749             }
750             catch (Exception JavaDoc e)
751             {
752                 throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionGeneric, e));
753             }
754         }
755         else
756         {
757             super.save(dbCon);
758         }
759         
760         // clear out the cache beause we want to make sure that
761
// things get updated properly.
762
ScarabCache.clear();
763     }
764
765     // *******************************************************************
766
// Turbine Group implementation get/setName and save are defined in
767
// parent class AbstractScarabModule
768
// *******************************************************************
769

770     /**
771      * Removes a group from the system.
772      *
773      * @throws TurbineSecurityException if the Group could not be removed.
774      */

775     public void remove()
776         throws TurbineSecurityException
777     {
778         throw new TurbineSecurityException("Not implemented"); //EXCEPTION
779
}
780
781     /**
782      * Renames the group.
783      *
784      * @param name The new Group name.
785      * @throws TurbineSecurityException if the Group could not be renamed.
786      */

787     public void rename(String JavaDoc name)
788         throws TurbineSecurityException
789     {
790         throw new TurbineSecurityException("Not implemented"); //EXCEPTION
791
}
792
793     /**
794      * Grants a Role in this Group to an User.
795      *
796      * @param user An User.
797      * @param role A Role.
798      * @throws TurbineSecurityException if there is a problem while assigning
799      * the Role.
800      */

801     public void grant(User user, Role role)
802         throws TurbineSecurityException
803     {
804         TurbineSecurity.grant(user,this,role);
805     }
806
807     /**
808      * Grants Roles in this Group to an User.
809      *
810      * @param user An User.
811      * @param roleSet A RoleSet.
812      * @throws TurbineSecurityException if there is a problem while assigning
813      * the Roles.
814      */

815     public void grant(User user, RoleSet roleSet)
816         throws TurbineSecurityException
817     {
818         throw new TurbineSecurityException("Not implemented"); //EXCEPTION
819
}
820
821     /**
822      * Revokes a Role in this Group from an User.
823      *
824      * @param user An User.
825      * @param role A Role.
826      * @throws TurbineSecurityException if there is a problem while unassigning
827      * the Role.
828      */

829     public void revoke(User user, Role role)
830         throws TurbineSecurityException
831     {
832         throw new TurbineSecurityException("Not implemented"); //EXCEPTION
833
}
834
835     /**
836      * Revokes Roles in this group from an User.
837      *
838      * @param user An User.
839      * @param roleSet a RoleSet.
840      * @throws TurbineSecurityException if there is a problem while unassigning
841      * the Roles.
842      */

843     public void revoke(User user, RoleSet roleSet)
844         throws TurbineSecurityException
845     {
846         throw new TurbineSecurityException("Not implemented"); //EXCEPTION
847
}
848
849     /**
850      * Used for ordering Groups.
851      *
852      * @param obj The Object to compare to.
853      * @return -1 if the name of the other object is lexically greater than
854      * this group, 1 if it is lexically lesser, 0 if they are equal.
855      */

856     public int compareTo(Object JavaDoc obj)
857     {
858         //---------------------------------------------------------------------
859
// dr@bitonic.com : commented out as per conversation with John McNally
860
// over IRC on 20-Dec-2001
861
//---------------------------------------------------------------------
862
//if (this.getClass() != obj.getClass())
863
//{
864
// throw new ClassCastException();
865
//}
866
String JavaDoc name1 = ((Group)obj).getName();
867         String JavaDoc name2 = this.getName();
868
869         return name2.compareTo(name1);
870     }
871
872
873     /**
874      * All emails related to this module will have a copy sent to
875      * this address. A system-wide default email address can be specified in
876      * Scarab.properties with the key: scarab.email.archive.toAddress
877      */

878     public String JavaDoc getArchiveEmail()
879     {
880         String JavaDoc email = super.getArchiveEmail();
881         if (email == null || email.length() == 0)
882         {
883             email = Turbine.getConfiguration()
884                 .getString(ScarabConstants.ARCHIVE_EMAIL_ADDRESS, null);
885         }
886         
887         return email;
888     }
889
890     /**
891      * returns an array of Roles that can be approved without need for
892      * moderation.
893      */

894     public String JavaDoc[] getAutoApprovedRoles()
895     {
896         return Turbine.getConfiguration()
897             .getStringArray(ScarabConstants.AUTO_APPROVED_ROLES);
898     }
899
900     /**
901      * Gets all module roles.
902      */

903     public List JavaDoc getRoles()
904         throws Exception JavaDoc
905     {
906         return new ArrayList JavaDoc(0);
907     }
908
909     public String JavaDoc toString()
910     {
911         return '{' + super.toString() + " - ID=" + getModuleId() + " - "
912             + getName() + '}';
913     }
914 }
915
916
Popular Tags