KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.List JavaDoc;
51 import java.util.ArrayList JavaDoc;
52 import java.util.Comparator JavaDoc;
53 import java.util.Collections JavaDoc;
54 import java.util.Iterator JavaDoc;
55
56 // Turbine classes
57
import org.apache.torque.TorqueException;
58 import org.apache.torque.om.Persistent;
59 import org.apache.torque.om.ObjectKey;
60 import org.apache.torque.util.Criteria;
61
62 import org.tigris.scarab.services.cache.ScarabCache;
63
64 /**
65  * This class deals with AttributeOptions. For more details
66  * about the implementation of this class, read the documentation
67  * about how Scarab manages Attributes.
68  * <p>
69  * The implementation of this class is "smart" in that it will only
70  * touch the database when it absolutely needs to. For example, if
71  * you create a new AttributeOption, it will not query the database
72  * for the parent/child relationships until you ask it to. It will then
73  * cache the information locally.
74  * <p>
75  * All instances of AttributeOptions are cached using the
76  * TurbineGlobalCache service.
77  *
78  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
79  * @version $Id: AttributeOption.java 8901 2004-02-01 14:06:36Z dep4b $
80  */

81 public class AttributeOption
82     extends BaseAttributeOption
83     implements Persistent
84 {
85     private static final Integer JavaDoc STATUS__CLOSED__PK = new Integer JavaDoc(7);
86
87     /** the name of this class */
88     private static final String JavaDoc CLASS_NAME = "AttributeOption";
89
90     /** a local Attribute reference */
91     private Attribute aAttribute;
92
93     /**
94      * Storage for ID's of the parents of this AttributeOption
95      */

96     private List JavaDoc sortedParents = null;
97
98     /**
99      * Storage for ID's of the children of this AttributeOption
100      */

101     private List JavaDoc sortedChildren = null;
102
103     /**
104      * A cached String of parentIds
105      */

106     private String JavaDoc parentIds = null;
107
108     /**
109      * Used in the creation of an
110      */

111     private List JavaDoc orderedTree = null;
112
113     /**
114      * Must call getInstance()
115      */

116     protected AttributeOption()
117     {
118     }
119
120     public static Integer JavaDoc getStatusClosedPK()
121     {
122         return STATUS__CLOSED__PK;
123     }
124
125     /**
126      * Creates a key for use in caching AttributeOptions
127      */

128     static String JavaDoc getCacheKey(ObjectKey key)
129     {
130          String JavaDoc keyString = key.getValue().toString();
131          return new StringBuffer JavaDoc(CLASS_NAME.length() + keyString.length())
132              .append(CLASS_NAME).append(keyString).toString();
133     }
134
135     /**
136      * A comparator for this class. Compares on OPTION_NAME.
137      */

138     private static final Comparator JavaDoc COMPARATOR = new Comparator JavaDoc()
139         {
140             public int compare(Object JavaDoc obj1, Object JavaDoc obj2)
141             {
142                 int result = 1;
143                 AttributeOption opt1 = (AttributeOption)obj1;
144                 AttributeOption opt2 = (AttributeOption)obj2;
145                 if (opt1.getName().equals(opt2.getName()))
146                 {
147                     result = 0;
148                 }
149                 else
150                 {
151                     result = -1;
152                 }
153                 return result;
154             }
155         };
156
157     /**
158      * Compares numeric value and in cases where the numeric value
159      * is the same it compares the display values.
160      */

161     public static Comparator JavaDoc getComparator()
162     {
163         return COMPARATOR;
164     }
165
166     /**
167      * Get the Attribute associated with this Option
168      */

169     public Attribute getAttribute() throws TorqueException
170     {
171         if (aAttribute==null && (getAttributeId() != null))
172         {
173             aAttribute = AttributeManager.getInstance(getAttributeId());
174             
175             // make sure the parent attribute is in synch.
176
super.setAttribute(aAttribute);
177         }
178         return aAttribute;
179     }
180
181     /**
182      * Set the Attribute associated with this Option
183      */

184     public void setAttribute(Attribute v) throws TorqueException
185     {
186         aAttribute = v;
187         super.setAttribute(v);
188     }
189
190     /**
191      * A new AttributeOption
192      */

193     public static AttributeOption getInstance()
194     {
195         return new AttributeOption();
196     }
197
198     /**
199      * @see #getInstance(Attribute, String, Module, IssueType)
200      */

201     public static AttributeOption getInstance(Attribute attribute, String JavaDoc name)
202         throws Exception JavaDoc
203     {
204         return getInstance(attribute, name, (Module) null, (IssueType) null);
205     }
206
207     /**
208      * Using some contextual information, get an instance of a
209      * particular <code>AttributeOption</code>.
210      *
211      * <p>TODO: Move <code>getInstance()</code> methods into
212      * AttributeOptionManager class.</p>
213      *
214      * @param attribute The attribute to which the named option
215      * belongs.
216      * @param name The module-specific alias or canonical value of the
217      * option.
218      * @param module May be <code>null</code>.
219      * @param issueType May be <code>null</code>.
220      */

221     public static AttributeOption getInstance(Attribute attribute, String JavaDoc name,
222                                               Module module,
223                                               IssueType issueType)
224         throws Exception JavaDoc
225     {
226         AttributeOption ao = null;
227         Criteria crit;
228         // FIXME: Optimize this implementation! It is grossly
229
// inefficient, which is problematic given how often it may be
230
// used.
231
if (module != null && issueType != null)
232         {
233             // Look for a module-scoped alias.
234
crit = new Criteria(4);
235             crit.add(AttributeOptionPeer.ATTRIBUTE_ID,
236                      attribute.getAttributeId());
237             crit.addJoin(AttributeOptionPeer.OPTION_ID,
238                          RModuleOptionPeer.OPTION_ID);
239             crit.add(RModuleOptionPeer.MODULE_ID, module.getModuleId());
240             crit.add(RModuleOptionPeer.ISSUE_TYPE_ID,
241                      issueType.getIssueTypeId());
242             crit.add(RModuleOptionPeer.DISPLAY_VALUE, name);
243             List JavaDoc rmos = RModuleOptionPeer.doSelect(crit);
244             if (rmos.size() == 1)
245             {
246                 RModuleOption rmo = (RModuleOption) rmos.get(0);
247                 ao = rmo.getAttributeOption();
248             }
249         }
250
251         if (ao == null)
252         {
253             // TODO It seems that we might not necessarily get the global option.
254
// Do we want to add a criteria to limit to getting the global option?
255
// This would be either "= 0" or "is null".
256

257             crit = new Criteria(2);
258             crit.add(AttributeOptionPeer.OPTION_NAME, name);
259             crit.add(AttributeOptionPeer.ATTRIBUTE_ID,
260                      attribute.getAttributeId());
261             crit.setIgnoreCase(true);
262             List JavaDoc options = AttributeOptionPeer.doSelect(crit);
263             if (options.size() == 1)
264             {
265                 ao = (AttributeOption) options.get(0);
266             }
267         }
268         return ao;
269     }
270     
271     /**
272      * Returns a list of AttributeOptions which are ancestors
273      * of this AttributeOption. An Ancestor is the parent tree
274      * going up from this AO. The order is bottom up.
275      */

276     public List JavaDoc getAncestors()
277         throws Exception JavaDoc
278     {
279         List JavaDoc options = new ArrayList JavaDoc();
280         addAncestors(options);
281         return options;
282     }
283
284     /**
285      * Recursive method that loops over the ancestors
286      */

287     private void addAncestors(List JavaDoc ancestors)
288         throws Exception JavaDoc
289     {
290         List JavaDoc parents = getParents();
291         for (int i=parents.size()-1; i>=0; i--)
292         {
293             AttributeOption parent = (AttributeOption)
294                 parents.get(i);
295             if (!ancestors.contains(parent))
296             {
297                 ancestors.add(parent);
298                 parent.addAncestors(ancestors);
299             }
300         }
301     }
302
303     /**
304      * Returns a list of AttributeOptions which are descendants
305      * of this AttributeOption. The descendants is the child tree
306      * going down from this AO. The order is bottom up.
307      */

308     public List JavaDoc getDescendants()
309         throws Exception JavaDoc
310     {
311         List JavaDoc options = new ArrayList JavaDoc();
312         addDescendants(options);
313         return options;
314     }
315
316     /**
317      * Recursive method that loops over the descendants
318      */

319     private void addDescendants(List JavaDoc descendants)
320         throws Exception JavaDoc
321     {
322         List JavaDoc children = getChildren();
323         for (int i=children.size()-1; i>=0; i--)
324         {
325             AttributeOption child = (AttributeOption)
326                 children.get(i);
327             descendants.add(child);
328             child.addDescendants(descendants);
329         }
330     }
331
332     /**
333      * Returns a list of AttributeOption's which are children
334      * of this AttributeOption.
335      */

336     public List JavaDoc getChildren()
337         throws TorqueException
338     {
339         if (sortedChildren == null)
340         {
341             buildChildren();
342         }
343         return sortedChildren;
344     }
345
346     /**
347      * Returns a list of AttributeOption's which are parents
348      * of this AttributeOption.
349      */

350     public List JavaDoc getParents()
351         throws Exception JavaDoc
352     {
353         buildParents();
354         return sortedParents;
355     }
356
357     /**
358      * Builds a list of AttributeOption's which are children
359      * of this AttributeOption.
360      */

361     private synchronized void buildChildren()
362         throws TorqueException
363     {
364         Criteria crit = new Criteria()
365             .add(ROptionOptionPeer.RELATIONSHIP_ID,
366                  OptionRelationship.PARENT_CHILD)
367             .add(ROptionOptionPeer.OPTION1_ID,
368                  super.getOptionId());
369
370         List JavaDoc relations = ROptionOptionPeer.doSelect(crit);
371         sortedChildren = new ArrayList JavaDoc(relations.size());
372         for (int i=0; i < relations.size(); i++)
373         {
374             ROptionOption relation = (ROptionOption)relations.get(i);
375             Integer JavaDoc key = relation.getOption2Id();
376             if (key != null)
377             {
378                 sortedChildren.add(relation.getOption2Option());
379             }
380         }
381         sortChildren();
382     }
383
384     /**
385      * Builds a list of AttributeOption's which are parents
386      * of this AttributeOption.
387      */

388     private synchronized void buildParents()
389         throws Exception JavaDoc
390     {
391         Criteria crit = new Criteria()
392             .add(ROptionOptionPeer.RELATIONSHIP_ID,
393                  OptionRelationship.PARENT_CHILD)
394             .add(ROptionOptionPeer.OPTION2_ID,
395                  super.getOptionId());
396
397         List JavaDoc relations = ROptionOptionPeer.doSelect(crit);
398         sortedParents = new ArrayList JavaDoc(relations.size());
399         for (int i=0; i < relations.size(); i++)
400         {
401             ROptionOption relation = (ROptionOption)relations.get(i);
402             Integer JavaDoc key = relation.getOption1Id();
403             if (key != null)
404             {
405                 sortedParents.add(relation.getOption1Option());
406             }
407         }
408         sortParents();
409     }
410
411     /**
412      * re-sorts the Parents
413      */

414     public void sortParents()
415     {
416         synchronized (this)
417         {
418             Collections.sort(sortedParents, getComparator());
419         }
420     }
421
422     /**
423      * re-sorts the children
424      */

425     public void sortChildren()
426     {
427         synchronized (this)
428         {
429             Collections.sort(sortedChildren, getComparator());
430         }
431     }
432
433     /**
434      * Checks to see if this Attribute option is a child of
435      * the passed in AttributeOption parent.
436      */

437     public boolean isChildOf(AttributeOption parent)
438         throws Exception JavaDoc
439     {
440         return getParents().contains(parent);
441     }
442
443     /**
444      * Checks to see if this Attribute option is a parent of
445      * the passed in AttributeOption child.
446      */

447     public boolean isParentOf(AttributeOption child)
448         throws Exception JavaDoc
449     {
450         return getChildren().contains(child);
451     }
452     
453     /**
454      * Does this AttributeOption have children?
455      */

456     public boolean hasChildren()
457         throws Exception JavaDoc
458     {
459         return getChildren().size() > 0 ? true : false;
460     }
461
462     /**
463      * Does this AttributeOption have parents?
464      */

465     public boolean hasParents()
466         throws Exception JavaDoc
467     {
468         return getParents().size() > 0 ? true : false;
469     }
470
471     /**
472      * Returns direct parent of this child.
473      */

474     public AttributeOption getParent()
475         throws Exception JavaDoc
476     {
477         AttributeOption parent = null;
478         Criteria crit = new Criteria()
479             .add(ROptionOptionPeer.RELATIONSHIP_ID,
480                  OptionRelationship.PARENT_CHILD)
481             .add(ROptionOptionPeer.OPTION2_ID,
482                  super.getOptionId());
483        
484         List JavaDoc results = ROptionOptionPeer.doSelect(crit);
485         if (results.size() == 1)
486         {
487            ROptionOption roo = (ROptionOption)results.get(0);
488            parent = roo.getOption1Option();
489         }
490         return parent;
491     }
492
493     /**
494      * Delete mappings with all modules and issue types.
495      */

496     public void deleteModuleMappings()
497         throws Exception JavaDoc
498     {
499         Criteria crit = new Criteria();
500         crit.add(RModuleOptionPeer.OPTION_ID, getOptionId());
501         RModuleOptionPeer.doDelete(crit);
502         ScarabCache.clear();
503     }
504
505     /**
506      * Delete mappings with global issue types.
507      */

508     public void deleteIssueTypeMappings()
509         throws Exception JavaDoc
510     {
511         Criteria crit = new Criteria();
512         crit.add(RIssueTypeOptionPeer.OPTION_ID, getOptionId());
513         RIssueTypeOptionPeer.doDelete(crit);
514         ScarabCache.clear();
515     }
516
517     /**
518      * Add a list of Children to this AttributeOption
519      * @throw Exception if child is already a child
520     public void addChildren(List children)
521         throws Exception
522     {
523         if (children == null)
524         {
525             throw new Exception ("AttributeOption.addChildren() -> no children to add");
526         }
527         else if (children.size() == 0)
528         {
529             return;
530         }
531         synchronized (this)
532         {
533             Iterator itr = children.iterator();
534             while (itr.hasNext())
535             {
536                 addChild((AttributeOption)itr.next());
537             }
538         }
539     }
540      */

541
542     /**
543      * Add a Child to this AttributeOption
544      * @throw Exception if child is already a child
545     public void addChild(AttributeOption child)
546         throws Exception
547     {
548         if (child.isChildOf(this))
549         {
550             throw new Exception (
551                 "The child: " + child.getName() +
552                 " is already a child of: " + this.getName());
553         }
554
555         // make sure that we exist in the database
556         this.save();
557         // make sure that the child exists in the database
558         child.save();
559
560         // create the mapping
561         Criteria crit = new Criteria();
562         crit.add (ROptionOptionPeer.OPTION1_ID, this.getOptionId());
563         crit.add (ROptionOptionPeer.OPTION2_ID, child.getOptionId());
564         ROptionOptionPeer.doInsert(crit);
565
566         synchronized (this)
567         {
568             getChildren().add(child);
569         }
570         synchronized (child)
571         {
572             child.getParents().add(this);
573         }
574         sortChildren();
575     }
576      */

577
578     /**
579      * Add a list of Parents to this AttributeOption
580      * @throw Exception if parents is already a parents
581     public void addParents(List parents)
582         throws Exception
583     {
584         if (parents == null)
585         {
586             throw new Exception ("AttributeOption.addParents() -> no parents to add");
587         }
588         else if (parents.size() == 0)
589         {
590             return;
591         }
592         synchronized (this)
593         {
594             Iterator itr = parents.iterator();
595             int counter = 1;
596             while (itr.hasNext())
597             {
598                 addParent((AttributeOption)itr.next(), counter++);
599             }
600         }
601     }
602      */

603
604 /*
605     public void addParent(AttributeOption parent)
606     {
607         ROptionOption roo = ROptionOption.getInstance();
608         roo.setOption1Id(parent.getOptionId());
609         roo.setOption2Id(this.getOptionId());
610         roo.setPreferredOrder(this.getPreferredOrder());
611         addParent(roo);
612     }
613 */

614     /**
615      * Add a Parent to this AttributeOption
616      * @throw Exception if parent is already a parent
617     public void addParent(ROptionOption parent)
618         throws Exception
619     {
620         if (parent.isParentOf(this))
621         {
622             throw new Exception (
623                 "The parent: " + parent.getOption1Option().getName() +
624                 " is already a parent of: " + this.getName());
625         }
626
627         // make sure that we exist in the database
628         this.save();
629
630         // create the mapping
631         Criteria crit = new Criteria();
632         crit.add (ROptionOptionPeer.OPTION1_ID, parent.getOption1Id());
633         crit.add (ROptionOptionPeer.OPTION2_ID, this.getOptionId());
634         crit.add (ROptionOptionPeer.RELATIONSHIP_ID, OptionRelationship.PARENT_CHILD);
635         crit.add (ROptionOptionPeer.PREFERRED_ORDER, preferredOrder);
636         ROptionOptionPeer.doInsert(crit);
637
638         synchronized (this)
639         {
640             getParents().add(parent.getOption1Option());
641         }
642         synchronized (parent)
643         {
644             parent.getChildren().add(this);
645         }
646         sortParents();
647         clearParentIds();
648     }
649      */

650      
651     /**
652      * Delete all parents. This is usually not a good idea to
653      * expose to the general public and is therefore a private
654      * method.
655     private void deleteParents()
656         throws Exception
657     {
658         Criteria crit = new Criteria();
659         crit.add (ROptionOptionPeer.OPTION2_ID, this.getOptionId());
660         ROptionOptionPeer.doDelete(crit);
661
662         synchronized (this)
663         {
664             getParents().clear();
665         }
666         clearParentIds();
667     }
668      */

669
670     /**
671      * Delete a specific parent
672     public void deleteParent(AttributeOption parent)
673         throws Exception
674     {
675         if (!isChildOf(parent))
676         {
677             throw new Exception (
678                 parent.getName() + " is not a parent of: " +
679                 this.getName());
680         }
681         Criteria crit = new Criteria();
682         crit.add (ROptionOptionPeer.OPTION1_ID, parent.getOptionId());
683         crit.add (ROptionOptionPeer.OPTION2_ID, this.getOptionId());
684         ROptionOptionPeer.doDelete(crit);
685         
686         synchronized (this)
687         {
688             getParents().remove(parent);
689         }
690         synchronized (parent)
691         {
692             parent.getChildren().remove(this);
693         }
694         sortParents();
695         clearParentIds();
696     }
697      */

698
699     /**
700      * Delete all children
701     public void deleteChildren()
702         throws Exception
703     {
704         Criteria crit = new Criteria();
705         crit.add (ROptionOptionPeer.OPTION1_ID, this.getOptionId());
706         ROptionOptionPeer.doDelete(crit);
707
708         synchronized (this)
709         {
710             getChildren().clear();
711         }
712     }
713      */

714
715     /**
716      * Delete a specific child
717     public void deleteChild(AttributeOption child)
718         throws Exception
719     {
720         if (!isParentOf(child))
721         {
722             throw new Exception (
723                 child.getName() + " is not a child of: " +
724                 this.getName());
725         }
726         Criteria crit = new Criteria();
727         crit.add (ROptionOptionPeer.OPTION1_ID, this.getOptionId());
728         crit.add (ROptionOptionPeer.OPTION2_ID, child.getOptionId());
729         ROptionOptionPeer.doDelete(crit);
730
731         synchronized (this)
732         {
733             getChildren().remove(child);
734         }
735         synchronized (child)
736         {
737             child.getParents().remove(this);
738         }
739         sortChildren();
740     }
741      */

742
743     /**
744      * Get a CSV list of Parent id's associated with this
745      * Attribute Option.
746     public String getParentIds()
747         throws Exception
748     {
749         if (parentIds == null)
750         {
751             // special case of no parents == 0
752             if (getParents().size() == 0)
753             {
754                 parentIds = "0";
755             }
756             else
757             {
758                 StringBuffer sb = new StringBuffer();
759                 synchronized (this)
760                 {
761                     boolean firstTime = true;
762                     Iterator itr = getParents().iterator();
763                     while (itr.hasNext())
764                     {
765                         if (!firstTime)
766                         {
767                             sb.append (",");
768                         }
769                         AttributeOption ao = (AttributeOption)itr.next();
770                         sb.append(ao.getOptionId());
771                         firstTime = false;
772                     }
773                 }
774                 parentIds = sb.toString();
775             }
776         }
777         return parentIds;
778     }
779      */

780
781     /**
782      * Set a CSV list of Parent id's associated with this
783      * Attribute Option.
784     public void setParentIds(String ids)
785         throws Exception
786     {
787         if (ids == null || ids.length() == 0)
788         {
789             throw new Exception ("Need to specify a list of parent ids!");
790         }
791         StringTokenizer st = new StringTokenizer(ids, ",");
792         int tokenCount = st.countTokens();
793         List options = new ArrayList(tokenCount+1);
794         if (tokenCount == 0)
795         {
796             AttributeOption ao =
797                 AttributeOption.getInstance((ObjectKey)new NumberKey(0));
798             if (!ao.isParentOf(this))
799             {
800                 options.add(ao);
801             }
802         }
803         else
804         {
805             while (st.hasMoreTokens())
806             {
807                 String id = st.nextToken();
808                 AttributeOption ao =
809                     AttributeOption.getInstance((ObjectKey)new NumberKey(id));
810                 if (!ao.isParentOf(this))
811                 {
812                     options.add(ao);
813                 }
814             }
815         }
816         deleteParents();
817         addParents(options);
818     }
819      */

820
821     /**
822      * Clears out the lists of parent ids
823      */

824     private void clearParentIds()
825     {
826         parentIds = null;
827     }
828
829     /**
830      * A String representation of this object.
831      */

832     public String JavaDoc toString()
833     {
834         try
835         {
836             return "Id: " + getOptionId() + " Name: " + getName();// + " ParentIds: " + getParentIds();
837
}
838         catch (Exception JavaDoc e)
839         {
840             e.printStackTrace();
841         }
842         return null;
843     }
844 /*
845     public List getOrderedChildTree(AttributeOption option)
846         throws Exception
847     {
848         walkTree(option);
849         ArrayList list = new ArrayList();
850         for (int j=orderedTree.size()-1; j>=0; j--)
851         {
852             AttributeOption ao = (AttributeOption) orderedTree.get(j);
853             System.out.println (
854                 getTabs(ao.getParents().size()) +
855                 ao.getOptionId() + " : '" +
856                 ao.getParentIds() + "' : " +
857                 ao.getWeight() + " : " +
858                 ao.getParents().size() + " : " +
859                 ao.getName());
860             list.add(ao);
861         }
862         return list;
863     }
864
865     private void walkTree(AttributeOption option)
866         throws Exception
867     {
868         List children = option.getChildren();
869         for (int j=children.size()-1; j>=0; j--)
870         {
871             AttributeOption ao = (AttributeOption) children.get(j);
872             if (ao.hasChildren())
873             {
874                 walkTree(ao);
875             }
876             orderedTree.add(ao);
877         }
878     }
879     
880     private String getTabs(int level)
881     {
882         StringBuffer sb = new StringBuffer();
883         for (int i = 0; i<level; i++)
884         {
885             sb.append("\t");
886         }
887         return sb.toString();
888     }
889 */

890
891
892     /**
893      * Get all the global issue type mappings for this attribute option.
894      */

895     private List JavaDoc getIssueTypesWithMappings()
896         throws Exception JavaDoc
897     {
898         Criteria crit = new Criteria();
899         crit.add(RIssueTypeOptionPeer.OPTION_ID, getOptionId());
900         crit.addJoin(RIssueTypeOptionPeer.ISSUE_TYPE_ID,
901                      IssueTypePeer.ISSUE_TYPE_ID);
902         return IssueTypePeer.doSelect(crit);
903     }
904
905
906     /**
907      * Checks if this attribute option is associated with atleast one of the
908      * global issue types that is system defined.
909      *
910      * @return True if it is associated with a System defined
911      * global Issue Type. False otherwise.
912      */

913
914     public boolean isSystemDefined()
915         throws Exception JavaDoc
916     {
917         boolean systemDefined = false;
918         List JavaDoc issueTypeList = getIssueTypesWithMappings();
919         for (Iterator JavaDoc i = issueTypeList.iterator();
920              i.hasNext() && !systemDefined;)
921         {
922             systemDefined = ((IssueType)i.next()).isSystemDefined();
923         }
924         return systemDefined;
925     }
926 }
927
Popular Tags