Scarab commit: svn commit: r10692 - trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java

Hussayn Dabbous <[email protected]>
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2009-02-14 07:33:32-0800
New Revision: 10692

Modified:
   trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java

Log:
Method AbstractScarabModule:getRModuleOptions(Attribute, IssueType , boolean )
Returns a list of Attribute options. One caveat here is, that it is possible
to disable options in the global attributes area. But if an option is disabled,
its order-place(!) is still taken into account. Thus the order values returned
here are well sorted from lower to higher, but not necessarily consecutively
positioned from 1 to #ofOptions

Another caveat is, that this method also allows for only retrieving the active 
options, where "active" can be defined on a per module/issue type basis. Also 
here we can possibly end in an ordered but not consecutive list of options.

Now this method takes care of thiese caveats and fixes the effect by readjusting 
the element order starting at position 1 and counting up to the number Of Options
available in the result set, thus it is now guaranteed that the options in the 
resultset get a meaningfull and consecutive order value.

The following table illustrates, what i mean. The numbers denote the value of the
order attribute of the RModuleOptions in each of the 2 lists:

Assume, option 2 has been disabled in the global attribute section, so it does not
appear in the allRModuleOptions list. Furthermore option 6 has been marked as inactive
in the current module/issuetype context , so it will be filtered out in the 
resultRModuleOptions. The algorythm as it is implemented now resolves the order 
values as follows:

+-----------------+--------------------+
|allRModuleOptions|resultRModuleOptions|
+-----------------+--------------------+
|        1        |             1      |
|        3        |             2      |
|        4        |             3      |
|        5        |             4      |
|        6        |                    | this element is filtered out.
|        7        |             5      |
+-----------------+--------------------+

THis fix is also related to SCB2623

Modified: trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java?view=diff&pathrev=10692&r1=10691&r2=10692
==============================================================================
--- trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java	(original)
+++ trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java	2009-02-14 07:33:32-0800
@@ -1222,32 +1222,65 @@
         return getRModuleOptions(attribute, issueType, true);
     }
 
+    /**
+     * Returns a list of Attribute options. One caveat here is, that it is possible
+     * to disable options in the global attributes area. But if an option is disabled,
+     * its order-place(!) is still taken into account. Thus the order values returned
+     * here are well sorted from lower to higher, but not necessarily consecutively
+     * positioned from 1 to #ofOptions
+     * 
+     * Another caveat is, that this method also allows for only retrieving the active 
+     * options, where "active" can be defined on a per module/issue type basis. Also 
+     * here we can possibly end in an ordered but not consecutive list of options.
+     * 
+     * Now this method takes care of thiese caveats and fixes the effect by readjusting 
+     * the element order starting at position 1 and counting up to the number Of Options
+     * available in the result set, thus it is now guaranteed that the options in the 
+     * resultset get a meaningfull and consecutive order value.
+     * 
+     * The following table illustrates, what i mean. The numbers denote the value of the
+     * order attribute of the RModuleOptions in each of the 2 lists:
+     * 
+     * Assume, option 2 has been disabled in the global attribute section, so it does not
+     * appear in the allRModuleOptions list. Furthermore option 6 has been marked as inactive
+     * in the current module/issuetype context , so it will be filtered out in the 
+     * resultRModuleOptions. The algorythm as it is implemented now resolves the order 
+     * values as follows:
+     * 
+     * +-----------------+--------------------+
+     * |allRModuleOptions|resultRModuleOptions|
+     * +-----------------+--------------------+
+     * |        1        |             1      |
+     * |        3        |             2      |
+     * |        4        |             3      |
+     * |        5        |             4      |
+     * |        6        |                    | this element is filtered out.
+     * |        7        |             5      |
+     * +-----------------+--------------------+
+     */
     public List getRModuleOptions(Attribute attribute, IssueType issueType,
                                   boolean activeOnly)
         throws TorqueException
     {
-        List allRModuleOptions = null;
-        allRModuleOptions = getAllRModuleOptions(attribute, issueType);
+        List allRModuleOptions    = getAllRModuleOptions(attribute, issueType);
+        List resultRModuleOptions = null;
 
-        if (allRModuleOptions != null)
+        if (allRModuleOptions != null) 
         {
-            if (activeOnly)
+            resultRModuleOptions = new ArrayList(allRModuleOptions.size());
+            int orderIndex = 0;
+            for (int i = 0; i < allRModuleOptions.size(); i++) 
             {
-                List activeRModuleOptions =
-                    new ArrayList(allRModuleOptions.size());
-                for (int i=0; i<allRModuleOptions.size(); i++)
+                RModuleOption rmo = (RModuleOption) allRModuleOptions.get(i);
+                if (!activeOnly || rmo.getActive()) 
                 {
-                    RModuleOption rmo =
-                        (RModuleOption)allRModuleOptions.get(i);
-                    if (rmo.getActive())
-                    {
-                        activeRModuleOptions.add(rmo);
-                    }
+                    rmo.setOrder(++orderIndex); // take care that the option order is consecutive
+                    resultRModuleOptions.add(rmo);
                 }
-                allRModuleOptions =  activeRModuleOptions;
             }
         }
-        return allRModuleOptions;
+
+        return resultRModuleOptions;
     }

------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=1158426
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.